@zinn-dev/cli 0.44.0 → 0.45.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.
Files changed (56) hide show
  1. package/package.json +2 -2
  2. package/skills/zinn/SKILL.md +7 -9
  3. package/src/capabilities-schema.d.ts +5 -1
  4. package/src/column-hint.js +1 -3
  5. package/src/database.d.ts +1 -2
  6. package/src/database.js +1 -6
  7. package/src/duration-input.d.ts +7 -0
  8. package/src/duration-input.js +31 -0
  9. package/src/errors.d.ts +22 -0
  10. package/src/errors.js +30 -5
  11. package/src/expected-values.d.ts +48 -0
  12. package/src/expected-values.js +60 -0
  13. package/src/follow.d.ts +9 -0
  14. package/src/follow.js +58 -0
  15. package/src/input.d.ts +0 -8
  16. package/src/input.js +36 -16
  17. package/src/lib.d.ts +5 -2
  18. package/src/lib.js +18 -8
  19. package/src/list-continuation.js +1 -4
  20. package/src/presentation/activity-presentation.d.ts +2 -0
  21. package/src/presentation/activity-presentation.js +58 -3
  22. package/src/presentation/column-presentation.d.ts +9 -4
  23. package/src/presentation/column-presentation.js +29 -12
  24. package/src/presentation/doctor-presentation.d.ts +4 -0
  25. package/src/presentation/doctor-presentation.js +24 -0
  26. package/src/presentation/relation-presentation.js +2 -1
  27. package/src/presentation/task-blame-presentation.d.ts +1 -4
  28. package/src/presentation/task-blame-presentation.js +1 -1
  29. package/src/presentation/task-presentation.d.ts +2 -0
  30. package/src/presentation/task-presentation.js +39 -2
  31. package/src/result-schemas.d.ts +353 -58
  32. package/src/result-schemas.js +46 -2
  33. package/src/results.d.ts +6 -2
  34. package/src/results.js +9 -3
  35. package/src/routes/activity-router.d.ts +12 -3
  36. package/src/routes/activity-router.js +93 -59
  37. package/src/routes/aliases.js +1 -0
  38. package/src/routes/comment-router.d.ts +24 -6
  39. package/src/routes/comment-router.js +15 -5
  40. package/src/routes/doctor-router.d.ts +39 -0
  41. package/src/routes/doctor-router.js +103 -0
  42. package/src/routes/label-router.d.ts +39 -6
  43. package/src/routes/label-router.js +22 -5
  44. package/src/routes/project-router.d.ts +60 -11
  45. package/src/routes/project-router.js +100 -33
  46. package/src/routes/restore-router.js +2 -2
  47. package/src/routes/router.js +3 -7
  48. package/src/routes/routes.d.ts +404 -33
  49. package/src/routes/routes.js +4 -0
  50. package/src/routes/skill-router.d.ts +25 -0
  51. package/src/routes/skill-router.js +96 -0
  52. package/src/routes/task-router.d.ts +231 -13
  53. package/src/routes/task-router.js +247 -19
  54. package/src/text-edit.d.ts +2 -2
  55. package/src/text-input.d.ts +19 -1
  56. package/src/text-input.js +26 -5
@@ -1,14 +1,16 @@
1
1
  import { jsonResult, taskDetailResults, taskChangeResults } from "../results.js";
2
2
  import { parseArgs } from "node:util";
3
- import { activity, task, project, parseTaskKey, taskCreateSchema, taskEditSchema, taskDeleteManySchema, taskPrioritySchema, taskSortSchema, } from "@zinn-dev/core";
3
+ import { activity, task, project, parseTaskKey, taskCreateSchema, taskEditSchema, taskDeleteManySchema, taskPrioritySchema, taskSortSchema, taskStateFilterSchema, CLAIM_WORK_LIMIT_MS, MIN_CLAIM_LEASE_MS, } from "@zinn-dev/core";
4
4
  import { listLimitOption, listLimitDescription, parseListLimit } from "../list-limit.js";
5
5
  import { formatListContinuation } from "../list-continuation.js";
6
6
  import { parseTimestampInput } from "../timestamp-input.js";
7
+ import { durationPattern, formatDurationInput, parseDurationInput } from "../duration-input.js";
7
8
  import { CliError } from "../errors.js";
8
9
  import { generateCommandUsage, taskKeyPositional, archiveConstraint, getOptionInputs, violatesConstraint, } from "../input.js";
9
10
  import { confirmationDescription, confirmAction, dashValueHelp, diagnostic, output, outputChanges, quit, validatePositionals, validateOrderForms, requireStringOption, renameFlag, validateUniqueOptions, } from "../lib.js";
10
11
  import { resolveTextEdit, textEditHelp, textEditOptions, textEditConstraints, } from "../text-edit.js";
11
- import { checkFieldsBeforeText, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
12
+ import { expectedValueFlags } from "../expected-values.js";
13
+ import { checkFieldsBeforeText, checkSingleStdinReader, resolveTextInput, textFileHelp, textFileOption, textSourceConstraint, } from "../text-input.js";
12
14
  import { currentActor } from "../actor.js";
13
15
  import { checkDefaultProject, chooseProjectKey, resolveProjectKey, projectScopeConstraint, requiredProjectDescription, projectScopeDescription, } from "../project.js";
14
16
  import { relationRouter } from "./relation-router.js";
@@ -18,7 +20,7 @@ import { formatCommentList, presentComments } from "../presentation/comment-pres
18
20
  import { formatSection } from "../presentation/section.js";
19
21
  import { abbreviateActivityIds, formatActivityList, presentActivities, } from "../presentation/activity-presentation.js";
20
22
  import { formatTaskBlame } from "../presentation/task-blame-presentation.js";
21
- import { columnPlacement, createColumnBoard } from "../presentation/column-presentation.js";
23
+ import { createColumnBoard } from "../presentation/column-presentation.js";
22
24
  import { formatTaskList, formatTaskTimestamps, presentTask, } from "../presentation/task-presentation.js";
23
25
  // A column is changed with task move, so a guessed --status or --column suggests it with the same task keys.
24
26
  function suggestTaskMove(args, options = {}) {
@@ -50,6 +52,29 @@ const dueOption = {
50
52
  description: "Integer epoch milliseconds or YYYY-MM-DDTHH:mm:ss[.SSS] with Z or a numeric offset. Fractions have 1 to 3 digits. none clears the deadline, ignoring case. Omission leaves it unset on creation and unchanged on edit.",
51
53
  },
52
54
  };
55
+ const taskExpectations = expectedValueFlags({
56
+ title: { field: "title", option: { type: "string", value: { kind: "text", name: "text" } } },
57
+ description: { field: "description", text: true },
58
+ priority: {
59
+ field: "priority",
60
+ option: {
61
+ type: "string",
62
+ value: { ...priorityOption.value, description: "none expects no priority." },
63
+ },
64
+ parse: parsePriority,
65
+ },
66
+ due: {
67
+ field: "due_at",
68
+ option: {
69
+ type: "string",
70
+ value: {
71
+ ...dueOption.value,
72
+ description: "Same formats as --due. none expects no deadline, ignoring case.",
73
+ },
74
+ },
75
+ parse: parseDue,
76
+ },
77
+ });
53
78
  const deadlineFilterOptions = {
54
79
  "due-since": {
55
80
  type: "string",
@@ -118,6 +143,10 @@ const taskInputs = {
118
143
  type: "string",
119
144
  value: { kind: "enum", name: "key", choices: taskSortSchema.options },
120
145
  },
146
+ state: {
147
+ type: "string",
148
+ value: { kind: "enum", name: "state", choices: taskStateFilterSchema.options },
149
+ },
121
150
  archived: { type: "boolean" },
122
151
  all: { type: "boolean" },
123
152
  "all-projects": { type: "boolean" },
@@ -169,6 +198,20 @@ const taskInputs = {
169
198
  "A query that is a task key ignores defaultProject unless a project was typed. --all-projects still excludes a typed project.",
170
199
  ],
171
200
  },
201
+ next: {
202
+ options: {
203
+ "all-projects": { type: "boolean" },
204
+ column: { type: "string", value: { kind: "column-name", name: "name" } },
205
+ },
206
+ forms: [
207
+ {
208
+ id: "default",
209
+ positionals: [{ name: "project-key", min: 0, max: 1, value: { kind: "project-key" } }],
210
+ },
211
+ ],
212
+ constraints: [projectScopeConstraint],
213
+ notes: [projectScopeDescription],
214
+ },
172
215
  view: {
173
216
  options: { history: { type: "boolean" } },
174
217
  forms: [
@@ -198,6 +241,7 @@ const taskInputs = {
198
241
  multiple: true,
199
242
  value: { kind: "label-name", name: "name" },
200
243
  },
244
+ ...taskExpectations.options,
201
245
  },
202
246
  forms: [
203
247
  {
@@ -209,11 +253,14 @@ const taskInputs = {
209
253
  textSourceConstraint("--description"),
210
254
  ...textEditConstraints("--description"),
211
255
  taskEditConstraint,
256
+ ...taskExpectations.constraints,
212
257
  ],
213
- notes: [textEditHelp("--description")],
258
+ notes: [textEditHelp("--description"), taskExpectations.help],
214
259
  },
215
260
  move: {
216
- options: {},
261
+ options: {
262
+ from: { type: "string", value: { kind: "column-name", name: "column" } },
263
+ },
217
264
  forms: [
218
265
  {
219
266
  id: "default",
@@ -273,6 +320,28 @@ const taskInputs = {
273
320
  ],
274
321
  constraints: [],
275
322
  },
323
+ claim: {
324
+ options: {
325
+ lease: {
326
+ type: "string",
327
+ required: true,
328
+ value: {
329
+ kind: "duration",
330
+ name: "duration",
331
+ pattern: durationPattern,
332
+ description: `Whole minutes or hours, such as 30m or 2h, from ${formatDurationInput(MIN_CLAIM_LEASE_MS)} through ${formatDurationInput(CLAIM_WORK_LIMIT_MS)}.`,
333
+ },
334
+ },
335
+ force: { type: "boolean" },
336
+ },
337
+ forms: [{ id: "default", positionals: [taskKeyPositional] }],
338
+ constraints: [],
339
+ },
340
+ heartbeat: {
341
+ options: {},
342
+ forms: [{ id: "default", positionals: [taskKeyPositional] }],
343
+ constraints: [],
344
+ },
276
345
  delete: {
277
346
  options: { yes: { type: "boolean" } },
278
347
  forms: [
@@ -370,7 +439,7 @@ Unknown columns, labels or related tasks abort creation.
370
439
 
371
440
  Examples:
372
441
  zinn task create MDR --title 'Refine the numbers' --description 'Meet the quarterly quota' --label urgent
373
- zinn task create MDR --title 'Review the numbers' --column 'In Progress'
442
+ zinn task create MDR --title 'Review the numbers' --column Doing
374
443
  zinn task create MDR --title 'Sort the files' --parent MDR-1 --depends-on MDR-2`,
375
444
  },
376
445
  list: {
@@ -401,12 +470,17 @@ Examples:
401
470
  argument: "--sort",
402
471
  });
403
472
  }
473
+ const state = taskStateFilterSchema.optional().safeParse(values.state);
474
+ if (!state.success) {
475
+ quit(`Unknown state "${values.state}". Use ${taskStateFilterSchema.options.join(", ")}`, undefined, { argument: "--state" });
476
+ }
404
477
  const page = task.getPage({
405
478
  ...parseDeadlineFilters(values),
406
479
  limit,
407
480
  sort: sort.data,
408
481
  projectKey,
409
482
  archive,
483
+ state: state.data,
410
484
  labelNames: values.label,
411
485
  columnName: values.column,
412
486
  startingAfter: values["starting-after"],
@@ -423,6 +497,7 @@ Examples:
423
497
 
424
498
  List active tasks by default.
425
499
  ${projectScopeDescription}
500
+ --state open lists tasks outside done and cancelled columns, and --state closed lists tasks in them.
426
501
  Use --archived to list archived tasks or --all to list both.
427
502
  Repeat --label to require every specified label.
428
503
  --column matches an exact column name. Column and label matching ignore case.
@@ -436,7 +511,7 @@ When additional matches remain after --limit, stderr gives a shell-quoted comman
436
511
  --starting-after <cursor>: Continue after the position a cursor records. Copy the cursor from that command.
437
512
  A cursor works only with the --sort it was made for. Changes to other tasks between commands can still cause repeats or skips.
438
513
 
439
- Use 'task view' to see a task's full details, including its description.
514
+ Use 'task view' to see a task's full details, including its description and an expired claim.
440
515
 
441
516
  Example: zinn task list MDR --label cli`,
442
517
  },
@@ -500,6 +575,47 @@ Repeat --label to require every specified label, ignoring case.
500
575
  ${deadlineFilterHelp}
501
576
 
502
577
  Example: zinn task search 'refinement quota' MDR --limit 5`,
578
+ },
579
+ next: {
580
+ summary: "Show the next task that is ready to work on.",
581
+ effects: { domain: "read", storage: "normal-open" },
582
+ confirmation: { kind: "none" },
583
+ input: taskInputs.next,
584
+ results: [jsonResult("NextTask")],
585
+ run: (args) => {
586
+ const { values, positionals, tokens } = parseArgs({
587
+ args,
588
+ options: taskInputs.next.options,
589
+ allowPositionals: true,
590
+ strict: true,
591
+ tokens: true,
592
+ });
593
+ validateUniqueOptions(tokens, taskInputs.next.options);
594
+ validatePositionals(positionals, taskInputs.next.forms[0]);
595
+ const projectKey = resolveProjectKey(positionals[0], { allProjects: values["all-projects"] });
596
+ const nextTask = task.next({ projectKey, columnName: values.column });
597
+ const board = createColumnBoard();
598
+ output(nextTask === null ? null : presentTask(nextTask, board), (presentedTask) => presentedTask === null ? "No task is ready." : formatTaskList([presentedTask]));
599
+ },
600
+ help: `${generateCommandUsage("task next", taskInputs.next)}
601
+
602
+ Show the next task that is ready to work on.
603
+ A task is ready when it is active, in a todo or backlog column, has no live claim, and every task it depends on is archived or in a done or cancelled column.
604
+ Only dependency relations hold a task back. A task with a live claim is skipped, including your own.
605
+ Ready tasks in todo columns come before those in backlog columns, whatever their priority.
606
+ Within each, tasks are ordered by priority (urgent first, unset last), then the earliest deadline with undated tasks last, then the oldest task.
607
+ ${projectScopeDescription}
608
+ --column takes ready tasks from one column instead, matching its exact name and ignoring case. Any column but a done or cancelled one can hold them.
609
+ When no task is ready, the command exits 0. With --json, it prints null.
610
+ To take the task, move it with task move --from, which fails if another caller moved it first. Then show that you are working on it with task claim.
611
+ task next <project> --column <working column> returns in-progress work with no live claim.
612
+
613
+ Use 'task view' to see the task's description, relations and comments.
614
+
615
+ Examples:
616
+ zinn task next MDR
617
+ zinn task next MDR --column Review
618
+ zinn task next MDR --column Doing`,
503
619
  },
504
620
  view: {
505
621
  summary: "Show a task with its description, relations, comments, and creation and update times.",
@@ -543,7 +659,11 @@ Example: zinn task search 'refinement quota' MDR --limit 5`,
543
659
  const comments = formatCommentList(t.comments);
544
660
  const isArchived = t.status === "Archived";
545
661
  const sections = [
546
- formatTaskList([t], { showsStatus: isArchived, showsFullPriority: true }),
662
+ formatTaskList([t], {
663
+ showsStatus: isArchived,
664
+ showsFullPriority: true,
665
+ showsClaimDetail: true,
666
+ }),
547
667
  ];
548
668
  if (t.description != null) {
549
669
  sections.push(formatSection("Description", t.description, sectionOptions));
@@ -570,6 +690,7 @@ Show a task with its description, relations, comments, and creation and update t
570
690
  A section is shown when the task has that content. The description prints in full, keeping its line breaks.
571
691
  Task update time advances for edits, label attachment changes, moves, reorders, archiving and unarchiving.
572
692
  With --json, created_at and updated_at are stored epoch milliseconds.
693
+ A claim shows with its holder and when its lease ends, also once it expired.
573
694
  Use --history to include this task's recorded activity, newest first, including reorders and comment changes.
574
695
  Use activity view <activity-id> for full recorded changes. Text times are local with a UTC offset.
575
696
  With --history --json, the activity field contains full activity records, or [] when none are recorded.
@@ -598,7 +719,7 @@ Examples:
598
719
  const board = createColumnBoard();
599
720
  return formatTaskBlame(blame, {
600
721
  relations: presentRelations(taskMatch, board),
601
- columnPlacement: columnPlacement(board(taskMatch.project_id), taskMatch.column_id),
722
+ columnCategory: board(taskMatch.project_id).find((boardColumn) => boardColumn.id === taskMatch.column_id)?.category ?? null,
602
723
  isArchived: taskMatch.archived_at != null,
603
724
  activityIdPrefixes: abbreviateActivityIds(activity.getIds()),
604
725
  });
@@ -641,13 +762,16 @@ Example: zinn task blame MDR-1`,
641
762
  addLabelNames: values["add-label"],
642
763
  removeLabelNames: values["remove-label"],
643
764
  };
644
- checkFieldsBeforeText(taskEditSchema, fields);
765
+ const expected = taskExpectations.parseValues(values);
766
+ checkFieldsBeforeText(taskEditSchema, { ...fields, expected });
767
+ checkSingleStdinReader(values, ["--description", ...taskExpectations.textFlags]);
645
768
  const description = await resolveTextEdit(values, "--description");
646
769
  // Without a text source nothing was read, so this usage error still comes before any input.
647
770
  if (violatesConstraint(taskEditConstraint, getOptionInputs(values))) {
648
771
  quit("Provide at least one edit flag: --title, --description, --description-file, --priority, --due, --add-label, or --remove-label", undefined, { field: [] });
649
772
  }
650
- const editedTask = task.edit({ ...fields, description }, currentActor());
773
+ const expectedText = await taskExpectations.resolveText(values);
774
+ const editedTask = task.edit({ ...fields, description, expected: { ...expected, ...expectedText } }, currentActor());
651
775
  const board = createColumnBoard();
652
776
  outputChanges([editedTask], (change) => presentTask(change.task, board), formatTaskList, (entry) => `${entry.key} was unchanged`);
653
777
  },
@@ -662,6 +786,8 @@ ${textFileHelp("--description")}
662
786
 
663
787
  ${textEditHelp("--description")}
664
788
 
789
+ ${taskExpectations.help}
790
+
665
791
  Repeat --add-label or --remove-label for multiple existing labels, ignoring case.
666
792
  The same label cannot be both added and removed.
667
793
  Archived tasks can be edited.
@@ -671,7 +797,8 @@ ${dashValueHelp("--description")}
671
797
 
672
798
  Examples:
673
799
  zinn task edit MDR-1 --title 'Meet the quarterly refinement quota'
674
- zinn task edit MDR-1 --description 'Bring waffles.' --append`,
800
+ zinn task edit MDR-1 --description 'Bring waffles.' --append
801
+ zinn task edit MDR-1 --title 'Refine the Cold Harbor file' --expect-title 'Refine the files'`,
675
802
  guessedFlags: {
676
803
  "--status": (args) => suggestTaskMove(args, taskInputs.edit.options),
677
804
  "--column": (args) => suggestTaskMove(args, taskInputs.edit.options),
@@ -689,16 +816,18 @@ Examples:
689
816
  input: taskInputs.move,
690
817
  results: taskChangeResults,
691
818
  run: (args) => {
692
- const { positionals } = parseArgs({
819
+ const { values, positionals, tokens } = parseArgs({
693
820
  options: taskInputs.move.options,
694
821
  args,
695
822
  allowPositionals: true,
696
823
  strict: true,
824
+ tokens: true,
697
825
  });
826
+ validateUniqueOptions(tokens, taskInputs.move.options);
698
827
  validatePositionals(positionals, taskInputs.move.forms[0]);
699
828
  const taskKeys = positionals.slice(0, -1);
700
829
  const targetColumn = positionals.at(-1);
701
- const moves = task.moveMany({ taskKeys, targetColumn }, currentActor());
830
+ const moves = task.moveMany({ taskKeys, targetColumn, fromColumn: values.from }, currentActor());
702
831
  const board = createColumnBoard();
703
832
  outputChanges(moves, (change) => presentTask(change.task, board), formatTaskList, (movedTask) => `${movedTask.key} was already in the ${movedTask.column} column`);
704
833
  },
@@ -710,9 +839,12 @@ Each task's column is looked up in its own project.
710
839
 
711
840
  Moving to the current column leaves the task unchanged.
712
841
  Archived tasks must be unarchived before they can be moved.
842
+ With --from, the move fails with a conflict error unless every task is still in that column.
713
843
  If any task cannot be moved, none change.
714
844
 
715
- Example: zinn task move MDR-1 MDR-2 'In Progress'`,
845
+ Examples:
846
+ zinn task move MDR-1 MDR-2 Doing
847
+ zinn task move MDR-1 Doing --from TODO`,
716
848
  guessedFlags: { "--status": suggestTaskMove, "--column": suggestTaskMove },
717
849
  },
718
850
  order: {
@@ -801,6 +933,87 @@ With --json, one task prints an object and several print an array.
801
933
  Each task's changed field is 'false' when it was already in the requested state.
802
934
 
803
935
  Example: zinn task unarchive MDR-1 MDR-2`,
936
+ },
937
+ claim: {
938
+ summary: "Claim a task for a lease, so other agents and people can see who works on it.",
939
+ effects: { domain: "update", storage: "normal-open" },
940
+ confirmation: { kind: "none" },
941
+ input: taskInputs.claim,
942
+ results: [jsonResult("TaskChange")],
943
+ run: (args) => {
944
+ const { values, positionals, tokens } = parseArgs({
945
+ args,
946
+ options: taskInputs.claim.options,
947
+ allowPositionals: true,
948
+ strict: true,
949
+ tokens: true,
950
+ });
951
+ validateUniqueOptions(tokens, taskInputs.claim.options);
952
+ validatePositionals(positionals, taskInputs.claim.forms[0]);
953
+ const lease = requireStringOption(taskInputs.claim.options.lease, values.lease, "lease", "A claim needs a lease: use --lease, such as --lease 30m");
954
+ const leaseMs = parseDurationInput(lease, "--lease");
955
+ const isLeaseInRange = leaseMs >= MIN_CLAIM_LEASE_MS && leaseMs <= CLAIM_WORK_LIMIT_MS;
956
+ if (!isLeaseInRange) {
957
+ quit(`Use a lease from ${formatDurationInput(MIN_CLAIM_LEASE_MS)} through ${formatDurationInput(CLAIM_WORK_LIMIT_MS)}`, undefined, { argument: "--lease" });
958
+ }
959
+ const claimed = task.claim({
960
+ taskKey: positionals[0],
961
+ leaseMs,
962
+ force: values.force,
963
+ }, currentActor());
964
+ outputClaimChange(claimed, (entry) => `${entry.key} was unchanged`);
965
+ },
966
+ help: `${generateCommandUsage("task claim", taskInputs.claim)}
967
+
968
+ Claim a task for a lease, so other agents and people can see who works on it.
969
+ --lease takes whole minutes or hours, such as 30m or 2h, from ${formatDurationInput(MIN_CLAIM_LEASE_MS)} through ${formatDurationInput(CLAIM_WORK_LIMIT_MS)}.
970
+ Any change the holder makes to the task, including a comment, renews the claim. So does task heartbeat.
971
+ A claim expires when its lease runs out, or ${formatDurationInput(CLAIM_WORK_LIMIT_MS)} after the holder last changed the task.
972
+ After that limit, only a change to the task renews it.
973
+ Claiming a task you hold renews it with the new lease.
974
+ An expired claim is replaced. A live claim by someone else is a conflict, unless --force takes it over.
975
+ Agents are told apart by their session or thread, so an agent needs one its host sets, or ZINN_SESSION_ID.
976
+ Archived tasks cannot be claimed. Archiving a task or moving it to a done or cancelled column releases its claim.
977
+
978
+ Examples:
979
+ zinn task claim MDR-1 --lease 30m
980
+ zinn task claim MDR-1 --lease 2h --force`,
981
+ },
982
+ heartbeat: {
983
+ summary: "Renew your claim on a task with its current lease.",
984
+ effects: { domain: "update", storage: "normal-open" },
985
+ confirmation: { kind: "none" },
986
+ input: taskInputs.heartbeat,
987
+ results: [jsonResult("TaskChange")],
988
+ run: (args) => {
989
+ const taskKey = parseClaimedTaskKey(args);
990
+ outputClaimChange(task.heartbeat(taskKey, currentActor()), (entry) => `${entry.key} was unchanged`);
991
+ },
992
+ help: `${generateCommandUsage("task heartbeat", taskInputs.heartbeat)}
993
+
994
+ Renew your claim on a task with its current lease.
995
+ It fails when the task has no claim or someone else holds it.
996
+ It also fails ${formatDurationInput(CLAIM_WORK_LIMIT_MS)} after you last changed the task. After that, only a change to the task renews the claim.
997
+
998
+ Example: zinn task heartbeat MDR-1`,
999
+ },
1000
+ release: {
1001
+ summary: "Release your claim on a task.",
1002
+ effects: { domain: "update", storage: "normal-open" },
1003
+ confirmation: { kind: "none" },
1004
+ input: taskInputs.heartbeat,
1005
+ results: [jsonResult("TaskChange")],
1006
+ run: (args) => {
1007
+ const taskKey = parseClaimedTaskKey(args);
1008
+ outputClaimChange(task.release(taskKey, currentActor()), (entry) => `${entry.key} had no claim`);
1009
+ },
1010
+ help: `${generateCommandUsage("task release", taskInputs.heartbeat)}
1011
+
1012
+ Release your claim on a task.
1013
+ Releasing a task without a claim does not do anything. Someone else's claim is a conflict.
1014
+ With --json, changed is false when the task had no claim.
1015
+
1016
+ Example: zinn task release MDR-1`,
804
1017
  },
805
1018
  delete: {
806
1019
  summary: "Permanently delete tasks after confirmation.",
@@ -892,6 +1105,21 @@ function parseTaskKeys(args) {
892
1105
  validatePositionals(positionals, taskInputs.archive.forms[0]);
893
1106
  return positionals;
894
1107
  }
1108
+ function parseClaimedTaskKey(args) {
1109
+ const { positionals } = parseArgs({
1110
+ options: taskInputs.heartbeat.options,
1111
+ args,
1112
+ allowPositionals: true,
1113
+ strict: true,
1114
+ });
1115
+ validatePositionals(positionals, taskInputs.heartbeat.forms[0]);
1116
+ return positionals[0];
1117
+ }
1118
+ /** Prints a claim command's task with its claim and when the lease ends */
1119
+ function outputClaimChange(change, describeUnchanged) {
1120
+ const board = createColumnBoard();
1121
+ outputChanges([change], (claimChange) => presentTask(claimChange.task, board), (entries) => formatTaskList(entries, { showsClaimDetail: true }), describeUnchanged);
1122
+ }
895
1123
  function parseTaskLabelArgs(args) {
896
1124
  const { positionals } = parseArgs({
897
1125
  options: taskInputs.label_add.options,
@@ -912,8 +1140,8 @@ function parseNewTaskRelations(flags) {
912
1140
  ];
913
1141
  return targetsByType.flatMap(([relation_type, targetTaskKeys]) => targetTaskKeys.map((targetTaskKey) => ({ relation_type, targetTaskKey })));
914
1142
  }
915
- function parseDue(value) {
916
- return value?.toLowerCase() === "none" ? null : parseTimestampInput(value, "--due");
1143
+ function parseDue(value, flag = "--due") {
1144
+ return value?.toLowerCase() === "none" ? null : parseTimestampInput(value, flag);
917
1145
  }
918
1146
  function parseDeadlineFilters(values) {
919
1147
  const dueSince = parseTimestampInput(values["due-since"], "--due-since");
@@ -924,7 +1152,7 @@ function parseDeadlineFilters(values) {
924
1152
  }
925
1153
  return { dueSince, dueUntil };
926
1154
  }
927
- function parsePriority(value) {
1155
+ function parsePriority(value, flag = "--priority") {
928
1156
  const normalizedPriority = value?.toLowerCase();
929
1157
  if (normalizedPriority === undefined) {
930
1158
  return undefined;
@@ -935,7 +1163,7 @@ function parsePriority(value) {
935
1163
  const priority = taskPrioritySchema.safeParse(normalizedPriority);
936
1164
  if (!priority.success) {
937
1165
  quit("Priority must be low, medium, high, urgent, or none", undefined, {
938
- argument: "--priority",
1166
+ argument: flag,
939
1167
  });
940
1168
  }
941
1169
  return priority.data;
@@ -22,11 +22,11 @@ export declare function textEditConstraints(textFlag: TextFlag): readonly [{
22
22
  }, {
23
23
  readonly kind: "requiresAny";
24
24
  readonly input: "option:append";
25
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
25
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
26
26
  }, {
27
27
  readonly kind: "requiresAny";
28
28
  readonly input: "option:replacing";
29
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
29
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
30
30
  }, {
31
31
  readonly kind: "requires";
32
32
  readonly input: "option:all";
@@ -9,6 +9,14 @@ declare const textOptions: {
9
9
  readonly text: "text";
10
10
  readonly file: "text-file";
11
11
  };
12
+ readonly "--expect-description": {
13
+ readonly text: "expect-description";
14
+ readonly file: "expect-description-file";
15
+ };
16
+ readonly "--expect-text": {
17
+ readonly text: "expect-text";
18
+ readonly file: "expect-text-file";
19
+ };
12
20
  };
13
21
  export type TextFlag = keyof typeof textOptions;
14
22
  export type TextValues = {
@@ -20,6 +28,12 @@ export declare function textOptionNames(textFlag: TextFlag): {
20
28
  } | {
21
29
  readonly text: "text";
22
30
  readonly file: "text-file";
31
+ } | {
32
+ readonly text: "expect-description";
33
+ readonly file: "expect-description-file";
34
+ } | {
35
+ readonly text: "expect-text";
36
+ readonly file: "expect-text-file";
23
37
  };
24
38
  /** The flag that reads a text flag's value from a file, or from stdin as "-" */
25
39
  export declare const textFileOption: {
@@ -33,7 +47,7 @@ export declare const textFileOption: {
33
47
  /** Inline text and its file flag are alternatives for the same field */
34
48
  export declare function textSourceConstraint(textFlag: TextFlag): {
35
49
  readonly kind: "exclusive";
36
- readonly members: readonly ["option:description" | "option:text", "option:description-file" | "option:text-file"];
50
+ readonly members: readonly ["option:description" | "option:text" | "option:expect-description" | "option:expect-text", "option:description-file" | "option:text-file" | "option:expect-description-file" | "option:expect-text-file"];
37
51
  };
38
52
  /**
39
53
  * Validates `fields` against their rules in a core input schema, so a command can reject
@@ -42,6 +56,10 @@ export declare function textSourceConstraint(textFlag: TextFlag): {
42
56
  */
43
57
  export declare function checkFieldsBeforeText(schema: z.ZodObject, fields: Record<string, unknown>): void;
44
58
  export declare function textFileHelp(textFlag: TextFlag): string;
59
+ /** Refuses inline text together with its file flag before anything is read */
60
+ export declare function checkSingleTextSource(text: string | undefined, path: string | undefined, textFlag: TextFlag): void;
61
+ /** Refuses more than one file flag reading stdin, since stdin can be read only once.*/
62
+ export declare function checkSingleStdinReader(values: TextValues, textFlags: ReadonlyArray<TextFlag>): void;
45
63
  /** Resolves one inline or file source before the command opens the database. */
46
64
  export declare function resolveTextInput(text: string | undefined, path: string | undefined, textFlag: TextFlag): Promise<string | undefined>;
47
65
  export {};
package/src/text-input.js CHANGED
@@ -7,6 +7,13 @@ import { CliError, classifyFailure } from "./errors.js";
7
7
  const textOptions = {
8
8
  "--description": { text: "description", file: "description-file" },
9
9
  "--text": { text: "text", file: "text-file" },
10
+ "--expect-description": { text: "expect-description", file: "expect-description-file" },
11
+ "--expect-text": { text: "expect-text", file: "expect-text-file" },
12
+ };
13
+ /** How to give an empty value for a text flag, shown when its file input is blank */
14
+ const blankInputHints = {
15
+ "--description": ' To clear a description, use --description "".',
16
+ "--expect-description": ' To expect no description, use --expect-description "".',
10
17
  };
11
18
  export function textOptionNames(textFlag) {
12
19
  return textOptions[textFlag];
@@ -133,15 +140,30 @@ async function readStdin(fileFlag, refuse) {
133
140
  readAvailable();
134
141
  });
135
142
  }
143
+ /** Refuses inline text together with its file flag before anything is read */
144
+ export function checkSingleTextSource(text, path, textFlag) {
145
+ const fileFlag = `--${textOptionNames(textFlag).file}`;
146
+ if (text !== undefined && path !== undefined) {
147
+ throw new CliError(`Options "${textFlag}" and "${fileFlag}" cannot be used together.`, "invalid_input", { argument: fileFlag, path });
148
+ }
149
+ }
150
+ /** Refuses more than one file flag reading stdin, since stdin can be read only once.*/
151
+ export function checkSingleStdinReader(values, textFlags) {
152
+ const stdinFlags = textFlags
153
+ .map((textFlag) => textOptionNames(textFlag).file)
154
+ .filter((file) => values[file] === "-")
155
+ .map((file) => `--${file}`);
156
+ if (stdinFlags.length > 1) {
157
+ throw new CliError(`Only one option can read stdin, but ${stdinFlags.join(" and ")} are both "-".`, "invalid_input", { argument: stdinFlags[1], path: "-" });
158
+ }
159
+ }
136
160
  /** Resolves one inline or file source before the command opens the database. */
137
161
  export async function resolveTextInput(text, path, textFlag) {
138
162
  const fileFlag = `--${textOptionNames(textFlag).file}`;
139
163
  const refuse = (message) => {
140
164
  throw new CliError(message, "invalid_input", { argument: fileFlag, path });
141
165
  };
142
- if (text !== undefined && path !== undefined) {
143
- refuse(`Options "${textFlag}" and "${fileFlag}" cannot be used together.`);
144
- }
166
+ checkSingleTextSource(text, path, textFlag);
145
167
  if (path === undefined) {
146
168
  return text;
147
169
  }
@@ -176,8 +198,7 @@ export async function resolveTextInput(text, path, textFlag) {
176
198
  }
177
199
  const result = decoded.slice(0, end);
178
200
  if (result.trim().length === 0) {
179
- const clearHint = textFlag === "--description" ? ' To clear a description, use --description "".' : "";
180
- refuse(`Input is empty or blank.${clearHint}`);
201
+ refuse(`Input is empty or blank.${blankInputHints[textFlag] ?? ""}`);
181
202
  }
182
203
  return result;
183
204
  }