Every function that reads or writes your program's files takes a Places: your program's name, its state folder and its config folder.
import { envName, placePaths, standardPlaces } from "fleethosts/places";
const places = standardPlaces("mytool");
// { program: "mytool", state: "/home/me/.local/state/mytool", config: "/home/me/.config/mytool" }
placePaths(places).hosts(); // "/home/me/.local/state/mytool/hosts.json"
envName(places, "SSH"); // "MYTOOL_SSH"standardPlaces is also exported from fleethosts.
The fields
Section titled "The fields"| Field | What it is |
|---|---|
program | The name your program writes under. It names environment variables and temporary folders. |
state | Per-machine state: caches, locks, logs, and the recorded fleet. |
config | Per-user config, where config.json lives. |
formerProgram | Optional. A name the program had before. fleethosts doesn't read it. |
legacyHookMark | Optional. A hook ownership key to keep from an earlier version. fleethosts doesn't read it. |
A Places is a plain object, so tests can build one with folders in a temporary directory.
Where the folders go
Section titled "Where the folders go"standardPlaces(program) follows the XDG base directory spec, and the platform's convention where it is unset:
| Folder | First match |
|---|---|
| config | $XDG_CONFIG_HOME/<program>, then %APPDATA%\<program> on Windows, then ~/.config/<program> |
| state | $XDG_STATE_HOME/<program>, then %LOCALAPPDATA%\<program> on Windows, then ~/.local/state/<program> |
A relative XDG_* path is ignored, as the spec says. The object comes back frozen.
An installed copy
Section titled "An installed copy"A program that installs itself as <state>/app/cli.mjs can pass that folder as the second argument:
import { installedStateDir, standardPlaces } from "fleethosts/places";
const places = standardPlaces("mytool", installedStateDir());installedStateDir() returns the state folder when the running script is <folder>/app/cli.mjs, and undefined otherwise. XDG_STATE_HOME still wins over it. On Windows, an existing state.json in %LOCALAPPDATA%\<program> keeps that folder; the choice stays fixed for the process.
Environment variables
Section titled "Environment variables"envName(places, name) gives <PROGRAM>_<name>, upper case, with any character outside A-Z and 0-9 turned into _. fleethosts reads two:
| Variable | What it changes |
|---|---|
<PROGRAM>_SSH | The ssh to run instead of ssh |
<PROGRAM>_TAILSCALE | The Tailscale CLI to run instead of tailscale |
A value ending in .js or .mjs runs with the current Node, which is how the tests stand in a fake ssh. For desk+tools, the variable is DESK_TOOLS_SSH.
File paths
Section titled "File paths"placePaths(places) returns functions that build file paths in the folders. It also takes a function that returns the places, read on every call.
fleethosts itself writes one of them: hosts(), the fleet recordHosts keeps. The others name files a program built on fleethosts keeps, such as config(), state(), lock(), cache() and logs(). See the API reference for the full list.