hive-tasks 1.2.0 → 1.5.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,101 @@ 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.5.0] - 2026-12-04
8
+
9
+ ### Added
10
+
11
+ - `rm <id> [--force] [--json]`: delete a task card. pending, failed, blocked and done
12
+ cards are removed by one compare-and-swap on refs/hive/v1/tasks, which drops the
13
+ card's blob from the tree. A claimed card is refused with exit 2 and a hint to
14
+ release or reopen it first; `--force` releases exactly that claim's hive leases
15
+ before deleting, so a forced delete never strands a lease. An unknown id is exit 2
16
+ and a second delete reports "no such task" instead of succeeding silently, so the
17
+ command is never a silent idempotent.
18
+ - Events: `task_delete`, carrying the card id, its state before the delete and the actor.
19
+
20
+ ### Tests
21
+
22
+ - 40 node:test scenarios: the original 34 unchanged, plus test/delete.test.mjs covering
23
+ every deletable state, blob removal, the claimed refusal and its lease, --force lease
24
+ release, the task_delete event, unknown ids, the non-idempotent second delete and
25
+ --json output.
26
+
27
+ ## [1.4.0] - 2026-12-04
28
+
29
+ ### Added
30
+
31
+ - Stage chains: add accepts repeated --stage ROLE[:ACCEPTANCE] flags and a --stages
32
+ FILE JSON array. A card can carry an ordered chain of stages (key, role, acceptance,
33
+ onFail, runtime state) plus the current stage and its stageState.
34
+ - done on a non-final stage marks that stage done, opens the next stage (owner cleared,
35
+ leases released) and keeps the card pending; only the last stage finishes the card.
36
+ done returns nextStage. claim accepts only the current pending stage, while an expired
37
+ claim is still reclaimable.
38
+ - fail/block mark the current stage failed/blocked. When the stage has an onFail target
39
+ that is done, the chain rewinds to it (target pending, attempt + 1, card ready again)
40
+ instead of failing the whole card; without a usable target the old whole-card failure
41
+ semantics apply. retry and reopen accept --stage KEY; reopen defaults to the first
42
+ stage and resets a chain so it can run again. done --verify runs the current stage's
43
+ acceptance command.
44
+ - Events: stage_done, stage_failed, stage_advanced and stage_rewound.
45
+ - Role resolution: resolveRole(repo, name) in src/role.js falls back repo (.hive/
46
+ roles.yaml) -> built-in (adapter dsh, model null, .hive/roles/<name>.md prompt) ->
47
+ synthetic generic contract carrying the name and stage key. It never throws and
48
+ returns a stable shape ({ name, source, adapter, model, prompt, args, stage }).
49
+ show prints the resolved source (repo|default|synthetic); show --json adds
50
+ roleResolved/roleSource; claim is never refused because a role is unconfigured.
51
+
52
+ ### Changed
53
+
54
+ - list/ready/show JSON always carries stages, stage and stageState. A card created
55
+ without stages reads as stages: [], stage: null, stageState: null; its stored blob and
56
+ every legacy transition are unchanged.
57
+ - ready/list role filtering follows the current stage role for staged cards, and ready
58
+ JSON adds readyRole (the role that should pick the card up).
59
+
60
+ ### Tests
61
+
62
+ - 34 node:test scenarios: the original 24 unchanged, plus test/stages.test.mjs covering
63
+ chain advance, cross-role routing, onFail rewind, reopen --stage, claim gating, legacy
64
+ cards, the three-tier resolveRole fallback, show role source and per-stage acceptance.
65
+
66
+ ### Published
67
+
68
+ - npm: `hive-tasks@1.4.0` on 2026-12-04.
69
+
70
+ ## [1.3.0] - 2026-12-04
71
+
72
+ ### Added
73
+
74
+ - reopen <id> [--reason R] [--agent A]: every stored state (pending, claimed, done,
75
+ failed, blocked) can go back to pending. The command clears owner, claimedUntil,
76
+ resultCommit and verdict, keeps attempt and increments it, records reason (default
77
+ "reopened") and appends a reopen event. Reopening a claimed card releases its hive
78
+ leases; reopening a pending card is a no-op, so the command is idempotent.
79
+ - Review cards: add --review-of <cardId> stores reviewOf and adds the upstream id to
80
+ after, so the review is ready only when the upstream is done. When a review card
81
+ fails and its upstream is done, the upstream is reopened in the same tree write
82
+ (attempt + 1, reason "test failed: <reason summary>") and the events record reopen
83
+ (via review_failed) and review_failed. A passed review does not touch the upstream.
84
+ - list --json keeps reviewOf; show prints review-of.
85
+
86
+ ### Changed
87
+
88
+ - No stored state is a one-way door any more: done and claimed gain reopen instead of
89
+ relying on the block/unblock detour.
90
+
91
+ ### Tests
92
+
93
+ - 24 node:test scenarios. test/reopen.test.mjs covers reopening every state, lease
94
+ release, attempt counting, idempotence, missing ids, review reflow and no-reflow.
95
+
96
+ ## [1.2.1] - 2026-12-04
97
+
98
+ ### Fixed
99
+
100
+ - --help and --version work outside a git repository.
101
+
7
102
  ## [1.2.0] - 2026-12-04
8
103
 
9
104
  ### Added
@@ -53,5 +148,8 @@ All notable changes to this project are documented here. The format follows
53
148
  - SPEC.md and RFC-0001 (why one tree, why the queue is derived).
54
149
  - 9 node:test scenarios, including two concurrent claims.
55
150
 
151
+ [1.5.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.5.0
152
+ [1.4.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.4.0
153
+ [1.3.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.3.0
56
154
  [1.1.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.1.0
57
155
  [1.0.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.0.0
package/README.md CHANGED
@@ -14,7 +14,7 @@ refs/hive/v1/tasks -> tree
14
14
 
15
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.
16
16
 
17
- > ~700 lines, zero dependencies, git >= 2.40
17
+ > ~1,400 lines, zero dependencies, git >= 2.40
18
18
 
19
19
  **Built for**: agent teams that already coordinate with hive; a queen that hands out work; a dispatcher that needs a stable list instead of a conversation.
20
20
 
@@ -64,17 +64,20 @@ token-tests-ba66 pending tester token tests
64
64
 
65
65
  | Command | Effect |
66
66
  | --- | --- |
67
- | add --title T [--role R] [--scope P] [--after ID] [--priority N] | create a card |
67
+ | add --title T [--role R] [--scope P] [--after ID] [--review-of ID] [--priority N] [--stage ROLE[:ACCEPTANCE]] [--stages FILE] | create a card; --review-of links it to the card it tests; --stage/--stages build a stage chain |
68
68
  | list [--state S] [--role R] [--json] | every card |
69
+ | show <id> [--json] | one card, its stage chain, and the resolved role source |
69
70
  | ready [--limit N] [--role R] [--json] | pending cards whose dependencies are done, ordered by priority then age |
70
71
  | next [--role R] | the single best candidate |
71
72
  | claim <id> --agent A [--ttl 5m] | card CAS, then hive leases on the scope |
72
73
  | renew <id> [--ttl 5m] | extend a claim so a long run is not stolen |
73
- | done <id> [--sha S] [--verdict pass\|fail] [--verify] | finish, release leases, record resultCommit; --verify runs the acceptance command first |
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
75
  | plan --file plan.json | create a whole dependency tree in one transaction |
75
- | fail <id> --reason R | failure is data: attempt stays |
76
- | retry <id> | failed or blocked back to pending |
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) |
77
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 |
78
81
 
79
82
  Exit codes: 0 done, 1 internal error, 2 refused (already claimed, wrong state, dependency missing, mode freeze, path busy).
80
83
 
@@ -123,6 +126,24 @@ $ hive-tasks claim slow-task-1a2b --agent agent-B # attempt 2, owner agent-B
123
126
 
124
127
  A long but healthy run calls renew to keep its claim.
125
128
 
129
+ ## Deleting a card
130
+
131
+ Remove a card that should not stay on the board:
132
+
133
+ ~~~bash
134
+ $ hive-tasks rm stale-card-1a2b
135
+ stale-card-1a2b deleted [pending] stale card
136
+
137
+ $ hive-tasks rm working-card-9f8e
138
+ 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
140
+ ~~~
141
+
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
144
+ no lease is stranded. An unknown id is exit 2, and a second delete reports "no such task"
145
+ instead of pretending to succeed.
146
+
126
147
  ## Acceptance and freeze
127
148
 
128
149
  A card may carry an acceptance command. It is **not** executed by default, because a card
@@ -137,6 +158,72 @@ $ hive-tasks done auth-takes-an-object-dea2 # records resultCommit
137
158
  When hive mode is freeze, ready returns only cards tagged fix, so the hotfix can run while
138
159
  the pipeline is red. Everything else waits.
139
160
 
161
+ ## Review cards
162
+
163
+ A review card tests another card. Link it when you create it:
164
+
165
+ ~~~bash
166
+ $ hive-tasks add --title "review auth" --role reviewer --review-of auth-takes-an-object-dea2
167
+ ~~~
168
+
169
+ reviewOf is stored, and the upstream id is added to after, so the review only becomes
170
+ ready once the implementation is done. When the review fails, the upstream card is
171
+ reopened automatically (attempt + 1, reason "test failed: ...") while the review card
172
+ becomes failed and can be retried. A passing review leaves the upstream alone.
173
+
174
+ ## Stage chains
175
+
176
+ One card can carry an ordered chain of stages instead of a single role. Every stage has a
177
+ role, an optional acceptance command and an optional onFail target:
178
+
179
+ ~~~bash
180
+ $ hive-tasks add --title "ship auth" --stage coder --stage tester:"npm test" --stage reviewer
181
+ $ hive-tasks claim ship-auth-1a2b --agent agent-A # the coder stage
182
+ $ hive-tasks done ship-auth-1a2b # stage done, next stage opens, card stays pending
183
+ $ hive-tasks ready --role tester # the same card, now routed to the tester
184
+ ~~~
185
+
186
+ done marks the current stage done and opens the next one, releasing the claim but not the
187
+ card; only the last stage finishes the card. claim accepts only the current pending stage,
188
+ so two agents cannot work two stages at once. --stages FILE writes explicit keys,
189
+ per-stage acceptance and onFail in one JSON array:
190
+
191
+ ~~~json
192
+ [
193
+ { "key": "code", "role": "coder" },
194
+ { "key": "test", "role": "tester", "onFail": "code" }
195
+ ]
196
+ ~~~
197
+
198
+ When a stage with onFail fails and its target is done, the chain rewinds: the target and
199
+ everything after it become pending again, attempt + 1, and the card is ready for the
200
+ earlier role instead of dying. fail without a usable onFail still fails the whole card.
201
+ reopen --stage KEY (default the first stage) resets a chain so it can run again. Cards
202
+ created without stages keep the old single-implicit-stage behaviour, stored blob included.
203
+
204
+ ## Role resolution
205
+
206
+ A role is a free string, never an enum, so resolving one must never block a card. show
207
+ prints where the role came from:
208
+
209
+ ~~~bash
210
+ $ hive-tasks show ship-auth-1a2b
211
+ role-source: default (adapter dsh, model -)
212
+ ~~~
213
+
214
+ resolveRole(repo, name) tries three tiers and never throws:
215
+
216
+ 1. repo: .hive/roles.yaml (the same file the runner reads) has an entry for the name; its
217
+ adapter, model and prompt file are used;
218
+ 2. default: a built-in role (coder, tester, reviewer, researcher, planner, worker, queen)
219
+ gets adapter dsh, model null and .hive/roles/<name>.md as the prompt when it exists;
220
+ 3. synthetic: any other name gets a generated generic contract that mentions the name and
221
+ the current stage key.
222
+
223
+ show --json returns the whole resolution as roleResolved ({ name, source, adapter, model,
224
+ prompt, args, stage }) plus roleSource, so a runner or supervisor can consume it directly;
225
+ claim never refuses a card because its role is not configured.
226
+
140
227
  ## Works with
141
228
 
142
229
  | Project | Question |
package/README.zh-CN.md CHANGED
@@ -14,7 +14,7 @@ refs/hive/v1/tasks -> 一棵树
14
14
 
15
15
  没有服务端、没有数据库、没有队列进程。认领就是对这个 ref 的一次 CAS,所以只有一个 agent 能赢;它要碰的路径同时在 [hive-consensus](https://github.com/d86e/hive-consensus) 里被租下。
16
16
 
17
- > 约 700 行 · 零依赖 · git >= 2.40
17
+ > 约 1,400 行 · 零依赖 · git >= 2.40
18
18
 
19
19
  **给谁用**:已经在用 hive 协调的 agent 团队;发任务的 queen;需要一个稳定列表而不是一段对话的调度器。
20
20
 
@@ -64,17 +64,20 @@ token-tests-ba66 pending tester token 测试
64
64
 
65
65
  | 命令 | 效果 |
66
66
  | --- | --- |
67
- | add --title T [--role R] [--scope P] [--after ID] [--priority N] | 建卡 |
67
+ | add --title T [--role R] [--scope P] [--after ID] [--review-of ID] [--priority N] [--stage ROLE[:ACCEPTANCE]] [--stages FILE] | 建卡;--review-of 挂到它要评审的卡上;--stage/--stages 建阶段链 |
68
68
  | list [--state S] [--role R] [--json] | 所有卡 |
69
+ | show <id> [--json] | 单张卡、它的阶段链,以及解析到的角色来源 |
69
70
  | ready [--limit N] [--role R] [--json] | 依赖已完成的 pending 卡,按优先级、再按时间排序 |
70
71
  | next [--role R] | 只给最优的那一张 |
71
72
  | claim <id> --agent A [--ttl 5m] | 先卡片 CAS,再对 scope 拿 hive 租约 |
72
73
  | renew <id> [--ttl 5m] | 续期认领,长任务不会被抢 |
73
- | done <id> [--sha S] [--verdict pass\|fail] [--verify] | 完成、释放租约、记录 resultCommit;--verify 先跑验收命令 |
74
+ | done <id> [--sha S] [--verdict pass\|fail] [--verify] | 完成、释放租约、记录 resultCommit;带阶段的卡会打开下一阶段;--verify 先跑当前阶段的验收 |
74
75
  | plan --file plan.json | 一次事务创建整棵依赖树 |
75
- | fail <id> --reason R | 失败是数据:attempt 保留 |
76
- | retry <id> | failed 或 blocked 回到 pending |
76
+ | fail <id> --reason R | 失败是数据:attempt 保留;阶段有已 done 的 onFail 目标时改为回退 |
77
+ | retry <id> [--stage KEY] | failed 或 blocked 回到 pending(或把链复位到 KEY) |
77
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 会先释放租约再删 |
78
81
 
79
82
  退出码:0 成功,1 内部错误,2 被拒(已被认领、状态不对、依赖缺失、模式 freeze、路径忙)。
80
83
 
@@ -119,6 +122,23 @@ $ hive-tasks claim slow-task-1a2b --agent agent-B # attempt 2,owner agent-
119
122
 
120
123
  跑得久的健康任务用 renew 续期。
121
124
 
125
+ ## 删除卡片
126
+
127
+ 不再需要的卡可以删掉:
128
+
129
+ ~~~bash
130
+ $ hive-tasks rm stale-card-1a2b
131
+ stale-card-1a2b deleted [pending] stale card
132
+
133
+ $ hive-tasks rm working-card-9f8e
134
+ hive-tasks: task working-card-9f8e is claimed by agent-A; release or reopen it first, or use --force # 退出码 2
135
+ $ hive-tasks rm working-card-9f8e --force # 先释放认领时的租约,再删除
136
+ ~~~
137
+
138
+ pending、failed、blocked、done 的卡都可以删。claimed 的卡是**故意保护**的:要加
139
+ --force 才删,并且会先释放这次认领持有的 hive 租约,不会留下孤儿租约。未知 id 退出码
140
+ 为 2;第二次删除会报 "no such task",不会静默成功。
141
+
122
142
  ## 验收与冻结
123
143
 
124
144
  卡片可以带一条验收命令。**默认不执行**——卡片是仓库内容,默认执行等于让别人 push 一段代码就能在你机器上跑:
@@ -131,6 +151,66 @@ $ hive-tasks done auth-takes-an-object-dea2 # 只记录 resultComm
131
151
 
132
152
  hive 处于 freeze 模式时,ready 只返回带 fix 标签的卡,让热修能跑、其余等待。
133
153
 
154
+ ## 评审回流(review-of)
155
+
156
+ 评审卡可以指向它要测的卡:
157
+
158
+ ~~~bash
159
+ $ hive-tasks add --title "评审 auth" --role reviewer --review-of auth-takes-an-object-dea2
160
+ ~~~
161
+
162
+ reviewOf 会存进卡里,同时把上游 id 补进 after——实现 done 之前评审卡不会 ready。评审
163
+ 失败时上游卡自动重开(attempt + 1,reason "test failed: ..."),评审卡自己变 failed,
164
+ 可以 retry;评审通过则不动上游。
165
+
166
+ ## 阶段链
167
+
168
+ 一张卡可以带一条有序的阶段链,每个阶段有自己的角色、可选验收命令和可选 onFail 目标:
169
+
170
+ ~~~bash
171
+ $ hive-tasks add --title "上线 auth" --stage coder --stage tester:"npm test" --stage reviewer
172
+ $ hive-tasks claim ship-auth-1a2b --agent agent-A # coder 阶段
173
+ $ hive-tasks done ship-auth-1a2b # 本阶段完成,下一阶段打开,卡仍是 pending
174
+ $ hive-tasks ready --role tester # 同一张卡,现在路由给 tester
175
+ ~~~
176
+
177
+ done 只把当前阶段标 done 并打开下一阶段:释放认领、不释放整卡;只有最后一个阶段结束才
178
+ 把整卡置 done。claim 只接受当前 pending 阶段,所以两个 agent 不会同时跑两个阶段。
179
+ --stages FILE 用一段 JSON 数组一次写出显式 key、每阶段验收和 onFail:
180
+
181
+ ~~~json
182
+ [
183
+ { "key": "code", "role": "coder" },
184
+ { "key": "test", "role": "tester", "onFail": "code" }
185
+ ]
186
+ ~~~
187
+
188
+ 带 onFail 的阶段失败、且目标阶段已 done 时,链会回退:目标及其后的阶段重新变 pending,
189
+ attempt + 1,卡片回到更早角色的队列,而不是整卡失败。没有可用 onFail 时 fail 仍然让
190
+ 整卡失败。reopen --stage KEY(默认第一个阶段)可以把链复位重跑。不带阶段的卡保持原来的
191
+ 「单隐式阶段」行为,连存下来的 blob 都不变。
192
+
193
+ ## 角色解析
194
+
195
+ 角色是自由字符串,不是枚举,所以解析角色永远不会阻塞一张卡。show 会打出角色来源:
196
+
197
+ ~~~bash
198
+ $ hive-tasks show ship-auth-1a2b
199
+ role-source: default (adapter dsh, model -)
200
+ ~~~
201
+
202
+ resolveRole(repo, name) 依次尝试三级回退,且永不抛错:
203
+
204
+ 1. repo:.hive/roles.yaml(runner 读的同一个文件)里有该角色,取它的 adapter、model
205
+ 和 prompt 文件;
206
+ 2. default:内置角色(coder、tester、reviewer、researcher、planner、worker、queen)
207
+ 用 adapter dsh、model null,prompt 取 .hive/roles/<name>.md(若存在);
208
+ 3. synthetic:其他任何名字生成一个通用契约,带上名字和当前阶段 key。
209
+
210
+ show --json 会把完整解析结果放在 roleResolved({ name, source, adapter, model, prompt,
211
+ args, stage })里,并附带 roleSource,runner / supervisor 可以直接消费;claim 不会因为
212
+ 角色没配置就拒绝任何卡。
213
+
134
214
  ## 和谁配合
135
215
 
136
216
  | 项目 | 回答的问题 |