@johngaynor/ocnus 2.0.1-next.71 → 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:
@@ -1275,7 +1289,7 @@ read afterwards. It is off until you turn it on, and works on macOS only.
1275
1289
 
1276
1290
  ```sh
1277
1291
  ocnus host on # turn recording on
1278
- ocnus host report [<period>] # how often CPU, memory and disk were at their limit, what used the most, and where the steps' time went
1292
+ ocnus host report [<period>] # the host's numbers summed up, what used the most, and where the steps' time went
1279
1293
  ocnus host report --card <space> <card> --json # what the host recorded while each of a card's steps ran, as JSON for programs
1280
1294
  ocnus host off # turn it off, and delete every reading
1281
1295
  ocnus host # whether recording is on, and what it has
@@ -1342,12 +1356,19 @@ waits on the model are kept for 90 days, in `~/.config/ocnus/host`, and
1342
1356
  recording uses well under 1% of the CPU.
1343
1357
 
1344
1358
  `host report` takes the last 7 days, `<n>d` or `<n>h` back from now, a day
1345
- such as `2026-11-29`, or `2026-11-01..2026-11-29`. For each of CPU, memory
1346
- and disk it says how much of the recorded time it was at its limit: the CPU
1347
- at least 90% busy across all cores, memory pressure at warning or critical,
1348
- or under 10% of the home folder's disk free. Time with no reading, such as
1349
- when no agent was open, is shown as missing, never as idle. It also says how
1350
- much of the CPU recording used, watching the test runs included. Then it lists the
1359
+ such as `2026-11-29`, or `2026-11-01..2026-11-29`. It says how much of the
1360
+ period was recorded, in all and on each day. Time with no reading, such as
1361
+ when no agent was open, is shown as missing, never as idle. Then it sums up
1362
+ each number the readings hold of the host, under CPU, memory, disk, network,
1363
+ and power and heat, and judges none of them: a total for an amount, such as
1364
+ the bytes read from the disk; an average and the most in one reading for a
1365
+ level, such as how busy the CPU was, or the least for the disk's free space
1366
+ and the Wi-Fi's signal; and how long each state lasted, such as each level
1367
+ of memory pressure. An average weighs each reading by its seconds in the
1368
+ period. One of the levels is how much of the CPU recording used, its
1369
+ average with watching the test runs included. A number that no reading in
1370
+ the period holds, as on a Mac without it or in readings from before it was
1371
+ recorded, is shown as not read, never as 0. Then it lists the
1351
1372
  10 steps and the 10 phases that used the most CPU time in the period, and
1352
1373
  the 10 of each that held the most memory at once, each one card's own, such
1353
1374
  as LAB-150's build step, with how long it ran. Then come the 10 test runs
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/cli/lib/host.sh CHANGED
@@ -19,6 +19,8 @@
19
19
  # under a terminal labelled with a space, apart from everything else on the
20
20
  # host, which is one number each, and the recorder's own CPU apart from both.
21
21
  # A process outside those terminals is never written down, not even its pid.
22
+ # `host report` sums those numbers up for a period, as totals, averages and
23
+ # peaks, and how long each state lasted, and judges none of them.
22
24
  #
23
25
  # With each reading go the shares of those terminals, one each: the CPU and
24
26
  # memory of every process under it, the commands its agent started included,
@@ -1209,13 +1211,14 @@ host_day() {
1209
1211
  [ "$ok" = 1 ] && [ -n "$DAY_START" ] && [ -n "$DAY_END" ]
1210
1212
  }
1211
1213
 
1212
- # How the CPU, memory and disk were, over a period: how much of the time it
1213
- # was recorded, and how much of that each was at its limit. Time with no
1214
- # reading is shown as missing, never as idle. Then come the steps, phases
1215
- # and test runs that used the most (host_ranks_sql), and it ends with where
1216
- # the steps' time went (host_split_sql).
1214
+ # How the host worked over a period, in its numbers alone: how much of the
1215
+ # period was recorded, in all and on each day, with time with no reading
1216
+ # shown as missing, never as idle (host_report_sql). Then the host's numbers
1217
+ # summed up (host_numbers_sql), the steps, phases and test runs that used the
1218
+ # most (host_ranks_sql), and it ends with where the steps' time went
1219
+ # (host_split_sql).
1217
1220
  host_report() {
1218
- local period=${1:-7d} now start end n first last row works splits
1221
+ local period=${1:-7d} now start end n first last row have ranks=0 works=0 splits=0
1219
1222
  # A card's readings, as JSON, are a form of their own.
1220
1223
  for n in "$@"; do
1221
1224
  case $n in --card | --json) host_card "$@"; return ;; esac
@@ -1259,21 +1262,19 @@ host_report() {
1259
1262
  say "Recording is on, and takes a reading every $HOST_EVERY seconds while an ocnus agent is open."
1260
1263
  return 0
1261
1264
  fi
1262
- # A store the recorder has not opened since the cores, the shares, the
1263
- # test runs and the splits came has none of them: one digit each, 1 for
1264
- # what it has. The report only reads the store, so it never adds them, and
1265
- # leaves out what is missing.
1266
- row=$(store "$HOST_DB" "select (select count(*) from pragma_table_info('readings') where name = 'cores')
1267
- || (select count(*) from sqlite_master where type = 'table' and name = 'shares')
1268
- || (select count(*) from sqlite_master where type = 'table' and name = 'test_runs')
1269
- || (select count(*) from sqlite_master where type = 'table' and name = 'splits');") || row=
1270
- works=0 splits=0
1271
- case $row in ?1??) works=1 ;; esac
1272
- case $row in ?1?1) splits=1 ;; esac
1273
- case $row in 111?) row=1 ;; *) row=0 ;; esac
1274
- store "$HOST_DB" "$(host_report_sql "$start" "$end" "$period" "$row")" ||
1275
- die "could not read $HOST_DB"
1276
- if [ "$row" = 1 ]; then
1265
+ # A store the recorder has not opened since a table or a column came has
1266
+ # none of it, and the report only reads the store, so it never adds them.
1267
+ # A number whose column the store lacks is not read. The lists of what
1268
+ # used the most need the readings' cores, the shares and the test runs,
1269
+ # and where the steps' time went needs the shares, and the splits to split
1270
+ # it.
1271
+ have=$(host_columns) || have=' '
1272
+ case $have in *' shares.'*) works=1 ;; esac
1273
+ case $have in *' splits.'*) splits=$works ;; esac
1274
+ case $have in *' readings.cores '*) case $have in *' test_runs.'*) ranks=$works ;; esac ;; esac
1275
+ store "$HOST_DB" "$(host_report_sql "$start" "$end" "$period")" || die "could not read $HOST_DB"
1276
+ store "$HOST_DB" "$(host_numbers_sql "$start" "$end" "$have")" || die "could not read $HOST_DB"
1277
+ if [ "$ranks" = 1 ]; then
1277
1278
  store "$HOST_DB" "$(host_ranks_sql "$start" "$end")" || die "could not read $HOST_DB"
1278
1279
  else
1279
1280
  say ''
@@ -1282,17 +1283,19 @@ host_report() {
1282
1283
  store "$HOST_DB" "$(host_split_sql "$start" "$end" "$works" "$splits")" || die "could not read $HOST_DB"
1283
1284
  }
1284
1285
 
1285
- # The report's query, for the period from $1 to $2, named $3. A reading
1286
- # covers the secs before its at, so each one counts for the part of that
1287
- # which falls in the period, and in each day. With $4 as 1, the store has
1288
- # test runs and the readings their cores, and what watching the test runs
1289
- # that started in the period used counts as recording's own CPU, as a share
1290
- # of the cores the readings counted over the recorded time.
1286
+ # The tables and the columns the readings' store has, each column as its
1287
+ # table and its name, like readings.cores, between spaces, from one query.
1288
+ host_columns() {
1289
+ store "$HOST_DB" "select ' ' || coalesce(group_concat(m.name || '.' || p.name, ' '), '') || ' '
1290
+ from sqlite_master m join pragma_table_info(m.name) p where m.type = 'table';"
1291
+ }
1292
+
1293
+ # The top of the report, for the period from $1 to $2, named $3: how much of
1294
+ # it was recorded and how much is missing, then the same for each day. A
1295
+ # reading covers the secs before its at, so each one counts for the part of
1296
+ # that which falls in the period, and in each day.
1291
1297
  host_report_sql() {
1292
- local s=$1 e=$2 name=$3 watch=0
1293
- [ "${4:-0}" != 1 ] ||
1294
- watch="coalesce(100.0 * (select sum(watch_secs) from test_runs where started >= $s and started < $e)
1295
- / (select nullif(max(cores), 0) from readings where at > $s and at < $e + $HOST_GAP and at - secs < $e), 0)"
1298
+ local s=$1 e=$2 name=$3
1296
1299
  cat <<EOF
1297
1300
  with recursive
1298
1301
  days(day, ds, de) as (
@@ -1304,46 +1307,158 @@ with recursive
1304
1307
  cast(strftime('%s', date(day, '+1 day'), 'utc') as integer),
1305
1308
  min($e, cast(strftime('%s', date(day, '+2 days'), 'utc') as integer))
1306
1309
  from days where de < $e),
1307
- parts(day, len, d, cpu_busy, mem_pressure, disk_free_pct, cpu_self) as (
1308
- select days.day, days.de - days.ds,
1309
- max(0, min(at, days.de) - max(at - secs, days.ds)), cpu_busy, mem_pressure, disk_free_pct, cpu_self
1310
+ parts(day, len, d) as (
1311
+ select days.day, days.de - days.ds, max(0, min(at, days.de) - max(at - secs, days.ds))
1310
1312
  from days left join readings on at > days.ds and at < days.de + $HOST_GAP and at - secs < days.de),
1311
- byday(day, len, rec, cpu, mem, disk, self_time, self_d) as (
1312
- select day, len, cast(coalesce(sum(d), 0) as integer),
1313
- cast(coalesce(sum(case when cpu_busy >= 90 then d end), 0) as integer),
1314
- cast(coalesce(sum(case when mem_pressure >= 2 then d end), 0) as integer),
1315
- cast(coalesce(sum(case when disk_free_pct < 10 then d end), 0) as integer),
1316
- coalesce(sum(cpu_self * d), 0), coalesce(sum(case when cpu_self is not null then d end), 0)
1317
- from parts group by day),
1318
- total(len, rec, cpu, mem, disk, self) as (
1319
- select $e - $s, sum(rec), sum(cpu), sum(mem), sum(disk),
1320
- case when sum(self_d) > 0 then (sum(self_time) + $watch) / sum(self_d) end
1321
- from byday),
1322
- shown(len, rec, missing, cpu, mem, disk, self) as (
1323
- select len, rec, max(0, len - rec), cpu, mem, disk, self from total),
1313
+ byday(day, len, rec) as (
1314
+ select day, len, cast(coalesce(sum(d), 0) as integer) from parts group by day),
1315
+ total(len, rec) as (
1316
+ select $e - $s, sum(rec) from byday),
1317
+ shown(len, rec, missing) as (
1318
+ select len, rec, max(0, len - rec) from total),
1324
1319
  lines(n, k, line) as (
1325
1320
  select 1, '', 'The host from ' || strftime('%Y-%m-%d %H:%M', $s, 'unixepoch', 'localtime') || ' to '
1326
1321
  || strftime('%Y-%m-%d %H:%M', $e, 'unixepoch', 'localtime') || ' ($name)' from shown
1327
1322
  union all select 2, '', ' recorded ' || $(sql_took rec) || ' of ' || $(sql_took len) from shown
1328
1323
  union all select 3, '', ' missing ' || $(sql_took missing) || ', shown as missing, not idle: no reading was taken then' from shown
1329
- union all select 4, '', ' CPU at its limit ' || $(sql_took cpu) || ', ' || printf('%.1f%%', 100.0 * cpu / rec)
1330
- || ' of the recorded time (at least 90% busy across all cores)' from shown
1331
- union all select 5, '', ' memory at its limit ' || $(sql_took mem) || ', ' || printf('%.1f%%', 100.0 * mem / rec)
1332
- || ' of the recorded time (memory pressure at warning or critical)' from shown
1333
- union all select 6, '', ' disk at its limit ' || $(sql_took disk) || ', ' || printf('%.1f%%', 100.0 * disk / rec)
1334
- || ' of the recorded time (under 10% free on the disk holding the home folder)' from shown
1335
- union all select 7, '', ' recording ' || case when self is null then 'its own use of the CPU was not read'
1336
- else 'used ' || printf('%.2f%%', self) || ' of the CPU, all cores together, on average' end from shown
1337
- union all select 8, '', '' union all select 9, '', 'By day:'
1338
- union all select 10, day, ' ' || day || ' recorded ' || $(sql_took rec) || ', missing ' || $(sql_took "max(0, len - rec)")
1339
- || case when rec > 0 then '; at its limit: CPU ' || printf('%.1f%%', 100.0 * cpu / rec)
1340
- || ', memory ' || printf('%.1f%%', 100.0 * mem / rec) || ', disk ' || printf('%.1f%%', 100.0 * disk / rec)
1341
- else '' end
1324
+ union all select 4, '', '' union all select 5, '', 'By day:'
1325
+ union all select 6, day, ' ' || day || ' recorded ' || $(sql_took rec) || ', missing ' || $(sql_took "max(0, len - rec)")
1342
1326
  from byday)
1343
1327
  select line from lines order by n, k;
1344
1328
  EOF
1345
1329
  }
1346
1330
 
1331
+ # The numbers a reading holds of the host, in the order the report gives
1332
+ # them: CPU, memory, disk, network, and power and heat.
1333
+ HOST_NUMBERS='cpu_busy cpu_system cpu_agents cpu_rest cpu_self cpu_p cpu_e
1334
+ mem_pressure mem_used_mb mem_agents_mb mem_rest_mb compressed_mb swap_used_mb swap_ins swap_outs
1335
+ disk_read_kb disk_write_kb disk_free_pct
1336
+ net_in_kb net_out_kb net_wifi net_resent_pct wifi_rssi wifi_noise
1337
+ on_battery low_power thermal'
1338
+
1339
+ # The host's numbers from $1 to $2, under five headings: CPU, memory, disk,
1340
+ # network, and power and heat. They are read from r, the readings in the
1341
+ # period, each with d, the part of its secs in the period, as the report
1342
+ # counts a reading. Each number is summed up as what it is:
1343
+ # a level its average, each reading weighed by its d, over the readings
1344
+ # that hold it, and its highest in one reading, or its lowest
1345
+ # for the disk's free space and the Wi-Fi's signal (host_level)
1346
+ # an amount its total: the recorder writes what it grew by in each
1347
+ # reading, and one on the period's edge counts in proportion to
1348
+ # its d, as host_split_sql counts a split (host_amount)
1349
+ # a state how long each value lasted, and how long it was not read when
1350
+ # that is more than nothing (host_state)
1351
+ # A number no reading in the period holds says not read in place of its
1352
+ # figures, as SQLite's printf would print a null as 0, and sql_took of a
1353
+ # null is null. $3 lists the store's tables and columns, as host_columns
1354
+ # gives them, and a column the store lacks is read as null, so that its
1355
+ # number says not read too. Every line is worked out in one pass over the
1356
+ # readings, into one array, which gives them in its order.
1357
+ #
1358
+ # Recording's average adds what watching the test runs that started in the
1359
+ # period used, as a share of the cores the readings counted, over the time
1360
+ # its own CPU was read. No reading holds that, so its most in one reading
1361
+ # is the recorder's own.
1362
+ host_numbers_sql() {
1363
+ local s=$1 e=$2 have=$3 c cols='' watch=''
1364
+ for c in $HOST_NUMBERS; do
1365
+ case $have in *" readings.$c "*) cols="$cols, $c" ;; *) cols="$cols, null as $c" ;; esac
1366
+ done
1367
+ case $have in
1368
+ *' readings.cores '*)
1369
+ case $have in
1370
+ *' test_runs.watch_secs '*)
1371
+ watch="coalesce(100.0 * (select sum(watch_secs) from test_runs where started >= $s and started < $e)
1372
+ / (select nullif(max(cores), 0) from readings where at > $s and at < $e + $HOST_GAP and at - secs < $e), 0)"
1373
+ ;;
1374
+ esac
1375
+ ;;
1376
+ esac
1377
+ cat <<EOF
1378
+ with
1379
+ r as (
1380
+ select max(0, min(at, $e) - max(at - secs, $s)) as d, secs$cols from readings
1381
+ where at > $s and at < $e + $HOST_GAP and at - secs < $e and secs > 0),
1382
+ numbers(lines) as (
1383
+ select json_array(
1384
+ '', 'CPU, as a share of all cores'' time:',
1385
+ $(host_level busy cpu_busy '%.1f%%'),
1386
+ $(host_level system cpu_system '%.1f%%'),
1387
+ $(host_level 'the agents' cpu_agents '%.1f%%'),
1388
+ $(host_level 'the rest' cpu_rest '%.1f%%'),
1389
+ $(host_level recording cpu_self '%.2f%%' '' most "$watch"),
1390
+ $(host_level 'performance cores' cpu_p '%.1f%%' 'busy on average'),
1391
+ $(host_level 'efficiency cores' cpu_e '%.1f%%' 'busy on average'),
1392
+ '', 'Memory:',
1393
+ $(host_state pressure mem_pressure 'not read' normal '< 2' warning 'between 2 and 3' critical '>= 4'),
1394
+ $(host_level used mem_used_mb '%.0f MB'),
1395
+ $(host_level 'the agents' mem_agents_mb '%.0f MB'),
1396
+ $(host_level 'the rest' mem_rest_mb '%.0f MB'),
1397
+ $(host_level compressed compressed_mb '%.0f MB'),
1398
+ $(host_level 'swap used' swap_used_mb '%.0f MB'),
1399
+ $(host_amount 'swapped in' swap_ins '%.0f pages'),
1400
+ $(host_amount 'swapped out' swap_outs '%.0f pages'),
1401
+ '', 'Disk:',
1402
+ $(host_amount read disk_read_kb '%.1f MB' 1024),
1403
+ $(host_amount written disk_write_kb '%.1f MB' 1024),
1404
+ $(host_level free disk_free_pct '%.1f%%' '' lowest),
1405
+ '', 'Network:',
1406
+ $(host_amount received net_in_kb '%.1f MB' 1024),
1407
+ $(host_amount sent net_out_kb '%.1f MB' 1024),
1408
+ $(host_state interface net_wifi 'offline or not read' Wi-Fi '= 1' another '= 0'),
1409
+ $(host_level 'sent again' net_resent_pct '%.1f%%' 'of TCP bytes on average'),
1410
+ $(host_level 'Wi-Fi signal' wifi_rssi '%.0f dBm' '' lowest),
1411
+ $(host_level 'Wi-Fi noise' wifi_noise '%.0f dBm'),
1412
+ '', 'Power and heat:',
1413
+ $(host_state power on_battery 'not read' 'on battery' '= 1' 'on power' '= 0'),
1414
+ $(host_state 'Low Power Mode' low_power 'not read' on '= 1' off '= 0'),
1415
+ $(host_state 'thermal state' thermal 'not read' nominal '= 0' fair '= 1' serious '= 2' critical '= 3'))
1416
+ from r)
1417
+ select value from numbers, json_each(numbers.lines) order by key;
1418
+ EOF
1419
+ }
1420
+
1421
+ # SQL for a line of the host's numbers on a level, over the readings r: the
1422
+ # label $1, then the average of the column $2, with the words $4 after it,
1423
+ # or "on average", and its highest in one reading, or its lowest with $5 as
1424
+ # lowest. $3 is the printf format of each figure. $6, when given, is added
1425
+ # to the readings' sum before it is divided by their seconds.
1426
+ host_level() {
1427
+ local peak="max($2)" most='at most'
1428
+ [ "${5:-}" != lowest ] || peak="min($2)" most='at the lowest'
1429
+ printf '%s' "' ' || printf('%-19s', '$1') || case when count($2) = 0 then 'not read'
1430
+ else printf('$3', (sum(1.0 * $2 * d)${6:+ + $6}) / sum(case when $2 is not null then d end))
1431
+ || ' ${4:-on average}, ' || printf('$3', $peak) || ' $most' end"
1432
+ }
1433
+
1434
+ # SQL for a line of the host's numbers on an amount, over the readings r:
1435
+ # the label $1, then the total of the column $2, divided by $4 when it is
1436
+ # given, in the printf format $3. Each reading counts what it grew by for
1437
+ # its d in proportion to its secs.
1438
+ host_amount() {
1439
+ printf '%s' "' ' || printf('%-19s', '$1') || case when count($2) = 0 then 'not read'
1440
+ else printf('$3', sum(1.0 * $2 * d / secs)${4:+ / $4}) end"
1441
+ }
1442
+
1443
+ # SQL for a line of the host's numbers on a state, over the readings r: the
1444
+ # label $1, then how long the column $2 held each value, $4 onward, each a
1445
+ # name and the SQL that tests the column for it, like normal '< 2'. Then,
1446
+ # when it is more than nothing, how long it held none of them, which $3
1447
+ # names.
1448
+ host_state() {
1449
+ local label=$1 col=$2 none=$3 shown='' left='sum(d)' v
1450
+ shift 3
1451
+ while [ "$#" -ge 2 ]; do
1452
+ v="sum(case when $col $2 then d else 0 end)"
1453
+ [ -z "$shown" ] || shown="$shown || ', ' || "
1454
+ shown="$shown'$1 ' || $(sql_took "$v")"
1455
+ left="$left - $v"
1456
+ shift 2
1457
+ done
1458
+ printf '%s' "' ' || printf('%-19s', '$label') || case when count($col) = 0 then 'not read'
1459
+ else $shown || case when $left > 0 then ', $none ' || $(sql_took "($left)") else '' end end"
1460
+ }
1461
+
1347
1462
  # The steps and the phases that used the most CPU time, and that held the
1348
1463
  # most memory at once, from $1 to $2: ten of each, each one card's own. Each
1349
1464
  # counts what its shares say for the part of their reading in the period,