hive-tasks 1.4.0 → 1.6.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 +52 -0
- package/README.md +21 -3
- package/README.zh-CN.md +19 -2
- package/SPEC.md +38 -37
- package/package.json +3 -3
- package/src/cli.js +41 -23
- package/src/role.js +1 -1
- package/src/stage.js +4 -4
- package/src/task.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,53 @@ 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.6.0] - 2026-12-04
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- The state machine has exactly four states: pending, claimed, done and failed. The
|
|
12
|
+
blocked state is removed; a card that cannot proceed is failed with a reason.
|
|
13
|
+
- Stage runtime states are the same four. fail marks the current stage failed; a stage
|
|
14
|
+
with a done onFail target still rewinds the chain.
|
|
15
|
+
- `block` and `unblock` are no longer commands. Use `fail <id> --reason R` to mark a
|
|
16
|
+
failure and `retry <id> [--stage KEY]` to return a failed card to pending.
|
|
17
|
+
- Events `task_block` and `task_unblock` are no longer emitted; a failure is `task_fail`.
|
|
18
|
+
|
|
19
|
+
### Removed
|
|
20
|
+
|
|
21
|
+
- The blocked card state and stage state from the CLI, list/ready/stats output, SPEC and
|
|
22
|
+
both READMEs; the block and unblock commands; their events.
|
|
23
|
+
|
|
24
|
+
### Tests
|
|
25
|
+
|
|
26
|
+
- 41 node:test scenarios: the four-state behaviour, fail/retry on plain and staged
|
|
27
|
+
cards, ready excluding failed cards, stats counting only the four states, and the
|
|
28
|
+
removal of block/unblock as commands.
|
|
29
|
+
|
|
30
|
+
## [1.5.0] - 2026-12-04
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- `rm <id> [--force] [--json]`: delete a task card. pending, failed, blocked and done
|
|
35
|
+
cards are removed by one compare-and-swap on refs/hive/v1/tasks, which drops the
|
|
36
|
+
card's blob from the tree. A claimed card is refused with exit 2 and a hint to
|
|
37
|
+
release or reopen it first; `--force` releases exactly that claim's hive leases
|
|
38
|
+
before deleting, so a forced delete never strands a lease. An unknown id is exit 2
|
|
39
|
+
and a second delete reports "no such task" instead of succeeding silently, so the
|
|
40
|
+
command is never a silent idempotent.
|
|
41
|
+
- Events: `task_delete`, carrying the card id, its state before the delete and the actor.
|
|
42
|
+
|
|
43
|
+
### Tests
|
|
44
|
+
|
|
45
|
+
- 40 node:test scenarios: the original 34 unchanged, plus test/delete.test.mjs covering
|
|
46
|
+
every deletable state, blob removal, the claimed refusal and its lease, --force lease
|
|
47
|
+
release, the task_delete event, unknown ids, the non-idempotent second delete and
|
|
48
|
+
--json output.
|
|
49
|
+
|
|
50
|
+
### Published
|
|
51
|
+
|
|
52
|
+
- npm: `hive-tasks@1.5.0` on 2026-12-04.
|
|
53
|
+
|
|
7
54
|
## [1.4.0] - 2026-12-04
|
|
8
55
|
|
|
9
56
|
### Added
|
|
@@ -43,6 +90,10 @@ All notable changes to this project are documented here. The format follows
|
|
|
43
90
|
chain advance, cross-role routing, onFail rewind, reopen --stage, claim gating, legacy
|
|
44
91
|
cards, the three-tier resolveRole fallback, show role source and per-stage acceptance.
|
|
45
92
|
|
|
93
|
+
### Published
|
|
94
|
+
|
|
95
|
+
- npm: `hive-tasks@1.4.0` on 2026-12-04.
|
|
96
|
+
|
|
46
97
|
## [1.3.0] - 2026-12-04
|
|
47
98
|
|
|
48
99
|
### Added
|
|
@@ -124,6 +175,7 @@ All notable changes to this project are documented here. The format follows
|
|
|
124
175
|
- SPEC.md and RFC-0001 (why one tree, why the queue is derived).
|
|
125
176
|
- 9 node:test scenarios, including two concurrent claims.
|
|
126
177
|
|
|
178
|
+
[1.5.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.5.0
|
|
127
179
|
[1.4.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.4.0
|
|
128
180
|
[1.3.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.3.0
|
|
129
181
|
[1.1.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.1.0
|
package/README.md
CHANGED
|
@@ -74,9 +74,9 @@ token-tests-ba66 pending tester token tests
|
|
|
74
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 |
|
|
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
|
|
78
|
-
| block <id> --reason R / unblock <id> | park a card without losing it |
|
|
77
|
+
| retry <id> [--stage KEY] | failed back to pending (or reset a chain to KEY) |
|
|
79
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 leases; 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 leases first |
|
|
80
80
|
|
|
81
81
|
Exit codes: 0 done, 1 internal error, 2 refused (already claimed, wrong state, dependency missing, mode freeze, path busy).
|
|
82
82
|
|
|
@@ -125,6 +125,24 @@ $ hive-tasks claim slow-task-1a2b --agent agent-B # attempt 2, owner agent-B
|
|
|
125
125
|
|
|
126
126
|
A long but healthy run calls renew to keep its claim.
|
|
127
127
|
|
|
128
|
+
## Deleting a card
|
|
129
|
+
|
|
130
|
+
Remove a card that should not stay on the board:
|
|
131
|
+
|
|
132
|
+
~~~bash
|
|
133
|
+
$ hive-tasks rm stale-card-1a2b
|
|
134
|
+
stale-card-1a2b deleted [pending] stale card
|
|
135
|
+
|
|
136
|
+
$ hive-tasks rm working-card-9f8e
|
|
137
|
+
hive-tasks: task working-card-9f8e is claimed by agent-A; release or reopen it first, or use --force # exit 2
|
|
138
|
+
$ hive-tasks rm working-card-9f8e --force # releases the claim's leases, then deletes
|
|
139
|
+
~~~
|
|
140
|
+
|
|
141
|
+
pending, failed and done cards are deletable. A claimed card is protected on
|
|
142
|
+
purpose: delete it with --force, which releases exactly that claim's hive leases first, so
|
|
143
|
+
no lease is stranded. An unknown id is exit 2, and a second delete reports "no such task"
|
|
144
|
+
instead of pretending to succeed.
|
|
145
|
+
|
|
128
146
|
## Acceptance and freeze
|
|
129
147
|
|
|
130
148
|
A card may carry an acceptance command. It is **not** executed by default, because a card
|
|
@@ -184,7 +202,7 @@ created without stages keep the old single-implicit-stage behaviour, stored blob
|
|
|
184
202
|
|
|
185
203
|
## Role resolution
|
|
186
204
|
|
|
187
|
-
A role is a free string, never an enum, so resolving one must never
|
|
205
|
+
A role is a free string, never an enum, so resolving one must never refuse a card. show
|
|
188
206
|
prints where the role came from:
|
|
189
207
|
|
|
190
208
|
~~~bash
|
package/README.zh-CN.md
CHANGED
|
@@ -74,9 +74,9 @@ token-tests-ba66 pending tester token 测试
|
|
|
74
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
|
|
78
|
-
| block <id> --reason R / unblock <id> | 挂起而不丢卡 |
|
|
77
|
+
| retry <id> [--stage KEY] | failed 回到 pending(或把链复位到 KEY) |
|
|
79
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 会先释放租约再删 |
|
|
80
80
|
|
|
81
81
|
退出码:0 成功,1 内部错误,2 被拒(已被认领、状态不对、依赖缺失、模式 freeze、路径忙)。
|
|
82
82
|
|
|
@@ -121,6 +121,23 @@ $ hive-tasks claim slow-task-1a2b --agent agent-B # attempt 2,owner agent-
|
|
|
121
121
|
|
|
122
122
|
跑得久的健康任务用 renew 续期。
|
|
123
123
|
|
|
124
|
+
## 删除卡片
|
|
125
|
+
|
|
126
|
+
不再需要的卡可以删掉:
|
|
127
|
+
|
|
128
|
+
~~~bash
|
|
129
|
+
$ hive-tasks rm stale-card-1a2b
|
|
130
|
+
stale-card-1a2b deleted [pending] stale card
|
|
131
|
+
|
|
132
|
+
$ hive-tasks rm working-card-9f8e
|
|
133
|
+
hive-tasks: task working-card-9f8e is claimed by agent-A; release or reopen it first, or use --force # 退出码 2
|
|
134
|
+
$ hive-tasks rm working-card-9f8e --force # 先释放认领时的租约,再删除
|
|
135
|
+
~~~
|
|
136
|
+
|
|
137
|
+
pending、failed、done 的卡都可以删。claimed 的卡是**故意保护**的:要加
|
|
138
|
+
--force 才删,并且会先释放这次认领持有的 hive 租约,不会留下孤儿租约。未知 id 退出码
|
|
139
|
+
为 2;第二次删除会报 "no such task",不会静默成功。
|
|
140
|
+
|
|
124
141
|
## 验收与冻结
|
|
125
142
|
|
|
126
143
|
卡片可以带一条验收命令。**默认不执行**——卡片是仓库内容,默认执行等于让别人 push 一段代码就能在你机器上跑:
|
package/SPEC.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# hive-tasks protocol
|
|
2
2
|
|
|
3
|
-
Status: implemented, 1.
|
|
3
|
+
Status: implemented, 1.6.0. Protocol version v1 (card blobs keep `v: 1`).
|
|
4
4
|
|
|
5
5
|
## 1. Scope
|
|
6
6
|
|
|
@@ -91,7 +91,7 @@ Implementation sketch (plumbing, no working tree involved):
|
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
142
|
-
├── unblock (blocked)
|
|
140
|
+
├── retry (failed)
|
|
143
141
|
└── reopen (every stored state)
|
|
144
142
|
```
|
|
145
143
|
|
|
@@ -151,30 +149,34 @@ claimed card releases its hive leases, so no orphan lease is left behind. On a s
|
|
|
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
|
|
|
152
|
+
`rm` is the only destructive command: it removes the card's blob from the task tree in
|
|
153
|
+
one CAS. pending, failed and done cards are deletable. A claimed card is refused
|
|
154
|
+
(exit 2, with a hint to release or reopen it) unless --force is given; --force releases
|
|
155
|
+
exactly that claim's hive leases and then deletes the card, so a forced delete cannot
|
|
156
|
+
strand a lease. Deleting a card is not idempotent: an unknown id is exit 2, and a second
|
|
157
|
+
`rm` of the same id reports "no such task". Cards that named the deleted id in `after`
|
|
158
|
+
now have a missing dependency, which the ready computation reports as a data error.
|
|
159
|
+
|
|
154
160
|
| From | Command | To | Effect |
|
|
155
161
|
| --- | --- | --- | --- |
|
|
156
162
|
| pending | claim | claimed | CAS winner; attempt + 1 |
|
|
157
163
|
| claimed | done | done | releases leases; records resultCommit and verdict |
|
|
158
164
|
| claimed | fail | failed | releases leases; attempt kept |
|
|
159
|
-
| claimed | block | blocked | releases leases |
|
|
160
165
|
| claimed | reopen | pending | releases leases; attempt + 1 |
|
|
161
166
|
| done | reopen | pending | attempt + 1; clears resultCommit and verdict |
|
|
162
167
|
| failed | retry | pending | attempt kept |
|
|
163
168
|
| failed | reopen | pending | attempt + 1 |
|
|
164
|
-
| blocked | unblock | pending | attempt kept |
|
|
165
|
-
| blocked | retry | pending | attempt kept |
|
|
166
|
-
| blocked | reopen | pending | attempt + 1 |
|
|
167
169
|
| pending | reopen | pending | no-op (exit 0) |
|
|
168
|
-
|
|
|
170
|
+
| pending/failed/done | rm | deleted | removes the blob in one CAS |
|
|
171
|
+
| claimed | rm --force | deleted | releases the claim's leases, then removes the blob |
|
|
169
172
|
|
|
170
173
|
- pending: exists, dependencies not satisfied (or no capacity to run it).
|
|
171
174
|
- ready: pending with every id in after in state done. Computed, never stored.
|
|
172
175
|
- claimed: a dispatcher claimed it; owner and attempt are set.
|
|
173
176
|
- done: owner finished and (optionally) a verdict was recorded.
|
|
174
177
|
- failed: the run failed; retry moves it back to pending with attempt preserved.
|
|
175
|
-
- blocked: cannot proceed (conflict, missing dependency, manual hold).
|
|
176
178
|
|
|
177
|
-
Stored states are pending, claimed, done, failed
|
|
179
|
+
Stored states are pending, claimed, done, failed. ready is always computed.
|
|
178
180
|
|
|
179
181
|
A claimed card carries claimedUntil. Once that time passes the card is **reclaimable**:
|
|
180
182
|
claim may take it over exactly as if it were pending, incrementing attempt. This is how
|
|
@@ -220,12 +222,12 @@ Rules:
|
|
|
220
222
|
(pending, owner cleared, leases released) and keeps the card pending. The last stage
|
|
221
223
|
finishes the card (state done, stageState done). done returns `nextStage` (null when
|
|
222
224
|
the chain is complete).
|
|
223
|
-
3. **Fail stops or rewinds.** fail
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
4. **Retry and reopen reset stages.** retry resets the failed
|
|
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
|
|
229
231
|
--stage target) to pending and keeps earlier done stages; reopen resets to the target
|
|
230
232
|
(default the first stage) and increments attempt.
|
|
231
233
|
5. **Acceptance is per stage.** done --verify runs the current stage acceptance, falling
|
|
@@ -240,13 +242,8 @@ Rules:
|
|
|
240
242
|
| claimed / claimed | done (last stage) | done / done | stage done; card done; resultCommit/verdict recorded |
|
|
241
243
|
| claimed / claimed | fail, onFail target done | pending / pending at target | stage failed; target..end pending; attempt + 1; card ready again |
|
|
242
244
|
| claimed / claimed | fail, no usable onFail | failed / failed | whole card failed; stage failed |
|
|
243
|
-
| claimed / claimed | block, onFail target done | pending / pending at target | stage blocked; target..end pending; attempt + 1 |
|
|
244
|
-
| claimed / claimed | block, no usable onFail | blocked / blocked | whole card blocked |
|
|
245
245
|
| failed / failed | retry [--stage KEY] | pending / pending at KEY | KEY..end reset to pending, attempt kept |
|
|
246
|
-
| blocked / blocked | unblock | pending / pending at current | current stage pending, attempt kept |
|
|
247
|
-
| blocked / blocked | retry [--stage KEY] | pending / pending at KEY | KEY..end reset to pending, attempt kept |
|
|
248
246
|
| any / any | reopen [--stage KEY] | pending / pending at KEY | KEY..end reset (default first), attempt + 1, leases released |
|
|
249
|
-
| any / any | block | blocked / blocked or rewind | block accepts any state |
|
|
250
247
|
|
|
251
248
|
## 5. Ready computation
|
|
252
249
|
|
|
@@ -282,9 +279,8 @@ see the same order; the claim CAS still gives exactly one winner per card.
|
|
|
282
279
|
hive-tasks done <id> [--sha S] [--verdict pass|fail] [--verify]
|
|
283
280
|
hive-tasks fail <id> --reason R
|
|
284
281
|
hive-tasks retry <id> [--stage KEY]
|
|
285
|
-
hive-tasks block <id> --reason R
|
|
286
|
-
hive-tasks unblock <id>
|
|
287
282
|
hive-tasks reopen <id> [--reason R] [--stage KEY]
|
|
283
|
+
hive-tasks rm <id> [--force] [--json]
|
|
288
284
|
|
|
289
285
|
`--stage ROLE[:ACCEPTANCE]` is repeatable: each flag adds one stage in order, and the
|
|
290
286
|
stage key is derived from the role (duplicates become role-2, role-3...). `--stages
|
|
@@ -305,11 +301,13 @@ held leases behind when the card CAS loses. Reverting the card is another CAS we
|
|
|
305
301
|
no state leaks. A staged card reverts its stageState to pending together with the card.
|
|
306
302
|
|
|
307
303
|
done releases the leases and records the verdict (or opens the next stage). fail releases
|
|
308
|
-
the leases and keeps the attempt counter. retry accepts failed
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
304
|
+
the leases and keeps the attempt counter. retry accepts failed cards and returns the card
|
|
305
|
+
to pending (or resets the chain to a stage). reopen accepts every stored state, returns
|
|
306
|
+
the card to pending and releases a claimed card's leases (section 4). add --review-of
|
|
307
|
+
links a review card to its upstream (section 4.1). rm deletes pending, failed and done
|
|
308
|
+
cards, and refuses a
|
|
309
|
+
claimed card (exit 2) unless --force, which releases the claim's leases first; it prints
|
|
310
|
+
the deleted card (with `deleted: true`) under --json.
|
|
313
311
|
|
|
314
312
|
## 7. Role resolution (dispatchers)
|
|
315
313
|
|
|
@@ -354,9 +352,12 @@ Each command appends one line to .hive/events.jsonl:
|
|
|
354
352
|
{ "ts": "...", "actor": "worker-3", "kind": "task_claim", "task": "auth-token-a1b2", "attempt": 1 }
|
|
355
353
|
```
|
|
356
354
|
|
|
357
|
-
kinds: task_add, task_claim, task_done, task_fail, task_retry,
|
|
358
|
-
|
|
359
|
-
|
|
355
|
+
kinds: task_add, task_claim, task_done, task_fail, task_retry, task_renew, task_plan,
|
|
356
|
+
task_delete, reopen, review_failed, stage_done, stage_failed, stage_advanced,
|
|
357
|
+
stage_rewound.
|
|
358
|
+
|
|
359
|
+
`task_delete` records the removed card: it carries both `task` and `id` (the card id),
|
|
360
|
+
`state` (the state the card had when it was deleted) and `actor`.
|
|
360
361
|
|
|
361
362
|
A review card that fails appends two extra events: reopen for the upstream card it sends
|
|
362
363
|
back to pending, and review_failed for the review itself (with reviewOf and reopened).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hive-tasks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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": ">=
|
|
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
|
@@ -42,11 +42,11 @@ const USAGE = [
|
|
|
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)",
|
|
49
|
+
" hive-tasks rm <id> [--force] [--json] delete a card; a claimed card needs --force",
|
|
50
50
|
"",
|
|
51
51
|
"ENVIRONMENT",
|
|
52
52
|
" HIVE_AGENT=name identity used for claims",
|
|
@@ -315,6 +315,43 @@ function run(argv) {
|
|
|
315
315
|
return printTask(reopened, options.json);
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
if (command === "rm") {
|
|
319
|
+
const id = options.args[0];
|
|
320
|
+
if (!id) fail("rm needs a task id", 2);
|
|
321
|
+
const agent = options.agent || process.env.HIVE_AGENT || "unknown";
|
|
322
|
+
const current = readTask(repo, id);
|
|
323
|
+
if (!current) fail("no such task: " + id, 2);
|
|
324
|
+
if (current.state === "claimed" && !options.force) {
|
|
325
|
+
fail("task " + id + " is claimed by " + (current.owner || "another agent") + "; release or reopen it first, or use --force", 2);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// The blob is removed by the same CAS that reads the board, so a card that
|
|
329
|
+
// moved meanwhile (another writer, a concurrent claim) is re-checked
|
|
330
|
+
// instead of racing the tree write.
|
|
331
|
+
let deleted = null;
|
|
332
|
+
try {
|
|
333
|
+
const result = mutate(repo, (tasks) => {
|
|
334
|
+
const task = byId(tasks).get(id);
|
|
335
|
+
if (!task) throw new Error("no such task: " + id);
|
|
336
|
+
if (task.state === "claimed" && !options.force) {
|
|
337
|
+
throw new Error("task " + id + " is claimed by " + (task.owner || "another agent") + "; release or reopen it first, or use --force");
|
|
338
|
+
}
|
|
339
|
+
deleted = task;
|
|
340
|
+
return tasks.filter((entry) => entry.id !== id);
|
|
341
|
+
});
|
|
342
|
+
if (!result.ok) fail("could not delete " + id + " (too much contention)");
|
|
343
|
+
} catch (error) {
|
|
344
|
+
fail(error.message, 2);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// --force deletes a claimed card only after releasing exactly the leases
|
|
348
|
+
// that claim holds, so a forced delete cannot strand them.
|
|
349
|
+
if (deleted.state === "claimed") releaseLeases(repo, { paths: deleted.scope, agent: deleted.owner || agent });
|
|
350
|
+
append(repo, { actor: agent, kind: "task_delete", task: id, id, state: deleted.state });
|
|
351
|
+
if (options.json) return process.stdout.write(JSON.stringify({ ...viewTask(deleted), deleted: true }, null, 2) + "\n");
|
|
352
|
+
return process.stdout.write(id + " deleted [" + deleted.state + "] " + deleted.title + "\n");
|
|
353
|
+
}
|
|
354
|
+
|
|
318
355
|
if (command === "add") {
|
|
319
356
|
if (!options.title) fail("--title is required", 2);
|
|
320
357
|
if (options.reviewOf && !readTask(repo, options.reviewOf)) fail("no such task: " + options.reviewOf, 2);
|
|
@@ -455,7 +492,7 @@ function run(argv) {
|
|
|
455
492
|
return printTask(claimed, options.json);
|
|
456
493
|
}
|
|
457
494
|
|
|
458
|
-
if (command === "done" || command === "fail" || command === "retry"
|
|
495
|
+
if (command === "done" || command === "fail" || command === "retry") {
|
|
459
496
|
const id = options.args[0];
|
|
460
497
|
if (!id) fail(command + " needs a task id", 2);
|
|
461
498
|
const agent = options.agent || process.env.HIVE_AGENT || "unknown";
|
|
@@ -468,8 +505,7 @@ function run(argv) {
|
|
|
468
505
|
|
|
469
506
|
if ((command === "done" || command === "fail") && current.state !== "claimed") fail("task " + id + " is " + current.state + ", not claimed", 2);
|
|
470
507
|
if ((command === "done" || command === "fail") && isStaged(current) && current.stageState !== "claimed") fail("task " + id + " stage " + current.stage + " is " + current.stageState + ", not claimed", 2);
|
|
471
|
-
if (command === "retry" && current.state !== "failed"
|
|
472
|
-
if (command === "unblock" && current.state !== "blocked") fail("task " + id + " is " + current.state + ", not blocked", 2);
|
|
508
|
+
if (command === "retry" && current.state !== "failed") fail("task " + id + " is " + current.state + ", not failed", 2);
|
|
473
509
|
|
|
474
510
|
if (command === "done" && options.verify) {
|
|
475
511
|
const acceptance = isStaged(current) ? ((currentStage(current) || {}).acceptance || current.acceptance) : current.acceptance;
|
|
@@ -526,19 +562,6 @@ function run(argv) {
|
|
|
526
562
|
}
|
|
527
563
|
return { targetState: "failed", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null }, events: [] };
|
|
528
564
|
}
|
|
529
|
-
if (command === "block") {
|
|
530
|
-
if (isStaged(task)) {
|
|
531
|
-
const blocked = failStage(task, "blocked");
|
|
532
|
-
const events = blocked.rewound ? [{ kind: "stage_rewound", from: blocked.from, stage: blocked.to, attempt: (task.attempt || 0) + 1 }] : [];
|
|
533
|
-
return {
|
|
534
|
-
targetState: blocked.rewound ? "pending" : "blocked",
|
|
535
|
-
nextStage: null,
|
|
536
|
-
patch: { owner: null, claimedUntil: null, reason: options.reason || null, ...blocked.patch },
|
|
537
|
-
events,
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
return { targetState: "blocked", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null }, events: [] };
|
|
541
|
-
}
|
|
542
565
|
if (command === "retry") {
|
|
543
566
|
if (isStaged(task)) {
|
|
544
567
|
const reset = resetStage(task, target || task.stage);
|
|
@@ -546,11 +569,6 @@ function run(argv) {
|
|
|
546
569
|
}
|
|
547
570
|
return { targetState: "pending", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null }, events: [] };
|
|
548
571
|
}
|
|
549
|
-
// unblock
|
|
550
|
-
if (isStaged(task)) {
|
|
551
|
-
return { targetState: "pending", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null, ...stageStatePatch(task, "pending") }, events: [] };
|
|
552
|
-
}
|
|
553
|
-
return { targetState: "pending", nextStage: null, patch: { owner: null, claimedUntil: null, reason: options.reason || null }, events: [] };
|
|
554
572
|
}
|
|
555
573
|
|
|
556
574
|
// A review card that fails sends its upstream card back to pending, so a
|
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
|
|
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
|
|
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"
|
|
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,
|
|
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
|
|
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"
|
|
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) {
|