@johngaynor/ocnus 2.0.1-next.7 → 2.0.1-next.73

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 (43) hide show
  1. package/README.md +518 -98
  2. package/cli/lib/agents.sh +32 -16
  3. package/cli/lib/asks.sh +762 -0
  4. package/cli/lib/banner.sh +181 -0
  5. package/cli/lib/brief.sh +375 -0
  6. package/cli/lib/chain.sh +363 -0
  7. package/cli/lib/close.sh +5 -3
  8. package/cli/lib/cost.sh +500 -0
  9. package/cli/lib/finish.sh +30 -4
  10. package/cli/lib/github.sh +106 -26
  11. package/cli/lib/guard.sh +39 -10
  12. package/cli/lib/handoff.sh +196 -31
  13. package/cli/lib/host.sh +340 -384
  14. package/cli/lib/linear.sh +552 -56
  15. package/cli/lib/links.sh +6 -3
  16. package/cli/lib/merges.sh +126 -27
  17. package/cli/lib/sessions.sh +132 -0
  18. package/cli/lib/settings.sh +31 -15
  19. package/cli/lib/task.sh +169 -54
  20. package/cli/lib/tests.sh +302 -7
  21. package/cli/lib/usage.sh +204 -0
  22. package/cli/ocnus +274 -76
  23. package/herdr/README.md +930 -232
  24. package/herdr/layouts/default.json +30 -11
  25. package/herdr/layouts/showcase.json +291 -0
  26. package/herdr/layouts/vibe.json +162 -0
  27. package/herdr/layouts/vibe.svg +41 -0
  28. package/herdr/mods/agent-settings/main.js +19 -7
  29. package/herdr/mods/memory/main.js +128 -0
  30. package/herdr/mods/memory/mod.json +1 -0
  31. package/herdr/mods/memory/reading.js +88 -0
  32. package/herdr/mods/names/main.js +22 -4
  33. package/herdr/mods/step-counts/main.js +281 -0
  34. package/herdr/mods/step-counts/mod.json +1 -0
  35. package/herdr/mods/usage/main.js +149 -0
  36. package/herdr/mods/usage/mod.json +1 -0
  37. package/package.json +1 -1
  38. package/prompts/task-new.md +1 -1
  39. package/skills/brief/SKILL.md +8 -0
  40. package/skills/sdlc-breakdown/SKILL.md +66 -18
  41. package/skills/sdlc-build/SKILL.md +6 -2
  42. package/skills/sdlc-pr/SKILL.md +2 -2
  43. package/skills/sdlc-review/SKILL.md +5 -5
package/cli/lib/linear.sh CHANGED
@@ -169,7 +169,7 @@ WRITE_QUERY='mutation { issueUpdate(id: "00000000-0000-0000-0000-000000000000",
169
169
 
170
170
  # What is said of a key that can read cards but not change them, by `status`
171
171
  # as a problem and by `linear key` once it has saved such a key.
172
- NO_WRITE_WHY="The key can read cards but not change them, so linear type, linear section, linear slices and linear move fail with it. Make a key with Write permission in $KEY_PLACE, then save it with: ocnus linear key"
172
+ NO_WRITE_WHY="The key can read cards but not change them, so linear type, linear section, linear slices, linear block and linear move fail with it. Make a key with Write permission in $KEY_PLACE, then save it with: ocnus linear key"
173
173
 
174
174
  # How Linear's answer to WRITE_QUERY reads, as one word and what follows it:
175
175
  # cannot a refusal: an error of type or code forbidden, or one whose
@@ -233,13 +233,27 @@ OPEN_TYPES='["triage","backlog","unstarted","started"]'
233
233
  # deciding that Linear will never say it has no more.
234
234
  LINEAR_PAGE=100
235
235
  LINEAR_PAGES=50
236
+ # For `task ls --json`: how many cards one question about blockers asks
237
+ # about, and how many of each card's relations it reads. Linear caps what one
238
+ # question may cost, and a list inside a list counts once for each card it is
239
+ # asked of, however few it holds (SLICE_RELATIONS), so both are kept small. A
240
+ # card with more relations than are read may have blockers that were not
241
+ # read, which the list says of it.
242
+ LIST_BLOCKED=50
243
+ LIST_RELATIONS=20
236
244
 
237
245
  # The teams Linear knows of those asked for, their open statuses, and one page
238
246
  # of their open cards, with when each was last changed. Linear pages through
239
247
  # the cards in the order it is asked for, each page starting where the last
240
248
  # ended. That order is when each card was made, which nothing changes: in the
241
249
  # order they were last changed, a card edited while the pages are fetched
242
- # would move onto a page already fetched, and never be listed.
250
+ # would move onto a page already fetched, and never be listed. Each card
251
+ # comes with Linear's own id for it, its parent, and the first of the
252
+ # relations that name it as the related card. That one tells whether any
253
+ # card is related to it at all, and so whether one may block it: the
254
+ # blockers themselves are asked for afterwards, of those cards alone
255
+ # (LIST_BLOCKERS_QUERY), since reading them here would cost every card on the
256
+ # page a list of them.
243
257
  LIST_QUERY='query($teams: [String!], $types: [String!], $first: Int, $after: String) {
244
258
  teams(filter: {key: {in: $teams}}) { nodes { key } }
245
259
  workflowStates(first: 250, filter: {team: {key: {in: $teams}}, type: {in: $types}}) {
@@ -247,15 +261,58 @@ LIST_QUERY='query($teams: [String!], $types: [String!], $first: Int, $after: Str
247
261
  }
248
262
  issues(first: $first, after: $after, orderBy: createdAt,
249
263
  filter: {team: {key: {in: $teams}}, state: {type: {in: $types}}}) {
250
- nodes { identifier title url updatedAt state { name type position } }
264
+ nodes { id identifier title url updatedAt state { name type position }
265
+ parent { id identifier title }
266
+ inverseRelations(first: 1) { nodes { id } } }
251
267
  pageInfo { hasNextPage endCursor }
252
268
  }
253
269
  }'
254
270
 
255
- # Turn the pages Linear answered with (one line of JSON each, on stdin) into
256
- # the list: every open status, in Linear's order, with its cards. Teams often
257
- # share a status name; a status of one name and kind is one group, whichever
258
- # teams have it. $space, $teams and $types are given by the caller.
271
+ # One page of the sub-issues of some cards, the parents the open cards name,
272
+ # by Linear's own ids for them: every sub-issue, whatever its status and its
273
+ # team, with when it was made, the kind of status it is in and which of the
274
+ # cards it is a sub-issue of. All the parents are asked about in one
275
+ # question, which is paged through as the list is, in the order the
276
+ # sub-issues were made, so that no parent's count stops short.
277
+ LIST_SUBS_QUERY='query($parents: [ID!], $first: Int, $after: String) {
278
+ issues(first: $first, after: $after, orderBy: createdAt, filter: {parent: {id: {in: $parents}}}) {
279
+ nodes { identifier createdAt state { type } parent { id } }
280
+ pageInfo { hasNextPage endCursor }
281
+ }
282
+ }'
283
+
284
+ # The relations of some cards, by Linear's own ids for them, that name each
285
+ # as the related card, as CARD_BLOCKERS_READ reads them for one card, with
286
+ # the other card's title too. Those of the kind "blocks" name a card that
287
+ # blocks it. Whether a card has more of them than were read comes with them.
288
+ LIST_BLOCKERS_QUERY='query($ids: [ID!], $first: Int) {
289
+ issues(first: $first, filter: {id: {in: $ids}}) {
290
+ nodes { id
291
+ inverseRelations(first: '$LIST_RELATIONS') { nodes { type issue { identifier title state { name type } } } pageInfo { hasNextPage } } }
292
+ }
293
+ }'
294
+
295
+ # From the pages of the list (as for LIST_SHAPE, on stdin), what `task ls
296
+ # --json` asks Linear next, by Linear's own ids: parents, the cards whose
297
+ # sub-issues to read, which are the parents the cards name; and ids, the
298
+ # cards whose blockers to read, which are the cards that some card is related
299
+ # to and the parents of the cards in a not-started status, since a card that
300
+ # blocks its parent holds such a card too. Each id is there once.
301
+ LIST_ASK='
302
+ [.[].list.issues.nodes[]?] as $cards
303
+ | {parents: ([$cards[] | .parent.id? | strings] | unique),
304
+ ids: ([$cards[]
305
+ | (select((.inverseRelations.nodes? // []) | length > 0) | .id?),
306
+ (select(.state.type? == "unstarted") | .parent.id?)
307
+ | strings] | unique)}'
308
+
309
+ # Turn what Linear answered (on stdin, a line of JSON for each answer, under
310
+ # a name that says which question it answers: list for a page of the list,
311
+ # subs for a page of sub-issues and blockers for an answer about blockers)
312
+ # into the list: every open status, in Linear's order, with its cards. Teams
313
+ # often share a status name; a status of one name and kind is one group,
314
+ # whichever teams have it. $space, $teams, $types and $detail are given by
315
+ # the caller.
259
316
  # - Under each status the card changed last comes first. Cards changed at
260
317
  # the same moment keep the order Linear gave them in.
261
318
  # - Should a card come on two pages, the first copy is kept.
@@ -263,12 +320,76 @@ LIST_QUERY='query($teams: [String!], $types: [String!], $first: Int, $after: Str
263
320
  # that it did not, such as one made while the pages were fetched, so that
264
321
  # no card is dropped for want of a group.
265
322
  # - A closed status is never listed, should Linear send one.
323
+ # A card is its id, title and url. When $detail is true, it also says where
324
+ # it stands, from the other two questions' answers:
325
+ # - parent is the card it is a sub-issue of, with how many sub-issues that
326
+ # card has and how many of them are done, which is in a completed status.
327
+ # Every sub-issue counts, whatever its status. place is where the card
328
+ # comes among them, from 1, in the order they were made, the order
329
+ # READ_SHAPE gives subIssues in; it is null should the card not be among
330
+ # them, as when its parent changed between the questions. Both are null
331
+ # for a card with no parent.
332
+ # - blockedBy is the cards that block it, done or not, as READ_SHAPE gives
333
+ # them, and none for a card no card is related to.
334
+ # - held is whether `task start` would hold it, by the test card_branch
335
+ # applies (task.sh): it is in a not-started status, and a card that
336
+ # blocks it or its parent is not done. waitsOn is those cards, its own
337
+ # blockers and then its parent's, each once, and none when it is not held.
338
+ # - blockersCut is true when blockers may be missing from that: the card
339
+ # has more relations than were read, or its parent has, when the parent's
340
+ # can hold it, or Linear's answer left one of the two out.
341
+ # A sub-issue or a blocker that is not in the form Linear gives it in did not
342
+ # come from Linear, so nothing is listed. The list's own pages are read as
343
+ # they always were: a card with no parent or relations in the answer has
344
+ # neither.
266
345
  LIST_SHAPE='
346
+ def text: if type == "string" then . else error("unreadable") end;
347
+ def nodes: if (.issues.nodes | type) == "array" then .issues.nodes[] else error("unreadable") end;
348
+ def status: if type == "object" then {name: (.name | text), type: (.type | text)} else error("unreadable") end;
267
349
  ($types | to_entries | map({key: .value, value: .key}) | from_entries) as $rank
268
- | .[0] as $first
269
- | ([.[].issues.nodes[]] | to_entries | unique_by(.value.identifier)
350
+ | [.[] | .list | values] as $pages
351
+ | $pages[0] as $first
352
+ | ([$pages[].issues.nodes[]] | to_entries | unique_by(.value.identifier)
270
353
  | sort_by([.value.updatedAt, -.key]) | reverse | map(.value)) as $cards
271
- | {
354
+ | ([.[] | .subs | values | nodes
355
+ | {id: (.identifier | text), at: (.createdAt | text), done: ((.state.type | text) == "completed"),
356
+ of: (.parent.id | text)}]
357
+ | to_entries | unique_by(.value.id) | sort_by([.value.at, .key]) | map(.value)
358
+ | group_by(.of) | map({key: .[0].of, value: .}) | from_entries) as $subs
359
+ | ([.[] | .blockers | values | nodes
360
+ | {key: (.id | text),
361
+ value: (.inverseRelations
362
+ | if type == "object" and (.nodes | type) == "array" and (.pageInfo.hasNextPage | type) == "boolean"
363
+ then {cut: .pageInfo.hasNextPage,
364
+ by: [.nodes[] | select((.type | text) == "blocks") | .issue
365
+ | if type == "object"
366
+ then {id: (.identifier | text), title: (.title | text), status: (.state | status)}
367
+ else error("unreadable") end]}
368
+ else error("unreadable") end)}]
369
+ | from_entries) as $read
370
+ | def none: {by: [], cut: false};
371
+ def read($id): if ($id | type) == "string" and ($read | has($id)) then $read[$id] else {by: [], cut: true} end;
372
+ def detail:
373
+ . as $card
374
+ | (if .parent == null then null
375
+ elif (.parent | type) == "object"
376
+ then .parent | {key: (.id | text), id: (.identifier | text), title: (.title | text)}
377
+ else error("unreadable") end) as $parent
378
+ | (if $parent == null then [] else $subs[$parent.key] // [] end) as $among
379
+ | (if ((.inverseRelations.nodes? // []) | length) > 0 then read(.id) else none end) as $own
380
+ | (if $parent != null and .state.type == "unstarted" then read($parent.key) else none end) as $above
381
+ | (reduce ($own.by[], $above.by[] | select(.status.type != "completed")) as $by ([];
382
+ if any(.[]; .id == $by.id) then . else . + [$by] end)) as $open
383
+ | (.state.type == "unstarted" and ($open | length) > 0) as $held
384
+ | {parent: (if $parent == null then null
385
+ else {id: $parent.id, title: $parent.title, subIssues: ($among | length),
386
+ done: ([$among[] | select(.done)] | length)} end),
387
+ place: (($among | map(.id) | index($card.identifier)) as $at | if $at == null then null else $at + 1 end),
388
+ blockedBy: $own.by,
389
+ blockersCut: ($own.cut or $above.cut),
390
+ held: $held,
391
+ waitsOn: (if $held then $open else [] end)};
392
+ {
272
393
  missing: ($teams - [$first.teams.nodes[].key]),
273
394
  space: $space,
274
395
  teams: $teams,
@@ -286,45 +407,90 @@ LIST_SHAPE='
286
407
  cards: [
287
408
  $cards[]
288
409
  | select(.state.name == $status.name and .state.type == $status.type)
289
- | {id: .identifier, title: .title, url: .url}
410
+ | {id: .identifier, title: .title, url: .url} + (if $detail then detail else {} end)
290
411
  ]
291
412
  }
292
413
  ]
293
414
  }'
294
415
 
295
- # Print the open cards of some Linear teams as one line of JSON, grouped by
296
- # status:
297
- # {"space":"demo","teams":["ABC"],"statuses":[
298
- # {"name":"Backlog","type":"backlog","cards":[{"id":"ABC-1","title":"…","url":"…"}]}]}
299
- # Every open status of the teams is there, with no cards when it has none.
300
- # linear_open_cards <space> <team key>...
301
- linear_open_cards() {
302
- local space=$1 key teams vars data pages='' after='' more asked=0 list missing
303
- shift
304
- linear_tools
305
- key=$(linear_saved_key) || exit 1
306
- teams=$(printf '%s\n' "$@" | jq -Rcn '[inputs]')
416
+ # Ask Linear a question that pages through cards, up to the last page, and
417
+ # print each page's answer as a line of JSON under a name, like
418
+ # {"list": <the answer>}, for LIST_SHAPE to tell the questions' answers
419
+ # apart by. The query takes $first and $after with the variables given, and
420
+ # answers with issues { nodes pageInfo { hasNextPage endCursor } }. When the
421
+ # pages cannot be read to the last one, it stops, as die does: what came so
422
+ # far would pass a part for the whole.
423
+ # linear_pages <key> <name> <what the pages hold, for a message> <query> <its other variables, as JSON>
424
+ linear_pages() {
425
+ local key=$1 name=$2 what=$3 query=$4 base=$5 vars data after='' more asked=0
307
426
  while :; do
308
427
  asked=$((asked + 1))
309
428
  [ "$asked" -le "$LINEAR_PAGES" ] ||
310
- die "Linear still had more cards after $LINEAR_PAGES pages of $LINEAR_PAGE, which is more than ocnus lists."
311
- vars=$(jq -cn --argjson teams "$teams" --argjson types "$OPEN_TYPES" --argjson first "$LINEAR_PAGE" \
312
- --arg after "$after" \
313
- '{teams: $teams, types: $types, first: $first, after: (if $after == "" then null else $after end)}')
314
- data=$(linear_ask "$key" "$LIST_QUERY" "$vars") || exit 1
315
- pages+=$data$'\n'
429
+ die "Linear still had more $what after $LINEAR_PAGES pages of $LINEAR_PAGE, which is more than ocnus lists."
430
+ vars=$(jq -cn --argjson base "$base" --argjson first "$LINEAR_PAGE" --arg after "$after" \
431
+ '$base + {first: $first, after: (if $after == "" then null else $after end)}') ||
432
+ die "could not put a question to Linear together."
433
+ data=$(linear_ask "$key" "$query" "$vars") || exit 1
434
+ printf '{"%s":%s}\n' "$name" "$data"
316
435
  more=$(printf '%s' "$data" | jq -r '.issues.pageInfo.hasNextPage == true' 2>/dev/null) ||
317
436
  die "Linear's answer was not one ocnus can read."
318
437
  [ "$more" = true ] || break
319
438
  # Listing what came so far would pass a part of the list for the whole.
320
439
  after=$(printf '%s' "$data" | jq -r '.issues.pageInfo.endCursor | strings' 2>/dev/null) || after=
321
440
  [ -n "$after" ] ||
322
- die "Linear said it had more cards but not where the next ones start, so the list would be cut short."
441
+ die "Linear said it had more $what but not where the next ones start, so the list would be cut short."
323
442
  done
324
- # The pages go to jq on stdin, not as an argument: a long list of cards is
325
- # more than a command's arguments may hold.
326
- list=$(printf '%s' "$pages" |
327
- jq -cs --arg space "$space" --argjson teams "$teams" --argjson types "$OPEN_TYPES" "$LIST_SHAPE" 2>/dev/null) ||
443
+ }
444
+
445
+ # Print the open cards of some Linear teams as one line of JSON, grouped by
446
+ # status:
447
+ # {"space":"demo","teams":["ABC"],"statuses":[
448
+ # {"name":"Backlog","type":"backlog","cards":[{"id":"ABC-1","title":"…","url":"…"}]}]}
449
+ # Every open status of the teams is there, with no cards when it has none.
450
+ # With the detail, which `task ls --json` asks for, each card also says
451
+ # where it stands (LIST_SHAPE):
452
+ # {"id":"ABC-123","title":"…","url":"…",
453
+ # "parent":{"id":"ABC-100","title":"…","subIssues":3,"done":1},"place":2,
454
+ # "blockedBy":[{"id":"ABC-122","title":"…","status":{"name":"In Progress","type":"started"}}],
455
+ # "blockersCut":false,"held":true,
456
+ # "waitsOn":[{"id":"ABC-122","title":"…","status":{"name":"In Progress","type":"started"}}]}
457
+ # That takes up to two more questions, each asked only when the list holds
458
+ # something to ask about: the sub-issues of the parents the cards name, all
459
+ # in one question, paged to its end, and then the blockers of the cards
460
+ # that some card is related to and of the parents of not-started cards,
461
+ # LIST_BLOCKED cards at a time. When one of them fails, or cannot be read to
462
+ # its end, nothing is printed, as for the list itself.
463
+ # linear_open_cards <space> <true, for the detail, or false> <team key>...
464
+ linear_open_cards() {
465
+ local space=$1 detail=$2 key teams pages ask count at=0 vars data list missing
466
+ shift 2
467
+ linear_tools
468
+ key=$(linear_saved_key) || exit 1
469
+ teams=$(printf '%s\n' "$@" | jq -Rcn '[inputs]')
470
+ pages=$(linear_pages "$key" list cards "$LIST_QUERY" \
471
+ "$(jq -cn --argjson teams "$teams" --argjson types "$OPEN_TYPES" '{teams: $teams, types: $types}')") || exit 1
472
+ if [ "$detail" = true ]; then
473
+ # The pages go to jq on stdin, here and below, not as an argument: a
474
+ # long list of cards is more than a command's arguments may hold.
475
+ ask=$(printf '%s\n' "$pages" | jq -cs "$LIST_ASK" 2>/dev/null) ||
476
+ die "Linear's answer was not one ocnus can read."
477
+ if [ "$(printf '%s' "$ask" | jq -r '.parents | length')" != 0 ]; then
478
+ data=$(linear_pages "$key" subs sub-issues "$LIST_SUBS_QUERY" "$(printf '%s' "$ask" | jq -c '{parents}')") || exit 1
479
+ pages+=$'\n'$data
480
+ fi
481
+ count=$(printf '%s' "$ask" | jq -r '.ids | length')
482
+ while [ "$at" -lt "$count" ]; do
483
+ # As many cards are asked for as are named, and no more.
484
+ vars=$(printf '%s' "$ask" |
485
+ jq -c --argjson at "$at" --argjson n "$LIST_BLOCKED" '.ids[$at:($at + $n)] | {ids: ., first: length}')
486
+ data=$(linear_ask "$key" "$LIST_BLOCKERS_QUERY" "$vars") || exit 1
487
+ pages+=$'\n'"{\"blockers\":$data}"
488
+ at=$((at + LIST_BLOCKED))
489
+ done
490
+ fi
491
+ list=$(printf '%s\n' "$pages" |
492
+ jq -cs --arg space "$space" --argjson teams "$teams" --argjson types "$OPEN_TYPES" --argjson detail "$detail" \
493
+ "$LIST_SHAPE" 2>/dev/null) ||
328
494
  die "Linear's answer was not one ocnus can read."
329
495
  missing=$(printf '%s' "$list" | jq -r '.missing | join(", ")')
330
496
  [ -z "$missing" ] ||
@@ -494,14 +660,18 @@ linear_key() {
494
660
  # it. `task ls` uses it too.
495
661
  PLAIN_DEF='def plain: explode | map(if . < 32 or (. > 126 and . < 160) then 32 else . end) | implode;'
496
662
 
497
- # How many labels, comments and sub-issues a read asks Linear for. A card
498
- # with more than that is not printed, since what was read would pass for the
499
- # whole of it.
663
+ # How many labels, comments, sub-issues and relations a read asks Linear
664
+ # for. A card with more than that is not printed, since what was read would
665
+ # pass for the whole of it. The relations are asked for each way: those from
666
+ # the card to another card, and those from another card to it.
500
667
  READ_LABELS=100
501
668
  READ_COMMENTS=100
502
669
  READ_SUBS=50
670
+ READ_RELATIONS=50
503
671
 
504
- # The question for linear read: the card whole.
672
+ # The question for linear read: the card whole. Its relations of the kind
673
+ # "blocks" name the cards it blocks, as their relatedIssue, and its inverse
674
+ # relations of that kind the cards that block it, as their issue.
505
675
  READ_QUERY='query($team: String!, $number: Float!) {
506
676
  issues(first: 1, filter: {team: {key: {eq: $team}}, number: {eq: $number}}) {
507
677
  nodes {
@@ -512,29 +682,38 @@ READ_QUERY='query($team: String!, $number: Float!) {
512
682
  project { name }
513
683
  comments(first: '$READ_COMMENTS') { nodes { body createdAt user { name } botActor { name } } pageInfo { hasNextPage } }
514
684
  children(first: '$READ_SUBS') { nodes { identifier title createdAt state { name type } } pageInfo { hasNextPage } }
685
+ relations(first: '$READ_RELATIONS') { nodes { type relatedIssue { identifier title state { name type } } } pageInfo { hasNextPage } }
686
+ inverseRelations(first: '$READ_RELATIONS') { nodes { type issue { identifier title state { name type } } } pageInfo { hasNextPage } }
515
687
  }
516
688
  }
517
689
  }'
518
690
 
519
691
  # From the answer to READ_QUERY, on stdin, print "none" when Linear has no
520
- # such card, {"more": <what>} when it has more comments, sub-issues or labels
521
- # than were asked for, or {"card": <the card>}, the card as linear read --json
522
- # prints it. A comment's author is the app Linear credits with it, or else
523
- # the user who wrote it. Comments come oldest first, and so do sub-issues, in
524
- # the order they were made, which is the order linear slices makes a card's
525
- # slices in, whatever order Linear lists them in; when each was made is left
526
- # out. An answer with a card in it that is not in this form did not come from
527
- # Linear. $group is TYPE_GROUP.
692
+ # such card, {"more": <what>} when it has more comments, sub-issues, labels
693
+ # or relations than were asked for, or {"card": <the card>}, the card as
694
+ # linear read --json prints it. A comment's author is the app Linear credits
695
+ # with it, or else the user who wrote it. Comments come oldest first, and so
696
+ # do sub-issues, in the order they were made, which is the order linear
697
+ # slices makes a card's slices in, whatever order Linear lists them in; when
698
+ # each was made is left out. blockedBy are the cards that block it and blocks
699
+ # the cards it blocks, from its relations of the kind "blocks" alone, done or
700
+ # not, each as a sub-issue is, in the order Linear lists them. An answer with
701
+ # a card in it that is not in this form did not come from Linear. $group is
702
+ # TYPE_GROUP.
528
703
  READ_SHAPE='
529
704
  def text: if type == "string" then . else error("unreadable") end;
530
705
  def list: if (.nodes | type) == "array" then .nodes[] else error("unreadable") end;
531
706
  def status: if type == "object" then {name: (.name | text), type: (.type | text)} else error("unreadable") end;
707
+ def other: if type == "object" then {id: (.identifier | text), title: (.title | text), status: (.state | status)}
708
+ else error("unreadable") end;
532
709
  if (.issues.nodes | type) != "array" then error("no list of cards")
533
710
  elif (.issues.nodes | length) == 0 then "none"
534
711
  else .issues.nodes[0]
535
712
  | if .comments.pageInfo.hasNextPage? == true then {more: "comments"}
536
713
  elif .children.pageInfo.hasNextPage? == true then {more: "sub-issues"}
537
714
  elif .labels.pageInfo.hasNextPage? == true then {more: "labels"}
715
+ elif .relations.pageInfo.hasNextPage? == true or .inverseRelations.pageInfo.hasNextPage? == true
716
+ then {more: "relations"}
538
717
  else {card: {
539
718
  id: (.identifier | text),
540
719
  title: (.title | text),
@@ -543,6 +722,8 @@ READ_SHAPE='
543
722
  type: ([.labels | list | select(.parent.name? == $group) | .name] | first),
544
723
  labels: [.labels | list | .name | text],
545
724
  parent: (if .parent == null then null else {id: (.parent.identifier | text), title: (.parent.title | text)} end),
725
+ blockedBy: [.inverseRelations | list | select((.type | text) == "blocks") | .issue | other],
726
+ blocks: [.relations | list | select((.type | text) == "blocks") | .relatedIssue | other],
546
727
  project: (if .project == null then null else {name: (.project.name | text)} end),
547
728
  description: (.description // "" | text),
548
729
  comments: ([.comments | list
@@ -555,7 +736,8 @@ READ_SHAPE='
555
736
  end
556
737
  end'
557
738
 
558
- # The card from READ_SHAPE, on stdin, laid out like the card: its head, the
739
+ # The card from READ_SHAPE, on stdin, laid out like the card: its head, with
740
+ # a line for each card that blocks it and each card it blocks, the
559
741
  # description as written, the comments, each with its body indented under who
560
742
  # wrote it and when, and the sub-issues. Every field is made plain, but the
561
743
  # description and the comments keep their line breaks, without the \r Linear
@@ -569,6 +751,8 @@ READ_TEXT=$PLAIN_DEF'
569
751
  "Status: \(.status.name | plain)",
570
752
  "Labels: \(if .labels == [] then "none" else .labels | map(plain) | join(", ") end)",
571
753
  (.parent // empty | "Parent: \(.id | plain) \(.title | plain)"),
754
+ (.blockedBy[] | "Blocked by: \(.id | plain) \(.status.name | plain) \(.title | plain)"),
755
+ (.blocks[] | "Blocks: \(.id | plain) \(.status.name | plain) \(.title | plain)"),
572
756
  (.project // empty | "Project: \(.name | plain)"),
573
757
  "URL: \(.url | plain)",
574
758
  "",
@@ -585,13 +769,17 @@ READ_TEXT=$PLAIN_DEF'
585
769
  # Print a card whole, laid out like the card, or with --json as one line of
586
770
  # JSON, for a mod:
587
771
  # {"id":"ABC-122","title":"…","url":"…","status":{"name":"In Progress","type":"started"},
588
- # "type":"feat","labels":["feat"],"parent":{"id":"ABC-100","title":"…"},"project":{"name":"…"},
772
+ # "type":"feat","labels":["feat"],"parent":{"id":"ABC-100","title":"…"},
773
+ # "blockedBy":[{"id":"ABC-121","title":"…","status":{"name":"In Progress","type":"started"}}],
774
+ # "blocks":[{"id":"ABC-130","title":"…","status":{"name":"Todo","type":"unstarted"}}],
775
+ # "project":{"name":"…"},
589
776
  # "description":"…",
590
777
  # "comments":[{"author":"…","createdAt":"…","body":"…"}],
591
778
  # "subIssues":[{"id":"ABC-123","title":"…","status":{"name":"Todo","type":"unstarted"}}]}
592
779
  # type is the card's label in the Type group, or null; parent and project, the
593
- # card's Linear project, are null for a card with none. When it fails it
594
- # prints nothing on stdout.
780
+ # card's Linear project, are null for a card with none. blockedBy are the
781
+ # cards that block it, and blocks the cards it blocks, done or not. When it
782
+ # fails it prints nothing on stdout.
595
783
  # ocnus linear read <card> [--json]
596
784
  linear_read() {
597
785
  local card=${1:-} json=0 key vars data shape more=''
@@ -617,6 +805,7 @@ linear_read() {
617
805
  '{"more":"comments"}') more="$READ_COMMENTS comments" ;;
618
806
  '{"more":"sub-issues"}') more="$READ_SUBS sub-issues" ;;
619
807
  '{"more":"labels"}') more="$READ_LABELS labels" ;;
808
+ '{"more":"relations"}') more="$READ_RELATIONS relations" ;;
620
809
  *) die "Linear's answer was not one ocnus can read. Something between this machine and Linear may be answering for it." ;;
621
810
  esac
622
811
  [ -z "$more" ] ||
@@ -630,11 +819,12 @@ linear_read() {
630
819
 
631
820
  # --- the card skills' writes ------------------------------------------------
632
821
  #
633
- # The card skills write three things: a card's type label, a section of its
634
- # description, and its slices, the sub-issues sdlc-breakdown makes of it. Each
635
- # is one command here, so that it goes the same way on every run, and each
636
- # reads back what Linear saved before it says it is done. The slices are the
637
- # one thing created; nothing else in Linear is changed.
822
+ # The card skills write four things: a card's type label, a section of its
823
+ # description, its slices, the sub-issues sdlc-breakdown makes of it, and the
824
+ # cards that block a card. Each is one command here, so that it goes the same
825
+ # way on every run, and each reads back what Linear saved before it says it
826
+ # is done. The slices and the blockers are the only things created; nothing
827
+ # else in Linear is changed, and nothing is removed.
638
828
 
639
829
  # The types a card can have. Each is the start of the card's branch name.
640
830
  CARD_TYPES='feat fix chore'
@@ -1116,6 +1306,311 @@ linear_slices() {
1116
1306
  .others[] | "Left alone: \(.identifier | plain) \(.title | plain), a sub-issue of \($card) that is not one of its slices"'
1117
1307
  }
1118
1308
 
1309
+ # --- recording blockers -----------------------------------------------------
1310
+ #
1311
+ # sdlc-breakdown records every other card a card or a slice depends on, in
1312
+ # another parent card too, as one that blocks it, so that the cards start in
1313
+ # the order the work needs: `task start` holds a card while a card that
1314
+ # blocks it is not done, and the chain starts it once they all are
1315
+ # (chain.sh). A blocker is a relation of the kind "blocks", from
1316
+ # the blocker to the card, as linear slices makes between slices. Nothing
1317
+ # here ever removes one.
1318
+
1319
+ # The question for linear block: a card's id, and the cards that block it
1320
+ # now, by their ids. It finds each blocker's id too. A card with more
1321
+ # relations than are read may have a blocker among the rest; asking for it
1322
+ # again costs nothing, since Linear keeps one relation of a kind between two
1323
+ # cards (SLICE_RELATIONS).
1324
+ BLOCK_QUERY='query($team: String!, $number: Float!) {
1325
+ issues(first: 1, filter: {team: {key: {eq: $team}}, number: {eq: $number}}) {
1326
+ nodes { id identifier
1327
+ inverseRelations(first: '$CARD_RELATIONS') { nodes { type issue { id } } } }
1328
+ }
1329
+ }'
1330
+
1331
+ # From the answer to BLOCK_QUERY, on stdin, the card as {"state": "ok", id,
1332
+ # blockers}, blockers being the ids of the cards that block it, or
1333
+ # {"state": "none"} when Linear has no such card. An answer with a card in it
1334
+ # that is not in this form did not come from Linear.
1335
+ BLOCK_SHAPE='
1336
+ def text: if type == "string" then . else error("unreadable") end;
1337
+ if (.issues.nodes | type) != "array" then error("no list of cards")
1338
+ elif (.issues.nodes | length) == 0 then {state: "none"}
1339
+ else .issues.nodes[0]
1340
+ | {state: "ok", id: (.id | text),
1341
+ blockers: [.inverseRelations.nodes[]? | select(.type? == "blocks") | .issue.id? | strings]}
1342
+ end'
1343
+
1344
+ # Print a card as BLOCK_SHAPE has it, one line of JSON, or stop and say why.
1345
+ # block_card <key> <card ID, in upper case>
1346
+ block_card() {
1347
+ local key=$1 card=$2 vars data found
1348
+ vars=$(jq -cn --arg team "${card%-*}" --arg number "${card##*-}" '{team: $team, number: ($number | tonumber)}') ||
1349
+ die "'$card' is not a card ID like ABC-122. Nothing was recorded."
1350
+ data=$(linear_ask "$key" "$BLOCK_QUERY" "$vars") || exit 1
1351
+ # Judged by what jq prints: some versions exit zero on an empty answer.
1352
+ found=$(printf '%s' "$data" | jq -c "$BLOCK_SHAPE" 2>/dev/null) || found=
1353
+ case $(printf '%s' "$found" | jq -r '.state' 2>/dev/null) in
1354
+ ok) printf '%s\n' "$found" ;;
1355
+ none) die "Linear has no card $card that the saved key can see. Check the ID, then run this again. Nothing was recorded." ;;
1356
+ *) die "Linear's answer was not one ocnus can read. Something between this machine and Linear may be answering for it. Nothing was recorded." ;;
1357
+ esac
1358
+ }
1359
+
1360
+ # Record in Linear that each blocker given blocks the card: a relation of the
1361
+ # kind blocks, from the blocker to the card. Every card is read before
1362
+ # anything is recorded, so an ID Linear does not have records nothing. A
1363
+ # blocker the card has already is skipped, one given twice is recorded once,
1364
+ # and each one recorded is read back before the next. A card never blocks
1365
+ # itself. Nothing is removed. It prints one line for each blocker:
1366
+ # <card> is now blocked by <blocker>
1367
+ # <card> is blocked by <blocker> already
1368
+ # A run that stopped partway is finished by running it again with the same
1369
+ # cards.
1370
+ # ocnus linear block <card> <blocker>...
1371
+ linear_block() {
1372
+ local card=${1:-} given blocker blockers='' key found card_id had ids='' id vars made
1373
+ [ "$#" -ge 2 ] ||
1374
+ die "usage: ocnus linear block <card> <blocker>..., like: ocnus linear block ABC-122 ABC-121, which records that ABC-121 blocks ABC-122"
1375
+ [[ $card =~ $CARD_RE ]] || die "'$card' is not a card ID like ABC-122. Nothing was recorded."
1376
+ card=$(printf '%s' "$card" | tr '[:lower:]' '[:upper:]')
1377
+ shift
1378
+ for given in "$@"; do
1379
+ [[ $given =~ $CARD_RE ]] || die "'$given' is not a card ID like ABC-121. Nothing was recorded."
1380
+ blocker=$(printf '%s' "$given" | tr '[:lower:]' '[:upper:]')
1381
+ [ "$blocker" != "$card" ] || die "$card cannot block itself. Nothing was recorded."
1382
+ in_list "$blocker" "$blockers" || blockers="$blockers $blocker"
1383
+ done
1384
+ linear_tools
1385
+ key=$(linear_saved_key) || exit 1
1386
+ found=$(block_card "$key" "$card") || exit 1
1387
+ card_id=$(printf '%s' "$found" | jq -r '.id')
1388
+ had=$(printf '%s' "$found" | jq -r '.blockers[]')
1389
+ # Each blocker's id, in the order given, before anything is recorded.
1390
+ for blocker in $blockers; do
1391
+ found=$(block_card "$key" "$blocker") || exit 1
1392
+ id=$(printf '%s' "$found" | jq -r '.id')
1393
+ [ "$id" != "$card_id" ] || die "$blocker is $card in Linear, and $card cannot block itself. Nothing was recorded."
1394
+ ids="$ids $id"
1395
+ done
1396
+ # The ids are Linear's, with no spaces in them, one for each blocker, in
1397
+ # the same order.
1398
+ # shellcheck disable=SC2086
1399
+ set -- $ids
1400
+ for blocker in $blockers; do
1401
+ id=$1
1402
+ shift
1403
+ if printf '%s\n' "$had" | grep -qxF -- "$id"; then
1404
+ say "$card is blocked by $blocker already"
1405
+ continue
1406
+ fi
1407
+ vars=$(jq -cn --arg from "$id" --arg to "$card_id" '{input: {issueId: $from, relatedIssueId: $to, type: "blocks"}}')
1408
+ made=$(linear_ask "$key" "$SLICE_BLOCK" "$vars" 2>&1) ||
1409
+ die "could not record $blocker as blocking $card: $(first_sentence "$made"). Run this again with the same cards to record the rest: it skips the blockers already there."
1410
+ [ "$(printf '%s' "$made" | jq -r --arg from "$id" --arg to "$card_id" '
1411
+ .issueRelationCreate.issueRelation | type == "object" and .type? == "blocks"
1412
+ and .issue.id? == $from and .relatedIssue.id? == $to' 2>/dev/null)" = true ] ||
1413
+ die "Linear did not record $blocker as blocking $card, as its answer shows. Look at $card in Linear, then run this again with the same cards to add it."
1414
+ say "$card is now blocked by $blocker"
1415
+ done
1416
+ }
1417
+
1418
+ # --- the cards that wait to start -------------------------------------------
1419
+ #
1420
+ # The chain (chain.sh) starts a card once every card that blocks it is done.
1421
+ # Two questions tell it which cards wait: linear_blocks, for the cards that a
1422
+ # card whose merge was just recorded blocks, and linear_waiting, for every
1423
+ # card of some teams that is in a not-started status, whatever blocks it.
1424
+ # Neither changes anything in Linear.
1425
+
1426
+ # How much of each list the two questions read. Linear caps what one question
1427
+ # may cost, and counts a list inside a list again for every card of the outer
1428
+ # one (SLICE_RELATIONS), so each is kept small: of a card that has merged, and
1429
+ # of the card it was sliced from, the relations that name the cards it blocks;
1430
+ # of a card that waits, and of the card it was sliced from, the relations that
1431
+ # name the cards that block it; a card's sub-issues; and how many cards that
1432
+ # wait are asked for at a time. A card with more than was read says so
1433
+ # (CHAIN_DEFS), and a card that was not read is found by the next question
1434
+ # that asks about every card that waits.
1435
+ CHAIN_RELATIONS=10
1436
+ CHAIN_BLOCKERS=20
1437
+ CHAIN_SUBS=20
1438
+ WAITING_PAGE=20
1439
+ # The kinds of status a card that waits to start is in: approved, and not
1440
+ # started. A card in Backlog is not approved, and is never asked for.
1441
+ WAITING_TYPES='["unstarted"]'
1442
+
1443
+ # A card's relations of every kind that name it as the related card
1444
+ # (CARD_BLOCKERS_READ).
1445
+ CHAIN_BLOCKERS_READ='inverseRelations(first: '$CHAIN_BLOCKERS') {
1446
+ nodes { type issue { identifier state { name type } } } pageInfo { hasNextPage } }'
1447
+ # A card that waits, as both questions read it: its status, its description,
1448
+ # which holds its sections, the cards that block it and those that block the
1449
+ # card it was sliced from, and its sub-issues, each with its status, its
1450
+ # description and when it was made.
1451
+ CHAIN_CARD='identifier description state { name type }
1452
+ '$CHAIN_BLOCKERS_READ'
1453
+ parent { identifier
1454
+ '$CHAIN_BLOCKERS_READ' }
1455
+ children(first: '$CHAIN_SUBS') {
1456
+ nodes { identifier createdAt description state { name type } } pageInfo { hasNextPage } }'
1457
+ # A card's relations of every kind that it is the first card of. Those of the
1458
+ # kind "blocks" name a card it blocks, as their relatedIssue.
1459
+ CHAIN_BLOCKS_READ='relations(first: '$CHAIN_RELATIONS') {
1460
+ nodes { type relatedIssue {
1461
+ '$CHAIN_CARD' } }
1462
+ pageInfo { hasNextPage } }'
1463
+ # The question for linear_blocks: a card, the card it was sliced from, and
1464
+ # the cards each of the two blocks.
1465
+ BLOCKS_QUERY='query($team: String!, $number: Float!) {
1466
+ issues(first: 1, filter: {team: {key: {eq: $team}}, number: {eq: $number}}) {
1467
+ nodes { identifier state { name type }
1468
+ '$CHAIN_BLOCKS_READ'
1469
+ parent { identifier state { name type }
1470
+ '$CHAIN_BLOCKS_READ' } }
1471
+ }
1472
+ }'
1473
+ # The question for linear_waiting: one page of the cards of some teams that
1474
+ # are in a status of the kinds given, in the order they were made, which
1475
+ # nothing changes while the pages are fetched (LIST_QUERY).
1476
+ WAITING_QUERY='query($teams: [String!], $types: [String!], $first: Int, $after: String) {
1477
+ issues(first: $first, after: $after, orderBy: createdAt,
1478
+ filter: {team: {key: {in: $teams}}, state: {type: {in: $types}}}) {
1479
+ nodes { '$CHAIN_CARD' }
1480
+ pageInfo { hasNextPage endCursor }
1481
+ }
1482
+ }'
1483
+
1484
+ # What both shapes below are made of. waiting turns a card, as CHAIN_CARD
1485
+ # reads it, into
1486
+ # {id, status, type, spec, plan, parent, blockers, cut, subs, subsCut}
1487
+ # status and type are the name and the kind of its status, made plain, as
1488
+ # every text of Linear's here is. spec and plan say whether its description
1489
+ # has a Specification and a Plan: the heading `linear section` writes for
1490
+ # each (SECTION_FORMS), which a line inside a fenced code block never is.
1491
+ # parent is the ID of the card it was sliced from, or null. blockers are the
1492
+ # cards that block it, and those that block its parent, each as CARD_SHAPE
1493
+ # has it: {id, status, type, of}, done or not. cut is true when it or its
1494
+ # parent has more relations than were read. subs are its sub-issues, in the
1495
+ # order they were made, which is the order `linear slices` makes a card's
1496
+ # slices in, each as {id, status, type, spec, plan}, and subsCut is true when
1497
+ # it has more than were read. A card, a blocker or a sub-issue whose ID is
1498
+ # not a card ID is left out: an ID is handed to `task start`.
1499
+ CHAIN_DEFS=$PLAIN_DEF'
1500
+ def has_section($name; $open): '$SECTION_FORMS'
1501
+ (split("\n") | map(rtrimstr("\r"))) as $lines
1502
+ | ($lines | in_code) as $code
1503
+ | any(range(0; $lines | length); ($code[.] | not) and ($lines[.] | is_heading));
1504
+ def is_id: type == "string" and test("^[A-Za-z][A-Za-z0-9]*-[0-9]+$");
1505
+ def status: {status: ((.state.name? | strings | plain) // ""), type: ((.state.type? | strings) // "")};
1506
+ def sections: ((.description? | strings) // "") as $text
1507
+ | {spec: ($text | has_section("Specification"; "false")), plan: ($text | has_section("Plan"; "false"))};
1508
+ def blockers: .identifier as $of
1509
+ | [.inverseRelations.nodes[]? | select(.type? == "blocks") | .issue | select(.identifier? | is_id)
1510
+ | {id: .identifier} + status + {of: $of}];
1511
+ def cut: .inverseRelations.pageInfo.hasNextPage? == true;
1512
+ def above: if (.parent | type) == "object" and (.parent.identifier? | is_id) then .parent else null end;
1513
+ def waiting: above as $above
1514
+ | {id: .identifier} + status + sections
1515
+ + {parent: (if $above == null then null else $above.identifier end),
1516
+ blockers: (blockers + (if $above == null then [] else ($above | blockers) end)),
1517
+ cut: (cut or ($above != null and ($above | cut))),
1518
+ subs: ([.children.nodes[]? | select(.identifier? | is_id)] | sort_by(.createdAt? // "")
1519
+ | map({id: .identifier} + status + sections)),
1520
+ subsCut: (.children.pageInfo.hasNextPage? == true)};
1521
+ def once: reduce .[] as $c ([]; if any(.[]; .id == $c.id) then . else . + [$c] end);'
1522
+
1523
+ # Turn Linear's answer to BLOCKS_QUERY into {card, cards, cut}, or "none"
1524
+ # when Linear has no such card. cards are the cards the card blocks, each as
1525
+ # waiting has it, in Linear's order, each once. When the card it was sliced
1526
+ # from is in a completed status, as once the merge of its last open slice has
1527
+ # closed it, the cards that card blocks come after them: the merge has freed
1528
+ # them too. While it is open, it still blocks them, so they are left out. A
1529
+ # card that is only related is never one of them. cut is true when Linear has
1530
+ # more of the relations than were read, so that a card it blocks may be
1531
+ # missing. An answer with no list of cards in it is not Linear saying it has
1532
+ # none, so it is an error (CARD_SHAPE).
1533
+ BLOCKS_SHAPE=$CHAIN_DEFS'
1534
+ def blocked: [.relations.nodes[]? | select(.type? == "blocks") | .relatedIssue
1535
+ | select((type == "object") and (.identifier? | is_id)) | waiting];
1536
+ def more: .relations.pageInfo.hasNextPage? == true;
1537
+ if (.issues.nodes | type) != "array" then error("no list of cards")
1538
+ elif (.issues.nodes | length) == 0 then "none"
1539
+ else .issues.nodes[0]
1540
+ | (if (.parent | type) == "object" and (.parent.state.type? == "completed") then .parent else null end) as $closed
1541
+ | {card: .identifier,
1542
+ cards: ((blocked + (if $closed == null then [] else ($closed | blocked) end)) | once),
1543
+ cut: (more or ($closed != null and ($closed | more)))}
1544
+ end'
1545
+
1546
+ # Turn the pages Linear answered WAITING_QUERY with, one line of JSON each,
1547
+ # into {cards}: every card that waits, as waiting has it, in the order they
1548
+ # were made, each once. A page with no list of cards in it is an error.
1549
+ WAITING_SHAPE=$CHAIN_DEFS'
1550
+ if any(.[]; (.issues.nodes | type) != "array") then error("no list of cards")
1551
+ else {cards: ([.[].issues.nodes[] | select((type == "object") and (.identifier? | is_id)) | waiting] | once)}
1552
+ end'
1553
+
1554
+ # Print the cards a card blocks, as one line of JSON (BLOCKS_SHAPE), or stop
1555
+ # and say why:
1556
+ # {"card":"ABC-122","cut":false,"cards":[{"id":"ABC-123","status":"Todo","type":"unstarted",
1557
+ # "spec":true,"plan":true,"parent":"ABC-100",
1558
+ # "blockers":[{"id":"ABC-122","status":"Done","type":"completed","of":"ABC-123"}],"cut":false,
1559
+ # "subs":[],"subsCut":false}]}
1560
+ # It asks Linear once.
1561
+ # linear_blocks <card ID, in upper case>
1562
+ linear_blocks() {
1563
+ local card=$1 key vars data found
1564
+ linear_tools
1565
+ key=$(linear_saved_key) || exit 1
1566
+ vars=$(jq -cn --arg team "${card%-*}" --arg number "${card##*-}" \
1567
+ '{team: $team, number: ($number | tonumber)}' 2>/dev/null) ||
1568
+ die "'$card' is not a card ID like ABC-122."
1569
+ data=$(linear_ask "$key" "$BLOCKS_QUERY" "$vars") || exit 1
1570
+ # Judged by what jq prints: some versions exit zero on an empty answer.
1571
+ found=$(printf '%s' "$data" | jq -c "$BLOCKS_SHAPE" 2>/dev/null) || found=
1572
+ case $found in
1573
+ '{'*) printf '%s\n' "$found" ;;
1574
+ '"none"') die "Linear has no card $card that the saved key can see." ;;
1575
+ *) die "Linear's answer was not one ocnus can read. Something between this machine and Linear may be answering for it." ;;
1576
+ esac
1577
+ }
1578
+
1579
+ # Print every card of some Linear teams that waits to start, as one line of
1580
+ # JSON (WAITING_SHAPE), or stop and say why:
1581
+ # {"cards":[{"id":"ABC-123","status":"Todo","type":"unstarted","spec":true,"plan":true,...}]}
1582
+ # It asks Linear once for every WAITING_PAGE cards that wait, so once while
1583
+ # there are no more than that.
1584
+ # linear_waiting <team key>...
1585
+ linear_waiting() {
1586
+ local key teams vars data pages='' after='' more asked=0 found
1587
+ linear_tools
1588
+ key=$(linear_saved_key) || exit 1
1589
+ teams=$(printf '%s\n' "$@" | jq -Rcn '[inputs]')
1590
+ while :; do
1591
+ asked=$((asked + 1))
1592
+ [ "$asked" -le "$LINEAR_PAGES" ] ||
1593
+ die "Linear still had more cards that wait to start after $LINEAR_PAGES pages of $WAITING_PAGE, which is more than ocnus reads."
1594
+ vars=$(jq -cn --argjson teams "$teams" --argjson types "$WAITING_TYPES" --argjson first "$WAITING_PAGE" \
1595
+ --arg after "$after" \
1596
+ '{teams: $teams, types: $types, first: $first, after: (if $after == "" then null else $after end)}')
1597
+ data=$(linear_ask "$key" "$WAITING_QUERY" "$vars") || exit 1
1598
+ pages+=$data$'\n'
1599
+ more=$(printf '%s' "$data" | jq -r '.issues.pageInfo.hasNextPage == true' 2>/dev/null) ||
1600
+ die "Linear's answer was not one ocnus can read."
1601
+ [ "$more" = true ] || break
1602
+ # Judging what came so far would pass a part of the cards for all of them.
1603
+ after=$(printf '%s' "$data" | jq -r '.issues.pageInfo.endCursor | strings' 2>/dev/null) || after=
1604
+ [ -n "$after" ] ||
1605
+ die "Linear said it had more cards that wait to start but not where the next ones start, so some would be missed."
1606
+ done
1607
+ found=$(printf '%s' "$pages" | jq -cs "$WAITING_SHAPE" 2>/dev/null) || found=
1608
+ case $found in
1609
+ '{'*) printf '%s\n' "$found" ;;
1610
+ *) die "Linear's answer was not one ocnus can read. Something between this machine and Linear may be answering for it." ;;
1611
+ esac
1612
+ }
1613
+
1119
1614
  # --- moving a card ----------------------------------------------------------
1120
1615
  #
1121
1616
  # ocnus moves a card at four points: the hand-off that records the
@@ -1414,9 +1909,10 @@ cmd_linear() {
1414
1909
  type) shift; linear_type "$@" ;;
1415
1910
  section) shift; linear_section "$@" ;;
1416
1911
  slices) shift; linear_slices "$@" ;;
1912
+ block) shift; linear_block "$@" ;;
1417
1913
  move) shift; linear_move_cmd "$@" ;;
1418
1914
  read) shift; linear_read "$@" ;;
1419
1915
  archive) shift; linear_archive_cmd "$@" ;;
1420
- *) die "usage: ocnus linear key, or: ocnus linear read <card> [--json], or: ocnus linear type <card> <feat|fix|chore>, or: ocnus linear section <card> <Specification|Plan|Breakdown|Review> [--replace], or: ocnus linear slices <card>, or: ocnus linear move <card> <approved|started|review|done>, or: ocnus linear archive [on|off|--json] (see: ocnus help)" ;;
1916
+ *) die "usage: ocnus linear key, or: ocnus linear read <card> [--json], or: ocnus linear type <card> <feat|fix|chore>, or: ocnus linear section <card> <Specification|Plan|Breakdown|Review> [--replace], or: ocnus linear slices <card>, or: ocnus linear block <card> <blocker>..., or: ocnus linear move <card> <approved|started|review|done>, or: ocnus linear archive [on|off|--json] (see: ocnus help)" ;;
1421
1917
  esac
1422
1918
  }