hive-tasks 1.8.1 → 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/CHANGELOG.md +43 -0
- package/README.md +50 -4
- package/README.zh-CN.md +45 -5
- package/SPEC.md +66 -8
- package/package.json +1 -1
- package/src/cli.js +405 -5
- package/src/lease.js +12 -0
- package/src/task.js +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -16,6 +16,45 @@ All notable changes to this project are documented here. The format follows
|
|
|
16
16
|
"never starts a process" claim and the generated id length). No behaviour or protocol
|
|
17
17
|
change.
|
|
18
18
|
|
|
19
|
+
## [1.9.0] - 2026-12-04
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- `edit <id>` with `--title`, `--scope-add`/`--scope-remove`, `--acceptance`,
|
|
24
|
+
`--priority`, `--after-set`, `--tag +T/-T`, `--role` and `--superseded`/
|
|
25
|
+
`--no-superseded`. It only works on pending or failed tasks and changes only the
|
|
26
|
+
fields passed. An empty `--acceptance` is refused; `--acceptance -` clears it on a
|
|
27
|
+
draft task; `--priority` must be an integer; `--after-set` refuses a dependency cycle.
|
|
28
|
+
A scope edit keeps the task's announcements in sync (added paths are announced under
|
|
29
|
+
the task announcer and removed paths a claim of the task wrote are released). An edit
|
|
30
|
+
never moves the lane, so `stateChangedAt` is untouched.
|
|
31
|
+
- `supersede <id> --reason R [--replaced-by ID]`: retire a task without marking it done
|
|
32
|
+
or failed. The flag keeps the lane but removes the task from ready, next and claim,
|
|
33
|
+
and stats counts superseded tasks separately. `edit --superseded`/`--no-superseded`
|
|
34
|
+
sets and clears the same flag on a pending or failed task.
|
|
35
|
+
- `split <id> --into '<json array>' [--keep] [--reason R] [--json]`: replace a task with
|
|
36
|
+
at least two cards described by `{title, role?, scope?, acceptance?, after?}`. Missing
|
|
37
|
+
values are inherited from the parent and every card needs an acceptance command.
|
|
38
|
+
Without --keep the parent is marked superseded and points at the first card via
|
|
39
|
+
replacedBy; with --keep it keeps its lane and every card lists it in after. Claimed or
|
|
40
|
+
done tasks cannot be split. --json returns `{ task, cards }`.
|
|
41
|
+
- Events: `task_edit` (`{ task, fields }` where fields names the changed fields, never
|
|
42
|
+
their values), `task_split` (`{ task, cards, kept, replacedBy? }`) and
|
|
43
|
+
`task_supersede` (`{ task, reason, replacedBy? }`).
|
|
44
|
+
|
|
45
|
+
### Tests
|
|
46
|
+
|
|
47
|
+
- 62 node:test scenarios: the 52 from 1.8.1 unchanged, plus ten in
|
|
48
|
+
test/edit-split.test.mjs covering per-field edits and the `{ task, fields }` event,
|
|
49
|
+
pending/failed-only edits, integer priority, dependency cycles and the superseded
|
|
50
|
+
toggle, scope announcement sync, the acceptance rules, a JSON-array split that
|
|
51
|
+
supersedes the parent, `--keep` gating, split refusals, `supersede` with
|
|
52
|
+
`--replaced-by`, and stats counting a superseded done task separately.
|
|
53
|
+
|
|
54
|
+
### Published
|
|
55
|
+
|
|
56
|
+
- Not published to npm in this change.
|
|
57
|
+
|
|
19
58
|
## [1.8.1] - 2026-12-04
|
|
20
59
|
|
|
21
60
|
### Added
|
|
@@ -33,6 +72,10 @@ All notable changes to this project are documented here. The format follows
|
|
|
33
72
|
covering lane changes, a stage advance while the card stays pending, renew and a
|
|
34
73
|
title-only metadata edit not moving it, and the updatedAt fallback for legacy cards.
|
|
35
74
|
|
|
75
|
+
### Published
|
|
76
|
+
|
|
77
|
+
- npm: `hive-tasks@1.8.1` on 2026-12-04.
|
|
78
|
+
|
|
36
79
|
## [1.8.0] - 2026-12-04
|
|
37
80
|
|
|
38
81
|
### Added
|
package/README.md
CHANGED
|
@@ -75,9 +75,12 @@ token-tests-ba66 pending tester token tests
|
|
|
75
75
|
| --- | --- |
|
|
76
76
|
| init | create .hive/ and the hive-tasks section in AGENTS.md |
|
|
77
77
|
| add --title T (--acceptance CMD \| --draft) [--role R] [--scope P] [--after ID] [--review-of ID] [--tag T] [--priority N] [--goal G] [--stage ROLE[:ACCEPTANCE]] [--stages FILE] | create a task; --acceptance is required unless --draft; --review-of links it to the task it tests; --stage/--stages build a stage chain |
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
78
|
+
| edit <id> [--title T] [--scope-add P] [--scope-remove P] [--acceptance CMD] [--priority N] [--after-set ID,ID] [--tag +T/-T] [--role R] [--superseded\|--no-superseded] | change only the fields you pass, on a pending or failed task; an empty --acceptance is refused and --acceptance - clears it on a draft; a scope edit syncs the task's announcements |
|
|
79
|
+
| split <id> --into '<json array>' [--keep] [--reason R] [--json] | replace a task with finer cards; the parent is marked superseded unless --keep keeps it and gates the cards on it |
|
|
80
|
+
| supersede <id> --reason R [--replaced-by ID] | retire a task without done/failed; it leaves ready, next and claim |
|
|
81
|
+
| list [--state S] [--role R] [--json] | every task, drafts and superseded ones included |
|
|
82
|
+
| show <id> [--json] | one task, its stage chain, the draft and superseded flags, and the resolved role source |
|
|
83
|
+
| ready [--limit N] [--role R] [--json] | pending, non-draft, non-superseded tasks whose dependencies are done, ordered by priority then age |
|
|
81
84
|
| next [--role R] [--json] | the single best candidate |
|
|
82
85
|
| claim <id> --agent A [--ttl 5m] | task CAS, then announce the scope paths on the hive-consensus board |
|
|
83
86
|
| renew <id> [--ttl 5m] | extend a claim so a long but healthy run is not recovered mid-flight |
|
|
@@ -124,7 +127,9 @@ hive-tasks stats
|
|
|
124
127
|
hive-tasks stats --json
|
|
125
128
|
~~~
|
|
126
129
|
|
|
127
|
-
Counts by state and role, plus the oldest pending task.
|
|
130
|
+
Counts by state and role, plus the oldest pending task. Superseded tasks keep their
|
|
131
|
+
lane but are counted separately: `superseded` in the JSON and its own line in the text
|
|
132
|
+
output; they are not part of byState/byRole or the oldest pending task.
|
|
128
133
|
|
|
129
134
|
## How a claim works
|
|
130
135
|
|
|
@@ -138,6 +143,47 @@ Announcements never refuse a task: two agents may hold two tasks whose scope ove
|
|
|
138
143
|
which is exactly what the queue must allow. merge-on-commit reconciles the two edits at
|
|
139
144
|
commit time; the task is the authority, the announcement is visibility for the board.
|
|
140
145
|
|
|
146
|
+
## Editing, splitting and superseding tasks
|
|
147
|
+
|
|
148
|
+
`edit` changes only the fields you pass, and only on a pending or failed task (a claimed
|
|
149
|
+
task must be done or failed first, a done task reopened first):
|
|
150
|
+
|
|
151
|
+
~~~bash
|
|
152
|
+
$ hive-tasks edit auth-takes-an-object-dea2 --title "auth takes options" --tag +api --priority 5
|
|
153
|
+
$ hive-tasks edit auth-takes-an-object-dea2 --scope-add src/token.ts --scope-remove src/legacy.ts
|
|
154
|
+
$ hive-tasks edit auth-takes-an-object-dea2 --after-set schema-migration-7c1d
|
|
155
|
+
$ hive-tasks edit idea-1a2b --acceptance - # only a draft may clear its acceptance
|
|
156
|
+
$ hive-tasks edit old-plan-1a2b --superseded --reason "replaced" # or --no-superseded
|
|
157
|
+
~~~
|
|
158
|
+
|
|
159
|
+
An empty `--acceptance` is refused; `--acceptance -` clears it on a draft task.
|
|
160
|
+
`--priority` must be an integer, `--after-set` refuses a dependency cycle, and a scope
|
|
161
|
+
edit keeps the task's announcements in sync: added paths are announced under the task's
|
|
162
|
+
announcer (or the editor) and removed paths that a claim of this task wrote are released.
|
|
163
|
+
The edit event stores `{ task, fields }` where `fields` names the changed fields, never
|
|
164
|
+
their values, and stateChangedAt does not move because the lane did not change.
|
|
165
|
+
|
|
166
|
+
`split` replaces one task with at least two finer cards given as a JSON array:
|
|
167
|
+
|
|
168
|
+
~~~bash
|
|
169
|
+
$ hive-tasks split auth-takes-an-object-dea2 --into '[
|
|
170
|
+
{ "title": "auth schema", "scope": ["src/schema.ts"], "acceptance": "npm test -- schema" },
|
|
171
|
+
{ "title": "auth api", "role": "tester" }
|
|
172
|
+
]'
|
|
173
|
+
~~~
|
|
174
|
+
|
|
175
|
+
Each entry takes title (required), role, scope, acceptance and after; missing fields are
|
|
176
|
+
inherited from the parent, and every resulting card must have an acceptance command. The
|
|
177
|
+
parent is marked superseded (its lane is unchanged) and `replacedBy` points at the first
|
|
178
|
+
new card; `--keep` keeps the parent and makes every card list it in `after`, so the cards
|
|
179
|
+
only become ready after the parent is done. `--json` returns `{ task, cards }`; the
|
|
180
|
+
task_split event records the parent and card ids. A claimed or done task cannot be split,
|
|
181
|
+
and splitting an already superseded task is refused.
|
|
182
|
+
|
|
183
|
+
`supersede <id> --reason R [--replaced-by ID]` retires a task without changing its lane:
|
|
184
|
+
it is excluded from ready, next and claim, and stats counts it separately. A superseded
|
|
185
|
+
task is a flag, not a fifth state: its pending/failed/done/claimed lane is unchanged.
|
|
186
|
+
|
|
141
187
|
## When an agent dies
|
|
142
188
|
|
|
143
189
|
Every claim carries claimedUntil (the --ttl, 5 minutes by default). Once it passes, the
|
package/README.zh-CN.md
CHANGED
|
@@ -74,9 +74,12 @@ token-tests-ba66 pending tester token tests
|
|
|
74
74
|
| --- | --- |
|
|
75
75
|
| init | 创建 .hive/,并在 AGENTS.md 里加 hive-tasks 小节 |
|
|
76
76
|
| add --title T (--acceptance CMD \| --draft) [--role R] [--scope P] [--after ID] [--review-of ID] [--tag T] [--priority N] [--goal G] [--stage ROLE[:ACCEPTANCE]] [--stages FILE] | 创建任务;非草稿任务必须带 --acceptance,--draft 创建草稿任务;--review-of 挂到它要评审的任务上;--stage/--stages 建阶段链 |
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
|
77
|
+
| edit <id> [--title T] [--scope-add P] [--scope-remove P] [--acceptance CMD] [--priority N] [--after-set ID,ID] [--tag +T/-T] [--role R] [--superseded\|--no-superseded] | 只改传入的字段,且只对 pending/failed 任务生效;空 --acceptance 被拒,草稿可用 --acceptance - 清空;scope 改动会同步任务自己的公告 |
|
|
78
|
+
| split <id> --into '<json array>' [--keep] [--reason R] [--json] | 用更细的卡替换一张任务;父任务默认标 superseded 并指向第一张新卡,--keep 保留父任务并让新卡以它为前置 |
|
|
79
|
+
| supersede <id> --reason R [--replaced-by ID] | 退休一张任务(不是 done/failed),不再进入 ready、next 和 claim |
|
|
80
|
+
| list [--state S] [--role R] [--json] | 所有任务,含草稿和 superseded |
|
|
81
|
+
| show <id> [--json] | 单个任务、它的阶段链、draft/superseded 标记,以及解析到的角色来源 |
|
|
82
|
+
| ready [--limit N] [--role R] [--json] | 依赖已完成的 pending 非草稿、非 superseded 任务,按优先级、再按时间排序 |
|
|
80
83
|
| next [--role R] [--json] | 只给最优的那一个 |
|
|
81
84
|
| claim <id> --agent A [--ttl 5m] | 先 CAS 任务,再把 scope 路径公告到 hive-consensus 公告看板 |
|
|
82
85
|
| renew <id> [--ttl 5m] | 续期认领,长任务不会被中途回收 |
|
|
@@ -86,7 +89,7 @@ token-tests-ba66 pending tester token tests
|
|
|
86
89
|
| retry <id> [--stage KEY] | failed 回到 pending(或把链复位到 KEY) |
|
|
87
90
|
| reopen <id> [--reason R] [--agent A] [--stage KEY] | 任何状态回到 pending;清 owner、认领、结果与判定,attempt + 1;释放认领时的公告;带阶段的任务复位到 KEY(默认第一阶段) |
|
|
88
91
|
| rm <id> [--force] [--json] | 删除 pending/failed/done 的任务;claimed 的任务默认拒绝(退出码 2),加 --force 会先释放公告再删 |
|
|
89
|
-
| stats [--json] | 按状态和角色计数,外加最老的 pending
|
|
92
|
+
| stats [--json] | 按状态和角色计数,外加最老的 pending 任务;superseded 单独计数 |
|
|
90
93
|
|
|
91
94
|
退出码:0 成功,1 内部错误,2 被拒(已被认领、状态不对、任务不存在、依赖缺失、
|
|
92
95
|
模式 freeze、阶段链非法、缺 --acceptance、认领草稿任务)。
|
|
@@ -119,7 +122,8 @@ hive-tasks stats
|
|
|
119
122
|
hive-tasks stats --json
|
|
120
123
|
~~~
|
|
121
124
|
|
|
122
|
-
按状态和角色计数,外加最老的 pending 任务。
|
|
125
|
+
按状态和角色计数,外加最老的 pending 任务。superseded 任务保留原 lane,但单独计数:
|
|
126
|
+
JSON 里是 `superseded`,文本输出单独一行;它们不计入 byState/byRole,也不参与最老 pending。
|
|
123
127
|
|
|
124
128
|
## claim 怎么走
|
|
125
129
|
|
|
@@ -132,6 +136,42 @@ hive-tasks stats --json
|
|
|
132
136
|
公告永远不拒绝任务:两个智能体可以同时持有 scope 重叠的两个任务,队列本来就该允许这种
|
|
133
137
|
情况。真正撞车的改动由 merge-on-commit 在提交时合并;**任务是权威,公告是看板上的可见性**。
|
|
134
138
|
|
|
139
|
+
## 编辑、拆分与退休任务
|
|
140
|
+
|
|
141
|
+
`edit` 只改传入的字段,且只对 pending/failed 任务生效(claimed 先 done/fail,done 先 reopen):
|
|
142
|
+
|
|
143
|
+
~~~bash
|
|
144
|
+
$ hive-tasks edit auth-takes-an-object-dea2 --title "auth 改成 options" --tag +api --priority 5
|
|
145
|
+
$ hive-tasks edit auth-takes-an-object-dea2 --scope-add src/token.ts --scope-remove src/legacy.ts
|
|
146
|
+
$ hive-tasks edit auth-takes-an-object-dea2 --after-set schema-migration-7c1d
|
|
147
|
+
$ hive-tasks edit idea-1a2b --acceptance - # 只有草稿能清空验收
|
|
148
|
+
$ hive-tasks edit old-plan-1a2b --superseded --reason "replaced" # 或 --no-superseded
|
|
149
|
+
~~~
|
|
150
|
+
|
|
151
|
+
空 `--acceptance` 会被拒绝;`--acceptance -` 仅对草稿任务清空验收。`--priority` 必须是
|
|
152
|
+
整数,`--after-set` 会拒绝依赖环;scope 改动会同步任务自己的公告:新增路径以任务的公告者
|
|
153
|
+
(没有就用编辑者)身份公告,被移除且由这张任务认领写下的公告会被释放。edit 事件形如
|
|
154
|
+
`{ task, fields }`,`fields` 只列变化的字段名,不存字段值;lane 没变,所以 stateChangedAt
|
|
155
|
+
不动。
|
|
156
|
+
|
|
157
|
+
`split` 用 JSON 数组给出的至少两张更细的卡替换一张任务:
|
|
158
|
+
|
|
159
|
+
~~~bash
|
|
160
|
+
$ hive-tasks split auth-takes-an-object-dea2 --into '[
|
|
161
|
+
{ "title": "auth schema", "scope": ["src/schema.ts"], "acceptance": "npm test -- schema" },
|
|
162
|
+
{ "title": "auth api", "role": "tester" }
|
|
163
|
+
]'
|
|
164
|
+
~~~
|
|
165
|
+
|
|
166
|
+
每项可带 title(必填)、role、scope、acceptance、after;缺省字段从父任务继承,且每张新卡
|
|
167
|
+
都必须有验收命令。父任务被标 superseded(lane 不变)并让 `replacedBy` 指向第一张新卡;
|
|
168
|
+
加 `--keep` 时保留父任务,每张新卡的 `after` 都引用它,所以父任务 done 后新卡才 ready。
|
|
169
|
+
`--json` 返回 `{ task, cards }`,task_split 事件记录父子 id。claimed 或 done 的任务不能
|
|
170
|
+
拆分,已 superseded 的任务也不能再拆。
|
|
171
|
+
|
|
172
|
+
`supersede <id> --reason R [--replaced-by ID]` 在不改 lane 的前提下退休一张任务:它不再
|
|
173
|
+
进入 ready、next、claim,stats 单独计数。superseded 是标记而不是第五种状态。
|
|
174
|
+
|
|
135
175
|
## 智能体中途死掉怎么办
|
|
136
176
|
|
|
137
177
|
每次认领都带 claimedUntil(--ttl,默认 5 分钟)。时间一过,这个任务就是**可回收的**:
|
package/SPEC.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# hive-tasks protocol
|
|
2
2
|
|
|
3
|
-
Status: implemented, 1.
|
|
3
|
+
Status: implemented, 1.9.0. Protocol version v1 (task blobs keep `v: 1`).
|
|
4
4
|
|
|
5
5
|
## 1. Scope
|
|
6
6
|
|
|
@@ -10,6 +10,7 @@ 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
|
+
- how a task is edited, and how one task is split into subtasks;
|
|
13
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
|
|
|
@@ -98,6 +99,9 @@ Implementation sketch (plumbing, no working tree involved):
|
|
|
98
99
|
| tags | free labels; "fix" is special (see mode) |
|
|
99
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 |
|
|
100
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` |
|
|
101
105
|
| claimedUntil | expiry of the current claim; a claimed task past it is reclaimable |
|
|
102
106
|
| resultCommit | the commit recorded when the task or its current stage was finished |
|
|
103
107
|
| stages | optional ordered stage chain. Absent or [] means a task without stages |
|
|
@@ -170,6 +174,18 @@ and title (`plan[1] ("park the redesign")`). The whole plan is refused before an
|
|
|
170
174
|
is written. An entry may carry both `acceptance` and `"draft": true`; the flag still
|
|
171
175
|
keeps that task out of dispatch.
|
|
172
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.
|
|
188
|
+
|
|
173
189
|
## 4. State machine
|
|
174
190
|
|
|
175
191
|
```
|
|
@@ -219,9 +235,10 @@ task is created, but a later delete can leave that reference dangling on the boa
|
|
|
219
235
|
- done: owner finished and (optionally) a verdict was recorded.
|
|
220
236
|
- failed: the run failed; retry moves it back to pending with attempt preserved.
|
|
221
237
|
|
|
222
|
-
Stored states are pending, claimed, done, failed. ready is always computed. draft
|
|
223
|
-
not
|
|
224
|
-
(
|
|
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.
|
|
225
242
|
|
|
226
243
|
A claimed task carries claimedUntil. Once that time passes the task is **reclaimable**:
|
|
227
244
|
claim may take it over exactly as if it were pending, incrementing attempt. This is how
|
|
@@ -295,8 +312,8 @@ Rules:
|
|
|
295
312
|
|
|
296
313
|
A task is ready when:
|
|
297
314
|
|
|
298
|
-
1. the task is not a draft
|
|
299
|
-
whatever its state;
|
|
315
|
+
1. the task is not a draft or superseded: either flag keeps it out of every dispatch
|
|
316
|
+
computation, whatever its state;
|
|
300
317
|
2. state is pending (or a claim expired and is reclaimable);
|
|
301
318
|
3. every id in after exists and is done;
|
|
302
319
|
4. hive mode is free, or the task is tagged "fix" (the fix must be able to run while the
|
|
@@ -332,6 +349,11 @@ see the same order; the claim CAS still gives exactly one winner per task.
|
|
|
332
349
|
hive-tasks show <id> [--json] # task plus resolved role source
|
|
333
350
|
hive-tasks claim <id> --agent A [--ttl 5m] [--force]
|
|
334
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]
|
|
335
357
|
hive-tasks done <id> [--sha S] [--verdict pass|fail] [--verify]
|
|
336
358
|
hive-tasks fail <id> --reason R
|
|
337
359
|
hive-tasks retry <id> [--stage KEY]
|
|
@@ -386,6 +408,34 @@ deletes pending, failed and done tasks, and refuses a claimed task (exit 2) unle
|
|
|
386
408
|
--force, which releases the claim's announcements first; it prints the deleted task
|
|
387
409
|
(with `deleted: true`) under --json.
|
|
388
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
|
+
|
|
389
439
|
## 7. Role resolution (dispatchers)
|
|
390
440
|
|
|
391
441
|
A dispatcher needs an adapter, a model and a prompt for the role that works a task.
|
|
@@ -433,12 +483,20 @@ staged done and a failed review add extra lines, see below):
|
|
|
433
483
|
```
|
|
434
484
|
|
|
435
485
|
kinds: task_add, task_claim, task_done, task_fail, task_retry, task_renew, task_plan,
|
|
436
|
-
task_delete, reopen, review_failed, stage_done,
|
|
437
|
-
stage_rewound.
|
|
486
|
+
task_edit, task_split, task_supersede, task_delete, reopen, review_failed, stage_done,
|
|
487
|
+
stage_failed, stage_advanced, stage_rewound.
|
|
438
488
|
|
|
439
489
|
`task_delete` records the removed task: it carries both `task` and `id` (the task id),
|
|
440
490
|
`state` (the state the task had when it was deleted) and `actor`.
|
|
441
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`.
|
|
497
|
+
|
|
498
|
+
`task_supersede` carries `task`, `reason` and, when given, `replacedBy`.
|
|
499
|
+
|
|
442
500
|
A review task that fails appends review_failed for the review itself (with reviewOf and
|
|
443
501
|
reopened); when it sends an upstream task back to pending, a reopen event is appended
|
|
444
502
|
too.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hive-tasks",
|
|
3
|
-
"version": "1.
|
|
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": {
|
package/src/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { git, out } from "./git.js";
|
|
5
5
|
import { ensureState, repoInfo } from "./repo.js";
|
|
6
6
|
import { listRaw, mutate, readTask } from "./store.js";
|
|
7
|
-
import { create, isDraft, isReady, isReclaimable, order, reopenPatch, transition } from "./task.js";
|
|
7
|
+
import { create, isDraft, isReady, isReclaimable, isSuperseded, now, order, reopenPatch, transition } from "./task.js";
|
|
8
8
|
import {
|
|
9
9
|
advanceStage,
|
|
10
10
|
currentStage,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
stagesFromFlags,
|
|
21
21
|
} from "./stage.js";
|
|
22
22
|
import { resolveRole } from "./role.js";
|
|
23
|
-
import { addVerdict, claimLeases, parseTtl, readMode, releaseLeases, toKey } from "./lease.js";
|
|
23
|
+
import { addVerdict, claimLeases, listLeases, parseTtl, readMode, releaseLeases, toKey } from "./lease.js";
|
|
24
24
|
import { append } from "./events.js";
|
|
25
25
|
|
|
26
26
|
const VERSION = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
@@ -33,6 +33,14 @@ const USAGE = [
|
|
|
33
33
|
" hive-tasks add --title T (--acceptance CMD | --draft) [--role R] [--scope P]...",
|
|
34
34
|
" [--after ID]... [--review-of ID] [--tag T] [--priority N] [--goal G]",
|
|
35
35
|
" [--stage ROLE[:ACCEPTANCE]]... [--stages FILE]",
|
|
36
|
+
" hive-tasks edit <id> [--title T] [--scope-add P]... [--scope-remove P]...",
|
|
37
|
+
" [--acceptance CMD] [--priority N] [--after-set ID,ID] [--tag +T|-T]... [--role R]",
|
|
38
|
+
" change only the fields you pass",
|
|
39
|
+
" hive-tasks split <id> --into '<json array>' [--keep] [--reason R] [--json]",
|
|
40
|
+
" replace a task with finer entries; the old",
|
|
41
|
+
" task is superseded and points at the first subtask",
|
|
42
|
+
" hive-tasks supersede <id> --reason R [--replaced-by ID]",
|
|
43
|
+
" retire a task without done/failed; never dispatched",
|
|
36
44
|
" hive-tasks list [--json] [--state S] [--role R]",
|
|
37
45
|
" hive-tasks show <id> [--json] card plus the resolved role source",
|
|
38
46
|
" hive-tasks ready [--json] [--limit N] [--role R]",
|
|
@@ -51,8 +59,11 @@ const USAGE = [
|
|
|
51
59
|
"",
|
|
52
60
|
"CARD RULES",
|
|
53
61
|
" add requires --acceptance unless --draft is passed; done --verify runs the command.",
|
|
62
|
+
" edit refuses an empty --acceptance; pass --acceptance - to clear it on a draft card.",
|
|
54
63
|
" --draft stores draft: true: the card stays on the board but is never ready, next or",
|
|
55
64
|
" claimable. Draft is a flag, not a state: pending/claimed/done/failed are unchanged.",
|
|
65
|
+
" superseded is a flag too: edit --superseded/--no-superseded on a pending or failed",
|
|
66
|
+
" task, or supersede in any state. A superseded task is never ready or claimable.",
|
|
56
67
|
"",
|
|
57
68
|
"ENVIRONMENT",
|
|
58
69
|
" HIVE_AGENT=name identity used for claims",
|
|
@@ -70,13 +81,21 @@ function value(argv, index, flag) {
|
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
function parse(argv) {
|
|
73
|
-
const out = { args: [], scopes: [], after: [], tags: [], stageArgs: [], json: false, reason: null, agent: null, ttl: null, verdict: null, sha: null, state: null, role: null, limit: null, title: null, goal: null, priority:
|
|
84
|
+
const out = { args: [], scopes: [], scopeAdd: [], scopeRemove: [], after: [], afterSet: null, tags: [], stageArgs: [], into: [], json: false, keep: false, reason: null, agent: null, ttl: null, verdict: null, sha: null, state: null, role: null, limit: null, title: null, goal: null, priority: null, force: false, acceptance: null, verify: false, file: null, stagesFile: null, reviewOf: null, replacedBy: null, supersedeFlag: null, draft: false };
|
|
74
85
|
for (let i = 0; i < argv.length; i++) {
|
|
75
86
|
const arg = argv[i];
|
|
76
87
|
if (arg === "--json") out.json = true;
|
|
77
88
|
else if (arg === "--force") out.force = true;
|
|
78
89
|
else if (arg === "--scope") out.scopes.push(value(argv, i++, arg));
|
|
90
|
+
else if (arg === "--scope-add") out.scopeAdd.push(value(argv, i++, arg));
|
|
91
|
+
else if (arg === "--scope-remove") out.scopeRemove.push(value(argv, i++, arg));
|
|
79
92
|
else if (arg === "--after") out.after.push(value(argv, i++, arg));
|
|
93
|
+
else if (arg === "--after-set") out.afterSet = value(argv, i++, arg);
|
|
94
|
+
else if (arg === "--into") out.into.push(value(argv, i++, arg));
|
|
95
|
+
else if (arg === "--keep") out.keep = true;
|
|
96
|
+
else if (arg === "--replaced-by") out.replacedBy = value(argv, i++, arg);
|
|
97
|
+
else if (arg === "--superseded") out.supersedeFlag = true;
|
|
98
|
+
else if (arg === "--no-superseded") out.supersedeFlag = false;
|
|
80
99
|
else if (arg === "--review-of") out.reviewOf = value(argv, i++, arg);
|
|
81
100
|
else if (arg === "--tag") out.tags.push(value(argv, i++, arg));
|
|
82
101
|
else if (arg === "--acceptance") out.acceptance = value(argv, i++, arg);
|
|
@@ -126,6 +145,12 @@ function draftClaimMessage(id) {
|
|
|
126
145
|
return "task " + id + " is a draft and cannot be claimed (rm it and re-add with --acceptance)";
|
|
127
146
|
}
|
|
128
147
|
|
|
148
|
+
/** A superseded task keeps its lane but is never dispatched again. */
|
|
149
|
+
function supersededClaimMessage(task) {
|
|
150
|
+
const replaced = task.replacedBy ? " (replaced by " + task.replacedBy + ")" : "";
|
|
151
|
+
return "task " + task.id + " is superseded" + replaced + " and cannot be claimed";
|
|
152
|
+
}
|
|
153
|
+
|
|
129
154
|
function board(repo) {
|
|
130
155
|
return listRaw(repo).map((entry) => entry.value);
|
|
131
156
|
}
|
|
@@ -134,6 +159,193 @@ function byId(tasks) {
|
|
|
134
159
|
return new Map(tasks.map((task) => [task.id, task]));
|
|
135
160
|
}
|
|
136
161
|
|
|
162
|
+
/** Parse --after-set: a comma list of dependency ids; an empty value clears it. */
|
|
163
|
+
function parseAfterSet(text) {
|
|
164
|
+
const ids = [];
|
|
165
|
+
for (const part of String(text).split(",")) {
|
|
166
|
+
const id = part.trim();
|
|
167
|
+
if (id !== "" && !ids.includes(id)) ids.push(id);
|
|
168
|
+
}
|
|
169
|
+
return ids;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** True when following `afterIds` from the edited task can reach the task itself. */
|
|
173
|
+
function dependencyCycle(map, taskId, afterIds) {
|
|
174
|
+
const seen = new Set();
|
|
175
|
+
const stack = [...afterIds];
|
|
176
|
+
while (stack.length > 0) {
|
|
177
|
+
const id = stack.pop();
|
|
178
|
+
if (id === taskId) return true;
|
|
179
|
+
if (seen.has(id)) continue;
|
|
180
|
+
seen.add(id);
|
|
181
|
+
const task = map.get(id);
|
|
182
|
+
if (!task) continue;
|
|
183
|
+
stack.push(...(task.after || []));
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Compute the patch and the changed field names for `edit`. Only fields the
|
|
190
|
+
* caller passed can change; every validation throws and the caller turns the
|
|
191
|
+
* message into exit 2 inside the CAS. Values are never stored in the event.
|
|
192
|
+
*/
|
|
193
|
+
function planEdit(task, options, map) {
|
|
194
|
+
const patch = {};
|
|
195
|
+
const fields = [];
|
|
196
|
+
|
|
197
|
+
if (options.title !== null) {
|
|
198
|
+
const title = String(options.title).trim();
|
|
199
|
+
if (title === "") throw new Error("edit: --title must not be empty");
|
|
200
|
+
if (title !== task.title) { patch.title = title; fields.push("title"); }
|
|
201
|
+
}
|
|
202
|
+
if (options.role !== null) {
|
|
203
|
+
const role = String(options.role).trim();
|
|
204
|
+
if (role === "") throw new Error("edit: --role must not be empty");
|
|
205
|
+
if (role !== task.role) { patch.role = role; fields.push("role"); }
|
|
206
|
+
}
|
|
207
|
+
if (options.priority !== null) {
|
|
208
|
+
if (!Number.isInteger(options.priority)) throw new Error("edit: --priority must be an integer");
|
|
209
|
+
if (options.priority !== task.priority) { patch.priority = options.priority; fields.push("priority"); }
|
|
210
|
+
}
|
|
211
|
+
if (options.acceptance !== null) {
|
|
212
|
+
const text = String(options.acceptance).trim();
|
|
213
|
+
if (text === "") throw new Error("edit: --acceptance must not be empty (use --acceptance - to clear it)");
|
|
214
|
+
if (text === "-") {
|
|
215
|
+
if (!isDraft(task)) throw new Error("edit: only a draft card can clear its acceptance (--acceptance -)");
|
|
216
|
+
if (task.acceptance !== "") { patch.acceptance = ""; fields.push("acceptance"); }
|
|
217
|
+
} else if (text !== task.acceptance) {
|
|
218
|
+
patch.acceptance = text;
|
|
219
|
+
fields.push("acceptance");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (options.scopeAdd.length > 0 || options.scopeRemove.length > 0) {
|
|
223
|
+
const add = [];
|
|
224
|
+
for (const raw of options.scopeAdd) {
|
|
225
|
+
const path = String(raw).trim();
|
|
226
|
+
if (path === "") throw new Error("edit: --scope-add needs a non-empty path");
|
|
227
|
+
if (!add.includes(path)) add.push(path);
|
|
228
|
+
}
|
|
229
|
+
const remove = [];
|
|
230
|
+
for (const raw of options.scopeRemove) {
|
|
231
|
+
const path = String(raw).trim();
|
|
232
|
+
if (path === "") throw new Error("edit: --scope-remove needs a non-empty path");
|
|
233
|
+
if (!remove.includes(path)) remove.push(path);
|
|
234
|
+
}
|
|
235
|
+
for (const path of add) {
|
|
236
|
+
if (remove.includes(path)) throw new Error("edit: scope path " + path + " is both added and removed");
|
|
237
|
+
}
|
|
238
|
+
const missing = remove.filter((path) => !task.scope.includes(path));
|
|
239
|
+
if (missing.length > 0) throw new Error("edit: --scope-remove: not in scope: " + missing.join(", "));
|
|
240
|
+
const scope = task.scope.filter((path) => !remove.includes(path));
|
|
241
|
+
for (const path of add) if (!scope.includes(path)) scope.push(path);
|
|
242
|
+
const same = scope.length === task.scope.length && scope.every((path, index) => path === task.scope[index]);
|
|
243
|
+
if (!same) { patch.scope = scope; fields.push("scope"); }
|
|
244
|
+
}
|
|
245
|
+
if (options.afterSet !== null) {
|
|
246
|
+
const ids = parseAfterSet(options.afterSet);
|
|
247
|
+
for (const dep of ids) {
|
|
248
|
+
if (dep === task.id) throw new Error("edit: a card cannot depend on itself");
|
|
249
|
+
if (!map.has(dep)) throw new Error("edit: --after-set: no such task: " + dep);
|
|
250
|
+
}
|
|
251
|
+
if (task.reviewOf && !ids.includes(task.reviewOf)) {
|
|
252
|
+
throw new Error("edit: --after-set must keep the review-of card " + task.reviewOf);
|
|
253
|
+
}
|
|
254
|
+
const same = ids.length === task.after.length
|
|
255
|
+
&& [...ids].sort().join("\u0000") === [...task.after].sort().join("\u0000");
|
|
256
|
+
if (!same) {
|
|
257
|
+
if (dependencyCycle(map, task.id, ids)) {
|
|
258
|
+
throw new Error("edit: --after-set would create a dependency cycle through " + task.id);
|
|
259
|
+
}
|
|
260
|
+
patch.after = ids;
|
|
261
|
+
fields.push("after");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (options.tags.length > 0) {
|
|
265
|
+
const add = [];
|
|
266
|
+
const remove = [];
|
|
267
|
+
for (const raw of options.tags) {
|
|
268
|
+
const text = String(raw).trim();
|
|
269
|
+
if (text.length < 2 || (text[0] !== "+" && text[0] !== "-")) {
|
|
270
|
+
throw new Error("edit: --tag must look like +name or -name");
|
|
271
|
+
}
|
|
272
|
+
const name = text.slice(1).trim();
|
|
273
|
+
if (name === "") throw new Error("edit: --tag must look like +name or -name");
|
|
274
|
+
if (text[0] === "+") { if (!add.includes(name)) add.push(name); }
|
|
275
|
+
else if (!remove.includes(name)) remove.push(name);
|
|
276
|
+
}
|
|
277
|
+
for (const name of add) {
|
|
278
|
+
if (remove.includes(name)) throw new Error("edit: tag " + name + " is both added and removed");
|
|
279
|
+
}
|
|
280
|
+
const tags = task.tags.filter((tag) => !remove.includes(tag));
|
|
281
|
+
for (const name of add) if (!tags.includes(name)) tags.push(name);
|
|
282
|
+
const same = tags.length === task.tags.length
|
|
283
|
+
&& [...tags].sort().join("\u0000") === [...task.tags].sort().join("\u0000");
|
|
284
|
+
if (!same) { patch.tags = tags; fields.push("tags"); }
|
|
285
|
+
}
|
|
286
|
+
const clear = [];
|
|
287
|
+
if (options.supersedeFlag !== null) {
|
|
288
|
+
if (options.supersedeFlag === true) {
|
|
289
|
+
if (task.superseded !== true) {
|
|
290
|
+
patch.superseded = true;
|
|
291
|
+
patch.supersededReason = options.reason !== null ? String(options.reason).trim() : "superseded by edit";
|
|
292
|
+
fields.push("superseded");
|
|
293
|
+
}
|
|
294
|
+
} else if (task.superseded === true) {
|
|
295
|
+
clear.push("superseded", "supersededReason", "replacedBy");
|
|
296
|
+
fields.push("superseded");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return { patch, fields, clear };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** A JSON array of strings, per split entry field. */
|
|
303
|
+
function splitStringList(value, where) {
|
|
304
|
+
if (!Array.isArray(value)) throw new Error(where + " must be a JSON array of strings");
|
|
305
|
+
const list = [];
|
|
306
|
+
for (const entry of value) {
|
|
307
|
+
if (typeof entry !== "string" || entry.trim() === "") throw new Error(where + " must contain non-empty strings");
|
|
308
|
+
if (!list.includes(entry.trim())) list.push(entry.trim());
|
|
309
|
+
}
|
|
310
|
+
return list;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** One --into entry: { title, role?, scope?, acceptance?, after? }. */
|
|
314
|
+
function splitItem(entry, index) {
|
|
315
|
+
const where = "split: --into[" + index + "]";
|
|
316
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) throw new Error(where + " must be an object");
|
|
317
|
+
const title = typeof entry.title === "string" ? entry.title.trim() : "";
|
|
318
|
+
if (title === "") throw new Error(where + " needs a non-empty title");
|
|
319
|
+
const item = { title };
|
|
320
|
+
if (entry.role !== undefined) {
|
|
321
|
+
if (typeof entry.role !== "string" || entry.role.trim() === "") throw new Error(where + ".role must be a non-empty string");
|
|
322
|
+
item.role = entry.role.trim();
|
|
323
|
+
}
|
|
324
|
+
if (entry.scope !== undefined) item.scope = splitStringList(entry.scope, where + ".scope");
|
|
325
|
+
if (entry.acceptance !== undefined) {
|
|
326
|
+
if (typeof entry.acceptance !== "string" || entry.acceptance.trim() === "") throw new Error(where + ".acceptance must be a non-empty string");
|
|
327
|
+
item.acceptance = entry.acceptance.trim();
|
|
328
|
+
}
|
|
329
|
+
if (entry.after !== undefined) item.after = splitStringList(entry.after, where + ".after");
|
|
330
|
+
return item;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** --into takes one JSON array with at least two entries. */
|
|
334
|
+
function splitItems(values) {
|
|
335
|
+
const raw = values.map((value) => String(value).trim()).filter((value) => value !== "");
|
|
336
|
+
const text = raw.length === 1 ? raw[0] : raw.join(" ");
|
|
337
|
+
if (text === "") throw new Error("split needs --into '<json array>'");
|
|
338
|
+
if (!text.startsWith("[")) throw new Error("split: --into must be a JSON array");
|
|
339
|
+
let parsed;
|
|
340
|
+
try {
|
|
341
|
+
parsed = JSON.parse(text);
|
|
342
|
+
} catch {
|
|
343
|
+
throw new Error("split: --into is not valid JSON");
|
|
344
|
+
}
|
|
345
|
+
if (!Array.isArray(parsed) || parsed.length < 2) throw new Error("split: --into JSON array needs at least two entries");
|
|
346
|
+
return parsed.map((entry, index) => splitItem(entry, index));
|
|
347
|
+
}
|
|
348
|
+
|
|
137
349
|
/** The target key of a retry/reopen --stage flag (the last one wins). */
|
|
138
350
|
function stageTarget(options) {
|
|
139
351
|
return options.stageArgs.length ? options.stageArgs[options.stageArgs.length - 1] : null;
|
|
@@ -174,6 +386,12 @@ function printTask(task, json, extra = {}, extraLines = []) {
|
|
|
174
386
|
}
|
|
175
387
|
}
|
|
176
388
|
if (task.draft) process.stdout.write(indent + "draft: true (never ready, not claimable)\n");
|
|
389
|
+
if (task.superseded) {
|
|
390
|
+
const parts = ["superseded: true"];
|
|
391
|
+
if (task.supersededReason) parts.push("reason: " + task.supersededReason);
|
|
392
|
+
if (task.replacedBy) parts.push("replaced by: " + task.replacedBy);
|
|
393
|
+
process.stdout.write(indent + parts.join(" ") + "\n");
|
|
394
|
+
}
|
|
177
395
|
if (task.scope.length) process.stdout.write(indent + "scope: " + task.scope.join(", ") + "\n");
|
|
178
396
|
if (task.after.length) process.stdout.write(indent + "after: " + task.after.join(", ") + "\n");
|
|
179
397
|
if (task.reviewOf) process.stdout.write(indent + "review-of: " + task.reviewOf + "\n");
|
|
@@ -378,6 +596,178 @@ function run(argv) {
|
|
|
378
596
|
return process.stdout.write(id + " deleted [" + deleted.state + "] " + deleted.title + "\n");
|
|
379
597
|
}
|
|
380
598
|
|
|
599
|
+
if (command === "edit") {
|
|
600
|
+
const id = options.args[0];
|
|
601
|
+
if (!id) fail("edit needs a task id", 2);
|
|
602
|
+
const actor = options.agent || process.env.HIVE_AGENT || "unknown";
|
|
603
|
+
if (!readTask(repo, id)) fail("no such task: " + id, 2);
|
|
604
|
+
const hasEdit = options.title !== null
|
|
605
|
+
|| options.role !== null
|
|
606
|
+
|| options.priority !== null
|
|
607
|
+
|| options.acceptance !== null
|
|
608
|
+
|| options.scopeAdd.length > 0
|
|
609
|
+
|| options.scopeRemove.length > 0
|
|
610
|
+
|| options.afterSet !== null
|
|
611
|
+
|| options.tags.length > 0
|
|
612
|
+
|| options.supersedeFlag !== null;
|
|
613
|
+
if (!hasEdit) {
|
|
614
|
+
fail("edit needs at least one field: --title, --scope-add, --scope-remove, --acceptance, --priority, --after-set, --tag, --role, --superseded", 2);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// Metadata only: the lane (state/stage/stageState) never changes here, so
|
|
618
|
+
// stateChangedAt is left alone and only updatedAt moves.
|
|
619
|
+
let previous = null;
|
|
620
|
+
let updated = null;
|
|
621
|
+
let fields = [];
|
|
622
|
+
try {
|
|
623
|
+
const result = mutate(repo, (tasks) => {
|
|
624
|
+
const map = byId(tasks);
|
|
625
|
+
const task = map.get(id);
|
|
626
|
+
if (!task) throw new Error("no such task: " + id);
|
|
627
|
+
if (task.state !== "pending" && task.state !== "failed") {
|
|
628
|
+
const hint = task.state === "claimed" ? "; done or fail it first" : task.state === "done" ? "; reopen it first" : "";
|
|
629
|
+
throw new Error("edit: task " + id + " is " + task.state + hint + " (edit only works on pending or failed tasks)");
|
|
630
|
+
}
|
|
631
|
+
const plan = planEdit(task, options, map);
|
|
632
|
+
if (plan.fields.length === 0) { updated = task; fields = []; return null; }
|
|
633
|
+
previous = task;
|
|
634
|
+
fields = plan.fields;
|
|
635
|
+
updated = { ...task, ...plan.patch, updatedAt: now() };
|
|
636
|
+
for (const key of plan.clear) delete updated[key];
|
|
637
|
+
return tasks.map((entry) => (entry.id === id ? updated : entry));
|
|
638
|
+
});
|
|
639
|
+
if (!result.ok) fail("could not edit " + id + " (too much contention)");
|
|
640
|
+
} catch (error) {
|
|
641
|
+
fail(error.message, 2);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Keep the announcement board in sync with the task scope: added paths are
|
|
645
|
+
// announced under the task announcer (or the editor) and removed paths a
|
|
646
|
+
// claim of this task wrote are released.
|
|
647
|
+
if (fields.includes("scope")) {
|
|
648
|
+
const added = updated.scope.filter((path) => !previous.scope.includes(path));
|
|
649
|
+
const removed = previous.scope.filter((path) => !updated.scope.includes(path));
|
|
650
|
+
const announced = listLeases(repo).filter((entry) => (entry.value.task || "") === id);
|
|
651
|
+
const ttlMs = parseTtl(options.ttl);
|
|
652
|
+
const announcer = announced.length > 0 ? announced[0].value.agent : actor;
|
|
653
|
+
if (added.length > 0) claimLeases(repo, { paths: added, agent: announcer, ttlMs, taskId: id });
|
|
654
|
+
if (removed.length > 0) {
|
|
655
|
+
for (const agent of new Set(announced.map((entry) => entry.value.agent))) {
|
|
656
|
+
releaseLeases(repo, { paths: removed, agent });
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (fields.length > 0) {
|
|
661
|
+
const changed = {};
|
|
662
|
+
for (const name of fields) changed[name] = true;
|
|
663
|
+
append(repo, { actor, kind: "task_edit", task: id, fields: changed });
|
|
664
|
+
}
|
|
665
|
+
return printTask(updated, options.json);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
if (command === "split") {
|
|
669
|
+
const id = options.args[0];
|
|
670
|
+
if (!id) fail("split needs a task id", 2);
|
|
671
|
+
const actor = options.agent || process.env.HIVE_AGENT || "unknown";
|
|
672
|
+
if (!readTask(repo, id)) fail("no such task: " + id, 2);
|
|
673
|
+
if (options.into.length === 0) fail("split needs --into '<json array>'", 2);
|
|
674
|
+
|
|
675
|
+
let parent = null;
|
|
676
|
+
let cards = [];
|
|
677
|
+
try {
|
|
678
|
+
const result = mutate(repo, (tasks) => {
|
|
679
|
+
const map = byId(tasks);
|
|
680
|
+
const task = map.get(id);
|
|
681
|
+
if (!task) throw new Error("no such task: " + id);
|
|
682
|
+
if (task.state !== "pending" && task.state !== "failed") {
|
|
683
|
+
const hint = task.state === "claimed" ? "; done or fail it first" : task.state === "done" ? "; reopen it first" : "";
|
|
684
|
+
throw new Error("split: task " + id + " is " + task.state + hint + " (split only works on pending or failed tasks)");
|
|
685
|
+
}
|
|
686
|
+
if (isSuperseded(task)) throw new Error("split: task " + id + " is already superseded");
|
|
687
|
+
const items = splitItems(options.into);
|
|
688
|
+
const parentDeps = Array.isArray(task.after) ? task.after.filter((dep) => dep !== id) : [];
|
|
689
|
+
cards = items.map((item, index) => {
|
|
690
|
+
const acceptance = item.acceptance !== undefined ? item.acceptance : task.acceptance;
|
|
691
|
+
if (!String(acceptance || "").trim()) {
|
|
692
|
+
throw new Error("split: --into[" + index + "] needs an acceptance command (the parent has none to inherit)");
|
|
693
|
+
}
|
|
694
|
+
const after = item.after !== undefined ? [...item.after] : [...parentDeps];
|
|
695
|
+
for (const dep of after) {
|
|
696
|
+
if (dep === id) throw new Error("split: --into[" + index + "].after cannot depend on the task being split");
|
|
697
|
+
if (!map.has(dep)) throw new Error("split: --into[" + index + "].after: no such task: " + dep);
|
|
698
|
+
}
|
|
699
|
+
const childAfter = options.keep && !after.includes(id) ? [...after, id] : after;
|
|
700
|
+
return create({
|
|
701
|
+
title: item.title,
|
|
702
|
+
role: item.role !== undefined ? item.role : task.role,
|
|
703
|
+
scope: item.scope !== undefined ? [...item.scope] : [...(task.scope || [])],
|
|
704
|
+
after: childAfter,
|
|
705
|
+
priority: task.priority,
|
|
706
|
+
tags: [...(task.tags || [])],
|
|
707
|
+
acceptance,
|
|
708
|
+
createdBy: actor,
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
if (options.keep) {
|
|
712
|
+
parent = task;
|
|
713
|
+
return [...tasks, ...cards];
|
|
714
|
+
}
|
|
715
|
+
const reason = options.reason !== null ? String(options.reason).trim() : "split into " + cards.length;
|
|
716
|
+
parent = { ...task, superseded: true, supersededReason: reason, replacedBy: cards[0].id, updatedAt: now() };
|
|
717
|
+
return [...tasks.map((entry) => (entry.id === id ? parent : entry)), ...cards];
|
|
718
|
+
});
|
|
719
|
+
if (!result.ok) fail("could not split " + id + " (too much contention)");
|
|
720
|
+
} catch (error) {
|
|
721
|
+
fail(error.message, 2);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
const event = { actor, kind: "task_split", task: id, cards: cards.map((card) => card.id), kept: Boolean(options.keep) };
|
|
725
|
+
if (!options.keep) event.replacedBy = cards[0].id;
|
|
726
|
+
append(repo, event);
|
|
727
|
+
if (options.json) {
|
|
728
|
+
const payload = { task: viewTask(parent), cards: cards.map((card) => viewTask(card)) };
|
|
729
|
+
return process.stdout.write(JSON.stringify(payload, null, 2) + "\n");
|
|
730
|
+
}
|
|
731
|
+
printTask(parent, false);
|
|
732
|
+
for (const card of cards) process.stdout.write(" " + card.id + " " + card.title + "\n");
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
if (command === "supersede") {
|
|
737
|
+
const id = options.args[0];
|
|
738
|
+
if (!id) fail("supersede needs a task id", 2);
|
|
739
|
+
const reason = options.reason === null ? "" : String(options.reason).trim();
|
|
740
|
+
if (reason === "") fail("supersede needs --reason R", 2);
|
|
741
|
+
const actor = options.agent || process.env.HIVE_AGENT || "unknown";
|
|
742
|
+
if (!readTask(repo, id)) fail("no such task: " + id, 2);
|
|
743
|
+
let updated = null;
|
|
744
|
+
try {
|
|
745
|
+
const result = mutate(repo, (tasks) => {
|
|
746
|
+
const map = byId(tasks);
|
|
747
|
+
const task = map.get(id);
|
|
748
|
+
if (!task) throw new Error("no such task: " + id);
|
|
749
|
+
if (isSuperseded(task)) throw new Error("task " + id + " is already superseded");
|
|
750
|
+
const patch = { superseded: true, supersededReason: reason, updatedAt: now() };
|
|
751
|
+
if (options.replacedBy !== null) {
|
|
752
|
+
const replacement = String(options.replacedBy).trim();
|
|
753
|
+
if (replacement === "") throw new Error("supersede: --replaced-by must not be empty");
|
|
754
|
+
if (replacement === id) throw new Error("supersede: a task cannot replace itself");
|
|
755
|
+
if (!map.has(replacement)) throw new Error("supersede: --replaced-by: no such task: " + replacement);
|
|
756
|
+
patch.replacedBy = replacement;
|
|
757
|
+
}
|
|
758
|
+
updated = { ...task, ...patch };
|
|
759
|
+
return tasks.map((entry) => (entry.id === id ? updated : entry));
|
|
760
|
+
});
|
|
761
|
+
if (!result.ok) fail("could not supersede " + id + " (too much contention)");
|
|
762
|
+
} catch (error) {
|
|
763
|
+
fail(error.message, 2);
|
|
764
|
+
}
|
|
765
|
+
const event = { actor, kind: "task_supersede", task: id, reason };
|
|
766
|
+
if (updated.replacedBy) event.replacedBy = updated.replacedBy;
|
|
767
|
+
append(repo, event);
|
|
768
|
+
return printTask(updated, options.json);
|
|
769
|
+
}
|
|
770
|
+
|
|
381
771
|
if (command === "add") {
|
|
382
772
|
if (!options.title) fail("--title is required", 2);
|
|
383
773
|
// Mechanical enforcement of the acceptance rule: a card that can be dispatched
|
|
@@ -436,7 +826,10 @@ function run(argv) {
|
|
|
436
826
|
return process.stdout.write(JSON.stringify(rows, null, 2) + "\n");
|
|
437
827
|
}
|
|
438
828
|
if (limited.length === 0) return process.stdout.write(command === "ready" ? "Nothing ready.\n" : "No tasks.\n");
|
|
439
|
-
for (const task of limited)
|
|
829
|
+
for (const task of limited) {
|
|
830
|
+
const tags = (task.draft ? " [draft]" : "") + (task.superseded ? " [superseded]" : "");
|
|
831
|
+
process.stdout.write(task.id.padEnd(34) + task.state.padEnd(9) + stageRole(task).padEnd(11) + task.title + tags + "\n");
|
|
832
|
+
}
|
|
440
833
|
return;
|
|
441
834
|
}
|
|
442
835
|
|
|
@@ -471,6 +864,7 @@ function run(argv) {
|
|
|
471
864
|
const preview = readTask(repo, id);
|
|
472
865
|
if (!preview) fail("no such task: " + id, 2);
|
|
473
866
|
if (isDraft(preview)) fail(draftClaimMessage(id), 2);
|
|
867
|
+
if (isSuperseded(preview)) fail(supersededClaimMessage(preview), 2);
|
|
474
868
|
if (readMode(repo) === "freeze" && !options.force && !(preview.tags || []).includes("fix")) {
|
|
475
869
|
fail("mode is freeze: only fix-tagged cards may be claimed (use --force to override)", 2);
|
|
476
870
|
}
|
|
@@ -488,6 +882,7 @@ function run(argv) {
|
|
|
488
882
|
const task = map.get(id);
|
|
489
883
|
if (!task) throw new Error("no such task: " + id);
|
|
490
884
|
if (isDraft(task)) throw new Error(draftClaimMessage(id));
|
|
885
|
+
if (isSuperseded(task)) throw new Error(supersededClaimMessage(task));
|
|
491
886
|
const canReclaim = isReclaimable(task);
|
|
492
887
|
if (task.state !== "pending" && !canReclaim) throw new Error("task " + id + " is " + task.state + stageOf(task));
|
|
493
888
|
if (isStaged(task) && task.stageState !== "pending" && !(task.stageState === "claimed" && canReclaim)) {
|
|
@@ -659,16 +1054,21 @@ function run(argv) {
|
|
|
659
1054
|
const items = board(repo);
|
|
660
1055
|
const byState = {};
|
|
661
1056
|
const byRole = {};
|
|
1057
|
+
let superseded = 0;
|
|
662
1058
|
let oldest = null;
|
|
663
1059
|
for (const task of items) {
|
|
1060
|
+
// Superseded tasks keep their lane but are counted separately, never as a
|
|
1061
|
+
// state or role of the live board.
|
|
1062
|
+
if (isSuperseded(task)) { superseded += 1; continue; }
|
|
664
1063
|
byState[task.state] = (byState[task.state] || 0) + 1;
|
|
665
1064
|
byRole[task.role] = (byRole[task.role] || 0) + 1;
|
|
666
1065
|
if (task.state === "pending" && (!oldest || task.createdAt < oldest.createdAt)) oldest = task;
|
|
667
1066
|
}
|
|
668
|
-
const summary = { total: items.length, byState, byRole, oldestPending: oldest ? { id: oldest.id, createdAt: oldest.createdAt } : null };
|
|
1067
|
+
const summary = { total: items.length, byState, byRole, superseded, oldestPending: oldest ? { id: oldest.id, createdAt: oldest.createdAt } : null };
|
|
669
1068
|
if (options.json) return process.stdout.write(JSON.stringify(summary, null, 2) + "\n");
|
|
670
1069
|
process.stdout.write("cards: " + summary.total + "\n");
|
|
671
1070
|
for (const [state, count] of Object.entries(byState)) process.stdout.write(" " + state.padEnd(8) + count + "\n");
|
|
1071
|
+
if (superseded > 0) process.stdout.write(" " + "superseded".padEnd(8) + superseded + "\n");
|
|
672
1072
|
if (oldest) process.stdout.write("oldest pending: " + oldest.id + " (" + oldest.createdAt + ")\n");
|
|
673
1073
|
return;
|
|
674
1074
|
}
|
package/src/lease.js
CHANGED
|
@@ -128,6 +128,18 @@ export function claimLeases(repo, { paths, agent, ttlMs, taskId }) {
|
|
|
128
128
|
return { granted: true, keys, overlaps };
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/** Every announcement currently on the board: [{ key, value }]. */
|
|
132
|
+
export function listLeases(repo) {
|
|
133
|
+
const raw = git(["for-each-ref", "refs/hive/v1/lease", "--format=%(refname)"], { cwd: repo.top }).stdout.trim();
|
|
134
|
+
if (!raw) return [];
|
|
135
|
+
const prefix = NS + "/lease/";
|
|
136
|
+
return raw
|
|
137
|
+
.split("\n")
|
|
138
|
+
.filter((ref) => ref.endsWith("/" + KEY_LEAF))
|
|
139
|
+
.map((ref) => ({ key: ref.slice(prefix.length, -(KEY_LEAF.length + 1)), value: readBlob(repo, ref) }))
|
|
140
|
+
.filter((entry) => entry.value);
|
|
141
|
+
}
|
|
142
|
+
|
|
131
143
|
export function releaseLeases(repo, { paths, agent }) {
|
|
132
144
|
const released = [];
|
|
133
145
|
for (const key of paths.map(toKey)) {
|
package/src/task.js
CHANGED
|
@@ -64,6 +64,11 @@ export function isDraft(task) {
|
|
|
64
64
|
return Boolean(task && task.draft === true);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** superseded is a flag, not a state: the task keeps its lane but is never dispatched. */
|
|
68
|
+
export function isSuperseded(task) {
|
|
69
|
+
return Boolean(task && task.superseded === true);
|
|
70
|
+
}
|
|
71
|
+
|
|
67
72
|
/** A claimed card whose claim expired can be taken over by the next agent. */
|
|
68
73
|
export function isReclaimable(task, now = Date.now()) {
|
|
69
74
|
if (task.state !== "claimed") return false;
|
|
@@ -82,8 +87,8 @@ function depsDone(task, byId) {
|
|
|
82
87
|
* (pending, or claimed and expired so it can be recovered).
|
|
83
88
|
*/
|
|
84
89
|
export function isReady(task, byId, { modeFree = true, now = Date.now() } = {}) {
|
|
85
|
-
//
|
|
86
|
-
if (isDraft(task)) return false;
|
|
90
|
+
// Draft and superseded never enter a dispatch computation, whatever their state.
|
|
91
|
+
if (isDraft(task) || isSuperseded(task)) return false;
|
|
87
92
|
const claimable = task.state === "pending" || isReclaimable(task, now);
|
|
88
93
|
if (!claimable) return false;
|
|
89
94
|
if (!depsDone(task, byId)) return false;
|