@johngaynor/ocnus 2.0.1-next.17 → 2.0.1-next.22
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 +12 -4
- package/cli/lib/linear.sh +199 -33
- package/cli/lib/task.sh +8 -4
- package/cli/ocnus +9 -1
- package/herdr/README.md +27 -6
- package/herdr/layouts/default.json +10 -0
- 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/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,7 +73,8 @@ worked out. Until then the build step itself installs into each worktree what
|
|
|
73
73
|
the tests need, and [`just`](https://just.systems) matters only once setup is
|
|
74
74
|
on; see [what a repo provides](herdr/README.md#what-a-repo-provides). On
|
|
75
75
|
Linux, the CPU mod in the `default` layout shows an error where its reading
|
|
76
|
-
would be, since it reads macOS's `/usr/bin/top
|
|
76
|
+
would be, since it reads macOS's `/usr/bin/top`, and so does the Memory mod
|
|
77
|
+
above it, which reads macOS's `sysctl`, `vm_stat` and `ps`.
|
|
77
78
|
|
|
78
79
|
## Setting up a machine
|
|
79
80
|
|
|
@@ -88,8 +89,8 @@ and the two phase profiles in [agents/](agents/), which it links into
|
|
|
88
89
|
`~/.claude/agents`; see [herdr/README.md](herdr/README.md) for the full
|
|
89
90
|
walkthrough. `install` ends by telling you to switch Herdr to the `default`
|
|
90
91
|
layout, which holds ocnus's panels: the Ocnus spaces panel, the Cards
|
|
91
|
-
and Steps panels, the Usage section
|
|
92
|
-
the settings button. Herdr's own Agents section is not on it. Herdr starts on
|
|
92
|
+
and Steps panels, the Usage section above Memory and CPU, the Layout dropdown
|
|
93
|
+
and the settings button. Herdr's own Agents section is not on it. Herdr starts on
|
|
93
94
|
its own layout, which has no Layout dropdown, so the first switch is
|
|
94
95
|
`ctrl-shift-l`, pressed until `default` shows.
|
|
95
96
|
|
|
@@ -302,7 +303,7 @@ In Herdr, the settings button shows which is set and switches it with a
|
|
|
302
303
|
click, through `billing subscription` and `billing api`; the key is saved in a
|
|
303
304
|
terminal, with `billing key`.
|
|
304
305
|
|
|
305
|
-
On the subscription, the Usage section,
|
|
306
|
+
On the subscription, the Usage section, above Memory and CPU in the `default`
|
|
306
307
|
layout's sidebar, shows how much of your Claude subscription's five-hour and
|
|
307
308
|
weekly usage limits is used, as a percentage and a bar each, and when each
|
|
308
309
|
resets.
|
|
@@ -378,6 +379,13 @@ ocnus space team my-space ABC # once: the team whose cards are ABC-122
|
|
|
378
379
|
ocnus task ls my-space
|
|
379
380
|
```
|
|
380
381
|
|
|
382
|
+
With `--json`, for programs, the list also says which cards are held and
|
|
383
|
+
which cards each of them waits on: a card is held while it is in a
|
|
384
|
+
not-started status, such as Todo, and a card that blocks it, or its parent,
|
|
385
|
+
is not done, which is when `task start` holds it. Each card names its parent
|
|
386
|
+
there too, with its place among the parent's sub-issues and how many of them
|
|
387
|
+
are done.
|
|
388
|
+
|
|
381
389
|
It asks Linear itself, with no agent running. `ocnus status` checks the
|
|
382
390
|
saved key with Linear each time it runs: it says whose the key is when it
|
|
383
391
|
works, notes when no key is saved or when the key could not be checked, and
|
package/cli/lib/linear.sh
CHANGED
|
@@ -233,13 +233,27 @@ OPEN_TYPES='["triage","backlog","unstarted","started"]'
|
|
|
233
233
|
# deciding that Linear will never say it has no more.
|
|
234
234
|
LINEAR_PAGE=100
|
|
235
235
|
LINEAR_PAGES=50
|
|
236
|
+
# For `task ls --json`: how many cards one question about blockers asks
|
|
237
|
+
# about, and how many of each card's relations it reads. Linear caps what one
|
|
238
|
+
# question may cost, and a list inside a list counts once for each card it is
|
|
239
|
+
# asked of, however few it holds (SLICE_RELATIONS), so both are kept small. A
|
|
240
|
+
# card with more relations than are read may have blockers that were not
|
|
241
|
+
# read, which the list says of it.
|
|
242
|
+
LIST_BLOCKED=50
|
|
243
|
+
LIST_RELATIONS=20
|
|
236
244
|
|
|
237
245
|
# The teams Linear knows of those asked for, their open statuses, and one page
|
|
238
246
|
# of their open cards, with when each was last changed. Linear pages through
|
|
239
247
|
# the cards in the order it is asked for, each page starting where the last
|
|
240
248
|
# ended. That order is when each card was made, which nothing changes: in the
|
|
241
249
|
# order they were last changed, a card edited while the pages are fetched
|
|
242
|
-
# would move onto a page already fetched, and never be listed.
|
|
250
|
+
# would move onto a page already fetched, and never be listed. Each card
|
|
251
|
+
# comes with Linear's own id for it, its parent, and the first of the
|
|
252
|
+
# relations that name it as the related card. That one tells whether any
|
|
253
|
+
# card is related to it at all, and so whether one may block it: the
|
|
254
|
+
# blockers themselves are asked for afterwards, of those cards alone
|
|
255
|
+
# (LIST_BLOCKERS_QUERY), since reading them here would cost every card on the
|
|
256
|
+
# page a list of them.
|
|
243
257
|
LIST_QUERY='query($teams: [String!], $types: [String!], $first: Int, $after: String) {
|
|
244
258
|
teams(filter: {key: {in: $teams}}) { nodes { key } }
|
|
245
259
|
workflowStates(first: 250, filter: {team: {key: {in: $teams}}, type: {in: $types}}) {
|
|
@@ -247,15 +261,58 @@ LIST_QUERY='query($teams: [String!], $types: [String!], $first: Int, $after: Str
|
|
|
247
261
|
}
|
|
248
262
|
issues(first: $first, after: $after, orderBy: createdAt,
|
|
249
263
|
filter: {team: {key: {in: $teams}}, state: {type: {in: $types}}}) {
|
|
250
|
-
nodes { identifier title url updatedAt state { name type position }
|
|
264
|
+
nodes { id identifier title url updatedAt state { name type position }
|
|
265
|
+
parent { id identifier title }
|
|
266
|
+
inverseRelations(first: 1) { nodes { id } } }
|
|
251
267
|
pageInfo { hasNextPage endCursor }
|
|
252
268
|
}
|
|
253
269
|
}'
|
|
254
270
|
|
|
255
|
-
#
|
|
256
|
-
#
|
|
257
|
-
#
|
|
258
|
-
#
|
|
271
|
+
# One page of the sub-issues of some cards, the parents the open cards name,
|
|
272
|
+
# by Linear's own ids for them: every sub-issue, whatever its status and its
|
|
273
|
+
# team, with when it was made, the kind of status it is in and which of the
|
|
274
|
+
# cards it is a sub-issue of. All the parents are asked about in one
|
|
275
|
+
# question, which is paged through as the list is, in the order the
|
|
276
|
+
# sub-issues were made, so that no parent's count stops short.
|
|
277
|
+
LIST_SUBS_QUERY='query($parents: [ID!], $first: Int, $after: String) {
|
|
278
|
+
issues(first: $first, after: $after, orderBy: createdAt, filter: {parent: {id: {in: $parents}}}) {
|
|
279
|
+
nodes { identifier createdAt state { type } parent { id } }
|
|
280
|
+
pageInfo { hasNextPage endCursor }
|
|
281
|
+
}
|
|
282
|
+
}'
|
|
283
|
+
|
|
284
|
+
# The relations of some cards, by Linear's own ids for them, that name each
|
|
285
|
+
# as the related card, as CARD_BLOCKERS_READ reads them for one card, with
|
|
286
|
+
# the other card's title too. Those of the kind "blocks" name a card that
|
|
287
|
+
# blocks it. Whether a card has more of them than were read comes with them.
|
|
288
|
+
LIST_BLOCKERS_QUERY='query($ids: [ID!], $first: Int) {
|
|
289
|
+
issues(first: $first, filter: {id: {in: $ids}}) {
|
|
290
|
+
nodes { id
|
|
291
|
+
inverseRelations(first: '$LIST_RELATIONS') { nodes { type issue { identifier title state { name type } } } pageInfo { hasNextPage } } }
|
|
292
|
+
}
|
|
293
|
+
}'
|
|
294
|
+
|
|
295
|
+
# From the pages of the list (as for LIST_SHAPE, on stdin), what `task ls
|
|
296
|
+
# --json` asks Linear next, by Linear's own ids: parents, the cards whose
|
|
297
|
+
# sub-issues to read, which are the parents the cards name; and ids, the
|
|
298
|
+
# cards whose blockers to read, which are the cards that some card is related
|
|
299
|
+
# to and the parents of the cards in a not-started status, since a card that
|
|
300
|
+
# blocks its parent holds such a card too. Each id is there once.
|
|
301
|
+
LIST_ASK='
|
|
302
|
+
[.[].list.issues.nodes[]?] as $cards
|
|
303
|
+
| {parents: ([$cards[] | .parent.id? | strings] | unique),
|
|
304
|
+
ids: ([$cards[]
|
|
305
|
+
| (select((.inverseRelations.nodes? // []) | length > 0) | .id?),
|
|
306
|
+
(select(.state.type? == "unstarted") | .parent.id?)
|
|
307
|
+
| strings] | unique)}'
|
|
308
|
+
|
|
309
|
+
# Turn what Linear answered (on stdin, a line of JSON for each answer, under
|
|
310
|
+
# a name that says which question it answers: list for a page of the list,
|
|
311
|
+
# subs for a page of sub-issues and blockers for an answer about blockers)
|
|
312
|
+
# into the list: every open status, in Linear's order, with its cards. Teams
|
|
313
|
+
# often share a status name; a status of one name and kind is one group,
|
|
314
|
+
# whichever teams have it. $space, $teams, $types and $detail are given by
|
|
315
|
+
# the caller.
|
|
259
316
|
# - Under each status the card changed last comes first. Cards changed at
|
|
260
317
|
# the same moment keep the order Linear gave them in.
|
|
261
318
|
# - Should a card come on two pages, the first copy is kept.
|
|
@@ -263,12 +320,76 @@ LIST_QUERY='query($teams: [String!], $types: [String!], $first: Int, $after: Str
|
|
|
263
320
|
# that it did not, such as one made while the pages were fetched, so that
|
|
264
321
|
# no card is dropped for want of a group.
|
|
265
322
|
# - A closed status is never listed, should Linear send one.
|
|
323
|
+
# A card is its id, title and url. When $detail is true, it also says where
|
|
324
|
+
# it stands, from the other two questions' answers:
|
|
325
|
+
# - parent is the card it is a sub-issue of, with how many sub-issues that
|
|
326
|
+
# card has and how many of them are done, which is in a completed status.
|
|
327
|
+
# Every sub-issue counts, whatever its status. place is where the card
|
|
328
|
+
# comes among them, from 1, in the order they were made, the order
|
|
329
|
+
# READ_SHAPE gives subIssues in; it is null should the card not be among
|
|
330
|
+
# them, as when its parent changed between the questions. Both are null
|
|
331
|
+
# for a card with no parent.
|
|
332
|
+
# - blockedBy is the cards that block it, done or not, as READ_SHAPE gives
|
|
333
|
+
# them, and none for a card no card is related to.
|
|
334
|
+
# - held is whether `task start` would hold it, by the test card_branch
|
|
335
|
+
# applies (task.sh): it is in a not-started status, and a card that
|
|
336
|
+
# blocks it or its parent is not done. waitsOn is those cards, its own
|
|
337
|
+
# blockers and then its parent's, each once, and none when it is not held.
|
|
338
|
+
# - blockersCut is true when blockers may be missing from that: the card
|
|
339
|
+
# has more relations than were read, or its parent has, when the parent's
|
|
340
|
+
# can hold it, or Linear's answer left one of the two out.
|
|
341
|
+
# A sub-issue or a blocker that is not in the form Linear gives it in did not
|
|
342
|
+
# come from Linear, so nothing is listed. The list's own pages are read as
|
|
343
|
+
# they always were: a card with no parent or relations in the answer has
|
|
344
|
+
# neither.
|
|
266
345
|
LIST_SHAPE='
|
|
346
|
+
def text: if type == "string" then . else error("unreadable") end;
|
|
347
|
+
def nodes: if (.issues.nodes | type) == "array" then .issues.nodes[] else error("unreadable") end;
|
|
348
|
+
def status: if type == "object" then {name: (.name | text), type: (.type | text)} else error("unreadable") end;
|
|
267
349
|
($types | to_entries | map({key: .value, value: .key}) | from_entries) as $rank
|
|
268
|
-
| .[
|
|
269
|
-
|
|
|
350
|
+
| [.[] | .list | values] as $pages
|
|
351
|
+
| $pages[0] as $first
|
|
352
|
+
| ([$pages[].issues.nodes[]] | to_entries | unique_by(.value.identifier)
|
|
270
353
|
| sort_by([.value.updatedAt, -.key]) | reverse | map(.value)) as $cards
|
|
271
|
-
|
|
|
354
|
+
| ([.[] | .subs | values | nodes
|
|
355
|
+
| {id: (.identifier | text), at: (.createdAt | text), done: ((.state.type | text) == "completed"),
|
|
356
|
+
of: (.parent.id | text)}]
|
|
357
|
+
| to_entries | unique_by(.value.id) | sort_by([.value.at, .key]) | map(.value)
|
|
358
|
+
| group_by(.of) | map({key: .[0].of, value: .}) | from_entries) as $subs
|
|
359
|
+
| ([.[] | .blockers | values | nodes
|
|
360
|
+
| {key: (.id | text),
|
|
361
|
+
value: (.inverseRelations
|
|
362
|
+
| if type == "object" and (.nodes | type) == "array" and (.pageInfo.hasNextPage | type) == "boolean"
|
|
363
|
+
then {cut: .pageInfo.hasNextPage,
|
|
364
|
+
by: [.nodes[] | select((.type | text) == "blocks") | .issue
|
|
365
|
+
| if type == "object"
|
|
366
|
+
then {id: (.identifier | text), title: (.title | text), status: (.state | status)}
|
|
367
|
+
else error("unreadable") end]}
|
|
368
|
+
else error("unreadable") end)}]
|
|
369
|
+
| from_entries) as $read
|
|
370
|
+
| def none: {by: [], cut: false};
|
|
371
|
+
def read($id): if ($id | type) == "string" and ($read | has($id)) then $read[$id] else {by: [], cut: true} end;
|
|
372
|
+
def detail:
|
|
373
|
+
. as $card
|
|
374
|
+
| (if .parent == null then null
|
|
375
|
+
elif (.parent | type) == "object"
|
|
376
|
+
then .parent | {key: (.id | text), id: (.identifier | text), title: (.title | text)}
|
|
377
|
+
else error("unreadable") end) as $parent
|
|
378
|
+
| (if $parent == null then [] else $subs[$parent.key] // [] end) as $among
|
|
379
|
+
| (if ((.inverseRelations.nodes? // []) | length) > 0 then read(.id) else none end) as $own
|
|
380
|
+
| (if $parent != null and .state.type == "unstarted" then read($parent.key) else none end) as $above
|
|
381
|
+
| (reduce ($own.by[], $above.by[] | select(.status.type != "completed")) as $by ([];
|
|
382
|
+
if any(.[]; .id == $by.id) then . else . + [$by] end)) as $open
|
|
383
|
+
| (.state.type == "unstarted" and ($open | length) > 0) as $held
|
|
384
|
+
| {parent: (if $parent == null then null
|
|
385
|
+
else {id: $parent.id, title: $parent.title, subIssues: ($among | length),
|
|
386
|
+
done: ([$among[] | select(.done)] | length)} end),
|
|
387
|
+
place: (($among | map(.id) | index($card.identifier)) as $at | if $at == null then null else $at + 1 end),
|
|
388
|
+
blockedBy: $own.by,
|
|
389
|
+
blockersCut: ($own.cut or $above.cut),
|
|
390
|
+
held: $held,
|
|
391
|
+
waitsOn: (if $held then $open else [] end)};
|
|
392
|
+
{
|
|
272
393
|
missing: ($teams - [$first.teams.nodes[].key]),
|
|
273
394
|
space: $space,
|
|
274
395
|
teams: $teams,
|
|
@@ -286,45 +407,90 @@ LIST_SHAPE='
|
|
|
286
407
|
cards: [
|
|
287
408
|
$cards[]
|
|
288
409
|
| select(.state.name == $status.name and .state.type == $status.type)
|
|
289
|
-
| {id: .identifier, title: .title, url: .url}
|
|
410
|
+
| {id: .identifier, title: .title, url: .url} + (if $detail then detail else {} end)
|
|
290
411
|
]
|
|
291
412
|
}
|
|
292
413
|
]
|
|
293
414
|
}'
|
|
294
415
|
|
|
295
|
-
#
|
|
296
|
-
#
|
|
297
|
-
#
|
|
298
|
-
#
|
|
299
|
-
#
|
|
300
|
-
#
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
key=$(linear_saved_key) || exit 1
|
|
306
|
-
teams=$(printf '%s\n' "$@" | jq -Rcn '[inputs]')
|
|
416
|
+
# Ask Linear a question that pages through cards, up to the last page, and
|
|
417
|
+
# print each page's answer as a line of JSON under a name, like
|
|
418
|
+
# {"list": <the answer>}, for LIST_SHAPE to tell the questions' answers
|
|
419
|
+
# apart by. The query takes $first and $after with the variables given, and
|
|
420
|
+
# answers with issues { nodes pageInfo { hasNextPage endCursor } }. When the
|
|
421
|
+
# pages cannot be read to the last one, it stops, as die does: what came so
|
|
422
|
+
# far would pass a part for the whole.
|
|
423
|
+
# linear_pages <key> <name> <what the pages hold, for a message> <query> <its other variables, as JSON>
|
|
424
|
+
linear_pages() {
|
|
425
|
+
local key=$1 name=$2 what=$3 query=$4 base=$5 vars data after='' more asked=0
|
|
307
426
|
while :; do
|
|
308
427
|
asked=$((asked + 1))
|
|
309
428
|
[ "$asked" -le "$LINEAR_PAGES" ] ||
|
|
310
|
-
die "Linear still had more
|
|
311
|
-
vars=$(jq -cn --argjson
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
data=$(linear_ask "$key" "$
|
|
315
|
-
|
|
429
|
+
die "Linear still had more $what after $LINEAR_PAGES pages of $LINEAR_PAGE, which is more than ocnus lists."
|
|
430
|
+
vars=$(jq -cn --argjson base "$base" --argjson first "$LINEAR_PAGE" --arg after "$after" \
|
|
431
|
+
'$base + {first: $first, after: (if $after == "" then null else $after end)}') ||
|
|
432
|
+
die "could not put a question to Linear together."
|
|
433
|
+
data=$(linear_ask "$key" "$query" "$vars") || exit 1
|
|
434
|
+
printf '{"%s":%s}\n' "$name" "$data"
|
|
316
435
|
more=$(printf '%s' "$data" | jq -r '.issues.pageInfo.hasNextPage == true' 2>/dev/null) ||
|
|
317
436
|
die "Linear's answer was not one ocnus can read."
|
|
318
437
|
[ "$more" = true ] || break
|
|
319
438
|
# Listing what came so far would pass a part of the list for the whole.
|
|
320
439
|
after=$(printf '%s' "$data" | jq -r '.issues.pageInfo.endCursor | strings' 2>/dev/null) || after=
|
|
321
440
|
[ -n "$after" ] ||
|
|
322
|
-
die "Linear said it had more
|
|
441
|
+
die "Linear said it had more $what but not where the next ones start, so the list would be cut short."
|
|
323
442
|
done
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
# Print the open cards of some Linear teams as one line of JSON, grouped by
|
|
446
|
+
# status:
|
|
447
|
+
# {"space":"demo","teams":["ABC"],"statuses":[
|
|
448
|
+
# {"name":"Backlog","type":"backlog","cards":[{"id":"ABC-1","title":"…","url":"…"}]}]}
|
|
449
|
+
# Every open status of the teams is there, with no cards when it has none.
|
|
450
|
+
# With the detail, which `task ls --json` asks for, each card also says
|
|
451
|
+
# where it stands (LIST_SHAPE):
|
|
452
|
+
# {"id":"ABC-123","title":"…","url":"…",
|
|
453
|
+
# "parent":{"id":"ABC-100","title":"…","subIssues":3,"done":1},"place":2,
|
|
454
|
+
# "blockedBy":[{"id":"ABC-122","title":"…","status":{"name":"In Progress","type":"started"}}],
|
|
455
|
+
# "blockersCut":false,"held":true,
|
|
456
|
+
# "waitsOn":[{"id":"ABC-122","title":"…","status":{"name":"In Progress","type":"started"}}]}
|
|
457
|
+
# That takes up to two more questions, each asked only when the list holds
|
|
458
|
+
# something to ask about: the sub-issues of the parents the cards name, all
|
|
459
|
+
# in one question, paged to its end, and then the blockers of the cards
|
|
460
|
+
# that some card is related to and of the parents of not-started cards,
|
|
461
|
+
# LIST_BLOCKED cards at a time. When one of them fails, or cannot be read to
|
|
462
|
+
# its end, nothing is printed, as for the list itself.
|
|
463
|
+
# linear_open_cards <space> <true, for the detail, or false> <team key>...
|
|
464
|
+
linear_open_cards() {
|
|
465
|
+
local space=$1 detail=$2 key teams pages ask count at=0 vars data list missing
|
|
466
|
+
shift 2
|
|
467
|
+
linear_tools
|
|
468
|
+
key=$(linear_saved_key) || exit 1
|
|
469
|
+
teams=$(printf '%s\n' "$@" | jq -Rcn '[inputs]')
|
|
470
|
+
pages=$(linear_pages "$key" list cards "$LIST_QUERY" \
|
|
471
|
+
"$(jq -cn --argjson teams "$teams" --argjson types "$OPEN_TYPES" '{teams: $teams, types: $types}')") || exit 1
|
|
472
|
+
if [ "$detail" = true ]; then
|
|
473
|
+
# The pages go to jq on stdin, here and below, not as an argument: a
|
|
474
|
+
# long list of cards is more than a command's arguments may hold.
|
|
475
|
+
ask=$(printf '%s\n' "$pages" | jq -cs "$LIST_ASK" 2>/dev/null) ||
|
|
476
|
+
die "Linear's answer was not one ocnus can read."
|
|
477
|
+
if [ "$(printf '%s' "$ask" | jq -r '.parents | length')" != 0 ]; then
|
|
478
|
+
data=$(linear_pages "$key" subs sub-issues "$LIST_SUBS_QUERY" "$(printf '%s' "$ask" | jq -c '{parents}')") || exit 1
|
|
479
|
+
pages+=$'\n'$data
|
|
480
|
+
fi
|
|
481
|
+
count=$(printf '%s' "$ask" | jq -r '.ids | length')
|
|
482
|
+
while [ "$at" -lt "$count" ]; do
|
|
483
|
+
# As many cards are asked for as are named, and no more.
|
|
484
|
+
vars=$(printf '%s' "$ask" |
|
|
485
|
+
jq -c --argjson at "$at" --argjson n "$LIST_BLOCKED" '.ids[$at:($at + $n)] | {ids: ., first: length}')
|
|
486
|
+
data=$(linear_ask "$key" "$LIST_BLOCKERS_QUERY" "$vars") || exit 1
|
|
487
|
+
pages+=$'\n'"{\"blockers\":$data}"
|
|
488
|
+
at=$((at + LIST_BLOCKED))
|
|
489
|
+
done
|
|
490
|
+
fi
|
|
491
|
+
list=$(printf '%s\n' "$pages" |
|
|
492
|
+
jq -cs --arg space "$space" --argjson teams "$teams" --argjson types "$OPEN_TYPES" --argjson detail "$detail" \
|
|
493
|
+
"$LIST_SHAPE" 2>/dev/null) ||
|
|
328
494
|
die "Linear's answer was not one ocnus can read."
|
|
329
495
|
missing=$(printf '%s' "$list" | jq -r '.missing | join(", ")')
|
|
330
496
|
[ -z "$missing" ] ||
|
package/cli/lib/task.sh
CHANGED
|
@@ -849,13 +849,17 @@ task_build() {
|
|
|
849
849
|
|
|
850
850
|
# List the open cards of a space's Linear teams, grouped by status: the
|
|
851
851
|
# cards `task new` can be given. Linear itself is asked in linear.sh. --json
|
|
852
|
-
# prints the list as one line for programs; the cards mod reads it.
|
|
852
|
+
# prints the list as one line for programs; the cards mod reads it. Only
|
|
853
|
+
# --json asks for the detail, where each card stands: its parent and its
|
|
854
|
+
# place among the parent's sub-issues, the cards that block it, and whether
|
|
855
|
+
# it is held. That costs up to two more questions to Linear, and the plain
|
|
856
|
+
# list shows none of it, so the plain list asks for the list alone.
|
|
853
857
|
task_ls() {
|
|
854
|
-
local name=${1:-} json=0 dir team keys list
|
|
858
|
+
local name=${1:-} json=0 detail=false dir team keys list
|
|
855
859
|
local -a teams=()
|
|
856
860
|
dir=$(space_dir "$name")
|
|
857
861
|
case ${2:-} in
|
|
858
|
-
--json) json=1 ;;
|
|
862
|
+
--json) json=1 detail=true ;;
|
|
859
863
|
'') ;;
|
|
860
864
|
*) die "unknown option for task ls: $2" ;;
|
|
861
865
|
esac
|
|
@@ -866,7 +870,7 @@ task_ls() {
|
|
|
866
870
|
while IFS= read -r team; do [ -z "$team" ] || teams+=("$team"); done <<< "$keys"
|
|
867
871
|
[ "${#teams[@]}" -gt 0 ] ||
|
|
868
872
|
die "space '$name' has no Linear team, so there are no cards to list. Set it with: ocnus space team $name <team key>, like: ocnus space team $name ABC"
|
|
869
|
-
list=$(linear_open_cards "$name" "${teams[@]}") || exit 1
|
|
873
|
+
list=$(linear_open_cards "$name" "$detail" "${teams[@]}") || exit 1
|
|
870
874
|
if [ "$json" = 1 ]; then
|
|
871
875
|
printf '%s\n' "$list"
|
|
872
876
|
return
|
package/cli/ocnus
CHANGED
|
@@ -112,7 +112,15 @@ by the trust question. It needs jq; without it Claude Code asks once.
|
|
|
112
112
|
A task is one piece of work in a space, usually a Linear card.
|
|
113
113
|
`task ls` lists the cards `task new` can be given: every card of the
|
|
114
114
|
space's Linear teams that is not done, cancelled or a duplicate, under its
|
|
115
|
-
status.
|
|
115
|
+
status. With --json, for programs, each card also says where it stands: its
|
|
116
|
+
parent card, with how many sub-issues the parent has and how many of them
|
|
117
|
+
are done, its place among them in the order they were made, the cards that
|
|
118
|
+
block it, and whether it is held, with the cards it waits on. A card is held
|
|
119
|
+
when it is in a not-started status and a card that blocks it, or its parent,
|
|
120
|
+
is not done, which is when `task start` holds it. That asks Linear up to two
|
|
121
|
+
more questions, for the sub-issues and for the blockers; the plain list asks
|
|
122
|
+
for neither.
|
|
123
|
+
`task ls` needs two things set once. `linear key` asks for a Linear API key
|
|
116
124
|
and saves it (make one in Linear, under Settings, Account, Security & access,
|
|
117
125
|
Personal API keys; Read permission is enough to list cards and for
|
|
118
126
|
`linear read`, which the card skills read a card with, and the card skills'
|
package/herdr/README.md
CHANGED
|
@@ -8,14 +8,15 @@ a layout (a whole-window arrangement of mods).
|
|
|
8
8
|
| Path | What it is |
|
|
9
9
|
|---|---|
|
|
10
10
|
| `mods/cpu/` | Live CPU usage with a scrolling history. macOS only (reads `/usr/bin/top`). |
|
|
11
|
-
| `mods/
|
|
11
|
+
| `mods/memory/` | Live memory use with a scrolling history, like the CPU mod's: memory used out of the Mac's total, in GB, as Activity Monitor's Memory Used counts it. Each reading is a bar as high as the share of the Mac's memory in use, coloured by macOS's memory pressure: green for normal, yellow for warning, red for critical. Under the figure, `claude` is the resident memory of every process whose command is `claude`: ocnus's agents, while their harness is `claude`, and any Claude Code session you opened yourself, but not what they run, such as a test run, which counts in memory used alone. So it is not the recorder's `mem_agents_mb`, which counts every process under a terminal labelled with one of your spaces (see [Recording the host](#recording-the-host)). `swap` is the swap in use. It reads macOS itself, so it shows the same whether recording is on or off. macOS only (reads `sysctl`, `vm_stat` and `ps`). |
|
|
12
|
+
| `mods/usage/` | The Usage section, above Memory and CPU, and as small: how much of your Claude subscription's five-hour and weekly usage limits is used, as a percentage and a bar each, and when each resets, as the agents ocnus starts last read them. See [The Usage section](#the-usage-section). |
|
|
12
13
|
| `mods/layout-switch/` | A dropdown that shows the current layout and switches to another. |
|
|
13
14
|
| `mods/ocnus-spaces/` | The Ocnus spaces panel: every space in your config, open or not. Click one to show it; `+` makes a new one. It is not `spaces`, which is Herdr's own list of the spaces it has open. |
|
|
14
15
|
| `mods/cards/` | The open Linear cards of the space that is showing, under their statuses. Start writes a card up with `task new`; Open shows the tab of a card already started. |
|
|
15
16
|
| `mods/steps/` | The steps of the card whose tab is selected: what each did, how long it took, and how long it waited on you. With no card's tab selected, the space's cards and where each stands. |
|
|
16
17
|
| `mods/agent-settings/` | The settings button, a cog at the right end of the tab bar, and the popup it opens: the model and effort of each phase profile and dev profile, then the breakdown approval, archiving, the tests setting and billing, each of which a click changes. See [The settings button](#the-settings-button). |
|
|
17
18
|
| `mods/names/` | Draws nothing. It gives the spaces and tabs the app takes in from herdr-core, for agents started while the app was closed, the names ocnus gave them. See [Writing the card up](#writing-the-card-up). |
|
|
18
|
-
| `layouts/default.json` | Herdr's own layout with ocnus's panels: the Ocnus spaces panel, the `ocnus-spaces` mod, in place of Herdr's own list of spaces; the layout dropdown, the Cards and Steps panels, the Usage section and the CPU mod in the sidebar, with Usage right above CPU; and the settings button beside the tabs. Herdr's Agents section, its `agents` mod, is not on it. The tab bar is a row of Herdr's `tabs`, `agent-settings` and `names`, in a block 1px wide, since a mod runs only while a layout places it. |
|
|
19
|
+
| `layouts/default.json` | Herdr's own layout with ocnus's panels: the Ocnus spaces panel, the `ocnus-spaces` mod, in place of Herdr's own list of spaces; the layout dropdown, the Cards and Steps panels, the Usage section, the Memory mod and the CPU mod in the sidebar, with Usage above Memory and CPU, and Memory right above CPU; and the settings button beside the tabs. Herdr's Agents section, its `agents` mod, is not on it. The tab bar is a row of Herdr's `tabs`, `agent-settings` and `names`, in a block 1px wide, since a mod runs only while a layout places it. |
|
|
19
20
|
| `spaces/template/` | The starting `SPACE.md` for every new space. |
|
|
20
21
|
|
|
21
22
|
The skills are in [../skills/](../skills/), outside this folder. They are
|
|
@@ -324,8 +325,28 @@ ocnus task ls <space> [--json]
|
|
|
324
325
|
`HTTPS_PROXY`, is still used.
|
|
325
326
|
- **`--json` prints the list as one line for programs**: the space, under the
|
|
326
327
|
key `space`, its teams, and each status with its `name`, its `type`
|
|
327
|
-
(`triage`, `backlog`, `unstarted` or `started`) and its `cards
|
|
328
|
-
`id`, a `title` and a `url
|
|
328
|
+
(`triage`, `backlog`, `unstarted` or `started`) and its `cards`. Each card
|
|
329
|
+
has an `id`, a `title` and a `url`, and then where it stands, which the
|
|
330
|
+
plain list does not show:
|
|
331
|
+
|
|
332
|
+
| Key | What it is |
|
|
333
|
+
|---|---|
|
|
334
|
+
| `parent` | The card it is a sub-issue of, as `{"id", "title", "subIssues", "done"}`, or `null` for a card with none. The parent is named whatever its status and its team: one that is done or canceled, or in a team the space does not list, is not in the list itself, and is still named here. `subIssues` is how many sub-issues the parent has, and `done` is how many of them are done. Every sub-issue counts towards `subIssues`, whatever its status and its team, a canceled one too. Only one in a completed status counts towards `done`, which is where a card is once its pull requests have merged. |
|
|
335
|
+
| `place` | Where the card comes among its parent's sub-issues, from 1, in the order they were made. That is the order `ocnus linear read` lists a card's sub-issues in, so the place agrees with the `slice N of M` a brief gives. It is `null` for a card with no parent, and for one that Linear's answer about the sub-issues no longer has, as when its parent changed while the list was read. With the parent's counts, a card can be shown as `place`/`subIssues`, and its parent as `done`/`subIssues` merged. |
|
|
336
|
+
| `blockedBy` | The cards that block it, each with its `id`, its `title` and its `status`, which is the `name` and the `type` of the status it is in: `[{"id", "title", "status": {"name", "type"}}]`, the form `linear read --json` gives them in. A blocker is listed done or not, and whatever team it is in. A card that is only related to it is not a blocker. A card nothing blocks has an empty list. |
|
|
337
|
+
| `held` | `true` when the card is in a not-started status, such as Todo, and a card that blocks it, or that blocks its parent, is not done. That is when `task start` holds a card (see [Starting the work](#starting-the-work)): a blocker that is canceled holds it, and one that is done does not. A card in any other status is never held, whatever blocks it. |
|
|
338
|
+
| `waitsOn` | For a card that is held, the blockers that are not done, its own and then its parent's, each once, in the form of `blockedBy`. Empty for a card that is not held. |
|
|
339
|
+
| `blockersCut` | `true` when the card may have blockers that were not read, so that `blockedBy` and `waitsOn` may not be all of them and `held` goes by the ones that were read. That is so when Linear has more than 20 relations from other cards to the card, or to the parent of a card in a not-started status, or when Linear's answer left the card or that parent out. |
|
|
340
|
+
|
|
341
|
+
To say this, `--json` asks Linear up to two more questions after the
|
|
342
|
+
list, each only when the list has something to ask about. The first is for
|
|
343
|
+
the sub-issues of every parent the cards name, all in one question. It is
|
|
344
|
+
read page by page to the last sub-issue, so a place or a count never stops
|
|
345
|
+
short. The second is for the blockers of the cards that another card is
|
|
346
|
+
related to, and of the parents of the cards in a not-started status, 50
|
|
347
|
+
cards at a time. When either fails, or cannot be read to its end, the
|
|
348
|
+
command fails rather than print a list without it. When it fails it prints
|
|
349
|
+
nothing on stdout.
|
|
329
350
|
- **Two teams' cards share a group when their statuses have the same name and
|
|
330
351
|
the same type**, such as a Backlog of type `backlog` in each. A status only
|
|
331
352
|
one team has is a group of its own, and so is one whose name another team
|
|
@@ -1575,8 +1596,8 @@ ocnus billing key
|
|
|
1575
1596
|
|
|
1576
1597
|
### The Usage section
|
|
1577
1598
|
|
|
1578
|
-
On the `default` layout, the Usage section sits in the sidebar
|
|
1579
|
-
CPU, and is as small: how much of your Claude subscription's usage limits is
|
|
1599
|
+
On the `default` layout, the Usage section sits in the sidebar above Memory
|
|
1600
|
+
and CPU, and is as small: how much of your Claude subscription's usage limits is
|
|
1580
1601
|
used, and when each resets, so you can pace the agents without leaving
|
|
1581
1602
|
Herdr.
|
|
1582
1603
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Live memory use, drawn as a scrolling history like the CPU mod's, which it
|
|
2
|
+
// sits above: memory used out of the Mac's total, a bar a reading whose
|
|
3
|
+
// colour is macOS's memory pressure, what the claude processes hold, and the
|
|
4
|
+
// swap in use.
|
|
5
|
+
//
|
|
6
|
+
// macOS only. It reads what macOS's own sysctl, vm_stat and ps print, and
|
|
7
|
+
// nothing that the host's recorder keeps, so it shows the same whether
|
|
8
|
+
// recording is on or off. What a reading is worked out from, and how, is in
|
|
9
|
+
// reading.js, which the tests run with node.
|
|
10
|
+
import { View, div } from "gpui-kit";
|
|
11
|
+
import { h_flex, v_flex } from "gpui-base";
|
|
12
|
+
import { exec, theme, window, checking, settings } from "herdr";
|
|
13
|
+
import { GB, reading, share, gb, outOf } from "./reading.js";
|
|
14
|
+
|
|
15
|
+
const SAMPLE_MS = 2000; // one reading every two seconds
|
|
16
|
+
const TIMEOUT_MS = 10000;
|
|
17
|
+
const BAR = 3; // px per reading
|
|
18
|
+
const GAP = 1;
|
|
19
|
+
const KEEP = 600; // readings kept, enough for a very wide panel
|
|
20
|
+
const HEIGHT = 64; // the block's own, as the layout gives it
|
|
21
|
+
|
|
22
|
+
// `herdr-app check` draws the mod once, and a reading there would run
|
|
23
|
+
// macOS's tools for nothing. It draws these instead: a reading at each
|
|
24
|
+
// pressure, so that a bar of each colour is drawn.
|
|
25
|
+
const SAMPLE = [
|
|
26
|
+
{ total: 16 * GB, used: 9.4 * GB, pressure: "normal", swap: 0, claude: 3.3 * GB },
|
|
27
|
+
{ total: 16 * GB, used: 13.1 * GB, pressure: "warning", swap: 1.5 * GB, claude: 4.2 * GB },
|
|
28
|
+
{ total: 16 * GB, used: 15.2 * GB, pressure: "critical", swap: 6 * GB, claude: 4.4 * GB },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
// What a tool printed, or nothing when it could not be run or took too long.
|
|
32
|
+
// reading.js then says which tool gave no reading, in a line short enough to
|
|
33
|
+
// show whole, which Herdr's own words for a tool that is not there are not.
|
|
34
|
+
const printed = (run) => run.then((r) => r.stdout, () => "");
|
|
35
|
+
|
|
36
|
+
export default class Memory extends View {
|
|
37
|
+
init(_props, cx) {
|
|
38
|
+
this.samples = [];
|
|
39
|
+
this.busy = false;
|
|
40
|
+
this.error = null;
|
|
41
|
+
this.graph = { width: 240, height: 40 };
|
|
42
|
+
if (checking()) return;
|
|
43
|
+
cx.timer.every(SAMPLE_MS, (cx) => this.sample(cx));
|
|
44
|
+
this.sample(cx);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
sample(cx) {
|
|
48
|
+
// Skip while a reading is in flight or nobody can see the window.
|
|
49
|
+
if (this.busy || window()?.visible === false) return;
|
|
50
|
+
this.busy = true;
|
|
51
|
+
cx.spawn(async (cx) => {
|
|
52
|
+
try {
|
|
53
|
+
const [sysctl, vmStat, ps] = await Promise.all([
|
|
54
|
+
printed(exec("/usr/sbin/sysctl", ["hw.memsize", "kern.memorystatus_vm_pressure_level", "vm.swapusage"], { timeout: TIMEOUT_MS })),
|
|
55
|
+
printed(exec("/usr/bin/vm_stat", [], { timeout: TIMEOUT_MS })),
|
|
56
|
+
printed(exec("/bin/ps", ["-axc", "-o", "rss=,comm="], { timeout: TIMEOUT_MS })),
|
|
57
|
+
]);
|
|
58
|
+
const r = reading(sysctl, vmStat, ps);
|
|
59
|
+
if (r.reason) {
|
|
60
|
+
this.error = r.reason;
|
|
61
|
+
} else {
|
|
62
|
+
this.samples.push(r);
|
|
63
|
+
if (this.samples.length > KEEP) this.samples.shift();
|
|
64
|
+
this.error = null;
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
this.error = String(e?.message ?? e);
|
|
68
|
+
}
|
|
69
|
+
this.busy = false;
|
|
70
|
+
cx.notify();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
render() {
|
|
75
|
+
if (checking()) {
|
|
76
|
+
// Both faces, so that a check draws each of them once: the figures
|
|
77
|
+
// beside a bar of each colour, and the line that takes the figures'
|
|
78
|
+
// place when there is no reading.
|
|
79
|
+
return v_flex().size_full()
|
|
80
|
+
.child(div().h(HEIGHT).child(this.face(SAMPLE, null, "sample")))
|
|
81
|
+
.child(div().h(HEIGHT).child(this.face([], "no reading from sysctl", "none")));
|
|
82
|
+
}
|
|
83
|
+
return this.face(this.samples, this.error, "memory");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The readout, and the history beside it.
|
|
87
|
+
// samples the readings to draw, the newest last
|
|
88
|
+
// error why there is no reading now, or null
|
|
89
|
+
// key what the ids in it start with
|
|
90
|
+
face(samples, error, key) {
|
|
91
|
+
const t = theme();
|
|
92
|
+
// Activity Monitor's colours for memory pressure. A reading whose
|
|
93
|
+
// pressure could not be read has none of them.
|
|
94
|
+
const colors = { normal: t.ansi2, warning: t.ansi3, critical: t.ansi1 };
|
|
95
|
+
// With no reading now, the last one's figures would be stale.
|
|
96
|
+
const last = error ? null : samples.at(-1);
|
|
97
|
+
|
|
98
|
+
const fit = Math.max(1, Math.floor(this.graph.width / (BAR + GAP)));
|
|
99
|
+
const shown = samples.slice(-fit);
|
|
100
|
+
const h = Math.max(1, this.graph.height);
|
|
101
|
+
|
|
102
|
+
const readout = v_flex().flex_none().w(132).gap(2).justify_center()
|
|
103
|
+
.child(h_flex().gap(8).items_end()
|
|
104
|
+
.child(div().text_size(11).text_color(t.muted).child("MEM"))
|
|
105
|
+
.child(div().text_size(20).font_semibold().text_color(t.foreground).child(last ? gb(last.used) : "–"))
|
|
106
|
+
.when(Boolean(last), (el) => el.child(div().text_size(11).text_color(t.muted).child(outOf(last.total)))))
|
|
107
|
+
.child(error
|
|
108
|
+
? div().text_size(11).text_color(t.blocked).truncate().child(error)
|
|
109
|
+
: h_flex().gap(10).text_size(11).text_color(t.muted)
|
|
110
|
+
.child(div().child(last ? `claude ${gb(last.claude)}` : "claude"))
|
|
111
|
+
.child(div().child(last ? `swap ${gb(last.swap)}` : "swap")));
|
|
112
|
+
|
|
113
|
+
const bars = h_flex().id(`${key}-graph`).flex_1().h_full().min_w(0).overflow_hidden()
|
|
114
|
+
.items_end().justify_end().gap(GAP).rounded(4).bg(t.surface)
|
|
115
|
+
.on_size_change((size, cx) => {
|
|
116
|
+
const zoom = Number(settings().zoom) || 1;
|
|
117
|
+
this.graph = { width: size.width / zoom, height: size.height / zoom };
|
|
118
|
+
cx.notify();
|
|
119
|
+
})
|
|
120
|
+
.children(shown.map((s) =>
|
|
121
|
+
div().flex_none().w(BAR).h(Math.round(share(s) * h)).bg(colors[s.pressure] ?? t.muted)));
|
|
122
|
+
|
|
123
|
+
return h_flex().size_full().px(14).py(8).gap(12).items_center()
|
|
124
|
+
.bg(t.chrome).border_t(1).border_color(t.border)
|
|
125
|
+
.child(readout)
|
|
126
|
+
.child(bars);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "place": "none", "title": "Memory" }
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// The Memory mod's arithmetic: from what macOS's tools print to a reading,
|
|
2
|
+
// and from a reading to what main.js draws of it. It is apart from main.js,
|
|
3
|
+
// and imports nothing, so that the tests can run it with node
|
|
4
|
+
// (test/memory.sh). So it uses only what any JavaScript has: nothing of
|
|
5
|
+
// Herdr's, and nothing of node's.
|
|
6
|
+
|
|
7
|
+
export const GB = 1024 ** 3;
|
|
8
|
+
// What `sysctl kern.memorystatus_vm_pressure_level` prints. macOS has these
|
|
9
|
+
// three levels and no other.
|
|
10
|
+
const PRESSURE = { 1: "normal", 2: "warning", 4: "critical" };
|
|
11
|
+
// The units `sysctl vm.swapusage` writes an amount in, in bytes.
|
|
12
|
+
const UNIT = { K: 1024, M: 1024 ** 2, G: GB };
|
|
13
|
+
// The counts of vm_stat's that memory used is worked out from, each by the
|
|
14
|
+
// name its line starts with.
|
|
15
|
+
const COUNTS = ["Anonymous pages", "Pages purgeable", "Pages wired down", "Pages occupied by compressor"];
|
|
16
|
+
|
|
17
|
+
// One of vm_stat's counts, in pages, or null when it has no line for it.
|
|
18
|
+
function pages(vmStat, name) {
|
|
19
|
+
const m = vmStat.match(new RegExp(`^${name}:\\s+(\\d+)\\.?\\s*$`, "m"));
|
|
20
|
+
return m ? Number(m[1]) : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The reading that the three tools' output gives:
|
|
24
|
+
// sysctl what sysctl prints for hw.memsize, vm.swapusage and
|
|
25
|
+
// kern.memorystatus_vm_pressure_level, each after its name
|
|
26
|
+
// vmStat what vm_stat prints
|
|
27
|
+
// ps what `ps -axc -o rss=,comm=` prints: each process's resident
|
|
28
|
+
// memory in KB, then its command's name
|
|
29
|
+
// It is { total, used, pressure, swap, claude }: bytes, but for the
|
|
30
|
+
// pressure, which is "normal", "warning" or "critical".
|
|
31
|
+
//
|
|
32
|
+
// Memory used is counted as Activity Monitor's Memory Used counts it, which
|
|
33
|
+
// is how the host's recorder counts mem_used_mb (cli/lib/host.sh): the
|
|
34
|
+
// anonymous pages less the purgeable ones, plus the wired ones and those the
|
|
35
|
+
// compressor occupies. claude is the resident memory of every process whose
|
|
36
|
+
// command is exactly claude, and 0 when ps lists none.
|
|
37
|
+
//
|
|
38
|
+
// Without the Mac's total or memory used there is nothing to draw, so the
|
|
39
|
+
// reading is { reason } instead: one short line that says which tool gave
|
|
40
|
+
// none. Any other value that cannot be read is null, and the rest of the
|
|
41
|
+
// reading is kept.
|
|
42
|
+
export function reading(sysctl = "", vmStat = "", ps = "") {
|
|
43
|
+
const total = Number(sysctl.match(/^hw\.memsize:\s*(\d+)\s*$/m)?.[1] ?? 0);
|
|
44
|
+
if (!(total > 0)) return { reason: "no reading from sysctl" };
|
|
45
|
+
|
|
46
|
+
const page = Number(vmStat.match(/page size of (\d+) bytes/)?.[1] ?? 0);
|
|
47
|
+
const counts = COUNTS.map((name) => pages(vmStat, name));
|
|
48
|
+
if (!(page > 0) || counts.includes(null)) return { reason: "no reading from vm_stat" };
|
|
49
|
+
const [anonymous, purgeable, wired, compressor] = counts;
|
|
50
|
+
|
|
51
|
+
const level = sysctl.match(/^kern\.memorystatus_vm_pressure_level:\s*(\d+)\s*$/m)?.[1];
|
|
52
|
+
const swap = sysctl.match(/^vm\.swapusage:.*\bused = (\d+(?:\.\d+)?)([KMG])/m);
|
|
53
|
+
|
|
54
|
+
// ps lists every process, so one that lists none did not run.
|
|
55
|
+
let listed = 0;
|
|
56
|
+
let held = 0;
|
|
57
|
+
for (const line of ps.split("\n")) {
|
|
58
|
+
const m = line.match(/^\s*(\d+)\s+(.*?)\s*$/);
|
|
59
|
+
if (!m) continue;
|
|
60
|
+
listed += 1;
|
|
61
|
+
if (m[2] === "claude") held += Number(m[1]) * 1024;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
total,
|
|
66
|
+
used: (anonymous - purgeable + wired + compressor) * page,
|
|
67
|
+
pressure: PRESSURE[level] ?? null,
|
|
68
|
+
swap: swap ? Math.round(Number(swap[1]) * UNIT[swap[2]]) : null,
|
|
69
|
+
claude: listed ? held : null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// The share of the Mac's memory in use, which is how high a reading's bar
|
|
74
|
+
// is: from 0 to 1, whatever the counts say.
|
|
75
|
+
export const share = (r) => Math.min(1, Math.max(0, r.used / r.total));
|
|
76
|
+
|
|
77
|
+
// An amount of memory as the readout writes it, in GB to one decimal: 9.4.
|
|
78
|
+
// None at all is 0, so that no claude process, or no swap in use, reads as
|
|
79
|
+
// none and not as 0.0, which is an amount too small to show. One that could
|
|
80
|
+
// not be read is –.
|
|
81
|
+
export function gb(bytes) {
|
|
82
|
+
if (bytes == null) return "–";
|
|
83
|
+
return bytes === 0 ? "0" : (bytes / GB).toFixed(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The Mac's total as the readout writes it after memory used: / 16 GB. A
|
|
87
|
+
// whole number of GB has no decimal.
|
|
88
|
+
export const outOf = (total) => `/ ${Math.round((total / GB) * 10) / 10} GB`;
|