hive-tasks 1.7.0 → 1.8.1
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 +67 -0
- package/README.md +135 -70
- package/README.zh-CN.md +133 -74
- package/SPEC.md +192 -115
- package/package.json +1 -1
- package/src/cli.js +44 -10
- package/src/task.js +27 -2
package/SPEC.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# hive-tasks protocol
|
|
2
2
|
|
|
3
|
-
Status: implemented, 1.
|
|
3
|
+
Status: implemented, 1.8.1. Protocol version v1 (task blobs keep `v: 1`).
|
|
4
4
|
|
|
5
5
|
## 1. Scope
|
|
6
6
|
|
|
@@ -10,12 +10,12 @@ defines:
|
|
|
10
10
|
- where a task lives (a git ref, same namespace family as hive);
|
|
11
11
|
- the task blob and its state machine;
|
|
12
12
|
- how a task is claimed, finished and failed, with compare-and-swap;
|
|
13
|
-
- optional stage chains, so one
|
|
13
|
+
- optional stage chains, so one task can move across roles without being released;
|
|
14
14
|
- what "ready" means, and the CLI surface a dispatcher consumes.
|
|
15
15
|
|
|
16
|
-
It does not start agents, split goals
|
|
17
|
-
|
|
18
|
-
use.
|
|
16
|
+
It does not start agents, split goals or store patches. The acceptance command runs only
|
|
17
|
+
when `done --verify` is passed; role resolution itself returns a description a dispatcher
|
|
18
|
+
can use and never calls a model.
|
|
19
19
|
|
|
20
20
|
## 2. Namespace
|
|
21
21
|
|
|
@@ -24,9 +24,9 @@ The whole board is one git tree, behind one ref:
|
|
|
24
24
|
refs/hive/v1/tasks -> tree
|
|
25
25
|
<id> -> blob (the task JSON)
|
|
26
26
|
|
|
27
|
-
<id> is the tree entry name: a
|
|
28
|
-
|
|
29
|
-
auth-token-a1b2). It is immutable once created.
|
|
27
|
+
<id> is the tree entry name: a slug generated from the title (lowercase letters, digits
|
|
28
|
+
and dashes, at most 32 characters) followed by a 4-hex-character random suffix, so at
|
|
29
|
+
most 37 characters (for example auth-token-a1b2). It is immutable once created.
|
|
30
30
|
|
|
31
31
|
Why a tree and not one ref per task:
|
|
32
32
|
|
|
@@ -62,7 +62,7 @@ Implementation sketch (plumbing, no working tree involved):
|
|
|
62
62
|
"attempt": 0,
|
|
63
63
|
"priority": 0,
|
|
64
64
|
"tags": [],
|
|
65
|
-
"acceptance": "",
|
|
65
|
+
"acceptance": "npm test -- auth",
|
|
66
66
|
"claimedUntil": null,
|
|
67
67
|
"resultCommit": null,
|
|
68
68
|
"verdict": null,
|
|
@@ -71,6 +71,7 @@ Implementation sketch (plumbing, no working tree involved):
|
|
|
71
71
|
"createdBy": "queen",
|
|
72
72
|
"createdAt": "2026-12-03T15:00:00.000Z",
|
|
73
73
|
"updatedAt": "2026-12-03T15:00:00.000Z",
|
|
74
|
+
"stateChangedAt": "2026-12-03T15:00:00.000Z",
|
|
74
75
|
|
|
75
76
|
"stages": [
|
|
76
77
|
{ "key": "code", "role": "coder", "acceptance": "npm test", "state": "done" },
|
|
@@ -83,33 +84,39 @@ Implementation sketch (plumbing, no working tree involved):
|
|
|
83
84
|
|
|
84
85
|
| Field | Meaning |
|
|
85
86
|
| --- | --- |
|
|
86
|
-
| goal | what the
|
|
87
|
-
| role |
|
|
88
|
-
| scope | paths or resource keys the task expects to touch; announced on the hive-consensus
|
|
87
|
+
| goal | what the agent should achieve; free text, no format |
|
|
88
|
+
| role | the role the team agrees on (coder, tester, reviewer, ...); routing metadata, never an access check, so claim does not verify it. For a staged task it is the display/fallback role; routing uses the stage role. When --role is omitted at creation, the first stage's role is used for a staged task, else worker |
|
|
89
|
+
| scope | paths or resource keys the task expects to touch; announced on the hive-consensus announcement board, where a live overlap is information, never a refusal. A resource key is any stable string such as resource:port:3000 |
|
|
89
90
|
| after | ids that must be done before this becomes ready |
|
|
90
91
|
| state | see below |
|
|
91
92
|
| owner | agent id while claimed |
|
|
92
|
-
| attempt | incremented on every claim and every reopen, and on an onFail rewind;
|
|
93
|
-
| verdict | pass or fail,
|
|
94
|
-
| reason | why the
|
|
95
|
-
|
|
|
93
|
+
| attempt | incremented on every claim and every reopen, and on an onFail rewind; a plain counter of how many tries the task has had |
|
|
94
|
+
| verdict | pass or fail, recorded by done --verdict; a done that has both --verdict and --sha also writes a git note under refs/notes/hive/verdict |
|
|
95
|
+
| reason | why the task is in its current state: the text passed to fail or reopen, or "test failed: ..." after a review reflow |
|
|
96
|
+
| stateChangedAt | ISO time of the last real lane or stage change (lane = state + current stage + stageState). A transition moves it when it changes the lane: claim, done, fail, retry, reopen and stage transitions, including a stage advance that keeps the task pending. Anything that leaves the lane alone does not move it (renew, an external title/goal edit, reclaiming an expired claim that stays claimed, reopening into the same lane). Tasks written before 1.8.1 do not store it and readers fall back to updatedAt |
|
|
97
|
+
| reviewOf | id of the task this review task tests; the id is also added to after, so the review is ready only when its upstream is done |
|
|
96
98
|
| tags | free labels; "fix" is special (see mode) |
|
|
97
|
-
| acceptance |
|
|
98
|
-
|
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
`
|
|
107
|
-
|
|
99
|
+
| acceptance | shell command used by done --verify. For a staged task the current stage's acceptance is used first and this command is the fallback. Required when the task is created, unless the task is a draft |
|
|
100
|
+
| draft | optional boolean, stored as true only on a draft task (section 3.2). Normal tasks omit the key entirely. A draft is a flag, not a state: it adds no state of its own and is never dispatched |
|
|
101
|
+
| claimedUntil | expiry of the current claim; a claimed task past it is reclaimable |
|
|
102
|
+
| resultCommit | the commit recorded when the task or its current stage was finished |
|
|
103
|
+
| stages | optional ordered stage chain. Absent or [] means a task without stages |
|
|
104
|
+
| stage | current stage key, or null for a task without stages |
|
|
105
|
+
| stageState | state of the current stage: pending, claimed, done, failed; null for a task without stages |
|
|
106
|
+
|
|
107
|
+
Fields at the end are only stored when the task has stages. A task created without
|
|
108
|
+
`--stage`/`--stages` has no stage fields: `stages`, `stage` and `stageState` are not
|
|
109
|
+
written, and the JSON view reports `stages: []`, `stage: null`, `stageState: null`. That
|
|
110
|
+
is the "single implicit stage": every command behaves as before.
|
|
111
|
+
|
|
112
|
+
`draft` is written only when the task is created with `--draft`; a normal task has no
|
|
113
|
+
`draft` key at all. Every task written by 1.8.1 and later also stores `stateChangedAt`;
|
|
114
|
+
that field is independent of the draft flag.
|
|
108
115
|
|
|
109
116
|
### 3.1 Stage object
|
|
110
117
|
|
|
111
118
|
```yaml
|
|
112
|
-
- key: code # unique inside the
|
|
119
|
+
- key: code # unique inside the task, ^[a-z][a-z0-9-]{0,31}$
|
|
113
120
|
role: coder # any string, not enumerated
|
|
114
121
|
acceptance: "npm test" # optional, used by done --verify at this stage
|
|
115
122
|
onFail: code # optional, the key to rewind to when this stage fails
|
|
@@ -118,15 +125,50 @@ Fields at the end are only stored when the card has stages. A card created witho
|
|
|
118
125
|
|
|
119
126
|
| Field | Meaning |
|
|
120
127
|
| --- | --- |
|
|
121
|
-
| key | unique and stable inside the
|
|
128
|
+
| key | unique and stable inside the task; the stage identifier |
|
|
122
129
|
| role | free-form role name; resolved to an adapter/model/prompt by the dispatcher (section 7) |
|
|
123
130
|
| 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 and that target is done, the chain rewinds to it instead of failing the
|
|
131
|
+
| 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 task |
|
|
125
132
|
| state | runtime stage state, maintained by every transition |
|
|
126
133
|
|
|
127
|
-
Stage state and
|
|
128
|
-
|
|
129
|
-
Once a non-final stage is done the
|
|
134
|
+
Stage state and task state move together for the current stage: a claimed stage means
|
|
135
|
+
task state claimed, a failed stage without a rewind means task state failed, and so on.
|
|
136
|
+
Once a non-final stage is done the task returns to pending while the next stage opens.
|
|
137
|
+
The task's stateChangedAt moves whenever this lane or the current stage really changes,
|
|
138
|
+
so a stage advance that keeps the task pending is still recorded.
|
|
139
|
+
|
|
140
|
+
### 3.2 Draft tasks
|
|
141
|
+
|
|
142
|
+
A task exists to be worked, so it must say how it is judged. `add` therefore requires
|
|
143
|
+
`--acceptance CMD` unless `--draft` is passed:
|
|
144
|
+
|
|
145
|
+
hive-tasks add --title "auth takes an object" --acceptance "npm test -- auth"
|
|
146
|
+
hive-tasks add --title "park the redesign" --draft
|
|
147
|
+
|
|
148
|
+
Without either flag `add` refuses with exit 2 and
|
|
149
|
+
|
|
150
|
+
hive-tasks: add: --acceptance is required (or pass --draft for a draft card)
|
|
151
|
+
|
|
152
|
+
`--draft` stores `draft: true`; when no acceptance command is passed the field stays
|
|
153
|
+
empty, but --draft --acceptance can be combined. draft is a flag, not a state: it adds no
|
|
154
|
+
fifth state and changes no transition, so a draft task stays pending because claim
|
|
155
|
+
refuses it; the flag stays on the blob. A draft is excluded as follows:
|
|
156
|
+
|
|
157
|
+
1. ready, next and every dispatch-ready computation exclude it (section 5);
|
|
158
|
+
2. claim refuses it with exit 2 and a message naming the flag, even if its dependencies
|
|
159
|
+
and stages would otherwise make it ready;
|
|
160
|
+
3. list and show expose `draft: true` (JSON and text), and the stored blob keeps the flag
|
|
161
|
+
through every transition.
|
|
162
|
+
|
|
163
|
+
There is no un-draft command: a draft that should run is removed with `rm` and created
|
|
164
|
+
again with an acceptance command. `draft` is not part of the state machine, so it never
|
|
165
|
+
adds a fifth state or changes the transition table.
|
|
166
|
+
|
|
167
|
+
`plan --file` applies the same rule to every entry: an entry without `acceptance` is
|
|
168
|
+
rejected unless it sets `"draft": true`, and the refusal names the entry by array index
|
|
169
|
+
and title (`plan[1] ("park the redesign")`). The whole plan is refused before any task
|
|
170
|
+
is written. An entry may carry both `acceptance` and `"draft": true`; the flag still
|
|
171
|
+
keeps that task out of dispatch.
|
|
130
172
|
|
|
131
173
|
## 4. State machine
|
|
132
174
|
|
|
@@ -142,43 +184,46 @@ Once a non-final stage is done the card returns to pending while the next stage
|
|
|
142
184
|
```
|
|
143
185
|
|
|
144
186
|
`reopen` is the universal escape hatch: no stored state is a one-way door. It moves the
|
|
145
|
-
|
|
187
|
+
task back to pending, clears owner, claimedUntil, resultCommit and verdict, keeps attempt
|
|
146
188
|
and increments it, records reason (default "reopened") and writes a reopen event.
|
|
147
|
-
Reopening a pending
|
|
148
|
-
claimed
|
|
149
|
-
|
|
150
|
-
including a
|
|
189
|
+
Reopening a pending task without stages is a no-op (exit 0) and does not change attempt.
|
|
190
|
+
Reopening a claimed task releases its announcements, so no orphan announcement is left
|
|
191
|
+
behind. On a staged task reopen always resets the chain (default first stage, --stage KEY
|
|
192
|
+
selects another), including a task that is currently pending.
|
|
151
193
|
|
|
152
|
-
`rm` is the only destructive command: it removes the
|
|
153
|
-
one CAS. pending, failed and done
|
|
194
|
+
`rm` is the only destructive command: it removes the task's blob from the task tree in
|
|
195
|
+
one CAS. pending, failed and done tasks are deletable. A claimed task is refused
|
|
154
196
|
(exit 2, with a hint to release or reopen it) unless --force is given; --force releases
|
|
155
|
-
exactly that claim's announcements and then deletes the
|
|
156
|
-
strand an announcement. Deleting a
|
|
157
|
-
`rm` of the same id reports "no such task".
|
|
158
|
-
|
|
197
|
+
exactly that claim's announcements and then deletes the task, so a forced delete cannot
|
|
198
|
+
strand an announcement. Deleting a task is not idempotent: an unknown id is exit 2, and a second
|
|
199
|
+
`rm` of the same id reports "no such task". A task that named the deleted id in `after`
|
|
200
|
+
then simply never becomes ready: `add` and `plan` refuse unknown dependency ids when the
|
|
201
|
+
task is created, but a later delete can leave that reference dangling on the board.
|
|
159
202
|
|
|
160
203
|
| From | Command | To | Effect |
|
|
161
204
|
| --- | --- | --- | --- |
|
|
162
205
|
| pending | claim | claimed | CAS winner; attempt + 1 |
|
|
163
|
-
| claimed | done | done | releases the claim's announcements; records resultCommit and verdict |
|
|
206
|
+
| claimed | done | done | releases the claim's announcements; records resultCommit and the optional verdict |
|
|
164
207
|
| claimed | fail | failed | releases the claim's announcements; attempt kept |
|
|
165
208
|
| claimed | reopen | pending | releases the claim's announcements; attempt + 1 |
|
|
166
209
|
| done | reopen | pending | attempt + 1; clears resultCommit and verdict |
|
|
167
210
|
| failed | retry | pending | attempt kept |
|
|
168
211
|
| failed | reopen | pending | attempt + 1 |
|
|
169
|
-
| pending | reopen | pending | no-op (exit 0) |
|
|
212
|
+
| pending (no stages) | reopen | pending | no-op (exit 0) |
|
|
170
213
|
| pending/failed/done | rm | deleted | removes the blob in one CAS |
|
|
171
214
|
| claimed | rm --force | deleted | releases the claim's announcements, then removes the blob |
|
|
172
215
|
|
|
173
|
-
- pending: exists
|
|
216
|
+
- pending: exists and is not claimed; dependencies may still be open.
|
|
174
217
|
- ready: pending with every id in after in state done. Computed, never stored.
|
|
175
218
|
- claimed: a dispatcher claimed it; owner and attempt are set.
|
|
176
219
|
- done: owner finished and (optionally) a verdict was recorded.
|
|
177
220
|
- failed: the run failed; retry moves it back to pending with attempt preserved.
|
|
178
221
|
|
|
179
|
-
Stored states are pending, claimed, done, failed. ready is always computed.
|
|
222
|
+
Stored states are pending, claimed, done, failed. ready is always computed. draft is
|
|
223
|
+
not a state: it is an independent boolean flag that only removes a task from dispatch
|
|
224
|
+
(section 3.2), so the transition table below is unchanged for draft tasks.
|
|
180
225
|
|
|
181
|
-
A claimed
|
|
226
|
+
A claimed task carries claimedUntil. Once that time passes the task is **reclaimable**:
|
|
182
227
|
claim may take it over exactly as if it were pending, incrementing attempt. This is how
|
|
183
228
|
a crashed or starved agent is recovered without an operator.
|
|
184
229
|
|
|
@@ -186,62 +231,63 @@ Every transition is a compare-and-swap on the task ref: read the blob, verify th
|
|
|
186
231
|
current state, write the new blob with the ref's current sha as the expected value.
|
|
187
232
|
Two claimants therefore cannot both win.
|
|
188
233
|
|
|
189
|
-
### 4.1 Review
|
|
234
|
+
### 4.1 Review tasks (review-of)
|
|
190
235
|
|
|
191
|
-
A review
|
|
236
|
+
A review task names the task it tests:
|
|
192
237
|
|
|
193
238
|
hive-tasks add --title "review auth" --role reviewer --review-of <upstream-id>
|
|
194
239
|
|
|
195
240
|
The CLI stores reviewOf and adds the upstream id to after when it is not there yet, so
|
|
196
|
-
the review
|
|
241
|
+
the review task becomes ready only once the upstream is done.
|
|
197
242
|
|
|
198
|
-
When the review
|
|
243
|
+
When the review task fails:
|
|
199
244
|
|
|
200
245
|
1. if the upstream exists and is done, it is reopened (state pending, attempt + 1,
|
|
201
246
|
reason "test failed: <reason summary>", claimedUntil/resultCommit/verdict cleared) in
|
|
202
|
-
the same tree write that moves the review
|
|
203
|
-
2. the review
|
|
204
|
-
3. the events record task_fail, reopen (via
|
|
247
|
+
the same tree write that moves the review task to failed;
|
|
248
|
+
2. the review task itself becomes failed and can be retried;
|
|
249
|
+
3. when the upstream is reopened, the events record task_fail, reopen (via
|
|
250
|
+
review_failed) and review_failed.
|
|
205
251
|
|
|
206
|
-
When the review
|
|
252
|
+
When the review task is done the upstream is not touched: passing the review settles it.
|
|
207
253
|
If the upstream is missing or not done, the review still fails and no upstream is
|
|
208
254
|
reopened; review_failed records reopened: false. If a staged review stage rewinds through
|
|
209
|
-
onFail the
|
|
255
|
+
onFail the task does not fail, so the upstream is not reopened.
|
|
210
256
|
|
|
211
257
|
### 4.2 Stage chains
|
|
212
258
|
|
|
213
|
-
A stage chain turns one
|
|
214
|
-
is how a single
|
|
259
|
+
A stage chain turns one task into an ordered pipeline, each stage owned by a role. This
|
|
260
|
+
is how a single task moves coder -> tester -> reviewer without a new task per role.
|
|
215
261
|
|
|
216
262
|
Rules:
|
|
217
263
|
|
|
218
|
-
1. **Current stage only.** claim accepts the
|
|
264
|
+
1. **Current stage only.** claim accepts the task only when its current stage is pending
|
|
219
265
|
(or when a claim expired, in which case the stage is reclaimed like any claim).
|
|
220
266
|
done and fail accept only a claimed current stage.
|
|
221
267
|
2. **Advance, do not release.** done marks the current stage done, opens the next stage
|
|
222
|
-
(pending, owner cleared, announcements released) and keeps the
|
|
223
|
-
finishes the
|
|
268
|
+
(pending, owner cleared, announcements released) and keeps the task pending. The last stage
|
|
269
|
+
finishes the task (state done, stageState done). done returns `nextStage` (null when
|
|
224
270
|
the chain is complete).
|
|
225
271
|
3. **Fail stops or rewinds.** fail marks the current stage failed. If the stage has
|
|
226
272
|
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
|
|
273
|
+
stages become pending, the current stage stays failed as history, the task becomes
|
|
228
274
|
pending and ready again, and attempt is incremented. Without a usable onFail target
|
|
229
|
-
the whole
|
|
275
|
+
the whole task becomes failed, exactly as before.
|
|
230
276
|
4. **Retry and reopen reset stages.** retry resets the failed stage (or the
|
|
231
277
|
--stage target) to pending and keeps earlier done stages; reopen resets to the target
|
|
232
278
|
(default the first stage) and increments attempt.
|
|
233
279
|
5. **Acceptance is per stage.** done --verify runs the current stage acceptance, falling
|
|
234
|
-
back to the
|
|
235
|
-
6. **Legacy
|
|
280
|
+
back to the task acceptance when the stage has none.
|
|
281
|
+
6. **Legacy tasks are unchanged.** Without stages there is a single implicit stage and
|
|
236
282
|
every rule in section 4 applies verbatim.
|
|
237
283
|
|
|
238
|
-
|
|
|
284
|
+
| Task / stageState | Command | Result | Effect |
|
|
239
285
|
| --- | --- | --- | --- |
|
|
240
286
|
| pending / pending | claim | claimed / claimed | owner, announcements, attempt + 1; stage state claimed |
|
|
241
287
|
| claimed / claimed | done (more stages) | pending / pending at next | stage done, next pending, owner cleared, announcements released; nextStage returned |
|
|
242
|
-
| claimed / claimed | done (last stage) | done / done | stage done;
|
|
243
|
-
| claimed / claimed | fail, onFail target done | pending / pending at target | stage failed; target..end pending; attempt + 1;
|
|
244
|
-
| claimed / claimed | fail, no usable onFail | failed / failed | whole
|
|
288
|
+
| claimed / claimed | done (last stage) | done / done | stage done; task done; resultCommit/verdict recorded |
|
|
289
|
+
| claimed / claimed | fail, onFail target done | pending / pending at target | stage failed; target..end pending; attempt + 1; task ready again |
|
|
290
|
+
| claimed / claimed | fail, no usable onFail | failed / failed | whole task failed; stage failed |
|
|
245
291
|
| failed / failed | retry [--stage KEY] | pending / pending at KEY | KEY..end reset to pending, attempt kept |
|
|
246
292
|
| any / any | reopen [--stage KEY] | pending / pending at KEY | KEY..end reset (default first), attempt + 1, announcements released |
|
|
247
293
|
|
|
@@ -249,74 +295,100 @@ Rules:
|
|
|
249
295
|
|
|
250
296
|
A task is ready when:
|
|
251
297
|
|
|
252
|
-
1.
|
|
253
|
-
|
|
254
|
-
|
|
298
|
+
1. the task is not a draft: draft: true keeps it out of every dispatch computation,
|
|
299
|
+
whatever its state;
|
|
300
|
+
2. state is pending (or a claim expired and is reclaimable);
|
|
301
|
+
3. every id in after exists and is done;
|
|
302
|
+
4. hive mode is free, or the task is tagged "fix" (the fix must be able to run while the
|
|
255
303
|
pipeline is frozen);
|
|
256
|
-
|
|
304
|
+
5. for a staged task: stageState is pending, or claimed with an expired claim so it can
|
|
257
305
|
be recovered;
|
|
258
|
-
|
|
259
|
-
stage role for a staged
|
|
260
|
-
ready
|
|
261
|
-
so a dispatcher can route without guessing.
|
|
306
|
+
6. when a role filter is given, the role that works the task now matches it: the current
|
|
307
|
+
stage role for a staged task, the task role otherwise. Without a role filter every
|
|
308
|
+
ready task is visible; ready JSON adds `readyRole`, and the list/ready text output
|
|
309
|
+
prints the role that would work the task, so a dispatcher can route without guessing.
|
|
262
310
|
|
|
263
|
-
A missing dependency id is
|
|
311
|
+
A missing dependency id is never treated as satisfied: the task is not ready. `add` and
|
|
312
|
+
`plan` refuse unknown ids up front; a delete can still leave one behind.
|
|
313
|
+
|
|
314
|
+
claim applies the freeze filter too: while hive mode is freeze it refuses a task that is
|
|
315
|
+
not tagged "fix" (exit 2), unless --force is passed.
|
|
264
316
|
|
|
265
317
|
The queue is that set, sorted by priority (descending) and then createdAt (ascending).
|
|
266
318
|
There is no stored queue and no head pointer: ordering is a query over the task tree, so
|
|
267
|
-
it cannot drift from the
|
|
268
|
-
see the same order; the claim CAS still gives exactly one winner per
|
|
319
|
+
it cannot drift from the tasks. Two dispatchers that read the list at the same moment
|
|
320
|
+
see the same order; the claim CAS still gives exactly one winner per task.
|
|
269
321
|
|
|
270
322
|
## 6. CLI
|
|
271
323
|
|
|
272
|
-
hive-tasks
|
|
273
|
-
|
|
324
|
+
hive-tasks init
|
|
325
|
+
hive-tasks add --title T (--acceptance CMD | --draft) [--role R] [--scope P]...
|
|
326
|
+
[--after ID]... [--goal G] [--review-of ID] [--tag T]...
|
|
327
|
+
[--priority N] [--stage ROLE[:ACCEPTANCE]]... [--stages FILE]
|
|
328
|
+
hive-tasks plan [--file plan.json] # no --file reads the plan from stdin
|
|
274
329
|
hive-tasks list [--json] [--state S] [--role R]
|
|
275
330
|
hive-tasks ready [--json] [--limit N] [--role R]
|
|
276
331
|
hive-tasks next [--role R] [--json] # the single best candidate, or null
|
|
277
|
-
hive-tasks show <id> [--json] #
|
|
278
|
-
hive-tasks claim <id> --agent A [--ttl 5m]
|
|
332
|
+
hive-tasks show <id> [--json] # task plus resolved role source
|
|
333
|
+
hive-tasks claim <id> --agent A [--ttl 5m] [--force]
|
|
334
|
+
hive-tasks renew <id> [--ttl 5m]
|
|
279
335
|
hive-tasks done <id> [--sha S] [--verdict pass|fail] [--verify]
|
|
280
336
|
hive-tasks fail <id> --reason R
|
|
281
337
|
hive-tasks retry <id> [--stage KEY]
|
|
282
|
-
hive-tasks reopen <id> [--reason R] [--stage KEY]
|
|
338
|
+
hive-tasks reopen <id> [--reason R] [--agent A] [--stage KEY]
|
|
283
339
|
hive-tasks rm <id> [--force] [--json]
|
|
340
|
+
hive-tasks stats [--json]
|
|
341
|
+
|
|
342
|
+
add requires `--acceptance` unless `--draft` is passed; without either it exits 2 with
|
|
343
|
+
`add: --acceptance is required (or pass --draft for a draft card)`. The rule applies to
|
|
344
|
+
staged tasks too: per-stage acceptance is what done --verify runs, but task creation still
|
|
345
|
+
needs an acceptance command unless the task is a draft (section 3.2).
|
|
346
|
+
|
|
347
|
+
`plan --file FILE` takes a JSON array of entries and is the way to create a whole
|
|
348
|
+
dependency tree in one transaction; without --file the plan is read from stdin. An
|
|
349
|
+
entry takes title (required), acceptance (or `"draft": true`), key, role, scope, after
|
|
350
|
+
(entries' keys or existing ids), priority, tags, goal and stages. Every entry needs
|
|
351
|
+
`acceptance`, unless it sets `"draft": true`; a missing acceptance refuses the whole plan
|
|
352
|
+
(exit 2) and names the offending entry as `plan[N] ("title")`.
|
|
284
353
|
|
|
285
354
|
`--stage ROLE[:ACCEPTANCE]` is repeatable: each flag adds one stage in order, and the
|
|
286
|
-
stage key is derived from the role (
|
|
355
|
+
stage key is derived from the role (a repeated role becomes coder-2, coder-3...). `--stages
|
|
287
356
|
FILE` takes a JSON array of stage objects and is the way to set explicit keys, onFail and
|
|
288
357
|
per-stage acceptance in one shot. The two flags are mutually exclusive.
|
|
289
358
|
|
|
290
359
|
Exit codes: 0 success; 1 internal error; 2 refused (already claimed, wrong state,
|
|
291
|
-
dependency missing, mode freeze, invalid stage chain).
|
|
360
|
+
dependency missing, mode freeze, invalid stage chain, missing --acceptance, draft claim).
|
|
292
361
|
|
|
293
|
-
claim couples the
|
|
362
|
+
claim couples the task with the hive-consensus announcement board, task first:
|
|
294
363
|
|
|
295
|
-
1. CAS the
|
|
296
|
-
2. announce every scope path (refs/hive/v1/lease/<key>/__key__). The
|
|
297
|
-
|
|
298
|
-
returned as an overlap (in the claim event and in --json) and is
|
|
299
|
-
|
|
364
|
+
1. CAS the task from pending to claimed (this is what picks the single winner);
|
|
365
|
+
2. announce every scope path (refs/hive/v1/lease/<key>/__key__). The announcement phase
|
|
366
|
+
never fails the claim: the latest announcement wins, and a live announcement by
|
|
367
|
+
another agent is returned as an overlap (in the claim event and in --json) and is
|
|
368
|
+
otherwise ignored;
|
|
369
|
+
3. done, fail, reopen and rm --force release the announcements the closed claim owns (retry
|
|
370
|
+
only accepts failed tasks, whose claim was already released by fail).
|
|
300
371
|
|
|
301
|
-
Announcements are advisory and never refuse a claim: two agents may hold two
|
|
302
|
-
scope overlaps, and merge-on-commit reconciles the two edits at commit time. The
|
|
372
|
+
Announcements are advisory and never refuse a claim: two agents may hold two tasks whose
|
|
373
|
+
scope overlaps, and merge-on-commit reconciles the two edits at commit time. The task is
|
|
303
374
|
the authority; the announcement is the board's visibility. An announcement blob is
|
|
304
375
|
{"v": 1, "agent", "task", "key", "startedAt", "expiresAt"}; release is a
|
|
305
376
|
compare-and-delete of the announcement the caller still owns, so a newer announcer's blob
|
|
306
377
|
is never deleted by an older claim.
|
|
307
378
|
|
|
308
|
-
done releases the announcements and records the verdict (or opens the next
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
379
|
+
done releases the announcements and records the optional verdict (or opens the next
|
|
380
|
+
stage). fail
|
|
381
|
+
releases the announcements and keeps the attempt counter. retry accepts failed tasks and
|
|
382
|
+
returns the task to pending (or resets the chain to a stage). reopen accepts every stored
|
|
383
|
+
state, returns the task to pending and releases a claimed task's announcements
|
|
384
|
+
(section 4). add --review-of links a review task to its upstream (section 4.1). rm
|
|
385
|
+
deletes pending, failed and done tasks, and refuses a claimed task (exit 2) unless
|
|
386
|
+
--force, which releases the claim's announcements first; it prints the deleted task
|
|
315
387
|
(with `deleted: true`) under --json.
|
|
316
388
|
|
|
317
389
|
## 7. Role resolution (dispatchers)
|
|
318
390
|
|
|
319
|
-
A dispatcher needs an adapter, a model and a prompt for the role that works a
|
|
391
|
+
A dispatcher needs an adapter, a model and a prompt for the role that works a task.
|
|
320
392
|
Roles are free strings, so resolving one must never fail. `resolveRole(repo, name,
|
|
321
393
|
options)` in src/role.js returns a plain object with a stable shape:
|
|
322
394
|
|
|
@@ -343,15 +415,18 @@ Resolution is a three-tier fallback:
|
|
|
343
415
|
3. **synthetic** - any other name gets a generated generic contract that mentions the
|
|
344
416
|
name and, when the dispatcher passes one, the stage key. Nothing is refused.
|
|
345
417
|
|
|
346
|
-
The
|
|
347
|
-
|
|
348
|
-
|
|
418
|
+
The third argument may be a stage key string or `{ stage }`; it only feeds the
|
|
419
|
+
synthetic prompt. The function never throws: a missing or malformed roles.yaml, an
|
|
420
|
+
unreadable prompt file, a relative path outside the repository or an unknown name all
|
|
421
|
+
fall through to the next tier. It only reads files under the repository top and does not
|
|
422
|
+
mutate the input.
|
|
349
423
|
`hive-tasks show` prints the resolved source and, with --json, the whole object as
|
|
350
424
|
`roleResolved` (plus `roleSource`).
|
|
351
425
|
|
|
352
426
|
## 8. Events
|
|
353
427
|
|
|
354
|
-
|
|
428
|
+
Every command that mutates a task appends at least one line to .hive/events.jsonl (a
|
|
429
|
+
staged done and a failed review add extra lines, see below):
|
|
355
430
|
|
|
356
431
|
```json
|
|
357
432
|
{ "ts": "...", "actor": "worker-3", "kind": "task_claim", "task": "auth-token-a1b2", "attempt": 1 }
|
|
@@ -361,21 +436,23 @@ kinds: task_add, task_claim, task_done, task_fail, task_retry, task_renew, task_
|
|
|
361
436
|
task_delete, reopen, review_failed, stage_done, stage_failed, stage_advanced,
|
|
362
437
|
stage_rewound.
|
|
363
438
|
|
|
364
|
-
`task_delete` records the removed
|
|
365
|
-
`state` (the state the
|
|
439
|
+
`task_delete` records the removed task: it carries both `task` and `id` (the task id),
|
|
440
|
+
`state` (the state the task had when it was deleted) and `actor`.
|
|
366
441
|
|
|
367
|
-
A review
|
|
368
|
-
|
|
442
|
+
A review task that fails appends review_failed for the review itself (with reviewOf and
|
|
443
|
+
reopened); when it sends an upstream task back to pending, a reopen event is appended
|
|
444
|
+
too.
|
|
369
445
|
|
|
370
446
|
Stage events are additional lines next to the task event:
|
|
371
447
|
|
|
372
448
|
- stage_done: a stage finished (task done or advanced); carries stage.
|
|
373
|
-
- stage_advanced: the
|
|
449
|
+
- stage_advanced: the task opened the next stage; carries from and stage.
|
|
374
450
|
- stage_failed: the current stage failed; carries stage and state.
|
|
375
|
-
- stage_rewound: an onFail target took the
|
|
451
|
+
- stage_rewound: an onFail target took the task back; carries from and stage (the target).
|
|
376
452
|
|
|
377
453
|
## 9. Requirements
|
|
378
454
|
|
|
455
|
+
- Node.js >= 22.19.
|
|
379
456
|
- hive-consensus >= 1.5.0 (announcement board, board, mode, verdict, events).
|
|
380
457
|
- git >= 2.40.
|
|
381
458
|
- No network, no database, no daemon.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hive-tasks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
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": {
|