agentlanes-cli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentlanes_cli-0.1.0/LICENSE +202 -0
- agentlanes_cli-0.1.0/PKG-INFO +323 -0
- agentlanes_cli-0.1.0/README.md +305 -0
- agentlanes_cli-0.1.0/pyproject.toml +30 -0
- agentlanes_cli-0.1.0/setup.cfg +4 -0
- agentlanes_cli-0.1.0/src/agentlanes/__init__.py +10 -0
- agentlanes_cli-0.1.0/src/agentlanes/__main__.py +3 -0
- agentlanes_cli-0.1.0/src/agentlanes/claims.py +215 -0
- agentlanes_cli-0.1.0/src/agentlanes/cli.py +323 -0
- agentlanes_cli-0.1.0/src/agentlanes/core.py +184 -0
- agentlanes_cli-0.1.0/src/agentlanes/hook.py +166 -0
- agentlanes_cli-0.1.0/src/agentlanes/jobs.py +126 -0
- agentlanes_cli-0.1.0/src/agentlanes/landlock.py +257 -0
- agentlanes_cli-0.1.0/src/agentlanes/onboard.py +364 -0
- agentlanes_cli-0.1.0/src/agentlanes/procs.py +255 -0
- agentlanes_cli-0.1.0/src/agentlanes/run.py +201 -0
- agentlanes_cli-0.1.0/src/agentlanes/slots.py +253 -0
- agentlanes_cli-0.1.0/src/agentlanes_cli.egg-info/PKG-INFO +323 -0
- agentlanes_cli-0.1.0/src/agentlanes_cli.egg-info/SOURCES.txt +24 -0
- agentlanes_cli-0.1.0/src/agentlanes_cli.egg-info/dependency_links.txt +1 -0
- agentlanes_cli-0.1.0/src/agentlanes_cli.egg-info/entry_points.txt +2 -0
- agentlanes_cli-0.1.0/src/agentlanes_cli.egg-info/top_level.txt +1 -0
- agentlanes_cli-0.1.0/tests/test_agentlanes.py +333 -0
- agentlanes_cli-0.1.0/tests/test_onboard.py +235 -0
- agentlanes_cli-0.1.0/tests/test_portability.py +170 -0
- agentlanes_cli-0.1.0/tests/test_run.py +271 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentlanes-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Claims, slots, an event log and a job queue for several AI coding agents sharing one machine
|
|
5
|
+
Author: Metastaz
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/metastazorg/agentlanes
|
|
8
|
+
Project-URL: Issues, https://github.com/metastazorg/agentlanes/issues
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Operating System :: MacOS
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Software Development
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# agentlanes
|
|
20
|
+
|
|
21
|
+
<p align="center"><img src="https://raw.githubusercontent.com/metastazorg/agentlanes/main/docs/demo.svg" width="800" alt="agentlanes demo: three agents share one file and one build slot, then a real Claude Code session is stopped by Landlock"></p>
|
|
22
|
+
|
|
23
|
+
<sub>A recorded run of <code>./demo.sh</code> (real timing), then a replay of a <a href="examples/landlock/real-session.txt">real Claude Code session</a> under <code>agentlanes run</code>. Regenerate with <code>tools/make_demo_svg.py</code>; video: <a href="docs/demo.mp4">docs/demo.mp4</a>.</sub>
|
|
24
|
+
|
|
25
|
+
Coordination for several AI coding agents (Claude Code, Codex, Cursor, Aider, ...) working on one Linux or macOS machine.
|
|
26
|
+
|
|
27
|
+
## The problem
|
|
28
|
+
|
|
29
|
+
- Two agents edit the same file at the same time and one silently overwrites the other.
|
|
30
|
+
- Two agents start a full build or test suite at once and the machine runs out of memory.
|
|
31
|
+
- Nobody, human or agent, can see who is working on what, or tell when another agent has finished.
|
|
32
|
+
|
|
33
|
+
agentlanes gives agents four small primitives for this: **claims** (leases on topics and paths), **slots** (an N-slot queue
|
|
34
|
+
for heavy commands), an **event log** that agents can block on, and a **job queue**. It is one Python package,
|
|
35
|
+
standard library only, no daemon. State is a directory of JSON files guarded by `flock`.
|
|
36
|
+
|
|
37
|
+
## 60-second quickstart
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
pip install agentlanes-cli # Python >= 3.9, no dependencies; the command is `agentlanes`
|
|
41
|
+
cd your-project
|
|
42
|
+
agentlanes init --claude-code --agents-md
|
|
43
|
+
agentlanes doctor # every line should say ok/info; anything else comes with a fix
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`init` is safe to run again. It creates `.agentlanes/` (this project's state, git-ignored by a `.gitignore` inside it),
|
|
47
|
+
merges a `PreToolUse` hook into `.claude/settings.json` without touching your other settings or hooks (the previous file
|
|
48
|
+
is kept as `settings.json.agentlanes-backup-<time>`), and appends the agent instructions to `AGENTS.md` once, between
|
|
49
|
+
`<!-- agentlanes:begin/end -->` markers. Other targets: `--claude-md`, `--cursor` (`.cursor/rules/agentlanes.mdc`),
|
|
50
|
+
`--strict` (see [Fail-open or fail-closed](#fail-open-or-fail-closed)).
|
|
51
|
+
|
|
52
|
+
From then on your agents (and you) work like this:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
agentlanes claim login-page --paths src/login.py --pid self --desc "add OAuth button"
|
|
56
|
+
agentlanes who src/login.py # -> HELD by claude-4242 (login-page, since 14:02:11) ...
|
|
57
|
+
agentlanes slot heavy 1 -- make -j8 # waits its turn if another agent is already building
|
|
58
|
+
agentlanes release login-page
|
|
59
|
+
agentlanes status # agents, claims, slots, jobs, recent events on one screen
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
In Claude Code the hook refuses an edit to a path another agent has claimed, even if the agent forgot to check
|
|
63
|
+
([a real session](https://github.com/metastazorg/agentlanes/blob/main/examples/claude-code/real-session.txt)). Run `./demo.sh` to see three agents compete for one file and
|
|
64
|
+
one build slot (transcript: [demo-output.txt](demo-output.txt)); on Linux with Landlock it ends with a kernel-lane step.
|
|
65
|
+
|
|
66
|
+
On Linux, start an agent under `agentlanes run` and the kernel itself refuses writes outside its claimed paths, including
|
|
67
|
+
writes made through shell commands that no hook sees ([a real Claude Code session](https://github.com/metastazorg/agentlanes/blob/main/examples/landlock/real-session.txt)):
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
agentlanes claim login-page --paths src/auth/ --desc "add OAuth button"
|
|
71
|
+
agentlanes run --allow-tmp --allow-common -- claude # writes only in src/auth/, its temp dir, its own config
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Commands
|
|
75
|
+
|
|
76
|
+
### Claims
|
|
77
|
+
|
|
78
|
+
| Command | What it does |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `claim TOPIC [--paths a,b] [--pid self\|PID] [--desc T] [--ttl MIN] [--share]` | Take a named claim. Fails (exit 1) if another agent holds `TOPIC` or any overlapping path. A directory claim covers everything under it. `--share` allows overlap on purpose. |
|
|
81
|
+
| `release TOPIC` | Drop your claim. `--force` drops someone else's. |
|
|
82
|
+
| `renew TOPIC [--ttl MIN]` | Extend your claim. |
|
|
83
|
+
| `who PATH...` | Which claim covers these paths (exit 1 if any). |
|
|
84
|
+
| `check TOPIC` / `list [--json]` / `reap` | Is a topic held; list live claims; drop dead and expired ones now. |
|
|
85
|
+
|
|
86
|
+
Every claim expires after `--ttl` minutes (default 120). With `--pid`, the claim is a **lease**: it ends as soon as that
|
|
87
|
+
process exits, including on `kill -9` or an OOM kill. `--pid self` means the coding-agent process this command runs
|
|
88
|
+
under (found by walking up the process tree to a known agent executable: `claude`, `codex`, `cursor-agent`, `aider`,
|
|
89
|
+
`gemini`, ...; add names with `AGENTLANES_AGENT_NAMES=a,b`). A recycled pid is detected by process start time.
|
|
90
|
+
|
|
91
|
+
Who you are (`--by`) defaults to `$AGENTLANES_AGENT`, else `<agent>-<pid>` of the enclosing agent, else `$USER`.
|
|
92
|
+
|
|
93
|
+
### Slots
|
|
94
|
+
|
|
95
|
+
`agentlanes slot NAME N [--wait SEC] [--mem-free MB] [--max-mem MB] -- COMMAND...`
|
|
96
|
+
|
|
97
|
+
Runs `COMMAND` once one of `N` slots named `NAME` is free. Waiters are served in arrival order (FIFO); a waiter that dies
|
|
98
|
+
leaves the queue. The slot is a `flock` that `COMMAND` inherits, so it stays taken while `COMMAND` runs and the kernel frees
|
|
99
|
+
it when `COMMAND` dies, even if everything was SIGKILLed. A leftover holder record is shown as stale and cleaned.
|
|
100
|
+
|
|
101
|
+
- `--wait SEC`: give up after SEC seconds (default 1800) with exit code 75.
|
|
102
|
+
- `--mem-free MB`: after getting the slot, wait until this much memory is available.
|
|
103
|
+
- `--max-mem MB`: kill `COMMAND` above this size. Uses a systemd user scope (`MemoryMax`) when one is available,
|
|
104
|
+
otherwise a watchdog that sums the RSS of the process tree every second and kills the group.
|
|
105
|
+
- `COMMAND` gets `AGENTLANES_SLOT=<slot number>` in its environment. Exit code is `COMMAND`'s.
|
|
106
|
+
|
|
107
|
+
`agentlanes slots [NAME] [--json]` shows holders, stale holders and waiters.
|
|
108
|
+
|
|
109
|
+
### Events
|
|
110
|
+
|
|
111
|
+
| Command | What it does |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `events emit KIND [--topic T] [--msg TEXT] [key=value...]` | Append an event. Use dotted lower-case kinds, e.g. `build.done`. |
|
|
114
|
+
| `events tail [-n N] [--kind PREFIX] [--since 2h] [-f] [--json]` | Show recent events; `-f` follows. |
|
|
115
|
+
| `events wait --kind PREFIX [--topic T] [--by W] [--timeout SEC]` | Block until a *new* matching event; exit 124 on timeout. Use this instead of sleep loops. |
|
|
116
|
+
| `events stats [--since 24h]` | Counts per kind and per agent. |
|
|
117
|
+
|
|
118
|
+
agentlanes itself writes `claim.add/renew/done/conflict/expire/reap/blocked`, `slot.acquire/release/timeout/stale/oom/mem_wait`
|
|
119
|
+
and `job.add/take/done/drop/requeue`. The log is append-only JSON lines and rotates at 4 MB (`AGENTLANES_EVENTS_MAX_BYTES`).
|
|
120
|
+
|
|
121
|
+
### Jobs
|
|
122
|
+
|
|
123
|
+
`jobs add TITLE [--prio N]`, `jobs list [--all]`, `jobs take [ID] [--pid self|PID|none]`, `jobs done ID [--result T]`,
|
|
124
|
+
`jobs drop ID [--why T]`. Lower `--prio` is taken first. A taken job is tied to the taker's process; if it dies, the job
|
|
125
|
+
returns to the queue (`job.requeue`).
|
|
126
|
+
|
|
127
|
+
### Status, agents, notifications
|
|
128
|
+
|
|
129
|
+
- `agentlanes status`: running agents, claims, slots, jobs, last events and available memory.
|
|
130
|
+
- `agentlanes agents [--all] [--json]`: coding-agent processes with memory (process tree RSS), age and the claims they hold.
|
|
131
|
+
- Notifications: set `AGENTLANES_NOTIFY_CMD` (or `--notify-cmd`, or `"notify_cmd"` in `<state>/config.json`) to any shell
|
|
132
|
+
command. It receives the event as JSON on stdin for `claim.conflict`, `claim.blocked`, `claim.reap`, `slot.stale`,
|
|
133
|
+
`slot.timeout`, `slot.oom` and `job.requeue` (change with `AGENTLANES_NOTIFY_KINDS=kind1,kind2`). Example:
|
|
134
|
+
`AGENTLANES_NOTIFY_CMD='jq -r .kind | xargs notify-send agentlanes'`.
|
|
135
|
+
|
|
136
|
+
### Kernel-enforced lanes (Linux): `agentlanes run`
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
agentlanes run [--claim NAME]... [--write PATH]... [--allow-tmp] [--allow-common]
|
|
140
|
+
[--no-net] [--allow-port N]... [--allow-bind N]... [--isolate] [--best-effort] [--dry-run] -- COMMAND...
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Starts COMMAND (an agent such as `claude` or `codex`, a shell, a build) under a
|
|
144
|
+
[Landlock](https://docs.kernel.org/userspace-api/landlock.html) ruleset that applies to it and to every process it
|
|
145
|
+
starts. No root, no container, no daemon: Landlock is an unprivileged Linux security module (Linux 5.13+).
|
|
146
|
+
|
|
147
|
+
- **Read and execute everywhere**, so compilers, package managers and the agent itself keep working.
|
|
148
|
+
- **Write only** beneath: the paths of the agent's claims (`--claim NAME`, repeatable; default: every live claim held
|
|
149
|
+
by `--by` / `$AGENTLANES_AGENT`), the agentlanes state directory (so the agent can still `claim`, `release` and emit
|
|
150
|
+
events), `--write PATH` (repeatable), and with `--allow-tmp` a private temp dir exported as `TMPDIR` and deleted when
|
|
151
|
+
the command exits. Devices in `/dev` (terminal, `/dev/null`) stay writable but nothing can be created there;
|
|
152
|
+
`/dev/shm` is not writable.
|
|
153
|
+
- `--allow-common` also allows the per-user places agents and build tools write to, if they exist: `~/.cache`,
|
|
154
|
+
`~/.claude`, `~/.claude.json`, `~/.codex`, `~/.cursor`, `~/.gemini`, `~/.aider`, `~/.npm`, `~/.local/state`, ...
|
|
155
|
+
(extend with `AGENTLANES_RUN_COMMON=path1:path2`). It is a flag, not the default, because it is a wider lane than the
|
|
156
|
+
claim. `claude -p` also runs without it (it then cannot save its session history).
|
|
157
|
+
- `--no-net` denies TCP connect and bind; `--allow-port 443` (repeatable) allows connecting to that port and implies
|
|
158
|
+
`--no-net`; `--allow-bind N` allows listening on N. Needs Landlock ABI 4 (Linux 6.7+); on older kernels `run` warns
|
|
159
|
+
and the network is not restricted. Landlock covers TCP only: UDP (including DNS) is not restricted.
|
|
160
|
+
- `--isolate` (ABI 6, Linux 6.12+): processes in the run cannot signal or connect to abstract unix sockets of processes
|
|
161
|
+
outside it.
|
|
162
|
+
- Without Landlock (not Linux, kernel older than 5.13, or Landlock disabled at boot) `run` **refuses** and says why.
|
|
163
|
+
`--best-effort` runs the command unconfined with a warning instead. `agentlanes doctor` prints the kernel's Landlock ABI.
|
|
164
|
+
- The ruleset follows the kernel's best-effort pattern: `run` asks for the ABI version and uses every right that
|
|
165
|
+
version knows (ABI 1 file writes, 2 cross-directory rename/link, 3 truncate, 4 TCP, 5 device ioctl, 6 scoping) and
|
|
166
|
+
warns about what an older ABI leaves open. `--dry-run` prints the exact rules.
|
|
167
|
+
- Events: `run.start` (command, ABI, writable paths, network rule) and `run.stop` (exit code, duration). The exit
|
|
168
|
+
code is the command's.
|
|
169
|
+
|
|
170
|
+
**The lanes are fixed when the command starts.** A claim the agent takes later does not widen a running agent's
|
|
171
|
+
sandbox: restart it, or run that sub-task under its own `agentlanes run --claim NEW -- ...`. A nested `run` can only
|
|
172
|
+
narrow (a path must be allowed by every layer). A file (not directory) claim allows writing that file in place, but not
|
|
173
|
+
tools that replace it through a temp file and rename (`sed -i`, most editors); claim the directory for those.
|
|
174
|
+
|
|
175
|
+
## State directory
|
|
176
|
+
|
|
177
|
+
First match wins: `--state-dir DIR`, `$AGENTLANES_STATE_DIR`, the nearest `.agentlanes/` directory above the current directory
|
|
178
|
+
(create one with `agentlanes init` for per-project state), then `$XDG_STATE_HOME/agentlanes` (default `~/.local/state/agentlanes`).
|
|
179
|
+
All agents that should see each other must use the same directory. Do not put it on a network filesystem: `flock` there
|
|
180
|
+
is not reliable.
|
|
181
|
+
|
|
182
|
+
## Hooks and instructions per agent
|
|
183
|
+
|
|
184
|
+
| Agent | How agentlanes is enforced | Set up |
|
|
185
|
+
|---|---|---|
|
|
186
|
+
| Claude Code | **Hook** (`PreToolUse` on Edit/Write/MultiEdit/NotebookEdit). Tested with a real session. | `agentlanes init --claude-code` |
|
|
187
|
+
| Codex | **Hook** (`PreToolUse` on `apply_patch`; file paths are read from the patch). Written to the Codex hooks documentation and unit-tested with sample payloads; not yet run in a real Codex session. | [examples/codex/config.toml](https://github.com/metastazorg/agentlanes/blob/main/examples/codex/config.toml) + `init --agents-md` |
|
|
188
|
+
| Cursor | **Hook, experimental** (`preToolUse` with matcher `Write`). Cursor documents the event and the `permission: allow/deny` answer, but not the field that carries the file path, so the adapter looks for `file_path`, `path` or `target_file`. Not yet run in real Cursor. | [examples/cursor/hooks.json](https://github.com/metastazorg/agentlanes/blob/main/examples/cursor/hooks.json) + `init --cursor` |
|
|
189
|
+
| Aider, other shell agents | **Instruction-only.** No pre-edit hook to attach to. | `init --agents-md`, then e.g. `aider --read AGENTS.md` |
|
|
190
|
+
|
|
191
|
+
Instruction-only means the agent is told to claim before editing and usually does, but nothing stops it if it does not.
|
|
192
|
+
|
|
193
|
+
### Claude Code hook
|
|
194
|
+
|
|
195
|
+
`agentlanes hook claude-code` reads the hook JSON on stdin. When the target file is covered by a claim held by a
|
|
196
|
+
different agent it answers `permissionDecision: "deny"` with the holder and the claim's description as the reason, which
|
|
197
|
+
Claude sees and can act on. Unclaimed paths and the agent's own claims produce no output, so the normal permission flow
|
|
198
|
+
is unchanged. "Own claim" means the claim was made from the same Claude Code process (or with the same
|
|
199
|
+
`$AGENTLANES_AGENT`). The hook can go in `.claude/settings.json` (project, what `init` writes) or `~/.claude/settings.json`
|
|
200
|
+
(user); see [examples/claude-code/settings.json](https://github.com/metastazorg/agentlanes/blob/main/examples/claude-code/settings.json).
|
|
201
|
+
|
|
202
|
+
### Fail-open or fail-closed
|
|
203
|
+
|
|
204
|
+
By default the hook **fails open**: if it cannot do its job, the edit goes ahead. That covers malformed hook input, a
|
|
205
|
+
corrupt `claims.json`, and an unreadable state directory. It also covers the case we hit ourselves: if `agentlanes` is
|
|
206
|
+
not on the `PATH` that the agent sees, the hook command fails to start, Claude Code treats that as a non-blocking hook
|
|
207
|
+
error, and edits pass silently. `agentlanes doctor` catches this by running the configured hook command once.
|
|
208
|
+
|
|
209
|
+
For fail-closed behaviour, use **strict mode**:
|
|
210
|
+
|
|
211
|
+
- `AGENTLANES_STRICT=1` in the agent's environment: a broken state or malformed input makes the hook deny the edit with
|
|
212
|
+
a message that names the problem and says to run `agentlanes doctor`.
|
|
213
|
+
- `agentlanes init --claude-code --strict` writes a hook command that also covers the missing-command case: it checks
|
|
214
|
+
`command -v agentlanes` first and exits 2 (Claude Code's "block" exit code, with the reason on stderr) if it is absent,
|
|
215
|
+
then runs the hook with `AGENTLANES_STRICT=1`.
|
|
216
|
+
|
|
217
|
+
Strict mode is a choice between "a broken coordination tool stops all edits" and "a broken coordination tool is
|
|
218
|
+
silently ignored". Teams that rely on claims for correctness should pick strict; solo users usually want the default.
|
|
219
|
+
|
|
220
|
+
## Limits
|
|
221
|
+
|
|
222
|
+
- **Hooks alone are a coordination tool, not a security boundary.** The hooks cover the agents' file-editing tools. An
|
|
223
|
+
agent that changes files through shell commands (`cp`, `sed -i`, `>` redirects, a build script) is not stopped by any
|
|
224
|
+
hook, and a determined or confused agent can always ignore instructions.
|
|
225
|
+
- **On Linux 5.13+ `agentlanes run` enforces write lanes in the kernel via Landlock; hooks remain as a fast, friendly
|
|
226
|
+
first line** (they explain who holds a path before the agent even tries). What Landlock under `run` does not cover:
|
|
227
|
+
- **Reads.** Everything stays readable, including secrets in your home directory. `run` limits what an agent can
|
|
228
|
+
change, not what it can see or send.
|
|
229
|
+
- **Already-open file descriptors and other processes.** Files opened before `run` started, and processes that are
|
|
230
|
+
not descendants of the run (your editor, a daemon, another agent, a build server the agent talks to over a socket
|
|
231
|
+
or `docker` API) write wherever they are allowed to. Asking such a process to write is not blocked.
|
|
232
|
+
- **Other users and root.** It confines one process tree of one user; it is not a multi-user boundary.
|
|
233
|
+
- **Network** only with ABI 4+ and only TCP; **signals** to outside processes only with ABI 6 (`--isolate`).
|
|
234
|
+
- Re-opening `/dev/stdout` or `/dev/stderr` fails when that stream is a regular file outside the lanes (write to the
|
|
235
|
+
inherited descriptor instead, which works).
|
|
236
|
+
- **Not Linux** (macOS, BSD, Windows): no Landlock. `run` refuses, or runs unconfined with `--best-effort`.
|
|
237
|
+
- Kernel enforcement that also covers reads, identity and sealed sessions is what Ranix (below) is for.
|
|
238
|
+
- Claims are advisory for agents without a hook (see the table above).
|
|
239
|
+
- `events wait` and slot queues poll (0.2 s) instead of using inotify/kqueue; fine for tens of agents, not thousands.
|
|
240
|
+
- The state directory must be on a local filesystem; `flock` over NFS/SMB is not reliable (`doctor` warns).
|
|
241
|
+
- Windows is not supported (`fcntl.flock`, POSIX process groups).
|
|
242
|
+
|
|
243
|
+
## Platform support: what is tested where
|
|
244
|
+
|
|
245
|
+
**Linux (tested).** All 71 tests pass on Linux aarch64 (kernel 6.8, Landlock ABI 4), Python 3.12, procps `ps`, with
|
|
246
|
+
and without a systemd user session for the memory cap. The Claude Code hook and `agentlanes run` are each tested in a
|
|
247
|
+
real Claude Code session. Landlock ABI 5 and 6 (device ioctl, `--isolate`) are unit-tested only: no such kernel was
|
|
248
|
+
available. x86_64 uses the same Landlock syscall numbers but was not run.
|
|
249
|
+
|
|
250
|
+
**macOS (written, not run on a Mac).** No Mac was available. What we did instead:
|
|
251
|
+
|
|
252
|
+
- Every Linux-only assumption has a portable path: process liveness, start time (pid-reuse check) and parent walk use
|
|
253
|
+
`ps -o stat= / lstart= / ppid= -o args=` with `LC_ALL=C`; the process table uses one `-o field=` per column (the form
|
|
254
|
+
BSD `ps` and procps both accept); working directories use `lsof -d cwd`; free memory uses `vm_stat`; the memory cap
|
|
255
|
+
uses the RSS watchdog instead of systemd; `demo.sh` works without `$BASHPID` (macOS ships bash 3.2).
|
|
256
|
+
- The `ps` paths run for real on Linux in the test suite (`AGENTLANES_NO_PROC=1` turns `/proc` off): leases, reaping,
|
|
257
|
+
pid-reuse detection and `--pid self` discovery all pass that way.
|
|
258
|
+
- The macOS-only parsing (BSD `ps` lines, `vm_stat`, `lsof`, `sys.platform == 'darwin'`) is tested with canned output.
|
|
259
|
+
- **Untested on macOS:** that real macOS `ps`, `vm_stat` and `lsof` print exactly what the canned samples assume; `flock`
|
|
260
|
+
on APFS under load; the RSS watchdog's kill timing; `demo.sh` under bash 3.2; Claude Code process names on macOS.
|
|
261
|
+
If you run it on a Mac, `agentlanes doctor` and `python3 -m unittest discover -s tests` are the quickest report.
|
|
262
|
+
|
|
263
|
+
## FAQ
|
|
264
|
+
|
|
265
|
+
**Why not just use git worktrees or containers?**
|
|
266
|
+
Use them too. A worktree or container gives each agent its own copy of the files, which removes edit collisions inside
|
|
267
|
+
the tree. It does not share or divide what is left over: ports, a local database, the package and build caches, GPU and
|
|
268
|
+
memory, a test phone, and the human who is editing in the main tree at the same time. Two agents in two worktrees can
|
|
269
|
+
still both start a full build on an 8 GB machine, both bind port 3000, or both run migrations against the same dev
|
|
270
|
+
database. And at some point the work has to be merged back, which is where claims on paths help. agentlanes is the
|
|
271
|
+
coordination layer that sits next to worktrees, not a replacement for them.
|
|
272
|
+
|
|
273
|
+
**Do I need a daemon or a server?** No. Every command reads and writes JSON files under a lock and exits.
|
|
274
|
+
|
|
275
|
+
**What happens when an agent crashes while holding something?** Claims taken with `--pid` end when that process
|
|
276
|
+
exits (also on `kill -9`); a slot is a lock inherited by the command, so the kernel frees it; a taken job goes back to
|
|
277
|
+
the queue.
|
|
278
|
+
|
|
279
|
+
**Does it work with agents I do not control?** Only as far as the agent follows instructions, unless it has a hook (see
|
|
280
|
+
the table).
|
|
281
|
+
|
|
282
|
+
## How we use it
|
|
283
|
+
|
|
284
|
+
We are two founders who run many coding agents at once on one Raspberry Pi with 8 GB of RAM: interactive sessions,
|
|
285
|
+
batch agents, and agents started by other agents, next to a few dozen services. Without coordination they overwrote each
|
|
286
|
+
other's edits and started heavy builds together until the machine swapped itself to a stop. Now every agent claims the
|
|
287
|
+
paths it changes, heavy work goes through slots (one heavy build at a time, browsers capped), and the event log tells us
|
|
288
|
+
and the agents who did what. agentlanes is that setup with our internal names taken out.
|
|
289
|
+
|
|
290
|
+
## Relation to Ranix
|
|
291
|
+
|
|
292
|
+
agentlanes comes from the coordination layer we use for our own agents while building Ranix, an independent kernel where
|
|
293
|
+
AI agents and humans work on the same machine. On Ranix these primitives become kernel objects: a lease is owned by a
|
|
294
|
+
process and released by the kernel when it exits, a slot is a counting semaphore with a visible wait queue, and the event
|
|
295
|
+
log is a kernel ring stamped with the sender's identity. On Linux and macOS this package emulates them in user space with
|
|
296
|
+
files, `flock` and process start times. The command-line interface is meant to stay the same on both.
|
|
297
|
+
|
|
298
|
+
## Tests
|
|
299
|
+
|
|
300
|
+
```sh
|
|
301
|
+
python3 -m unittest discover -s tests -v
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
71 tests. Most drive the real CLI in subprocesses: concurrent claims from 16 processes, lease end on holder death and
|
|
305
|
+
pid reuse, TTL expiry, FIFO slot order, slot capacity, stale holder reclaim after SIGKILL, dead waiters, the memory
|
|
306
|
+
watchdog, `events wait`, concurrent emitters, job requeue, the Claude Code, Codex and Cursor hooks, strict mode,
|
|
307
|
+
`init` (fresh project, idempotency, merging into a `settings.json` that already has other hooks, invalid JSON left
|
|
308
|
+
alone) and `doctor`. `tests/test_run.py` runs real commands under Landlock: writes inside a claimed path work, and
|
|
309
|
+
`echo >`, `>>`, `cp`, `sed -i`, `mv` in and out, `rm`, `mkdir`, hard and symbolic links, `mkfifo`, `touch` and
|
|
310
|
+
`truncate` outside it fail with `Permission denied`; renames and links between two lanes work (REFER); `claim`/`release`
|
|
311
|
+
work from inside; a claim taken inside does not widen the lane; nested runs only narrow; the private temp dir works and
|
|
312
|
+
is removed; `--no-net`/`--allow-port` against a local TCP listener; events and exit codes. ABI degradation (ABI 1 to 6),
|
|
313
|
+
the struct size per ABI and the unsupported-kernel paths (ENOSYS, disabled, not Linux, refuse vs `--best-effort`) are
|
|
314
|
+
unit-tested without the kernel. Kernel tests skip themselves where Landlock is missing. `tests/test_portability.py` covers the `ps`-based and macOS code paths.
|
|
315
|
+
|
|
316
|
+
## Renaming
|
|
317
|
+
|
|
318
|
+
The name is a working name. Change `NAME` in `src/agentlanes/__init__.py` (prog name, `AGENTLANES_*` environment prefix,
|
|
319
|
+
state directory and `.agentlanes` marker follow it), the two marked lines in `pyproject.toml`, and rename `src/agentlanes/`.
|
|
320
|
+
|
|
321
|
+
## License
|
|
322
|
+
|
|
323
|
+
Apache-2.0, see [LICENSE](LICENSE). (The Ranix kernel itself is EUPL-1.2.)
|