hive-tasks 1.5.0 → 1.7.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,56 @@ All notable changes to this project are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
5
5
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.7.0] - 2026-12-04
8
+
9
+ ### Changed
10
+
11
+ - claim is announcement-only. A card claim always succeeds; the scope paths are
12
+ announced on the hive-consensus lease board instead of being taken as exclusive
13
+ leases. The latest announcer per key wins, and a live announcement by another agent
14
+ is reported as an overlap in the claim event and in `--json`, never as a refusal.
15
+ - done, fail, retry, reopen and rm --force release the announcements the claim owns; a
16
+ release only deletes the blob this claim still wrote, so a newer announcer survives.
17
+ - Two agents may claim two cards whose scope overlaps, which is what the queue needs;
18
+ merge-on-commit reconciles the edits at commit time.
19
+
20
+ ### Removed
21
+
22
+ - The `path busy` refusal and the card-revert branch behind it.
23
+
24
+ ### Tests
25
+
26
+ - 43 node:test scenarios: the original 41 unchanged, plus two cards on one scope claimed
27
+ by different agents (both claimed, both visible on the hive board, overlap reported)
28
+ and release ownership for a superseded announcement.
29
+
30
+ ## [1.6.0] - 2026-12-04
31
+
32
+ ### Changed
33
+
34
+ - The state machine has exactly four states: pending, claimed, done and failed. The
35
+ blocked state is removed; a card that cannot proceed is failed with a reason.
36
+ - Stage runtime states are the same four. fail marks the current stage failed; a stage
37
+ with a done onFail target still rewinds the chain.
38
+ - `block` and `unblock` are no longer commands. Use `fail <id> --reason R` to mark a
39
+ failure and `retry <id> [--stage KEY]` to return a failed card to pending.
40
+ - Events `task_block` and `task_unblock` are no longer emitted; a failure is `task_fail`.
41
+
42
+ ### Removed
43
+
44
+ - The blocked card state and stage state from the CLI, list/ready/stats output, SPEC and
45
+ both READMEs; the block and unblock commands; their events.
46
+
47
+ ### Tests
48
+
49
+ - 41 node:test scenarios: the four-state behaviour, fail/retry on plain and staged
50
+ cards, ready excluding failed cards, stats counting only the four states, and the
51
+ removal of block/unblock as commands.
52
+
53
+ ### Published
54
+
55
+ - npm: `hive-tasks@1.6.0` on 2026-12-04.
56
+
7
57
  ## [1.5.0] - 2026-12-04
8
58
 
9
59
  ### Added
@@ -24,6 +74,10 @@ All notable changes to this project are documented here. The format follows
24
74
  release, the task_delete event, unknown ids, the non-idempotent second delete and
25
75
  --json output.
26
76
 
77
+ ### Published
78
+
79
+ - npm: `hive-tasks@1.5.0` on 2026-12-04.
80
+
27
81
  ## [1.4.0] - 2026-12-04
28
82
 
29
83
  ### Added
package/README.md CHANGED
@@ -12,7 +12,7 @@ refs/hive/v1/tasks -> tree
12
12
  auth-token-a1b2 -> blob (the card)
13
13
  ```
14
14
 
15
- No server, no database, no queue process. A claim is a compare-and-swap on that one ref, so exactly one agent wins, and the paths it touches are leased through [hive-consensus](https://github.com/d86e/hive-consensus) at the same time.
15
+ No server, no database, no queue process. A claim is a compare-and-swap on that one ref, so exactly one agent wins a card; the paths it touches are announced on the [hive-consensus](https://github.com/d86e/hive-consensus) board, where overlaps are visible information rather than a refusal.
16
16
 
17
17
  > ~1,400 lines, zero dependencies, git >= 2.40
18
18
 
@@ -69,17 +69,16 @@ token-tests-ba66 pending tester token tests
69
69
  | show <id> [--json] | one card, its stage chain, and the resolved role source |
70
70
  | ready [--limit N] [--role R] [--json] | pending cards whose dependencies are done, ordered by priority then age |
71
71
  | next [--role R] | the single best candidate |
72
- | claim <id> --agent A [--ttl 5m] | card CAS, then hive leases on the scope |
72
+ | claim <id> --agent A [--ttl 5m] | card CAS, then announce the scope paths on the hive-consensus board |
73
73
  | renew <id> [--ttl 5m] | extend a claim so a long run is not stolen |
74
- | done <id> [--sha S] [--verdict pass\|fail] [--verify] | finish, release leases, record resultCommit; on a staged card it opens the next stage; --verify runs the current stage acceptance first |
74
+ | done <id> [--sha S] [--verdict pass\|fail] [--verify] | finish, release the claim's announcements, record resultCommit; on a staged card it opens the next stage; --verify runs the current stage acceptance first |
75
75
  | plan --file plan.json | create a whole dependency tree in one transaction |
76
76
  | fail <id> --reason R | failure is data: attempt stays; a stage with a done onFail target rewinds instead |
77
- | retry <id> [--stage KEY] | failed or blocked back to pending (or reset a chain to KEY) |
78
- | block <id> --reason R / unblock <id> | park a card without losing it |
79
- | reopen <id> [--reason R] [--agent A] [--stage KEY] | every state back to pending; clears owner, claim, result and verdict, attempt + 1; releases the claim's leases; a staged card resets to KEY (default the first stage) |
80
- | rm <id> [--force] [--json] | delete a pending/failed/blocked/done card; a claimed card is refused (exit 2) unless --force, which releases its leases first |
77
+ | retry <id> [--stage KEY] | failed back to pending (or reset a chain to KEY) |
78
+ | reopen <id> [--reason R] [--agent A] [--stage KEY] | every state back to pending; clears owner, claim, result and verdict, attempt + 1; releases the claim's announcements; a staged card resets to KEY (default the first stage) |
79
+ | rm <id> [--force] [--json] | delete a pending/failed/done card; a claimed card is refused (exit 2) unless --force, which releases its announcements first |
81
80
 
82
- Exit codes: 0 done, 1 internal error, 2 refused (already claimed, wrong state, dependency missing, mode freeze, path busy).
81
+ Exit codes: 0 done, 1 internal error, 2 refused (already claimed, wrong state, dependency missing, mode freeze).
83
82
 
84
83
  ## Resource keys
85
84
 
@@ -91,8 +90,9 @@ hive-tasks add --title "run the dev server" --scope src/web --scope resource:por
91
90
  hive-tasks add --title "migrate" --scope resource:db:dev
92
91
  ~~~
93
92
 
94
- Two cards that name the same resource cannot be claimed at the same time, which is the
95
- same guarantee files get. Nothing else is required: no daemon watches ports.
93
+ Two cards that name the same resource can be claimed at the same time: the claim
94
+ announces the key and reports an existing live announcement as an overlap. Nothing else
95
+ is required: no daemon watches ports, and no claim is refused because of one.
96
96
 
97
97
  ## Stats
98
98
 
@@ -105,11 +105,15 @@ Counts by state and role, plus the oldest pending card.
105
105
 
106
106
  ## How a claim works
107
107
 
108
- 1. the card CAS moves pending -> claimed in the task tree (one winner);
109
- 2. the scope paths are claimed as hive leases, all or nothing;
110
- 3. if a lease is refused, the card is reverted to pending with a reason.
108
+ 1. the card CAS moves pending -> claimed in the task tree (one winner per card);
109
+ 2. every scope path is announced on the hive-consensus lease board; the latest
110
+ announcement wins and a live announcement by another agent is reported as an
111
+ overlap;
112
+ 3. done, fail, retry, reopen and rm --force release the announcements their claim owns.
111
113
 
112
- Reverting is another CAS we own, so a lost race never strands a lease. The card is the authority; the leases are the courtesy that keeps two agents out of the same file.
114
+ Announcements never refuse a card: two agents may hold two cards whose scope overlaps,
115
+ which is exactly what the queue must allow. merge-on-commit reconciles the two edits at
116
+ commit time; the card is the authority, the announcement is visibility for the board.
113
117
 
114
118
  ## When an agent dies
115
119
 
@@ -136,11 +140,11 @@ stale-card-1a2b deleted [pending] stale card
136
140
 
137
141
  $ hive-tasks rm working-card-9f8e
138
142
  hive-tasks: task working-card-9f8e is claimed by agent-A; release or reopen it first, or use --force # exit 2
139
- $ hive-tasks rm working-card-9f8e --force # releases the claim's leases, then deletes
143
+ $ hive-tasks rm working-card-9f8e --force # releases the claim's announcements, then deletes
140
144
  ~~~
141
145
 
142
- pending, failed, blocked and done cards are deletable. A claimed card is protected on
143
- purpose: delete it with --force, which releases exactly that claim's hive leases first, so
146
+ pending, failed and done cards are deletable. A claimed card is protected on
147
+ purpose: delete it with --force, which releases exactly that claim's announcements first, so
144
148
  no lease is stranded. An unknown id is exit 2, and a second delete reports "no such task"
145
149
  instead of pretending to succeed.
146
150
 
@@ -203,7 +207,7 @@ created without stages keep the old single-implicit-stage behaviour, stored blob
203
207
 
204
208
  ## Role resolution
205
209
 
206
- A role is a free string, never an enum, so resolving one must never block a card. show
210
+ A role is a free string, never an enum, so resolving one must never refuse a card. show
207
211
  prints where the role came from:
208
212
 
209
213
  ~~~bash
package/README.zh-CN.md CHANGED
@@ -12,7 +12,7 @@ refs/hive/v1/tasks -> 一棵树
12
12
  auth-token-a1b2 -> blob(任务卡)
13
13
  ```
14
14
 
15
- 没有服务端、没有数据库、没有队列进程。认领就是对这个 ref 的一次 CAS,所以只有一个 agent 能赢;它要碰的路径同时在 [hive-consensus](https://github.com/d86e/hive-consensus) 里被租下。
15
+ 没有服务端、没有数据库、没有队列进程。认领就是对这个 ref 的一次 CAS,所以一张卡只有一个 agent 能赢;它要碰的路径会公告到 [hive-consensus](https://github.com/d86e/hive-consensus) 的看板上,重叠只是可见的信息,不会拒绝任何认领。
16
16
 
17
17
  > 约 1,400 行 · 零依赖 · git >= 2.40
18
18
 
@@ -69,17 +69,16 @@ token-tests-ba66 pending tester token 测试
69
69
  | show <id> [--json] | 单张卡、它的阶段链,以及解析到的角色来源 |
70
70
  | ready [--limit N] [--role R] [--json] | 依赖已完成的 pending 卡,按优先级、再按时间排序 |
71
71
  | next [--role R] | 只给最优的那一张 |
72
- | claim <id> --agent A [--ttl 5m] | 先卡片 CAS,再对 scope 拿 hive 租约 |
72
+ | claim <id> --agent A [--ttl 5m] | 先卡片 CAS,再把 scope 路径公告到 hive-consensus 看板 |
73
73
  | renew <id> [--ttl 5m] | 续期认领,长任务不会被抢 |
74
- | done <id> [--sha S] [--verdict pass\|fail] [--verify] | 完成、释放租约、记录 resultCommit;带阶段的卡会打开下一阶段;--verify 先跑当前阶段的验收 |
74
+ | done <id> [--sha S] [--verdict pass\|fail] [--verify] | 完成、释放认领的公告、记录 resultCommit;带阶段的卡会打开下一阶段;--verify 先跑当前阶段的验收 |
75
75
  | plan --file plan.json | 一次事务创建整棵依赖树 |
76
76
  | fail <id> --reason R | 失败是数据:attempt 保留;阶段有已 done 的 onFail 目标时改为回退 |
77
- | retry <id> [--stage KEY] | failed 或 blocked 回到 pending(或把链复位到 KEY) |
78
- | block <id> --reason R / unblock <id> | 挂起而不丢卡 |
79
- | reopen <id> [--reason R] [--agent A] [--stage KEY] | 任何状态回到 pending;清 owner、认领、结果与判定,attempt + 1;释放认领时的租约;带阶段的卡复位到 KEY(默认第一阶段) |
80
- | rm <id> [--force] [--json] | 删除 pending/failed/blocked/done 的卡;claimed 的卡默认拒绝(退出码 2),加 --force 会先释放租约再删 |
77
+ | retry <id> [--stage KEY] | failed 回到 pending(或把链复位到 KEY) |
78
+ | reopen <id> [--reason R] [--agent A] [--stage KEY] | 任何状态回到 pending;清 owner、认领、结果与判定,attempt + 1;释放认领时的公告;带阶段的卡复位到 KEY(默认第一阶段) |
79
+ | rm <id> [--force] [--json] | 删除 pending/failed/done 的卡;claimed 的卡默认拒绝(退出码 2),加 --force 会先释放公告再删 |
81
80
 
82
- 退出码:0 成功,1 内部错误,2 被拒(已被认领、状态不对、依赖缺失、模式 freeze、路径忙)。
81
+ 退出码:0 成功,1 内部错误,2 被拒(已被认领、状态不对、依赖缺失、模式 freeze)。
83
82
 
84
83
  ## 资源 key
85
84
 
@@ -90,7 +89,7 @@ hive-tasks add --title "起 dev server" --scope src/web --scope resource:port:30
90
89
  hive-tasks add --title "跑迁移" --scope resource:db:dev
91
90
  ~~~
92
91
 
93
- 两张卡写了同一个资源,就不可能同时被认领——和文件拿到的是同一种保证。不需要额外的东西:没有守护进程去盯端口。
92
+ 两张卡写了同一个资源,可以同时被认领:后一次认领会公告这个 key,并把人家的存活公告作为 overlap 返回。不需要额外的东西:没有守护进程去盯端口,也没有认领会因此被拒。
94
93
 
95
94
  ## 统计
96
95
 
@@ -103,11 +102,11 @@ hive-tasks stats --json
103
102
 
104
103
  ## claim 怎么走
105
104
 
106
- 1. 卡片 CAS 把 pending 推到 claimed(唯一赢家);
107
- 2. 对 scope 里的路径拿 hive 租约,要么全拿要么不拿;
108
- 3. 租约被拒就把卡 CAS 回 pending 并记原因。
105
+ 1. 卡片 CAS 把 pending 推到 claimed(一张卡唯一赢家);
106
+ 2. scope 里每个路径都公告到 hive-consensus 的租约看板:后来者覆盖公告,别人的存活公告作为 overlap 返回;
107
+ 3. done、fail、retry、reopen 和 rm --force 释放这次认领自己写的公告。
109
108
 
110
- 回滚是我们自己持有的另一次 CAS,所以输掉竞争不会泄漏租约。**卡是权威,租约是礼貌**——它只是让两个 agent 不去碰同一个文件。
109
+ 公告永远不拒绝认领:两个 agent 可以同时持有 scope 重叠的两张卡,队列本来就该允许这种情况。真正撞车的改动由 merge-on-commit 在提交时合并;**卡是权威,公告是看板上的可见性**。
111
110
 
112
111
  ## agent 中途死掉怎么办
113
112
 
@@ -135,7 +134,7 @@ hive-tasks: task working-card-9f8e is claimed by agent-A; release or reopen it f
135
134
  $ hive-tasks rm working-card-9f8e --force # 先释放认领时的租约,再删除
136
135
  ~~~
137
136
 
138
- pending、failed、blocked、done 的卡都可以删。claimed 的卡是**故意保护**的:要加
137
+ pending、failed、done 的卡都可以删。claimed 的卡是**故意保护**的:要加
139
138
  --force 才删,并且会先释放这次认领持有的 hive 租约,不会留下孤儿租约。未知 id 退出码
140
139
  为 2;第二次删除会报 "no such task",不会静默成功。
141
140
 
package/SPEC.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # hive-tasks protocol
2
2
 
3
- Status: implemented, 1.4.0. Protocol version v1 (card blobs keep `v: 1`).
3
+ Status: implemented, 1.7.0. Protocol version v1 (card blobs keep `v: 1`).
4
4
 
5
5
  ## 1. Scope
6
6
 
@@ -85,13 +85,13 @@ Implementation sketch (plumbing, no working tree involved):
85
85
  | --- | --- |
86
86
  | goal | what the worker should achieve; free text, no format |
87
87
  | role | who may claim: a role name the team agrees on (coder, tester, reviewer, ...). For a staged card it is the fallback/display role; routing uses the stage role |
88
- | scope | paths or resource keys the task expects to touch; used for hive leases. A resource key is any stable string such as resource:port:3000 |
88
+ | scope | paths or resource keys the task expects to touch; announced on the hive-consensus lease board, where a live overlap is information, never a refusal. A resource key is any stable string such as resource:port:3000 |
89
89
  | after | ids that must be done before this becomes ready |
90
90
  | state | see below |
91
91
  | owner | agent id while claimed |
92
92
  | attempt | incremented on every claim and every reopen, and on an onFail rewind; used to stop retry loops |
93
93
  | verdict | pass or fail, copied from the hive verdict when the card itself is done |
94
- | reason | why the card is in its current state: the text passed to fail, block or reopen, or "test failed: ..." after a review reflow |
94
+ | reason | why the card is in its current state: the text passed to fail or reopen, or "test failed: ..." after a review reflow |
95
95
  | reviewOf | id of the card this review card tests; the id is also added to after, so the review is ready only when its upstream is done |
96
96
  | tags | free labels; "fix" is special (see mode) |
97
97
  | acceptance | optional shell command; used by done --verify when the card has no stages |
@@ -99,7 +99,7 @@ Implementation sketch (plumbing, no working tree involved):
99
99
  | resultCommit | the commit recorded when the card or its current stage was finished |
100
100
  | stages | optional ordered stage chain. Absent or [] means a card without stages |
101
101
  | stage | current stage key, or null for a card without stages |
102
- | stageState | state of the current stage: pending, claimed, done, failed, blocked; null for a card without stages |
102
+ | stageState | state of the current stage: pending, claimed, done, failed; null for a card without stages |
103
103
 
104
104
  Fields at the end are only stored when the card has stages. A card created without
105
105
  `--stage`/`--stages` has exactly the 1.3.0 blob: `stages`, `stage` and
@@ -113,7 +113,7 @@ Fields at the end are only stored when the card has stages. A card created witho
113
113
  role: coder # any string, not enumerated
114
114
  acceptance: "npm test" # optional, used by done --verify at this stage
115
115
  onFail: code # optional, the key to rewind to when this stage fails
116
- state: pending # runtime: pending | claimed | done | failed | blocked
116
+ state: pending # runtime: pending | claimed | done | failed
117
117
  ```
118
118
 
119
119
  | Field | Meaning |
@@ -121,7 +121,7 @@ Fields at the end are only stored when the card has stages. A card created witho
121
121
  | key | unique and stable inside the card; the stage identifier |
122
122
  | role | free-form role name; resolved to an adapter/model/prompt by the dispatcher (section 7) |
123
123
  | acceptance | optional command; done --verify runs the current stage's command before it advances |
124
- | onFail | optional key of an earlier stage. When this stage fails or is blocked and that target is done, the chain rewinds to it instead of failing the card |
124
+ | onFail | optional key of an earlier stage. When this stage fails and that target is done, the chain rewinds to it instead of failing the card |
125
125
  | state | runtime stage state, maintained by every transition |
126
126
 
127
127
  Stage state and card state move together for the current stage: a claimed stage means
@@ -133,13 +133,11 @@ Once a non-final stage is done the card returns to pending while the next stage
133
133
  ```
134
134
  claim
135
135
  pending ─────────────────────▶ claimed
136
- ▲ │ │ │
137
- │ │ │ └── block ─▶ blocked
136
+ ▲ │ │
138
137
  │ │ └──── fail ──▶ failed
139
138
  │ └───── done ───▶ done
140
139
  │
141
- ├── retry (failed, blocked)
142
- ├── unblock (blocked)
140
+ ├── retry (failed)
143
141
  └── reopen (every stored state)
144
142
  ```
145
143
 
@@ -147,44 +145,38 @@ Once a non-final stage is done the card returns to pending while the next stage
147
145
  card back to pending, clears owner, claimedUntil, resultCommit and verdict, keeps attempt
148
146
  and increments it, records reason (default "reopened") and writes a reopen event.
149
147
  Reopening a pending card is a no-op (exit 0) and does not change attempt. Reopening a
150
- claimed card releases its hive leases, so no orphan lease is left behind. On a staged
148
+ claimed card releases its announcements, so no orphan announcement is left behind. On a staged
151
149
  card reopen always resets the chain (default first stage, --stage KEY selects another),
152
150
  including a card that is currently pending.
153
151
 
154
152
  `rm` is the only destructive command: it removes the card's blob from the task tree in
155
- one CAS. pending, failed, blocked and done cards are deletable. A claimed card is refused
153
+ one CAS. pending, failed and done cards are deletable. A claimed card is refused
156
154
  (exit 2, with a hint to release or reopen it) unless --force is given; --force releases
157
- exactly that claim's hive leases and then deletes the card, so a forced delete cannot
158
- strand a lease. Deleting a card is not idempotent: an unknown id is exit 2, and a second
155
+ exactly that claim's announcements and then deletes the card, so a forced delete cannot
156
+ strand an announcement. Deleting a card is not idempotent: an unknown id is exit 2, and a second
159
157
  `rm` of the same id reports "no such task". Cards that named the deleted id in `after`
160
158
  now have a missing dependency, which the ready computation reports as a data error.
161
159
 
162
160
  | From | Command | To | Effect |
163
161
  | --- | --- | --- | --- |
164
162
  | pending | claim | claimed | CAS winner; attempt + 1 |
165
- | claimed | done | done | releases leases; records resultCommit and verdict |
166
- | claimed | fail | failed | releases leases; attempt kept |
167
- | claimed | block | blocked | releases leases |
168
- | claimed | reopen | pending | releases leases; attempt + 1 |
163
+ | claimed | done | done | releases the claim's announcements; records resultCommit and verdict |
164
+ | claimed | fail | failed | releases the claim's announcements; attempt kept |
165
+ | claimed | reopen | pending | releases the claim's announcements; attempt + 1 |
169
166
  | done | reopen | pending | attempt + 1; clears resultCommit and verdict |
170
167
  | failed | retry | pending | attempt kept |
171
168
  | failed | reopen | pending | attempt + 1 |
172
- | blocked | unblock | pending | attempt kept |
173
- | blocked | retry | pending | attempt kept |
174
- | blocked | reopen | pending | attempt + 1 |
175
169
  | pending | reopen | pending | no-op (exit 0) |
176
- | any stored state | block | blocked | block accepts any state |
177
- | pending/failed/blocked/done | rm | deleted | removes the blob in one CAS |
178
- | claimed | rm --force | deleted | releases the claim's leases, then removes the blob |
170
+ | pending/failed/done | rm | deleted | removes the blob in one CAS |
171
+ | claimed | rm --force | deleted | releases the claim's announcements, then removes the blob |
179
172
 
180
173
  - pending: exists, dependencies not satisfied (or no capacity to run it).
181
174
  - ready: pending with every id in after in state done. Computed, never stored.
182
175
  - claimed: a dispatcher claimed it; owner and attempt are set.
183
176
  - done: owner finished and (optionally) a verdict was recorded.
184
177
  - failed: the run failed; retry moves it back to pending with attempt preserved.
185
- - blocked: cannot proceed (conflict, missing dependency, manual hold).
186
178
 
187
- Stored states are pending, claimed, done, failed, blocked. ready is always computed.
179
+ Stored states are pending, claimed, done, failed. ready is always computed.
188
180
 
189
181
  A claimed card carries claimedUntil. Once that time passes the card is **reclaimable**:
190
182
  claim may take it over exactly as if it were pending, incrementing attempt. This is how
@@ -227,15 +219,15 @@ Rules:
227
219
  (or when a claim expired, in which case the stage is reclaimed like any claim).
228
220
  done and fail accept only a claimed current stage.
229
221
  2. **Advance, do not release.** done marks the current stage done, opens the next stage
230
- (pending, owner cleared, leases released) and keeps the card pending. The last stage
222
+ (pending, owner cleared, announcements released) and keeps the card pending. The last stage
231
223
  finishes the card (state done, stageState done). done returns `nextStage` (null when
232
224
  the chain is complete).
233
- 3. **Fail stops or rewinds.** fail/block mark the current stage failed/blocked. If the
234
- stage has onFail and that target stage is done, the chain rewinds: the target and all
235
- later stages become pending, the current stage stays failed/blocked as history, the
236
- card becomes pending and ready again, and attempt is incremented. Without a usable
237
- onFail target the whole card becomes failed/blocked, exactly as before.
238
- 4. **Retry and reopen reset stages.** retry resets the failed/blocked stage (or the
225
+ 3. **Fail stops or rewinds.** fail marks the current stage failed. If the stage has
226
+ onFail and that target stage is done, the chain rewinds: the target and all later
227
+ stages become pending, the current stage stays failed as history, the card becomes
228
+ pending and ready again, and attempt is incremented. Without a usable onFail target
229
+ the whole card becomes failed, exactly as before.
230
+ 4. **Retry and reopen reset stages.** retry resets the failed stage (or the
239
231
  --stage target) to pending and keeps earlier done stages; reopen resets to the target
240
232
  (default the first stage) and increments attempt.
241
233
  5. **Acceptance is per stage.** done --verify runs the current stage acceptance, falling
@@ -245,18 +237,13 @@ Rules:
245
237
 
246
238
  | Card / stageState | Command | Result | Effect |
247
239
  | --- | --- | --- | --- |
248
- | pending / pending | claim | claimed / claimed | owner, leases, attempt + 1; stage state claimed |
249
- | claimed / claimed | done (more stages) | pending / pending at next | stage done, next pending, owner cleared, leases released; nextStage returned |
240
+ | pending / pending | claim | claimed / claimed | owner, announcements, attempt + 1; stage state claimed |
241
+ | claimed / claimed | done (more stages) | pending / pending at next | stage done, next pending, owner cleared, announcements released; nextStage returned |
250
242
  | claimed / claimed | done (last stage) | done / done | stage done; card done; resultCommit/verdict recorded |
251
243
  | claimed / claimed | fail, onFail target done | pending / pending at target | stage failed; target..end pending; attempt + 1; card ready again |
252
244
  | claimed / claimed | fail, no usable onFail | failed / failed | whole card failed; stage failed |
253
- | claimed / claimed | block, onFail target done | pending / pending at target | stage blocked; target..end pending; attempt + 1 |
254
- | claimed / claimed | block, no usable onFail | blocked / blocked | whole card blocked |
255
245
  | failed / failed | retry [--stage KEY] | pending / pending at KEY | KEY..end reset to pending, attempt kept |
256
- | blocked / blocked | unblock | pending / pending at current | current stage pending, attempt kept |
257
- | blocked / blocked | retry [--stage KEY] | pending / pending at KEY | KEY..end reset to pending, attempt kept |
258
- | any / any | reopen [--stage KEY] | pending / pending at KEY | KEY..end reset (default first), attempt + 1, leases released |
259
- | any / any | block | blocked / blocked or rewind | block accepts any state |
246
+ | any / any | reopen [--stage KEY] | pending / pending at KEY | KEY..end reset (default first), attempt + 1, announcements released |
260
247
 
261
248
  ## 5. Ready computation
262
249
 
@@ -292,8 +279,6 @@ see the same order; the claim CAS still gives exactly one winner per card.
292
279
  hive-tasks done <id> [--sha S] [--verdict pass|fail] [--verify]
293
280
  hive-tasks fail <id> --reason R
294
281
  hive-tasks retry <id> [--stage KEY]
295
- hive-tasks block <id> --reason R
296
- hive-tasks unblock <id>
297
282
  hive-tasks reopen <id> [--reason R] [--stage KEY]
298
283
  hive-tasks rm <id> [--force] [--json]
299
284
 
@@ -305,24 +290,29 @@ per-stage acceptance in one shot. The two flags are mutually exclusive.
305
290
  Exit codes: 0 success; 1 internal error; 2 refused (already claimed, wrong state,
306
291
  dependency missing, mode freeze, invalid stage chain).
307
292
 
308
- claim couples the card with the hive leases, card first:
293
+ claim couples the card with the hive-consensus announcement board, card first:
309
294
 
310
295
  1. CAS the card from pending to claimed (this is what picks the single winner);
311
- 2. claim every scope path as a hive lease, all or nothing;
312
- 3. if a lease is refused, CAS the card back to pending with a reason and exit 2.
313
-
314
- Card-first is deliberate: a lost card race costs nothing, while lease-first would leave
315
- held leases behind when the card CAS loses. Reverting the card is another CAS we own, so
316
- no state leaks. A staged card reverts its stageState to pending together with the card.
317
-
318
- done releases the leases and records the verdict (or opens the next stage). fail releases
319
- the leases and keeps the attempt counter. retry accepts failed or blocked and returns the
320
- card to pending (or resets the chain to a stage). block accepts any state; unblock
321
- accepts blocked. reopen accepts every stored state, returns the card to pending and
322
- releases a claimed card's leases (section 4). add --review-of links a review card to its
323
- upstream (section 4.1). rm deletes pending, failed, blocked and done cards, and refuses a
324
- claimed card (exit 2) unless --force, which releases the claim's leases first; it prints
325
- the deleted card (with `deleted: true`) under --json.
296
+ 2. announce every scope path (refs/hive/v1/lease/<key>/__key__). The claim always
297
+ succeeds: the latest announcement wins, and a live announcement by another agent is
298
+ returned as an overlap (in the claim event and in --json) and is otherwise ignored;
299
+ 3. done, fail, retry, reopen and rm --force release the announcements the claim owns.
300
+
301
+ Announcements are advisory and never refuse a claim: two agents may hold two cards whose
302
+ scope overlaps, and merge-on-commit reconciles the two edits at commit time. The card is
303
+ the authority; the announcement is the board's visibility. An announcement blob is
304
+ {"v": 1, "agent", "task", "key", "startedAt", "expiresAt"}; release is a
305
+ compare-and-delete of the announcement the caller still owns, so a newer announcer's blob
306
+ is never deleted by an older claim.
307
+
308
+ done releases the announcements and records the verdict (or opens the next stage). fail
309
+ releases the announcements and keeps the attempt counter. retry accepts failed cards and
310
+ returns the card to pending (or resets the chain to a stage). reopen accepts every stored
311
+ state, returns the card to pending and releases a claimed card's announcements
312
+ (section 4). add --review-of links a review card to its upstream (section 4.1). rm
313
+ deletes pending, failed and done cards, and refuses a claimed card (exit 2) unless
314
+ --force, which releases the claim's announcements first; it prints the deleted card
315
+ (with `deleted: true`) under --json.
326
316
 
327
317
  ## 7. Role resolution (dispatchers)
328
318
 
@@ -367,9 +357,9 @@ Each command appends one line to .hive/events.jsonl:
367
357
  { "ts": "...", "actor": "worker-3", "kind": "task_claim", "task": "auth-token-a1b2", "attempt": 1 }
368
358
  ```
369
359
 
370
- kinds: task_add, task_claim, task_done, task_fail, task_retry, task_block,
371
- task_unblock, task_renew, task_plan, task_delete, reopen, review_failed, stage_done,
372
- stage_failed, stage_advanced, stage_rewound.
360
+ kinds: task_add, task_claim, task_done, task_fail, task_retry, task_renew, task_plan,
361
+ task_delete, reopen, review_failed, stage_done, stage_failed, stage_advanced,
362
+ stage_rewound.
373
363
 
374
364
  `task_delete` records the removed card: it carries both `task` and `id` (the card id),
375
365
  `state` (the state the card had when it was deleted) and `actor`.
@@ -386,7 +376,7 @@ Stage events are additional lines next to the task event:
386
376
 
387
377
  ## 9. Requirements
388
378
 
389
- - hive-consensus >= 1.2.0 (leases, board, mode, verdict, events).
379
+ - hive-consensus >= 1.5.0 (announcement board, board, mode, verdict, events).
390
380
  - git >= 2.40.
391
381
  - No network, no database, no daemon.
392
382
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hive-tasks",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "Task cards for agent teams: one git tree behind one ref, with a state machine, optional stage chains, role resolution, dependencies and hive leases.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,7 @@
16
16
  "CHANGELOG.md"
17
17
  ],
18
18
  "engines": {
19
- "node": ">=20"
19
+ "node": ">=22.19"
20
20
  },
21
21
  "scripts": {
22
22
  "test": "node --test test/*.test.mjs",
@@ -43,4 +43,4 @@
43
43
  "url": "https://github.com/d86e/hive-tasks/issues"
44
44
  },
45
45
  "homepage": "https://github.com/d86e/hive-tasks#readme"
46
- }
46
+ }
package/src/cli.js CHANGED
@@ -37,13 +37,12 @@ const USAGE = [
37
37
  " hive-tasks show <id> [--json] card plus the resolved role source",
38
38
  " hive-tasks ready [--json] [--limit N] [--role R]",
39
39
  " hive-tasks next [--role R] [--json] the single best candidate",
40
- " hive-tasks claim <id> --agent A [--ttl 5m] card CAS, then hive leases",
40
+ " hive-tasks claim <id> --agent A [--ttl 5m] card CAS, then announce scope paths",
41
41
  " hive-tasks renew <id> [--ttl 5m] extend a claim",
42
42
  " hive-tasks plan --file plan.json create a whole DAG in one transaction",
43
43
  " hive-tasks done <id> [--sha S] [--verdict pass|fail] [--verify]",
44
44
  " hive-tasks fail <id> --reason R",
45
- " hive-tasks retry <id> [--stage KEY]",
46
- " hive-tasks block <id> --reason R | unblock <id>",
45
+ " hive-tasks retry <id> [--stage KEY] failed back to pending",
47
46
  " hive-tasks reopen <id> [--reason R] [--agent A] [--stage KEY]",
48
47
  " any state back to pending, attempt+1; a staged card",
49
48
  " resets to KEY (default the first stage)",
@@ -310,7 +309,7 @@ function run(argv) {
310
309
  return printTask(readTask(repo, id), options.json);
311
310
  }
312
311
 
313
- // A claimed card may still hold hive leases; release exactly the claim we reset.
312
+ // A claimed card may still hold announcements; release exactly the claim we reset.
314
313
  if (previous.state === "claimed") releaseLeases(repo, { paths: previous.scope, agent: previous.owner || agent });
315
314
  append(repo, { actor: agent, kind: "reopen", task: id, from: previous.state, reason, attempt: reopened.attempt, stage: isStaged(reopened) ? reopened.stage : undefined });
316
315
  return printTask(reopened, options.json);
@@ -345,7 +344,7 @@ function run(argv) {
345
344
  fail(error.message, 2);
346
345
  }
347
346
 
348
- // --force deletes a claimed card only after releasing exactly the leases
347
+ // --force deletes a claimed card only after releasing exactly the announcements
349
348
  // that claim holds, so a forced delete cannot strand them.
350
349
  if (deleted.state === "claimed") releaseLeases(repo, { paths: deleted.scope, agent: deleted.owner || agent });
351
350
  append(repo, { actor: agent, kind: "task_delete", task: id, id, state: deleted.state });
@@ -477,23 +476,24 @@ function run(argv) {
477
476
 
478
477
  if (!claimed) fail("could not claim " + id, 2);
479
478
 
480
- const leases = claimLeases(repo, { paths: claimed.scope, agent, ttlMs, taskId: claimed.id });
481
- if (leases.granted === false) {
482
- const holder = leases.denied[0];
483
- mutate(repo, (tasks) => tasks.map((entry) => {
484
- if (entry.id !== id) return entry;
485
- return transition(entry, "pending", { owner: null, claimedUntil: null, reason: "lease held by " + (holder ? holder.agent : "another agent"), ...stageStatePatch(entry, "pending") });
486
- }));
487
- const detail = holder ? " (" + holder.agent + " holds " + holder.key + ")" : "";
488
- fail("could not claim " + id + ": path busy" + detail, 2);
489
- }
490
-
479
+ // Announcements are information, never a gate: the card claim already
480
+ // succeeded, and a live announcement by someone else is reported as an
481
+ // overlap instead of reverting the card.
482
+ const announcements = claimLeases(repo, { paths: claimed.scope, agent, ttlMs, taskId: claimed.id });
491
483
  publishPresence(repo, { agent, task: claimed, state: "working", files: claimed.scope });
492
- append(repo, { actor: agent, kind: "task_claim", task: claimed.id, attempt: claimed.attempt, stage: isStaged(claimed) ? claimed.stage : undefined });
493
- return printTask(claimed, options.json);
484
+ append(repo, {
485
+ actor: agent,
486
+ kind: "task_claim",
487
+ task: claimed.id,
488
+ attempt: claimed.attempt,
489
+ stage: isStaged(claimed) ? claimed.stage : undefined,
490
+ ...(announcements.overlaps.length > 0 ? { overlaps: announcements.overlaps } : {}),
491
+ });
492
+ const extra = announcements.overlaps.length > 0 ? { overlaps: announcements.overlaps } : {};
493
+ return printTask(claimed, options.json, extra);
494
494
  }
495
495
 
496
- if (command === "done" || command === "fail" || command === "retry" || command === "block" || command === "unblock") {
496
+ if (command === "done" || command === "fail" || command === "retry") {
497
497
  const id = options.args[0];
498
498
  if (!id) fail(command + " needs a task id", 2);
499
499
  const agent = options.agent || process.env.HIVE_AGENT || "unknown";
@@ -506,8 +506,7 @@ function run(argv) {
506
506
 
507
507
  if ((command === "done" || command === "fail") && current.state !== "claimed") fail("task " + id + " is " + current.state + ", not claimed", 2);
508
508
  if ((command === "done" || command === "fail") && isStaged(current) && current.stageState !== "claimed") fail("task " + id + " stage " + current.stage + " is " + current.stageState + ", not claimed", 2);
509
- if (command === "retry" && current.state !== "failed" && current.state !== "blocked") fail("task " + id + " is " + current.state + ", not failed or blocked", 2);
510
- if (command === "unblock" && current.state !== "blocked") fail("task " + id + " is " + current.state + ", not blocked", 2);
509
+ if (command === "retry" && current.state !== "failed") fail("task " + id + " is " + current.state + ", not failed", 2);
511
510
 
512
511
  if (command === "done" && options.verify) {
513
512
  const acceptance = isStaged(current) ? ((currentStage(current) || {}).acceptance || current.acceptance) : current.acceptance;
@@ -564,19 +563,6 @@ function run(argv) {
564
563
  }
565
564
  return { targetState: "failed", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null }, events: [] };
566
565
  }
567
- if (command === "block") {
568
- if (isStaged(task)) {
569
- const blocked = failStage(task, "blocked");
570
- const events = blocked.rewound ? [{ kind: "stage_rewound", from: blocked.from, stage: blocked.to, attempt: (task.attempt || 0) + 1 }] : [];
571
- return {
572
- targetState: blocked.rewound ? "pending" : "blocked",
573
- nextStage: null,
574
- patch: { owner: null, claimedUntil: null, reason: options.reason || null, ...blocked.patch },
575
- events,
576
- };
577
- }
578
- return { targetState: "blocked", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null }, events: [] };
579
- }
580
566
  if (command === "retry") {
581
567
  if (isStaged(task)) {
582
568
  const reset = resetStage(task, target || task.stage);
@@ -584,11 +570,6 @@ function run(argv) {
584
570
  }
585
571
  return { targetState: "pending", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null }, events: [] };
586
572
  }
587
- // unblock
588
- if (isStaged(task)) {
589
- return { targetState: "pending", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null, ...stageStatePatch(task, "pending") }, events: [] };
590
- }
591
- return { targetState: "pending", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null }, events: [] };
592
573
  }
593
574
 
594
575
  // A review card that fails sends its upstream card back to pending, so a
package/src/lease.js CHANGED
@@ -39,40 +39,93 @@ export function readMode(repo) {
39
39
  return (readBlob(repo, MODE_REF) || { mode: "free" }).mode;
40
40
  }
41
41
 
42
- /** Claim every scope path or none of them. An expired lease is taken over. */
42
+ /** One consistent observation of a lease ref: its sha and parsed blob. */
43
+ function readEntry(repo, ref) {
44
+ const rev = git(["rev-parse", "--verify", "--quiet", ref], { cwd: repo.top, allowFail: true });
45
+ if (rev.status !== 0) return { sha: null, value: null };
46
+ const sha = rev.stdout.trim();
47
+ try {
48
+ return { sha, value: JSON.parse(out(["cat-file", "blob", sha], { cwd: repo.top })) };
49
+ } catch {
50
+ return { sha, value: null };
51
+ }
52
+ }
53
+
54
+ /** Write one announcement with no compare-and-swap: the last announcer wins. */
55
+ function replaceAnnouncement(repo, ref, value) {
56
+ const blob = out(["hash-object", "-w", "--stdin"], { cwd: repo.top, input: JSON.stringify(value) });
57
+ return git(["update-ref", ref, blob], { cwd: repo.top, allowFail: true }).status === 0;
58
+ }
59
+
60
+ /**
61
+ * Announce every scope path. Announcements never fail and never block a claim.
62
+ *
63
+ * The consensus layer is a shared announcement board: the latest announcer per
64
+ * key wins, and a live announcement by another agent is reported as an overlap
65
+ * (information) instead of refusing the card. merge-on-commit reconciles two
66
+ * agents writing the same file at commit time.
67
+ *
68
+ * Returns { granted: true, keys, overlaps: [{ key, agent, task, expiresAt }] }.
69
+ */
43
70
  export function claimLeases(repo, { paths, agent, ttlMs, taskId }) {
44
- const keys = paths.map(toKey);
45
- if (keys.length === 0) return { granted: true, denied: [] };
71
+ const keys = [];
72
+ for (const path of paths) {
73
+ const key = toKey(path);
74
+ if (!keys.includes(key)) keys.push(key);
75
+ }
76
+ if (keys.length === 0) return { granted: true, keys, overlaps: [] };
46
77
 
47
- const now = Date.now();
48
- const lines = ["start"];
49
- const denied = [];
78
+ let overlaps = [];
79
+ for (let attempt = 0; attempt < 8; attempt++) {
80
+ const now = Date.now();
81
+ const entries = new Map();
82
+ overlaps = [];
83
+ for (const key of keys) {
84
+ const entry = readEntry(repo, leaseRef(key));
85
+ entries.set(key, entry);
86
+ const current = entry.value;
87
+ if (
88
+ current &&
89
+ Date.parse(current.expiresAt) > now &&
90
+ (current.agent !== agent || (current.task || "") !== (taskId || ""))
91
+ ) {
92
+ overlaps.push({ key, agent: current.agent, task: current.task || "", expiresAt: current.expiresAt });
93
+ }
94
+ }
50
95
 
51
- for (const key of keys) {
52
- const ref = leaseRef(key);
53
- const current = readBlob(repo, ref);
54
- if (current && current.agent !== agent && Date.parse(current.expiresAt) > now) {
55
- denied.push({ key, agent: current.agent, expiresAt: current.expiresAt });
56
- continue;
96
+ const lines = ["start"];
97
+ for (const key of keys) {
98
+ const entry = entries.get(key);
99
+ const value = {
100
+ v: 1,
101
+ agent,
102
+ task: taskId || "",
103
+ key,
104
+ startedAt: new Date(now).toISOString(),
105
+ expiresAt: new Date(now + ttlMs).toISOString(),
106
+ };
107
+ const blob = out(["hash-object", "-w", "--stdin"], { cwd: repo.top, input: JSON.stringify(value) });
108
+ lines.push("update " + leaseRef(key) + " " + blob + " " + (entry.sha || "0".repeat(blob.length)));
57
109
  }
58
- const value = {
110
+ lines.push("prepare", "commit");
111
+ const result = git(["update-ref", "--stdin"], { cwd: repo.top, input: lines.join("\n") + "\n", allowFail: true });
112
+ if (result.status === 0) return { granted: true, keys, overlaps };
113
+ }
114
+
115
+ // Announcements are advisory: after repeated contention the last write wins
116
+ // instead of turning an announcement into a failure.
117
+ const now = Date.now();
118
+ for (const key of keys) {
119
+ replaceAnnouncement(repo, leaseRef(key), {
59
120
  v: 1,
60
121
  agent,
61
122
  task: taskId || "",
62
123
  key,
63
124
  startedAt: new Date(now).toISOString(),
64
125
  expiresAt: new Date(now + ttlMs).toISOString(),
65
- };
66
- const blob = out(["hash-object", "-w", "--stdin"], { cwd: repo.top, input: JSON.stringify(value) });
67
- const currentSha = git(["rev-parse", "--verify", "--quiet", ref], { cwd: repo.top, allowFail: true }).stdout.trim();
68
- lines.push("update " + ref + " " + blob + " " + (currentSha || "0".repeat(blob.length)));
126
+ });
69
127
  }
70
-
71
- if (denied.length > 0) return { granted: false, denied };
72
-
73
- lines.push("prepare", "commit");
74
- const result = git(["update-ref", "--stdin"], { cwd: repo.top, input: lines.join("\n") + "\n", allowFail: true });
75
- return { granted: result.status === 0, denied: [], stderr: (result.stderr || "").trim() };
128
+ return { granted: true, keys, overlaps };
76
129
  }
77
130
 
78
131
  export function releaseLeases(repo, { paths, agent }) {
package/src/role.js CHANGED
@@ -9,7 +9,7 @@ import path from "node:path";
9
9
  * 2. default the name is one of the built-in roles (adapter dsh, model null,
10
10
  * prompt from .hive/roles/<name>.md when that file exists)
11
11
  * 3. synthetic a generated generic contract for any other name, so a card is
12
- * never blocked because the team has no role config for it
12
+ * never refused because the team has no role config for it
13
13
  *
14
14
  * The returned object shape is stable and is what the runner/supervisor should
15
15
  * consume:
package/src/stage.js CHANGED
@@ -5,11 +5,11 @@
5
5
  * null, and every legacy path behaves exactly as it did in 1.3.0.
6
6
  *
7
7
  * A stage stores its configuration (key, role, acceptance, onFail) plus its
8
- * runtime state (pending, claimed, done, failed, blocked). The card records
8
+ * runtime state (pending, claimed, done, failed). The card records
9
9
  * the current stage and its state in stage / stageState.
10
10
  */
11
11
 
12
- export const STAGE_STATES = ["pending", "claimed", "done", "failed", "blocked"];
12
+ export const STAGE_STATES = ["pending", "claimed", "done", "failed"];
13
13
  export const STAGE_KEY_RE = /^[a-z][a-z0-9-]{0,31}$/;
14
14
 
15
15
  export function isStaged(task) {
@@ -149,7 +149,7 @@ export function stageView(task) {
149
149
  };
150
150
  }
151
151
 
152
- /** Set the current stage's runtime state (claim, lease revert, unblock). */
152
+ /** Set the current stage's runtime state (claim, lease revert, retry). */
153
153
  export function stageStatePatch(task, state) {
154
154
  if (!isStaged(task)) return {};
155
155
  const index = stageIndex(task, task.stage);
@@ -183,7 +183,7 @@ export function advanceStage(task) {
183
183
  }
184
184
 
185
185
  /**
186
- * Fail or block the current stage. When the stage names an onFail target that
186
+ * Fail the current stage. When the stage names an onFail target that
187
187
  * is already done, the chain rewinds to it (target pending, later stages
188
188
  * pending, attempt + 1) and the card stays runnable. Otherwise the whole card
189
189
  * takes the failure state.
package/src/task.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import crypto from "node:crypto";
2
2
  import { initialStageFields, isStageReady } from "./stage.js";
3
3
 
4
- export const STATES = ["pending", "claimed", "done", "failed", "blocked"];
4
+ export const STATES = ["pending", "claimed", "done", "failed"];
5
5
  export const ROLES = ["coder", "tester", "reviewer", "researcher", "planner", "worker"];
6
6
 
7
7
  export function slug(title) {