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

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
@@ -100,9 +100,10 @@ its own layout, which has no Layout dropdown, so the first switch is
100
100
  a block of its own, so that you can see each one working before you choose
101
101
  what to put in a layout of your own. `vibe` is three columns for steering
102
102
  every agent without reading code, with no files, diffs or split terminals,
103
- and the dropdown again, to come back to `default`. The `layouts/vibe.json`
104
- row in [herdr/README.md](herdr/README.md#whats-here) says what each column
105
- holds.
103
+ and the dropdown again, to come back to `default`. Its middle column starts
104
+ with the card list, the cards that are running and every open card of the
105
+ space that is showing. The `layouts/vibe.json` row in
106
+ [herdr/README.md](herdr/README.md#whats-here) says what each column holds.
106
107
 
107
108
  In a terminal, `ocnus install` and `ocnus help`, which `ocnus` with no
108
109
  command is too, open with a banner: OCNUS in block letters beside Ocnus on
@@ -651,6 +652,19 @@ not yet started. The section draws what `task log <space> --json` counts,
651
652
  and updates on its own. See
652
653
  [herdr/README.md](herdr/README.md#the-step-counts-section).
653
654
 
655
+ On the `vibe` layout, the card list, at the top of the middle column, shows
656
+ the cards of the space that is showing in two views. Agents lists the cards
657
+ that are running, those whose tab ocnus opened is open with their phase
658
+ still going on, the ones that need you first: Stuck, then Permission,
659
+ Approve? and Asking, then Merge?, then Working. Each row has the card's
660
+ parent, a bar for its seven steps, its status, how long it has been so and
661
+ the tokens its agents have used. Linear lists every open card under its
662
+ parent card, with Start for a card not approved yet, Held and what it waits
663
+ on for one that is held, and the rest as `task log` has them. A click on a
664
+ running card opens its agent on the right. It draws what `task ls` and
665
+ `task log` give, and updates on its own. See
666
+ [herdr/README.md](herdr/README.md#the-card-list).
667
+
654
668
  `task asks` lists every question that waits on you in a space, oldest first,
655
669
  so that you, or a board, can see what each agent is asking without opening
656
670
  its tab:
package/cli/lib/agents.sh CHANGED
@@ -59,6 +59,12 @@
59
59
  # neither place can list the space's tabs: herdr-core cannot list its
60
60
  # terminals, and the app is not running or `herdr-app ls` fails. With no
61
61
  # tab to look in, no agent is running then.
62
+ # - What was seen in the card's tab is kept beside its agent state, as
63
+ # seen, whether or not the agent has anything to say: closed when the
64
+ # tab is not open, or when it was not looked for, as with no tab to look
65
+ # in. It is not an agent state either: the list's JSON reads it to say
66
+ # whether the card is running, as the card list in Herdr shows it
67
+ # (cards_sql in handoff.sh).
62
68
 
63
69
  # The seconds after a start row in which the agent is still starting.
64
70
  AGENT_START_GRACE=15
@@ -232,12 +238,14 @@ card_seen() {
232
238
  # AGENT_READY is 1 for a card ready to merge: its pull requests wait on the
233
239
  # human, it has no agent state, and ocnus's watch says they are ready
234
240
  # (merges_seen). It is 0 for any other card, and AGENT_JSON is null with it.
241
+ # AGENT_SEEN is left as card_seen saw the card's tab, and is closed when it
242
+ # did not look, whatever AGENT_JSON is.
235
243
  # card_agent <card> <the card in lower case> <step> <status> <next>
236
244
  # <seconds since the hand-off> <space>
237
245
  AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0
238
246
  card_agent() {
239
247
  local card=$1 low=$2 step=$3 status=$4 next=$5 since=$6 space=$7
240
- AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0
248
+ AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0 AGENT_SEEN=closed
241
249
  # Its pull requests wait on the human.
242
250
  local waits=0
243
251
  [ "$step $status" != 'pr needs-human' ] || waits=1
@@ -329,20 +337,24 @@ card_agent() {
329
337
  }
330
338
 
331
339
  # Work out the agent of every card in a view of the log, as AGENTS_SQL: the
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).
340
+ # SQL for the table agents (card, agent, ready, seen) that the log's query
341
+ # joins, with each card whose agent has something to say and its JSON, with
342
+ # ready 0; each card ready to merge, which has no agent state: its agent is
343
+ # null and its ready 1, for the list's counts (counts_sql in handoff.sh); and
344
+ # each other card whose tab is open, with its agent null and its ready 0.
345
+ # seen is what card_seen saw in the card's tab, closed when it is not open,
346
+ # for whether the card is running (cards_sql in handoff.sh). A card with no
347
+ # row has no agent state, and its tab is closed.
336
348
  # The space's tabs are read here, once. AGENT_NOW is the last agent's label
337
349
  # and how long it has been so, as the list shows them, for the `now:` line
338
350
  # of the log of one card. Nothing is worked out without jq, which reads hc's
339
351
  # answers, as ocnus's watch on the merges needs it to run.
340
352
  # agents_table <view> <space> <the space's folder>
341
- AGENTS_SQL='agents (card, agent, ready) as (select null, null, null where 0)'
353
+ AGENTS_SQL='agents (card, agent, ready, seen) as (select null, null, null, null where 0)'
342
354
  AGENT_NOW=''
343
355
  agents_table() {
344
356
  local view=$1 name=$2 dir=$3 rows sep=$'\x1f' card low step status next since values='' only=''
345
- AGENTS_SQL='agents (card, agent, ready) as (select null, null, null where 0)' AGENT_NOW=''
357
+ AGENTS_SQL='agents (card, agent, ready, seen) as (select null, null, null, null where 0)' AGENT_NOW=''
346
358
  [ -n "$view" ] || return 0
347
359
  command -v jq >/dev/null 2>&1 || return 0
348
360
  agents_read "$name" "$dir"
@@ -354,13 +366,14 @@ agents_table() {
354
366
  from shown where after is null $only order by id;") || return 0
355
367
  while IFS=$sep read -r card low step status next since; do
356
368
  [ -n "$card" ] || continue
357
- card_agent "$card" "$low" "$step" "$status" "$next" "$since" "$name" || AGENT_JSON=null AGENT_READY=0
369
+ card_agent "$card" "$low" "$step" "$status" "$next" "$since" "$name" ||
370
+ AGENT_JSON=null AGENT_READY=0 AGENT_SEEN=closed
358
371
  if [ "$AGENT_JSON" != null ]; then
359
- values="$values${values:+, }($(sql_str "$card"), $(sql_str "$AGENT_JSON"), 0)"
372
+ values="$values${values:+, }($(sql_str "$card"), $(sql_str "$AGENT_JSON"), 0, $(sql_str "$AGENT_SEEN"))"
360
373
  AGENT_NOW="$AGENT_LABEL, for $AGENT_FOR"
361
- elif [ "$AGENT_READY" = 1 ]; then
362
- values="$values${values:+, }($(sql_str "$card"), null, 1)"
374
+ elif [ "$AGENT_READY" = 1 ] || [ "$AGENT_SEEN" != closed ]; then
375
+ values="$values${values:+, }($(sql_str "$card"), null, $AGENT_READY, $(sql_str "$AGENT_SEEN"))"
363
376
  fi
364
377
  done <<< "$rows"
365
- [ -z "$values" ] || AGENTS_SQL="agents (card, agent, ready) as (values $values)"
378
+ [ -z "$values" ] || AGENTS_SQL="agents (card, agent, ready, seen) as (values $values)"
366
379
  }
package/cli/lib/asks.sh CHANGED
@@ -280,6 +280,19 @@ ask_kind() {
280
280
  esac
281
281
  }
282
282
 
283
+ # The same kind as SQL, for the list's JSON (cards_sql, in handoff.sh): merge,
284
+ # approval or choice, from the columns that hold the hand-off's step and its
285
+ # options. The first option is the text before the first " | ", without the
286
+ # spaces around it, as ask_kind takes it, and GLOB, unlike LIKE, minds the
287
+ # case, as `case` does. A change to one is a change to both.
288
+ # ask_kind_sql <step column> <options column>
289
+ ask_kind_sql() {
290
+ local first="trim(substr($2, 1, instr($2 || ' | ', ' | ') - 1))"
291
+ printf "case when %s = 'pr' and %s = 'merged' then 'merge'
292
+ when %s = 'breakdown' and %s glob 'approve*' then 'approval' else 'choice' end" \
293
+ "$1" "$first" "$1" "$first"
294
+ }
295
+
283
296
  # The links of the open pull requests of a card that waits on its merge, a
284
297
  # line each: the ones ocnus's watch on the merges last saw open, one in
285
298
  # conflict among them, from the card's .pulls file (merges_check, in
@@ -447,18 +447,28 @@ log_read() {
447
447
  # them: a card whose pull requests have merged stands on no step.
448
448
  COUNT_STEPS='define plan breakdown start build review pr'
449
449
 
450
+ # SQL for the step a card stands on, from the columns of its latest hand-off:
451
+ # the step that comes next when that hand-off is done, with setup, start's
452
+ # old name, counted as start, and that hand-off's own step otherwise: the
453
+ # step that asked, was answered or failed. A card whose next step is merged
454
+ # stands on no step, and this is null for it. The counts and the card list
455
+ # both place a card by it, as the column stand of the table latest
456
+ # (log_cards), so a card's dot in the Step counts section and its row in the
457
+ # card list are on the same step.
458
+ stand_sql() {
459
+ printf '%s' "case when status = 'done'
460
+ then case next when 'setup' then 'start' when 'merged' then null else next end
461
+ else step end"
462
+ }
463
+
450
464
  # How many of the space's cards stand on each of COUNT_STEPS, and how each
451
465
  # card's agent is doing, for the list's JSON: its counts, which the Step
452
466
  # counts section in Herdr draws, holding no rules of its own. It prints the
453
467
  # SQL for the table counted (step, nth, count, marks), a row for each step,
454
468
  # with nth its place among them. It reads the tables latest, each card's
455
- # latest row, and agents, what Herdr and ocnus's watch say of each card
456
- # (agents.sh), so it follows them in the query.
457
- #
458
- # A card stands on the step that comes next when its latest hand-off is
459
- # done, with setup, start's old name, counted as start, and on that
460
- # hand-off's own step otherwise: the step that asked, was answered or
461
- # failed. So a card whose next step is merged stands on no step.
469
+ # latest row with the step it stands on (stand_sql), and agents, what Herdr
470
+ # and ocnus's watch say of each card (agents.sh), so it follows them in the
471
+ # query. A card whose next step is merged stands on no step.
462
472
  #
463
473
  # count is how many cards stand on the step, and marks is a JSON list with a
464
474
  # mark for each of them. A card's mark is the first of these that holds:
@@ -482,9 +492,7 @@ counts_sql() {
482
492
  done
483
493
  printf "steps (step, nth) as (values %s),
484
494
  placed as (
485
- select status, json_extract(agent, '\$.state') as doing, coalesce(ready, 0) as ready,
486
- case when status = 'done' then case when next = 'setup' then 'start' else next end
487
- else step end as stand
495
+ select status, json_extract(agent, '\$.state') as doing, coalesce(ready, 0) as ready, stand
488
496
  from latest left join agents using (card)),
489
497
  marked as (
490
498
  select stand,
@@ -516,36 +524,97 @@ counts_none() {
516
524
  printf '[%s]' "$out"
517
525
  }
518
526
 
527
+ # What the card list in Herdr shows of each card, for the list's JSON: SQL
528
+ # for the table shows (card, stand, running, word, mark, need), a row for
529
+ # each card. It reads the tables latest and agents, as counts_sql does, and
530
+ # the card list draws it, holding no rules of its own.
531
+ #
532
+ # stand is the step the card stands on (stand_sql). running is 1 while a tab
533
+ # ocnus opened for the card is open for the phase going on: the tab its
534
+ # agent is looked for in (card_seen, in agents.sh), the write-up tab until
535
+ # the work starts and then the task's tab, is open (the agents table's seen
536
+ # is not closed), and the card stands on a step, so not once it has merged.
537
+ # At start the card is approved, and its write-up agent's turn there is over
538
+ # but for the `task start` it runs, so only an agent working, blocked or with
539
+ # an error counts there.
540
+ #
541
+ # word is the card's status in the list, the first of these that holds, with
542
+ # its mark, the colour the counts give it, and its need, its place in the
543
+ # order of need, from 0, the most urgent:
544
+ # Stuck stuck 0 its agent has any state but blocked, as the
545
+ # log says it, or its step failed
546
+ # Permission needs-human 1 its agent is blocked on a permission prompt
547
+ # Approve? needs-human 1 breakdown asks the human to approve the card
548
+ # Asking needs-human 1 its agent is blocked otherwise, or it asks
549
+ # any other question but for the merge
550
+ # Merge? needs-human 2 its pull requests wait on the human to merge
551
+ # or ready them: ready once ocnus's watch says they
552
+ # are ready (the agents table's ready)
553
+ # Working working 3 it is running
554
+ # A card none of these holds for is not running, and its word, mark and need
555
+ # are null. An approval and a merge are told as `task asks` tells them
556
+ # (ask_kind_sql, in asks.sh).
557
+ cards_sql() {
558
+ printf "shows as (
559
+ select card, stand, running, word,
560
+ case when word is null then null when word = 'Stuck' then 'stuck'
561
+ when word = 'Working' then 'working' when word = 'Merge?' and ready = 1 then 'ready'
562
+ else 'needs-human' end as mark,
563
+ case word when 'Stuck' then 0 when 'Permission' then 1 when 'Approve?' then 1
564
+ when 'Asking' then 1 when 'Merge?' then 2 when 'Working' then 3 end as need
565
+ from (
566
+ select *,
567
+ case when (doing is not null and doing <> 'blocked') or status = 'failed' then 'Stuck'
568
+ when doing = 'blocked' and prompt = 'permission' then 'Permission'
569
+ when asked = 'approval' then 'Approve?'
570
+ when doing = 'blocked' or asked = 'choice' then 'Asking'
571
+ when asked = 'merge' then 'Merge?'
572
+ when running then 'Working' end as word
573
+ from (
574
+ select latest.card as card, stand, status, coalesce(ready, 0) as ready,
575
+ json_extract(agent, '\$.state') as doing, json_extract(agent, '\$.kind') as prompt,
576
+ case when status = 'needs-human' then %s end as asked,
577
+ coalesce(seen, 'closed') <> 'closed' and stand is not null
578
+ and (stand <> 'start' or seen in ('working', 'blocked', 'error')) as running
579
+ from latest left join agents using (card))))" "$(ask_kind_sql step options)"
580
+ }
581
+
519
582
  # The space's cards that have hand-offs, newest first by their latest row:
520
583
  # where each stands and how long it has stood there, or what its agent is
521
584
  # doing when Herdr says it is stuck or has stopped, then what the card's
522
585
  # agents have used in all, or that it is not recorded. With --json, the same
523
586
  # as one line of JSON, with the agent beside where the card stands, and the
524
587
  # card's total as tokens and cost, each null when nothing is recorded, and
525
- # partial, true when a step of the card is not recorded; and then counts:
526
- # the seven steps in order, each with how many cards stand on it, a mark for
527
- # each card and its text (counts_sql).
588
+ # partial, true when a step of the card is not recorded; what the card list
589
+ # in Herdr shows of it, its stand, running, word, mark and need (cards_sql);
590
+ # and then counts: the seven steps in order, each with how many cards stand
591
+ # on it, a mark for each card and its text (counts_sql).
528
592
  # log_cards <space> <json: 1 or 0> <view>
529
593
  log_cards() {
530
594
  local name=$1 json=$2 list
531
- # Each card's latest row is the one with nothing after it.
595
+ # Each card's latest row is the one with nothing after it, with the step
596
+ # the card stands on.
532
597
  list="$3, latest as (
533
- select *, max(cast(strftime('%s', 'now') - strftime('%s', at) as integer), 0) as since
598
+ select *, max(cast(strftime('%s', 'now') - strftime('%s', at) as integer), 0) as since,
599
+ $(stand_sql) as stand
534
600
  from shown where after is null), $AGENTS_SQL"
535
601
  if [ "$json" = 1 ]; then
536
602
  if [ ! -e "$STORE" ]; then
537
603
  printf '{"space":"%s","cards":[],"counts":%s}\n' "$(json_str "$name")" "$(counts_none)"
538
604
  return
539
605
  fi
540
- log_read "$name" "$list, $(counts_sql)" "
606
+ log_read "$name" "$list, $(counts_sql), $(cards_sql)" "
541
607
  select json_object('space', $(sql_str "$name"),
542
608
  'cards', (select json_group_array(json(c)) from (
543
609
  select json_object('card', latest.card, 'at', at, 'state', state,
544
610
  'waiting', nullif(waiting, ''), 'for', $(sql_took since), 'seconds', since,
545
611
  'run', run, 'step', latest.step, 'status', status, 'next', next,
546
612
  'agent', json(agent), 'tokens', json(t.tokens), 'cost', json(t.cost),
547
- 'partial', json(case when t.missing > 0 then 'true' else 'false' end)) as c
613
+ 'partial', json(case when t.missing > 0 then 'true' else 'false' end),
614
+ 'stand', s.stand, 'running', json(case when s.running then 'true' else 'false' end),
615
+ 'word', s.word, 'mark', s.mark, 'need', s.need) as c
548
616
  from latest left join agents using (card) join told t on t.part = 2 and t.card = latest.card
617
+ join shows s on s.card = latest.card
549
618
  order by at desc, latest.id desc)),
550
619
  'counts', (select json_group_array(json(c)) from (
551
620
  select json_object('step', step, 'count', count, 'marks', json(marks),
package/herdr/README.md CHANGED
@@ -13,13 +13,14 @@ layouts (whole-window arrangements of mods).
13
13
  | `mods/layout-switch/` | A dropdown that shows the current layout and switches to another. |
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
+ | `mods/card-list/` | The card list, at the top of the `vibe` layout's middle column, and in a column of its own beside the terminals on `showcase`: the cards of the space that is showing, in two views. Agents lists the cards running now, the ones that need you first; Linear lists every open card under its parent card, with Start for a card not approved yet. A click on a running card opens its agent on the right. See [The card list](#the-card-list). |
16
17
  | `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
18
  | `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). |
18
19
  | `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). |
19
20
  | `mods/names/` | Draws nothing but a note saying what it does, and that only where a layout asks for it, as `showcase` does. 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). |
20
21
  | `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. |
21
- | `layouts/showcase.json` | For seeing each mod working before you choose what to put in a layout of your own: it places every mod ocnus ships, each in a block of its own that shows as soon as the layout opens, and each is the mod itself, on this machine's own data, as on `default`. It is `default` with two changes: the Usage section, the Memory mod and the CPU mod leave the sidebar for a row along the bottom, under the terminals, and `names` sits at the end of that row, where it draws a note saying that it draws nothing, and what it does. `npm test` fails, naming the mod, when a mod in `mods/` is not on it, so a card that adds a mod adds it here too. |
22
- | `layouts/vibe.json` | Three columns side by side, each the window's full height, for steering every agent without reading code. The left one is the sidebar, 268px wide as `default`'s is: Herdr's brand, the layout dropdown, the Ocnus spaces panel and, at its bottom, the Step counts section, the Usage section, the Memory mod and the CPU mod, stacked in that order with nothing between them. The middle one is the place for the card list (LAB-237) above the place for Brainstorm (LAB-240), and the right one is the place for Needs you (LAB-238), which turns into the opened agent (LAB-239). Those three places are still empty: each is a column with nothing in it, which its card swaps for the mod's block, so the layout names no mod that is not installed. It shows no files, diffs or split terminals: it has no Files panel, no Changes panel, no tab bar and no block for a tab's terminals, shown or hidden, so code is only in the pull requests. It has no settings button and no footer either: the settings button is on `default`, and Herdr's Settings still opens by its key. The `names` mod is beside the brand, in a block 1px wide. `layouts/vibe.svg`, beside it, is its picture in Herdr's Settings: `ocnus install` and `ocnus update` link it, and `ocnus status` lists it, as they do a layout. |
22
+ | `layouts/showcase.json` | For seeing each mod working before you choose what to put in a layout of your own: it places every mod ocnus ships, each in a block of its own that shows as soon as the layout opens, and each is the mod itself, on this machine's own data, as on `default`. It is `default` with three changes: the card list, which `default` does not have, is a column of its own left of the terminals, 540px wide; the Usage section, the Memory mod and the CPU mod leave the sidebar for a row along the bottom, under the terminals; and `names` sits at the end of that row, where it draws a note saying that it draws nothing, and what it does. `npm test` fails, naming the mod, when a mod in `mods/` is not on it, so a card that adds a mod adds it here too. |
23
+ | `layouts/vibe.json` | Three columns side by side, each the window's full height, for steering every agent without reading code. The left one is the sidebar, 268px wide as `default`'s is: Herdr's brand, the layout dropdown, the Ocnus spaces panel and, at its bottom, the Step counts section, the Usage section, the Memory mod and the CPU mod, stacked in that order with nothing between them. The middle one is the card list, the `card-list` mod, which fills its place there (see [The card list](#the-card-list)), above the place for Brainstorm (LAB-240), and the right one is the place for Needs you (LAB-238), which turns into the opened agent (LAB-239). Those two places are still empty: each is a column with nothing in it, which its card swaps for the mod's block, so the layout names no mod that is not installed. It shows no files, diffs or split terminals: it has no Files panel, no Changes panel, no tab bar and no block for a tab's terminals, shown or hidden, so code is only in the pull requests. It has no settings button and no footer either: the settings button is on `default`, and Herdr's Settings still opens by its key. The `names` mod is beside the brand, in a block 1px wide. `layouts/vibe.svg`, beside it, is its picture in Herdr's Settings: `ocnus install` and `ocnus update` link it, and `ocnus status` lists it, as they do a layout. |
23
24
  | `spaces/template/` | The starting `SPACE.md` for every new space. |
24
25
 
25
26
  The skills are in [../skills/](../skills/), outside this folder. They are
@@ -614,6 +615,118 @@ has merged.
614
615
  has stopped is in the mark's colour, and its tooltip says what `task log`
615
616
  says.
616
617
 
618
+ ### The card list
619
+
620
+ On the `vibe` layout, the card list fills the top of the middle column,
621
+ above the place for Brainstorm, and `showcase` has it in a column of its own
622
+ beside the terminals. It shows the cards of the space that is showing in two
623
+ views, so that you can tell where each card stands, start one and open its
624
+ agent with a click, without looking for a tab or opening Linear.
625
+
626
+ - **A toggle at its top picks the view**: Agents or Linear, each with how
627
+ many cards it has, the running cards and the open ones. The list shows
628
+ Agents until you click Linear, and a click on either side shows that
629
+ view. Herdr starts it on Agents again. A list too long for its place
630
+ scrolls there, and Brainstorm's place below it stays as it is.
631
+ - **Agents lists the cards that are running**, and no others, one row each
632
+ however many tabs a card has. A card is running while a tab ocnus opened
633
+ for it is open and the phase that tab is for is still going on: its
634
+ write-up tab until the card is approved and its agent's turn there has
635
+ ended, then its task's tab, from when `task start` records the start until
636
+ its pull requests have merged. So when the build phase starts, the card's
637
+ row goes on with the newer agent. A held card whose write-up tab is still
638
+ open is not running once its agent's turn there has ended, and neither is
639
+ a merged card whose tab has not closed yet, nor a card whose tab you closed
640
+ while its step was under way. A card you start with `task new` is running
641
+ as soon as its write-up tab is open.
642
+ - **Its rows come in order of need**: Stuck first, then Permission, Approve?
643
+ and Asking together, then Merge?, then Working. Rows of the same need come
644
+ in the order of their IDs, by number, so a row moves only when its status
645
+ changes.
646
+ - **A row shows** the card's ID, its title and, under it, which sub-issue of
647
+ which parent card it is, as `2/4 of LAB-30` and that card's title, or
648
+ `no parent card`. Then a bar of seven boxes, one for each step, define,
649
+ plan, breakdown, start, build, review and pr: the box of the step the card
650
+ stands on, as `task log` has it, is in the colour of its status, the boxes
651
+ before it are done, and the bar's tooltip names the step. Then its status,
652
+ and how long it has been so, as `ocnus task log <space>` gives it, over
653
+ the tokens the card's agents have used so far over all its steps, as
654
+ `640k tok` or `1.2M tok` (see [Hand-offs](#hand-offs)). A card with no
655
+ figures shows the time alone, never 0.
656
+ - **A status is the first of these that holds**, in its colour:
657
+
658
+ | Status | Colour | The card |
659
+ |---|---|---|
660
+ | Stuck | 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 Stuck too |
661
+ | Permission | Amber | Its agent waits on a permission prompt in its tab |
662
+ | Approve? | Amber | `sdlc-breakdown` asks you to approve the card |
663
+ | Asking | Amber | It waits on you for anything else: a question its step asked, or its agent asking in its tab or waiting for a sign-in |
664
+ | Merge? | Green or amber | Its pull requests wait on you to merge them: green once the card is ready to merge, as its dot in the Step counts section is, and amber until then |
665
+ | Working | Blue | It is running, and none of those holds: its step is under way |
666
+
667
+ Answering is Needs you's: a row only shows that a card is asking.
668
+ - **Linear lists every open card of the space's teams**, the cards
669
+ `ocnus task ls <space>` lists, each under the row of its parent card,
670
+ parents in the order of their IDs, the highest number first, and each
671
+ sub-issue in its place, which its row starts with, as `2/4`. A parent has
672
+ a row even when it is not running, when it is not open itself and when it
673
+ is in another team. Its row shows only its ID, its title, its status when
674
+ it is running, or `no agent`, and how many of its sub-issues have merged,
675
+ as `1/4 merged`: no steps and no button. A sub-issue that is a parent too
676
+ shows only as the head of its own sub-issues. Cards with no parent come
677
+ last, under `No parent card`, the highest number first. A running card's
678
+ row shows what its row in Agents shows, but for the line about its parent.
679
+ Any other row is the first of these that fits:
680
+ - **Not started**, with an empty bar and a Start button, for a card not
681
+ approved yet: in Backlog, or another status before its team's first
682
+ not-started one (a status of type `triage` or `backlog`).
683
+ - **Held**, with its bar on start and each card it waits on, as
684
+ `waits on LAB-9`, for a card `task ls` says is held (see
685
+ [Starting the work](#starting-the-work)).
686
+ - **Its bar and status as `task log` has them**, such as Stuck when its
687
+ agent has stopped or Merge? when its pull requests wait on you, or, when
688
+ no status holds, its status in Linear, such as Todo, in grey. A card
689
+ that is not running is never Working.
690
+ - **Start runs `ocnus task new <space> <card>`**, as Start does in the
691
+ Cards panel: one card starts at a time, the button reads Starting… until
692
+ the command is done, and if it fails, a notification shows what it said.
693
+ Once the card's tab is open, its row is a running one.
694
+ - **A row with no button is not one to start here**: a card that is
695
+ approved or further on never has Start, and a parent's row has none.
696
+ Starting again a card whose agent has stopped is for its tab, or for
697
+ `task build --continue` (see [Starting the work](#starting-the-work)).
698
+ - **A click on a running card's row opens its agent**, in either view, a
699
+ parent's row too: it sets Herdr's shared value `ocnus.open` to
700
+ `{"space": "<space>", "card": "<card>"}`, which every mod can read. The
701
+ opened agent (LAB-239) shows that card on the right side of `vibe`, and
702
+ the row is marked for as long as the value names it. A row of a card that
703
+ is not running has no click. Before the opened agent is installed, a
704
+ click marks the row and does nothing more.
705
+ - **It updates on its own** while Herdr's window is visible, with no click
706
+ or restart. It looks at Herdr's tabs in the space every 2 seconds, and
707
+ reads `task log` again as soon as a tab opens, closes or is renamed, or
708
+ one of its terminals reports another status, and every 6 seconds: an
709
+ agent's change of state shows within 5 seconds, and a card's move to
710
+ another step within 10, as in the Step counts section. It reads the cards
711
+ of `task ls` again about once a minute, so a change in Linear, such as a
712
+ new card, a merge or a blocker that is done, shows within about a minute,
713
+ and at once when another space is shown.
714
+ - **One line stands in place of the rows** when the space that is showing is
715
+ not an ocnus space, when the `ocnus` on the machine is too old to say
716
+ which cards are running, when `task log` fails, in which case it is what
717
+ `ocnus` said, with no card running, in Agents, and with no open card, in
718
+ Linear. When the cards cannot be read from Linear, Linear says why in the
719
+ words of `task ls`, such as no Linear key saved or Linear out of reach,
720
+ and Agents still lists the running cards, each with its ID, its bar, its
721
+ status and its time.
722
+ - **It works nothing out itself.** The space comes from
723
+ `ocnus space ls --json`, the cards, with their parents, places and
724
+ blockers, from `ocnus task ls <space> --json`, and where each card stands,
725
+ whether it is running, its status, its colour and its place in the order
726
+ of need, with its time and its tokens, from `ocnus task log <space> --json`
727
+ (see [Hand-offs](#hand-offs)), joined by card ID. When `ocnus` is not on
728
+ Herdr's `PATH`, it runs the copy the mod is linked from.
729
+
617
730
  ### Hand-offs
618
731
 
619
732
  Each step of the write-up phase ends by handing off: which step it was, how it
@@ -1098,8 +1211,19 @@ ocnus task answer <space> <card> <question> <answer>
1098
1211
  `needs-human`, `ready` or `working`, most urgent first, and none at
1099
1212
  `start`), and its `text`, the count as the Step counts section shows it,
1100
1213
  such as `2 held` at `start` (see
1101
- [The Step counts section](#the-step-counts-section)). None of it is
1102
- stored: it is read from Herdr and those
1214
+ [The Step counts section](#the-step-counts-section)). Each of its
1215
+ `cards` has what the card list shows of it too (see
1216
+ [The card list](#the-card-list)):
1217
+
1218
+ | Key | What it is |
1219
+ |---|---|
1220
+ | `stand` | The step the card stands on, as the counts place it, so the card's row and its dot are on the same step: the step that comes next after one that is done, or the step that asked, was answered or failed. `null` once its pull requests have merged |
1221
+ | `running` | `true` while a tab ocnus opened for the card is open for the phase going on: the tab its agent is looked for in, until the card has merged. At `start`, the card is approved, and it is running only while its write-up agent is working, blocked or has hit an error. `false` with no tab to look in |
1222
+ | `word` | Its status in the card list, the first of these that holds: `Stuck` (any agent state but `blocked`, or a step that failed), `Permission` (`blocked` on a permission prompt), `Approve?` (breakdown's question for the approval), `Asking` (`blocked` otherwise, or any other question but the wait for the merge), `Merge?` (the pr step's wait for the merge) and `Working` (the card is running). `null` when none holds. The approval and the merge are told as `task asks` tells them |
1223
+ | `mark` | The word's colour, as the marks of `counts` name them: `stuck` for Stuck, `ready` for a Merge? that is ready to merge, `working` for Working, and `needs-human` for the rest; `null` with no word |
1224
+ | `need` | The word's place in the order of need: 0 for Stuck, 1 for Permission, Approve? and Asking, 2 for Merge? and 3 for Working; `null` with no word |
1225
+
1226
+ None of it is stored: it is read from Herdr and those
1103
1227
  files each time, and no row or step's time changes with it. With `jq`
1104
1228
  missing, every card shows as before. With `hc` missing, or with neither
1105
1229
  herdr-core able to list its terminals nor the app open and able to list
@@ -137,6 +137,18 @@
137
137
  "id": "work-body",
138
138
  "type": "row",
139
139
  "children": [
140
+ {
141
+ "id": "card-list",
142
+ "type": "block",
143
+ "content": {
144
+ "mod": "card-list"
145
+ },
146
+ "size": {
147
+ "px": 540
148
+ },
149
+ "min": 280,
150
+ "max": 900
151
+ },
140
152
  {
141
153
  "id": "main",
142
154
  "type": "block",
@@ -113,8 +113,10 @@
113
113
  "children": [
114
114
  {
115
115
  "id": "card-list",
116
- "type": "column",
117
- "children": []
116
+ "type": "block",
117
+ "content": {
118
+ "mod": "card-list"
119
+ }
118
120
  },
119
121
  {
120
122
  "id": "brainstorm",
@@ -0,0 +1,658 @@
1
+ // The card list: the cards of the ocnus space that is showing in Herdr, in
2
+ // the middle column of the vibe layout, in two views. Agents lists the cards
3
+ // that are running, the ones that need the human first. Linear lists every
4
+ // open card of the space's teams under its parent card.
5
+ //
6
+ // Which ocnus space a Herdr space is, which cards are open and how each one
7
+ // stands are the ocnus command's to say. `ocnus space ls --json` names the
8
+ // space, and `ocnus task ls <space> --json` lists its open cards, each with
9
+ // its title, its status in Linear, its parent, its place among the parent's
10
+ // sub-issues and whether it is held. `ocnus task log <space> --json` gives
11
+ // each card with hand-offs the step it stands on, whether it is running, its
12
+ // word, the word's mark, its need, how long it has been so and what its
13
+ // agents have used in all, and the steps in order, with its counts. This mod
14
+ // joins the two by card ID and draws them. It holds no rules about steps,
15
+ // agents or hand-offs: which cards are running, each one's word and colour
16
+ // and the order of need all arrive from the command.
17
+ //
18
+ // A click on a running card's row sets Herdr's shared value `ocnus.open` to
19
+ // that card, which the opened agent shows on the right of the layout, and the
20
+ // row is drawn selected while that value names it. A card not approved yet
21
+ // has Start, which runs `ocnus task new <space> <card>` as the Cards panel's
22
+ // Start does.
23
+ import { View, div, svg } from "gpui-kit";
24
+ import { v_flex, h_flex } from "gpui-base";
25
+ import { exec, spaces, panes, terminals, notify, theme, window, checking, appHome, shared, setShared } from "herdr";
26
+
27
+ // How often to see whether another space is showing, or Herdr's tabs in it
28
+ // have changed. A change in them is read at once, so an agent's change of
29
+ // state shows within this and a read.
30
+ const LOOK_MS = 2000;
31
+ const LOG_MS = 6000; // how often to read the log again, for a card's move to another step
32
+ const CARDS_MS = 60000; // how often to read the cards again, for a change in Linear
33
+ const TIMEOUT_MS = 10000;
34
+ const LIST_TIMEOUT_MS = 30000; // task ls waits up to 20s on Linear
35
+ const START_TIMEOUT_MS = 60000;
36
+ // How this mod's own link into the repo that ships it ends.
37
+ const LINKED_AT = "/herdr/mods/card-list";
38
+ // The shared value that names the card whose agent is open on the right of
39
+ // the layout: { space, card }.
40
+ const OPEN = "ocnus.open";
41
+ const SPINNER = "mods/workspace-chrome/spinner.svg";
42
+ const NOT_A_SPACE = "The shown space is not an ocnus space.";
43
+ const OLD_CLI = "This ocnus is too old for the card list. Run: ocnus update";
44
+ const READING = "Reading…";
45
+ const NONE_RUNNING = "No card is running.";
46
+ const NONE_OPEN = "No open card.";
47
+ // The statuses of a card not approved yet, by their type in Linear: those
48
+ // before its team's first not-started status.
49
+ const NOT_STARTED = new Set(["triage", "backlog"]);
50
+ // Where a held card stands: approved, with its work not started, as
51
+ // `task start` holds it.
52
+ const HELD_AT = "start";
53
+ const VIEWS = { agents: "running now · needs you first", linear: "every open card · by parent" };
54
+
55
+ // The colour of each mark, as the Step counts section colours its dots: red
56
+ // for a card that is stuck, amber for one that needs the human, green for
57
+ // one that is ready to merge and blue for one whose agent is working.
58
+ const colors = (t) => ({ stuck: t.ansi1, "needs-human": t.ansi3, ready: t.ansi2, working: t.ansi4 });
59
+
60
+ // `herdr-app check` draws the mod once, with nothing read, which would show
61
+ // one line and none of the rows. It is given these to draw instead: both
62
+ // views, one under the other, then each line that stands in place of the
63
+ // rows, so that a mistake in any of them fails the check. The log gives
64
+ // every word and mark, its cards out of the order of need, a running card
65
+ // that the cards do not list, a row with tokens and rows without. The cards
66
+ // give a card being started, a held card, an approved card in grey, a
67
+ // running parent, a parent with no agent that is not in the list, and cards
68
+ // with no parent.
69
+ const SAMPLE_STEPS = ["define", "plan", "breakdown", "start", "build", "review", "pr"];
70
+ const SAMPLE_LOG = {
71
+ steps: SAMPLE_STEPS,
72
+ cards: [
73
+ { card: "ABC-12", stand: "build", running: true, word: "Working", mark: "working", need: 3, for: "14m 02s",
74
+ agent: null, tokens: { total: 1800000, short: "1.8M" } },
75
+ { card: "ABC-17", stand: "build", running: true, word: "Stuck", mark: "stuck", need: 0, for: "1h 02m",
76
+ agent: { state: "stopped", label: "agent stopped without handing off", for: "12m 30s" }, tokens: { total: 900000, short: "900k" } },
77
+ { card: "ABC-9", stand: "pr", running: true, word: "Merge?", mark: "ready", need: 2, for: "1h 10m",
78
+ agent: null, tokens: { total: 1200000, short: "1.2M" } },
79
+ { card: "ABC-15", stand: "review", running: true, word: "Permission", mark: "needs-human", need: 1, for: "20m 00s",
80
+ agent: { state: "blocked", kind: "permission", label: "agent waiting on a permission prompt", for: "1m 10s" }, tokens: null },
81
+ { card: "ABC-22", stand: "breakdown", running: true, word: "Approve?", mark: "needs-human", need: 1, for: "3m 05s",
82
+ agent: null, tokens: { total: 640000, short: "640k" } },
83
+ { card: "ABC-14", stand: "plan", running: true, word: "Asking", mark: "needs-human", need: 1, for: "6m 40s",
84
+ agent: null, tokens: { total: 520000, short: "520k" } },
85
+ { card: "ABC-30", stand: "define", running: true, word: "Working", mark: "working", need: 3, for: "2m 00s",
86
+ agent: null, tokens: { total: 0, short: "0" } },
87
+ { card: "ABC-5", stand: "pr", running: true, word: "Working", mark: "working", need: 3, for: "40s", agent: null, tokens: null },
88
+ { card: "ABC-19", stand: "pr", running: false, word: "Merge?", mark: "needs-human", need: 2, for: "2h 00m", agent: null, tokens: null },
89
+ { card: "ABC-11", stand: "start", running: false, word: null, mark: null, need: null, for: "1d 02h", agent: null, tokens: null },
90
+ { card: "ABC-13", stand: "start", running: false, word: null, mark: null, need: null, for: "3d 04h", agent: null, tokens: null },
91
+ ],
92
+ };
93
+ const SAMPLE_PARENT = { id: "ABC-30", title: "Vibe layout in Herdr", subIssues: 4, done: 0 };
94
+ const SAMPLE_OTHER = { id: "ABC-8", title: "Sidebar polish", subIssues: 3, done: 1 };
95
+ const sampleCard = (id, title, more = {}) => ({ id, title, url: "", parent: null, place: null, held: false, waitsOn: [], ...more });
96
+ const SAMPLE_CARDS = {
97
+ space: "sample",
98
+ statuses: [
99
+ { name: "Backlog", type: "backlog", cards: [
100
+ sampleCard("ABC-20", "Board keyboard nav"),
101
+ sampleCard("ABC-21", "Toast when an agent blocks", { parent: SAMPLE_PARENT, place: 4 }),
102
+ sampleCard("ABC-22", "Held cards show their blockers", { parent: SAMPLE_PARENT, place: 3 }),
103
+ ] },
104
+ { name: "Todo", type: "unstarted", cards: [
105
+ sampleCard("ABC-11", "Space marks on the rail", { held: true, waitsOn: [{ id: "ABC-9", title: "Space colors", status: { name: "In Review", type: "started" } }] }),
106
+ sampleCard("ABC-13", "Idle section remembers fold"),
107
+ ] },
108
+ { name: "In Progress", type: "started", cards: [
109
+ sampleCard("ABC-30", "Vibe layout in Herdr"),
110
+ sampleCard("ABC-15", "Brainstorm pane per space", { parent: SAMPLE_PARENT, place: 1 }),
111
+ sampleCard("ABC-16", "Agent board mod", { parent: SAMPLE_PARENT, place: 2 }),
112
+ sampleCard("ABC-12", "Steps timeline for each card", { parent: SAMPLE_OTHER, place: 2 }),
113
+ sampleCard("ABC-17", "Retry failed Linear sync"),
114
+ sampleCard("ABC-14", "Coach price snapshot importer"),
115
+ ] },
116
+ { name: "In Review", type: "started", cards: [
117
+ sampleCard("ABC-9", "Space colors in the sidebar", { parent: SAMPLE_OTHER, place: 1 }),
118
+ sampleCard("ABC-19", "Pin an agent", { parent: SAMPLE_OTHER, place: 3 }),
119
+ ] },
120
+ ],
121
+ };
122
+ const SAMPLE_STARTING = "ABC-21";
123
+ const SAMPLE_OPEN = { space: "sample", card: "ABC-14" };
124
+ const SAMPLE_LINES = [
125
+ { line: READING }, { line: NOT_A_SPACE }, { line: OLD_CLI, error: true }, { line: NONE_RUNNING }, { line: NONE_OPEN },
126
+ { line: "no Linear key saved. Run: ocnus linear key", error: true },
127
+ ];
128
+
129
+ function parse(text) {
130
+ try {
131
+ return JSON.parse(text);
132
+ } catch {
133
+ return null;
134
+ }
135
+ }
136
+
137
+ // What a failed command said, without the name it starts its errors with.
138
+ const said = (r) => (r.stderr || r.stdout).trim().replace(/^ocnus: /, "");
139
+ // An ocnus from before --json answers with its usage line, not JSON, and
140
+ // one from before the list of cards asks which card.
141
+ const failure = (r, what) => {
142
+ const text = said(r);
143
+ return text.startsWith("usage:") || text.startsWith("which card?") ? OLD_CLI : text || `${what} failed`;
144
+ };
145
+
146
+ // The shown space's folder, when that space is on this computer: the only
147
+ // place an ocnus space can be.
148
+ function shownFolder() {
149
+ const space = spaces().find((s) => s.active);
150
+ return space && !space.machine ? space.folder : null;
151
+ }
152
+
153
+ // What Herdr shows of the tabs in the spaces whose folder is `folder`, on
154
+ // this computer: each tab's id and name, and each of its terminals' status
155
+ // and app. `task log` works out from these which cards are running and how
156
+ // each one's agent is doing, so a change in them is read at once. A pane's
157
+ // status has no word for hc's error, so each terminal's own word, from
158
+ // terminals(), is in it too.
159
+ function herdrSees(folder) {
160
+ if (folder === null) return "";
161
+ const word = new Map(terminals().map((t) => [t.address, t.status ?? null]));
162
+ const tabs = new Set();
163
+ const seen = [];
164
+ for (const space of spaces()) {
165
+ if (space.machine || space.folder !== folder) continue;
166
+ for (const tab of space.tabs) {
167
+ tabs.add(tab.id);
168
+ seen.push([tab.id, tab.name]);
169
+ }
170
+ }
171
+ for (const p of panes()) {
172
+ if (p.terminal && tabs.has(p.tab)) seen.push([p.tab, p.terminal, p.status, p.app, word.get(p.terminal) ?? null]);
173
+ }
174
+ return JSON.stringify(seen);
175
+ }
176
+
177
+ // A card ID's team key and number.
178
+ function idParts(id) {
179
+ const text = String(id ?? "").toUpperCase();
180
+ const m = text.match(/^(.*)-([0-9]+)$/);
181
+ return m ? [m[1], Number(m[2])] : [text, 0];
182
+ }
183
+ // Card IDs in order: by team key, then by number, read as a number, so that
184
+ // ABC-9 comes before ABC-17.
185
+ function idOrder(a, b) {
186
+ const [ka, na] = idParts(a);
187
+ const [kb, nb] = idParts(b);
188
+ return ka < kb ? -1 : ka > kb ? 1 : na - nb;
189
+ }
190
+
191
+ // What its agents have used, as "640k tok", from the figures `task log`
192
+ // gives the card: nothing for a card with none, never 0.
193
+ function tokens(c) {
194
+ const t = c?.tokens;
195
+ return t && Number(t.total) > 0 && t.short ? `${t.short} tok` : null;
196
+ }
197
+
198
+ // Which sub-issue of which parent card a card is, as "2/4 of ABC-30" and the
199
+ // parent's title, or that it has none.
200
+ function parentLine(k) {
201
+ const p = k.parent;
202
+ if (!p?.id) return "no parent card";
203
+ return `${k.place ?? "?"}/${p.subIssues ?? "?"} of ${p.id} ${p.title ?? ""}`.trim();
204
+ }
205
+
206
+ // The row of a running card: its ID and title, with the line about its
207
+ // parent when `withParent`, and its steps, word, time and tokens, as the
208
+ // log gives them. `k` is the card as `task ls` lists it, or null.
209
+ function runningRow(c, k, steps, withParent) {
210
+ return {
211
+ id: c.card, title: k?.title ?? "", parent: withParent && k ? parentLine(k) : null,
212
+ steps, at: steps.indexOf(c.stand), box: c.mark ?? null, tip: c.stand ?? "",
213
+ word: c.word ?? "", tone: c.mark ?? null,
214
+ time: c.agent?.for ?? c.for ?? "", tok: tokens(c), opens: true,
215
+ };
216
+ }
217
+
218
+ // The row of a card in Linear, under its parent's row: `k` as `task ls`
219
+ // lists it, with its status, `c` as the log gives it, or null for a card
220
+ // with no hand-offs, and `place` its place among its parent's sub-issues,
221
+ // undefined for a card with no parent.
222
+ // The first that fits: a running card's row; Not started, with Start, for a
223
+ // card not approved yet; Held, with what it waits on; else its steps and its
224
+ // word, or its status in Linear in grey when it has none.
225
+ function linearRow(k, c, steps, place) {
226
+ if (c?.running === true) return { ...runningRow(c, k, steps, false), place };
227
+ const row = { id: k.id, title: k.title ?? "", parent: null, place, steps, time: null, tok: null, opens: false };
228
+ if (NOT_STARTED.has(k.status?.type)) {
229
+ return { ...row, at: -1, box: null, tip: "", word: "Not started", tone: null, start: true };
230
+ }
231
+ if (k.held === true) {
232
+ const waits = (Array.isArray(k.waitsOn) ? k.waitsOn : []).map((w) => w?.id).filter(Boolean);
233
+ return { ...row, at: steps.indexOf(HELD_AT), box: null, tip: HELD_AT, word: "Held", tone: null,
234
+ waits: waits.length ? `waits on ${waits.join(", ")}` : null };
235
+ }
236
+ return { ...row, at: c ? steps.indexOf(c.stand) : -1, box: c?.word ? c.mark ?? null : null, tip: c?.stand ?? "",
237
+ word: c?.word ?? k.status?.name ?? "", tone: c?.word ? c.mark ?? null : null };
238
+ }
239
+
240
+ // The cards that are running, as the log says, in the order of need, and
241
+ // then by ID, so that a row moves only when its word changes. A card that
242
+ // `task ls` does not list, as every card when it failed, has no title and no
243
+ // line about its parent.
244
+ function agentRows(log, listed) {
245
+ return log.cards.filter((c) => c?.running === true && typeof c.card === "string")
246
+ .sort((a, b) => (a.need ?? 9) - (b.need ?? 9) || idOrder(a.card, b.card))
247
+ .map((c) => runningRow(c, listed.get(c.card.toUpperCase()) ?? null, log.steps, true));
248
+ }
249
+
250
+ // The cards `task ls` listed, each under its parent's row: the parents by ID,
251
+ // the highest number first, each card by its place, then the cards with no
252
+ // parent under a line of their own. A parent's row is its ID, its title, its
253
+ // word when it is running or "no agent", and how many of its sub-issues have
254
+ // merged. A card that is a parent heads its own group alone.
255
+ function linearRows(cards, log) {
256
+ const logged = new Map(log.cards.filter((c) => typeof c?.card === "string").map((c) => [c.card.toUpperCase(), c]));
257
+ const heads = new Set(cards.filter((k) => k.parent?.id).map((k) => String(k.parent.id).toUpperCase()));
258
+ const groups = new Map();
259
+ const loose = [];
260
+ for (const k of cards) {
261
+ if (heads.has(k.id.toUpperCase())) continue;
262
+ if (!k.parent?.id) {
263
+ loose.push(k);
264
+ continue;
265
+ }
266
+ const id = String(k.parent.id).toUpperCase();
267
+ if (!groups.has(id)) groups.set(id, { parent: k.parent, kids: [] });
268
+ groups.get(id).kids.push(k);
269
+ }
270
+ const rows = [];
271
+ for (const [id, g] of [...groups].sort((a, b) => idOrder(b[0], a[0]))) {
272
+ const c = logged.get(id) ?? null;
273
+ const running = c?.running === true;
274
+ rows.push({ head: true, id: g.parent.id, title: g.parent.title ?? "", word: running ? c.word ?? "" : "no agent",
275
+ tone: running ? c.mark ?? null : null, merged: `${g.parent.done ?? 0}/${g.parent.subIssues ?? 0} merged`, opens: running });
276
+ g.kids.sort((a, b) => (a.place ?? Infinity) - (b.place ?? Infinity) || idOrder(a.id, b.id));
277
+ for (const k of g.kids) {
278
+ const place = `${k.place ?? "?"}/${g.parent.subIssues ?? "?"}`;
279
+ rows.push(linearRow(k, logged.get(k.id.toUpperCase()) ?? null, log.steps, place));
280
+ }
281
+ }
282
+ if (loose.length) {
283
+ rows.push({ loose: true });
284
+ for (const k of loose.sort((a, b) => idOrder(b.id, a.id))) {
285
+ rows.push(linearRow(k, logged.get(k.id.toUpperCase()) ?? null, log.steps, undefined));
286
+ }
287
+ }
288
+ return rows;
289
+ }
290
+
291
+ // What each view shows of the space in `folder`, from what was read for it:
292
+ // `found`, the space, or why it is not known; `got`, its cards as `task ls`
293
+ // lists them, or what it said; and `log`, what `task log` gives, or what it
294
+ // said. Each view is { rows } or { line }, the one line that stands in their
295
+ // place, and counts are how many cards each side of the toggle has: the
296
+ // running cards and the open ones, or null when they are not known.
297
+ function shape(folder, found, got, log) {
298
+ const line = (text, error = false) => ({ line: text, error });
299
+ const counts = { agents: null, linear: null };
300
+ if (folder === null || (found && !found.space && !found.error)) {
301
+ return { space: null, counts, agents: line(NOT_A_SPACE), linear: line(NOT_A_SPACE) };
302
+ }
303
+ if (!found) return { space: null, counts, agents: line(READING), linear: line(READING) };
304
+ if (found.error) return { space: null, counts, agents: line(found.error, true), linear: line(found.error, true) };
305
+ const cards = [];
306
+ for (const s of got?.statuses ?? []) {
307
+ for (const k of s?.cards ?? []) {
308
+ if (typeof k?.id === "string") cards.push({ ...k, status: { name: s.name, type: s.type } });
309
+ }
310
+ }
311
+ const listed = new Map(cards.map((k) => [k.id.toUpperCase(), k]));
312
+ if (got?.statuses) counts.linear = cards.length;
313
+ let agents;
314
+ if (!log) agents = line(READING);
315
+ else if (log.error) agents = line(log.error, true);
316
+ else {
317
+ const rows = agentRows(log, listed);
318
+ counts.agents = rows.length;
319
+ agents = rows.length ? { rows } : line(NONE_RUNNING);
320
+ }
321
+ let linear;
322
+ if (!got) linear = line(READING);
323
+ else if (got.error) linear = line(got.error, true);
324
+ else if (!log) linear = line(READING);
325
+ else if (log.error) linear = line(log.error, true);
326
+ else {
327
+ const rows = linearRows(cards, log);
328
+ linear = rows.length ? { rows } : line(NONE_OPEN);
329
+ }
330
+ return { space: found.space, counts, agents, linear };
331
+ }
332
+
333
+ export default class CardList extends View {
334
+ init(_props, cx) {
335
+ this.cmd = "ocnus"; // the one on PATH, until that cannot start
336
+ this.view = "agents"; // the view that shows, until the human picks the other
337
+ // The folder of the shown space that the space below was looked up for,
338
+ // and what was found: { space } with its name or null, or { error }.
339
+ this.folder = undefined;
340
+ this.found = null;
341
+ // Its cards, as `task ls` lists them: { statuses } or { error }.
342
+ this.got = null;
343
+ this.cardsAt = 0;
344
+ this.cardsBusy = false;
345
+ // What `task log` gives: { cards, steps } or { error }, for the folder
346
+ // logFor, and what Herdr showed of the space's tabs then.
347
+ this.log = null;
348
+ this.logFor = undefined;
349
+ this.logAt = 0;
350
+ this.logBusy = false;
351
+ this.logAgain = false; // read again as soon as the read under way is done
352
+ this.seen = null;
353
+ this.starting = null; // the card whose `task new` is running
354
+ this.drawn = null; // what the last redraw showed, to redraw only on a change
355
+ if (checking()) return;
356
+ cx.timer.every(LOOK_MS, (cx) => this.look(cx));
357
+ this.look(cx);
358
+ }
359
+
360
+ // Runs the ocnus command. With `fallback`, a command that cannot run is
361
+ // tried again as the copy this mod is linked from (Herdr may have been
362
+ // started without the user's PATH). Only the readings ask for that: they
363
+ // only read, and the cards have been listed before there is a card to
364
+ // start. A start never does, because its failure may be a timeout with the
365
+ // first run still opening the tab.
366
+ async ocnus(args, { fallback = false, timeout = TIMEOUT_MS } = {}) {
367
+ try {
368
+ return await exec(this.cmd, args, { timeout });
369
+ } catch (e) {
370
+ if (!fallback || this.cmd !== "ocnus") throw e;
371
+ const link = await exec("readlink", [`${appHome()}/mods/card-list`]);
372
+ const at = link.stdout.trim();
373
+ if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
374
+ this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/ocnus`;
375
+ return exec(this.cmd, args, { timeout });
376
+ }
377
+ }
378
+
379
+ // Read the cards again when another space is showing, or when they are a
380
+ // minute old, and the log as `lookLog` says. When ocnus could not list
381
+ // the spaces, they are tried again as often as the log is read. Nothing is
382
+ // read while nobody can see the window.
383
+ look(cx) {
384
+ if (window()?.visible === false) return;
385
+ const every = this.found?.error ? LOG_MS : CARDS_MS;
386
+ if (shownFolder() !== this.folder || Date.now() - this.cardsAt >= every) this.readCards(cx);
387
+ this.lookLog(cx);
388
+ }
389
+
390
+ // Look up the ocnus space of the shown folder, then read its log at once,
391
+ // and its cards, which wait on Linear.
392
+ readCards(cx) {
393
+ if (this.cardsBusy) return;
394
+ this.cardsBusy = true;
395
+ const folder = shownFolder();
396
+ cx.spawn(async (cx) => {
397
+ const found = await this.find(folder);
398
+ if (folder !== this.folder) this.got = null;
399
+ this.folder = folder;
400
+ this.found = found;
401
+ this.logAgain = true;
402
+ this.lookLog(cx);
403
+ this.redraw(cx);
404
+ const got = found.space ? await this.readList(found.space) : null;
405
+ if (folder === this.folder) this.got = got;
406
+ this.cardsAt = Date.now();
407
+ this.cardsBusy = false;
408
+ this.redraw(cx);
409
+ // A space chosen while this was being read is read now, not at the
410
+ // next look.
411
+ if (shownFolder() !== this.folder) this.readCards(cx);
412
+ });
413
+ }
414
+
415
+ // Read the log again when Herdr's tabs in the shown space have changed,
416
+ // when it is 6 seconds old, and after the space is looked up. There is
417
+ // nothing to read until the shown folder's space is known.
418
+ lookLog(cx) {
419
+ if (this.logBusy) return;
420
+ const folder = shownFolder();
421
+ const space = folder === this.folder ? this.found?.space : null;
422
+ if (!space) return;
423
+ const seen = herdrSees(folder);
424
+ if (!this.logAgain && folder === this.logFor && seen === this.seen && Date.now() - this.logAt < LOG_MS) return;
425
+ this.logBusy = true;
426
+ this.logAgain = false;
427
+ cx.spawn(async (cx) => {
428
+ const log = await this.readLog(space);
429
+ this.log = log;
430
+ this.logFor = folder;
431
+ this.seen = seen;
432
+ this.logAt = Date.now();
433
+ this.logBusy = false;
434
+ this.redraw(cx);
435
+ if (this.logAgain) this.lookLog(cx);
436
+ });
437
+ }
438
+
439
+ // A redraw of a mod redraws the whole window, so only when what the list
440
+ // shows has changed.
441
+ redraw(cx) {
442
+ const drawn = JSON.stringify(this.shown());
443
+ if (drawn === this.drawn) return;
444
+ this.drawn = drawn;
445
+ cx.notify();
446
+ }
447
+
448
+ // What both views show of the space that is showing, from what was read
449
+ // for it.
450
+ shown() {
451
+ const folder = shownFolder();
452
+ const mine = folder === this.folder;
453
+ return shape(folder, mine ? this.found : null, mine ? this.got : null, folder === this.logFor ? this.log : null);
454
+ }
455
+
456
+ // The ocnus space whose folder is `folder`: { space } with its name, or
457
+ // null when it is none, or { error } when ocnus cannot list the spaces.
458
+ async find(folder) {
459
+ if (folder === null) return { space: null };
460
+ try {
461
+ const r = await this.ocnus(["space", "ls", "--json"], { fallback: true });
462
+ const listed = r.code === 0 ? parse(r.stdout)?.spaces : null;
463
+ if (!Array.isArray(listed)) return { error: r.code === 0 ? OLD_CLI : failure(r, "ocnus space ls") };
464
+ return { space: listed.find((s) => s.folder === folder)?.name ?? null };
465
+ } catch (e) {
466
+ return { error: `Could not run ocnus: ${e?.message ?? e}` };
467
+ }
468
+ }
469
+
470
+ // The space's open cards, under their statuses, or what `task ls` said.
471
+ async readList(space) {
472
+ try {
473
+ const r = await this.ocnus(["task", "ls", space, "--json"], { fallback: true, timeout: LIST_TIMEOUT_MS });
474
+ const list = r.code === 0 ? parse(r.stdout) : null;
475
+ if (Array.isArray(list?.statuses)) return { statuses: list.statuses };
476
+ return { error: r.code === 0 ? OLD_CLI : failure(r, "ocnus task ls") };
477
+ } catch (e) {
478
+ return { error: `Could not run ocnus: ${e?.message ?? e}` };
479
+ }
480
+ }
481
+
482
+ // The space's cards that have hand-offs, as `task log` gives them, with
483
+ // the steps in order, or what it said. An ocnus from before the card list
484
+ // gives the cards without running.
485
+ async readLog(space) {
486
+ try {
487
+ const r = await this.ocnus(["task", "log", space, "--json"], { fallback: true });
488
+ const got = r.code === 0 ? parse(r.stdout) : null;
489
+ if (!Array.isArray(got?.cards) || !Array.isArray(got?.counts)) return { error: r.code === 0 ? OLD_CLI : failure(r, "ocnus task log") };
490
+ if (got.cards.some((c) => typeof c?.running !== "boolean")) return { error: OLD_CLI };
491
+ return { cards: got.cards, steps: got.counts.map((c) => c?.step).filter((s) => typeof s === "string") };
492
+ } catch (e) {
493
+ return { error: `Could not run ocnus: ${e?.message ?? e}` };
494
+ }
495
+ }
496
+
497
+ // Runs `task new` for a card, one at a time, as the Cards panel's Start
498
+ // does. Once it is done, the log is read again: the card's tab is open,
499
+ // and its row a running one.
500
+ start(space, id, cx) {
501
+ if (this.starting) return;
502
+ this.starting = id;
503
+ cx.notify();
504
+ cx.spawn(async (cx) => {
505
+ let failed = null;
506
+ try {
507
+ const r = await this.ocnus(["task", "new", space, id], { timeout: START_TIMEOUT_MS });
508
+ if (r.code !== 0) failed = said(r) || "ocnus task new failed";
509
+ } catch (e) {
510
+ failed = `Could not run ocnus: ${e?.message ?? e}`;
511
+ }
512
+ if (failed !== null) notify({ title: `Could not start ${id}`, body: failed, level: "error" });
513
+ this.starting = null;
514
+ cx.notify();
515
+ this.logAgain = true;
516
+ this.lookLog(cx);
517
+ });
518
+ }
519
+
520
+ // Show the view `name`, agents or linear.
521
+ pick(name, cx) {
522
+ if (this.view === name) return;
523
+ this.view = name;
524
+ cx.notify();
525
+ }
526
+
527
+ // The toggle, each side with how many cards it has, and what the view that
528
+ // shows lists.
529
+ header(view, counts, t) {
530
+ const side = (name, label, n) => h_flex().id(`card-list-${name}`).flex_none().h(26).px(12).gap(6).items_center()
531
+ .rounded(7).text_size(12.5).font_semibold()
532
+ .when(view === name, (el) => el.bg(t.selected).text_color(t.foreground))
533
+ .when(view !== name, (el) => el.text_color(t.muted).cursor_pointer().hover((s) => s.bg(t.hover))
534
+ .on_click((_e, cx) => this.pick(name, cx)))
535
+ .child(label)
536
+ .when(n !== null, (el) => el.child(div().font_normal().text_color(t.dim).child(String(n))));
537
+ return h_flex().h(48).flex_none().px(16).gap(10).items_center()
538
+ .child(h_flex().flex_none().p(2).gap(2).rounded(9).border_1().border_color(t.border).bg(t.chrome)
539
+ .child(side("agents", "Agents", counts.agents))
540
+ .child(side("linear", "Linear", counts.linear)))
541
+ .child(div().flex_1().min_w(0).truncate().text_size(12).text_color(t.dim).child(VIEWS[view]));
542
+ }
543
+
544
+ // The seven boxes of a card's steps: those before the step it stands on as
545
+ // done, that step's in the colour of the card's mark, or in grey with
546
+ // none, and the rest empty, with the step's name in the tooltip. A card
547
+ // that stands on no step has empty boxes and no tooltip.
548
+ bar(key, r, t) {
549
+ const now = colors(t)[r.box] ?? t.muted;
550
+ return h_flex().id(`${key}-steps`).flex_none().gap(3).items_center()
551
+ .when(Boolean(r.tip), (el) => el.tooltip(r.tip))
552
+ .children(r.steps.map((_s, i) => div().flex_none().w(10).h(4).rounded(2)
553
+ .bg(i < r.at ? t.dim : i === r.at ? now : t.border)));
554
+ }
555
+
556
+ // Start, for a card not approved yet. One card starts at a time: it reads
557
+ // Starting… while its `task new` runs, and the others wait.
558
+ startButton(space, id, starting, t) {
559
+ const mine = starting === id;
560
+ const waiting = Boolean(starting) && !mine;
561
+ return h_flex().id(`card-list-start-${id}`).h(24).flex_none().px(10).gap(5).items_center().rounded(7)
562
+ .border_1().border_color(t.input).bg(t.raised).text_size(11.5).text_color(t.foreground)
563
+ .when(mine, (el) => el.text_color(t.muted)
564
+ .child(svg(SPINNER).size(10).flex_none().text_color(t.working).spin(900)))
565
+ .when(waiting, (el) => el.opacity(0.45))
566
+ .when(!mine && !waiting, (el) => el.cursor_pointer().tooltip(`Start ${id}: open its tab with the agent running`)
567
+ .hover((s) => s.bg(t.hover)).on_click((_e, cx) => this.start(space, id, cx)))
568
+ .child(mine ? "Starting…" : "Start");
569
+ }
570
+
571
+ // A card's row: its place under its parent in Linear, its ID, its title
572
+ // and, in Agents, the line about its parent, its steps, its word, and at
573
+ // the end its time and tokens, Start, or what it waits on, which `wide`
574
+ // makes room for in Linear. Only a running card's row has a click, which
575
+ // opens its agent, and it is drawn selected while its agent is the one
576
+ // open.
577
+ row(r, key, space, open, starting, wide, t) {
578
+ const word = colors(t)[r.tone] ?? t.dim;
579
+ const end = v_flex().w(wide ? 96 : 60).flex_none().items_end().justify_center().text_size(11.5).text_color(t.dim);
580
+ return h_flex().id(key).flex_none().min_h(36).px(10).py(4).gap(10).items_center().rounded(8)
581
+ .when(r.opens && open, (el) => el.bg(t.selected))
582
+ .when(r.opens && !open, (el) => el.cursor_pointer().hover((s) => s.bg(t.hover)))
583
+ .when(r.opens, (el) => el.on_click(() => setShared(OPEN, { space, card: r.id })))
584
+ .when(r.place !== undefined, (el) => el.child(div().w(30).flex_none().text_size(11).text_color(t.muted).child(r.place)))
585
+ .child(div().w(58).flex_none().truncate().text_size(11.5).text_color(t.dim).child(r.id))
586
+ .child(v_flex().flex_1().min_w(0)
587
+ .child(div().truncate().text_color(r.opens ? t.foreground : t.muted).child(r.title))
588
+ .when(r.parent !== null, (el) => el.child(div().truncate().text_size(11).text_color(t.dim).child(r.parent))))
589
+ .child(this.bar(key, r, t))
590
+ .child(div().w(84).flex_none().truncate().text_size(12).text_color(word)
591
+ .when(Boolean(r.tone), (el) => el.font_semibold()).child(r.word))
592
+ .child(r.start
593
+ ? end.child(this.startButton(space, r.id, starting, t))
594
+ : end
595
+ .when(Boolean(r.waits), (el) => el.child(div().w_full().text_right().truncate().text_size(11).child(r.waits)))
596
+ .when(Boolean(r.time), (el) => el.child(div().child(r.time)))
597
+ .when(Boolean(r.tok), (el) => el.child(div().text_size(10.5).child(r.tok))));
598
+ }
599
+
600
+ // A parent card's row: its ID, its title, its word when it is running or
601
+ // "no agent", and how many of its sub-issues have merged. It has no steps
602
+ // and no Start. When it is running, a click opens its agent.
603
+ head(r, key, space, open, t) {
604
+ const word = colors(t)[r.tone] ?? t.dim;
605
+ return h_flex().id(key).flex_none().min_h(32).mt(6).px(10).gap(10).items_center().rounded(8)
606
+ .when(r.opens && open, (el) => el.bg(t.selected))
607
+ .when(r.opens && !open, (el) => el.cursor_pointer().hover((s) => s.bg(t.hover)))
608
+ .when(r.opens, (el) => el.on_click(() => setShared(OPEN, { space, card: r.id })))
609
+ .child(div().w(58).flex_none().truncate().text_size(11.5).text_color(t.dim).child(r.id))
610
+ .child(div().flex_1().min_w(0).truncate().font_semibold().text_color(t.foreground).child(r.title))
611
+ .child(h_flex().flex_none().gap(6).items_center().text_size(11.5)
612
+ .child(div().text_color(word).when(Boolean(r.tone), (el) => el.font_semibold()).child(r.word))
613
+ .child(div().text_color(t.dim).child(`· ${r.merged}`)));
614
+ }
615
+
616
+ // A view's rows. `view` makes each row's id its own, `opened` is the card
617
+ // whose agent is open, and `starting` the card being started.
618
+ items(rows, view, space, opened, starting, t) {
619
+ const open = (id) => opened?.space === space && opened?.card === id;
620
+ return rows.map((r) => {
621
+ if (r.loose) return div().flex_none().px(10).pt(14).pb(4).text_size(11.5).text_color(t.dim).child("No parent card");
622
+ if (r.head) return this.head(r, `${view}-head-${r.id}`, space, open(r.id), t);
623
+ return this.row(r, `${view}-${r.id}`, space, open(r.id), starting, view === "linear", t);
624
+ });
625
+ }
626
+
627
+ // The one line that stands in place of a view's rows.
628
+ line(v, t) {
629
+ return div().flex_none().px(10).py(6).text_size(12.5).text_color(v.error ? t.blocked : t.dim).whitespace_normal()
630
+ .child(v.line);
631
+ }
632
+
633
+ render() {
634
+ const t = theme();
635
+ const box = () => v_flex().size_full().min_h(0).bg(t.background).text_size(13).text_color(t.foreground);
636
+ const rows = (items) => v_flex().id("card-list-rows").flex_1().min_h(0).px(10).pb(10).overflow_y_scrollbar()
637
+ .children(items);
638
+ if (checking()) {
639
+ const s = shape("sample", { space: "sample" }, SAMPLE_CARDS, SAMPLE_LOG);
640
+ return box()
641
+ .child(this.header("agents", s.counts, t))
642
+ .child(this.header("linear", s.counts, t))
643
+ .child(rows([
644
+ ...this.items(s.agents.rows, "agents", "sample", SAMPLE_OPEN, SAMPLE_STARTING, t),
645
+ ...this.items(s.linear.rows, "linear", "sample", SAMPLE_OPEN, SAMPLE_STARTING, t),
646
+ ...SAMPLE_LINES.map((v) => this.line(v, t)),
647
+ ]));
648
+ }
649
+ const s = this.shown();
650
+ const v = s[this.view];
651
+ const opened = shared(OPEN);
652
+ return box()
653
+ .child(this.header(this.view, s.counts, t))
654
+ .child(rows(v.rows
655
+ ? this.items(v.rows, this.view, s.space, opened && typeof opened === "object" ? opened : null, this.starting, t)
656
+ : [this.line(v, t)]));
657
+ }
658
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "Card list" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngaynor/ocnus",
3
- "version": "2.0.1-next.73",
3
+ "version": "2.0.1-next.76",
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": {