Directive & Remote Computing
DIRECTIVE sends commands to a registered remote machine. The oql-client agent is installed on any machine - it connects outbound to ql.ocalt.com, receives commands, and executes them natively. No inbound ports. No firewall rules required. The agent does not run an OcaltQL runtime - it executes shell commands, file transfers, and system operations directly. All OcaltQL logic stays on the server side.
TUNNEL, SERVE and SERVE FOLDER). It runs EXEC, KILL, READ, WRITE, LIST, LIST DRIVES, DOWNLOAD, UPLOAD, SCREEN, SCREENSHOT, MOUSE, KEYBOARD, POINTER, REDIRECT, WAKE, TUNNEL, SERVE, SERVE FOLDER, Site Mode, POLL and TTL, up to six commands side by side. VIEW, PEERS and LOCAL PEERS, ONDEVICE, WEBASSEMBLY and WINDOW are not available on macOS yet: each returns an error that names it, which OR CATCH ERROR catches. Install it from client.ocalt.com/download.Inline Operations
Every DIRECTIVE operation is a single inline statement - there is no OPEN ... CLOSE block form. Conditionals, loops and variables are handled by the script on the server; the machine only carries out each operation it is sent. EXEC can run any shell command on the target machine, which means any operation the machine supports is reachable through it.
Machine Slots
Every machine must claim a slot before it can be addressed. DIRECTIVE REGISTER claims one for a machine id of your choosing - that id is what you use in every later DIRECTIVE call. Calling DIRECTIVE against an id that was never registered is a fatal error.
Every account holds 4,096 machine slots - the same on every plan. A slot is taken when a machine registers and released when it is removed.
DIRECTIVE UNREGISTER refuses to release it, which keeps a machine id stable for anything already addressing it. This is a mechanism, not a plan limit - it applies identically on every plan.The lock holds back one thing only: releasing. After 24 hours DIRECTIVE UNREGISTER frees the slot. A slot that has been released is free at once - that id can be claimed again immediately, by the same machine or a different one. There is no waiting period on a released slot, and nothing expires a slot on its own: a slot stays claimed until it is released.
DIRECTIVE REGISTER fails with a fatal error telling you either to release a slot, or how many hours remain until the oldest one can be released. Re-registering an id you already hold is harmless and does not consume a second slot.DIRECTIVE REGISTER "home-nas" SET ?reg
AFTER EMIT ?reg("slots")
AFTER EMIT ?reg("used")
AFTER DIRECTIVE "home-nas" EXEC "uptime" SET ?r
AFTER EMIT ?r("stdout")
DIRECTIVE UNREGISTER "old-laptop" SET ?rel
AFTER EMIT ?rel
AFTER DIRECTIVE REGISTER "new-laptop" SET ?reg
AFTER EMIT ?reg
DIRECTIVE "never-registered" EXEC "echo hi"
(* Fatal: unregistered machine id 'never-registered' - claim a slot with DIRECTIVE REGISTER first *)
DIRECTIVE UNREGISTER "home-nas"
(* Fatal: 'home-nas' was registered 5 hour(s) ago - a slot can only
be released after 24 hours *)
Agent Management
DIRECTIVE LIST SET ?agents
AFTER EMIT ?agents("agents")
AFTER EMIT ?agents("used")
AFTER EMIT ?agents("slots")
AFTER DIRECTIVE STATUS "my-home-server" SET ?status
AFTER EMIT ?status("online")
AFTER EMIT ?status("last_seen")
AFTER EMIT ?status("seconds_since_seen")
An agent checks in with the hub on its POLL interval, and every check-in is recorded. DIRECTIVE STATUS "id" returns online, which is true when the machine checked in within the last 15 seconds; last_seen, the moment of its last check-in as "YYYY-MM-DD HH:MM:SS" in the hub's time; and seconds_since_seen, how long ago that was. A machine that is registered but has never checked in reports null for both. The answer also carries the machine’s approximate location, lat and lon, described under The Machine’s Location. Each entry of ?agents("agents") from DIRECTIVE LIST carries machine_id and the same fields. A machine polling every few minutes shows online as false between check-ins; seconds_since_seen against its interval tells whether it is merely between check-ins or gone.
POLL - How Often an Agent Checks In
An agent polls for work on an interval. POLL sets it, per machine, and takes effect on that machine’s next check-in.
The interval is how long a machine waits when it has nothing to do. When several commands are waiting for it, it takes them straight away, at any setting, and runs them side by side where its client can (see Commands Side by Side).
DIRECTIVE "build-box" POLL 0 SECONDS
AFTER DIRECTIVE "personal-server" POLL 1 SECONDS
AFTER DIRECTIVE "home-nas" POLL 5 MINUTES
AFTER DIRECTIVE "backup-box" POLL 60 MINUTES
Commands Side by Side
AND branches run at the same time, and that holds when they speak to the same machine. Each branch queues its own command at the hub; the machine takes several at one check-in and runs them together, so three branches that each take four seconds finish in about four seconds, not twelve.
DIRECTIVE "build-box" WEBASSEMBLY TYPE "bash" ENTER `sleep 4; echo a` SET ?a AND DIRECTIVE "build-box" WEBASSEMBLY TYPE "bash" ENTER `sleep 4; echo b` SET ?b AND DIRECTIVE "build-box" WEBASSEMBLY TYPE "bash" ENTER `sleep 4; echo c` SET ?c
AFTER EMIT ?a & ?b & ?c
(* abc - in about 4 seconds: the three commands run on the machine at once *)
How a machine takes its work
The hub keeps each machine’s commands in a queue, oldest first. A client asks for as many as it has room for, up to sixteen, and each command it is given is claimed in the same moment, so a second check-in can never be handed a command that is already running. A client that asks for one at a time is given one at a time and keeps working exactly as before.
Before November 2026 every client took one command per check-in and finished it before asking for the next, so branches aimed at one machine queued behind each other: the example above took about twelve seconds. Branches aimed at different machines were always parallel.
AFTER still run one after another, because the script waits for each result before it sends the next. Only commands that are waiting at the same moment, such as AND branches or transfers started without waiting, run together.TTL - How Long a Command May Wait
A directive command does not travel straight to the machine. It is queued at the hub, and the machine takes it on its next check-in - the pace POLL above sets. With no TTL the command waits in that queue for as long as it takes: a machine that has been switched off for three days takes the command the moment it comes back. That is the right default for work that is still worth doing whenever it lands, such as a package to install or a file to fetch.
It is the wrong default for work that is only worth doing now. TTL puts a deadline on the wait. If the machine has not taken the command by the time that deadline passes, the hub drops the command and it never runs at all. TTL is optional, and a command written without one behaves exactly as it always has.
DIRECTIVE "kiosk" EXEC "systemctl restart signage" TTL 30 SECONDS SET ?r
AFTER EMIT ?r("stdout")
(* If the kiosk has not checked in within 30 seconds the restart is
dropped from the hub, rather than run at some unknown point later. *)
SECONDS, or SECOND when the TTL is one. The minimum is 1 SECOND and the maximum is 3600 SECONDS - sixty minutes, written in seconds. A value outside that range is FATAL, and so is any other unit: TTL 5 MINUTES does not mean five minutes, it is a FATAL error. Write TTL 300 SECONDS.The deadline measures the wait, not the work
The clock starts when the command is queued and stops the moment the machine takes it. What happens after that is not the TTL’s business: a command with TTL 5 SECONDS that the machine picks up after four seconds and then spends an hour running is never cut off. Once a machine has taken a command its TTL is spent, and the command runs to completion.
So TTL answers “is this still worth starting?”, never “how long may this take?”. A long job with a short TTL is a sensible thing to write: it says start it now, or not at all. To bound how long a script waits for a result instead, use SET PROMISE with WAIT FOR, described in Error Reporting & Catching.
What a script sees when one expires
An expired command is gone from the hub, so it has no result and never will have one. A script waiting on it does not sit out its own timeout - the statement fails as soon as the runtime finds the command dropped. This is an ERROR rather than a FATAL: a machine failing to check in is an external condition, not a mistake in the script, so it is catchable like any other.
DIRECTIVE "kiosk" EXEC "systemctl restart signage" TTL 10 SECONDS SET ?r
OR CATCH ERROR
OPEN
EMIT "the kiosk did not check in in time - nothing was run"
AFTER EMIT !ERROR('code')
CLOSE
E4009. The hub drops a command whose TTL has passed whether or not a script is waiting for it, so TTL is just as useful on a BACKGROUND command that nobody is watching.TTL belongs on a command sent to a machine, the DIRECTIVE "id" ... form, whatever the action. The hub’s own operations - DIRECTIVE REGISTER, UNREGISTER, LIST and STATUS - answer immediately and queue nothing, so there is nothing there for a TTL to govern.TTL adds nothing to the cost of a command. It is a modifier on a call you are already making. See Quotas & Pricing.EXEC and KILL - Remote Shell
Shell commands run directly on the target machine. BACKGROUND makes the call non-blocking, returning a process handle immediately instead of waiting for completion.
DIRECTIVE "personal-server" EXEC "apt-get update && apt-get install -y ffmpeg" SET ?r
AFTER EMIT ?r("stdout")
DIRECTIVE "personal-server" EXEC "python3 /home/worker.py" BACKGROUND SET ?pid
AFTER SLEEP 5 SECONDS
AFTER DIRECTIVE "personal-server" KILL ?pid
DOWNLOAD and UPLOAD
Transfers stream directly between the machine and your namespace, so file size is bounded by your storage quota rather than by memory. DOWNLOAD pulls a file from the machine into the namespace; UPLOAD pushes one the other way. Namespace paths are absolute - /root/... or /mounted/....
DOWNLOAD and UPLOAD never hold the script. Each returns at once with an object carrying the command id, the transfer's tid and its state, and the file moves in the background while the script carries on. At that moment the file has usually not arrived yet. To use the file in the same script, wait for it: ask DIRECTIVE STATUS about the transfer until its state is done, or failed.
DIRECTIVE "home-nas" DOWNLOAD "/srv/reports/latest.csv" TO "/root/latest.csv" SET ?d
AFTER DIRECTIVE STATUS ?d SET ?p
AFTER WHILE ?p("state") IS NOT EQUAL TO "done" AND ?p("state") IS NOT EQUAL TO "failed"
OPEN
SLEEP 1 SECONDS
AFTER DIRECTIVE STATUS ?d SET ?p
CLOSE
AFTER EMIT ?p("state")
AFTER FILE READ "/root/latest.csv" SET ?csv
(* First path is on the machine, second is in your namespace.
FILE READ runs only once the transfer reports done. *)
DIRECTIVE "personal-server" UPLOAD "/root/config.json" TO "/etc/app/config.json" SET ?upl
DIRECTIVE "personal-server" DOWNLOAD "/var/big.bin" TO "/root/big.bin" SET ?job
AFTER EMIT "transfer started, script keeps running"
AFTER STRING ?job("tid") SET CONSISTENT "big_download"
(* A later script reads the tid back and asks after the same transfer:
DIRECTIVE STATUS ?tid SET ?p, then ?p("state"), ?p("percent") *)
PEERS and NETWORK - Machine-to-Machine Transfer
PEERS, LOCAL PEERS and everything built on them (NETWORK ... TRANSFER and SHARE) is not available in the Mac client yet. Sent to a Mac, it returns an error that names it, which OR CATCH ERROR catches. See On a Mac.DIRECTIVE PEERS groups several registered machines into one network value. DIRECTIVE NETWORK ... TRANSFER then moves a file directly between two of them - the bytes travel machine to machine, not up through the server and back down. Each endpoint is written as a machine id, then ://, then a path on that machine.
DIRECTIVE PEERS is refused with an error, and so is a TRANSFER whose two ends are the same machine or a SHARE that lists a machine twice. Every transfer and share needs two different machines.buffering while the two machines connect, in progress while the file moves, done when it has landed, and failed if it could not complete; an interrupted transfer resumes from where it stopped.TRANSFER returns at once, with a tid in its object; it never holds the script while the file moves. DIRECTIVE STATUS on that object, or on the tid alone, returns state, bytes moved so far, total (the file’s size) and percent. Keep the tid in CONSISTENT or PERSISTENT and a later script can ask after the same transfer.DOWNLOAD or UPLOAD returns carries a tid beside its command id, and DIRECTIVE STATUS on that object, or on the tid alone, returns the same state, bytes, total and percent. None of these calls hold the script: the file moves in the background while the script carries on. Any other directive call can be made the same way with SET PROMISE and collected later with WAIT FOR.DIRECTIVE "laptop" DOWNLOAD "D:/footage/day1.mp4" TO "/root/footage/day1.mp4" SET ?d
AFTER SLEEP 5 SECONDS
AFTER DIRECTIVE STATUS ?d SET ?p
AFTER EMIT ?p("state") & ": " & ?p("percent") & "% of " & ?p("total") & " bytes"
DIRECTIVE "personal-server" EXEC "./nightly-report.sh" SET PROMISE ?job
AFTER EMIT "report started"
AFTER WAIT FOR ?job SET ?r
AFTER EMIT ?r("stdout")
WRITE writes exactly what it is given: a string as its UTF-8 bytes, a READ result or any bytes value as itself. ?r("data") is a string when the file is valid UTF-8 and bytes otherwise; ?r("bytes") is the size either way. So DIRECTIVE "a" READ "x" SET ?r then DIRECTIVE "b" WRITE "y" CONTENT ?r("data") copies any file faithfully.DIRECTIVE PEERS "personal-server" AND "laptop" SET ?net
AFTER DIRECTIVE NETWORK ?net TRANSFER FROM "personal-server:///backups/site.tar" TO "laptop://D:/backups/site.tar" SET ?t
AFTER STRING ?t("tid") SET CONSISTENT "backup_transfer"
CONSISTENT "backup_transfer" SET ?tid
AFTER DIRECTIVE STATUS ?tid SET ?p
AFTER EMIT ?p("state") & ": " & ?p("bytes") & " of " & ?p("total") & " bytes, " & ?p("percent") & "%"
DIRECTIVE PEERS "deviceid1" AND "deviceid2" AND "deviceid3" SET ?network
AFTER EMIT ?network(0)("id")
AFTER COUNT ?network SET ?n
AFTER EMIT ?n & " peers"
DIRECTIVE PEERS "deviceid1" AND "deviceid2" AND "deviceid3" SET ?network
AFTER DIRECTIVE NETWORK ?network TRANSFER FROM ?network(0)('id') & "://c:/downloads/file.zip" TO ?network(1)('id') & "://var/www/folder/destfile.zip" SET ?statusanchor
AFTER DIRECTIVE STATUS ?statusanchor SET ?progress
AFTER IF ?progress("state") IS IDENTICAL TO "buffering"
OPEN
SLEEP 5 SECONDS
CLOSE
OR IF ?progress("state") IS IDENTICAL TO "done"
OPEN
EMIT "peer transfer done"
CLOSE
OR
OPEN
EMIT "still in progress check back later"
CLOSE
DIRECTIVE PEERS "deviceid1" AND "deviceid2" AND "deviceid3" SET ?network
AFTER DIRECTIVE NETWORK ?network SHARE ?network(0)('id') PORT 80 AS 8080 SET ?status
(* Any machine in the network can now reach node 0's port 80
at its own localhost:8080 *)
SHARE is peer-to-peer, not a public tunnel. PORT names the port on the machine being shared; AS is the local port every other peer binds. Nothing is exposed to the internet - only members of the network reach it, and only on their own loopback. TUNNEL is the verb for a public URL.TRANSFER returns a status anchor immediately rather than waiting for the file to land. DIRECTIVE STATUS ?statusanchor reads the current state of that transfer - distinct from DIRECTIVE STATUS "id", which reports whether a machine is online. The verb tells them apart by what it is given: a status anchor, or a machine id.LOCAL PEERS - a network that stays in the building
DIRECTIVE LOCAL PEERS is DIRECTIVE PEERS with one word added and one promise attached: the machines must be on the same local network, and everything they exchange stays on it. The lines that follow are written exactly as before. DIRECTIVE NETWORK ... TRANSFER and DIRECTIVE NETWORK ... SHARE do not change; what changes is how the machines reach each other.
DIRECTIVE LOCAL PEERS "laptop" AND "studio-pc" SET ?lan
AFTER DIRECTIVE NETWORK ?lan TRANSFER FROM "laptop://D:/footage/day1.mp4" TO "studio-pc://E:/ingest/day1.mp4" SET ?move
AFTER SLEEP 5 SECONDS
AFTER DIRECTIVE STATUS ?move SET ?p
AFTER EMIT ?p("state") & ": " & ?p("percent") & "%"
DIRECTIVE LOCAL PEERS "nas" AND "laptop" AND "tablet" SET ?lan
AFTER DIRECTIVE NETWORK ?lan SHARE "nas" PORT 5000 AS 5000 SET ?status
(* the laptop and the tablet now reach the NAS at their own localhost:5000,
over the local network and nothing else *)
DIRECTIVE PEERS | DIRECTIVE LOCAL PEERS | |
|---|---|---|
| Where the machines may be | Anywhere | On one local network. A machine that is somewhere else is refused on the LOCAL PEERS line, by name |
| How they find each other | Public address first, local address as well | Local addresses only. No public address is asked for or offered |
| When they cannot connect directly | Falls back to the relay | Fails. There is no relay and no second route |
| Where the bytes travel | Machine to machine, or through the relay | Machine to machine across the local network, never beyond it |
LOCAL PEERS line checks every machine named: each must be connected at that moment, and all of them must be reaching Ocalt from the same network. If one is not, the line fails and names it: machine 'tablet' is not on the same local network as 'nas', or machine 'tablet' is not connected, so it cannot be found on the local network. When a transfer or share then starts, the machines connect across private addresses only; one that cannot be reached that way ends the transfer as failed instead of looking for another route.SCREENSHOT and WAKE
DIRECTIVE "personal-server" SCREENSHOT SET ?shot
AFTER EMIT ?shot
(* ?shot is the path to a real PNG in your namespace *)
The capture is written into your namespace as an ordinary PNG and the verb hands back its path. Nothing is base64, and nothing needs decoding: it is a file, so IMAGE LOAD, GRAPHIC, FILE SHARE and everything else that takes a file work on it directly.
DIRECTIVE "laptop" SCREENSHOT SET ?shot
AFTER FILE SHARE ?shot SET ?link
AFTER EMIT ?link
AFTER EMIT `<img src="` & ?link & `">`
(* The URL points at the PNG itself - no wrapper page needed *)
DIRECTIVE "office-pc" WAKE "AA:BB:CC:DD:EE:FF"
(* An online agent sends the magic packet on its LAN to wake another machine *)
WAKE only succeeds if another already-online oql-client agent shares that machine's local network and can relay the magic packet locally.TUNNEL - Hosting Without a Static IP
Tunnel traffic travels over the connection the agent already holds open to Ocalt - there is no second program to install and no port to open on the machine or the router. Requests arrive at the tunnel URL, are passed down that connection, answered by whatever is listening on the machine's local port, and streamed back.
A tunnel exposes a port on the target machine to the public internet through the agent's own outbound connection - no port forwarding, no static IP, works behind NAT and on mobile connections. Opening one returns a generated URL of the form https://<token>.tunnel.ocalt.com. The tunnel runs independently of the script that created it; closing it deletes the token, and the URL stops working immediately even if the machine is still online.
DIRECTIVE "home-nas" TUNNEL PORT 3000 SET ?tunnel
AFTER EMIT ?tunnel("url")
(* Returns https://<token>.tunnel.ocalt.com - public traffic reaches localhost:3000 on the agent machine *)
DIRECTIVE TUNNEL END ?tunnel
/style.css and /img/logo.png resolve inside that tunnel rather than colliding at the top of a shared domain. Nothing is stored in the browser to make this work.Tunnel URLs are generated per tunnel and are not tied to your subdomains. Site Mode hosting is unaffected by tunnels: a subdomain always serves its own files, whether or not any tunnel is open.
REDIRECT on the Remote Agent
DIRECTIVE "id" REDIRECT "url" opens a URL on the remote agent machine's own local client - useful when the remote machine itself needs to open something locally, such as joining a video call from its own side. This is distinct from the normal REDIRECT verb, which redirects the visitor who triggered the script.
NEW VIDEO BRIDGE 2 PEERS SET ?room
AFTER DIRECTIVE "home-server" REDIRECT ?room("peers")(0)("connect_url")
(* Opens the URL on the remote agent's own local client *)
AFTER REDIRECT ?room("peers")(1)("connect_url")
(* Redirects the actual visitor who ran this script *)
File Access - Read & Write
Read and write files directly on the target machine. A path is the machine’s own path, used exactly as given, and reaches anything the agent’s operating-system user can read or write. The root folder in the agent’s configuration is for Site Mode only; it never applies to READ, WRITE, LIST, DOWNLOAD, UPLOAD or SERVE. Give absolute paths, since a relative path depends on the folder the agent was started in.
DIRECTIVE "personal-server" WRITE "/opt/app/config/app.json" CONTENT '{"mode":"live"}' SET ?w
AFTER DIRECTIVE "personal-server" READ "/opt/app/config/app.json" SET ?cfg
AFTER EMIT ?cfg("data")
(* WRITE creates parent folders as needed; READ returns file contents in data *)
DIRECTIVE "personal-server" READ "C:/app/config.json" SET ?cfg
AFTER EMIT ?cfg
DIRECTIVE "personal-server" READ "/var/log/app.log" SET ?log
AFTER FILE WRITE "/mounted/logs/app.log" CONTENT ?log("data")
Browsing the Machine's Filesystem
LIST FROM returns the contents of a folder on the target machine; LIST DRIVES returns the machine's drives, which is how you find out what paths exist before listing one. Both are read-only and need no desktop session.
MOUSE, KEYBOARD, POINTER, SCREENSHOT, VIEW and SCREEN act on a logged-in graphical session; on a headless machine they return a display error. LIST, LIST DRIVES, READ, WRITE, DOWNLOAD and UPLOAD need no session. On macOS the person grants Screen Recording and Accessibility once in System Settings before capture and input work.DIRECTIVE "personal-server" LIST DRIVES SET ?arrayofdrives
AFTER EMIT ?arrayofdrives(0)
AFTER DIRECTIVE "personal-server" LIST FROM "C:/" SET ?cdrivefolderitemarray
AFTER FOREACH ?cdrivefolderitemarray SET ?item
OPEN
EMIT ?item("name")
CLOSE
LIST DRIVES returns an array of paths, each ready to pass to LIST FROM: on Linux, the mounted filesystems, such as "/" and "/boot/efi"; on Windows, the drive roots, such as C:\. It names the drives and nothing more. A drive's size and free space come from the machine itself, through EXEC, which runs /bin/sh on Linux and cmd.exe on Windows: df answers on Linux, and PowerShell's Get-PSDrive on Windows.
DIRECTIVE "personal-server" EXEC "df -B1 --output=target,size,avail /" SET ?r
AFTER EMIT ?r("stdout")
(* Output, in bytes:
Mounted on 1B-blocks Avail
/ 103865303040 23160971264 *)
LIST FROM carries name, is_dir, size and modified - the same shape FILE LIST returns for your own namespace, so the two can be walked by identical code.SERVE - Expose a File Over the Tunnel
SERVE exposes a single file on the machine, without copying it anywhere. It returns a public url ready to use, and also the local port it bound, so the file can be paired with TUNNEL by hand when a script needs the port for something else. Nothing is installed and nothing is uploaded; the file is read from disk as it is requested.
DIRECTIVE "laptop" SERVE "C:/media/clip.mp4" SET ?src
AFTER EMIT ?src("url")
(* Returns https://serve.ocalt.com/<token>.mp4 - the served file’s extension is part of the URL, so a browser or player picks the right handler. The file streams from the machine on demand *)
SERVE uses serve.ocalt.com/<token>.<ext>. The token carries the served file’s extension, so the URL ends in .mp4, .pdf and the like. A TUNNEL, which fronts a whole site, gets its own subdomain instead.DIRECTIVE "laptop" SERVE "C:/media/clip.mp4" SET ?src
AFTER DIRECTIVE "laptop" TUNNEL PORT ?src("port") SET ?tunnel
AFTER EMIT ?tunnel("url")
(* The file is now readable at that URL, streamed from the machine on demand *)
SERVE FOLDER - A Whole Folder, Browsable
SERVE FOLDER exposes a folder on the machine, as it is: every file in it, and every folder beneath it. It is not a tunnel and nothing runs - there is no process and no port of yours involved. A request for a file is answered by reading that file off the machine’s disk at the moment it is asked for, so what is served is always what is there now.
DIRECTIVE "laptop" SERVE FOLDER "C:/myfolder/" SET ?src
AFTER EMIT ?src("url")
(* https://serve.ocalt.com/<token> - no extension, because it is a folder *)
AFTER EMIT ?src("url") & "/docs/report.pdf"
(* any file inside it, by its path relative to the folder *)
The URL is the folder. Anything inside it is reached by its path relative to the folder, joined on with /, exactly as it sits on the machine: ?src("url") & "/images/logo.png" is C:/myfolder/images/logo.png. Linux and macOS paths work the same way: DIRECTIVE "nas" SERVE FOLDER "/var/myfolder" SET ?src.
Browsing it
Opening the folder URL, or the URL of any folder inside it, shows that folder’s index.html when it has one, so a folder of web pages is a site that works the moment it is served. A folder without an index.html shows a listing of what it contains - names, sizes and dates, each a link - so a folder of files can be browsed and downloaded from any browser. LISTING shows the listing even where an index.html exists.
DIRECTIVE "nas" SERVE FOLDER "/srv/shared" LISTING SET ?share
AFTER EMIT ?share("url")
- As it is. Each file is sent with the content type its extension names, and ranged requests are supported, so a video in the folder plays and seeks in a browser. Files stream in chunks; size is not a constraint.
- Inside the folder only. A path containing
..is refused before it is looked at, and a link inside the folder that points somewhere outside it is not followed. Nothing above the folder you served can be reached through its URL. - Live. A file added to the folder after it was served is there on the next request; one removed answers 404. The machine has to be online for the URL to answer.
Ending a served file or folder
A served file or folder stays up until it is ended. DIRECTIVE SERVE END takes what SERVE or SERVE FOLDER returned, and the URL stops answering at once, whether or not the machine is online.
DIRECTIVE "laptop" SERVE FOLDER "C:/myfolder/" SET ?src
AFTER EMIT ?src("url")
(* ...later, in this script or another one *)
AFTER DIRECTIVE SERVE END ?src
SCREEN - Display Geometry
SCREEN returns one entry per display, so a script can work out where it is pointing before it moves anything. Each entry carries width, height, x, y and primary.
DIRECTIVE "laptop" SCREEN SET ?screen
AFTER EMIT ?screen(0)("width")
AFTER EMIT ?screen(0)("height")
AFTER CALCULATE ?screen(0)("width") / 2 SET ?cx
AFTER CALCULATE ?screen(0)("height") / 2 SET ?cy
AFTER DIRECTIVE "laptop" POINTER X ?cx Y ?cy
AFTER DIRECTIVE "laptop" MOUSE "[Click]"
(* ?screen(1) is null when there is only one display *)
SCREENSHOT takes the same display numbers, and can capture every display at once.
DIRECTIVE "laptop" SCREENSHOT SET ?shot
AFTER EMIT ?shot
(* The primary display. One screen asked for, one path back. *)
AFTER DIRECTIVE "laptop" SCREENSHOT ON DISPLAY 2 SET ?second
AFTER EMIT ?second
(* One screen by number, counting from 1 in SCREEN's order. *)
AFTER DIRECTIVE "laptop" SCREENSHOT ON DISPLAY "all" SET ?shots
AFTER COUNT ?shots SET ?n
AFTER EMIT ?n & " displays captured"
AFTER FOREACH ?shots SET ?path
OPEN
EMIT ?path
CLOSE
(* Every screen, in one capture. "all" answers with an array of
paths, so COUNT is how many screens the machine has and
FOREACH walks them. *)
Displays are numbered from 1, in the order SCREEN reports them, so a script can ask what is there before deciding what to capture.
The shape of the answer follows the request, and it is worth being deliberate about which one you asked for. A capture of a single screen - the primary by default, or one named by number - comes back as one path, a string. ON DISPLAY "all" comes back as an array of paths, one per screen, in that same order; it is an array even on a machine with one screen, so a script written against "all" keeps working when someone plugs in a second monitor. That is why the example above can COUNT it and walk it without checking anything first.
VIEW - The Screen, Live
VIEW feed is not available in the Mac client yet. Sent to a Mac, it returns an error that names it, which OR CATCH ERROR catches. See On a Mac.VIEW returns an object with url, token, format, display and fps. The URL takes the same form a served file does, https://serve.ocalt.com/<token>.<ext>, the extension naming the stream. By default it is .live: a live player that shows the screen as video, a fraction of a second behind the machine. Open it directly or put it in an <iframe>. FPS n sets the frame rate from 1 to 30; the default is 15, and anything outside that range is an error. AS MJPEG asks for the older .mjpg feed instead, which any browser plays in an <img> tag, at the cost of more bandwidth and more delay. On an Android phone the feed is always .mjpg, with or without AS MJPEG: the OcaltQL Client there carries no video encoder, and the format it returns says mjpeg. ON DISPLAY n picks a screen, and each display streams on its own, so every screen of a machine can be watched at once. A feed closes after 300 seconds with no viewer, or at DIRECTIVE VIEW END ?feed. To publish a feed further, to RTSP or HLS, pass its URL to NEW TRANSCODE STREAM.DIRECTIVE "workstation" VIEW ON DISPLAY 2 FPS 30 SET ?feed
AFTER EMIT `<iframe src="` & ?feed("url") & `" style="width:100%;aspect-ratio:16/9;border:0"></iframe>`
(* Displays are numbered from 1, in the order SCREEN reports them *)
AFTER DIRECTIVE "workstation" VIEW AS MJPEG SET ?still
AFTER EMIT `<img src="` & ?still("url") & `">`
(* The older feed, for a page that can only take an image *)
How long a feed lasts
A feed lives while it is being watched. Five minutes after the last time anything pulls from it, it closes and its URL stops working.
Idle is the right thing to measure, not age. A fixed expiry would cut off someone in the middle of watching, and would keep an abandoned tab transcoding long after everyone walked away. This way a feed you are using never dies under you, and a feed nobody is looking at stops costing anything.
DIRECTIVE "laptop" VIEW SET ?feed
AFTER EMIT ?feed("url")
AFTER EMIT ?feed("expires_after")
(* 300 - seconds of inactivity before it closes *)
(* Later, in another script *)
AFTER DIRECTIVE VIEW END ?feed
(* Or just stop watching: it closes on its own. *)
DIRECTIVE VIEW END closes it immediately.Look, decide, act
(* Look. *)
DIRECTIVE "personal-server" SCREENSHOT SET ?before
AFTER FILE SHARE ?before SET ?link
AFTER EMIT ?link
(* Act, then look again. *)
AFTER DIRECTIVE "personal-server" POINTER X 400 Y 300
AFTER DIRECTIVE "personal-server" MOUSE "[Click]"
AFTER DIRECTIVE "personal-server" SCREENSHOT SET ?after
AFTER FILE SHARE ?after SET ?link2
AFTER EMIT ?link2
(* Two files, two moments - you can see exactly what the click did. *)
MOUSE, KEYBOARD, POINTER, SCREENSHOT, VIEW and SCREEN all act on a real display - injecting input into it or reading pixels from it. On a machine with no graphical session, such as a headless server, they return an error about not reaching a display. That is not something a script can work around: the machine needs a logged-in desktop for them to have anything to act on.MOUSE, KEYBOARD, POINTER MOVE and POINTER COORDINATES run through an accessibility service the person switches on once in Settings › Accessibility › Ocalt. Android has no other way for an app to drive input, and the switch cannot be flipped from code. Until it is on, those four return a needs-setup message the same way a headless desktop reports a missing session. A phone has no hardware pointer, so POINTER MOVE sets a virtual pointer and MOUSE "[Click]" taps where it sits.Input Control - Mouse, Keyboard & Pointer
Beyond shell access, DIRECTIVE can drive the target machine's actual mouse and keyboard through the OcaltQL Client's input service. The client must be running on the target with input access - combined with SCREENSHOT, this makes a machine fully navigable from a script. Keys and buttons are written as [Name] tokens joined by +: "[Control]+[c]", "[MouseDown]+[Down]". The full grammar is below.
Key and Button Syntax
Keys and buttons are written as [Name] tokens. Combine them with + between brackets - [Control]+[c], [Control]+[Shift]+[Escape]. A quoted string inside the brackets is a literal character, which is how you send the bracket keys themselves: ["]"] is the ] key, ["["] is [. Single characters need no quotes: [a], [5], [/].
KEYBOARD takes a whole instruction in one command, so a phrase costs one round trip rather than one per letter:
"[Control]+[c]" is a chord, the modifiers held while the last key is tapped;
"[h][e][l][l][o]" is five keys pressed one after another;
"Hello there." is typed literally, character for character, including characters no key is named for;
and the forms mix, as in "[Control]+[a]Replacement text[Enter]".
A key the machine does not recognise raises an error you can catch, so a mistyped name can never fail quietly.DIRECTIVE "laptop" KEYBOARD "[Control]+[a]"
AFTER DIRECTIVE "laptop" KEYBOARD "Rewritten by a script.[Enter]"
AFTER DIRECTIVE "laptop" KEYBOARD "[Control]+[s]"
Named keys follow the platform key set: [Enter], [Escape], [Tab], [Space], [Backspace], [Delete], [Insert], [Home], [End], [PageUp], [PageDown], [Up] [Down] [Left] [Right] (or [ArrowUp] etc.), [F1]–[F20], [CapsLock], [NumLock], [ScrollLock], [PrintScreen], [Pause], [ContextMenu], media keys such as [VolumeUp], [VolumeDown], [VolumeMute], [MediaPlayPause], [MediaNextTrack], and numpad keys [Numpad0]–[Numpad9].
Modifiers: [Control] (or [Ctrl]), [Shift], [Alt], [Meta] (or [Win], [Cmd]). In a combination the last token is the key pressed; everything before it is held down and released after.
Mouse tokens: [Click], [RightClick], [MouseDown], [MouseUp], [Up] [Down] [Left] [Right] (relative movement), [ScrollUp], [ScrollDown]. Combine them the same way: [MouseDown]+[Down] drags downward.
0,0; a monitor to its right occupies x values beyond the primary's width, and one to its left uses negative x. POINTER COORDINATES reads back in the same space, so you can read a position, work out which display it falls on, and move relative to it.DIRECTIVE "personal-server" POINTER X 400 Y 300
AFTER DIRECTIVE "personal-server" POINTER COORDINATES SET ?coord
AFTER EMIT ?coord("x")
AFTER EMIT ?coord("y")
(* POINTER COORDINATES blocks for the agent's reply - ?coord("x"), ?coord("y") *)
DIRECTIVE "personal-server" MOUSE "[MouseDown]+[Down]"
AFTER DIRECTIVE "personal-server" MOUSE "[ScrollDown]"
(* Tokens: [Click] [RightClick] [MouseDown] [MouseUp] [Up] [Down] [Left] [Right] [ScrollUp] [ScrollDown] *)
DIRECTIVE "personal-server" KEYBOARD "[Control]+[c]"
AFTER DIRECTIVE "personal-server" KEYBOARD "[Enter]" SET ?ok
AFTER EMIT ?ok
(* Single keys or + combinations. Optional SET returns true/false for success *)
DIRECTIVE "personal-server" SCREENSHOT SET ?img
AFTER DIRECTIVE "personal-server" POINTER X 250 Y 480
AFTER DIRECTIVE "personal-server" MOUSE "[Click]"
AFTER DIRECTIVE "personal-server" KEYBOARD "[Enter]"
(* Capture, locate a target, move, click, type - the remote navigation loop *)
ONDEVICE - The Machine’s Own Hardware
ONDEVICE is not available in the Mac client yet. Sent to a Mac, it returns an error that names it, which OR CATCH ERROR catches. See On a Mac.ONDEVICE reaches the hardware of a machine running the OcaltQL Client: its camera, microphone, GPS, Bluetooth, NFC, sensors, contacts, calendar, storage and notifications. It is the same command language an Applicate app’s onDevice speaks, with the same commands and the same answers - sent from a script, to a machine, rather than called from inside an app.
The command goes between square brackets. Inside them is device command language, not OcaltQL, exactly as written on the Applicate page:
DIRECTIVE "Phone" ONDEVICE [CAMERA REAR CAPTURE MAXWIDTH 1600] SET ?photo
AFTER EMIT ?photo("path")
(* the photograph, written into your namespace as a JPEG *)
AFTER DIRECTIVE "Phone" ONDEVICE [GPS ACCURACY 20 TIMEOUT 30] SET ?fix
AFTER EMIT ?fix("lat") & ", " & ?fix("lng") & " within " & ?fix("accuracy") & " m"
BIND - values into the command
A ?name inside the brackets is a placeholder, and BIND fills it from your script. Values travel as they are - strings as strings, bytes as bytes - with no quoting and nothing to escape, so a filename with a quote or a bracket in it, or the bytes of an image, arrive intact. Anything that is not a literal you typed goes in through BIND.
DIRECTIVE "Phone" ONDEVICE [DRIVE LIST] SET ?drives
AFTER DIRECTIVE "Phone" ONDEVICE [DRIVE ?d FILE READ ?p] BIND ["d" AS ?drives(0)("id") AND "p" AS "/DCIM/Camera/IMG_0412.jpg"] SET ?file
AFTER FILE WRITE "/root/photos/IMG_0412.jpg" CONTENT ?file("data")
AFTER DIRECTIVE "laptop" ONDEVICE [NOTIFY ?m WITH "Ocalt"] BIND ["m" AS "The backup finished"]
Fire, halt and stream
Every command has one of three shapes, the same three the Applicate page describes. A fire command returns as soon as the machine has it. A halt command waits for the machine’s answer - a photograph, a fix, a person’s choice - up to the directive ceiling of 300 seconds, and answers null if the person refused, the hardware is absent or the time ran out. A stream keeps producing values, so it needs somewhere to send them: INTO CHANNEL names a sync channel, and every value arrives there as it is produced, under the event name the command gave it.
NEW SYNC CHANNEL SET ?ch
AFTER DIRECTIVE "Phone" ONDEVICE [GPS WATCH EVERY 5 SECONDS INTO "position"] INTO CHANNEL ?ch
(* each fix reaches ?ch as a "position" event - a page listening on the
channel moves its marker as the phone moves *)
AFTER EMIT ?ch("connect_url")
(* ...and when it is no longer wanted *)
AFTER DIRECTIVE "Phone" ONDEVICE [GPS WATCH STOP]
Captures become files. A photograph, a recording, a screenshot and a finished screen recording are written into your namespace as real files - path names the file, data holds its bytes - so IMAGE LOAD, MEDIA LOAD, FILE SHARE and everything else that takes a file works on them directly. Nothing is base64.
| Commands | Shape | What comes back |
|---|---|---|
NOTIFY, VIBRATE, CLIPBOARD WRITE, CALL, CALL NOW, MESSAGE COMPOSE | Fire | Returns as soon as the machine has it |
CAMERA CAPTURE, CAMERA VIDEO CAPTURE, MICROPHONE RECORD, SCREENSHOT | Halt | The capture is written into your namespace as a real file: path names it, data holds its bytes, beside the keys the Applicate table lists |
GPS, WIFI, WIFI SCAN, NFC READ, SENSOR, SENSORS LIST, ORIENTATION, BATTERY, NETWORK, DEVICE, CLIPBOARD READ, CALENDAR LIST | Halt | An object, exactly as on the Applicate page |
DRIVE LIST, DRIVE ?d FILE LIST ?p, DRIVE ?d FILE READ ?p, DRIVE ?d FILE WRITE ?p CONTENT ?b | Halt | The machine’s own storage; FILE READ returns data as bytes |
DRIVE PICK, CONTACTS PICK, BIOMETRIC PROMPT, WIFI JOIN | Halt | Waits for the person at the machine to choose or confirm |
BLUETOOTH SCAN, CONNECT, SERVICES, READ, WRITE, CLOSE; NFC WRITE | Halt | Bluetooth Low Energy, as on the Applicate page |
SCREEN KEEP ON, SCREEN KEEP OFF | Fire | The screen comes on and stays on - for good, or FOR a number of SECONDS, MINUTES or HOURS - until OFF hands it back to the machine’s own timeout |
SCREEN RECORD START, SCREEN RECORD STOP | Halt | START waits until recording has begun and answers recording, width, height, max_seconds and audio; STOP answers the recording as an mp4 file, with its duration |
GPS WATCH, SENSOR ... WATCH, BLUETOOTH ... NOTIFY | Stream | Delivered to a sync channel with INTO CHANNEL; ended with its own STOP form |
MESSAGE SEND; CALL STATE, WAIT, ANSWER, REJECT, END, PLAY, BRIDGE | Halt | A phone’s messages and calls, described below |
MICROPHONE RECORD START, STOP; MICROPHONE STREAM; AUDIO PLAY, AUDIO STOP | Halt, Stream, Fire | Sound recorded, streamed and played, described below |
... PERMISSION | Halt | Every halting command’s permission form - true, false or null |
The keys each answer carries, and every modifier each command takes, are the ones listed on the Applicate page. Four commands there have no place on a machine reached from a script and are not accepted by ONDEVICE: SPLASH (a client has no splash screen), TRAY (the tray belongs to the client), BROWSER OPEN (DIRECTIVE REDIRECT already does it) and CAMERA VIEW INLINE (there is no page to draw it into - inside a WINDOW page it works as it does in an app).
The screen: kept on, recorded
A phone on a stand showing a dashboard, a tablet at a front desk, a laptop running a long job someone will look at later - each needs its screen left on. SCREEN KEEP ON wakes the screen and keeps it lit until SCREEN KEEP OFF, or for as long as FOR says. It needs no permission and shows nothing on the machine; the screen simply stays on. The machine can still be locked as usual.
SCREEN RECORD START records the screen until SCREEN RECORD STOP, which answers the recording as an mp4 in your namespace - path, data, width, height, duration - like any other capture. MAXSECONDS (300 if not given, at most 1800) ends a recording nobody stopped; the finished file waits for the next STOP, and a new START drops one nobody collected. AUDIO adds the microphone on Android. With INTO "event" and INTO CHANNEL, the channel also hears {state: "recording"} when it begins and {state: "stopped"} when it ends; on Android that event carries reason - "stop", "maxseconds", or "system" when the person ended sharing from the phone itself.
DIRECTIVE "Phone" ONDEVICE [SCREEN KEEP ON FOR 30 MINUTES]
AFTER DIRECTIVE "Phone" ONDEVICE [SCREEN RECORD START MAXSECONDS 120] SET ?rec
AFTER EMIT "recording at " & ?rec("width") & "x" & ?rec("height")
AFTER SLEEP 15 SECONDS
AFTER DIRECTIVE "Phone" ONDEVICE [SCREEN RECORD STOP] SET ?video
AFTER EMIT ?video("path") & ", " & ?video("duration") & " seconds"
AFTER DIRECTIVE "Phone" ONDEVICE [SCREEN KEEP OFF]
SCREEN RECORD START brings the client forward with Android’s own “start recording?” question, and START answers null if the person says no. While it records, Android shows its screen-sharing indicator and the client’s notification says so; a SCREENSHOT taken during a recording answers null, because the one capture Android allows is busy. Windows records with ffmpeg’s desktop capture and Linux with X11 capture, both without sound; on Linux SCREEN KEEP ON turns off blanking for the logged-in X session and answers null on a machine with no graphical session.Text messages, sent without a tap
MESSAGE COMPOSE opens the phone’s messaging app with the text filled in and waits for the person to press send. MESSAGE SEND sends it. Nothing opens on the phone, nobody presses anything, and the answer says whether the network took the message.
DIRECTIVE "Phone" ONDEVICE [MESSAGE SEND ?text TO ?to] BIND ["text" AS "Your Ocalt code is 482913" AND "to" AS "+27821234567"] SET ?sms
AFTER EMIT ?sms("sent") & " in " & ?sms("parts") & " part(s)"
The answer carries sent (true once the network has accepted it), to, parts (a long message is split and sent as several) and, when sent is false, error: no service, radio off, refused by the network or timed out. The first MESSAGE SEND raises Android’s own question about sending messages; if the person says no, the command answers null. Messages are sent from the phone’s SIM and cost whatever its plan charges.
Calls: placed, answered, ended
A phone running the client can place a call, notice one coming in, read the number, answer or reject it, play sound to the caller and hang up, all from a script.
| Command | What it does | What comes back |
|---|---|---|
CALL NOW "+27821234567" | Places the call at once | true when the call was started |
CALL STATE | Reads what the phone is doing now | state: idle, ringing or active; number for an incoming call |
CALL WAIT TIMEOUT 60 | Waits for a call to come in, for up to that many seconds | state and number the moment it rings; null if no call came |
CALL ANSWER, CALL ANSWER SPEAKER | Answers the call that is ringing; SPEAKER puts it on the loudspeaker | true, or false when nothing was ringing |
CALL REJECT | Declines the call that is ringing | true, or false when nothing was ringing |
CALL END | Hangs up the call in progress | true, or false when there was no call |
CALL PLAY "file or address", CALL PLAY STOP | Plays a sound file to the other person. LOOP repeats it; VOLUME 0 to 100 sets how loud | playing and duration in seconds |
CALL BRIDGE ?url, CALL BRIDGE STOP | Joins an audio bridge on the phone and plays it to the other person | joined |
DIRECTIVE "Phone" ONDEVICE [CALL WAIT TIMEOUT 120] SET ?in
AFTER EMIT ?in("state") & " " & ?in("number")
DIRECTIVE "Phone" ONDEVICE [CALL ANSWER SPEAKER]
AFTER DIRECTIVE "Phone" ONDEVICE [CALL PLAY "/sdcard/Music/greeting.mp3" VOLUME 100] SET ?g
AFTER SLEEP ?g("duration") SECONDS
AFTER DIRECTIVE "Phone" ONDEVICE [CALL END]
NEW AUDIO BRIDGE 2 PEERS SET ?room
AFTER DIRECTIVE "Phone" ONDEVICE [CALL ANSWER SPEAKER]
AFTER DIRECTIVE "Phone" ONDEVICE [CALL BRIDGE ?url] BIND ["url" AS ?room("peers")(0)]
(* whoever joins the bridge's other seat is now heard by the caller *)
CALL PLAY takes a file on the phone or an https address, so a file in your namespace plays once it has a FILE SHARE link. CALL WAIT holds its command open while it listens, so give it a TTL longer than its TIMEOUT when you wait for more than a minute.
CALL PLAY and CALL BRIDGE turn the loudspeaker on and play through it, and the phone’s own microphone carries the sound to the other person: it works with the phone lying on a desk, and how clearly it carries depends on the handset. For the same reason a bridge can speak to a caller but cannot hear them. The caller’s number is read only if the person allowed the client to see calls; without that, number is empty. These commands answer null on a computer.Audio: recorded, streamed, played
MICROPHONE RECORD MAXSECONDS 60 records for a fixed time and waits. Three more forms cover a recording of unknown length, live sound, and playing a sound on the machine.
| Command | Shape | What comes back |
|---|---|---|
MICROPHONE RECORD START | Halt | Returns once recording has begun: recording and max_seconds. MAXSECONDS is the longest it may run, 3600 unless you say otherwise |
MICROPHONE RECORD STOP | Halt | The recording, written into your namespace as an .m4a file: path, duration, mime, size |
MICROPHONE STREAM INTO "audio", MICROPHONE STREAM STOP | Stream | Live sound, delivered to a sync channel with INTO CHANNEL as one event every half second, or EVERY so many MILLISECONDS. RATE is the sample rate: 16000 unless you ask for 8000, 22050 or 44100 |
AUDIO PLAY "file or address", AUDIO STOP | Fire | Plays a sound through the machine’s speaker. LOOP repeats it; VOLUME 0 to 100 sets how loud. Answers playing and duration |
DIRECTIVE "Phone" ONDEVICE [MICROPHONE RECORD START MAXSECONDS 1800]
AFTER SLEEP 30 SECONDS
AFTER DIRECTIVE "Phone" ONDEVICE [MICROPHONE RECORD STOP] SET ?audio
AFTER EMIT ?audio("path") & " (" & ?audio("duration") & " s)"
NEW SYNC CHANNEL SET ?ch
AFTER DIRECTIVE "Phone" ONDEVICE [MICROPHONE STREAM INTO "audio" EVERY 500 MILLISECONDS] INTO CHANNEL ?ch
AFTER EMIT ?ch("connect_url")
(* ...and when it is no longer wanted *)
AFTER DIRECTIVE "Phone" ONDEVICE [MICROPHONE STREAM STOP]
Each audio event carries seq, rate, channels (always 1), format (always pcm16), level (how loud that slice was, 0 to 100) and data: the samples, 16-bit little-endian, as base64. A page listening on the channel plays them one after another:
const ctx = new AudioContext(); let next = 0;
function play(ev) { // ev is one "audio" event
const raw = atob(ev.data), n = raw.length / 2;
const buf = ctx.createBuffer(1, n, ev.rate), out = buf.getChannelData(0);
for (let i = 0; i < n; i++) {
const v = raw.charCodeAt(i * 2) | raw.charCodeAt(i * 2 + 1) << 8;
out[i] = (v > 32767 ? v - 65536 : v) / 32768;
}
const src = ctx.createBufferSource(); src.buffer = buf; src.connect(ctx.destination);
next = Math.max(next, ctx.currentTime + 0.05); src.start(next); next += buf.duration;
}
STOP, when the client is stopped, or after two hours. For now MICROPHONE RECORD START and STOP, MICROPHONE STREAM and AUDIO PLAY run on Android; on a computer they answer null.Permission is the person’s
The OcaltQL Client can be sent any command, so it carries every permission the command language needs. Carrying a permission is not being granted it: on Android the first command that needs the camera, the microphone, location, contacts or the calendar raises the system’s own question on the phone, and the person may say no - in which case that command answers null, as it would in an app. On Windows and Linux the operating system’s own settings decide the same way. Every halting command has a PERMISSION form that asks without doing anything else.
GPS WATCH that keeps running while the phone is locked needs location allowed all the time, which Android only lets the person choose in Settings, never from a prompt. Until they do, a watch pauses when the screen goes off.WEBASSEMBLY on the Machine
DIRECTIVE WEBASSEMBLY, with SERVE, PROCESSES and STOP, is not available in the Mac client yet. Sent to a Mac, it returns an error that names it, which OR CATCH ERROR catches. See On a Mac.DIRECTIVE "id" WEBASSEMBLY runs code on a machine running the OcaltQL Client, in any of the languages WEBASSEMBLY runs on Ocalt, with the same statements, the same grants and the same answers. What changes is where it runs: on that machine, with that machine’s storage and that machine’s network.
STRING "Ocalt" SET ?name
AFTER DIRECTIVE "laptop" WEBASSEMBLY GRANT ?name AS "name"
AFTER DIRECTIVE "laptop" WEBASSEMBLY TYPE "python" ENTER `
import os, numpy as np
print("hello", oql['name'], "-", len(os.listdir("C:/Users")), "profiles,", np.arange(10).sum())
` SET ?r
AFTER EMIT ?r
Where each language runs
On Windows and Linux every language runs natively, from runtimes the client keeps beside itself. They come to a gigabyte or more, so the Windows installer downloads them during setup, and a runtime that is not there yet is fetched from Ocalt the first time a script needs it; that first run takes longer. On Android every language runs natively too. The client keeps builds made for the phone’s own ARM processor - Python, PHP, Node, Ruby, Perl, bash, Java, Rust, Go and wasm - and fetches each one the first time a script needs it, so that first run takes longer: from about 16 MB for Perl to about 200 MB for Go. After that a language starts as quickly as it does on a computer. Long-running processes are offered on Android as well: WEBASSEMBLY SERVE keeps a server running on the phone exactly as it does on any other machine. A language that has no build for a machine answers so, rather than failing silently.
The machine’s storage, the machine’s network
On Ocalt a sandbox sees only /root and /mounted. On a machine there is no /root and no /mounted: paths are the machine’s own - C:/, D:/, /var/, /storage/emulated/0/ - and the code can reach whatever the client’s operating-system user can. Its network is the machine’s network too. The namespace network does not apply, and 127.0.0.1 is that machine’s own loopback, so code can talk to a database or a service already running there.
DIRECTIVE "nas" WEBASSEMBLY TYPE "node" ENTER `
(async () => {
const r = await fetch("http://127.0.0.1:8080/health");
console.log(r.status, await r.text());
})();
` SET ?health
AFTER EMIT ?health
Every language, every machine
Each TYPE the server offers is offered on the machine, with the same library set: php, python (NumPy, pandas, SciPy, scikit-learn, PyTorch and the rest), node, ruby, perl, bash, java, rust, go and wasm, on Windows, Linux and Android alike. A grant reaches the code in the same form for each language - $oql['alias'], oql['alias'], oql.alias, OQL_alias - as the table on the WEBASSEMBLY page lists.
The runtimes come from Ocalt, as described above: once a language is on the machine, every later run starts at once, and the client keeps it up to date. TYPE "wasm" takes the path of a compiled module on the machine.
DIRECTIVE "Phone" WEBASSEMBLY TYPE "rust" ENTER `
fn main() { println!("{} cores", std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1)); }
` SET ?r
AFTER DIRECTIVE "Phone" WEBASSEMBLY TYPE "java" ENTER `
System.out.println(System.getProperty("os.arch"));
` SET ?j
AFTER EMIT ?r & " / " & ?j
A process that stays up
WEBASSEMBLY SERVE, PROCESSES and STOP work on a machine as they do on Ocalt: the process keeps running after the script returns, on the machine, listening on the machine. Pair it with TUNNEL to give it a public address. Its output is written to a log in the client’s own folder, and PROCESSES gives that log’s path, which DIRECTIVE READ fetches. Each process reports the same fields as on Ocalt, running, exited and exit_code included, plus log.
DIRECTIVE "nas" WEBASSEMBLY SERVE "api" TYPE "node" ENTER "/srv/app/server.js" ON 3000 SET ?p
AFTER DIRECTIVE "nas" TUNNEL PORT 3000 SET ?t
AFTER EMIT ?t("url")
(* later *)
AFTER DIRECTIVE "nas" WEBASSEMBLY PROCESSES SET ?procs
AFTER DIRECTIVE "nas" WEBASSEMBLY STOP "api"
WINDOW - A Window of Your Own on the Machine
WINDOW is not available in the Mac client yet. Sent to a Mac, it returns an error that names it, which OR CATCH ERROR catches. See On a Mac.WINDOW opens a window on the machine and shows the page you send it. The window has nothing of its own: no address bar, no menus, no tabs - only the operating system’s own minimise, maximise and close. Everything inside it is your page, so navigation, buttons and layout are whatever your HTML makes them. It is a different thing from REDIRECT, which opens a URL in the machine’s default browser; WINDOW is a window that belongs to your script.
DIRECTIVE "kiosk" WINDOW PAYLOAD `<html><body style="font:48px sans-serif">Welcome</body></html>` SET ?status
AFTER EMIT ?status
(* "ok" - or null if it could not be shown *)
AFTER DIRECTIVE "kiosk" WINDOW URL "https://example.com" SET ?status
PAYLOAD takes the page itself. URL takes an address - a website, http://localhost:3000 on that machine, or the path of a local file such as C:/kiosk/index.html. Sending again replaces what is showing: a machine has one WINDOW, and a script changes what is in it.
How it opens
| Modifier | The window |
|---|---|
RESIZE | A normal window: framed, centred, resizable, about 70% of the screen. SIZE WIDTH n HEIGHT n sets its size instead |
MAXIMIZED | Fills the screen, keeping the operating system’s frame and taskbar |
FULLSCREEN | Borderless, over everything including the taskbar - for a kiosk, a sign or a display wall |
| none | A window that is already open keeps the state it is in, so new content never makes it jump. One that is not yet open opens as RESIZE |
The person at the machine can still minimise, resize or close it; closing it closes the window and nothing else - the client keeps running, and the next WINDOW opens it again. On a phone the window is the client’s own full screen, and the three modifiers have nothing to change.
FILE READ "/root/kiosk/index.html" SET ?page
AFTER DIRECTIVE "lobby-screen" WINDOW PAYLOAD ?page FULLSCREEN SET ?status
BASE - where a payload’s files are
A page sent as a payload has no folder of its own, so a relative link in it - <img src="logo.png">, <script src="app.js"> - has nowhere to resolve. BASE names a folder on the machine for those links to resolve against.
DIRECTIVE "kiosk" WINDOW PAYLOAD ?page BASE "C:/kiosk/" MAXIMIZED SET ?status
(* logo.png in the page is C:/kiosk/logo.png *)
AFTER DIRECTIVE "kiosk" WINDOW CLOSE
What the page can do
The window is a full Chromium, the same engine everywhere: on Windows it is WebView2, which Windows already has; on Android it is the system’s own Chromium WebView; on Linux, whose built-in engine is WebKit, the OcaltQL Client carries its own Chromium inside it. Nothing is downloaded when WINDOW is first used. The client brings its own engine on Linux because WebKit lacks WebUSB, Web Serial, WebHID, Web Bluetooth and the File System Access API; with Chromium everywhere, a page that works in one window works in every window.
Every permission is granted. A page in the window gets the camera, the microphone, location, notifications, the clipboard, USB, serial and Bluetooth without a prompt, whether it came as a payload, a local file or a URL - there is no address bar from which anyone could send it somewhere else, so whatever is in it is what your script put there.
And it has onDevice. A page in a WINDOW can call onDevice.enter(...) exactly as an applicated app does - the same commands as ONDEVICE, including CAMERA VIEW INLINE drawn into the page - and reach https://ql.ocalt.com/api like any client. Script and page work together: the script decides what the machine shows, and the page is the machine’s interface for as long as it is showing.
DIRECTIVE "dock-3" WINDOW PAYLOAD `<html><body>
<div id="cam" style="width:100%;height:70vh"></div><p id="out">Scan a tag</p>
<script>
onDevice.enter('CAMERA VIEW INLINE INTO "#cam"');
var tag = onDevice.enter('NFC READ TIMEOUT 120');
document.getElementById("out").textContent = tag ? tag.id : "No tag read";
</script></body></html>` MAXIMIZED SET ?status
WINDOW answers "ok" when the page is showing and null when it could not be shown - a machine with no desktop session, as with SCREENSHOT, is the usual reason.
When Things Fail
Two conditions stop a script outright, because the script named something that cannot work: addressing a machine id that holds no slot, and calling DIRECTIVE REGISTER when every slot is in use. Both raise a fatal error naming the id and, for slot saturation, how long until a slot can be released.
Everything else is reported rather than fatal. A blocking command against an agent that is offline or stops responding waits until the command's ceiling of 300 seconds and then returns a timeout - the row stays on the hub, so if that agent reconnects later it still receives the work. A command the agent could not carry out is reported both ways at once: the variable you SET receives the machine’s answer, with ok false and an error describing why, which you can branch on, and the same failure is raised as an error that OR CATCH ERROR catches. Use DIRECTIVE STATUS "id" before a long run if you would rather check that a machine is online first.
A tunnel is torn down if its agent stops reconnecting, and closing one revokes it centrally: the URL stops working immediately, whatever state the machine is in.
Rules
| Rule | Detail |
|---|---|
| Nesting | OcaltQL is nestable everywhere; only operations are not nestable within each other. A DIRECTIVE can sit inside a block, an operation or another statement like any other verb |
| Machine ID | Must be a registered slot. A command for a machine that is offline waits in its queue until the machine checks in, or until its TTL passes; WAKE reaches an offline machine through an online relay |
| Filesystem | DIRECTIVE READ/WRITE, SERVE FOLDER, ONDEVICE DRIVE and DIRECTIVE WEBASSEMBLY resolve paths on the remote machine's filesystem - there is no /root or /mounted on a machine |
| Credentials | The agent uses the same Ocalt credentials as the namespace that registered it |
| TTL | Optional, seconds only, 1 to 3600. Bounds how long a command may wait to be taken, never how long it may run; once taken it runs to completion |
| Machine slots | 4,096 on every plan - a slot can be released 24 hours after it is claimed, and a released slot is reusable at once |
The Machine's Location
Every registered machine reports its location as lat and lon, with accuracy in metres and source saying where the fix came from.
sourceis"device"when the machine has a location service of its own (GPS on a phone, the operating system’s location service on a laptop or desktop) and its owner has allowed the OcaltQL Client to use it on that machine. The Client asks once, on the machine itself; the answer belongs to whoever uses that device.sourceis"ip"otherwise: the coordinates are resolved from the public address the machine checks in from, the same city-level accuracy a web server infers from an IP, andaccuracyisnull.
All four are null until the machine has checked in since the hub last started, and for an address the location database does not cover.
DIRECTIVE STATUS "home-nas" SET ?s
AFTER EMIT ?s("lat") & ", " & ?s("lon")
AFTER DIRECTIVE LIST SET ?machines
AFTER FOREACH ?machines("agents") SET ?m
OPEN
EMIT ?m("machine_id") & ": " & ?m("lat") & "," & ?m("lon") & " (" & ?m("source") & ")"
CLOSE
"ip" come from the machine’s public address, so a machine behind a VPN reports the VPN’s location, and one with no internet route reports nothing. A "device" fix is where the device is. For a precise fix from a person’s device, use USER DEVICE in a script they load - that asks the browser, and the visitor consents.A Local Server on the Machine
The agent can serve the machine’s root folder as a website on a port of its own. Static files come straight off local disk; an .oql file executes on Ocalt with the visitor’s request forwarded, exactly as Site Mode does. The same script behaves identically on a subdomain and on the machine.
localhost:12345/config, alongside the root folder. Any free port works - including 80 - except 12345, which the agent’s own interface uses. Blank or 0 turns it off.DIRECTIVE "home-nas" TUNNEL PORT 80 SET ?t.Using it as a development server
This is how you build a site without deploying anything. Point the agent’s root at the folder you are working in, give it a port, and open it in a browser - you are editing files on your own machine while real OcaltQL runs against your real namespace.
(* 1. Open the agent's own manager on the machine *)
http://localhost:12345/config
(* 2. Set two fields:
Root /home/you/projects/myshop
Local port 8080 *)
(* 3. Write a script in that folder *)
/home/you/projects/myshop/index.oql
(* 4. Open it *)
http://localhost:8080/
No build step, no upload, no restart. The agent reads the file off disk on every request, so a refresh always shows what you last saved.
How a URL becomes a file
| You open | It serves |
|---|---|
/ | index.oql in the root folder |
/orders | orders.oql - an extensionless path falls back to .oql |
/shop/ | shop/index.oql - a folder serves its index |
/style.css | The file itself, straight off local disk |
/video.mp4 | The file, with byte ranges - so seeking in a player works |
That is the same routing Site Mode uses on a subdomain, which is the point: a script that works here works there unchanged, because it is the same script running in the same place. Only the thing that fetched it differs.
What reaches your script
The agent forwards the visitor’s method, query string, body and cookies along with the script, so !GET, !POST, !REQUEST, !COOKIE and START SESSION behave exactly as they will in production. A form you test on localhost posts to the same code that will receive it live.
(* index.oql *)
IF !REQUEST("method") IS IDENTICAL TO "POST"
OPEN
EMIT "You sent: " & !POST("message")
CLOSE
OR
OPEN
EMIT `<form method="post">
<input name="message">
<button>Send</button>
</form>`
CLOSE
.. is rejected before it is looked at. Port 12345 cannot be used - that is the agent’s own manager.Agent Setup
Install the oql-client application on the machine you want to reach. On first run it opens its own local manager at http://localhost:12345, where you enter your Ocalt credentials, a machine alias (the id you target in DIRECTIVE), and a local root folder, which is what Site Mode serves. The agent stores that config and connects outbound on its own - no inbound port forwarding, and nothing to open on your router.
The manager also shows a live activity log of every command the machine has run, and the agent can be set to start automatically at logon. Once configured, the machine is addressable from any OcaltQL script using its alias.
On a Mac the client is a Node.js app: install Node.js first, then follow the macOS steps. What it supports is listed under On a Mac at the top of this page.
Full Verb Reference
| Verb | Description |
|---|---|
DIRECTIVE "id" EXEC "cmd" SET ?r | Run a shell command, blocking |
DIRECTIVE "id" EXEC "cmd" BACKGROUND SET ?pid | Run a shell command, non-blocking |
DIRECTIVE "id" KILL ?pid | Terminate a background process by its operating-system pid - the whole process group is signalled, so child processes die with it |
DIRECTIVE "id" DOWNLOAD "remote" TO "local" SET ?h | Transfer a file from the remote machine |
DIRECTIVE "id" UPLOAD "local" TO "remote" SET ?h | Transfer a file to the remote machine |
<call> SET PROMISE ?job | Run a blocking directive call, such as EXEC, in the background - ?job is WAITING, collect with WAIT FOR. DOWNLOAD and UPLOAD never block and need no promise |
DIRECTIVE "id" <action> TTL n SECONDS | Drop the command if the machine has not taken it within n seconds - 1 to 3600, seconds only. Without it a queued command waits indefinitely. See TTL |
DIRECTIVE "id" WAKE "MAC" | An online agent broadcasts a Wake-on-LAN packet on its LAN for the given MAC |
DIRECTIVE "id" TUNNEL PORT n SET ?tunnel | Expose a local port publicly, no port forwarding needed |
DIRECTIVE TUNNEL END ?tunnel | Close an active tunnel |
DIRECTIVE REGISTER "id" SET ?reg | Claim a machine slot - fatal if every slot is in use |
DIRECTIVE UNREGISTER "id" SET ?rel | Release a slot, permitted once it is 24 hours old |
DIRECTIVE "id" SERVE "path" SET ?src | Serve one file straight off the machine - returns a public url plus the local port |
DIRECTIVE "id" SERVE FOLDER "path" [LISTING] SET ?src | Serve a whole folder as it is, browsable - ?src("url") is the folder, ?src("url") & "/file" anything inside it |
DIRECTIVE SERVE END ?src | End a served file or folder; its URL stops answering at once |
DIRECTIVE "id" ONDEVICE [command] [BIND [...]] [INTO CHANNEL ?ch] SET ?r | Run a device command on the machine - camera, GPS, Bluetooth, NFC, sensors, storage, notifications - with the answers an Applicate app gets |
DIRECTIVE "id" WEBASSEMBLY GRANT ?var AS "alias" | Expose a variable to the next code run on the machine |
DIRECTIVE "id" WEBASSEMBLY TYPE "lang" ENTER `code` SET ?r | Run code on the machine in any WEBASSEMBLY language, with its storage and its loopback |
DIRECTIVE "id" WEBASSEMBLY SERVE "name" TYPE "lang" ENTER "path" ON port SET ?p | Start a process on the machine that keeps running |
DIRECTIVE "id" WEBASSEMBLY PROCESSES SET ?p / WEBASSEMBLY STOP "name" | List and stop processes started on the machine |
DIRECTIVE "id" WINDOW PAYLOAD `html` | URL "url" [BASE "folder"] [RESIZE [SIZE WIDTH n HEIGHT n] | MAXIMIZED | FULLSCREEN] SET ?status | Show a page in the machine’s own window - "ok" or null |
DIRECTIVE "id" WINDOW CLOSE | Close the window |
DIRECTIVE "id" SCREEN SET ?s | Display geometry per monitor - ?s(0)("width"), ("height"), ("x"), ("y"), ("primary") |
DIRECTIVE "id" SCREENSHOT [ON DISPLAY n | "all"] SET ?path | Capture a display to a timestamped PNG in your namespace |
DIRECTIVE "id" VIEW [ON DISPLAY n] [FPS n] [AS MJPEG] SET ?feed | Open a live feed of a display, returning its URL |
DIRECTIVE "id" REDIRECT "url" | Open a URL in that machine's own default browser |
DIRECTIVE "id" POLL n SECONDS|MINUTES | Check-in interval for one machine - 0 SECONDS (the fastest), or 1 SECOND to 60 MINUTES, default 1 SECOND |
DIRECTIVE PEERS "id" AND "id" SET ?network | Group registered machines into one peer network value |
DIRECTIVE LOCAL PEERS "id" AND "id" SET ?network | Group machines on one local network; every transfer and share that uses it stays on that network or fails |
DIRECTIVE NETWORK ?network TRANSFER FROM "id://path" TO "id://path" SET ?anchor | Move a file directly between two peers - non-blocking, returns a status anchor |
DIRECTIVE NETWORK ?network SHARE "id" PORT n AS n SET ?status | Expose one peer’s port on every other peer’s localhost |
DIRECTIVE STATUS ?anchor SET ?progress | Read a peer transfer's progress - buffering, in progress, done or failed, with bytes, total and percent |
DIRECTIVE "id" LIST FROM "C:/" SET ?items | List a folder on the machine - name, is_dir, size, modified |
DIRECTIVE "id" LIST DRIVES SET ?drives | List the machine's drives as an array of paths: its mounted filesystems on Linux, drive roots such as C:\ on Windows |
DIRECTIVE LIST SET ?a | Registered machines plus slot accounting: ?a("agents"), each with machine_id, online, last_seen, seconds_since_seen, lat, lon, accuracy and source; ?a("used"), ?a("slots") |
DIRECTIVE STATUS "id" SET ?status | A specific agent's liveness and location: online, last_seen, seconds_since_seen, lat, lon, accuracy, source |
DIRECTIVE "id" READ "path" SET ?r | Read a file at the machine’s own path - returns data and bytes |
DIRECTIVE "id" WRITE "path" CONTENT "..." | Write a file at the machine’s own path, creating its folders |
DIRECTIVE "id" MOUSE "[Token]" | Button, scroll or relative move, e.g. "[MouseDown]+[Down]" |
DIRECTIVE "id" KEYBOARD "[Key]+[Key]" | Send a key or chord, e.g. "[Control]+[c]" |
DIRECTIVE "id" POINTER X n Y n | Move the pointer to absolute coordinates |
DIRECTIVE "id" POINTER COORDINATES SET ?c | Read current pointer position - ?c("x"), ?c("y") |