Branches and forks
Every disk starts with a main branch. A fork is an instant copy that shares the data.
A branch is a line of commits on a disk. Every disk starts with main. Fork a branch when you want to change it without touching the original, for example to give an agent its own copy of main.
import { Skywake } from "skywake";
const sky = new Skywake();
const app = sky.disk("app");
await app.write("src/auth.ts", "export const timeout = 30;\n");
const work = await app.fork("agent-1");
await work.write("src/auth.ts", "export const timeout = 60;\n");
console.log("main: ", await app.read("src/auth.ts"));
console.log("agent-1:", await work.read("src/auth.ts"));
console.log((await app.branches()).map((branch) => branch.name));
await work.destroy();Forks
fork(name) makes a new branch from the one the handle is on and returns a handle to it. In the CLI, skywake fork app agent-1 forks main, and --from picks another branch. To use a branch that already exists, ask for it by name: sky.disk("app", { branch: "agent-1" }) in TypeScript, sky.disk("app", branch="agent-1") in Python, or app@agent-1 in the CLI.
A fork copies a pointer, never the data, so it takes the same time however much the branch holds. From then on each branch sees only its own commits, and the files both share are stored once.
To fork an older commit instead of the newest, pass at: app.fork("audit", { at: commit }) in TypeScript or app.fork("audit", at=commit) in Python.
Listing branches
app.branches() (CLI: skywake branches app) lists every branch with its name, the branch it was forked from, and when it was created. work.head() returns a branch's newest commit.
Undo
You can undo work on a branch in two ways. Revert undoes one commit. Restore makes the branch look like it did at an earlier commit. Both add a new commit on top, so the history is kept.
Two writers on one branch
Moving a branch's head is a conditional write. When two writers start from the same head at the same time, one wins and the other gets a Conflict error. To avoid this, give each agent its own fork. Then they never wait for each other.
Destroying a branch
work.destroy() (CLI: skywake destroy app@agent-1) deletes the branch. destroy on main deletes the whole disk. The CLI asks first; pass --yes to skip the question.
A destroyed branch's data stays in the bucket until garbage collection removes it. On a store you run yourself, run gc with --local:
skywake gc --local=s3://my-bucket --dry-run
skywake gc --local=s3://my-bucket| Flag | Default | Meaning |
|---|---|---|
--grace-minutes | 11520 (8 days) | Only data older than this is deleted, so saves that are still in progress are safe. Under 2 days is unsafe while anyone writes. |
--dry-run | off | Only count. Delete nothing. |
gc needs delete rights on the whole store.
With no server
--local[=DIR] (or SKYWAKE_STORE) runs fork, merge, branches, log, diff, destroy NAME@BRANCH, upload and download against a bucket or folder directly, with no API. The store is one disk, so only the branch in NAME@BRANCH is used. When skywaked is running and no store is named, these commands go through the daemon and act on its store, as far as its access file allows. See mount.