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/CHANGELOG.md +110 -0
- package/README.md +181 -70
- package/README.zh-CN.md +173 -74
- package/SPEC.md +252 -117
- package/package.json +1 -1
- package/src/cli.js +446 -12
- package/src/lease.js +12 -0
- package/src/task.js +32 -2
package/src/task.js
CHANGED
|
@@ -21,7 +21,7 @@ export function now() {
|
|
|
21
21
|
return new Date().toISOString();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function create({ title, goal, role, scope, after, priority, createdBy, tags, acceptance, reviewOf, stages }) {
|
|
24
|
+
export function create({ title, goal, role, scope, after, priority, createdBy, tags, acceptance, reviewOf, stages, draft }) {
|
|
25
25
|
if (!title || !title.trim()) throw new Error("title is required");
|
|
26
26
|
const time = now();
|
|
27
27
|
const firstRole = Array.isArray(stages) && stages[0] ? stages[0].role : null;
|
|
@@ -47,13 +47,28 @@ export function create({ title, goal, role, scope, after, priority, createdBy, t
|
|
|
47
47
|
createdBy: createdBy || "unknown",
|
|
48
48
|
createdAt: time,
|
|
49
49
|
updatedAt: time,
|
|
50
|
+
stateChangedAt: time,
|
|
50
51
|
};
|
|
52
|
+
// draft is an optional flag, never a state: a draft card keeps the normal
|
|
53
|
+
// pending/claimed/done/failed machine but is never dispatched. Normal cards
|
|
54
|
+
// omit the key entirely, exactly like the other optional fields.
|
|
55
|
+
if (draft) task.draft = true;
|
|
51
56
|
// A card without stages is untouched: no stage fields are stored at all, so
|
|
52
57
|
// 1.3.0 blobs and 1.4.0 legacy blobs are identical.
|
|
53
58
|
if (stages && stages.length > 0) Object.assign(task, initialStageFields(stages));
|
|
54
59
|
return task;
|
|
55
60
|
}
|
|
56
61
|
|
|
62
|
+
/** A draft is a flag, not a state: it only removes the card from dispatch. */
|
|
63
|
+
export function isDraft(task) {
|
|
64
|
+
return Boolean(task && task.draft === true);
|
|
65
|
+
}
|
|
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
|
+
|
|
57
72
|
/** A claimed card whose claim expired can be taken over by the next agent. */
|
|
58
73
|
export function isReclaimable(task, now = Date.now()) {
|
|
59
74
|
if (task.state !== "claimed") return false;
|
|
@@ -72,6 +87,8 @@ function depsDone(task, byId) {
|
|
|
72
87
|
* (pending, or claimed and expired so it can be recovered).
|
|
73
88
|
*/
|
|
74
89
|
export function isReady(task, byId, { modeFree = true, now = Date.now() } = {}) {
|
|
90
|
+
// Draft and superseded never enter a dispatch computation, whatever their state.
|
|
91
|
+
if (isDraft(task) || isSuperseded(task)) return false;
|
|
75
92
|
const claimable = task.state === "pending" || isReclaimable(task, now);
|
|
76
93
|
if (!claimable) return false;
|
|
77
94
|
if (!depsDone(task, byId)) return false;
|
|
@@ -86,9 +103,22 @@ export function order(a, b) {
|
|
|
86
103
|
return a.createdAt < b.createdAt ? -1 : 1;
|
|
87
104
|
}
|
|
88
105
|
|
|
106
|
+
/**
|
|
107
|
+
* The lane a card is in: its state plus the current stage and stage state. A
|
|
108
|
+
* stage advance can keep the card pending, so state alone is not enough.
|
|
109
|
+
*/
|
|
110
|
+
function laneKey(task) {
|
|
111
|
+
return [task.state, task.stage == null ? "" : task.stage, task.stageState == null ? "" : task.stageState].join("\u0000");
|
|
112
|
+
}
|
|
113
|
+
|
|
89
114
|
export function transition(task, next, patch = {}) {
|
|
90
115
|
if (!STATES.includes(next)) throw new Error("unknown state: " + next);
|
|
91
|
-
|
|
116
|
+
const updated = { ...task, ...patch, state: next };
|
|
117
|
+
// stateChangedAt tracks real lane/stage moves only; a patch that leaves the
|
|
118
|
+
// lane alone (a reason, a verdict, metadata) must not reset it.
|
|
119
|
+
if (laneKey(updated) !== laneKey(task)) updated.stateChangedAt = now();
|
|
120
|
+
updated.updatedAt = now();
|
|
121
|
+
return updated;
|
|
92
122
|
}
|
|
93
123
|
|
|
94
124
|
/**
|