starfold

TypeScript

The headless client for Node, Bun and Deno, and starting a server from code.

starfold is a client for agents and scripts driving a starfold desktop: screenshots, waiting for the screen, mouse and keyboard, recordings and files. Node 20+, Bun and Deno; no dependencies.

npm install starfold
bun add starfold
pip install starfold
uv add starfold

Driving a desktop

import { Starfold, act } from 'starfold';

// password defaults to $STARFOLD_PASSWORD
const sf = new Starfold('http://localhost:6901', { password: '...' });

const shot = await sf.screenshot(); // shot.png (Uint8Array), shot.seq, shot.size
await shot.save('before.png');

await sf.click(400, 300);
const r = await sf.typeText('hello\n');
await sf.wait({ change: true, since: r.seq }); // once the typing changed the screen
await sf.wait({ idleMs: 300 }); // and once it settled

await sf.key('ctrl+shift+t');
await sf.scroll(0, 3, 400, 300);
await sf.drag(100, 100, 400, 100);
await sf.actions([
	act.key('ctrl+l'),
	act.typeText('example.com'),
	act.key('Enter'),
]);

const clips = await sf.record(5); // MP4s: one, or more if the encoder changed mid-recording
await sf.filesUpload('data.csv', 'local/data.csv');
console.log((await sf.filesList()).entries.map((e) => e.name));

The methods are the Python client's in camelCase, each returning a Promise. wait() takes its options as an object (idleMs, timeoutMs, change, region, since). timeoutMs in the constructor (default 30000) applies per request; waits and recordings get their own length on top. filesUpload() takes bytes, a Blob or a local file's path.

Keys for key() follow the input actions.

Errors

AuthError (wrong or missing password), ReadOnlyError (the server runs with --read-only), RecordingOffError (without --enable-recording), ForbiddenError, NotFoundError, StarfoldTimeoutError and StarfoldConnectionError are all StarfoldError, with message and status. wait() reports a timeout in its result (timedOut) rather than throwing.

Starting a server from code

@starfold/server has the server: the starfold command and startServer(), which starts one on this machine and gives you a client already signed in to it. It depends on starfold.

npm install @starfold/servernpx starfold --version
pip install starfold-serverstarfold --version
cargo install --locked starfoldstarfold --version
import { startServer } from '@starfold/server';

await using server = await startServer(); // loopback, a free port, a generated password
const sf = server.client(); // a Starfold, signed in already
await (await sf.screenshot()).save('desktop.png');

startServer() listens on 127.0.0.1 unless you pass addr. port (default: a free one), password (default: a generated one), args (more server flags), env, binary and timeoutMs (until it answers, default 30000) are optional. It resolves to a LocalServer with url, password, process, client(), output() and close(). The server stops on close(), at the end of an await using block, and when your process exits.

If the server exits, doesn't answer in time or finds its port taken, startServer() throws a ServerStartError whose output is what the server printed. On Linux it needs a display (DISPLAY, for example from Xvfb); it doesn't start one, and it needs the libraries under Install the server: without them it throws a MissingLibrariesError that names what is missing.

binaryPath() is the binary: $STARFOLD_BIN if set, else the platform package's; without one it throws a BinaryNotFoundError.

Upgrading from 0.3.2

Up to 0.3.2, starfold also carried the server. From 0.4.0:

0.3.20.4.0
import { startServer } from 'starfold', and likewise LocalServer, StartServerOptions, binaryPath, checkLibraries, missingLibraries, platformKey, serverPackage, LINUX_LIBRARIES_HINT, BinaryNotFoundError, MissingLibrariesError, ServerStartErrorthe same names from '@starfold/server'
npx starfold / npm i -g starfoldnpx @starfold/server / npm i -g @starfold/server
Starfold, act, StarfoldError and the client's other errors, the typesunchanged, from starfold

A named import of a moved name from starfold fails at link time and in tsc. Staying on starfold@0.3.2 changes nothing: it still carries the server.

On this page