@johngaynor/ocnus 2.0.1-next.24 → 2.0.1-next.69

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/cli/lib/agents.sh CHANGED
@@ -49,7 +49,11 @@
49
49
  # is not running, ocnus's watch is not running, or gh could not
50
50
  # ask GitHub. That holds whatever the agent in the tab is doing.
51
51
  # Otherwise, with ocnus's watch watching, the card shows as it does
52
- # with no agent state.
52
+ # with no agent state. Such a card is noted as ready to merge when the
53
+ # watch's last pass saw every pull request of the card open and ready
54
+ # (MERGES_READY). That is not an agent state: the log says nothing of
55
+ # it, and only the counts in the list's JSON show it, as the mark
56
+ # ready (counts_sql in handoff.sh).
53
57
  # - No card gets an agent state when jq is missing. None but those whose
54
58
  # pull requests wait on the human get one when hc is missing, or when
55
59
  # neither place can list the space's tabs: herdr-core cannot list its
@@ -224,12 +228,16 @@ card_seen() {
224
228
  # subshell. With Herdr's tabs not read (AGENTS_ON 0), only a card whose pull
225
229
  # requests wait on the human has anything to say: with no tab to look in, no
226
230
  # agent is running.
231
+ #
232
+ # AGENT_READY is 1 for a card ready to merge: its pull requests wait on the
233
+ # human, it has no agent state, and ocnus's watch says they are ready
234
+ # (merges_seen). It is 0 for any other card, and AGENT_JSON is null with it.
227
235
  # card_agent <card> <the card in lower case> <step> <status> <next>
228
236
  # <seconds since the hand-off> <space>
229
- AGENT_JSON=null AGENT_LABEL='' AGENT_FOR=''
237
+ AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0
230
238
  card_agent() {
231
239
  local card=$1 low=$2 step=$3 status=$4 next=$5 since=$6 space=$7
232
- AGENT_JSON=null AGENT_LABEL='' AGENT_FOR=''
240
+ AGENT_JSON=null AGENT_LABEL='' AGENT_FOR='' AGENT_READY=0
233
241
  # Its pull requests wait on the human.
234
242
  local waits=0
235
243
  [ "$step $status" != 'pr needs-human' ] || waits=1
@@ -280,6 +288,9 @@ card_agent() {
280
288
  names=${names:+$names, }$PULL_NAME
281
289
  done
282
290
  ;;
291
+ # Nothing to say of its agent or its pull requests: it is ready to
292
+ # merge when the watch says so.
293
+ '') AGENT_READY=$MERGES_READY ;;
283
294
  esac
284
295
  fi
285
296
 
@@ -318,18 +329,20 @@ card_agent() {
318
329
  }
319
330
 
320
331
  # Work out the agent of every card in a view of the log, as AGENTS_SQL: the
321
- # SQL for the table agents (card, agent) that the log's query joins, with
322
- # each card whose agent has something to say and its JSON. The space's tabs
323
- # are read here, once. AGENT_NOW is the last such agent's label and how long
324
- # it has been so, as the list shows them, for the `now:` line of the log of
325
- # one card. Nothing is worked out without jq, which reads hc's answers, as
326
- # ocnus's watch on the merges needs it to run.
332
+ # SQL for the table agents (card, agent, ready) that the log's query joins,
333
+ # with each card whose agent has something to say and its JSON, with ready
334
+ # 0, and each card ready to merge, which has no agent state: its agent is
335
+ # null and its ready 1, for the list's counts (counts_sql in handoff.sh).
336
+ # The space's tabs are read here, once. AGENT_NOW is the last agent's label
337
+ # and how long it has been so, as the list shows them, for the `now:` line
338
+ # of the log of one card. Nothing is worked out without jq, which reads hc's
339
+ # answers, as ocnus's watch on the merges needs it to run.
327
340
  # agents_table <view> <space> <the space's folder>
328
- AGENTS_SQL='agents (card, agent) as (select null, null where 0)'
341
+ AGENTS_SQL='agents (card, agent, ready) as (select null, null, null where 0)'
329
342
  AGENT_NOW=''
330
343
  agents_table() {
331
344
  local view=$1 name=$2 dir=$3 rows sep=$'\x1f' card low step status next since values='' only=''
332
- AGENTS_SQL='agents (card, agent) as (select null, null where 0)' AGENT_NOW=''
345
+ AGENTS_SQL='agents (card, agent, ready) as (select null, null, null where 0)' AGENT_NOW=''
333
346
  [ -n "$view" ] || return 0
334
347
  command -v jq >/dev/null 2>&1 || return 0
335
348
  agents_read "$name" "$dir"
@@ -341,10 +354,13 @@ agents_table() {
341
354
  from shown where after is null $only order by id;") || return 0
342
355
  while IFS=$sep read -r card low step status next since; do
343
356
  [ -n "$card" ] || continue
344
- card_agent "$card" "$low" "$step" "$status" "$next" "$since" "$name" || AGENT_JSON=null
345
- [ "$AGENT_JSON" != null ] || continue
346
- values="$values${values:+, }($(sql_str "$card"), $(sql_str "$AGENT_JSON"))"
347
- AGENT_NOW="$AGENT_LABEL, for $AGENT_FOR"
357
+ card_agent "$card" "$low" "$step" "$status" "$next" "$since" "$name" || AGENT_JSON=null AGENT_READY=0
358
+ if [ "$AGENT_JSON" != null ]; then
359
+ values="$values${values:+, }($(sql_str "$card"), $(sql_str "$AGENT_JSON"), 0)"
360
+ AGENT_NOW="$AGENT_LABEL, for $AGENT_FOR"
361
+ elif [ "$AGENT_READY" = 1 ]; then
362
+ values="$values${values:+, }($(sql_str "$card"), null, 1)"
363
+ fi
348
364
  done <<< "$rows"
349
- [ -z "$values" ] || AGENTS_SQL="agents (card, agent) as (values $values)"
365
+ [ -z "$values" ] || AGENTS_SQL="agents (card, agent, ready) as (values $values)"
350
366
  }