hive-tasks 1.2.0 → 1.4.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 +73 -0
- package/README.md +73 -5
- package/README.zh-CN.md +67 -5
- package/SPEC.md +242 -50
- package/package.json +4 -3
- package/src/cli.js +328 -60
- package/src/role.js +240 -0
- package/src/stage.js +240 -0
- package/src/task.js +28 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,77 @@ 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.4.0] - 2026-12-04
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Stage chains: add accepts repeated --stage ROLE[:ACCEPTANCE] flags and a --stages
|
|
12
|
+
FILE JSON array. A card can carry an ordered chain of stages (key, role, acceptance,
|
|
13
|
+
onFail, runtime state) plus the current stage and its stageState.
|
|
14
|
+
- done on a non-final stage marks that stage done, opens the next stage (owner cleared,
|
|
15
|
+
leases released) and keeps the card pending; only the last stage finishes the card.
|
|
16
|
+
done returns nextStage. claim accepts only the current pending stage, while an expired
|
|
17
|
+
claim is still reclaimable.
|
|
18
|
+
- fail/block mark the current stage failed/blocked. When the stage has an onFail target
|
|
19
|
+
that is done, the chain rewinds to it (target pending, attempt + 1, card ready again)
|
|
20
|
+
instead of failing the whole card; without a usable target the old whole-card failure
|
|
21
|
+
semantics apply. retry and reopen accept --stage KEY; reopen defaults to the first
|
|
22
|
+
stage and resets a chain so it can run again. done --verify runs the current stage's
|
|
23
|
+
acceptance command.
|
|
24
|
+
- Events: stage_done, stage_failed, stage_advanced and stage_rewound.
|
|
25
|
+
- Role resolution: resolveRole(repo, name) in src/role.js falls back repo (.hive/
|
|
26
|
+
roles.yaml) -> built-in (adapter dsh, model null, .hive/roles/<name>.md prompt) ->
|
|
27
|
+
synthetic generic contract carrying the name and stage key. It never throws and
|
|
28
|
+
returns a stable shape ({ name, source, adapter, model, prompt, args, stage }).
|
|
29
|
+
show prints the resolved source (repo|default|synthetic); show --json adds
|
|
30
|
+
roleResolved/roleSource; claim is never refused because a role is unconfigured.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- list/ready/show JSON always carries stages, stage and stageState. A card created
|
|
35
|
+
without stages reads as stages: [], stage: null, stageState: null; its stored blob and
|
|
36
|
+
every legacy transition are unchanged.
|
|
37
|
+
- ready/list role filtering follows the current stage role for staged cards, and ready
|
|
38
|
+
JSON adds readyRole (the role that should pick the card up).
|
|
39
|
+
|
|
40
|
+
### Tests
|
|
41
|
+
|
|
42
|
+
- 34 node:test scenarios: the original 24 unchanged, plus test/stages.test.mjs covering
|
|
43
|
+
chain advance, cross-role routing, onFail rewind, reopen --stage, claim gating, legacy
|
|
44
|
+
cards, the three-tier resolveRole fallback, show role source and per-stage acceptance.
|
|
45
|
+
|
|
46
|
+
## [1.3.0] - 2026-12-04
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- reopen <id> [--reason R] [--agent A]: every stored state (pending, claimed, done,
|
|
51
|
+
failed, blocked) can go back to pending. The command clears owner, claimedUntil,
|
|
52
|
+
resultCommit and verdict, keeps attempt and increments it, records reason (default
|
|
53
|
+
"reopened") and appends a reopen event. Reopening a claimed card releases its hive
|
|
54
|
+
leases; reopening a pending card is a no-op, so the command is idempotent.
|
|
55
|
+
- Review cards: add --review-of <cardId> stores reviewOf and adds the upstream id to
|
|
56
|
+
after, so the review is ready only when the upstream is done. When a review card
|
|
57
|
+
fails and its upstream is done, the upstream is reopened in the same tree write
|
|
58
|
+
(attempt + 1, reason "test failed: <reason summary>") and the events record reopen
|
|
59
|
+
(via review_failed) and review_failed. A passed review does not touch the upstream.
|
|
60
|
+
- list --json keeps reviewOf; show prints review-of.
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
|
|
64
|
+
- No stored state is a one-way door any more: done and claimed gain reopen instead of
|
|
65
|
+
relying on the block/unblock detour.
|
|
66
|
+
|
|
67
|
+
### Tests
|
|
68
|
+
|
|
69
|
+
- 24 node:test scenarios. test/reopen.test.mjs covers reopening every state, lease
|
|
70
|
+
release, attempt counting, idempotence, missing ids, review reflow and no-reflow.
|
|
71
|
+
|
|
72
|
+
## [1.2.1] - 2026-12-04
|
|
73
|
+
|
|
74
|
+
### Fixed
|
|
75
|
+
|
|
76
|
+
- --help and --version work outside a git repository.
|
|
77
|
+
|
|
7
78
|
## [1.2.0] - 2026-12-04
|
|
8
79
|
|
|
9
80
|
### Added
|
|
@@ -53,5 +124,7 @@ All notable changes to this project are documented here. The format follows
|
|
|
53
124
|
- SPEC.md and RFC-0001 (why one tree, why the queue is derived).
|
|
54
125
|
- 9 node:test scenarios, including two concurrent claims.
|
|
55
126
|
|
|
127
|
+
[1.4.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.4.0
|
|
128
|
+
[1.3.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.3.0
|
|
56
129
|
[1.1.0]: https://github.com/d86e/hive-tasks/releases/tag/v1.1.0
|
|
57
130
|
[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
|
-
> ~
|
|
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,19 @@ 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
|
|
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) |
|
|
78
80
|
|
|
79
81
|
Exit codes: 0 done, 1 internal error, 2 refused (already claimed, wrong state, dependency missing, mode freeze, path busy).
|
|
80
82
|
|
|
@@ -137,6 +139,72 @@ $ hive-tasks done auth-takes-an-object-dea2 # records resultCommit
|
|
|
137
139
|
When hive mode is freeze, ready returns only cards tagged fix, so the hotfix can run while
|
|
138
140
|
the pipeline is red. Everything else waits.
|
|
139
141
|
|
|
142
|
+
## Review cards
|
|
143
|
+
|
|
144
|
+
A review card tests another card. Link it when you create it:
|
|
145
|
+
|
|
146
|
+
~~~bash
|
|
147
|
+
$ hive-tasks add --title "review auth" --role reviewer --review-of auth-takes-an-object-dea2
|
|
148
|
+
~~~
|
|
149
|
+
|
|
150
|
+
reviewOf is stored, and the upstream id is added to after, so the review only becomes
|
|
151
|
+
ready once the implementation is done. When the review fails, the upstream card is
|
|
152
|
+
reopened automatically (attempt + 1, reason "test failed: ...") while the review card
|
|
153
|
+
becomes failed and can be retried. A passing review leaves the upstream alone.
|
|
154
|
+
|
|
155
|
+
## Stage chains
|
|
156
|
+
|
|
157
|
+
One card can carry an ordered chain of stages instead of a single role. Every stage has a
|
|
158
|
+
role, an optional acceptance command and an optional onFail target:
|
|
159
|
+
|
|
160
|
+
~~~bash
|
|
161
|
+
$ hive-tasks add --title "ship auth" --stage coder --stage tester:"npm test" --stage reviewer
|
|
162
|
+
$ hive-tasks claim ship-auth-1a2b --agent agent-A # the coder stage
|
|
163
|
+
$ hive-tasks done ship-auth-1a2b # stage done, next stage opens, card stays pending
|
|
164
|
+
$ hive-tasks ready --role tester # the same card, now routed to the tester
|
|
165
|
+
~~~
|
|
166
|
+
|
|
167
|
+
done marks the current stage done and opens the next one, releasing the claim but not the
|
|
168
|
+
card; only the last stage finishes the card. claim accepts only the current pending stage,
|
|
169
|
+
so two agents cannot work two stages at once. --stages FILE writes explicit keys,
|
|
170
|
+
per-stage acceptance and onFail in one JSON array:
|
|
171
|
+
|
|
172
|
+
~~~json
|
|
173
|
+
[
|
|
174
|
+
{ "key": "code", "role": "coder" },
|
|
175
|
+
{ "key": "test", "role": "tester", "onFail": "code" }
|
|
176
|
+
]
|
|
177
|
+
~~~
|
|
178
|
+
|
|
179
|
+
When a stage with onFail fails and its target is done, the chain rewinds: the target and
|
|
180
|
+
everything after it become pending again, attempt + 1, and the card is ready for the
|
|
181
|
+
earlier role instead of dying. fail without a usable onFail still fails the whole card.
|
|
182
|
+
reopen --stage KEY (default the first stage) resets a chain so it can run again. Cards
|
|
183
|
+
created without stages keep the old single-implicit-stage behaviour, stored blob included.
|
|
184
|
+
|
|
185
|
+
## Role resolution
|
|
186
|
+
|
|
187
|
+
A role is a free string, never an enum, so resolving one must never block a card. show
|
|
188
|
+
prints where the role came from:
|
|
189
|
+
|
|
190
|
+
~~~bash
|
|
191
|
+
$ hive-tasks show ship-auth-1a2b
|
|
192
|
+
role-source: default (adapter dsh, model -)
|
|
193
|
+
~~~
|
|
194
|
+
|
|
195
|
+
resolveRole(repo, name) tries three tiers and never throws:
|
|
196
|
+
|
|
197
|
+
1. repo: .hive/roles.yaml (the same file the runner reads) has an entry for the name; its
|
|
198
|
+
adapter, model and prompt file are used;
|
|
199
|
+
2. default: a built-in role (coder, tester, reviewer, researcher, planner, worker, queen)
|
|
200
|
+
gets adapter dsh, model null and .hive/roles/<name>.md as the prompt when it exists;
|
|
201
|
+
3. synthetic: any other name gets a generated generic contract that mentions the name and
|
|
202
|
+
the current stage key.
|
|
203
|
+
|
|
204
|
+
show --json returns the whole resolution as roleResolved ({ name, source, adapter, model,
|
|
205
|
+
prompt, args, stage }) plus roleSource, so a runner or supervisor can consume it directly;
|
|
206
|
+
claim never refuses a card because its role is not configured.
|
|
207
|
+
|
|
140
208
|
## Works with
|
|
141
209
|
|
|
142
210
|
| 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
|
-
> 约
|
|
17
|
+
> 约 1,400 行 · 零依赖 · git >= 2.40
|
|
18
18
|
|
|
19
19
|
**给谁用**:已经在用 hive 协调的 agent 团队;发任务的 queen;需要一个稳定列表而不是一段对话的调度器。
|
|
20
20
|
|
|
@@ -64,17 +64,19 @@ 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
|
|
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(默认第一阶段) |
|
|
78
80
|
|
|
79
81
|
退出码:0 成功,1 内部错误,2 被拒(已被认领、状态不对、依赖缺失、模式 freeze、路径忙)。
|
|
80
82
|
|
|
@@ -131,6 +133,66 @@ $ hive-tasks done auth-takes-an-object-dea2 # 只记录 resultComm
|
|
|
131
133
|
|
|
132
134
|
hive 处于 freeze 模式时,ready 只返回带 fix 标签的卡,让热修能跑、其余等待。
|
|
133
135
|
|
|
136
|
+
## 评审回流(review-of)
|
|
137
|
+
|
|
138
|
+
评审卡可以指向它要测的卡:
|
|
139
|
+
|
|
140
|
+
~~~bash
|
|
141
|
+
$ hive-tasks add --title "评审 auth" --role reviewer --review-of auth-takes-an-object-dea2
|
|
142
|
+
~~~
|
|
143
|
+
|
|
144
|
+
reviewOf 会存进卡里,同时把上游 id 补进 after——实现 done 之前评审卡不会 ready。评审
|
|
145
|
+
失败时上游卡自动重开(attempt + 1,reason "test failed: ..."),评审卡自己变 failed,
|
|
146
|
+
可以 retry;评审通过则不动上游。
|
|
147
|
+
|
|
148
|
+
## 阶段链
|
|
149
|
+
|
|
150
|
+
一张卡可以带一条有序的阶段链,每个阶段有自己的角色、可选验收命令和可选 onFail 目标:
|
|
151
|
+
|
|
152
|
+
~~~bash
|
|
153
|
+
$ hive-tasks add --title "上线 auth" --stage coder --stage tester:"npm test" --stage reviewer
|
|
154
|
+
$ hive-tasks claim ship-auth-1a2b --agent agent-A # coder 阶段
|
|
155
|
+
$ hive-tasks done ship-auth-1a2b # 本阶段完成,下一阶段打开,卡仍是 pending
|
|
156
|
+
$ hive-tasks ready --role tester # 同一张卡,现在路由给 tester
|
|
157
|
+
~~~
|
|
158
|
+
|
|
159
|
+
done 只把当前阶段标 done 并打开下一阶段:释放认领、不释放整卡;只有最后一个阶段结束才
|
|
160
|
+
把整卡置 done。claim 只接受当前 pending 阶段,所以两个 agent 不会同时跑两个阶段。
|
|
161
|
+
--stages FILE 用一段 JSON 数组一次写出显式 key、每阶段验收和 onFail:
|
|
162
|
+
|
|
163
|
+
~~~json
|
|
164
|
+
[
|
|
165
|
+
{ "key": "code", "role": "coder" },
|
|
166
|
+
{ "key": "test", "role": "tester", "onFail": "code" }
|
|
167
|
+
]
|
|
168
|
+
~~~
|
|
169
|
+
|
|
170
|
+
带 onFail 的阶段失败、且目标阶段已 done 时,链会回退:目标及其后的阶段重新变 pending,
|
|
171
|
+
attempt + 1,卡片回到更早角色的队列,而不是整卡失败。没有可用 onFail 时 fail 仍然让
|
|
172
|
+
整卡失败。reopen --stage KEY(默认第一个阶段)可以把链复位重跑。不带阶段的卡保持原来的
|
|
173
|
+
「单隐式阶段」行为,连存下来的 blob 都不变。
|
|
174
|
+
|
|
175
|
+
## 角色解析
|
|
176
|
+
|
|
177
|
+
角色是自由字符串,不是枚举,所以解析角色永远不会阻塞一张卡。show 会打出角色来源:
|
|
178
|
+
|
|
179
|
+
~~~bash
|
|
180
|
+
$ hive-tasks show ship-auth-1a2b
|
|
181
|
+
role-source: default (adapter dsh, model -)
|
|
182
|
+
~~~
|
|
183
|
+
|
|
184
|
+
resolveRole(repo, name) 依次尝试三级回退,且永不抛错:
|
|
185
|
+
|
|
186
|
+
1. repo:.hive/roles.yaml(runner 读的同一个文件)里有该角色,取它的 adapter、model
|
|
187
|
+
和 prompt 文件;
|
|
188
|
+
2. default:内置角色(coder、tester、reviewer、researcher、planner、worker、queen)
|
|
189
|
+
用 adapter dsh、model null,prompt 取 .hive/roles/<name>.md(若存在);
|
|
190
|
+
3. synthetic:其他任何名字生成一个通用契约,带上名字和当前阶段 key。
|
|
191
|
+
|
|
192
|
+
show --json 会把完整解析结果放在 roleResolved({ name, source, adapter, model, prompt,
|
|
193
|
+
args, stage })里,并附带 roleSource,runner / supervisor 可以直接消费;claim 不会因为
|
|
194
|
+
角色没配置就拒绝任何卡。
|
|
195
|
+
|
|
134
196
|
## 和谁配合
|
|
135
197
|
|
|
136
198
|
| 项目 | 回答的问题 |
|