@johngaynor/ocnus 2.0.1-next.80 → 2.0.1-next.86
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 -3
- package/cli/lib/asks.sh +33 -10
- package/cli/lib/handoff.sh +2 -1
- package/herdr/README.md +92 -2
- package/herdr/layouts/showcase.json +11 -0
- package/herdr/layouts/vibe.json +7 -2
- package/herdr/mods/needs-you/main.js +526 -0
- package/herdr/mods/needs-you/mod.json +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,8 +102,10 @@ what to put in a layout of your own. `vibe` is three columns for steering
|
|
|
102
102
|
every agent without reading code, with no files, diffs or split terminals,
|
|
103
103
|
and the dropdown again, to come back to `default`. Its middle column starts
|
|
104
104
|
with the card list, the cards that are running and every open card of the
|
|
105
|
-
space that is showing
|
|
106
|
-
|
|
105
|
+
space that is showing, and its right column is Needs you, every question
|
|
106
|
+
that waits on you in the space, each answered with a click. The
|
|
107
|
+
`layouts/vibe.json` row in [herdr/README.md](herdr/README.md#whats-here)
|
|
108
|
+
says what each column holds.
|
|
107
109
|
|
|
108
110
|
In a terminal, `ocnus install` and `ocnus help`, which `ocnus` with no
|
|
109
111
|
command is too, open with a banner: OCNUS in block letters beside Ocnus on
|
|
@@ -703,7 +705,9 @@ The first three are a card's latest hand-off, while that is `needs-human`,
|
|
|
703
705
|
and the id is its number in the store. A permission prompt's id starts with
|
|
704
706
|
`p`. `--json` prints the same as one line, for a program:
|
|
705
707
|
`{"space": …, "questions": […]}`, the list empty when none waits. Each
|
|
706
|
-
question has its `id`, `card`, `kind`, `
|
|
708
|
+
question has its `id`, `card`, `kind`, `step` (the step its agent is at:
|
|
709
|
+
its hand-off's, or for a permission prompt the step its card stands on, or
|
|
710
|
+
`null` for a card with no hand-off), `text`, `options` (a list), `at` (when
|
|
707
711
|
it was asked, in UTC), `seconds` (how long ago), `summary` (or `null`),
|
|
708
712
|
`words` (whether it can be answered in your own words) and `running`
|
|
709
713
|
(whether its agent is running, to take an answer). A merge also has `pulls`,
|
|
@@ -760,6 +764,18 @@ Only you answer. Run from inside the session of an agent ocnus started,
|
|
|
760
764
|
`task answer` sends nothing and merges nothing, and says so; `task asks`
|
|
761
765
|
lists there as anywhere.
|
|
762
766
|
|
|
767
|
+
On the `vibe` layout, Needs you does both with a click. It lists what
|
|
768
|
+
`task asks` lists for the space that is showing, the merges after the rest,
|
|
769
|
+
and keeps up on its own. A permission prompt, an approval and a merge have
|
|
770
|
+
their options as buttons, such as Yes and No, Approve, or Merge and Ask for
|
|
771
|
+
changes, and a merge an Open button for each pull request, which opens it in
|
|
772
|
+
your browser. An agent's own options are numbered rows. A click runs
|
|
773
|
+
`task answer` with that option, then shows `✓ Sent`, or what ocnus said
|
|
774
|
+
when it refused, with the buttons back. The last row, Something else,
|
|
775
|
+
answers nothing: it opens the agent, for you to answer in your own words,
|
|
776
|
+
once the opened agent (LAB-239) is there to show it. See
|
|
777
|
+
[herdr/README.md](herdr/README.md#needs-you).
|
|
778
|
+
|
|
763
779
|
A permission prompt is seen through a Claude Code hook, which `task new` and
|
|
764
780
|
`task build` give every `claude` they start: `ocnus task hold <space>
|
|
765
781
|
<card>`. Claude Code runs it beside the prompt. It writes the question to
|
package/cli/lib/asks.sh
CHANGED
|
@@ -313,14 +313,35 @@ ask_pulls() {
|
|
|
313
313
|
done
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
# The step each card of a space stands on, as one JSON object by card, for
|
|
317
|
+
# the permission prompts: the step that comes next when the card's latest
|
|
318
|
+
# hand-off is done, and that hand-off's own step otherwise, as the Step
|
|
319
|
+
# counts section places a card (stand_sql, in handoff.sh). A card with no
|
|
320
|
+
# hand-off is not in it.
|
|
321
|
+
# asks_stands <space>
|
|
322
|
+
asks_stands() {
|
|
323
|
+
local out=''
|
|
324
|
+
if [ -e "$STORE" ]; then
|
|
325
|
+
out=$(store "$STORE" "select json_group_object(card, stand) from (
|
|
326
|
+
select card, $(stand_sql) as stand
|
|
327
|
+
from (select *, row_number() over (partition by card order by id desc) as nth
|
|
328
|
+
from handoffs where space = $(sql_str "$1"))
|
|
329
|
+
where nth = 1);") ||
|
|
330
|
+
die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
331
|
+
fi
|
|
332
|
+
[ -n "$out" ] || out='{}'
|
|
333
|
+
printf '%s\n' "$out"
|
|
334
|
+
}
|
|
335
|
+
|
|
316
336
|
# Every question that waits on the human in a space, a line of JSON each, as
|
|
317
337
|
# `task asks --json` gives one, and with it what `task answer` needs: asked,
|
|
318
|
-
# the time it was asked in seconds since 1970, its
|
|
319
|
-
#
|
|
320
|
-
#
|
|
321
|
-
#
|
|
322
|
-
#
|
|
323
|
-
#
|
|
338
|
+
# the time it was asked in seconds since 1970, and its terminal and pid for
|
|
339
|
+
# a permission prompt. Each has its step: the step of its hand-off, or for a
|
|
340
|
+
# permission prompt the step its card stands on (asks_stands), null for a
|
|
341
|
+
# card with no hand-off. It reads the store, the watch's files, the hooks'
|
|
342
|
+
# files and hc, and changes nothing. The space's tabs are read only when a
|
|
343
|
+
# hand-off waits, and a hand-off's agent counts as not running when its tab
|
|
344
|
+
# is closed or holds its own shell alone, as it is with no tab to look in.
|
|
324
345
|
# asks_collect <space> <the space's folder>
|
|
325
346
|
asks_collect() {
|
|
326
347
|
local space=$1 dir=$2 sep=$'\x1f' rows='' tabs=0 now
|
|
@@ -357,7 +378,7 @@ asks_collect() {
|
|
|
357
378
|
die "could not put $card's question together with jq."
|
|
358
379
|
done <<< "$rows"
|
|
359
380
|
|
|
360
|
-
local f q pid term
|
|
381
|
+
local f q pid term stands=''
|
|
361
382
|
now=$(date +%s)
|
|
362
383
|
for f in "$ASKS_DIR/$space"/*/p*.json; do
|
|
363
384
|
[ -f "$f" ] || continue
|
|
@@ -365,20 +386,22 @@ asks_collect() {
|
|
|
365
386
|
[ -n "$q" ] || continue
|
|
366
387
|
pid=$(printf '%s' "$q" | jq -r '.pid // empty') term=$(printf '%s' "$q" | jq -r '.terminal // empty')
|
|
367
388
|
ask_alive "$pid" && [ -n "$term" ] && [ "$(terminal_doing "$term")" = blocked ] || continue
|
|
389
|
+
[ -n "$stands" ] || stands=$(asks_stands "$space") || exit 1
|
|
368
390
|
printf '%s' "$q" | jq -c --argjson now "$now" --arg allow "$ASK_ALLOW" --arg refuse "$ASK_REFUSE" \
|
|
369
|
-
--arg always "$ASK_ALWAYS" '
|
|
391
|
+
--arg always "$ASK_ALWAYS" --argjson stands "$stands" '
|
|
370
392
|
(.asked | if type == "number" then . else $now end) as $asked
|
|
371
393
|
| {id, card, kind: "permission", text: (.text | if type == "string" then . else "" end),
|
|
372
394
|
options: ([$allow, $refuse] + (if .always == true then [$always] else [] end)),
|
|
373
395
|
at: (.at | if type == "string" then . else ($asked | todate) end),
|
|
374
396
|
seconds: ([$now - $asked, 0] | max), summary: null, words: false, running: true,
|
|
375
|
-
tool: (.tool | if type == "string" then . else null end),
|
|
397
|
+
tool: (.tool | if type == "string" then . else null end), step: ($stands[.card] // null),
|
|
398
|
+
asked: $asked, terminal, pid}' || true
|
|
376
399
|
done
|
|
377
400
|
}
|
|
378
401
|
|
|
379
402
|
# jq: a question as `task asks --json` gives it, without what only `task
|
|
380
403
|
# answer` reads.
|
|
381
|
-
ASK_PUBLIC='del(.asked, .
|
|
404
|
+
ASK_PUBLIC='del(.asked, .terminal, .pid)'
|
|
382
405
|
|
|
383
406
|
# List the questions that wait on the human in a space, oldest first: each
|
|
384
407
|
# with its card, its kind, its id, when it was asked, its text, any summary,
|
package/cli/lib/handoff.sh
CHANGED
|
@@ -454,7 +454,8 @@ COUNT_STEPS='define plan breakdown start build review pr'
|
|
|
454
454
|
# stands on no step, and this is null for it. The counts and the card list
|
|
455
455
|
# both place a card by it, as the column stand of the table latest
|
|
456
456
|
# (log_cards), so a card's dot in the Step counts section and its row in the
|
|
457
|
-
# card list are on the same step.
|
|
457
|
+
# card list are on the same step. `task asks` gives a permission prompt
|
|
458
|
+
# the step its card stands on by it too (asks_stands, in asks.sh).
|
|
458
459
|
stand_sql() {
|
|
459
460
|
printf '%s' "case when status = 'done'
|
|
460
461
|
then case next when 'setup' then 'start' when 'merged' then null else next end
|
package/herdr/README.md
CHANGED
|
@@ -16,11 +16,12 @@ layouts (whole-window arrangements of mods).
|
|
|
16
16
|
| `mods/card-list/` | The card list, at the top of the `vibe` layout's middle column, and in a column of its own beside the terminals on `showcase`: the cards of the space that is showing, in two views. Agents lists the cards running now, the ones that need you first; Linear lists every open card under its parent card, with Start for a card not approved yet. A click on a running card opens its agent on the right. See [The card list](#the-card-list). |
|
|
17
17
|
| `mods/steps/` | The steps of the card whose tab is selected: what each did, how long it took, and how long it waited on you. With no card's tab selected, the space's cards and where each stands. |
|
|
18
18
|
| `mods/step-counts/` | The Step counts section, right above Usage and about as small: the seven steps, each with a dot for every card of the space that is showing that stands on it, coloured by how the card's agent is doing, and how many there are. See [The Step counts section](#the-step-counts-section). |
|
|
19
|
+
| `mods/needs-you/` | Needs you, the right column of `vibe`: the questions that wait on you in the space that is showing, most urgent first, each answered with a click, with nothing typed in the agent's tab. See [Needs you](#needs-you). |
|
|
19
20
|
| `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). |
|
|
20
21
|
| `mods/names/` | Draws nothing but a note saying what it does, and that only where a layout asks for it, as `showcase` does. It gives the spaces and tabs the app takes in from herdr-core, for agents started while the app was closed, the names ocnus gave them. See [Writing the card up](#writing-the-card-up). |
|
|
21
22
|
| `layouts/default.json` | Herdr's own layout with ocnus's panels: the Ocnus spaces panel, the `ocnus-spaces` mod, in place of Herdr's own list of spaces; the layout dropdown, the Cards and Steps panels, the Step counts section, the Usage section, the Memory mod and the CPU mod in the sidebar, with the Step counts right above Usage, Usage above Memory and CPU, and Memory right above CPU; and the settings button beside the tabs. Herdr's Agents section, its `agents` mod, is not on it. The tab bar is a row of Herdr's `tabs`, `agent-settings` and `names`, in a block 1px wide, since a mod runs only while a layout places it. |
|
|
22
|
-
| `layouts/showcase.json` | For seeing each mod working before you choose what to put in a layout of your own: it places every mod ocnus ships, each in a block of its own that shows as soon as the layout opens, and each is the mod itself, on this machine's own data, as on `default`. It is `default` with
|
|
23
|
-
| `layouts/vibe.json` | Three columns side by side, each the window's full height, for steering every agent without reading code. The left one is the sidebar, 268px wide as `default`'s is: Herdr's brand, the layout dropdown, the Ocnus spaces panel and, at its bottom, the Step counts section, the Usage section, the Memory mod and the CPU mod, stacked in that order with nothing between them. The middle one is the card list, the `card-list` mod, which fills its place there (see [The card list](#the-card-list)), above the place for Brainstorm (LAB-240), and the right one is the
|
|
23
|
+
| `layouts/showcase.json` | For seeing each mod working before you choose what to put in a layout of your own: it places every mod ocnus ships, each in a block of its own that shows as soon as the layout opens, and each is the mod itself, on this machine's own data, as on `default`. It is `default` with four changes: the card list, which `default` does not have, is a column of its own left of the terminals, 540px wide; Needs you, which `default` does not have either, is a column of its own right of them, 368px wide; the Usage section, the Memory mod and the CPU mod leave the sidebar for a row along the bottom, under the terminals; and `names` sits at the end of that row, where it draws a note saying that it draws nothing, and what it does. `npm test` fails, naming the mod, when a mod in `mods/` is not on it, so a card that adds a mod adds it here too. |
|
|
24
|
+
| `layouts/vibe.json` | Three columns side by side, each the window's full height, for steering every agent without reading code. The left one is the sidebar, 268px wide as `default`'s is: Herdr's brand, the layout dropdown, the Ocnus spaces panel and, at its bottom, the Step counts section, the Usage section, the Memory mod and the CPU mod, stacked in that order with nothing between them. The middle one is the card list, the `card-list` mod, which fills its place there (see [The card list](#the-card-list)), above the place for Brainstorm (LAB-240), and the right one is Needs you, the `needs-you` mod (see [Needs you](#needs-you)), which turns into the opened agent (LAB-239). The place for Brainstorm is still empty: it is a column with nothing in it, which its card swaps for the mod's block, so the layout names no mod that is not installed. It shows no files, diffs or split terminals: it has no Files panel, no Changes panel, no tab bar and no block for a tab's terminals, shown or hidden, so code is only in the pull requests. It has no settings button and no footer either: the settings button is on `default`, and Herdr's Settings still opens by its key. The `names` mod is beside the brand, in a block 1px wide. `layouts/vibe.svg`, beside it, is its picture in Herdr's Settings: `ocnus install` and `ocnus update` link it, and `ocnus status` lists it, as they do a layout. |
|
|
24
25
|
| `spaces/template/` | The starting `SPACE.md` for every new space. |
|
|
25
26
|
|
|
26
27
|
The skills are in [../skills/](../skills/), outside this folder. They are
|
|
@@ -967,6 +968,7 @@ ocnus task answer <space> <card> <question> <answer>
|
|
|
967
968
|
|---|---|
|
|
968
969
|
| `id` | The question's id, a string: what `task answer` takes |
|
|
969
970
|
| `card`, `kind`, `text` | The card, one of the four kinds, and what is asked. A permission prompt's text names the tool and what it would do, such as `Allow Bash to run: npm test` or `Allow Edit on the file: /repo/app.ts` |
|
|
971
|
+
| `step` | The step the question's agent is at. For an approval, a choice or a merge, the step of its hand-off. For a permission prompt, the step its card stands on, as the Step counts section places a card: the step that comes next when the card's latest hand-off is `done`, and that hand-off's own step otherwise, as after an answer. null for a card with no hand-off |
|
|
970
972
|
| `options` | The options, a list of strings |
|
|
971
973
|
| `at`, `seconds` | When it was asked, in UTC, and how many seconds ago |
|
|
972
974
|
| `summary` | The summary the agent recorded with the question, or null |
|
|
@@ -1373,6 +1375,94 @@ ocnus task answer <space> <card> <question> <answer>
|
|
|
1373
1375
|
tab opens, closes or is renamed, or one of its terminals reports another
|
|
1374
1376
|
status. They also read it again every 6 seconds.
|
|
1375
1377
|
|
|
1378
|
+
### Needs you
|
|
1379
|
+
|
|
1380
|
+
On the `vibe` layout, the right column is Needs you: the questions that
|
|
1381
|
+
wait on you in the space that is showing, as `task asks` lists them (see
|
|
1382
|
+
[Hand-offs](#hand-offs)), each answered with a click and with nothing typed
|
|
1383
|
+
in the agent's tab. An agent with no question waiting is not in it.
|
|
1384
|
+
|
|
1385
|
+
- **It lists what `task asks <space> --json` lists, most urgent first:**
|
|
1386
|
+
permission prompts, approvals and the agents' own lists of options, then
|
|
1387
|
+
merges, and within each of those two groups the question that has waited
|
|
1388
|
+
longest first. That is ocnus's order, oldest first, with the merges moved
|
|
1389
|
+
after the rest, which is the one thing the mod orders. Its heading says how
|
|
1390
|
+
many there are, as `Needs you · 3`.
|
|
1391
|
+
- **Each question shows** its card's ID and title, the step its agent is at
|
|
1392
|
+
(`step`), how long it has waited, as `<1m`, then in whole minutes, hours
|
|
1393
|
+
or days, such as `6m`, `2h` or `3d`, and its kind: Permission, Approve? or
|
|
1394
|
+
Asking in the theme's `blocked` colour, and Merge? in its `done` colour.
|
|
1395
|
+
Under them come the question's text and, when the agent recorded one with
|
|
1396
|
+
it, its summary. The titles come from `task ls <space> --json`, so a card
|
|
1397
|
+
`task ls` does not list, as when no Linear key is saved, shows its ID
|
|
1398
|
+
alone. A read of the titles that fails leaves the ones the space's last
|
|
1399
|
+
read gave.
|
|
1400
|
+
- **A permission prompt, an approval and a merge show their options as
|
|
1401
|
+
buttons in a row**, in the order ocnus gives them, the first standing
|
|
1402
|
+
out. Each answers with the option ocnus gave:
|
|
1403
|
+
|
|
1404
|
+
| Kind | Button | Answers with |
|
|
1405
|
+
|---|---|---|
|
|
1406
|
+
| `permission` | Yes | `allow` |
|
|
1407
|
+
| `permission` | No | `refuse` |
|
|
1408
|
+
| `permission` | Yes, and don't ask again, only where the prompt offers it | `allow from now on` |
|
|
1409
|
+
| `approval` | Approve, Change breakdown, Change plan, Change specification: each option with a capital | the option, such as `approve` |
|
|
1410
|
+
| `merge` | Merge | `merge`, which merges the card's pull requests on GitHub |
|
|
1411
|
+
| `merge` | Ask for changes | `a change you want made`, which goes to the agent |
|
|
1412
|
+
| `merge` | Open and a pull request's repo and number, such as `Open acme/api#7 ↗`, for each of the card's open pull requests (`pulls`) | nothing: it opens the pull request in your browser |
|
|
1413
|
+
|
|
1414
|
+
A merge's `stop here` has no button: give it in the agent's tab.
|
|
1415
|
+
- **An agent's own list of options is a stack of rows**, in the agent's
|
|
1416
|
+
order, each with its number and the option as the agent wrote it, on as
|
|
1417
|
+
many lines as it needs. The last row is Something else. A click on it
|
|
1418
|
+
answers nothing and runs no command: it sets Herdr's shared value
|
|
1419
|
+
`ocnus.open` to `{space, card}`, which the opened agent (LAB-239) reads to
|
|
1420
|
+
open that agent on its conversation, where you answer in your own words.
|
|
1421
|
+
Until the opened agent is installed, nothing reads it. When the agent's
|
|
1422
|
+
own last option is Something else, in any case, it shows once, as that
|
|
1423
|
+
row.
|
|
1424
|
+
- **A click on any other button or row answers its question,** with
|
|
1425
|
+
`ocnus task answer <space> <card> <question> <option>`. From the click,
|
|
1426
|
+
the question shows the choice beside a spinner in place of its buttons or
|
|
1427
|
+
rows, and takes no second answer. Once the command exits zero, which is
|
|
1428
|
+
once ocnus says the agent, the prompt's hook or GitHub took the answer,
|
|
1429
|
+
it shows `✓ Sent:` and the choice until ocnus no longer lists the
|
|
1430
|
+
question. Each question has its own state, so one being sent holds no
|
|
1431
|
+
other. The questions are read again as soon as an answer has ended.
|
|
1432
|
+
- **When ocnus refuses the answer or cannot deliver it,** the question shows
|
|
1433
|
+
what `task answer` said, with its buttons or rows back under it, and
|
|
1434
|
+
nothing reads as sent, so a question that still waits can be answered
|
|
1435
|
+
again. That is so for a question answered already in the tab, one whose
|
|
1436
|
+
agent is not running, a pull request GitHub will not merge as it stands,
|
|
1437
|
+
and each of the other refusals under [Hand-offs](#hand-offs), and for a
|
|
1438
|
+
command that cannot start or has not ended after 2 minutes.
|
|
1439
|
+
- **It keeps up on its own** while Herdr's window is visible. It looks every
|
|
1440
|
+
second, and reads the questions again every 4 seconds, at once when
|
|
1441
|
+
Herdr's tabs in the space open, close, are renamed or report another
|
|
1442
|
+
status, and once an answer has ended. So a question shows within 5
|
|
1443
|
+
seconds of ocnus listing it, and goes within 5 seconds of ocnus no longer
|
|
1444
|
+
listing it, however it was answered: by a click, in the agent's tab or by
|
|
1445
|
+
a merge on GitHub, which ocnus records within a minute. Showing another
|
|
1446
|
+
space reads that space's questions at once. The spaces and the cards'
|
|
1447
|
+
titles are read when another space shows and every minute, on their own,
|
|
1448
|
+
so a slow Linear never holds the questions up. Nothing is read while the
|
|
1449
|
+
window is hidden, and it redraws only when what it shows has changed.
|
|
1450
|
+
- **In place of the list, one line says why** there is none:
|
|
1451
|
+
|
|
1452
|
+
| It says | When |
|
|
1453
|
+
|---|---|
|
|
1454
|
+
| `Nothing needs you.` | No question waits on you in the space. |
|
|
1455
|
+
| `This space is not an ocnus space.` | The Herdr space that is showing is not one of ocnus's spaces. |
|
|
1456
|
+
| `This ocnus cannot list the questions. Run: ocnus update` | The `ocnus` it runs is from before `task asks`. |
|
|
1457
|
+
| What `task asks` or `space ls` said, such as that `sqlite3` is not installed | Either one failed, or could not run. |
|
|
1458
|
+
|
|
1459
|
+
- **It works nothing out itself.** The space comes from `space ls --json`,
|
|
1460
|
+
the questions from `task asks <space> --json`, the titles from
|
|
1461
|
+
`task ls <space> --json`, and what an answer does from `task answer`, so
|
|
1462
|
+
Needs you and the commands always agree. It runs the `ocnus` on your
|
|
1463
|
+
`PATH`, or the copy it is linked from when Herdr cannot start that, as the
|
|
1464
|
+
other panels do.
|
|
1465
|
+
|
|
1376
1466
|
### The Step counts section
|
|
1377
1467
|
|
|
1378
1468
|
On the `default` layout, the Step counts section sits in the sidebar right
|
|
@@ -210,6 +210,17 @@
|
|
|
210
210
|
"min": 280,
|
|
211
211
|
"max": 900,
|
|
212
212
|
"hidden": true
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"id": "needs-you",
|
|
216
|
+
"type": "block",
|
|
217
|
+
"content": {
|
|
218
|
+
"mod": "needs-you"
|
|
219
|
+
},
|
|
220
|
+
"size": {
|
|
221
|
+
"px": 368
|
|
222
|
+
},
|
|
223
|
+
"min": 280
|
|
213
224
|
}
|
|
214
225
|
],
|
|
215
226
|
"padding": 8,
|
package/herdr/layouts/vibe.json
CHANGED
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
// Needs you: the questions that wait on the human in the ocnus space that is
|
|
2
|
+
// showing, most urgent first, each answered with a click. It fills the right
|
|
3
|
+
// column of the vibe layout.
|
|
4
|
+
//
|
|
5
|
+
// What waits, and what answers it, are the ocnus command's to say:
|
|
6
|
+
// `ocnus task asks <space> --json` lists each question with its card, its
|
|
7
|
+
// kind, the step its agent is at, how long it has waited, its text and its
|
|
8
|
+
// options, and `ocnus task answer <space> <card> <question> <option>`
|
|
9
|
+
// answers one, with no one typing in the agent's tab. This mod draws the list
|
|
10
|
+
// and runs that command, and holds no rules about questions: which questions
|
|
11
|
+
// wait, what kind each is and whether an answer was taken all arrive from the
|
|
12
|
+
// command. The one thing it orders is the merges, which it moves after the
|
|
13
|
+
// rest. The cards' titles come from `ocnus task ls <space> --json`.
|
|
14
|
+
//
|
|
15
|
+
// A permission prompt, an approval and a merge show their options as buttons
|
|
16
|
+
// in a row, and a merge has an Open PR button for each of its open pull
|
|
17
|
+
// requests, which opens it in the browser and answers nothing. An agent's own
|
|
18
|
+
// list of options is a stack of numbered rows, the last of them Something
|
|
19
|
+
// else, which answers nothing either: it sets Herdr's shared value ocnus.open
|
|
20
|
+
// to the card, and the opened agent shows the card it names.
|
|
21
|
+
import { View, div, svg } from "gpui-kit";
|
|
22
|
+
import { v_flex, h_flex } from "gpui-base";
|
|
23
|
+
import { exec, spaces, panes, terminals, theme, window, checking, appHome, setShared } from "herdr";
|
|
24
|
+
|
|
25
|
+
// How often to see whether another space is showing, or Herdr's tabs in it
|
|
26
|
+
// have changed. A change in them is read at once, so a question shows within
|
|
27
|
+
// this and a read.
|
|
28
|
+
const LOOK_MS = 1000;
|
|
29
|
+
const ASKS_MS = 4000; // how often to read the questions again
|
|
30
|
+
// A look comes about every LOOK_MS, a little early or late, so the questions
|
|
31
|
+
// are read again at the fourth look after the last read began, counted from
|
|
32
|
+
// its start: a read that waits ASKS_MS from its end comes every 5 seconds.
|
|
33
|
+
const DUE_MS = ASKS_MS - LOOK_MS / 2;
|
|
34
|
+
const TITLES_MS = 60000; // how often to read the spaces and the cards' titles again
|
|
35
|
+
const TIMEOUT_MS = 10000;
|
|
36
|
+
const LIST_TIMEOUT_MS = 30000; // task ls waits up to 20s on Linear
|
|
37
|
+
// task answer waits up to 30s for an agent to end its turn and 15s for it to
|
|
38
|
+
// start on the answer, and a merge asks GitHub.
|
|
39
|
+
const ANSWER_TIMEOUT_MS = 120000;
|
|
40
|
+
// How this mod's own link into the repo that ships it ends.
|
|
41
|
+
const LINKED_AT = "/herdr/mods/needs-you";
|
|
42
|
+
const SPINNER = "mods/workspace-chrome/spinner.svg";
|
|
43
|
+
|
|
44
|
+
// The lines that stand in place of the questions.
|
|
45
|
+
const NOT_A_SPACE = "This space is not an ocnus space.";
|
|
46
|
+
const OLD_CLI = "This ocnus cannot list the questions. Run: ocnus update";
|
|
47
|
+
const NOTHING = "Nothing needs you.";
|
|
48
|
+
|
|
49
|
+
// The word each kind of question shows with.
|
|
50
|
+
const WORDS = new Map([["permission", "Permission"], ["approval", "Approve?"], ["choice", "Asking"], ["merge", "Merge?"]]);
|
|
51
|
+
// The kinds whose options are buttons. Any other kind's are rows.
|
|
52
|
+
const HAS_BUTTONS = new Set(["permission", "approval", "merge"]);
|
|
53
|
+
// What the options of a permission prompt and of a merge read on their
|
|
54
|
+
// buttons. Any other option of theirs has no button. An approval's options
|
|
55
|
+
// read as ocnus gives them, with a capital.
|
|
56
|
+
const BUTTONS = new Map([
|
|
57
|
+
["permission", new Map([["allow", "Yes"], ["refuse", "No"], ["allow from now on", "Yes, and don't ask again"]])],
|
|
58
|
+
["merge", new Map([["merge", "Merge"], ["a change you want made", "Ask for changes"]])],
|
|
59
|
+
]);
|
|
60
|
+
// The last row of an agent's own options, which opens the agent.
|
|
61
|
+
const SOMETHING_ELSE = "Something else";
|
|
62
|
+
|
|
63
|
+
// `herdr-app check` draws the mod once, with no space showing, which would
|
|
64
|
+
// draw one line of text and none of the questions. It is given these to draw
|
|
65
|
+
// instead, so a mistake in an entry fails the check: a question of each kind,
|
|
66
|
+
// given out of order, with the merge first; a permission prompt with two
|
|
67
|
+
// options and one with three; a merge with two pull requests; a choice whose
|
|
68
|
+
// own last option is Something else; one being sent, one sent and one
|
|
69
|
+
// refused; and a card with no title. It draws each line under them too.
|
|
70
|
+
const SAMPLE = {
|
|
71
|
+
space: "demo",
|
|
72
|
+
questions: [
|
|
73
|
+
{ id: "41", card: "ABC-1", kind: "merge", step: "pr", seconds: 7300,
|
|
74
|
+
text: "Merge https://github.com/acme/api/pull/7 and https://github.com/acme/web/pull/3. ocnus's watch sees the merge on GitHub and records it; tell me here if you want a change instead.",
|
|
75
|
+
summary: "Opened both pull requests and moved ABC-1 to In Review.",
|
|
76
|
+
options: ["merge", "a change you want made", "stop here"],
|
|
77
|
+
pulls: ["https://github.com/acme/api/pull/7", "https://github.com/acme/web/pull/3"] },
|
|
78
|
+
{ id: "pa1b2c3d4", card: "ABC-2", kind: "permission", step: "review", seconds: 30,
|
|
79
|
+
text: "Allow Bash to run: npm test -- orders", summary: null, options: ["allow", "refuse", "allow from now on"] },
|
|
80
|
+
{ id: "43", card: "ABC-3", kind: "approval", step: "breakdown", seconds: 200,
|
|
81
|
+
text: "Approve ABC-3 as specified, planned and broken down, and start its build phase?",
|
|
82
|
+
summary: "One piece: one mod and one command.",
|
|
83
|
+
options: ["approve", "change breakdown", "change plan", "change specification"] },
|
|
84
|
+
{ id: "44", card: "ABC-4", kind: "choice", step: "plan", seconds: 360,
|
|
85
|
+
text: "Prices arrive in USD, GBP and EUR. How should the importer store them?", summary: null,
|
|
86
|
+
options: ["store each price in its own currency", "convert each to USD as it comes in",
|
|
87
|
+
"keep the price as it came and a USD column beside it, so that the charts stay simple and nothing is lost",
|
|
88
|
+
"something else"] },
|
|
89
|
+
{ id: "pe5f6a7b8", card: "ABC-5", kind: "permission", step: null, seconds: 90000,
|
|
90
|
+
text: "Allow Edit on the file: /repo/app.ts", summary: null, options: ["allow", "refuse"] },
|
|
91
|
+
{ id: "46", card: "ABC-6", kind: "choice", step: "pr", seconds: 600,
|
|
92
|
+
text: "https://github.com/acme/web/pull/8 is in conflict with main in app.ts. Keep both exports?",
|
|
93
|
+
summary: "The tests fail after the merge of main.", options: ["keep both exports", "keep main's", "stop here"] },
|
|
94
|
+
{ id: "47", card: "ABC-7", kind: "approval", step: "breakdown", seconds: 4000,
|
|
95
|
+
text: "Approve ABC-7 as specified, planned and broken down, and start its build phase?", summary: null,
|
|
96
|
+
options: ["approve", "change breakdown", "change plan", "change specification"] },
|
|
97
|
+
{ id: "p0c1d2e3f", card: "ABC-8", kind: "permission", step: "build", seconds: 15,
|
|
98
|
+
text: "Allow Bash to run: git push", summary: null, options: ["allow", "refuse"] },
|
|
99
|
+
],
|
|
100
|
+
titles: {
|
|
101
|
+
"ABC-1": "Export orders as CSV",
|
|
102
|
+
"ABC-2": "Orders page filters",
|
|
103
|
+
"ABC-3": "Held cards show their blockers",
|
|
104
|
+
"ABC-4": "Coach price snapshot importer",
|
|
105
|
+
"ABC-6": "Retry a failed Linear sync",
|
|
106
|
+
"ABC-7": "Space colours in the sidebar",
|
|
107
|
+
"ABC-8": "Push the release notes",
|
|
108
|
+
},
|
|
109
|
+
answers: {
|
|
110
|
+
"demo/ABC-6/46": { state: "sending", label: "keep both exports" },
|
|
111
|
+
"demo/ABC-7/47": { state: "sent", label: "Approve" },
|
|
112
|
+
"demo/ABC-8/p0c1d2e3f": { state: "failed", label: "Yes",
|
|
113
|
+
said: "ABC-8's permission prompt p0c1d2e3f no longer waits: its terminal, t8, is no longer at a prompt, so it was answered in the tab. Nothing was sent." },
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
function parse(text) {
|
|
118
|
+
try {
|
|
119
|
+
return JSON.parse(text);
|
|
120
|
+
} catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// What a failed command said, without the name it starts its errors with.
|
|
126
|
+
const said = (r) => (r.stderr || r.stdout).trim().replace(/^ocnus: /, "");
|
|
127
|
+
// An ocnus from before `task asks` answers with its usage line, not JSON.
|
|
128
|
+
const failure = (r, what) => {
|
|
129
|
+
const text = said(r);
|
|
130
|
+
return text.startsWith("usage:") ? OLD_CLI : text || `${what} failed`;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// The shown space's folder, when that space is on this computer: the only
|
|
134
|
+
// place an ocnus space can be.
|
|
135
|
+
function shownFolder() {
|
|
136
|
+
const space = spaces().find((s) => s.active);
|
|
137
|
+
return space && !space.machine ? space.folder : null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// What Herdr shows of the tabs in the spaces whose folder is `folder`, on
|
|
141
|
+
// this computer: each tab's id and name, and each of its terminals' status
|
|
142
|
+
// and app. An agent that asks, or is answered in its tab, changes these, so a
|
|
143
|
+
// change in them is read at once. A pane's status has no word for hc's error,
|
|
144
|
+
// so each terminal's own word, from terminals(), is in it too.
|
|
145
|
+
function herdrSees(folder) {
|
|
146
|
+
if (folder === null) return "";
|
|
147
|
+
const word = new Map(terminals().map((t) => [t.address, t.status ?? null]));
|
|
148
|
+
const tabs = new Set();
|
|
149
|
+
const seen = [];
|
|
150
|
+
for (const space of spaces()) {
|
|
151
|
+
if (space.machine || space.folder !== folder) continue;
|
|
152
|
+
for (const tab of space.tabs) {
|
|
153
|
+
tabs.add(tab.id);
|
|
154
|
+
seen.push([tab.id, tab.name]);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (const p of panes()) {
|
|
158
|
+
if (p.terminal && tabs.has(p.tab)) seen.push([p.tab, p.terminal, p.status, p.app, word.get(p.terminal) ?? null]);
|
|
159
|
+
}
|
|
160
|
+
return JSON.stringify(seen);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Most urgent first: the questions in ocnus's order, oldest first, with the
|
|
164
|
+
// merges moved after the rest. Nothing else is put out of ocnus's order.
|
|
165
|
+
const ordered = (questions) => [
|
|
166
|
+
...questions.filter((q) => q.kind !== "merge"),
|
|
167
|
+
...questions.filter((q) => q.kind === "merge"),
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
// What became of a click is kept by the question: its space, its card and
|
|
171
|
+
// its id.
|
|
172
|
+
const keyOf = (space, q) => `${space}/${q.card}/${q.id}`;
|
|
173
|
+
|
|
174
|
+
// How long a question has waited, from its seconds: in whole minutes, then
|
|
175
|
+
// whole hours, then whole days.
|
|
176
|
+
function waited(seconds) {
|
|
177
|
+
const s = Math.max(0, Math.floor(Number(seconds) || 0));
|
|
178
|
+
if (s < 60) return "<1m";
|
|
179
|
+
if (s < 3600) return `${Math.floor(s / 60)}m`;
|
|
180
|
+
if (s < 86400) return `${Math.floor(s / 3600)}h`;
|
|
181
|
+
return `${Math.floor(s / 86400)}d`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// A pull request by its repo and number, as acme/api#7.
|
|
185
|
+
function pullName(url) {
|
|
186
|
+
const m = url.match(/^https?:\/\/[^/]+\/(.+?)\/pull\/(\d+)/);
|
|
187
|
+
return m ? `${m[1]}#${m[2]}` : url;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// A question's options, as ocnus gives them.
|
|
191
|
+
const optionsOf = (q) => (Array.isArray(q.options) ? q.options.filter((o) => typeof o === "string") : []);
|
|
192
|
+
|
|
193
|
+
// The buttons of a permission prompt, an approval or a merge: [label, option]
|
|
194
|
+
// for each option that has one, in the order ocnus gives them.
|
|
195
|
+
function choices(q) {
|
|
196
|
+
const options = optionsOf(q);
|
|
197
|
+
if (q.kind === "approval") return options.map((o) => [o.charAt(0).toUpperCase() + o.slice(1), o]);
|
|
198
|
+
const names = BUTTONS.get(q.kind);
|
|
199
|
+
return names ? options.filter((o) => names.has(o)).map((o) => [names.get(o), o]) : [];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// An agent's own options, for its rows, in its order. An own last option
|
|
203
|
+
// that reads Something else, in any case, is left out: it is the last row.
|
|
204
|
+
function ownOptions(q) {
|
|
205
|
+
const options = optionsOf(q);
|
|
206
|
+
const last = options[options.length - 1];
|
|
207
|
+
return last?.trim().toLowerCase() === SOMETHING_ELSE.toLowerCase() ? options.slice(0, -1) : options;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default class NeedsYou extends View {
|
|
211
|
+
init(_props, cx) {
|
|
212
|
+
this.cmd = "ocnus"; // the one on PATH, until that cannot start
|
|
213
|
+
this.listed = null; // the spaces ocnus listed last
|
|
214
|
+
this.listedAt = 0;
|
|
215
|
+
this.key = null; // the folder that the questions on hand were read for
|
|
216
|
+
this.space = null; // the ocnus space the shown Herdr space is, or null
|
|
217
|
+
this.questions = null; // the questions read last, in ocnus's order
|
|
218
|
+
this.error = null;
|
|
219
|
+
this.busy = false;
|
|
220
|
+
this.readAt = 0;
|
|
221
|
+
this.seen = null; // what Herdr showed of the space's tabs when they were read
|
|
222
|
+
this.again = false; // read again at the next look, as once an answer has ended
|
|
223
|
+
this.drawn = null; // what the last redraw showed, to redraw only on a change
|
|
224
|
+
// The titles of the open cards of the space titlesFor, by card ID.
|
|
225
|
+
this.titles = new Map();
|
|
226
|
+
this.titlesFor = null;
|
|
227
|
+
this.titlesAt = 0;
|
|
228
|
+
this.titlesBusy = false;
|
|
229
|
+
// What became of each click, by question (keyOf): sending, sent, or
|
|
230
|
+
// failed with what ocnus said. Kept until ocnus no longer lists the
|
|
231
|
+
// question.
|
|
232
|
+
this.answers = new Map();
|
|
233
|
+
if (checking()) return;
|
|
234
|
+
cx.timer.every(LOOK_MS, (cx) => this.look(cx));
|
|
235
|
+
this.look(cx);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Runs the ocnus command. With `fallback`, a command that cannot run is
|
|
239
|
+
// tried again as the copy this mod is linked from (Herdr may have been
|
|
240
|
+
// started without the user's PATH). Only the readings ask for that: they
|
|
241
|
+
// only read, and they have run before there is a question to answer. An
|
|
242
|
+
// answer never does, because its failure may be a timeout with the first
|
|
243
|
+
// run still answering.
|
|
244
|
+
async ocnus(args, { fallback = false, timeout = TIMEOUT_MS } = {}) {
|
|
245
|
+
try {
|
|
246
|
+
return await exec(this.cmd, args, { timeout });
|
|
247
|
+
} catch (e) {
|
|
248
|
+
if (!fallback || this.cmd !== "ocnus") throw e;
|
|
249
|
+
const link = await exec("readlink", [`${appHome()}/mods/needs-you`]);
|
|
250
|
+
const at = link.stdout.trim();
|
|
251
|
+
if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
|
|
252
|
+
this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/ocnus`;
|
|
253
|
+
return exec(this.cmd, args, { timeout });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Read the questions again when another space is showing, when Herdr's
|
|
258
|
+
// tabs in it have changed, once an answer has ended, and every 4 seconds:
|
|
259
|
+
// so is a read that failed, which is tried again. A Herdr space that is not
|
|
260
|
+
// an ocnus space is looked up again only as often as the spaces are
|
|
261
|
+
// listed. Nothing is read while nobody can see the window.
|
|
262
|
+
look(cx) {
|
|
263
|
+
if (window()?.visible === false) return;
|
|
264
|
+
this.lookTitles(cx);
|
|
265
|
+
if (this.busy) return;
|
|
266
|
+
const folder = shownFolder();
|
|
267
|
+
const key = folder ?? "";
|
|
268
|
+
const seen = herdrSees(folder);
|
|
269
|
+
const stale = this.space || this.error
|
|
270
|
+
? this.again || Date.now() - this.readAt >= DUE_MS || seen !== this.seen
|
|
271
|
+
: Date.now() - this.readAt >= TITLES_MS;
|
|
272
|
+
if (key === this.key && !stale) return;
|
|
273
|
+
this.busy = true;
|
|
274
|
+
this.again = false;
|
|
275
|
+
const started = Date.now();
|
|
276
|
+
cx.spawn(async (cx) => {
|
|
277
|
+
let space = null;
|
|
278
|
+
let questions = null;
|
|
279
|
+
let error = null;
|
|
280
|
+
try {
|
|
281
|
+
if (folder !== null && (!this.listed || key !== this.key || Date.now() - this.listedAt >= TITLES_MS)) {
|
|
282
|
+
const r = await this.ocnus(["space", "ls", "--json"], { fallback: true });
|
|
283
|
+
const list = r.code === 0 ? parse(r.stdout)?.spaces : null;
|
|
284
|
+
if (Array.isArray(list)) {
|
|
285
|
+
this.listed = list;
|
|
286
|
+
this.listedAt = Date.now();
|
|
287
|
+
} else {
|
|
288
|
+
error = r.code === 0 ? OLD_CLI : failure(r, "ocnus space ls");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (folder !== null && !error) space = (this.listed ?? []).find((s) => s.folder === folder)?.name ?? null;
|
|
292
|
+
if (space) {
|
|
293
|
+
const r = await this.ocnus(["task", "asks", space, "--json"], { fallback: true });
|
|
294
|
+
const got = r.code === 0 ? parse(r.stdout) : null;
|
|
295
|
+
if (Array.isArray(got?.questions)) questions = got.questions.filter((q) => q !== null && typeof q === "object");
|
|
296
|
+
else error = r.code === 0 ? OLD_CLI : failure(r, "ocnus task asks");
|
|
297
|
+
}
|
|
298
|
+
} catch (e) {
|
|
299
|
+
error = `Could not run ocnus: ${e?.message ?? e}`;
|
|
300
|
+
}
|
|
301
|
+
// A question ocnus no longer lists takes what became of its click with
|
|
302
|
+
// it. One still being sent keeps it until its answer has ended.
|
|
303
|
+
if (space && questions) {
|
|
304
|
+
const listed = new Set(questions.map((q) => keyOf(space, q)));
|
|
305
|
+
for (const [k, a] of this.answers) {
|
|
306
|
+
if (k.startsWith(`${space}/`) && a.state !== "sending" && !listed.has(k)) this.answers.delete(k);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
this.key = key;
|
|
310
|
+
this.space = space;
|
|
311
|
+
this.questions = questions;
|
|
312
|
+
this.error = error;
|
|
313
|
+
this.readAt = started;
|
|
314
|
+
this.seen = seen;
|
|
315
|
+
this.busy = false;
|
|
316
|
+
this.redraw(cx);
|
|
317
|
+
this.lookTitles(cx);
|
|
318
|
+
// A space chosen, or an answer ended, while this was being read is
|
|
319
|
+
// read now, not at the next look.
|
|
320
|
+
if ((shownFolder() ?? "") !== key || this.again) this.look(cx);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Read the cards' titles when another space shows and every minute, on
|
|
325
|
+
// their own: `task ls` asks Linear, which may be slow or out of reach, and
|
|
326
|
+
// the questions never wait for it. They are read only for the space that
|
|
327
|
+
// is showing, once its questions have been.
|
|
328
|
+
lookTitles(cx) {
|
|
329
|
+
const space = this.space;
|
|
330
|
+
if (this.titlesBusy || !space || (shownFolder() ?? "") !== this.key) return;
|
|
331
|
+
if (space === this.titlesFor && Date.now() - this.titlesAt < TITLES_MS) return;
|
|
332
|
+
this.titlesBusy = true;
|
|
333
|
+
cx.spawn(async (cx) => {
|
|
334
|
+
const titles = await this.readTitles(space);
|
|
335
|
+
// A read that failed leaves the titles the space's last read gave.
|
|
336
|
+
if (titles || space !== this.titlesFor) this.titles = titles ?? new Map();
|
|
337
|
+
this.titlesFor = space;
|
|
338
|
+
this.titlesAt = Date.now();
|
|
339
|
+
this.titlesBusy = false;
|
|
340
|
+
this.redraw(cx);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// The titles of the space's open cards, by ID, or null when `task ls`
|
|
345
|
+
// cannot list them.
|
|
346
|
+
async readTitles(space) {
|
|
347
|
+
try {
|
|
348
|
+
const r = await this.ocnus(["task", "ls", space, "--json"], { fallback: true, timeout: LIST_TIMEOUT_MS });
|
|
349
|
+
const statuses = r.code === 0 ? parse(r.stdout)?.statuses : null;
|
|
350
|
+
if (!Array.isArray(statuses)) return null;
|
|
351
|
+
const titles = new Map();
|
|
352
|
+
for (const s of statuses) {
|
|
353
|
+
for (const c of Array.isArray(s?.cards) ? s.cards : []) {
|
|
354
|
+
if (typeof c?.id === "string" && typeof c.title === "string") titles.set(c.id.toUpperCase(), c.title);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return titles;
|
|
358
|
+
} catch {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// A redraw of a mod redraws the whole window, so only when what it draws
|
|
364
|
+
// has changed. How long a question has waited is drawn in whole minutes.
|
|
365
|
+
redraw(cx) {
|
|
366
|
+
const titles = this.titlesFor === this.space ? this.titles : new Map();
|
|
367
|
+
const drawn = JSON.stringify([this.key, this.space, this.error, (this.questions ?? []).map((q) =>
|
|
368
|
+
[q.id, q.card, q.kind, q.step, waited(q.seconds), q.text, q.summary, q.options, q.pulls,
|
|
369
|
+
titles.get(String(q.card ?? "").toUpperCase()) ?? null])]);
|
|
370
|
+
if (drawn !== this.drawn) {
|
|
371
|
+
this.drawn = drawn;
|
|
372
|
+
cx.notify();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Answers a question with one of its options, by `task answer`, with no
|
|
377
|
+
// fallback, as the Cards panel's Start runs `task new`: one that timed out
|
|
378
|
+
// may have answered. From the click the question shows the choice and takes
|
|
379
|
+
// no second answer. Exit 0 is ocnus saying the answer was taken, which
|
|
380
|
+
// shows as ✓ Sent; anything else puts the buttons or rows back, under what
|
|
381
|
+
// ocnus said. Each question has its own state, so one being sent holds no
|
|
382
|
+
// other. The questions are read again as soon as it has ended.
|
|
383
|
+
answer(space, q, option, label, cx) {
|
|
384
|
+
const key = keyOf(space, q);
|
|
385
|
+
const was = this.answers.get(key)?.state;
|
|
386
|
+
if (was === "sending" || was === "sent") return;
|
|
387
|
+
this.answers.set(key, { state: "sending", label });
|
|
388
|
+
cx.notify();
|
|
389
|
+
cx.spawn(async (cx) => {
|
|
390
|
+
let failed = null;
|
|
391
|
+
try {
|
|
392
|
+
const r = await this.ocnus(["task", "answer", space, q.card, q.id, option], { timeout: ANSWER_TIMEOUT_MS });
|
|
393
|
+
if (r.code !== 0) failed = said(r) || "ocnus task answer failed";
|
|
394
|
+
} catch (e) {
|
|
395
|
+
failed = `Could not run ocnus: ${e?.message ?? e}`;
|
|
396
|
+
}
|
|
397
|
+
this.answers.set(key, failed === null ? { state: "sent", label } : { state: "failed", label, said: failed });
|
|
398
|
+
this.again = true;
|
|
399
|
+
cx.notify();
|
|
400
|
+
this.look(cx);
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Something else: opens the card's agent on its conversation, where the
|
|
405
|
+
// human answers in their own words, by setting Herdr's shared value
|
|
406
|
+
// ocnus.open to the card, which the opened agent shows. It answers nothing
|
|
407
|
+
// and runs no command, and with no opened agent installed nothing reads it.
|
|
408
|
+
open(space, q) {
|
|
409
|
+
setShared("ocnus.open", { space, card: q.card });
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
render() {
|
|
413
|
+
const t = theme();
|
|
414
|
+
const sample = checking();
|
|
415
|
+
const space = sample ? SAMPLE.space : this.space;
|
|
416
|
+
// Until the space that is showing has been read, nothing is drawn for it.
|
|
417
|
+
const fresh = sample || (shownFolder() ?? "") === this.key;
|
|
418
|
+
const questions = sample ? SAMPLE.questions : fresh && !this.error ? this.questions : null;
|
|
419
|
+
const titles = sample ? new Map(Object.entries(SAMPLE.titles)) : this.titlesFor === space ? this.titles : new Map();
|
|
420
|
+
const answers = sample ? new Map(Object.entries(SAMPLE.answers)) : this.answers;
|
|
421
|
+
const entries = () => ordered(questions).map((q) => this.entry(space, q,
|
|
422
|
+
titles.get(String(q.card ?? "").toUpperCase()) ?? null, answers.get(keyOf(space, q)) ?? null, t));
|
|
423
|
+
// The one line that stands in place of the questions.
|
|
424
|
+
const line = (text, color) => div().py(4).text_size(12.5).text_color(color).whitespace_normal().child(text);
|
|
425
|
+
let items;
|
|
426
|
+
if (sample) items = [...entries(), line(NOT_A_SPACE, t.dim), line(OLD_CLI, t.blocked), line(NOTHING, t.dim)];
|
|
427
|
+
else if (!fresh) items = [line("Reading…", t.dim)];
|
|
428
|
+
else if (this.error) items = [line(this.error, t.blocked)];
|
|
429
|
+
else if (!space) items = [line(NOT_A_SPACE, t.dim)];
|
|
430
|
+
else if (!questions?.length) items = [line(NOTHING, t.dim)];
|
|
431
|
+
else items = entries();
|
|
432
|
+
const heading = space && Array.isArray(questions) ? `Needs you · ${questions.length}` : "Needs you";
|
|
433
|
+
return v_flex().size_full().min_h(0).bg(t.background).text_size(13).text_color(t.foreground)
|
|
434
|
+
.child(h_flex().h(46).flex_none().px(20).items_center().border_b(1).border_color(t.border)
|
|
435
|
+
.child(div().text_size(14).font_semibold().text_color(questions?.length ? t.blocked : t.muted).child(heading)))
|
|
436
|
+
.child(v_flex().id("needs-you-list").flex_1().min_h(0).px(20).py(16).gap(12)
|
|
437
|
+
.overflow_y_scrollbar().mode("always").children(items));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// A question: its card's ID and title, the step its agent is at, how long
|
|
441
|
+
// it has waited and its kind's word, then its text and any summary, then
|
|
442
|
+
// its buttons or rows, or what became of a click on them. `title` is null
|
|
443
|
+
// for a card `task ls` did not list. `st` is what became of a click, or
|
|
444
|
+
// null.
|
|
445
|
+
entry(space, q, title, st, t) {
|
|
446
|
+
const color = q.kind === "merge" ? t.done : t.blocked;
|
|
447
|
+
const taken = st?.state === "sending" || st?.state === "sent";
|
|
448
|
+
const when = [q.step, waited(q.seconds)].filter(Boolean).join(" · ");
|
|
449
|
+
return v_flex().id(`ask-${q.id}`).flex_none().gap(10).px(14).py(12).rounded(10)
|
|
450
|
+
.bg(t.surface).border_1().border_color(color + "55")
|
|
451
|
+
.child(h_flex().gap(8).items_center()
|
|
452
|
+
.child(div().flex_none().text_size(11.5).text_color(t.dim).child(String(q.card ?? "")))
|
|
453
|
+
.child(div().id(`ask-title-${q.id}`).flex_1().min_w(0).truncate().font_medium().tooltip(title ?? "")
|
|
454
|
+
.child(title ?? ""))
|
|
455
|
+
.child(div().flex_none().text_size(11.5).text_color(t.muted).child(when))
|
|
456
|
+
.child(div().flex_none().text_size(11.5).font_semibold().text_color(color)
|
|
457
|
+
.child(WORDS.get(q.kind) ?? String(q.kind ?? ""))))
|
|
458
|
+
.child(div().whitespace_normal().child(String(q.text ?? "")))
|
|
459
|
+
.when(Boolean(q.summary), (el) => el.child(div().text_size(12).text_color(t.muted).whitespace_normal()
|
|
460
|
+
.child(String(q.summary))))
|
|
461
|
+
.when(st?.state === "failed", (el) => el.child(div().text_size(12).text_color(t.blocked).whitespace_normal()
|
|
462
|
+
.child(st.said)))
|
|
463
|
+
.when(!taken, (el) => el.child(HAS_BUTTONS.has(q.kind) ? this.buttons(space, q, t) : this.rows(space, q, t)))
|
|
464
|
+
.when(taken, (el) => el.child(this.status(st, t)));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// A permission prompt's, an approval's or a merge's options as buttons in a
|
|
468
|
+
// row, the first standing out, then a merge's Open PR buttons.
|
|
469
|
+
buttons(space, q, t) {
|
|
470
|
+
const pulls = q.kind === "merge" && Array.isArray(q.pulls) ? q.pulls.filter((u) => typeof u === "string") : [];
|
|
471
|
+
return h_flex().flex_wrap().gap(8).items_center()
|
|
472
|
+
.children(choices(q).map(([label, option], i) => this.button(`ask-${q.id}-${i}`, label, i === 0, t,
|
|
473
|
+
(_e, cx) => this.answer(space, q, option, label, cx))))
|
|
474
|
+
.children(pulls.map((url, i) => this.pull(`ask-${q.id}-pull-${i}`, url, t)));
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
button(id, label, primary, t, action) {
|
|
478
|
+
return h_flex().id(id).h(32).flex_none().px(12).items_center().rounded(8).border_1()
|
|
479
|
+
.border_color(primary ? t.solid : t.input).bg(primary ? t.solid : t.raised)
|
|
480
|
+
.text_color(primary ? t.solid_foreground : t.foreground).text_size(12.5).font_medium()
|
|
481
|
+
.cursor_pointer().hover((s) => s.opacity(0.88)).on_click(action).child(label);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// An Open PR button, named by its pull request's repo and number. It opens
|
|
485
|
+
// the pull request in the browser, answers nothing and runs no command.
|
|
486
|
+
pull(id, url, t) {
|
|
487
|
+
return this.button(id, `Open ${pullName(url)} ↗`, false, t, (_e, cx) => {
|
|
488
|
+
try {
|
|
489
|
+
cx.open_url(url);
|
|
490
|
+
} catch {
|
|
491
|
+
// Not a link the system opens.
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// An agent's own options as a stack of rows, in its order, each with its
|
|
497
|
+
// number and the option as the agent wrote it, on as many lines as it
|
|
498
|
+
// needs; then Something else, numbered after them, which opens the agent.
|
|
499
|
+
rows(space, q, t) {
|
|
500
|
+
const options = ownOptions(q);
|
|
501
|
+
return v_flex().gap(6)
|
|
502
|
+
.children(options.map((o, i) => this.row(`ask-${q.id}-${i}`, i + 1, o, t,
|
|
503
|
+
(_e, cx) => this.answer(space, q, o, o, cx))))
|
|
504
|
+
.child(this.row(`ask-${q.id}-else`, options.length + 1, SOMETHING_ELSE, t, () => this.open(space, q)));
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
row(id, n, text, t, action) {
|
|
508
|
+
return h_flex().id(id).w_full().min_h(40).px(10).py(8).gap(10).items_start().rounded(8)
|
|
509
|
+
.border_1().border_color(t.border).bg(t.background).cursor_pointer()
|
|
510
|
+
.hover((s) => s.bg(t.hover)).on_click(action)
|
|
511
|
+
.child(div().size(22).flex_none().rounded(6).bg(t.raised).flex().items_center().justify_center()
|
|
512
|
+
.text_size(11.5).text_color(t.muted).child(String(n)))
|
|
513
|
+
.child(div().flex_1().min_w(0).pt(2).whitespace_normal().child(text));
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// What became of a click: the choice beside a spinner while it is sent,
|
|
517
|
+
// then ✓ Sent and the choice once ocnus says the answer was taken.
|
|
518
|
+
status(st, t) {
|
|
519
|
+
if (st.state === "sending") {
|
|
520
|
+
return h_flex().gap(8).items_center().text_size(12.5).text_color(t.muted)
|
|
521
|
+
.child(svg(SPINNER).size(12).flex_none().text_color(t.working).spin(900))
|
|
522
|
+
.child(div().flex_1().min_w(0).whitespace_normal().child(`Sending: ${st.label}`));
|
|
523
|
+
}
|
|
524
|
+
return div().text_size(12.5).text_color(t.done).whitespace_normal().child(`✓ Sent: ${st.label}`);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "place": "none", "title": "Needs you" }
|