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