hive-tasks 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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, isReady, isReclaimable, order, reopenPatch, transition } from "./task.js";
7
+ import { create, isDraft, isReady, isReclaimable, order, reopenPatch, transition } from "./task.js";
8
8
  import {
9
9
  advanceStage,
10
10
  currentStage,
@@ -30,8 +30,8 @@ const USAGE = [
30
30
  "",
31
31
  "USAGE",
32
32
  " hive-tasks init create .hive/ and the AGENTS.md section",
33
- " hive-tasks add --title T [--role R] [--scope P]... [--after ID]... [--review-of ID]",
34
- " [--tag T] [--priority N] [--goal G] [--acceptance CMD]",
33
+ " hive-tasks add --title T (--acceptance CMD | --draft) [--role R] [--scope P]...",
34
+ " [--after ID]... [--review-of ID] [--tag T] [--priority N] [--goal G]",
35
35
  " [--stage ROLE[:ACCEPTANCE]]... [--stages FILE]",
36
36
  " hive-tasks list [--json] [--state S] [--role R]",
37
37
  " hive-tasks show <id> [--json] card plus the resolved role source",
@@ -39,7 +39,8 @@ const USAGE = [
39
39
  " hive-tasks next [--role R] [--json] the single best candidate",
40
40
  " hive-tasks claim <id> --agent A [--ttl 5m] card CAS, then announce scope paths",
41
41
  " hive-tasks renew <id> [--ttl 5m] extend a claim",
42
- " hive-tasks plan --file plan.json create a whole DAG in one transaction",
42
+ " hive-tasks plan --file plan.json create a whole DAG in one transaction;",
43
+ " every entry needs acceptance unless draft: true",
43
44
  " hive-tasks done <id> [--sha S] [--verdict pass|fail] [--verify]",
44
45
  " hive-tasks fail <id> --reason R",
45
46
  " hive-tasks retry <id> [--stage KEY] failed back to pending",
@@ -48,6 +49,11 @@ const USAGE = [
48
49
  " resets to KEY (default the first stage)",
49
50
  " hive-tasks rm <id> [--force] [--json] delete a card; a claimed card needs --force",
50
51
  "",
52
+ "CARD RULES",
53
+ " add requires --acceptance unless --draft is passed; done --verify runs the command.",
54
+ " --draft stores draft: true: the card stays on the board but is never ready, next or",
55
+ " claimable. Draft is a flag, not a state: pending/claimed/done/failed are unchanged.",
56
+ "",
51
57
  "ENVIRONMENT",
52
58
  " HIVE_AGENT=name identity used for claims",
53
59
  ].join("\n");
@@ -64,7 +70,7 @@ function value(argv, index, flag) {
64
70
  }
65
71
 
66
72
  function parse(argv) {
67
- 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: 0, force: false, acceptance: null, verify: false, file: null, stagesFile: null, reviewOf: null };
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: 0, force: false, acceptance: null, verify: false, file: null, stagesFile: null, reviewOf: null, draft: false };
68
74
  for (let i = 0; i < argv.length; i++) {
69
75
  const arg = argv[i];
70
76
  if (arg === "--json") out.json = true;
@@ -74,6 +80,7 @@ function parse(argv) {
74
80
  else if (arg === "--review-of") out.reviewOf = value(argv, i++, arg);
75
81
  else if (arg === "--tag") out.tags.push(value(argv, i++, arg));
76
82
  else if (arg === "--acceptance") out.acceptance = value(argv, i++, arg);
83
+ else if (arg === "--draft") out.draft = true;
77
84
  else if (arg === "--verify") out.verify = true;
78
85
  else if (arg === "--file") out.file = value(argv, i++, arg);
79
86
  else if (arg === "--stages") out.stagesFile = value(argv, i++, arg);
@@ -114,6 +121,11 @@ function reviewFailureReason(reason) {
114
121
  return detail ? "test failed: " + detail : "test failed";
115
122
  }
116
123
 
124
+ /** One message for both the preview and the CAS: a draft is never dispatchable. */
125
+ function draftClaimMessage(id) {
126
+ return "task " + id + " is a draft and cannot be claimed (rm it and re-add with --acceptance)";
127
+ }
128
+
117
129
  function board(repo) {
118
130
  return listRaw(repo).map((entry) => entry.value);
119
131
  }
@@ -135,9 +147,16 @@ function readyList(repo, tasks, { role } = {}) {
135
147
  .sort(order);
136
148
  }
137
149
 
138
- /** JSON/print view of a card: stages, stage and stageState are always present. */
150
+ /**
151
+ * JSON/print view of a card: stages, stage and stageState are always present.
152
+ * Cards written before 1.8.1 have no stateChangedAt; they read as updatedAt.
153
+ */
139
154
  function viewTask(task) {
140
- return { ...task, ...stageView(task) };
155
+ return {
156
+ ...task,
157
+ ...stageView(task),
158
+ stateChangedAt: task.stateChangedAt || task.updatedAt,
159
+ };
141
160
  }
142
161
 
143
162
  function printTask(task, json, extra = {}, extraLines = []) {
@@ -154,6 +173,7 @@ function printTask(task, json, extra = {}, extraLines = []) {
154
173
  process.stdout.write(indent + "chain: " + task.stages.map((entry) => entry.key + ":" + entry.state).join(" -> ") + "\n");
155
174
  }
156
175
  }
176
+ if (task.draft) process.stdout.write(indent + "draft: true (never ready, not claimable)\n");
157
177
  if (task.scope.length) process.stdout.write(indent + "scope: " + task.scope.join(", ") + "\n");
158
178
  if (task.after.length) process.stdout.write(indent + "after: " + task.after.join(", ") + "\n");
159
179
  if (task.reviewOf) process.stdout.write(indent + "review-of: " + task.reviewOf + "\n");
@@ -213,8 +233,13 @@ function run(argv) {
213
233
  if (!Array.isArray(plan) || plan.length === 0) fail("plan must be a non-empty JSON array", 2);
214
234
 
215
235
  const keys = new Map();
216
- const drafts = plan.map((entry) => {
217
- if (!entry || !entry.title) fail("every plan entry needs a title", 2);
236
+ const drafts = plan.map((entry, index) => {
237
+ const where = "plan[" + index + "]";
238
+ if (!entry || !entry.title) fail(where + " needs a title", 2);
239
+ const isDraftEntry = entry.draft === true;
240
+ if (!entry.acceptance && !isDraftEntry) {
241
+ fail(where + " (\"" + entry.title + "\"): acceptance is required (or set \"draft\": true)", 2);
242
+ }
218
243
  let task;
219
244
  try {
220
245
  task = create({
@@ -226,6 +251,7 @@ function run(argv) {
226
251
  priority: entry.priority,
227
252
  tags: entry.tags || [],
228
253
  acceptance: entry.acceptance || "",
254
+ draft: isDraftEntry,
229
255
  createdBy: options.agent || process.env.HIVE_AGENT || "planner",
230
256
  stages: entry.stages,
231
257
  });
@@ -354,6 +380,11 @@ function run(argv) {
354
380
 
355
381
  if (command === "add") {
356
382
  if (!options.title) fail("--title is required", 2);
383
+ // Mechanical enforcement of the acceptance rule: a card that can be dispatched
384
+ // must say how it will be judged, unless it is deliberately parked as a draft.
385
+ if (!options.acceptance && !options.draft) {
386
+ fail("add: --acceptance is required (or pass --draft for a draft card)", 2);
387
+ }
357
388
  if (options.reviewOf && !readTask(repo, options.reviewOf)) fail("no such task: " + options.reviewOf, 2);
358
389
  if (options.stageArgs.length && options.stagesFile) fail("use --stage or --stages, not both", 2);
359
390
  let stages = null;
@@ -375,6 +406,7 @@ function run(argv) {
375
406
  tags: options.tags,
376
407
  acceptance: options.acceptance || "",
377
408
  reviewOf: options.reviewOf,
409
+ draft: options.draft,
378
410
  createdBy: options.agent || process.env.HIVE_AGENT || "unknown",
379
411
  stages,
380
412
  });
@@ -404,7 +436,7 @@ function run(argv) {
404
436
  return process.stdout.write(JSON.stringify(rows, null, 2) + "\n");
405
437
  }
406
438
  if (limited.length === 0) return process.stdout.write(command === "ready" ? "Nothing ready.\n" : "No tasks.\n");
407
- for (const task of limited) process.stdout.write(task.id.padEnd(34) + task.state.padEnd(9) + stageRole(task).padEnd(11) + task.title + "\n");
439
+ for (const task of limited) process.stdout.write(task.id.padEnd(34) + task.state.padEnd(9) + stageRole(task).padEnd(11) + task.title + (task.draft ? " [draft]" : "") + "\n");
408
440
  return;
409
441
  }
410
442
 
@@ -438,6 +470,7 @@ function run(argv) {
438
470
 
439
471
  const preview = readTask(repo, id);
440
472
  if (!preview) fail("no such task: " + id, 2);
473
+ if (isDraft(preview)) fail(draftClaimMessage(id), 2);
441
474
  if (readMode(repo) === "freeze" && !options.force && !(preview.tags || []).includes("fix")) {
442
475
  fail("mode is freeze: only fix-tagged cards may be claimed (use --force to override)", 2);
443
476
  }
@@ -454,6 +487,7 @@ function run(argv) {
454
487
  const map = byId(tasks);
455
488
  const task = map.get(id);
456
489
  if (!task) throw new Error("no such task: " + id);
490
+ if (isDraft(task)) throw new Error(draftClaimMessage(id));
457
491
  const canReclaim = isReclaimable(task);
458
492
  if (task.state !== "pending" && !canReclaim) throw new Error("task " + id + " is " + task.state + stageOf(task));
459
493
  if (isStaged(task) && task.stageState !== "pending" && !(task.stageState === "claimed" && canReclaim)) {
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,23 @@ 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
+
57
67
  /** A claimed card whose claim expired can be taken over by the next agent. */
58
68
  export function isReclaimable(task, now = Date.now()) {
59
69
  if (task.state !== "claimed") return false;
@@ -72,6 +82,8 @@ function depsDone(task, byId) {
72
82
  * (pending, or claimed and expired so it can be recovered).
73
83
  */
74
84
  export function isReady(task, byId, { modeFree = true, now = Date.now() } = {}) {
85
+ // A draft never enters a dispatch computation, whatever its state.
86
+ if (isDraft(task)) return false;
75
87
  const claimable = task.state === "pending" || isReclaimable(task, now);
76
88
  if (!claimable) return false;
77
89
  if (!depsDone(task, byId)) return false;
@@ -86,9 +98,22 @@ export function order(a, b) {
86
98
  return a.createdAt < b.createdAt ? -1 : 1;
87
99
  }
88
100
 
101
+ /**
102
+ * The lane a card is in: its state plus the current stage and stage state. A
103
+ * stage advance can keep the card pending, so state alone is not enough.
104
+ */
105
+ function laneKey(task) {
106
+ return [task.state, task.stage == null ? "" : task.stage, task.stageState == null ? "" : task.stageState].join("\u0000");
107
+ }
108
+
89
109
  export function transition(task, next, patch = {}) {
90
110
  if (!STATES.includes(next)) throw new Error("unknown state: " + next);
91
- return { ...task, ...patch, state: next, updatedAt: now() };
111
+ const updated = { ...task, ...patch, state: next };
112
+ // stateChangedAt tracks real lane/stage moves only; a patch that leaves the
113
+ // lane alone (a reason, a verdict, metadata) must not reset it.
114
+ if (laneKey(updated) !== laneKey(task)) updated.stateChangedAt = now();
115
+ updated.updatedAt = now();
116
+ return updated;
92
117
  }
93
118
 
94
119
  /**