@johngaynor/ocnus 2.0.1-next.24 → 2.0.1-next.27

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/README.md CHANGED
@@ -89,8 +89,9 @@ and the two phase profiles in [agents/](agents/), which it links into
89
89
  `~/.claude/agents`; see [herdr/README.md](herdr/README.md) for the full
90
90
  walkthrough. `install` ends by telling you to switch Herdr to the `default`
91
91
  layout, which holds ocnus's panels: the Ocnus spaces panel, the Cards
92
- and Steps panels, the Usage section above Memory and CPU, the Layout dropdown
93
- and the settings button. Herdr's own Agents section is not on it. Herdr starts on
92
+ and Steps panels, the Step counts section right above the Usage section,
93
+ which is above Memory and CPU, the Layout dropdown and the settings button.
94
+ Herdr's own Agents section is not on it. Herdr starts on
94
95
  its own layout, which has no Layout dropdown, so the first switch is
95
96
  `ctrl-shift-l`, pressed until `default` shows.
96
97
 
@@ -505,6 +506,20 @@ the card's own log and in the Steps and Cards panels, which draw what
505
506
  request is closed or in conflict, the card shows as waiting on you, as
506
507
  before.
507
508
 
509
+ On the `default` layout, the Step counts section, right above Usage in the
510
+ sidebar, shows where every card of the space that is showing stands, at a
511
+ glance: the seven steps, from `define` to `pr`, each with a dot for every
512
+ card that stands on it, and how many there are. A dot is amber when its card
513
+ needs you, waiting on you or with its agent blocked on a prompt in its tab;
514
+ blue while its agent is working; green, at `pr`, once the card is ready to
515
+ merge, with its pull requests all open, none in conflict and every check on
516
+ them passed; and red when `task log` says its agent is stuck or has stopped,
517
+ or that a pull request of the card's is closed, in conflict or unwatched.
518
+ `start` has no dots: it says how many approved cards are held, their work
519
+ not yet started. The section draws what `task log <space> --json` counts,
520
+ and updates on its own. See
521
+ [herdr/README.md](herdr/README.md#the-step-counts-section).
522
+
508
523
  `task start` starts the work, once you have approved the card. It takes the
509
524
  card too, makes a branch and a git worktree of it in every repo of the
510
525
  space, opens a tab for it, and starts the agent there that runs the build
package/cli/lib/agents.sh CHANGED
@@ -49,7 +49,11 @@
49
49
  # is not running, ocnus's watch is not running, or gh could not
50
50
  # ask GitHub. That holds whatever the agent in the tab is doing.
51
51
  # Otherwise, with ocnus's watch watching, the card shows as it does
52
- # with no agent state.
52
+ # with no agent state. Such a card is noted as ready to merge when the
53
+ # watch's last pass saw every pull request of the card open and ready
54
+ # (MERGES_READY). That is not an agent state: the log says nothing of
55
+ # it, and only the counts in the list's JSON show it, as the mark
56
+ # ready (counts_sql in handoff.sh).
53
57
  # - No card gets an agent state when jq is missing. None but those whose
54
58
  # pull requests wait on the human get one when hc is missing, or when
55
59
  # neither place can list the space's tabs: herdr-core cannot list its
@@ -224,12 +228,16 @@ card_seen() {
224
228
  # subshell. With Herdr's tabs not read (AGENTS_ON 0), only a card whose pull
225
229
  # requests wait on the human has anything to say: with no tab to look in, no
226
230
  # agent is running.
231
+ #
232
+ # AGENT_READY is 1 for a card ready to merge: its pull requests wait on the
233
+ # human, it has no agent state, and ocnus's watch says they are ready
234
+ # (merges_seen). It is 0 for any other card, and AGENT_JSON is null with it.
227
235
  # card_agent <card> <the card in lower case> <step> <status> <next>
228
236
  # <seconds since the hand-off> <space>
229
- AGENT_JSON=null AGENT_LABEL='' AGENT_FOR=''
237
+ AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0
230
238
  card_agent() {
231
239
  local card=$1 low=$2 step=$3 status=$4 next=$5 since=$6 space=$7
232
- AGENT_JSON=null AGENT_LABEL='' AGENT_FOR=''
240
+ AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0
233
241
  # Its pull requests wait on the human.
234
242
  local waits=0
235
243
  [ "$step $status" != 'pr needs-human' ] || waits=1
@@ -280,6 +288,9 @@ card_agent() {
280
288
  names=${names:+$names, }$PULL_NAME
281
289
  done
282
290
  ;;
291
+ # Nothing to say of its agent or its pull requests: it is ready to
292
+ # merge when the watch says so.
293
+ '') AGENT_READY=$MERGES_READY ;;
283
294
  esac
284
295
  fi
285
296
 
@@ -318,18 +329,20 @@ card_agent() {
318
329
  }
319
330
 
320
331
  # Work out the agent of every card in a view of the log, as AGENTS_SQL: the
321
- # SQL for the table agents (card, agent) that the log's query joins, with
322
- # each card whose agent has something to say and its JSON. The space's tabs
323
- # are read here, once. AGENT_NOW is the last such agent's label and how long
324
- # it has been so, as the list shows them, for the `now:` line of the log of
325
- # one card. Nothing is worked out without jq, which reads hc's answers, as
326
- # ocnus's watch on the merges needs it to run.
332
+ # SQL for the table agents (card, agent, ready) that the log's query joins,
333
+ # with each card whose agent has something to say and its JSON, with ready
334
+ # 0, and each card ready to merge, which has no agent state: its agent is
335
+ # null and its ready 1, for the list's counts (counts_sql in handoff.sh).
336
+ # The space's tabs are read here, once. AGENT_NOW is the last agent's label
337
+ # and how long it has been so, as the list shows them, for the `now:` line
338
+ # of the log of one card. Nothing is worked out without jq, which reads hc's
339
+ # answers, as ocnus's watch on the merges needs it to run.
327
340
  # agents_table <view> <space> <the space's folder>
328
- AGENTS_SQL='agents (card, agent) as (select null, null where 0)'
341
+ AGENTS_SQL='agents (card, agent, ready) as (select null, null, null where 0)'
329
342
  AGENT_NOW=''
330
343
  agents_table() {
331
344
  local view=$1 name=$2 dir=$3 rows sep=$'\x1f' card low step status next since values='' only=''
332
- AGENTS_SQL='agents (card, agent) as (select null, null where 0)' AGENT_NOW=''
345
+ AGENTS_SQL='agents (card, agent, ready) as (select null, null, null where 0)' AGENT_NOW=''
333
346
  [ -n "$view" ] || return 0
334
347
  command -v jq >/dev/null 2>&1 || return 0
335
348
  agents_read "$name" "$dir"
@@ -341,10 +354,13 @@ agents_table() {
341
354
  from shown where after is null $only order by id;") || return 0
342
355
  while IFS=$sep read -r card low step status next since; do
343
356
  [ -n "$card" ] || continue
344
- card_agent "$card" "$low" "$step" "$status" "$next" "$since" "$name" || AGENT_JSON=null
345
- [ "$AGENT_JSON" != null ] || continue
346
- values="$values${values:+, }($(sql_str "$card"), $(sql_str "$AGENT_JSON"))"
347
- AGENT_NOW="$AGENT_LABEL, for $AGENT_FOR"
357
+ card_agent "$card" "$low" "$step" "$status" "$next" "$since" "$name" || AGENT_JSON=null AGENT_READY=0
358
+ if [ "$AGENT_JSON" != null ]; then
359
+ values="$values${values:+, }($(sql_str "$card"), $(sql_str "$AGENT_JSON"), 0)"
360
+ AGENT_NOW="$AGENT_LABEL, for $AGENT_FOR"
361
+ elif [ "$AGENT_READY" = 1 ]; then
362
+ values="$values${values:+, }($(sql_str "$card"), null, 1)"
363
+ fi
348
364
  done <<< "$rows"
349
- [ -z "$values" ] || AGENTS_SQL="agents (card, agent) as (values $values)"
365
+ [ -z "$values" ] || AGENTS_SQL="agents (card, agent, ready) as (values $values)"
350
366
  }
package/cli/lib/github.sh CHANGED
@@ -8,12 +8,18 @@
8
8
  # GitHub is asked once a minute, however many cards wait, in however many
9
9
  # spaces and repos. The call names each worktree's repo, from its origin
10
10
  # (github_repo), and its branch, and asks for that branch's newest pull
11
- # request. Its answer is read by these rules (GITHUB_READ): only the newest
12
- # pull request counts, an open one that GitHub says conflicts with its
13
- # default branch is conflict, and one whose mergeable is still UNKNOWN,
14
- # while GitHub works that out, is open. Asking
15
- # GitHub sits here alone, so that another host, such as GitLab, can sit
16
- # beside it later.
11
+ # request, with whether it can be merged and what its checks came to. Its
12
+ # answer is read by these rules (GITHUB_READ): only the newest pull request
13
+ # counts, an open one that GitHub says conflicts with its default branch is
14
+ # conflict, and one whose mergeable is still UNKNOWN, while GitHub works
15
+ # that out, is open. An open one is ready to merge, ready, when GitHub says
16
+ # that it can be merged, MERGEABLE, and that every check on its newest
17
+ # commit passed: its statusCheckRollup, which sums up its check runs and
18
+ # commit statuses, is SUCCESS, or null, as for a pull request with no
19
+ # checks. It is open while a check is pending, and once one has failed. A
20
+ # review that the repo's rules ask for is not a check, so ready does not say
21
+ # that GitHub would let it merge. Asking GitHub sits here alone, so that
22
+ # another host, such as GitLab, can sit beside it later.
17
23
  #
18
24
  # `gh search prs` asks across repos too, but it cannot say whether an open
19
25
  # pull request is in conflict.
@@ -47,18 +53,24 @@ github_repo() {
47
53
  }
48
54
 
49
55
  # GitHub's answer to github_ask's call, read as one line for each branch it
50
- # asked about, p0 to p<$n - 1>, in order: merged, open, closed or conflict,
51
- # then the pull request's URL; none when the branch has none; or failed and
52
- # GitHub's words when it answered that repo with an error, such as one it
53
- # cannot find. A closed pull request is closed, whatever GitHub says of its
54
- # conflicts. An answer that is empty, or holds no data, is an error, so that
55
- # the whole call counts as failed.
56
+ # asked about, p0 to p<$n - 1>, in order: merged, ready, open, closed or
57
+ # conflict, then the pull request's URL; none when the branch has none; or
58
+ # failed and GitHub's words when it answered that repo with an error, such
59
+ # as one it cannot find. A closed pull request is closed, whatever GitHub
60
+ # says of its conflicts, and an open one is ready only when it can be merged
61
+ # and its checks passed, or it has none. An error that GitHub gives for a
62
+ # pull request's checks alone, as when gh's token may not read them, fails
63
+ # nothing: the pull request is read without them, so an open one is open,
64
+ # never ready, and a merged one is still merged. An answer that is empty, or
65
+ # holds no data, is an error, so that the whole call counts as failed.
56
66
  GITHUB_READ='input
57
67
  | if (.data | type) != "object" then error("no data") else . end
58
68
  | . as $all
59
69
  | ($all.errors // []) as $errors
60
70
  | range(0; $n) | "p\(.)" as $alias
61
- | ([$errors[] | select((.path // [])[0] == $alias) | .message] | first) as $own
71
+ | [$errors[] | select((.path // [])[0] == $alias)] as $mine
72
+ | ([$mine[] | select(any(.path[]; . == "statusCheckRollup") | not) | .message] | first) as $own
73
+ | any($mine[]; any(.path[]; . == "statusCheckRollup")) as $unchecked
62
74
  | $all.data[$alias] as $repo
63
75
  | if $own != null then "failed \($own)"
64
76
  elif $repo == null then "failed \(([$errors[] | .message] | first) // "GitHub gave no answer for it")"
@@ -67,6 +79,8 @@ GITHUB_READ='input
67
79
  elif $pr.state == "MERGED" then "merged \($pr.url)"
68
80
  elif $pr.state == "CLOSED" then "closed \($pr.url)"
69
81
  elif $pr.state == "OPEN" and $pr.mergeable == "CONFLICTING" then "conflict \($pr.url)"
82
+ elif $pr.state == "OPEN" and $pr.mergeable == "MERGEABLE" and ($unchecked | not)
83
+ and ($pr.statusCheckRollup == null or $pr.statusCheckRollup.state == "SUCCESS") then "ready \($pr.url)"
70
84
  else "open \($pr.url)" end
71
85
  end
72
86
  | split("\r") | join(" ") | split("\n") | join(" ")'
@@ -83,11 +97,13 @@ GITHUB_CALL_WHY=''
83
97
  # or in calls of GITHUB_BATCH when more are given. Each line on stdin is a
84
98
  # key, which holds no space, the worktree, and its branch, with the unit
85
99
  # separator between them. It prints a line for each, in the same order:
86
- # <key> merged|open|closed|conflict <the pull request's URL>
100
+ # <key> merged|ready|open|closed|conflict <the pull request's URL>
87
101
  # <key> none the branch has no pull request
88
102
  # <key> failed <the worktree's folder>: <why>
89
- # A call that fails as a whole, such as with GitHub out of reach, fails
90
- # every line it asked about, with gh's words, which GITHUB_CALL_WHY keeps.
103
+ # ready is an open pull request that can be merged and whose checks passed
104
+ # (GITHUB_READ). A call that fails as a whole, such as with GitHub out of
105
+ # reach, fails every line it asked about, with gh's words, which
106
+ # GITHUB_CALL_WHY keeps.
91
107
  # GITHUB_SIGN_IN is 1 then when gh needs signing in: it exits 4 when it has
92
108
  # no sign-in (gh help exit-codes), and names HTTP 401 when GitHub refuses its
93
109
  # token. A repo that GitHub answers with an error fails only its own lines,
@@ -133,7 +149,7 @@ github_ask() {
133
149
  at+=("$i")
134
150
  lines[i]="failed ${wts[i]##*/}: its answer could not be read"
135
151
  vars="$vars, \$o$n: String!, \$n$n: String!, \$b$n: String!"
136
- body="$body p$n: repository(owner: \$o$n, name: \$n$n) { pullRequests(headRefName: \$b$n, states: [OPEN, CLOSED, MERGED], first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { url state mergeable } } }"
152
+ body="$body p$n: repository(owner: \$o$n, name: \$n$n) { pullRequests(headRefName: \$b$n, states: [OPEN, CLOSED, MERGED], first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { url state mergeable statusCheckRollup { state } } } }"
137
153
  args+=(-f "o$n=$owner" -f "n$n=$name" -f "b$n=$branch")
138
154
  n=$((n + 1))
139
155
  done
@@ -343,7 +343,8 @@ merge_linear() {
343
343
  # the merges folder beside the store, merges/.alive, the time its latest pass
344
344
  # began, and merges/<space>/<card>, the time and what that pass saw of the
345
345
  # card's pull requests. They are never rows in the store, and nothing in the
346
- # log reads them but the agent.
346
+ # log reads them but the agent, and the counts in the list's JSON, which mark
347
+ # each card from the same table (counts_sql).
347
348
 
348
349
  # SQL for a number of seconds as text: 50s, 1m 44s, 1h 02m, 3d 04h. @ stands
349
350
  # for the column that holds the seconds.
@@ -413,10 +414,86 @@ log_view() {
413
414
 
414
415
  LOG_USAGE='usage: ocnus task log <space> [<card>] [--json]'
415
416
 
417
+ # The steps a card can stand on, in the order a card goes through them: the
418
+ # seven that the Step counts section in Herdr lists. merged is not one of
419
+ # them: a card whose pull requests have merged stands on no step.
420
+ COUNT_STEPS='define plan breakdown start build review pr'
421
+
422
+ # How many of the space's cards stand on each of COUNT_STEPS, and how each
423
+ # card's agent is doing, for the list's JSON: its counts, which the Step
424
+ # counts section in Herdr draws, holding no rules of its own. It prints the
425
+ # SQL for the table counted (step, nth, count, marks), a row for each step,
426
+ # with nth its place among them. It reads the tables latest, each card's
427
+ # latest row, and agents, what Herdr and ocnus's watch say of each card
428
+ # (agents.sh), so it follows them in the query.
429
+ #
430
+ # A card stands on the step that comes next when its latest hand-off is
431
+ # done, with setup, start's old name, counted as start, and on that
432
+ # hand-off's own step otherwise: the step that asked, was answered or
433
+ # failed. So a card whose next step is merged stands on no step.
434
+ #
435
+ # count is how many cards stand on the step, and marks is a JSON list with a
436
+ # mark for each of them. A card's mark is the first of these that holds:
437
+ # - none, at start: the card is held, approved with its work not started,
438
+ # whatever the agent of its write-up phase is doing
439
+ # - needs-human its agent is blocked on a prompt in its tab
440
+ # - stuck its agent has any other state, as the log says it: it hit
441
+ # an error, stopped without handing off or is not running,
442
+ # or a pull request of the card's is closed, in conflict or
443
+ # unwatched; or its step failed
444
+ # - ready it waits on the human at pr, and ocnus's watch says its
445
+ # pull requests are ready to merge (the agents table's ready)
446
+ # - needs-human it waits on the human
447
+ # - working anything else: its step is under way
448
+ # A step's marks come most urgent first: stuck, needs-human, ready, working.
449
+ counts_sql() {
450
+ local s n=0 steps=''
451
+ for s in $COUNT_STEPS; do
452
+ n=$((n + 1))
453
+ steps="$steps${steps:+, }('$s', $n)"
454
+ done
455
+ printf "steps (step, nth) as (values %s),
456
+ placed as (
457
+ select status, json_extract(agent, '\$.state') as doing, coalesce(ready, 0) as ready,
458
+ case when status = 'done' then case when next = 'setup' then 'start' else next end
459
+ else step end as stand
460
+ from latest left join agents using (card)),
461
+ marked as (
462
+ select stand,
463
+ case when stand = 'start' then null
464
+ when doing = 'blocked' then 'needs-human'
465
+ when doing is not null or status = 'failed' then 'stuck'
466
+ when status = 'needs-human' and stand = 'pr' and ready = 1 then 'ready'
467
+ when status = 'needs-human' then 'needs-human'
468
+ else 'working' end as mark
469
+ from placed),
470
+ counted as (
471
+ select steps.step, nth, (select count(*) from marked where stand = steps.step) as count,
472
+ (select json_group_array(mark) from (
473
+ select mark from marked where stand = steps.step and mark is not null
474
+ order by case mark when 'stuck' then 1 when 'needs-human' then 2 when 'ready' then 3 else 4 end)) as marks
475
+ from steps)" "$steps"
476
+ }
477
+
478
+ # The counts of a space with no card on any step, as the list's JSON gives
479
+ # them, for a machine with no store yet: every step with 0 and no marks. A
480
+ # step's text is its count, and start's how many cards are held.
481
+ counts_none() {
482
+ local s text out=''
483
+ for s in $COUNT_STEPS; do
484
+ text=0
485
+ [ "$s" != start ] || text='0 held'
486
+ out="$out${out:+,}{\"step\":\"$s\",\"count\":0,\"marks\":[],\"text\":\"$text\"}"
487
+ done
488
+ printf '[%s]' "$out"
489
+ }
490
+
416
491
  # The space's cards that have hand-offs, newest first by their latest row:
417
492
  # where each stands and how long it has stood there, or what its agent is
418
493
  # doing when Herdr says it is stuck or has stopped. With --json, the same as
419
- # one line of JSON, with the agent beside where the card stands.
494
+ # one line of JSON, with the agent beside where the card stands, and then
495
+ # counts: the seven steps in order, each with how many cards stand on it, a
496
+ # mark for each card and its text (counts_sql).
420
497
  # log_cards <space> <json: 1 or 0> <view>
421
498
  log_cards() {
422
499
  local name=$1 json=$2 list
@@ -426,17 +503,21 @@ log_cards() {
426
503
  from shown where after is null), $AGENTS_SQL"
427
504
  if [ "$json" = 1 ]; then
428
505
  if [ ! -e "$STORE" ]; then
429
- printf '{"space":"%s","cards":[]}\n' "$(json_str "$name")"
506
+ printf '{"space":"%s","cards":[],"counts":%s}\n' "$(json_str "$name")" "$(counts_none)"
430
507
  return
431
508
  fi
432
- store "$STORE" "$list
509
+ store "$STORE" "$list, $(counts_sql)
433
510
  select json_object('space', $(sql_str "$name"),
434
511
  'cards', (select json_group_array(json(c)) from (
435
512
  select json_object('card', card, 'at', at, 'state', state,
436
513
  'waiting', nullif(waiting, ''), 'for', $(sql_took since), 'seconds', since,
437
514
  'run', run, 'step', step, 'status', status, 'next', next,
438
515
  'agent', json(agent)) as c
439
- from latest left join agents using (card) order by at desc, id desc)));" ||
516
+ from latest left join agents using (card) order by at desc, id desc)),
517
+ 'counts', (select json_group_array(json(c)) from (
518
+ select json_object('step', step, 'count', count, 'marks', json(marks),
519
+ 'text', case when step = 'start' then count || ' held' else '' || count end) as c
520
+ from counted order by nth)));" ||
440
521
  die "could not read the hand-offs in $STORE. It may not be ocnus's store."
441
522
  return
442
523
  fi
package/cli/lib/merges.sh CHANGED
@@ -70,8 +70,9 @@
70
70
  # live terminal hold a name, so there is never more than one watch.
71
71
  #
72
72
  # What it saw is left for `task log`, which says when nothing can see a
73
- # card's pull requests (merges_seen, read by card_agent in agents.sh), and
74
- # for `ocnus status`, which says whether the watch runs (merges_status).
73
+ # card's pull requests, and counts the card as ready to merge once every one
74
+ # of them is open and ready (merges_seen, read by card_agent in agents.sh),
75
+ # and for `ocnus status`, which says whether the watch runs (merges_status).
75
76
  # As a pass begins it writes the time to merges/.alive, and after each card's
76
77
  # turn it writes merges/<space>/<card>: on one line, the time, then what it
77
78
  # saw (merges_saw). A pass whose call to GitHub failed as a whole writes
@@ -429,9 +430,12 @@ merges_tidy() {
429
430
  # What a check of a card's pull requests saw, as MERGES_SAW, for the card's
430
431
  # file: closed and the URL of each closed without merging, as a closed one
431
432
  # comes first; else conflict and each in conflict; else failed and why
432
- # GitHub could not be asked about one; else open while one is open, merged
433
- # once all have, or none when the card has none. It is none too for a card
434
- # the pass did not check, as one whose task is not on this machine.
433
+ # GitHub could not be asked about one; else ready when every pull request of
434
+ # the card is open and ready to merge, as GitHub said of each (GITHUB_READ),
435
+ # or open while one is open and that does not hold, as when another has
436
+ # merged; else merged once all have, or none when the card has none. It is
437
+ # none too for a card the pass did not check, as one whose task is not on
438
+ # this machine.
435
439
  # merges_saw <the check's lines>
436
440
  MERGES_SAW=none
437
441
  merges_saw() {
@@ -445,6 +449,7 @@ merges_saw() {
445
449
  if [ -n "$closed" ]; then MERGES_SAW="closed $closed"
446
450
  elif [ -n "$conflict" ]; then MERGES_SAW="conflict $conflict"
447
451
  elif [ "$CHECK_FAILED" -gt 0 ]; then MERGES_SAW="failed $(plain_note "$CHECK_WHY")"
452
+ elif [ "$CHECK_OPEN" -gt 0 ] && [ "$CHECK_READY" = "$CHECK_OPEN" ] && [ "$CHECK_MERGED" = 0 ]; then MERGES_SAW=ready
448
453
  elif [ "$CHECK_OPEN" -gt 0 ]; then MERGES_SAW=open
449
454
  elif [ "$CHECK_MERGED" -gt 0 ]; then MERGES_SAW=merged
450
455
  else MERGES_SAW=none
@@ -483,8 +488,8 @@ MERGES_NOW='' MERGES_CORE=''
483
488
  # is:
484
489
  # '' ocnus's watch is watching them, or nothing is
485
490
  # known: it ran a pass within MERGES_FRESH seconds and
486
- # saw them open, merged or none, or has not seen the
487
- # card in that time
491
+ # saw them ready, open, merged or none, or has not seen
492
+ # the card in that time
488
493
  # closed, conflict ocnus's watch is running and, within MERGES_FRESH
489
494
  # seconds, saw one closed without merging or in
490
495
  # conflict: MERGES_PULLS are their URLs, a space between
@@ -493,13 +498,15 @@ MERGES_NOW='' MERGES_CORE=''
493
498
  # ocnus's watch has not begun a pass within
494
499
  # MERGES_FRESH seconds, or GitHub could not be asked, as
495
500
  # its last pass saw
496
- # Whether an agent runs to be woken is card_agent's to say.
501
+ # MERGES_READY is 1 when ocnus's watch is running and, within MERGES_FRESH
502
+ # seconds, saw every pull request of the card open and ready to merge, and 0
503
+ # otherwise. Whether an agent runs to be woken is card_agent's to say.
497
504
  # merges_seen <space> <card ID, in upper case>
498
505
  MERGES_FRESH=$((3 * MERGES_PAUSE))
499
- MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY=''
506
+ MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY='' MERGES_READY=0
500
507
  merges_seen() {
501
508
  local space=$1 card=$2 at what rest
502
- MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY=''
509
+ MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY='' MERGES_READY=0
503
510
  MERGES_SEEN=unwatched
504
511
  have_hc || { MERGES_WHY="Herdr's hc not installed"; return 0; }
505
512
  if [ -z "$MERGES_CORE" ]; then
@@ -519,6 +526,7 @@ merges_seen() {
519
526
  case $what in
520
527
  closed | conflict) [ -z "$rest" ] || MERGES_SEEN=$what MERGES_PULLS=$rest ;;
521
528
  failed) MERGES_SEEN=unwatched MERGES_WHY=${rest:-gh failed} ;;
529
+ ready) MERGES_READY=1 ;;
522
530
  esac
523
531
  }
524
532
 
@@ -708,7 +716,9 @@ merge_wake_agent() {
708
716
 
709
717
  # What GitHub said of a card's pull requests, from the card's lines of
710
718
  # github_pulls: a line for each pull request, merged, open, closed or
711
- # conflict, then its URL, and the CHECK_* counts. A branch with no pull request is skipped, since the work
719
+ # conflict, then its URL, and the CHECK_* counts. An open one that GitHub
720
+ # called ready is open here too, and is counted in CHECK_READY as well. A
721
+ # branch with no pull request is skipped, since the work
712
722
  # did not change that repo. One that GitHub could not be asked about is
713
723
  # counted in CHECK_FAILED, with the first why in CHECK_WHY, and said on
714
724
  # stderr; CHECK_SIGN_IN is 1 for it when gh needs signing in.
@@ -716,13 +726,14 @@ merge_wake_agent() {
716
726
  merges_pulls() {
717
727
  local key state rest
718
728
  CHECK_OPEN=0 CHECK_CLOSED=0 CHECK_MERGED=0 CHECK_CONFLICT=0 CHECK_FAILED=0
719
- CHECK_SIGN_IN=0 CHECK_WHY=''
729
+ CHECK_READY=0 CHECK_SIGN_IN=0 CHECK_WHY=''
720
730
  while read -r key state rest; do
721
731
  case $state in
722
732
  merged) CHECK_MERGED=$((CHECK_MERGED + 1)); say "merged $rest" ;;
723
733
  closed) CHECK_CLOSED=$((CHECK_CLOSED + 1)); say "closed $rest" ;;
724
734
  conflict) CHECK_CONFLICT=$((CHECK_CONFLICT + 1)); say "conflict $rest" ;;
725
735
  open) CHECK_OPEN=$((CHECK_OPEN + 1)); say "open $rest" ;;
736
+ ready) CHECK_OPEN=$((CHECK_OPEN + 1)); CHECK_READY=$((CHECK_READY + 1)); say "open $rest" ;;
726
737
  none) ;;
727
738
  *)
728
739
  CHECK_FAILED=$((CHECK_FAILED + 1))
package/herdr/README.md CHANGED
@@ -14,9 +14,10 @@ a layout (a whole-window arrangement of mods).
14
14
  | `mods/ocnus-spaces/` | The Ocnus spaces panel: every space in your config, open or not. Click one to show it; `+` makes a new one. It is not `spaces`, which is Herdr's own list of the spaces it has open. |
15
15
  | `mods/cards/` | The open Linear cards of the space that is showing, under their statuses. Start writes a card up with `task new`; Open shows the tab of a card already started. |
16
16
  | `mods/steps/` | The steps of the card whose tab is selected: what each did, how long it took, and how long it waited on you. With no card's tab selected, the space's cards and where each stands. |
17
+ | `mods/step-counts/` | The Step counts section, right above Usage and about as small: the seven steps, each with a dot for every card of the space that is showing that stands on it, coloured by how the card's agent is doing, and how many there are. See [The Step counts section](#the-step-counts-section). |
17
18
  | `mods/agent-settings/` | The settings button, a cog at the right end of the tab bar, and the popup it opens: the model and effort of each phase profile and dev profile, then the breakdown approval, archiving, the tests setting and billing, each of which a click changes. See [The settings button](#the-settings-button). |
18
19
  | `mods/names/` | Draws nothing. It gives the spaces and tabs the app takes in from herdr-core, for agents started while the app was closed, the names ocnus gave them. See [Writing the card up](#writing-the-card-up). |
19
- | `layouts/default.json` | Herdr's own layout with ocnus's panels: the Ocnus spaces panel, the `ocnus-spaces` mod, in place of Herdr's own list of spaces; the layout dropdown, the Cards and Steps panels, the Usage section, the Memory mod and the CPU mod in the sidebar, with Usage above Memory and CPU, and Memory right above CPU; and the settings button beside the tabs. Herdr's Agents section, its `agents` mod, is not on it. The tab bar is a row of Herdr's `tabs`, `agent-settings` and `names`, in a block 1px wide, since a mod runs only while a layout places it. |
20
+ | `layouts/default.json` | Herdr's own layout with ocnus's panels: the Ocnus spaces panel, the `ocnus-spaces` mod, in place of Herdr's own list of spaces; the layout dropdown, the Cards and Steps panels, the Step counts section, the Usage section, the Memory mod and the CPU mod in the sidebar, with the Step counts right above Usage, Usage above Memory and CPU, and Memory right above CPU; and the settings button beside the tabs. Herdr's Agents section, its `agents` mod, is not on it. The tab bar is a row of Herdr's `tabs`, `agent-settings` and `names`, in a block 1px wide, since a mod runs only while a layout places it. |
20
21
  | `spaces/template/` | The starting `SPACE.md` for every new space. |
21
22
 
22
23
  The skills are in [../skills/](../skills/), outside this folder. They are
@@ -738,7 +739,10 @@ ocnus task log <space> [<card>]
738
739
  every such card in one call, with `gh api graphql`, however many cards wait
739
740
  and in however many spaces and repos (past 100 worktrees, in calls of 100).
740
741
  It names each worktree's repo by its `origin` on GitHub, and only a
741
- branch's newest pull request counts. A
742
+ branch's newest pull request counts. The same call asks whether each can
743
+ be merged and what its checks came to, which is how a pass knows that a
744
+ card is ready to merge (see
745
+ [The Step counts section](#the-step-counts-section)). A
742
746
  repo that GitHub answers with an error, or a worktree whose origin is not on
743
747
  GitHub, leaves only its own card as it is, and `task log` says why. It
744
748
  records the card's merge, as your answer
@@ -861,7 +865,10 @@ ocnus task log <space> [<card>]
861
865
  before. `task log` learns what ocnus's watch saw from the files
862
866
  each pass leaves: `~/.config/ocnus/merges/.alive`, the time its
863
867
  latest pass began, and `~/.config/ocnus/merges/<space>/<card>`, the
864
- time and what it saw of the card's pull requests. Beside them, a pass
868
+ time and what it saw of the card's pull requests: `closed` or `conflict`
869
+ with each such pull request's URL, `failed` and why GitHub could not be
870
+ asked, `ready` once every one of them is open and ready to merge, `open`
871
+ while one is open and that does not hold, `merged`, or `none`. Beside them, a pass
865
872
  whose call to GitHub failed leaves `~/.config/ocnus/merges/.gh`, for
866
873
  `ocnus status`: the time, `sign-in` when `gh` needs signing in or else
867
874
  `failed`, and `gh`'s words. The next pass whose call works, or that asks
@@ -882,7 +889,14 @@ ocnus task log <space> [<card>]
882
889
  when closed), its `label`, `for`, `seconds` and `pulls`: the URLs of the
883
890
  pull requests its label names, an empty list for any state but `closed`
884
891
  and `conflict`. The card's own `state`, `for` and `seconds` keep
885
- their meaning. None of it is stored: it is read from Herdr and those
892
+ their meaning. With no card, `--json` gives `counts` too, beside `cards`:
893
+ the seven steps in order, each with its `step`, its `count`, how many
894
+ cards stand on it, its `marks`, one for each of those cards (`stuck`,
895
+ `needs-human`, `ready` or `working`, most urgent first, and none at
896
+ `start`), and its `text`, the count as the Step counts section shows it,
897
+ such as `2 held` at `start` (see
898
+ [The Step counts section](#the-step-counts-section)). None of it is
899
+ stored: it is read from Herdr and those
886
900
  files each time, and no row or step's time changes with it. With `jq`
887
901
  missing, every card shows as before. With `hc` missing, or with neither
888
902
  herdr-core able to list its terminals nor the app open and able to list
@@ -919,6 +933,86 @@ ocnus task log <space> [<card>]
919
933
  tab opens, closes or is renamed, or one of its terminals reports another
920
934
  status. They also read it again every 6 seconds.
921
935
 
936
+ ### The Step counts section
937
+
938
+ On the `default` layout, the Step counts section sits in the sidebar right
939
+ above Usage, under a line like the one above Usage, and is about as small:
940
+ how many cards are at each step in the space that is showing, and how each
941
+ card's agent is doing, so you can see where the work stands, and what needs
942
+ you, without opening a tab.
943
+
944
+ - **Seven rows, one for each step**, in two columns: `define`, `plan`,
945
+ `breakdown` and `start`, then `build`, `review` and `pr`. A row has a dot
946
+ for each card that stands on its step, and how many there are: `0`, with
947
+ no dots, when there are none.
948
+ - **A card stands where `ocnus task log <space>` has it**: on the step
949
+ that comes next after one that is done, or on the step that is asking
950
+ while it waits on you; and so on the step that was answered, or that
951
+ failed. Each card is counted once. A card whose pull requests have merged
952
+ is on no row, and neither is a card with no hand-offs.
953
+ - **A dot's colour says how its card is doing:**
954
+
955
+ | Colour | The card |
956
+ |---|---|
957
+ | Amber | Needs you: it is waiting on you, or its agent is blocked on a prompt in its tab |
958
+ | Blue | Its agent is working: its step is under way |
959
+ | Green | Is ready to merge, at `pr`: its pull requests are all open, none is in conflict, and every check on them has passed |
960
+ | Red | `task log` says its agent is stuck or has stopped: it hit an error, stopped without handing off or is not running, or a pull request of the card's is closed, in conflict or unwatched. A card whose step failed is red too |
961
+
962
+ The first of these that holds gives the colour: an agent blocked on a
963
+ prompt is amber, whatever else holds; any other state `task log` gives
964
+ the agent (see [Hand-offs](#hand-offs)), or a step that failed, is red; a
965
+ card waiting on you is green when it is ready to merge and amber
966
+ otherwise; and anything else is blue. A row's dots come most urgent
967
+ first: red, amber, green, then blue.
968
+ - **Green takes the place of amber at `pr`.** A card whose pull requests
969
+ wait on you to merge them is amber until they are ready, and green once
970
+ they are. ocnus's watch on the merges asks GitHub about them once a
971
+ minute, so a card turns green within about a minute of its last check
972
+ passing, and amber again within a minute of a new commit whose checks are
973
+ running. A pull request with no checks, as in a repo that has none, has
974
+ nothing to wait for and counts as passed. A review that the repo's rules
975
+ ask for is not a check, so green does not say that GitHub will let you
976
+ merge. The card is amber while a check is running or has failed, while
977
+ GitHub has not yet said whether a pull request can be merged, once one of
978
+ several has merged, and when the watch has not seen the card in the last 3
979
+ minutes. It stays amber, too, when GitHub will not say what a pull
980
+ request's checks came to, as when `gh`'s token may not read them.
981
+ - **`start` has no dots**, since no agent runs that step. Its row says how
982
+ many cards are held there, as `2 held`: approved, with their work not yet
983
+ started. `task start` has recorded no start for them, as while a card that
984
+ blocks one is not done yet (see [Starting the work](#starting-the-work)).
985
+ Once it records the start, the card is on `build`.
986
+ - **A row with more dots than fit** shows the ones that fit and `+N` for the
987
+ rest. Its count still says how many there are in all.
988
+ - **It updates on its own** while Herdr's window is visible, with no click
989
+ or restart. It looks at Herdr's tabs in the space every 2 seconds, and
990
+ reads the counts again as soon as a tab opens, closes or is renamed, or
991
+ one of its terminals reports another status: a change in an agent's state
992
+ shows within 5 seconds, as in the Cards and Steps panels. It also reads
993
+ them again every 6 seconds, so a card's move to another step shows within
994
+ 10.
995
+ - **One line stands in place of the rows** when the space that is showing is
996
+ not an ocnus space, when the counts cannot be read, in which case it is
997
+ what `ocnus` said, and when the `ocnus` on the machine is too old to give
998
+ them. A read that failed is tried again. The rest of the sidebar works as
999
+ before. On the sidebar's rail, the section draws only its line.
1000
+ - **It works nothing out itself.** It draws the `counts` that
1001
+ `ocnus task log <space> --json` prints, so the section and `task log`
1002
+ always agree. When `ocnus` is not on Herdr's `PATH`, it runs the copy the
1003
+ mod is linked from. Each entry of `counts` is a step: its name, how many
1004
+ cards stand on it, a mark for each of them, and the text to show:
1005
+
1006
+ ```
1007
+ "counts":[{"step":"define","count":0,"marks":[],"text":"0"},…,{"step":"start","count":2,"marks":[],"text":"2 held"},{"step":"build","count":3,"marks":["stuck","needs-human","working"],"text":"3"},…]
1008
+ ```
1009
+
1010
+ A mark is `stuck`, which shows red, `needs-human`, amber, `ready`, green,
1011
+ or `working`, blue.
1012
+ - **It needs `jq` to say how an agent is doing.** Without it, `task log`
1013
+ reads no agent and no pull request, so a card is amber when it waits on
1014
+ you, red when its step failed, and blue otherwise.
1015
+
922
1016
  ### Starting the work
923
1017
 
924
1018
  One branch for an approved card, checked out as a git worktree of the repos
@@ -70,6 +70,16 @@
70
70
  }
71
71
  ]
72
72
  },
73
+ {
74
+ "id": "step-counts",
75
+ "type": "block",
76
+ "size": {
77
+ "px": 72
78
+ },
79
+ "content": {
80
+ "mod": "step-counts"
81
+ }
82
+ },
73
83
  {
74
84
  "id": "usage",
75
85
  "type": "block",
@@ -0,0 +1,281 @@
1
+ // The Step counts section: how many cards are at each step, in the ocnus
2
+ // space that is showing, and how each card's agent is doing. It sits above
3
+ // Usage in the default layout's sidebar, and is about as small.
4
+ //
5
+ // All of that is worked out by `ocnus task log <space> --json`, whose
6
+ // `counts` are the steps in order, each with how many cards are on it, a mark
7
+ // for each of those cards and the text to show at its right. This mod draws
8
+ // those counts and holds no rules about hand-offs, steps or agents: where a
9
+ // card stands, what its mark is and what a step's text says all arrive from
10
+ // the command. What is its own is the drawing: a dot of its colour for each
11
+ // mark, as many dots as fit in the row, and "+N" for the rest.
12
+ import { View, div } from "gpui-kit";
13
+ import { v_flex, h_flex } from "gpui-base";
14
+ import { exec, spaces, panes, terminals, theme, layout, window, checking, appHome, settings } from "herdr";
15
+
16
+ // How often to see whether another space is showing, or Herdr's tabs have
17
+ // changed. A change in them is read at once, so an agent's state shows within
18
+ // this and a read.
19
+ const LOOK_MS = 2000;
20
+ const REREAD_MS = 6000; // how often to read the counts again
21
+ const SPACES_MS = 60000; // spaces change rarely
22
+ const TIMEOUT_MS = 10000;
23
+ // How this mod's own link into the repo that ships it ends.
24
+ const LINKED_AT = "/herdr/mods/step-counts";
25
+
26
+ const LEFT = 4; // the steps in the left column; the rest are in the right one
27
+ const COLUMN_GAP = 12;
28
+ const NAME_CH = 6.6; // px a letter of a step's name takes, to line a column's dots up
29
+ const DOT = 6; // px across a mark's dot
30
+ const DOT_GAP = 3;
31
+ const MORE_CH = 7; // px kept for each character of "+N"
32
+ const ROOM = 36; // px a row's dots are taken to have, until the row is measured
33
+
34
+ // The colour of each mark's dot: red for a card whose agent is stuck or has
35
+ // stopped, amber for one that needs the human, green for one that is ready to
36
+ // merge, and blue for one whose agent is working.
37
+ const colors = (t) => ({ stuck: t.ansi1, "needs-human": t.ansi3, ready: t.ansi2, working: t.ansi4 });
38
+
39
+ // `herdr-app check` draws the mod once, with nothing read, which would show
40
+ // one line of text and none of the rows. It is given these to draw, so a
41
+ // mistake in a row fails the check: every mark, a row with more dots than
42
+ // fit, a row with none, and a count of cards that are held. It draws a line
43
+ // under them too, as one stands in place of the rows.
44
+ const SAMPLE = {
45
+ space: "demo",
46
+ counts: [
47
+ { step: "define", count: 1, marks: ["working"], text: "1" },
48
+ { step: "plan", count: 0, marks: [], text: "0" },
49
+ { step: "breakdown", count: 1, marks: ["needs-human"], text: "1" },
50
+ { step: "start", count: 2, marks: [], text: "2 held" },
51
+ { step: "build", count: 12, text: "12",
52
+ marks: ["stuck", "needs-human", "needs-human", "working", "working", "working", "working", "working",
53
+ "working", "working", "working", "working"] },
54
+ { step: "review", count: 2, marks: ["needs-human", "working"], text: "2" },
55
+ { step: "pr", count: 3, marks: ["stuck", "needs-human", "ready"], text: "3" },
56
+ ],
57
+ };
58
+
59
+ function find(node, id) {
60
+ if (node?.id === id) return node;
61
+ for (const child of node?.children ?? []) {
62
+ const found = find(child, id);
63
+ if (found) return found;
64
+ }
65
+ return null;
66
+ }
67
+
68
+ // The sidebar's rail goes by its width, as in Herdr's own lists.
69
+ const narrow = () => (find(layout(), "sidebar")?.size?.px ?? Infinity) < 160;
70
+
71
+ function parse(text) {
72
+ try {
73
+ return JSON.parse(text);
74
+ } catch {
75
+ return null;
76
+ }
77
+ }
78
+
79
+ // What Herdr shows of the tabs in the spaces whose folder is `folder`, on
80
+ // this computer: each tab's id and name, and each of its terminals' status
81
+ // and app. `task log` works out each card's mark from these, so a change in
82
+ // them is read at once. A pane's status has no word for hc's error, so each
83
+ // terminal's own word, from terminals(), is in it too.
84
+ function herdrSees(folder) {
85
+ if (folder === null) return "";
86
+ const word = new Map(terminals().map((t) => [t.address, t.status ?? null]));
87
+ const tabs = new Set();
88
+ const seen = [];
89
+ for (const space of spaces()) {
90
+ if (space.machine || space.folder !== folder) continue;
91
+ for (const tab of space.tabs) {
92
+ tabs.add(tab.id);
93
+ seen.push([tab.id, tab.name]);
94
+ }
95
+ }
96
+ for (const p of panes()) {
97
+ if (p.terminal && tabs.has(p.tab)) seen.push([p.tab, p.terminal, p.status, p.app, word.get(p.terminal) ?? null]);
98
+ }
99
+ return JSON.stringify(seen);
100
+ }
101
+
102
+ // What a failed command said, without the name it starts its errors with.
103
+ const said = (r) => (r.stderr || r.stdout).trim().replace(/^ocnus: /, "");
104
+
105
+ const OLD_CLI = "This ocnus is too old for the step counts. Run: ocnus update";
106
+ const NOT_OCNUS = "This space is not an ocnus space.";
107
+ // An ocnus from before --json answers with its usage line, not JSON, and
108
+ // one from before the list of cards asks which card.
109
+ const failure = (r, what) => {
110
+ const text = said(r);
111
+ return text.startsWith("usage:") || text.startsWith("which card?") ? OLD_CLI : text || `${what} failed`;
112
+ };
113
+
114
+ // The folder of the space that is showing on this computer, or null.
115
+ const selected = () => spaces().find((s) => s.active && !s.machine)?.folder ?? null;
116
+
117
+ // How many dots to draw for a row of `marks` marks in `room` px: all of
118
+ // them when they fit, and else as many as fit beside the "+N" that stands
119
+ // for the rest.
120
+ function fit(marks, room) {
121
+ const wide = (n) => n * DOT + Math.max(0, n - 1) * DOT_GAP;
122
+ if (wide(marks) <= room) return marks;
123
+ for (let n = marks - 1; n > 0; n--) {
124
+ const more = (String(marks - n).length + 1) * MORE_CH;
125
+ if (wide(n) + DOT_GAP + more <= room) return n;
126
+ }
127
+ return 0;
128
+ }
129
+
130
+ export default class StepCounts extends View {
131
+ init(_props, cx) {
132
+ this.cmd = "ocnus"; // the one on PATH, until that cannot start
133
+ this.listed = null; // the spaces ocnus listed last
134
+ this.listedAt = 0;
135
+ this.key = null; // the folder that the counts on hand were read for
136
+ this.space = null; // the ocnus space the shown Herdr space is, or null
137
+ this.counts = null; // the counts read last
138
+ this.error = null;
139
+ this.busy = false;
140
+ this.readAt = 0;
141
+ this.seen = null; // what Herdr showed of the space's tabs when it was read
142
+ this.drawn = null; // what the last redraw showed, to redraw only on a change
143
+ this.room = {}; // the px each row has for its dots, as measured, by the row's place
144
+ if (checking()) return;
145
+ cx.timer.every(LOOK_MS, (cx) => this.look(cx));
146
+ this.look(cx);
147
+ }
148
+
149
+ // Runs the ocnus command. One that cannot run is tried again as the
150
+ // copy this mod is linked from: Herdr may have been started without the
151
+ // user's PATH. Everything this mod runs only reads, so twice is safe.
152
+ async ocnus(args) {
153
+ try {
154
+ return await exec(this.cmd, args, { timeout: TIMEOUT_MS });
155
+ } catch (e) {
156
+ if (this.cmd !== "ocnus") throw e;
157
+ const link = await exec("readlink", [`${appHome()}/mods/step-counts`]);
158
+ const at = link.stdout.trim();
159
+ if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
160
+ this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/ocnus`;
161
+ return exec(this.cmd, args, { timeout: TIMEOUT_MS });
162
+ }
163
+ }
164
+
165
+ // Read the counts again when another space is showing, when Herdr's tabs
166
+ // in the space have changed, or when what is on hand is stale: so does a
167
+ // read that failed, which is tried again. A space that is not an ocnus
168
+ // space is looked up again only as often as the spaces are listed. Nothing
169
+ // is read while nobody can see the section.
170
+ look(cx) {
171
+ if (this.busy || window()?.visible === false || narrow()) return;
172
+ const folder = selected();
173
+ const key = folder ?? "";
174
+ const seen = herdrSees(folder);
175
+ const stale = this.space || this.error
176
+ ? Date.now() - this.readAt >= REREAD_MS || seen !== this.seen
177
+ : Date.now() - this.readAt >= SPACES_MS;
178
+ if (key === this.key && !stale) return;
179
+ this.busy = true;
180
+ cx.spawn(async (cx) => {
181
+ let space = null;
182
+ let counts = null;
183
+ let error = null;
184
+ try {
185
+ if (!this.listed || Date.now() - this.listedAt >= SPACES_MS) {
186
+ const r = await this.ocnus(["space", "ls", "--json"]);
187
+ const list = r.code === 0 ? parse(r.stdout)?.spaces : null;
188
+ if (Array.isArray(list)) {
189
+ this.listed = list;
190
+ this.listedAt = Date.now();
191
+ } else {
192
+ error = r.code === 0 ? OLD_CLI : failure(r, "ocnus space ls");
193
+ }
194
+ }
195
+ space = (this.listed ?? []).find((s) => s.folder === folder)?.name ?? null;
196
+ if (!error && space) {
197
+ const r = await this.ocnus(["task", "log", space, "--json"]);
198
+ const got = r.code === 0 ? parse(r.stdout) : null;
199
+ // An ocnus from before the counts gives the list without them.
200
+ if (Array.isArray(got?.counts)) counts = got.counts;
201
+ else error = r.code === 0 ? OLD_CLI : failure(r, "ocnus task log");
202
+ }
203
+ } catch (e) {
204
+ error = `Could not run ocnus: ${e?.message ?? e}`;
205
+ }
206
+ this.key = key;
207
+ this.space = space;
208
+ this.counts = counts;
209
+ this.error = error;
210
+ this.readAt = Date.now();
211
+ this.seen = seen;
212
+ this.busy = false;
213
+ // A redraw of a mod redraws the whole window, so only when what it
214
+ // shows has changed.
215
+ const drawn = JSON.stringify([key, space, counts, error]);
216
+ if (drawn !== this.drawn) {
217
+ this.drawn = drawn;
218
+ cx.notify();
219
+ }
220
+ // A space chosen while this was being read is read now, not at the
221
+ // next look.
222
+ if ((selected() ?? "") !== key) this.look(cx);
223
+ });
224
+ }
225
+
226
+ // One step, on one line: its name, a dot for each of its cards, as many as
227
+ // fit, with "+N" for the rest, and its text at the right. `i` is its place
228
+ // among the steps, and `name` the px its column gives a name.
229
+ row(c, i, t, name) {
230
+ const marks = Array.isArray(c.marks) ? c.marks : [];
231
+ const color = colors(t);
232
+ const shown = fit(marks.length, this.room[i] ?? ROOM);
233
+ const rest = marks.length - shown;
234
+ return h_flex().flex_none().gap(6).items_center()
235
+ .child(div().flex_none().min_w(name).text_color(t.muted).child(String(c.step ?? "")))
236
+ .child(h_flex().id(`dots-${i}`).flex_1().min_w(0).gap(DOT_GAP).items_center().overflow_hidden()
237
+ // The room the dots have, measured. The size is in window px.
238
+ .on_size_change((size, cx) => {
239
+ const room = size.width / (Number(settings().zoom) || 1);
240
+ const was = this.room[i] ?? ROOM;
241
+ this.room[i] = room;
242
+ if (fit(marks.length, room) !== fit(marks.length, was)) cx.notify();
243
+ })
244
+ .children(marks.slice(0, shown).map((m) =>
245
+ div().flex_none().size(DOT).rounded(DOT / 2).bg(color[m] ?? t.dim)))
246
+ .when(rest > 0, (el) => el.child(div().flex_none().text_color(t.dim).child(`+${rest}`))))
247
+ .child(div().flex_none().text_color(c.count > 0 ? t.foreground : t.dim).child(String(c.text ?? "")));
248
+ }
249
+
250
+ render() {
251
+ const t = theme();
252
+ // The block and the line above it, as Usage and CPU have theirs.
253
+ const block = () => v_flex().size_full().bg(t.chrome).border_t(1).border_color(t.border);
254
+ // The sidebar's rail has room for the line alone.
255
+ if (narrow()) return block();
256
+ const sample = checking();
257
+ const counts = (sample ? SAMPLE.counts : this.counts) ?? [];
258
+ // A column of rows, with the room for a name that its longest one needs.
259
+ const column = (from, to) => {
260
+ const rows = counts.slice(from, to);
261
+ const name = Math.ceil(Math.max(0, ...rows.map((c) => String(c.step ?? "").length)) * NAME_CH);
262
+ return v_flex().flex_1().min_w(0).overflow_hidden()
263
+ .children(rows.map((c, i) => this.row(c, from + i, t, name)));
264
+ };
265
+ const rows = () => h_flex().flex_none().gap(COLUMN_GAP).items_start()
266
+ .child(column(0, LEFT))
267
+ .child(column(LEFT, counts.length));
268
+ // The one line that stands in place of the rows.
269
+ const line = (text, color) => div().flex_none().text_color(color).whitespace_normal().child(text);
270
+ let body;
271
+ if (sample) body = [rows(), line(NOT_OCNUS, t.dim)];
272
+ else if ((selected() ?? "") !== this.key) body = [line("Reading…", t.dim)];
273
+ else if (this.error) body = [line(this.error, t.blocked)];
274
+ else if (!this.space) body = [line(NOT_OCNUS, t.dim)];
275
+ else body = [rows()];
276
+ // A line height of its own, so that the four rows of the left column fit
277
+ // the 72px the layout gives the section, whatever the default is.
278
+ return block().px(14).py(6).justify_center().line_height(1.25).overflow_hidden().text_size(11)
279
+ .children(body);
280
+ }
281
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "Step counts" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngaynor/ocnus",
3
- "version": "2.0.1-next.24",
3
+ "version": "2.0.1-next.27",
4
4
  "description": "A software factory: agent skills and the Herdr setup to run them, installed with one command.",
5
5
  "license": "MIT",
6
6
  "bin": {