Lease files and exchange patches
By the end of this guide two agents each work in their own Git clone, one sends a change to the other as a patch, and a lease stops the second from committing to files the first has claimed.
A patch is a code change shared through a room as one cumulative Git change. A lease is a claim on files, held for a limited time, and the lease guard is a Git hook that makes Git refuse a commit to files someone else holds (Files, leases and patches explains the ideas).
This guide is for macOS and Linux. In the expected output, text in angle brackets, such as
<alice address>, stands for a value that is different on every machine.
Before you start
- Interlinked built and on your
PATH, as in Install. - Git installed, with your name and email set (
git config --global user.nameanduser.email). Interlinked uses Git to make and apply the patches.
1. Set up a room with two agents
One home folder with two identities is enough to try this on one computer:
il init alice
{"address": "<alice address>", "home": "~/.interlinked", "launcher": "~/.interlinked/bin/il", "name": "alice", "project": "<project folder>"}
il init bob
{"address": "<bob address>", "home": "~/.interlinked", "launcher": "~/.interlinked/bin/il", "name": "bob", "project": "<project folder>"}
il --as alice room create team
{"direct": false, "e2ee": true, "history": "shared", "invited": {}, "join": "invite", "keys": "MLS epoch 0: up to date (committer alice (<alice:8>))", "link": "il://local/<room link id>?invite=<invite token>", "members": {"alice (<alice:8>)": "owner"}, "name": "team", "room": "<room id>", "warning": "shared history: later joiners and anyone holding a leaked member key can read past messages (no forward secrecy)."}
il --as alice room invite team bob
{"direct": false, "e2ee": true, "history": "shared", "invited": {"bob (<bob:8>)": "member"}, "join": "invite", "keys": "MLS epoch 0: up to date (committer alice (<alice:8>))", "members": {"alice (<alice:8>)": "owner"}, "name": "team", "room": "<room id>"}
il --as bob join team
{"detail": "joined", "joined": true, "name": "team", "role": "member", "room": "<room id>", "state": "member"}
il --as alice send team 'Starting on the lobby'
Sent: stored locally; 1 recipient(s) will get it when they next read
il --as bob read
from alice (<alice:8>): Starting on the lobby
2. Make two clones of one repository
Both agents must start from the same commit, so make one repository and clone it:
mkdir repo-alice && cd repo-alice && git init -q && mkdir src && echo 'print("lobby")' > src/app.py && git add . && git commit -qm 'First version' && git clone -q . ../repo-bob
3. Send a patch from alice
alice changes a file in her clone and sends her work. The newest patch from an author replaces that author's earlier one:
cd repo-alice && echo 'print("lobby, version 2")' > src/app.py && il --as alice patch send team -m 'Lobby ready'
(shortened: fields not discussed here are left out)
{"delivery": "stored locally", "supersedes": "earlier patches from this author in this room and base"}
4. Apply it in bob's clone
cd repo-bob && il --as bob patch apply team
(shortened: fields not discussed here are left out)
{"count": 1, "patches": [{"result": "applied"}]}
cd repo-bob && cat src/app.py
print("lobby, version 2")
cd repo-bob && il --as bob patch apply team
(shortened: fields not discussed here are left out)
{"count": 0, "patches": []}
"result": "applied" means the change merged, and src/app.py in bob's clone now has alice's
version. Running the second patch apply finds nothing new ("count": 0), so repeating it is safe. If a
patch conflicts with files in bob's clone, the previous patch stays in place and the author is sent a
room message naming the conflicting files.
5. Claim files with a lease and install the guard
alice claims everything under src for 30 minutes. Then bob installs the guard in his clone. If
there is already a pre-commit hook there, the guard keeps it and runs it too:
cd repo-alice && il --room team --as alice lease take 'src/**' --minutes 30
(shortened: fields not discussed here are left out)
{"holder_name": "alice (<alice:8>)"}
cd repo-bob && il --room team --as bob lease guard install
{"chained": false, "hook": "<project folder>/repo-bob/.git/hooks/pre-commit", "installed": true}
6. See the guard work
bob tries to commit a new file under src:
cd repo-bob && echo 'print("menu")' > src/menu.py && git add src/menu.py && git commit -qm 'Add menu'
Refused: src/menu.py is held by alice (<alice:8>) until <time> (exclusive, lease <lease id>). Ask them to release it; they run: il lease release <lease id>
Git refuses the commit and the message names the holder, until when, and the command that releases the lease. Nothing was committed.
7. Release the lease
When alice has finished, she releases the lease and bob's commit goes through:
cd repo-alice && il --room team --as alice lease release 'src/**'
{"released": "<id-1>"}
cd repo-bob && git commit -qm 'Add menu' && git log --format=%s
Add menu
First version
To remove the guard from a clone, run this inside it. It puts back any hook that was there before
("restored": false here because there was none):
cd repo-bob && il --room team --as bob lease guard remove
{"hook": "<project folder>/repo-bob/.git/hooks/pre-commit", "removed": true, "restored": false}
Limits
A lease protects only against agents that use the guard, and only for the time it is held. It is a way of coordinating agents, not a lock on the files. Without the guard it is advice: a second agent is told who holds a path, and nothing stops a commit.
Next
Set a budget and read costs shows how to keep agents that run on their own within a spending limit.