agent-lock 3.1.0 → 4.0.0
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.
- checksums.yaml +4 -4
- data/.gitleaks.toml +23 -0
- data/AGENTS.md +11 -17
- data/CHANGELOG.md +124 -3
- data/README.md +496 -100
- data/Rakefile +13 -6
- data/docs/badges/coverage_badge.svg +21 -0
- data/docs/badges/yardoc.svg +1 -0
- data/docs/img/alock-sequence.avif +0 -0
- data/docs/img/alock-sequence.md +29 -0
- data/docs/img/alock-sequence.png +0 -0
- data/lefthook.yml +39 -0
- data/lib/agent/lock/cli/commands/acquire.rb +25 -19
- data/lib/agent/lock/cli/commands/base.rb +59 -23
- data/lib/agent/lock/cli/commands/break.rb +12 -7
- data/lib/agent/lock/cli/commands/check.rb +10 -9
- data/lib/agent/lock/cli/commands/completion.rb +15 -32
- data/lib/agent/lock/cli/commands/list.rb +46 -37
- data/lib/agent/lock/cli/commands/listing.rb +170 -0
- data/lib/agent/lock/cli/commands/mine.rb +7 -5
- data/lib/agent/lock/cli/commands/note.rb +13 -9
- data/lib/agent/lock/cli/commands/release.rb +10 -7
- data/lib/agent/lock/cli/commands/release_all.rb +7 -5
- data/lib/agent/lock/cli/commands/resume.rb +13 -7
- data/lib/agent/lock/cli/commands/show.rb +172 -0
- data/lib/agent/lock/cli/commands/skills.rb +28 -19
- data/lib/agent/lock/cli/commands/switch_backend.rb +205 -0
- data/lib/agent/lock/cli/commands/tree_command.rb +72 -0
- data/lib/agent/lock/cli/commands/version.rb +2 -1
- data/lib/agent/lock/cli/commands/whoami.rb +7 -3
- data/lib/agent/lock/cli.rb +63 -19
- data/lib/agent/lock/error.rb +52 -1
- data/lib/agent/lock/facade/async.rb +83 -0
- data/lib/agent/lock/facade/backend.rb +133 -0
- data/lib/agent/lock/facade/memo.rb +30 -0
- data/lib/agent/lock/facade/refusal.rb +78 -0
- data/lib/agent/lock/facade/session.rb +142 -0
- data/lib/agent/lock/facade/strategies.rb +36 -0
- data/lib/agent/lock/facade.rb +369 -0
- data/lib/agent/lock/freeze.rb +59 -5
- data/lib/agent/lock/identity.rb +63 -5
- data/lib/agent/lock/launcher.rb +17 -1
- data/lib/agent/lock/manager/enforcement.rb +98 -0
- data/lib/agent/lock/manager/switch.rb +91 -0
- data/lib/agent/lock/manager/thaw.rb +68 -0
- data/lib/agent/lock/manager.rb +176 -79
- data/lib/agent/lock/process_info/legacy_start.rb +60 -0
- data/lib/agent/lock/process_info.rb +42 -11
- data/lib/agent/lock/record.rb +124 -10
- data/lib/agent/lock/scope.rb +49 -4
- data/lib/agent/lock/skill.rb +14 -10
- data/lib/agent/lock/store/backend_name.rb +62 -0
- data/lib/agent/lock/store/file_system_store.rb +20 -1
- data/lib/agent/lock/store/redis_index.rb +179 -0
- data/lib/agent/lock/store/redis_store.rb +191 -33
- data/lib/agent/lock/store.rb +180 -19
- data/lib/agent/lock/text.rb +62 -0
- data/lib/agent/lock/tree.rb +143 -16
- data/lib/agent/lock/version.rb +2 -1
- data/lib/agent/lock.rb +3 -0
- data/skills/agent-lock/SKILL.md +75 -10
- metadata +41 -22
- data/justfile +0 -127
- data/sig/agent/lock.rbs +0 -6
data/skills/agent-lock/SKILL.md
CHANGED
|
@@ -1,13 +1,64 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: agent-lock
|
|
3
|
-
description: Use when several agents or sub-agents write in one checkout or worktree, before creating or editing files there, when launching sub-agents that will write files, or when `alock` or `agent-lock` answers REFUSED, HELD, STALE or INTERRUPTED WORK.
|
|
3
|
+
description: Use when several agents or sub-agents write in one checkout or worktree, before creating or editing files there, when launching sub-agents that will also may write files, or when `alock` or `agent-lock` answers REFUSED, HELD, STALE or INTERRUPTED WORK. Use when a software factory is in use that spans more than one server, where the same repo maybe checked out in different locations.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
version: "4.0.0"
|
|
7
|
+
author: Konstantin Gredeskoul
|
|
8
|
+
allowed-tools: "Bash(alock *) Bash(git:*) Bash(gh:*) Read Write"
|
|
9
|
+
compatibility: Requires Ruby 4.0 and later
|
|
4
10
|
---
|
|
5
11
|
|
|
6
|
-
#
|
|
12
|
+
# Declaring advisory locks on files or folders
|
|
7
13
|
|
|
8
14
|
## Overview
|
|
9
15
|
|
|
10
|
-
`
|
|
16
|
+
This skill uses a Ruby gem, `agent-lock`, which can be installed using `gem install agent-lock` command. Once installed, it provides both the rich CLI for managing advisory locks on files and folders; as well as a bit more capable Ruby API that can be invoked directly from any Ruby application without having to `fork()/exec()` to run an external shell command. Certainly for usage within a web request cycle the Ruby API is the strongly recommended way of using this the locks, which avoids starting a new process once or more than once per web request.
|
|
17
|
+
|
|
18
|
+
Once the gem is installed, its CLI can be invoked via `alock` or via `agent-lock` (those are identical).
|
|
19
|
+
|
|
20
|
+
When used by Agents in a consistent way, it helps to keep agents and sub-agents that share a repo checkout from clobbering over each other's changes. A lock is only advisory: it protects a file **only if every writer first checks for locks before writing, and if not set — acquires the lock before writing, under its own name, in the tree it writes in, and releases it when the changes to the files are written to the disk.**
|
|
21
|
+
|
|
22
|
+
## Choosing the Backend
|
|
23
|
+
|
|
24
|
+
This gem can use two completely separate backends to actually store locking information: Redis and Filesystem.
|
|
25
|
+
|
|
26
|
+
Creating a lock using one backend and checking or releasing using another is meaningless (and in fact is an error).
|
|
27
|
+
|
|
28
|
+
The priority of choosing backends:
|
|
29
|
+
|
|
30
|
+
1. A store named on the call comes first: `-s redis`, `-s filesystem`, or `-u <url>` for one Redis and no other.
|
|
31
|
+
|
|
32
|
+
2. Then a store named in your environment. `$AGENT_LOCK_REDIS_URL` names both the Redis backend and the one Redis to use, with no fallback, and `$AGENT_LOCK_BACKEND` names the backend alone (`file` or `redis`). Set `AGENT_LOCK_REDIS_URL` globally in your dot-init files to never think about it again.
|
|
33
|
+
|
|
34
|
+
3. With no store named, a checkout that has been used before stays on the store its first `alock` call recorded.
|
|
35
|
+
|
|
36
|
+
4. In a checkout nobody has used yet, `alock` looks for a Redis by itself: `$REDIS_URL` when it is set, then `redis://127.0.0.1:6379/0`. A local Redis needs no `export`. To use `$REDIS_URL` or fail, with no fallback to the local one, pass `-u "$REDIS_URL"` on every call.
|
|
37
|
+
|
|
38
|
+
5. If neither Redis answers, the gem switches to the filesystem-based backend, which, for each repo, stores locks inside the `.git` folder, which does not require modifying `.gitignore`, and is the most natural place to store locks after Redis for a repo.
|
|
39
|
+
|
|
40
|
+
The store a checkout recorded wins over steps 1 and 2: naming the other one, with a flag or a variable, exits 2 and moves nothing. `AGENT_LOCK_REDIS_URL` in a checkout bound to the file store is that case. Only `alock switch-backend` moves a checkout.
|
|
41
|
+
|
|
42
|
+
### Which store the locks live in
|
|
43
|
+
|
|
44
|
+
As discussed above, `alock` uses Redis when one answers and the file store inside `.git` otherwise, and the first call in a checkout records that choice. The caller can choose instead, and should whenever somebody else chose first:
|
|
45
|
+
|
|
46
|
+
- **You were given a strategy or a Redis URL** (by your orchestrator, a dispatcher, or your instructions): pass it on every `alock` call that reads or writes locks (`acquire`, `release`, `release-all`, `check`, `list`, `mine`, `note`, `resume`, `break`), not only `acquire`. `whoami` and `version` take neither flag. `-s redis` or `-s filesystem` names the store; `-u <url>` names the one Redis to use and implies `-s redis`.
|
|
47
|
+
|
|
48
|
+
- **`AGENT_LOCK_REDIS_URL` is already set in your environment:** it means the same as `-u` on every call, so pass no flag and do not unset or change it.
|
|
49
|
+
|
|
50
|
+
- **You launch sub-agents** and you passed either flag yourself: give each sub-agent the same flags with its name. A different Redis URL is a different store, where nobody sees your locks.
|
|
51
|
+
|
|
52
|
+
- **You were given neither:** pass neither.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
cd ~/src/shop && \
|
|
56
|
+
AGENT_ID=shipping-rates-7f3a alock acquire "src/shipping/**" "rate tables" -u redis://locks.internal:6379
|
|
57
|
+
cd ~/src/shop && \
|
|
58
|
+
AGENT_ID=shipping-rates-7f3a alock release "src/shipping/**" -u redis://locks.internal:6379
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
If alock exits with the value 2, it means that the flags disagree with the checkout or the Redis did not answer. Do not drop the flag to get past it: that puts your lock where nobody else is looking. Report it, fix the URL, or run the `alock switch-backend <store>` that the error's `HINT:` line names. That command moves every agent in the checkout, so ask the human first.
|
|
11
62
|
|
|
12
63
|
## Four ways a claim silently protects nothing
|
|
13
64
|
|
|
@@ -16,6 +67,15 @@ description: Use when several agents or sub-agents write in one checkout or work
|
|
|
16
67
|
1. **A lock in another checkout guards nothing here.** Run `alock` inside the checkout you write in: `cd <checkout> && AGENT_ID=<your-name> alock ...`, or pass `--dir <checkout>`.
|
|
17
68
|
1. **An orchestrator's lock does not keep siblings apart.** It keeps other sessions out. Each sub-agent still claims its own files inside it.
|
|
18
69
|
|
|
70
|
+
|
|
71
|
+
## When a dispatcher started you
|
|
72
|
+
|
|
73
|
+
A dispatcher (OpenLanes, or any harness) may start you with `AGENT_ID`, `AGENT_PARENT_ID` and `AGENT_LOCK_REDIS_URL` already set. Check with `alock whoami`: if it prints your name and a parent `(from AGENT_PARENT_ID)`, this applies.
|
|
74
|
+
|
|
75
|
+
- **Leave all three alone.** They put your locks in the dispatcher's store, as its child, which is what lets you claim inside the area it holds for you. Run `alock` with no name prefix and no store flag.
|
|
76
|
+
- **Your sub-agents inherit all three**, so an unnamed one signs as you. Give each its own name and nothing else: `AGENT_ID=<sub-agent-name> alock ...`. Do not make yourself their parent: nobody may claim inside a grandparent's lock, so they would be refused everywhere in the dispatcher's area. Named this way they are your siblings, so release, or never claim, what you hand to one, and their locks are not released by your `release-all`.
|
|
77
|
+
- **Never set `AGENT_PARENT_ID` to nothing.** Empty means "no parent", and you are then refused inside the dispatcher's claim.
|
|
78
|
+
|
|
19
79
|
## Recipe
|
|
20
80
|
|
|
21
81
|
The orchestrator runs `alock` bare, which makes it the parent, and gives each sub-agent a distinct name and the checkout:
|
|
@@ -27,13 +87,17 @@ cd ~/src/shop && alock acquire "src/**" "fanning out the pricing work"
|
|
|
27
87
|
A sub-agent, under the name it was given. Given none, it uses its own task plus four random characters, chosen once and typed the same on every call; never the example below:
|
|
28
88
|
|
|
29
89
|
```bash
|
|
30
|
-
|
|
31
|
-
cd ~/src/shop && AGENT_ID=shipping-rates-7f3a alock
|
|
32
|
-
cd ~/src/shop && AGENT_ID=shipping-rates-7f3a alock
|
|
33
|
-
cd ~/src/shop && AGENT_ID=shipping-rates-7f3a alock
|
|
90
|
+
# id shipping-rates-7f3a, parent inferred
|
|
91
|
+
cd ~/src/shop && AGENT_ID=shipping-rates-7f3a alock whoami
|
|
92
|
+
cd ~/src/shop && AGENT_ID=shipping-rates-7f3a alock acquire "src/shipping/**/*.py" "rate tables"
|
|
93
|
+
cd ~/src/shop && AGENT_ID=shipping-rates-7f3a alock note "src/shipping/**/*.py" "rates done, specs red"
|
|
94
|
+
# yours and your sub-agents', never your parent's
|
|
95
|
+
cd ~/src/shop && AGENT_ID=shipping-rates-7f3a alock release-all
|
|
34
96
|
```
|
|
35
97
|
|
|
36
|
-
Write only inside what you claimed, and claim the narrowest scope that covers it. A directory means everything under it; `**` is rarely right.
|
|
98
|
+
Write only inside what you claimed, and claim the narrowest scope that covers it. A directory means everything under it; `**` is rarely right.
|
|
99
|
+
|
|
100
|
+
Make sure to quote globs.
|
|
37
101
|
|
|
38
102
|
## Reading the answer
|
|
39
103
|
|
|
@@ -44,7 +108,8 @@ Write only inside what you claimed, and claim the narrowest scope that covers it
|
|
|
44
108
|
| `REFUSED: ... your parent's whole claim` | 1 | Claim something narrower inside it |
|
|
45
109
|
| `HELD ... STALE` | 1 | The holder is alive but quiet. Ask, or announce, then `alock break` |
|
|
46
110
|
| `INTERRUPTED WORK` | 1 | `alock resume` takes it over with its notes; `alock break` discards it |
|
|
47
|
-
| `
|
|
111
|
+
| `ERROR: alock: ...` | 2 | The command could not run: empty scope, a path outside the tree, a store mismatch, a Redis that did not answer |
|
|
112
|
+
| `HINT: run 'alock ...'` under an error | 2 | The command that gets past it. `switch-backend` moves every agent in the checkout: ask the human first |
|
|
48
113
|
|
|
49
114
|
## Common mistakes
|
|
50
115
|
|
|
@@ -56,4 +121,4 @@ Write only inside what you claimed, and claim the narrowest scope that covers it
|
|
|
56
121
|
| Running `alock` from wherever the shell started | The lock lands in another repository |
|
|
57
122
|
| Writing after a refusal | The collision the lock existed to prevent |
|
|
58
123
|
|
|
59
|
-
Needs `agent-lock` newer than 0.1.0 (`alock version`). Run `alock <command> --help` for flags.
|
|
124
|
+
Needs `agent-lock` newer than 0.1.0 (`alock version`); the store flags, `AGENT_LOCK_REDIS_URL` and an empty `AGENT_PARENT_ID` meaning "no parent" need 4.0.0. Run `alock <command> --help` for flags.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: agent-lock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Konstantin Gredeskoul
|
|
@@ -93,22 +93,17 @@ dependencies:
|
|
|
93
93
|
- - "~>"
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: '5.0'
|
|
96
|
-
description: '
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
the
|
|
107
|
-
gems, and offers a configuration file that installs a set of coding agents, skills,
|
|
108
|
-
plugins, commands, from various guthub folders, or via running commands, and so
|
|
109
|
-
on. In other words the repo''s purpose is to ensure your agentic setup is identical
|
|
110
|
-
from machine to machine, and by modifying the config file you can pick and choose
|
|
111
|
-
your skills, your AGENT.md/CLAUDE.md file and so on.'
|
|
96
|
+
description: 'agent-lock installs `alock`, a CLI that coding agents (Claude Code,
|
|
97
|
+
Codex, Cursor, sub-agents of one session, or agents on several machines) can run
|
|
98
|
+
before they write: `alock acquire <glob> <intent>` claims a path, and any overlapping
|
|
99
|
+
claim is refused with who holds it, since when, and why. Locks are Markdown documents
|
|
100
|
+
kept in Redis (shared across machines) or in a file store inside .git, keyed by
|
|
101
|
+
repository and branch. Identity comes from the agent session, crashed holders are
|
|
102
|
+
reaped or orphaned with their notes, and macOS can freeze files outright with --enforce.
|
|
103
|
+
Used by OpenLanes to keep concurrent agents from overwriting each other. Since 4.0
|
|
104
|
+
every command is also a Ruby method on Agent::Lock::Facade, with a block form of
|
|
105
|
+
acquire that releases afterwards, and an opt-in async mode that returns futures
|
|
106
|
+
(it needs the concurrent-ruby gem).'
|
|
112
107
|
email:
|
|
113
108
|
- kigster@gmail.com
|
|
114
109
|
executables:
|
|
@@ -118,6 +113,7 @@ extensions: []
|
|
|
118
113
|
extra_rdoc_files: []
|
|
119
114
|
files:
|
|
120
115
|
- ".claude/CLAUDE.md"
|
|
116
|
+
- ".gitleaks.toml"
|
|
121
117
|
- ".openlanes.yml"
|
|
122
118
|
- ".ruby-version"
|
|
123
119
|
- AGENTS.md
|
|
@@ -125,9 +121,14 @@ files:
|
|
|
125
121
|
- LICENSE.txt
|
|
126
122
|
- README.md
|
|
127
123
|
- Rakefile
|
|
124
|
+
- docs/badges/coverage_badge.svg
|
|
125
|
+
- docs/badges/yardoc.svg
|
|
126
|
+
- docs/img/alock-sequence.avif
|
|
127
|
+
- docs/img/alock-sequence.md
|
|
128
|
+
- docs/img/alock-sequence.png
|
|
128
129
|
- exe/agent-lock
|
|
129
130
|
- exe/alock
|
|
130
|
-
-
|
|
131
|
+
- lefthook.yml
|
|
131
132
|
- lib/agent/lock.rb
|
|
132
133
|
- lib/agent/lock/cli.rb
|
|
133
134
|
- lib/agent/lock/cli/commands/acquire.rb
|
|
@@ -136,29 +137,46 @@ files:
|
|
|
136
137
|
- lib/agent/lock/cli/commands/check.rb
|
|
137
138
|
- lib/agent/lock/cli/commands/completion.rb
|
|
138
139
|
- lib/agent/lock/cli/commands/list.rb
|
|
140
|
+
- lib/agent/lock/cli/commands/listing.rb
|
|
139
141
|
- lib/agent/lock/cli/commands/mine.rb
|
|
140
142
|
- lib/agent/lock/cli/commands/note.rb
|
|
141
143
|
- lib/agent/lock/cli/commands/release.rb
|
|
142
144
|
- lib/agent/lock/cli/commands/release_all.rb
|
|
143
145
|
- lib/agent/lock/cli/commands/resume.rb
|
|
146
|
+
- lib/agent/lock/cli/commands/show.rb
|
|
144
147
|
- lib/agent/lock/cli/commands/skills.rb
|
|
148
|
+
- lib/agent/lock/cli/commands/switch_backend.rb
|
|
149
|
+
- lib/agent/lock/cli/commands/tree_command.rb
|
|
145
150
|
- lib/agent/lock/cli/commands/version.rb
|
|
146
151
|
- lib/agent/lock/cli/commands/whoami.rb
|
|
147
152
|
- lib/agent/lock/error.rb
|
|
153
|
+
- lib/agent/lock/facade.rb
|
|
154
|
+
- lib/agent/lock/facade/async.rb
|
|
155
|
+
- lib/agent/lock/facade/backend.rb
|
|
156
|
+
- lib/agent/lock/facade/memo.rb
|
|
157
|
+
- lib/agent/lock/facade/refusal.rb
|
|
158
|
+
- lib/agent/lock/facade/session.rb
|
|
159
|
+
- lib/agent/lock/facade/strategies.rb
|
|
148
160
|
- lib/agent/lock/freeze.rb
|
|
149
161
|
- lib/agent/lock/identity.rb
|
|
150
162
|
- lib/agent/lock/launcher.rb
|
|
151
163
|
- lib/agent/lock/manager.rb
|
|
164
|
+
- lib/agent/lock/manager/enforcement.rb
|
|
165
|
+
- lib/agent/lock/manager/switch.rb
|
|
166
|
+
- lib/agent/lock/manager/thaw.rb
|
|
152
167
|
- lib/agent/lock/process_info.rb
|
|
168
|
+
- lib/agent/lock/process_info/legacy_start.rb
|
|
153
169
|
- lib/agent/lock/record.rb
|
|
154
170
|
- lib/agent/lock/scope.rb
|
|
155
171
|
- lib/agent/lock/skill.rb
|
|
156
172
|
- lib/agent/lock/store.rb
|
|
173
|
+
- lib/agent/lock/store/backend_name.rb
|
|
157
174
|
- lib/agent/lock/store/file_system_store.rb
|
|
175
|
+
- lib/agent/lock/store/redis_index.rb
|
|
158
176
|
- lib/agent/lock/store/redis_store.rb
|
|
177
|
+
- lib/agent/lock/text.rb
|
|
159
178
|
- lib/agent/lock/tree.rb
|
|
160
179
|
- lib/agent/lock/version.rb
|
|
161
|
-
- sig/agent/lock.rbs
|
|
162
180
|
- skills/agent-lock/SKILL.md
|
|
163
181
|
homepage: https://github.com/kigster/agent-lock
|
|
164
182
|
licenses:
|
|
@@ -168,6 +186,7 @@ metadata:
|
|
|
168
186
|
homepage_uri: https://github.com/kigster/agent-lock
|
|
169
187
|
source_code_uri: https://github.com/kigster/agent-lock
|
|
170
188
|
changelog_uri: https://github.com/kigster/agent-lock/blob/main/CHANGELOG.md
|
|
189
|
+
documentation_uri: https://kigster.github.io/agent-lock/
|
|
171
190
|
rubygems_mfa_required: 'true'
|
|
172
191
|
rdoc_options: []
|
|
173
192
|
require_paths:
|
|
@@ -176,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
176
195
|
requirements:
|
|
177
196
|
- - ">="
|
|
178
197
|
- !ruby/object:Gem::Version
|
|
179
|
-
version:
|
|
198
|
+
version: '4.0'
|
|
180
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
200
|
requirements:
|
|
182
201
|
- - ">="
|
|
@@ -185,6 +204,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
185
204
|
requirements: []
|
|
186
205
|
rubygems_version: 4.0.23
|
|
187
206
|
specification_version: 4
|
|
188
|
-
summary: Advisory
|
|
189
|
-
|
|
207
|
+
summary: Advisory file and directory locks for AI coding agents sharing a checkout
|
|
208
|
+
or a branch.
|
|
190
209
|
test_files: []
|
data/justfile
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# Tell 'just' to run bash, source our setup script, then execute the recipe
|
|
2
|
-
set shell := ["bash", "-c"]
|
|
3
|
-
|
|
4
|
-
version := `grep VERSION lib/agent/lock/version.rb | awk '{print $3}' | tr -d '"' | tr -d '\n'`
|
|
5
|
-
repo := 'git@github.com:kigster/agent-lock.git'
|
|
6
|
-
|
|
7
|
-
rbenv := 'eval "$(rbenv init - bash 2>/dev/null || true)"; bundle exec '
|
|
8
|
-
|
|
9
|
-
# 1Password secret reference for the RubyGems TOTP, and the full path to `op`
|
|
10
|
-
# because a recipe does not inherit an interactive shell's PATH.
|
|
11
|
-
# The account is NOT named here: it is a private 1Password address and this
|
|
12
|
-
# file is public. `op` reads it from OP_ACCOUNT, exported by the ecosystem
|
|
13
|
-
# root's .envrc, which lives outside every repo. Two accounts are
|
|
14
|
-
# registered and only one holds the open-source-repos vault, so without
|
|
15
|
-
# OP_ACCOUNT the read can resolve against the wrong one, return nothing,
|
|
16
|
-
# and publish silently falls back to prompting mid-release.
|
|
17
|
-
op := '/opt/homebrew/bin/op'
|
|
18
|
-
otp_ref := 'op://open-source-repos/ruby-gems/one-time password?attribute=otp'
|
|
19
|
-
|
|
20
|
-
gem_name := 'agent-lock'
|
|
21
|
-
gem_file := 'pkg/' + gem_name + '-' + version + '.gem'
|
|
22
|
-
gem_url := 'https://rubygems.org/gems/' + gem_name
|
|
23
|
-
|
|
24
|
-
[no-exit-message]
|
|
25
|
-
recipes:
|
|
26
|
-
just --choose
|
|
27
|
-
|
|
28
|
-
# Sync all dependencies
|
|
29
|
-
install:
|
|
30
|
-
bin/setup
|
|
31
|
-
|
|
32
|
-
build: install
|
|
33
|
-
|
|
34
|
-
# standardrb
|
|
35
|
-
lint:
|
|
36
|
-
{{ rbenv }} standardrb
|
|
37
|
-
|
|
38
|
-
# Fix style with standardrb, then format the markdown
|
|
39
|
-
format:
|
|
40
|
-
bundle exec rubocop -a
|
|
41
|
-
bundle exec rubocop --auto-gen-config
|
|
42
|
-
/usr/bin/find . -name '*.md' -exec mdformat --wrap no {} \; -print
|
|
43
|
-
|
|
44
|
-
update-workflow:
|
|
45
|
-
bundle exec tilda docs -o docs/WORKFLOW.md
|
|
46
|
-
|
|
47
|
-
# Run all the tests
|
|
48
|
-
test *args:
|
|
49
|
-
export ENVIRONMENT=test; {{ rbenv }} rspec {{ args }}
|
|
50
|
-
|
|
51
|
-
# Run tests with coverage
|
|
52
|
-
test-coverage *args:
|
|
53
|
-
export ENVIRONMENT=test; export COVERAGE=true; {{ rbenv }} rspec {{ args }}
|
|
54
|
-
|
|
55
|
-
ci: lint test-coverage
|
|
56
|
-
|
|
57
|
-
alias check-all := ci
|
|
58
|
-
|
|
59
|
-
clean:
|
|
60
|
-
#!/usr/bin/env bash
|
|
61
|
-
@find . -name .DS_Store -delete -print || true
|
|
62
|
-
@rm -rf tmp/*
|
|
63
|
-
|
|
64
|
-
# Run all lefthook pre-commit hooks
|
|
65
|
-
lefthook:
|
|
66
|
-
{{ rbenv }} lefthook run pre-commit --all-files
|
|
67
|
-
|
|
68
|
-
# Print current gem version
|
|
69
|
-
version:
|
|
70
|
-
@echo "{{ version }}"
|
|
71
|
-
|
|
72
|
-
# Clobber
|
|
73
|
-
clobber:
|
|
74
|
-
{{ rbenv }} rake clobber
|
|
75
|
-
|
|
76
|
-
# Generate documentation
|
|
77
|
-
doc:
|
|
78
|
-
#!/usr/bin/env bash
|
|
79
|
-
{{ rbenv }} rake doc
|
|
80
|
-
|
|
81
|
-
# `gem push` rather than `rake release`: release also guards the tree, tags and
|
|
82
|
-
# pushes git — which `just release` does deliberately and separately — and it
|
|
83
|
-
# gives no way to pass a 2FA code, so it always stopped to prompt.
|
|
84
|
-
#
|
|
85
|
-
# The code comes from 1Password unless one is passed in:
|
|
86
|
-
#
|
|
87
|
-
# just publish # read the code from 1Password
|
|
88
|
-
# just publish 123456 # use this code
|
|
89
|
-
#
|
|
90
|
-
# `just publish-all` in agent-lock-tools passes one, because a TOTP is single-use:
|
|
91
|
-
# four gems reading the same 30-second window would have the second push
|
|
92
|
-
# rejected as a replay.
|
|
93
|
-
#
|
|
94
|
-
# Build the .gem and push it to RubyGems, non-interactively
|
|
95
|
-
publish otp="": build
|
|
96
|
-
#!/usr/bin/env bash
|
|
97
|
-
set -euo pipefail
|
|
98
|
-
eval "$(rbenv init - bash 2>/dev/null || true)"
|
|
99
|
-
|
|
100
|
-
mkdir -p pkg
|
|
101
|
-
gem build {{ gem_name }}.gemspec --output "{{ gem_file }}"
|
|
102
|
-
|
|
103
|
-
# `|| true` is load-bearing: under `set -e` a failed `op read` — not signed
|
|
104
|
-
# in to 1Password, item renamed, op not installed — would abort the recipe
|
|
105
|
-
# before the prompting fallback below could run.
|
|
106
|
-
otp="{{ otp }}"
|
|
107
|
-
[[ -n "${otp}" ]] || otp=$({{ op }} read "{{ otp_ref }}" 2>/dev/null || true)
|
|
108
|
-
|
|
109
|
-
if [[ -n "${otp}" ]]; then
|
|
110
|
-
{{ rbenv }} gem push "{{ gem_file }}" --otp "${otp}"
|
|
111
|
-
else
|
|
112
|
-
echo "rubygems: no OTP available — gem push will prompt if 2FA is required."
|
|
113
|
-
{{ rbenv }} gem push "{{ gem_file }}" --no-document
|
|
114
|
-
fi
|
|
115
|
-
|
|
116
|
-
# Only reachable when the push succeeded: `set -e` aborts the recipe on a
|
|
117
|
-
# non-zero `gem push`, so the page never opens for a release that failed.
|
|
118
|
-
echo "published {{ gem_name }} {{ version }} → {{ gem_url }}"
|
|
119
|
-
open "{{ gem_url }}" 2>/dev/null || xdg-open "{{ gem_url }}" 2>/dev/null || true
|
|
120
|
-
|
|
121
|
-
# Tag v{{ version }}, publish the GH release, & refresh the Homebrew tap.
|
|
122
|
-
release:
|
|
123
|
-
git fetch --tags
|
|
124
|
-
git tag -f "v{{ version }}"
|
|
125
|
-
git push -f --tags
|
|
126
|
-
gh release delete -y "v{{ version }}" --repo {{ repo }} 2>/dev/null || true
|
|
127
|
-
gh release create "v{{ version }}" --generate-notes --repo {{ repo }}
|