@johngaynor/ocnus 2.0.1-next.7 → 2.0.1-next.71
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 +506 -93
- package/cli/lib/agents.sh +32 -16
- package/cli/lib/asks.sh +762 -0
- package/cli/lib/banner.sh +181 -0
- package/cli/lib/brief.sh +375 -0
- package/cli/lib/chain.sh +363 -0
- package/cli/lib/close.sh +5 -3
- package/cli/lib/cost.sh +500 -0
- package/cli/lib/finish.sh +30 -4
- package/cli/lib/github.sh +106 -26
- package/cli/lib/guard.sh +39 -10
- package/cli/lib/handoff.sh +196 -31
- package/cli/lib/host.sh +186 -345
- package/cli/lib/linear.sh +552 -56
- package/cli/lib/links.sh +6 -3
- package/cli/lib/merges.sh +126 -27
- package/cli/lib/sessions.sh +132 -0
- package/cli/lib/settings.sh +31 -15
- package/cli/lib/task.sh +169 -54
- package/cli/lib/tests.sh +302 -7
- package/cli/lib/usage.sh +204 -0
- package/cli/ocnus +264 -72
- package/herdr/README.md +867 -223
- package/herdr/layouts/default.json +30 -11
- package/herdr/layouts/showcase.json +291 -0
- package/herdr/layouts/vibe.json +162 -0
- package/herdr/layouts/vibe.svg +41 -0
- package/herdr/mods/agent-settings/main.js +19 -7
- package/herdr/mods/memory/main.js +128 -0
- package/herdr/mods/memory/mod.json +1 -0
- package/herdr/mods/memory/reading.js +88 -0
- package/herdr/mods/names/main.js +22 -4
- package/herdr/mods/step-counts/main.js +281 -0
- package/herdr/mods/step-counts/mod.json +1 -0
- package/herdr/mods/usage/main.js +149 -0
- package/herdr/mods/usage/mod.json +1 -0
- package/package.json +1 -1
- package/prompts/task-new.md +1 -1
- package/skills/brief/SKILL.md +8 -0
- package/skills/sdlc-breakdown/SKILL.md +66 -18
- package/skills/sdlc-build/SKILL.md +6 -2
- package/skills/sdlc-pr/SKILL.md +2 -2
- package/skills/sdlc-review/SKILL.md +5 -5
package/cli/lib/host.sh
CHANGED
|
@@ -33,9 +33,7 @@
|
|
|
33
33
|
# turn, as herdr-core's status for its terminal says, and waiting while it is
|
|
34
34
|
# open but its turn has ended, it waits on the human in its tab, it hit an
|
|
35
35
|
# error, or it reports no status. A tab that holds its shell alone is not
|
|
36
|
-
# open, so it is neither.
|
|
37
|
-
# working, how much of the time the host was at its limit, and from which
|
|
38
|
-
# number the host was the limit.
|
|
36
|
+
# open, so it is neither.
|
|
39
37
|
#
|
|
40
38
|
# Beside the readings go the test runs: each run of a repo's tests that an
|
|
41
39
|
# agent starts through `ocnus tests run` (tests.sh), with its card and
|
|
@@ -43,16 +41,12 @@
|
|
|
43
41
|
# memory it held at once. A test run is named by its card and repo alone.
|
|
44
42
|
# Its command is kept only as a fingerprint, a number the same for the same
|
|
45
43
|
# command and from which its text cannot be read back, and nothing else of
|
|
46
|
-
# its command line is kept. `host report` ranks the test runs too
|
|
47
|
-
# runs of the same command in the same repo against each other to say how
|
|
48
|
-
# much slower they were with more agents working.
|
|
44
|
+
# its command line is kept. `host report` ranks the test runs too.
|
|
49
45
|
#
|
|
50
46
|
# With each reading go the shares of the test runs going then, too, each
|
|
51
47
|
# worked out as a terminal's is, from the processes under the run's job,
|
|
52
48
|
# which are in their terminal's share as well. A run that ended since the
|
|
53
|
-
# reading before gets the rest of its CPU in the next one.
|
|
54
|
-
# names the cards' steps and the test runs going in the longest stretches
|
|
55
|
-
# when the CPU or memory was at its limit.
|
|
49
|
+
# reading before gets the rest of its CPU in the next one.
|
|
56
50
|
#
|
|
57
51
|
# While recording is on, `task new` and `task build` start claude with hooks
|
|
58
52
|
# that mark its agent's time (host_hooks): cli/host-mark appends a word and
|
|
@@ -64,16 +58,15 @@
|
|
|
64
58
|
# those marks (host_splits): on the host, while its tools run, and waiting
|
|
65
59
|
# on the model. The rest of the time its agent was open is neither, such as
|
|
66
60
|
# waiting on the human. `host report` says where the steps' time went by
|
|
67
|
-
# them
|
|
68
|
-
# the agents' time on the host in it: what to upgrade first, if anything.
|
|
61
|
+
# them.
|
|
69
62
|
#
|
|
70
63
|
# From the same marks, each wait on the model is kept too, as its start and
|
|
71
|
-
# end alone, by the reading it ended in.
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
64
|
+
# end alone, by the reading it ended in.
|
|
65
|
+
#
|
|
66
|
+
# `host report --card <space> <card> --json` gives a program the readings
|
|
67
|
+
# taken while each of a card's steps ran, as one line of JSON (host_card):
|
|
68
|
+
# the whole host's CPU and memory, with each step's start and end from the
|
|
69
|
+
# hand-off store, which it only reads.
|
|
77
70
|
#
|
|
78
71
|
# A share's card, phase and step, a split's, a wait's, and a test run's card
|
|
79
72
|
# and repo, are the only text the readings hold, and only the values
|
|
@@ -215,7 +208,7 @@ host_table() {
|
|
|
215
208
|
[ -z "$sql" ] || store "$HOST_DB" "begin; ${sql}commit;"
|
|
216
209
|
}
|
|
217
210
|
|
|
218
|
-
HOST_USAGE='usage: ocnus host [on|off|report [<period>]] (see: ocnus help)'
|
|
211
|
+
HOST_USAGE='usage: ocnus host [on|off|report [<period>]|report --card <space> <card> --json] (see: ocnus help)'
|
|
219
212
|
HOST_PERIODS='a period is <n>d or <n>h back from now, like 7d or 12h; a day, like 2026-11-29; or two days and every day between, like 2026-11-01..2026-11-29'
|
|
220
213
|
|
|
221
214
|
# --- on and off -------------------------------------------------------------
|
|
@@ -1218,11 +1211,15 @@ host_day() {
|
|
|
1218
1211
|
|
|
1219
1212
|
# How the CPU, memory and disk were, over a period: how much of the time it
|
|
1220
1213
|
# was recorded, and how much of that each was at its limit. Time with no
|
|
1221
|
-
# reading is shown as missing, never as idle.
|
|
1222
|
-
#
|
|
1223
|
-
# the
|
|
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).
|
|
1224
1217
|
host_report() {
|
|
1225
|
-
local period=${1:-7d} now start end n first last row works
|
|
1218
|
+
local period=${1:-7d} now start end n first last row works splits
|
|
1219
|
+
# A card's readings, as JSON, are a form of their own.
|
|
1220
|
+
for n in "$@"; do
|
|
1221
|
+
case $n in --card | --json) host_card "$@"; return ;; esac
|
|
1222
|
+
done
|
|
1226
1223
|
[ "$#" -le 1 ] || die "$HOST_USAGE"
|
|
1227
1224
|
now=$(date +%s)
|
|
1228
1225
|
case $period in
|
|
@@ -1262,38 +1259,20 @@ host_report() {
|
|
|
1262
1259
|
say "Recording is on, and takes a reading every $HOST_EVERY seconds while an ocnus agent is open."
|
|
1263
1260
|
return 0
|
|
1264
1261
|
fi
|
|
1265
|
-
# A store the recorder has not opened since the
|
|
1266
|
-
# test runs and
|
|
1267
|
-
#
|
|
1268
|
-
#
|
|
1269
|
-
# the power state how many of its 3 columns it has. The report only reads
|
|
1270
|
-
# the store, so it never adds them, and leaves out what is missing.
|
|
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.
|
|
1271
1266
|
row=$(store "$HOST_DB" "select (select count(*) from pragma_table_info('readings') where name = 'cores')
|
|
1272
1267
|
|| (select count(*) from sqlite_master where type = 'table' and name = 'shares')
|
|
1273
1268
|
|| (select count(*) from sqlite_master where type = 'table' and name = 'test_runs')
|
|
1274
|
-
|| (select count(*) from sqlite_master where type = 'table' and name = '
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|| (select count(*) from pragma_table_info('test_runs') where name = 'cmd')
|
|
1280
|
-
|| (select count(*) from sqlite_master where type = 'table' and name = 'model_waits');") || row=
|
|
1281
|
-
works=0 runs=0 working=0 shared=0 splits=0 power=0 slower=0 waits=0
|
|
1282
|
-
case $row in ?1????????) works=1 ;; esac
|
|
1283
|
-
case $row in ??11??????) runs=1 ;; esac
|
|
1284
|
-
case $row in ????1?????) working=1 ;; esac
|
|
1285
|
-
case $row in ?1???1????) shared=1 ;; esac
|
|
1286
|
-
case $row in ?1????1???) splits=1 ;; esac
|
|
1287
|
-
case $row in ???????3??) power=1 ;; esac
|
|
1288
|
-
case $row in ????1???1?) slower=1 ;; esac
|
|
1289
|
-
case $row in ?????????1) waits=1 ;; esac
|
|
1290
|
-
case $row in 111???????) row=1 ;; *) row=0 ;; esac
|
|
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
|
|
1291
1274
|
store "$HOST_DB" "$(host_report_sql "$start" "$end" "$period" "$row")" ||
|
|
1292
1275
|
die "could not read $HOST_DB"
|
|
1293
|
-
store "$HOST_DB" "$(host_working_sql "$start" "$end" "$working" "$slower")" ||
|
|
1294
|
-
die "could not read $HOST_DB"
|
|
1295
|
-
store "$HOST_DB" "$(host_peaks_sql "$start" "$end" "$works" "$runs" "$shared")" ||
|
|
1296
|
-
die "could not read $HOST_DB"
|
|
1297
1276
|
if [ "$row" = 1 ]; then
|
|
1298
1277
|
store "$HOST_DB" "$(host_ranks_sql "$start" "$end")" || die "could not read $HOST_DB"
|
|
1299
1278
|
else
|
|
@@ -1301,7 +1280,6 @@ host_report() {
|
|
|
1301
1280
|
say 'No step, phase or test run was recorded in this period.'
|
|
1302
1281
|
fi
|
|
1303
1282
|
store "$HOST_DB" "$(host_split_sql "$start" "$end" "$works" "$splits")" || die "could not read $HOST_DB"
|
|
1304
|
-
store "$HOST_DB" "$(host_verdict_sql "$start" "$end" "$splits" "$power" "$waits")" || die "could not read $HOST_DB"
|
|
1305
1283
|
}
|
|
1306
1284
|
|
|
1307
1285
|
# The report's query, for the period from $1 to $2, named $3. A reading
|
|
@@ -1366,178 +1344,6 @@ select line from lines order by n, k;
|
|
|
1366
1344
|
EOF
|
|
1367
1345
|
}
|
|
1368
1346
|
|
|
1369
|
-
# The agents working at once, from $1 to $2: for each number of agents
|
|
1370
|
-
# working that the readings counted, from none up, how long that many were
|
|
1371
|
-
# working, and how much of that time the CPU or the memory was at its limit,
|
|
1372
|
-
# as the report counts it. Each reading counts for the part of it in the
|
|
1373
|
-
# period. A reading from before the agents working were counted has no
|
|
1374
|
-
# count, and nor has any when $3 is not 1, as the store has no column for
|
|
1375
|
-
# them yet: it is left out, never counted as none working, and its time is
|
|
1376
|
-
# on a line of its own. Last, the fewest working at which the CPU or memory
|
|
1377
|
-
# was at its limit for at least a quarter of the time is named as the number
|
|
1378
|
-
# from which the host was the limit; or it says there is no such number, or
|
|
1379
|
-
# that no reading counted the agents working.
|
|
1380
|
-
#
|
|
1381
|
-
# Under each number from 2 up, with $4 as 1, which says the store has the
|
|
1382
|
-
# fingerprints of the test runs' commands, comes how much slower test runs
|
|
1383
|
-
# were than with one working. A test run that started in the period counts
|
|
1384
|
-
# at the number working that covers most of its time, over the readings
|
|
1385
|
-
# that counted them, and at the larger number on a tie. A run that was cut
|
|
1386
|
-
# short, is still going, has no fingerprint, as one from before they were
|
|
1387
|
-
# kept, or overlaps no reading with a count, is left out. A command is a
|
|
1388
|
-
# repo and a fingerprint, so only runs of the same command in the same repo
|
|
1389
|
-
# are set against each other, and a command counts at a number when it ran
|
|
1390
|
-
# at least 3 times with that many working and 3 times with one. Its ratio is
|
|
1391
|
-
# its runs' median time with that many working over their median time with
|
|
1392
|
-
# one, and the figure is the median of the commands' ratios, so one odd run,
|
|
1393
|
-
# such as one that failed early, does not move it. With no such command, it
|
|
1394
|
-
# says it cannot tell yet.
|
|
1395
|
-
host_working_sql() {
|
|
1396
|
-
local s=$1 e=$2 working=working slower=0 runs='select null, null, null, null, null where 0' counted=null
|
|
1397
|
-
[ "${3:-0}" = 1 ] || working=null
|
|
1398
|
-
if [ "$working" = working ] && [ "${4:-0}" = 1 ]; then
|
|
1399
|
-
slower=1 counted=g.working
|
|
1400
|
-
runs="select id, repo, cmd, started, secs from test_runs
|
|
1401
|
-
where started >= $s and started < $e and ended is not null and cut = 0 and cmd is not null and secs is not null"
|
|
1402
|
-
fi
|
|
1403
|
-
cat <<EOF
|
|
1404
|
-
with
|
|
1405
|
-
parts(n, d, lim) as (
|
|
1406
|
-
select $working, max(0, min(at, $e) - max(at - secs, $s)), coalesce(cpu_busy >= 90 or mem_pressure >= 2, 0)
|
|
1407
|
-
from readings where at > $s and at < $e + $HOST_GAP and at - secs < $e),
|
|
1408
|
-
counts(n, len, lim) as (
|
|
1409
|
-
select n, sum(d), sum(case when lim then d else 0 end) from parts where n is not null group by n),
|
|
1410
|
-
uncounted(len) as (select coalesce(sum(d), 0) from parts where n is null),
|
|
1411
|
-
fewest(n) as (select min(n) from counts where len > 0 and 4 * lim >= len),
|
|
1412
|
-
runs(id, repo, cmd, started, secs) as ($runs),
|
|
1413
|
-
-- A cross join keeps the runs outside, so that each one looks up only its
|
|
1414
|
-
-- own readings by their at, never every reading for each run.
|
|
1415
|
-
over(id, n, d) as (
|
|
1416
|
-
select r.id, $counted, sum(max(0, min(g.at, r.started + r.secs) - max(g.at - g.secs, r.started)))
|
|
1417
|
-
from runs r cross join readings g
|
|
1418
|
-
on g.at > r.started and g.at < r.started + r.secs + $HOST_GAP and g.at - g.secs < r.started + r.secs
|
|
1419
|
-
where $counted is not null group by r.id, $counted),
|
|
1420
|
-
at_n(id, n) as (
|
|
1421
|
-
select id, n from (select id, n, row_number() over (partition by id order by d desc, n desc) k from over) where k = 1),
|
|
1422
|
-
timed(repo, cmd, n, secs, i, c) as (
|
|
1423
|
-
select r.repo, r.cmd, a.n, r.secs, row_number() over (partition by r.repo, r.cmd, a.n order by r.secs),
|
|
1424
|
-
count(*) over (partition by r.repo, r.cmd, a.n)
|
|
1425
|
-
from runs r join at_n a on a.id = r.id),
|
|
1426
|
-
medians(repo, cmd, n, runs, secs) as (
|
|
1427
|
-
select repo, cmd, n, max(c), avg(secs) from timed where i in ((c + 1) / 2, (c + 2) / 2) group by repo, cmd, n),
|
|
1428
|
-
ratios(n, ratio, runs, base, i, c) as (
|
|
1429
|
-
select m.n, m.secs / b.secs, m.runs, b.runs, row_number() over (partition by m.n order by m.secs / b.secs),
|
|
1430
|
-
count(*) over (partition by m.n)
|
|
1431
|
-
from medians m join medians b on b.repo = m.repo and b.cmd = m.cmd and b.n = 1
|
|
1432
|
-
where m.n >= 2 and m.runs >= 3 and b.runs >= 3 and b.secs > 0),
|
|
1433
|
-
slower(n, ratio) as (select n, avg(ratio) from ratios where i in ((c + 1) / 2, (c + 2) / 2) group by n),
|
|
1434
|
-
rested(n, cmds, runs, base) as (select n, count(*), sum(runs), sum(base) from ratios group by n),
|
|
1435
|
-
lines(part, n, o, line) as (
|
|
1436
|
-
select 0, 0, 0, ''
|
|
1437
|
-
union all select 0, 1, 0, 'Agents working at once:'
|
|
1438
|
-
union all
|
|
1439
|
-
select 1, n, 0, ' ' || printf('%-11s', n || ' working') || ' ' || $(sql_took len) || ', CPU or memory at its limit '
|
|
1440
|
-
|| $(sql_took lim) || ', ' || printf('%.1f%%', 100.0 * lim / nullif(len, 0)) || ' of it'
|
|
1441
|
-
from counts
|
|
1442
|
-
union all
|
|
1443
|
-
select 1, c.n, 1, ' test runs' || case when s.ratio is null
|
|
1444
|
-
then ': cannot tell yet, as no command ran at least 3 times with ' || c.n || ' working and 3 times with 1'
|
|
1445
|
-
else ' ' || case when s.ratio >= 1 then printf('%.0f%% slower', 100.0 * (s.ratio - 1))
|
|
1446
|
-
else printf('%.0f%% faster', 100.0 * (1 - s.ratio)) end
|
|
1447
|
-
|| ' than with 1 working, from ' || r.runs || ' runs of ' || r.cmds || case when r.cmds = 1 then ' command' else ' commands' end
|
|
1448
|
-
|| ' against ' || r.base || ' with 1 working' end
|
|
1449
|
-
from counts c left join slower s on s.n = c.n left join rested r on r.n = c.n
|
|
1450
|
-
where c.n >= 2 and $slower
|
|
1451
|
-
union all
|
|
1452
|
-
select 2, 0, 0, ' not counted ' || $(sql_took len) || ', by readings from before the agents working were counted'
|
|
1453
|
-
from uncounted where len > 0
|
|
1454
|
-
union all
|
|
1455
|
-
select 3, 0, 0, case
|
|
1456
|
-
when not exists (select 1 from counts) then ' No reading in this period counted the agents working.'
|
|
1457
|
-
when n is null then ' The host was not the limit at any number of working agents in this period: at each, the CPU or memory was at its limit for under a quarter of the time.'
|
|
1458
|
-
else ' The host was the limit from ' || n || ' working ' || case when n = 1 then 'agent' else 'agents' end
|
|
1459
|
-
|| ': the fewest at which the CPU or memory was at its limit for at least a quarter of the time.' end
|
|
1460
|
-
from fewest)
|
|
1461
|
-
select line from lines order by part, n, o;
|
|
1462
|
-
EOF
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
# The longest stretches from $1 to $2 when the CPU or the memory was at its
|
|
1466
|
-
# limit, as the report counts it, five at most, longest first. A stretch is
|
|
1467
|
-
# readings in a row at the limit, each starting where the one before ended,
|
|
1468
|
-
# and each counts for the part of it in the period, as the report counts a
|
|
1469
|
-
# reading. Each says when it started, how long it lasted and which of the
|
|
1470
|
-
# two was at its limit, then the work going in it: each card's step, or its
|
|
1471
|
-
# phase when its card is in none, from the shares when $3 is 1, then each
|
|
1472
|
-
# test run, from their shares when $4 is 1. Each has its share of all cores
|
|
1473
|
-
# over the stretch, its share in each reading counted for that reading's
|
|
1474
|
-
# part, and the most memory it held in one reading. Each card also has how
|
|
1475
|
-
# much of the stretch its agent was working: the parts of the readings in
|
|
1476
|
-
# which a share of its was working, over the stretch's length. With $5 not 1,
|
|
1477
|
-
# the shares have no column for it, and with no share that says, as from
|
|
1478
|
-
# before the agents working were told apart, it says it was not read. A
|
|
1479
|
-
# share that names no card is left out. With no stretch, it says the host was
|
|
1480
|
-
# never at its limit.
|
|
1481
|
-
host_peaks_sql() {
|
|
1482
|
-
local s=$1 e=$2 shares runs
|
|
1483
|
-
shares='select at, card, phase, step, cpu, mem_mb, working from shares'
|
|
1484
|
-
[ "${5:-0}" = 1 ] || shares='select at, card, phase, step, cpu, mem_mb, null from shares'
|
|
1485
|
-
[ "${3:-0}" = 1 ] || shares='select null, null, null, null, null, null, null where 0'
|
|
1486
|
-
runs='select r.at, r.run, t.card, t.repo, t.started, r.cpu, r.mem_mb from run_shares r join test_runs t on t.id = r.run'
|
|
1487
|
-
[ "${4:-0}" = 1 ] || runs='select null, null, null, null, null, null, null where 0'
|
|
1488
|
-
cat <<EOF
|
|
1489
|
-
with
|
|
1490
|
-
lim(at, start, d, cpu, mem, new) as (
|
|
1491
|
-
select at, max(at - secs, $s), max(0, min(at, $e) - max(at - secs, $s)),
|
|
1492
|
-
coalesce(cpu_busy >= 90, 0), coalesce(mem_pressure >= 2, 0),
|
|
1493
|
-
case when lag(at) over (order by at) = at - secs then 0 else 1 end
|
|
1494
|
-
from readings
|
|
1495
|
-
where at > $s and at < $e + $HOST_GAP and at - secs < $e and (cpu_busy >= 90 or mem_pressure >= 2)),
|
|
1496
|
-
grouped(at, start, d, cpu, mem, n) as (
|
|
1497
|
-
select at, start, d, cpu, mem, sum(new) over (order by at rows between unbounded preceding and current row) from lim),
|
|
1498
|
-
stretches(n, start, len, cpu, mem) as (
|
|
1499
|
-
select n, min(start), sum(d), max(cpu), max(mem) from grouped group by n),
|
|
1500
|
-
ranked(k, n, start, len, cpu, mem) as (
|
|
1501
|
-
select row_number() over (order by len desc, start), n, start, len, cpu, mem from stretches),
|
|
1502
|
-
top(k, n, start, len, cpu, mem) as (select k, n, start, len, cpu, mem from ranked where k <= 5),
|
|
1503
|
-
parts(k, len, at, d) as (select t.k, t.len, g.at, g.d from top t join grouped g on g.n = t.n),
|
|
1504
|
-
sh(at, card, phase, step, cpu, mem, working) as ($shares),
|
|
1505
|
-
rs(at, run, card, repo, started, cpu, mem) as ($runs),
|
|
1506
|
-
cards(k, len, at, d, name, cpu, mem, working) as (
|
|
1507
|
-
select p.k, p.len, p.at, p.d, sh.card || ' ' || coalesce(sh.step || ' step', sh.phase || ' phase'), sum(sh.cpu), sum(sh.mem),
|
|
1508
|
-
max(sh.working)
|
|
1509
|
-
from parts p join sh on sh.at = p.at
|
|
1510
|
-
where sh.card is not null and coalesce(sh.step, sh.phase) is not null
|
|
1511
|
-
group by p.k, p.at, sh.card, sh.step, sh.phase),
|
|
1512
|
-
work(k, part, name, cpu, mem, working) as (
|
|
1513
|
-
select k, 1, name, sum(1.0 * cpu * d) / len, max(mem),
|
|
1514
|
-
case when count(working) > 0 then 100.0 * sum(case when working = 1 then d else 0 end) / len end
|
|
1515
|
-
from cards group by k, name
|
|
1516
|
-
union all
|
|
1517
|
-
select p.k, 2, rs.card || ' ' || rs.repo || ' test run ' || strftime('%Y-%m-%d %H:%M', rs.started, 'unixepoch', 'localtime'),
|
|
1518
|
-
sum(1.0 * rs.cpu * p.d) / p.len, max(rs.mem), null
|
|
1519
|
-
from parts p join rs on rs.at = p.at group by p.k, rs.run),
|
|
1520
|
-
lines(k, part, o, line) as (
|
|
1521
|
-
select -1, 0, 0, ''
|
|
1522
|
-
union all select 0, 0, 0, 'Longest stretches with CPU or memory at its limit:' where exists (select 1 from top)
|
|
1523
|
-
union all select 0, 0, 0, 'The host was never at its limit for CPU or memory in this period.' where not exists (select 1 from top)
|
|
1524
|
-
union all
|
|
1525
|
-
select k, 0, 0, ' ' || strftime('%Y-%m-%d %H:%M:%S', start, 'unixepoch', 'localtime') || ' for ' || $(sql_took len) || ', '
|
|
1526
|
-
|| case when cpu and mem then 'CPU and memory at their limit' when cpu then 'CPU at its limit' else 'memory at its limit' end
|
|
1527
|
-
from top
|
|
1528
|
-
union all
|
|
1529
|
-
select k, part, row_number() over (partition by k, part order by cpu desc, name),
|
|
1530
|
-
' ' || printf('%-44s', name) || ' ' || case when cpu is null then 'CPU not read' else 'CPU ' || printf('%.1f%%', cpu) end
|
|
1531
|
-
|| ', ' || case when mem is null then 'memory not read' else 'memory ' || mem || ' MB' end
|
|
1532
|
-
|| case when part = 2 then '' when working is null then ', working not read'
|
|
1533
|
-
else ', working ' || printf('%.0f%%', working) || ' of it' end
|
|
1534
|
-
from work
|
|
1535
|
-
union all
|
|
1536
|
-
select k, 3, 0, ' no card or test run was going' from top t where not exists (select 1 from work w where w.k = t.k))
|
|
1537
|
-
select line from lines order by k, part, o;
|
|
1538
|
-
EOF
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
1347
|
# The steps and the phases that used the most CPU time, and that held the
|
|
1542
1348
|
# most memory at once, from $1 to $2: ten of each, each one card's own. Each
|
|
1543
1349
|
# counts what its shares say for the part of their reading in the period,
|
|
@@ -1663,131 +1469,166 @@ select line from lines order by k;
|
|
|
1663
1469
|
EOF
|
|
1664
1470
|
}
|
|
1665
1471
|
|
|
1666
|
-
# The
|
|
1667
|
-
#
|
|
1668
|
-
#
|
|
1669
|
-
#
|
|
1472
|
+
# The readings taken while each of a card's steps ran, as one line of JSON:
|
|
1473
|
+
# `host report --card <space> <card> --json`. Anything else it is asked is
|
|
1474
|
+
# refused on stderr, with nothing on stdout, so that a program never reads
|
|
1475
|
+
# words as JSON.
|
|
1670
1476
|
#
|
|
1671
|
-
# A
|
|
1672
|
-
#
|
|
1673
|
-
#
|
|
1674
|
-
#
|
|
1675
|
-
#
|
|
1676
|
-
#
|
|
1677
|
-
#
|
|
1678
|
-
# be the cause: how many of the period's waits were slow while the host was
|
|
1679
|
-
# below its limit, and the median. A store with no waits on the model has
|
|
1680
|
-
# none.
|
|
1477
|
+
# A step is each time the card was in it: hand-offs of one step in a row,
|
|
1478
|
+
# from the hand-off before the first to the last, so the time it waited on
|
|
1479
|
+
# the human is inside it. The times are log_view's, as `task log` shows
|
|
1480
|
+
# them, so the two cannot disagree. A `new` or a `start` row has no time
|
|
1481
|
+
# there, so it has no entry here. The step under way runs to now and is
|
|
1482
|
+
# open: the one the log counts as under way (card_agent in agents.sh), or
|
|
1483
|
+
# one whose question still waits.
|
|
1681
1484
|
#
|
|
1682
|
-
#
|
|
1683
|
-
#
|
|
1684
|
-
#
|
|
1685
|
-
#
|
|
1686
|
-
#
|
|
1687
|
-
#
|
|
1688
|
-
#
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
select
|
|
1790
|
-
|
|
1485
|
+
# A reading counts for its seconds inside the step, as the report counts
|
|
1486
|
+
# one in a period. A step with more than HOST_CARD_POINTS readings is cut
|
|
1487
|
+
# into that many equal parts, to the second, and each part with a reading in
|
|
1488
|
+
# it gives one point: the average CPU and memory over its recorded seconds,
|
|
1489
|
+
# and the worst memory pressure in it. Time with no reading gives no point,
|
|
1490
|
+
# so it is never a number. With recording off, or with no readings kept, the
|
|
1491
|
+
# steps are still listed, each with none.
|
|
1492
|
+
HOST_CARD_POINTS=60
|
|
1493
|
+
HOST_CARD_FORM='ocnus host report --card <space> <card> --json'
|
|
1494
|
+
host_card() {
|
|
1495
|
+
local name='' card='' json=0 asked=0
|
|
1496
|
+
while [ "$#" -gt 0 ]; do
|
|
1497
|
+
case $1 in
|
|
1498
|
+
--json)
|
|
1499
|
+
[ "$json" = 0 ] || die "--json is given once: $HOST_CARD_FORM"
|
|
1500
|
+
json=1
|
|
1501
|
+
;;
|
|
1502
|
+
--card)
|
|
1503
|
+
[ "$asked" = 0 ] || die "--card is given once, for one card: $HOST_CARD_FORM"
|
|
1504
|
+
asked=1
|
|
1505
|
+
case ${2:-} in '' | --*) die "--card takes a space and a card: $HOST_CARD_FORM" ;; esac
|
|
1506
|
+
case ${3:-} in '' | --*) die "--card takes a space and a card: $HOST_CARD_FORM" ;; esac
|
|
1507
|
+
name=$2 card=$3
|
|
1508
|
+
shift 2
|
|
1509
|
+
;;
|
|
1510
|
+
*)
|
|
1511
|
+
[ "$asked" = 1 ] || case " $* " in *' --card '*) asked=1 ;; esac
|
|
1512
|
+
[ "$asked" = 1 ] ||
|
|
1513
|
+
die "--json needs --card: only a card's readings come as JSON, with $HOST_CARD_FORM. The report on a period is in words."
|
|
1514
|
+
die "'$1' does not go with --card: a card's readings are those of its steps, whatever the period. Ask with: $HOST_CARD_FORM"
|
|
1515
|
+
;;
|
|
1516
|
+
esac
|
|
1517
|
+
shift
|
|
1518
|
+
done
|
|
1519
|
+
[ "$asked" = 1 ] ||
|
|
1520
|
+
die "--json needs --card: only a card's readings come as JSON, with $HOST_CARD_FORM. The report on a period is in words."
|
|
1521
|
+
[ "$json" = 1 ] || die "--card needs --json: a card's readings come as JSON alone. Ask with: $HOST_CARD_FORM"
|
|
1522
|
+
space_named "$name" || die "there is no ocnus space called '$name'. See: ocnus space ls"
|
|
1523
|
+
[[ $card =~ $CARD_RE ]] || die "'$card' is not a card ID like ABC-122."
|
|
1524
|
+
card=$(printf '%s' "$card" | tr '[:lower:]' '[:upper:]')
|
|
1525
|
+
have_sqlite || die "$SQLITE is not installed, and the hand-offs and the readings are kept with it."
|
|
1526
|
+
|
|
1527
|
+
local recording=false now uri attach='' out
|
|
1528
|
+
[ ! -d "$HOST_DIR" ] || recording=true
|
|
1529
|
+
# As `task log --json` with no store: the same keys, and no steps.
|
|
1530
|
+
if [ ! -e "$STORE" ]; then
|
|
1531
|
+
printf '{"space":"%s","card":"%s","recording":%s,"steps":[]}\n' "$(json_str "$name")" "$(json_str "$card")" "$recording"
|
|
1532
|
+
return
|
|
1533
|
+
fi
|
|
1534
|
+
now=$(date +%s)
|
|
1535
|
+
# With no readings kept, a table with none stands in for them.
|
|
1536
|
+
local readings='(select 0 as at, 0 as secs, null as cpu_busy, null as mem_used_mb, null as mem_pressure where 0)'
|
|
1537
|
+
if [ -e "$HOST_DB" ]; then
|
|
1538
|
+
# In a URI, % starts an escape, ? the options and # the end.
|
|
1539
|
+
uri=${HOST_DB//\%/%25}; uri=${uri//\?/%3F}; uri=${uri//\#/%23}
|
|
1540
|
+
attach="attach $(sql_str "file:$uri?mode=ro") as host;"
|
|
1541
|
+
readings=host.readings
|
|
1542
|
+
fi
|
|
1543
|
+
# Each table is worked out once, whatever the card's length:
|
|
1544
|
+
# flagged, grouped the card's rows, numbered by the time it was in a step
|
|
1545
|
+
# spans, latest each of those times' first and last row, and the
|
|
1546
|
+
# card's latest row with the step under way, if any
|
|
1547
|
+
# ended, steps the steps, in order, the one under way running to now
|
|
1548
|
+
# inside, counts each reading's seconds inside each step, and how
|
|
1549
|
+
# many readings a step has
|
|
1550
|
+
# spread, pieces for a step to thin, each reading's seconds in each of
|
|
1551
|
+
# the equal parts it reaches: the first and the last of
|
|
1552
|
+
# them are worked out, so no reading is tried against
|
|
1553
|
+
# every part
|
|
1554
|
+
# points, drawn each step's points, and all of them as one array
|
|
1555
|
+
# SQLite builds the JSON, so no value is escaped by hand.
|
|
1556
|
+
out=$(store "$STORE" "$attach
|
|
1557
|
+
$(log_view "$name" "$card"),
|
|
1558
|
+
flagged(id, run, step, kind, status, next, after, t, prev_t, first) as (
|
|
1559
|
+
select id, run, step, kind, status, next, after,
|
|
1560
|
+
cast(strftime('%s', at) as integer), cast(strftime('%s', prev_at) as integer),
|
|
1561
|
+
case when lag(step) over (order by id) is step then 0 else 1 end
|
|
1562
|
+
from shown),
|
|
1563
|
+
grouped(id, run, step, kind, status, next, after, t, prev_t, g) as (
|
|
1564
|
+
select id, run, step, kind, status, next, after, t, prev_t,
|
|
1565
|
+
sum(first) over (order by id rows between unbounded preceding and current row)
|
|
1566
|
+
from flagged),
|
|
1567
|
+
spans(g, first_id, last_id) as (
|
|
1568
|
+
select g, min(id), max(id) from grouped where kind != 'start' group by g),
|
|
1569
|
+
latest(run, step, t, under) as (
|
|
1570
|
+
select run, step, t, case when status in ('answered', 'needs-human') then step
|
|
1571
|
+
when status = 'done' and coalesce(next, '') not in ('', 'start', 'setup', 'merged') then next end
|
|
1572
|
+
from grouped where after is null),
|
|
1573
|
+
ended(o, run, step, s, e, open) as (
|
|
1574
|
+
select sp.g, l.run, l.step, coalesce(f.prev_t, f.t), l.t, l.after is null and l.step is u.under
|
|
1575
|
+
from spans sp join grouped f on f.id = sp.first_id join grouped l on l.id = sp.last_id left join latest u on 1
|
|
1576
|
+
union all
|
|
1577
|
+
select (select max(g) from grouped) + 1, run, under, t, t, 1 from latest
|
|
1578
|
+
where under is not null and under is not step),
|
|
1579
|
+
steps(n, run, step, s, e, open) as (
|
|
1580
|
+
select row_number() over (order by o), run, step, s, case when open then max($now, e) else e end, open from ended),
|
|
1581
|
+
inside(n, at, a, b, cpu, mem, pressure) as (
|
|
1582
|
+
select st.n, g.at, max(g.at - g.secs, st.s), min(g.at, st.e), g.cpu_busy, g.mem_used_mb, g.mem_pressure
|
|
1583
|
+
from steps st cross join $readings g
|
|
1584
|
+
on g.at > st.s and g.at < st.e + $HOST_GAP and g.at - g.secs < st.e
|
|
1585
|
+
where min(g.at, st.e) > max(g.at - g.secs, st.s)),
|
|
1586
|
+
counts(n, readings, recorded) as (select n, count(*), sum(b - a) from inside group by n),
|
|
1587
|
+
spread(n, k, last, s, len, a, b, cpu, mem, pressure) as (
|
|
1588
|
+
select p.n, ($HOST_CARD_POINTS * (p.a - st.s + 1) - 1) / (st.e - st.s), ($HOST_CARD_POINTS * (p.b - st.s) - 1) / (st.e - st.s),
|
|
1589
|
+
st.s, st.e - st.s, p.a, p.b, p.cpu, p.mem, p.pressure
|
|
1590
|
+
from inside p join counts c on c.n = p.n and c.readings > $HOST_CARD_POINTS join steps st on st.n = p.n
|
|
1591
|
+
union all
|
|
1592
|
+
select n, k + 1, last, s, len, a, b, cpu, mem, pressure from spread where k < last),
|
|
1593
|
+
pieces(n, k, lo, hi, d, cpu, mem, pressure) as (
|
|
1594
|
+
select n, k, lo, hi, min(b, hi) - max(a, lo), cpu, mem, pressure from (
|
|
1595
|
+
select n, k, s + len * k / $HOST_CARD_POINTS as lo, s + len * (k + 1) / $HOST_CARD_POINTS as hi, a, b, cpu, mem, pressure
|
|
1596
|
+
from spread)
|
|
1597
|
+
where min(b, hi) > max(a, lo)),
|
|
1598
|
+
points(n, o, a, b, d, cpu, mem, pressure) as (
|
|
1599
|
+
select p.n, p.at, p.a, p.b, p.b - p.a, p.cpu, p.mem, p.pressure
|
|
1600
|
+
from inside p join counts c on c.n = p.n and c.readings <= $HOST_CARD_POINTS
|
|
1601
|
+
union all
|
|
1602
|
+
select n, k, lo, hi, sum(d), 1.0 * sum(cpu * d) / sum(case when cpu is not null then d end),
|
|
1603
|
+
cast(round(1.0 * sum(mem * d) / sum(case when mem is not null then d end)) as integer), max(pressure)
|
|
1604
|
+
from pieces group by n, k),
|
|
1605
|
+
drawn(n, i, points) as (
|
|
1606
|
+
select n, row_number() over (partition by n order by o),
|
|
1607
|
+
json_group_array(json_object(
|
|
1608
|
+
'start', strftime('%Y-%m-%dT%H:%M:%SZ', a, 'unixepoch'),
|
|
1609
|
+
'end', strftime('%Y-%m-%dT%H:%M:%SZ', b, 'unixepoch'), 'seconds', d,
|
|
1610
|
+
'cpu_busy', round(cpu, 1), 'mem_used_mb', mem,
|
|
1611
|
+
'mem_pressure', case when pressure >= 4 then 'critical' when pressure >= 2 then 'warning'
|
|
1612
|
+
when pressure is not null then 'normal' end))
|
|
1613
|
+
over (partition by n order by o rows between unbounded preceding and unbounded following)
|
|
1614
|
+
from points)
|
|
1615
|
+
select json_object('space', $(sql_str "$name"), 'card', $(sql_str "$card"), 'recording', json('$recording'),
|
|
1616
|
+
'steps', json((select json_group_array(json(entry)) from (
|
|
1617
|
+
select json_object('run', st.run, 'step', st.step,
|
|
1618
|
+
'start', strftime('%Y-%m-%dT%H:%M:%SZ', st.s, 'unixepoch'),
|
|
1619
|
+
'end', strftime('%Y-%m-%dT%H:%M:%SZ', st.e, 'unixepoch'),
|
|
1620
|
+
'seconds', max(st.e - st.s, 0), 'open', json(case when st.open then 'true' else 'false' end),
|
|
1621
|
+
'readings', coalesce(c.readings, 0), 'recorded', coalesce(c.recorded, 0),
|
|
1622
|
+
'points', json(coalesce(d.points, '[]'))) as entry
|
|
1623
|
+
from steps st left join counts c on c.n = st.n left join drawn d on d.n = st.n and d.i = 1
|
|
1624
|
+
order by st.n))));") || {
|
|
1625
|
+
# Which of the two it could not read: the hand-offs alone are tried again.
|
|
1626
|
+
[ -n "$attach" ] && store "$STORE" 'select count(*) from handoffs where 0;' >/dev/null ||
|
|
1627
|
+
die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
1628
|
+
die "could not read the readings in $HOST_DB. They may not be the ones ocnus host records."
|
|
1629
|
+
}
|
|
1630
|
+
[ -n "$out" ] || die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
1631
|
+
say "$out"
|
|
1791
1632
|
}
|
|
1792
1633
|
|
|
1793
1634
|
cmd_host() {
|