@johngaynor/ocnus 2.0.1-next.22 → 2.0.1-next.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -56
- package/cli/lib/agents.sh +32 -16
- package/cli/lib/github.sh +33 -17
- package/cli/lib/handoff.sh +86 -5
- package/cli/lib/host.sh +18 -348
- package/cli/lib/merges.sh +23 -12
- package/cli/lib/tests.sh +2 -3
- package/cli/ocnus +9 -39
- package/herdr/README.md +100 -142
- package/herdr/layouts/default.json +10 -0
- package/herdr/mods/step-counts/main.js +281 -0
- package/herdr/mods/step-counts/mod.json +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,8 +89,9 @@ and the two phase profiles in [agents/](agents/), which it links into
|
|
|
89
89
|
`~/.claude/agents`; see [herdr/README.md](herdr/README.md) for the full
|
|
90
90
|
walkthrough. `install` ends by telling you to switch Herdr to the `default`
|
|
91
91
|
layout, which holds ocnus's panels: the Ocnus spaces panel, the Cards
|
|
92
|
-
and Steps panels, the
|
|
93
|
-
|
|
92
|
+
and Steps panels, the Step counts section right above the Usage section,
|
|
93
|
+
which is above Memory and CPU, the Layout dropdown and the settings button.
|
|
94
|
+
Herdr's own Agents section is not on it. Herdr starts on
|
|
94
95
|
its own layout, which has no Layout dropdown, so the first switch is
|
|
95
96
|
`ctrl-shift-l`, pressed until `default` shows.
|
|
96
97
|
|
|
@@ -505,6 +506,20 @@ the card's own log and in the Steps and Cards panels, which draw what
|
|
|
505
506
|
request is closed or in conflict, the card shows as waiting on you, as
|
|
506
507
|
before.
|
|
507
508
|
|
|
509
|
+
On the `default` layout, the Step counts section, right above Usage in the
|
|
510
|
+
sidebar, shows where every card of the space that is showing stands, at a
|
|
511
|
+
glance: the seven steps, from `define` to `pr`, each with a dot for every
|
|
512
|
+
card that stands on it, and how many there are. A dot is amber when its card
|
|
513
|
+
needs you, waiting on you or with its agent blocked on a prompt in its tab;
|
|
514
|
+
blue while its agent is working; green, at `pr`, once the card is ready to
|
|
515
|
+
merge, with its pull requests all open, none in conflict and every check on
|
|
516
|
+
them passed; and red when `task log` says its agent is stuck or has stopped,
|
|
517
|
+
or that a pull request of the card's is closed, in conflict or unwatched.
|
|
518
|
+
`start` has no dots: it says how many approved cards are held, their work
|
|
519
|
+
not yet started. The section draws what `task log <space> --json` counts,
|
|
520
|
+
and updates on its own. See
|
|
521
|
+
[herdr/README.md](herdr/README.md#the-step-counts-section).
|
|
522
|
+
|
|
508
523
|
`task start` starts the work, once you have approved the card. It takes the
|
|
509
524
|
card too, makes a branch and a git worktree of it in every repo of the
|
|
510
525
|
space, opens a tab for it, and starts the agent there that runs the build
|
|
@@ -885,7 +900,7 @@ read afterwards. It is off until you turn it on, and works on macOS only.
|
|
|
885
900
|
|
|
886
901
|
```sh
|
|
887
902
|
ocnus host on # turn recording on
|
|
888
|
-
ocnus host report [<period>] # how often CPU, memory and disk were at their limit,
|
|
903
|
+
ocnus host report [<period>] # how often CPU, memory and disk were at their limit, what used the most, and where the steps' time went
|
|
889
904
|
ocnus host off # turn it off, and delete every reading
|
|
890
905
|
ocnus host # whether recording is on, and what it has
|
|
891
906
|
ocnus tests run <command> # run a test command, and record the test run
|
|
@@ -956,31 +971,7 @@ and disk it says how much of the recorded time it was at its limit: the CPU
|
|
|
956
971
|
at least 90% busy across all cores, memory pressure at warning or critical,
|
|
957
972
|
or under 10% of the home folder's disk free. Time with no reading, such as
|
|
958
973
|
when no agent was open, is shown as missing, never as idle. It also says how
|
|
959
|
-
much of the CPU recording used, watching the test runs included. Then
|
|
960
|
-
each number of agents working at once, from none up, it says how long that
|
|
961
|
-
many were working and how much of that time the CPU or memory was at its
|
|
962
|
-
limit. It names the fewest working at which that was at least a quarter of
|
|
963
|
-
the time, as the number from which the host was the limit, so you can tell
|
|
964
|
-
how many agents to run at once, or says the host was not the limit at any
|
|
965
|
-
number. Readings from before the agents working were counted are left out
|
|
966
|
-
of these figures, and their time is counted on a line of its own. Under
|
|
967
|
-
each number from 2 up, it says how much slower test runs were than with one
|
|
968
|
-
agent working, as a percentage, such as `test runs 30% slower than with 1
|
|
969
|
-
working, from 3 runs of 1 command against 3 with 1 working`. It sets only
|
|
970
|
-
runs of the same command in the same repo against each other, and a command
|
|
971
|
-
counts only once it has run at least 3 times with that many working and 3
|
|
972
|
-
times with one; with none that has, it says it cannot tell yet. A test run
|
|
973
|
-
counts at the number of agents working for most of its time. Runs cut
|
|
974
|
-
short, runs from before the fingerprints were kept, and runs while no
|
|
975
|
-
reading counted the agents working are left out. Then it names the 5
|
|
976
|
-
longest stretches in the period when the CPU or memory was at its limit,
|
|
977
|
-
longest first: when each started, how long it lasted and which of the two
|
|
978
|
-
was at its limit, then every card going then, with its step, or its phase
|
|
979
|
-
when it was in none, and every test run going then, each with its share of
|
|
980
|
-
all cores over the stretch and the most memory it held. Each card also says
|
|
981
|
-
for how much of the stretch its agent was working. With none, it says the
|
|
982
|
-
host was never at its limit for CPU or memory. Disk is not among them: a
|
|
983
|
-
full disk is not caused by a moment's work. Then it lists the
|
|
974
|
+
much of the CPU recording used, watching the test runs included. Then it lists the
|
|
984
975
|
10 steps and the 10 phases that used the most CPU time in the period, and
|
|
985
976
|
the 10 of each that held the most memory at once, each one card's own, such
|
|
986
977
|
as LAB-150's build step, with how long it ran. Then come the 10 test runs
|
|
@@ -990,34 +981,6 @@ Then it says where the steps' time went: the agents' time in all on the
|
|
|
990
981
|
host, waiting on the model and the rest, then the same for the 10 steps open
|
|
991
982
|
longest, each one card's own, such as LAB-152's build step, and how many
|
|
992
983
|
steps had no split.
|
|
993
|
-
|
|
994
|
-
Then it says whether the network may be the cause, as a slow wait on the
|
|
995
|
-
model can be the network rather than the host. A wait is slow when it took
|
|
996
|
-
over twice the median of every wait on the model recorded, up to 90 days.
|
|
997
|
-
When waits that ended in the period were slow while CPU, memory and disk
|
|
998
|
-
were all below their limit, in every reading over the wait, it says so:
|
|
999
|
-
`The network may be the cause: 14 of 120 waits on the model were slow (over
|
|
1000
|
-
twice the median of 6.2s) while CPU, memory and disk were below their
|
|
1001
|
-
limit.` A slow wait with no reading over it does not count. With none, it
|
|
1002
|
-
says nothing. It cannot tell a slow network from a slow model.
|
|
1003
|
-
|
|
1004
|
-
Last comes the verdict, one line with the numbers behind it, so that money
|
|
1005
|
-
goes on what slows the agents' work on the host. It weighs each reading by
|
|
1006
|
-
the agents' time on the host in it, the seconds their tools ran, an agent's
|
|
1007
|
-
second each, from the splits. With fewer than 10 steps with their time
|
|
1008
|
-
split in the period, or under 1 hour of the agents' time on the host, there
|
|
1009
|
-
is too little data yet, and it says how many and how long. Otherwise, of
|
|
1010
|
-
CPU, memory and disk, the one at its limit for the most of the agents' time
|
|
1011
|
-
on the host, when that is at least 10% of it, is the one to upgrade first:
|
|
1012
|
-
`upgrade memory first: it was at its limit for 23.0% of the agents' 6h 10m
|
|
1013
|
-
on the host (CPU 8.0%, disk 0.0%)`. When over half of its time at its limit
|
|
1014
|
-
was on battery, in Low Power Mode or with the thermal state at serious or
|
|
1015
|
-
critical, the verdict is that the power state was the limit, in place of an
|
|
1016
|
-
upgrade: plugging in, or letting the machine cool, costs nothing. With none
|
|
1017
|
-
at its limit for 10%, the network was the limit when at least 10% of the
|
|
1018
|
-
period's waits on the model were slow while CPU, memory and disk were below
|
|
1019
|
-
their limit, so that no host upgrade is bought that would not have helped.
|
|
1020
|
-
Otherwise no upgrade is needed.
|
|
1021
984
|
See [herdr/README.md](herdr/README.md#recording-the-host) for what a
|
|
1022
985
|
reading holds.
|
|
1023
986
|
|
package/cli/lib/agents.sh
CHANGED
|
@@ -49,7 +49,11 @@
|
|
|
49
49
|
# is not running, ocnus's watch is not running, or gh could not
|
|
50
50
|
# ask GitHub. That holds whatever the agent in the tab is doing.
|
|
51
51
|
# Otherwise, with ocnus's watch watching, the card shows as it does
|
|
52
|
-
# with no agent state.
|
|
52
|
+
# with no agent state. Such a card is noted as ready to merge when the
|
|
53
|
+
# watch's last pass saw every pull request of the card open and ready
|
|
54
|
+
# (MERGES_READY). That is not an agent state: the log says nothing of
|
|
55
|
+
# it, and only the counts in the list's JSON show it, as the mark
|
|
56
|
+
# ready (counts_sql in handoff.sh).
|
|
53
57
|
# - No card gets an agent state when jq is missing. None but those whose
|
|
54
58
|
# pull requests wait on the human get one when hc is missing, or when
|
|
55
59
|
# neither place can list the space's tabs: herdr-core cannot list its
|
|
@@ -224,12 +228,16 @@ card_seen() {
|
|
|
224
228
|
# subshell. With Herdr's tabs not read (AGENTS_ON 0), only a card whose pull
|
|
225
229
|
# requests wait on the human has anything to say: with no tab to look in, no
|
|
226
230
|
# agent is running.
|
|
231
|
+
#
|
|
232
|
+
# AGENT_READY is 1 for a card ready to merge: its pull requests wait on the
|
|
233
|
+
# human, it has no agent state, and ocnus's watch says they are ready
|
|
234
|
+
# (merges_seen). It is 0 for any other card, and AGENT_JSON is null with it.
|
|
227
235
|
# card_agent <card> <the card in lower case> <step> <status> <next>
|
|
228
236
|
# <seconds since the hand-off> <space>
|
|
229
|
-
AGENT_JSON=null AGENT_LABEL='' AGENT_FOR=''
|
|
237
|
+
AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0
|
|
230
238
|
card_agent() {
|
|
231
239
|
local card=$1 low=$2 step=$3 status=$4 next=$5 since=$6 space=$7
|
|
232
|
-
AGENT_JSON=null AGENT_LABEL='' AGENT_FOR=''
|
|
240
|
+
AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0
|
|
233
241
|
# Its pull requests wait on the human.
|
|
234
242
|
local waits=0
|
|
235
243
|
[ "$step $status" != 'pr needs-human' ] || waits=1
|
|
@@ -280,6 +288,9 @@ card_agent() {
|
|
|
280
288
|
names=${names:+$names, }$PULL_NAME
|
|
281
289
|
done
|
|
282
290
|
;;
|
|
291
|
+
# Nothing to say of its agent or its pull requests: it is ready to
|
|
292
|
+
# merge when the watch says so.
|
|
293
|
+
'') AGENT_READY=$MERGES_READY ;;
|
|
283
294
|
esac
|
|
284
295
|
fi
|
|
285
296
|
|
|
@@ -318,18 +329,20 @@ card_agent() {
|
|
|
318
329
|
}
|
|
319
330
|
|
|
320
331
|
# Work out the agent of every card in a view of the log, as AGENTS_SQL: the
|
|
321
|
-
# SQL for the table agents (card, agent) that the log's query joins,
|
|
322
|
-
# each card whose agent has something to say and its JSON
|
|
323
|
-
#
|
|
324
|
-
#
|
|
325
|
-
#
|
|
326
|
-
#
|
|
332
|
+
# SQL for the table agents (card, agent, ready) that the log's query joins,
|
|
333
|
+
# with each card whose agent has something to say and its JSON, with ready
|
|
334
|
+
# 0, and each card ready to merge, which has no agent state: its agent is
|
|
335
|
+
# null and its ready 1, for the list's counts (counts_sql in handoff.sh).
|
|
336
|
+
# The space's tabs are read here, once. AGENT_NOW is the last agent's label
|
|
337
|
+
# and how long it has been so, as the list shows them, for the `now:` line
|
|
338
|
+
# of the log of one card. Nothing is worked out without jq, which reads hc's
|
|
339
|
+
# answers, as ocnus's watch on the merges needs it to run.
|
|
327
340
|
# agents_table <view> <space> <the space's folder>
|
|
328
|
-
AGENTS_SQL='agents (card, agent) as (select null, null where 0)'
|
|
341
|
+
AGENTS_SQL='agents (card, agent, ready) as (select null, null, null where 0)'
|
|
329
342
|
AGENT_NOW=''
|
|
330
343
|
agents_table() {
|
|
331
344
|
local view=$1 name=$2 dir=$3 rows sep=$'\x1f' card low step status next since values='' only=''
|
|
332
|
-
AGENTS_SQL='agents (card, agent) as (select null, null where 0)' AGENT_NOW=''
|
|
345
|
+
AGENTS_SQL='agents (card, agent, ready) as (select null, null, null where 0)' AGENT_NOW=''
|
|
333
346
|
[ -n "$view" ] || return 0
|
|
334
347
|
command -v jq >/dev/null 2>&1 || return 0
|
|
335
348
|
agents_read "$name" "$dir"
|
|
@@ -341,10 +354,13 @@ agents_table() {
|
|
|
341
354
|
from shown where after is null $only order by id;") || return 0
|
|
342
355
|
while IFS=$sep read -r card low step status next since; do
|
|
343
356
|
[ -n "$card" ] || continue
|
|
344
|
-
card_agent "$card" "$low" "$step" "$status" "$next" "$since" "$name" || AGENT_JSON=null
|
|
345
|
-
[ "$AGENT_JSON" != null ]
|
|
346
|
-
|
|
347
|
-
|
|
357
|
+
card_agent "$card" "$low" "$step" "$status" "$next" "$since" "$name" || AGENT_JSON=null AGENT_READY=0
|
|
358
|
+
if [ "$AGENT_JSON" != null ]; then
|
|
359
|
+
values="$values${values:+, }($(sql_str "$card"), $(sql_str "$AGENT_JSON"), 0)"
|
|
360
|
+
AGENT_NOW="$AGENT_LABEL, for $AGENT_FOR"
|
|
361
|
+
elif [ "$AGENT_READY" = 1 ]; then
|
|
362
|
+
values="$values${values:+, }($(sql_str "$card"), null, 1)"
|
|
363
|
+
fi
|
|
348
364
|
done <<< "$rows"
|
|
349
|
-
[ -z "$values" ] || AGENTS_SQL="agents (card, agent) as (values $values)"
|
|
365
|
+
[ -z "$values" ] || AGENTS_SQL="agents (card, agent, ready) as (values $values)"
|
|
350
366
|
}
|
package/cli/lib/github.sh
CHANGED
|
@@ -8,12 +8,18 @@
|
|
|
8
8
|
# GitHub is asked once a minute, however many cards wait, in however many
|
|
9
9
|
# spaces and repos. The call names each worktree's repo, from its origin
|
|
10
10
|
# (github_repo), and its branch, and asks for that branch's newest pull
|
|
11
|
-
# request
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
11
|
+
# request, with whether it can be merged and what its checks came to. Its
|
|
12
|
+
# answer is read by these rules (GITHUB_READ): only the newest pull request
|
|
13
|
+
# counts, an open one that GitHub says conflicts with its default branch is
|
|
14
|
+
# conflict, and one whose mergeable is still UNKNOWN, while GitHub works
|
|
15
|
+
# that out, is open. An open one is ready to merge, ready, when GitHub says
|
|
16
|
+
# that it can be merged, MERGEABLE, and that every check on its newest
|
|
17
|
+
# commit passed: its statusCheckRollup, which sums up its check runs and
|
|
18
|
+
# commit statuses, is SUCCESS, or null, as for a pull request with no
|
|
19
|
+
# checks. It is open while a check is pending, and once one has failed. A
|
|
20
|
+
# review that the repo's rules ask for is not a check, so ready does not say
|
|
21
|
+
# that GitHub would let it merge. Asking GitHub sits here alone, so that
|
|
22
|
+
# another host, such as GitLab, can sit beside it later.
|
|
17
23
|
#
|
|
18
24
|
# `gh search prs` asks across repos too, but it cannot say whether an open
|
|
19
25
|
# pull request is in conflict.
|
|
@@ -47,18 +53,24 @@ github_repo() {
|
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
# GitHub's answer to github_ask's call, read as one line for each branch it
|
|
50
|
-
# asked about, p0 to p<$n - 1>, in order: merged, open, closed or
|
|
51
|
-
# then the pull request's URL; none when the branch has none; or
|
|
52
|
-
# GitHub's words when it answered that repo with an error, such
|
|
53
|
-
# cannot find. A closed pull request is closed, whatever GitHub
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
+
# asked about, p0 to p<$n - 1>, in order: merged, ready, open, closed or
|
|
57
|
+
# conflict, then the pull request's URL; none when the branch has none; or
|
|
58
|
+
# failed and GitHub's words when it answered that repo with an error, such
|
|
59
|
+
# as one it cannot find. A closed pull request is closed, whatever GitHub
|
|
60
|
+
# says of its conflicts, and an open one is ready only when it can be merged
|
|
61
|
+
# and its checks passed, or it has none. An error that GitHub gives for a
|
|
62
|
+
# pull request's checks alone, as when gh's token may not read them, fails
|
|
63
|
+
# nothing: the pull request is read without them, so an open one is open,
|
|
64
|
+
# never ready, and a merged one is still merged. An answer that is empty, or
|
|
65
|
+
# holds no data, is an error, so that the whole call counts as failed.
|
|
56
66
|
GITHUB_READ='input
|
|
57
67
|
| if (.data | type) != "object" then error("no data") else . end
|
|
58
68
|
| . as $all
|
|
59
69
|
| ($all.errors // []) as $errors
|
|
60
70
|
| range(0; $n) | "p\(.)" as $alias
|
|
61
|
-
|
|
|
71
|
+
| [$errors[] | select((.path // [])[0] == $alias)] as $mine
|
|
72
|
+
| ([$mine[] | select(any(.path[]; . == "statusCheckRollup") | not) | .message] | first) as $own
|
|
73
|
+
| any($mine[]; any(.path[]; . == "statusCheckRollup")) as $unchecked
|
|
62
74
|
| $all.data[$alias] as $repo
|
|
63
75
|
| if $own != null then "failed \($own)"
|
|
64
76
|
elif $repo == null then "failed \(([$errors[] | .message] | first) // "GitHub gave no answer for it")"
|
|
@@ -67,6 +79,8 @@ GITHUB_READ='input
|
|
|
67
79
|
elif $pr.state == "MERGED" then "merged \($pr.url)"
|
|
68
80
|
elif $pr.state == "CLOSED" then "closed \($pr.url)"
|
|
69
81
|
elif $pr.state == "OPEN" and $pr.mergeable == "CONFLICTING" then "conflict \($pr.url)"
|
|
82
|
+
elif $pr.state == "OPEN" and $pr.mergeable == "MERGEABLE" and ($unchecked | not)
|
|
83
|
+
and ($pr.statusCheckRollup == null or $pr.statusCheckRollup.state == "SUCCESS") then "ready \($pr.url)"
|
|
70
84
|
else "open \($pr.url)" end
|
|
71
85
|
end
|
|
72
86
|
| split("\r") | join(" ") | split("\n") | join(" ")'
|
|
@@ -83,11 +97,13 @@ GITHUB_CALL_WHY=''
|
|
|
83
97
|
# or in calls of GITHUB_BATCH when more are given. Each line on stdin is a
|
|
84
98
|
# key, which holds no space, the worktree, and its branch, with the unit
|
|
85
99
|
# separator between them. It prints a line for each, in the same order:
|
|
86
|
-
# <key> merged|open|closed|conflict <the pull request's URL>
|
|
100
|
+
# <key> merged|ready|open|closed|conflict <the pull request's URL>
|
|
87
101
|
# <key> none the branch has no pull request
|
|
88
102
|
# <key> failed <the worktree's folder>: <why>
|
|
89
|
-
#
|
|
90
|
-
#
|
|
103
|
+
# ready is an open pull request that can be merged and whose checks passed
|
|
104
|
+
# (GITHUB_READ). A call that fails as a whole, such as with GitHub out of
|
|
105
|
+
# reach, fails every line it asked about, with gh's words, which
|
|
106
|
+
# GITHUB_CALL_WHY keeps.
|
|
91
107
|
# GITHUB_SIGN_IN is 1 then when gh needs signing in: it exits 4 when it has
|
|
92
108
|
# no sign-in (gh help exit-codes), and names HTTP 401 when GitHub refuses its
|
|
93
109
|
# token. A repo that GitHub answers with an error fails only its own lines,
|
|
@@ -133,7 +149,7 @@ github_ask() {
|
|
|
133
149
|
at+=("$i")
|
|
134
150
|
lines[i]="failed ${wts[i]##*/}: its answer could not be read"
|
|
135
151
|
vars="$vars, \$o$n: String!, \$n$n: String!, \$b$n: String!"
|
|
136
|
-
body="$body p$n: repository(owner: \$o$n, name: \$n$n) { pullRequests(headRefName: \$b$n, states: [OPEN, CLOSED, MERGED], first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { url state mergeable } } }"
|
|
152
|
+
body="$body p$n: repository(owner: \$o$n, name: \$n$n) { pullRequests(headRefName: \$b$n, states: [OPEN, CLOSED, MERGED], first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { url state mergeable statusCheckRollup { state } } } }"
|
|
137
153
|
args+=(-f "o$n=$owner" -f "n$n=$name" -f "b$n=$branch")
|
|
138
154
|
n=$((n + 1))
|
|
139
155
|
done
|
package/cli/lib/handoff.sh
CHANGED
|
@@ -343,7 +343,8 @@ merge_linear() {
|
|
|
343
343
|
# the merges folder beside the store, merges/.alive, the time its latest pass
|
|
344
344
|
# began, and merges/<space>/<card>, the time and what that pass saw of the
|
|
345
345
|
# card's pull requests. They are never rows in the store, and nothing in the
|
|
346
|
-
# log reads them but the agent
|
|
346
|
+
# log reads them but the agent, and the counts in the list's JSON, which mark
|
|
347
|
+
# each card from the same table (counts_sql).
|
|
347
348
|
|
|
348
349
|
# SQL for a number of seconds as text: 50s, 1m 44s, 1h 02m, 3d 04h. @ stands
|
|
349
350
|
# for the column that holds the seconds.
|
|
@@ -413,10 +414,86 @@ log_view() {
|
|
|
413
414
|
|
|
414
415
|
LOG_USAGE='usage: ocnus task log <space> [<card>] [--json]'
|
|
415
416
|
|
|
417
|
+
# The steps a card can stand on, in the order a card goes through them: the
|
|
418
|
+
# seven that the Step counts section in Herdr lists. merged is not one of
|
|
419
|
+
# them: a card whose pull requests have merged stands on no step.
|
|
420
|
+
COUNT_STEPS='define plan breakdown start build review pr'
|
|
421
|
+
|
|
422
|
+
# How many of the space's cards stand on each of COUNT_STEPS, and how each
|
|
423
|
+
# card's agent is doing, for the list's JSON: its counts, which the Step
|
|
424
|
+
# counts section in Herdr draws, holding no rules of its own. It prints the
|
|
425
|
+
# SQL for the table counted (step, nth, count, marks), a row for each step,
|
|
426
|
+
# with nth its place among them. It reads the tables latest, each card's
|
|
427
|
+
# latest row, and agents, what Herdr and ocnus's watch say of each card
|
|
428
|
+
# (agents.sh), so it follows them in the query.
|
|
429
|
+
#
|
|
430
|
+
# A card stands on the step that comes next when its latest hand-off is
|
|
431
|
+
# done, with setup, start's old name, counted as start, and on that
|
|
432
|
+
# hand-off's own step otherwise: the step that asked, was answered or
|
|
433
|
+
# failed. So a card whose next step is merged stands on no step.
|
|
434
|
+
#
|
|
435
|
+
# count is how many cards stand on the step, and marks is a JSON list with a
|
|
436
|
+
# mark for each of them. A card's mark is the first of these that holds:
|
|
437
|
+
# - none, at start: the card is held, approved with its work not started,
|
|
438
|
+
# whatever the agent of its write-up phase is doing
|
|
439
|
+
# - needs-human its agent is blocked on a prompt in its tab
|
|
440
|
+
# - stuck its agent has any other state, as the log says it: it hit
|
|
441
|
+
# an error, stopped without handing off or is not running,
|
|
442
|
+
# or a pull request of the card's is closed, in conflict or
|
|
443
|
+
# unwatched; or its step failed
|
|
444
|
+
# - ready it waits on the human at pr, and ocnus's watch says its
|
|
445
|
+
# pull requests are ready to merge (the agents table's ready)
|
|
446
|
+
# - needs-human it waits on the human
|
|
447
|
+
# - working anything else: its step is under way
|
|
448
|
+
# A step's marks come most urgent first: stuck, needs-human, ready, working.
|
|
449
|
+
counts_sql() {
|
|
450
|
+
local s n=0 steps=''
|
|
451
|
+
for s in $COUNT_STEPS; do
|
|
452
|
+
n=$((n + 1))
|
|
453
|
+
steps="$steps${steps:+, }('$s', $n)"
|
|
454
|
+
done
|
|
455
|
+
printf "steps (step, nth) as (values %s),
|
|
456
|
+
placed as (
|
|
457
|
+
select status, json_extract(agent, '\$.state') as doing, coalesce(ready, 0) as ready,
|
|
458
|
+
case when status = 'done' then case when next = 'setup' then 'start' else next end
|
|
459
|
+
else step end as stand
|
|
460
|
+
from latest left join agents using (card)),
|
|
461
|
+
marked as (
|
|
462
|
+
select stand,
|
|
463
|
+
case when stand = 'start' then null
|
|
464
|
+
when doing = 'blocked' then 'needs-human'
|
|
465
|
+
when doing is not null or status = 'failed' then 'stuck'
|
|
466
|
+
when status = 'needs-human' and stand = 'pr' and ready = 1 then 'ready'
|
|
467
|
+
when status = 'needs-human' then 'needs-human'
|
|
468
|
+
else 'working' end as mark
|
|
469
|
+
from placed),
|
|
470
|
+
counted as (
|
|
471
|
+
select steps.step, nth, (select count(*) from marked where stand = steps.step) as count,
|
|
472
|
+
(select json_group_array(mark) from (
|
|
473
|
+
select mark from marked where stand = steps.step and mark is not null
|
|
474
|
+
order by case mark when 'stuck' then 1 when 'needs-human' then 2 when 'ready' then 3 else 4 end)) as marks
|
|
475
|
+
from steps)" "$steps"
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
# The counts of a space with no card on any step, as the list's JSON gives
|
|
479
|
+
# them, for a machine with no store yet: every step with 0 and no marks. A
|
|
480
|
+
# step's text is its count, and start's how many cards are held.
|
|
481
|
+
counts_none() {
|
|
482
|
+
local s text out=''
|
|
483
|
+
for s in $COUNT_STEPS; do
|
|
484
|
+
text=0
|
|
485
|
+
[ "$s" != start ] || text='0 held'
|
|
486
|
+
out="$out${out:+,}{\"step\":\"$s\",\"count\":0,\"marks\":[],\"text\":\"$text\"}"
|
|
487
|
+
done
|
|
488
|
+
printf '[%s]' "$out"
|
|
489
|
+
}
|
|
490
|
+
|
|
416
491
|
# The space's cards that have hand-offs, newest first by their latest row:
|
|
417
492
|
# where each stands and how long it has stood there, or what its agent is
|
|
418
493
|
# doing when Herdr says it is stuck or has stopped. With --json, the same as
|
|
419
|
-
# one line of JSON, with the agent beside where the card stands
|
|
494
|
+
# one line of JSON, with the agent beside where the card stands, and then
|
|
495
|
+
# counts: the seven steps in order, each with how many cards stand on it, a
|
|
496
|
+
# mark for each card and its text (counts_sql).
|
|
420
497
|
# log_cards <space> <json: 1 or 0> <view>
|
|
421
498
|
log_cards() {
|
|
422
499
|
local name=$1 json=$2 list
|
|
@@ -426,17 +503,21 @@ log_cards() {
|
|
|
426
503
|
from shown where after is null), $AGENTS_SQL"
|
|
427
504
|
if [ "$json" = 1 ]; then
|
|
428
505
|
if [ ! -e "$STORE" ]; then
|
|
429
|
-
printf '{"space":"%s","cards":[]}\n' "$(json_str "$name")"
|
|
506
|
+
printf '{"space":"%s","cards":[],"counts":%s}\n' "$(json_str "$name")" "$(counts_none)"
|
|
430
507
|
return
|
|
431
508
|
fi
|
|
432
|
-
store "$STORE" "$list
|
|
509
|
+
store "$STORE" "$list, $(counts_sql)
|
|
433
510
|
select json_object('space', $(sql_str "$name"),
|
|
434
511
|
'cards', (select json_group_array(json(c)) from (
|
|
435
512
|
select json_object('card', card, 'at', at, 'state', state,
|
|
436
513
|
'waiting', nullif(waiting, ''), 'for', $(sql_took since), 'seconds', since,
|
|
437
514
|
'run', run, 'step', step, 'status', status, 'next', next,
|
|
438
515
|
'agent', json(agent)) as c
|
|
439
|
-
from latest left join agents using (card) order by at desc, id desc))
|
|
516
|
+
from latest left join agents using (card) order by at desc, id desc)),
|
|
517
|
+
'counts', (select json_group_array(json(c)) from (
|
|
518
|
+
select json_object('step', step, 'count', count, 'marks', json(marks),
|
|
519
|
+
'text', case when step = 'start' then count || ' held' else '' || count end) as c
|
|
520
|
+
from counted order by nth)));" ||
|
|
440
521
|
die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
441
522
|
return
|
|
442
523
|
fi
|