@plot-pm/board 0.25.0 → 0.26.0

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/plot-host.sh CHANGED
@@ -699,7 +699,7 @@ gh_marker_comment_id() { gh api --paginate "repos/{owner}/{repo}/issues/$1/comme
699
699
  # EDITS THE COMMENT `$1` HOLDS, OR POSTS `$4` TO `$3` ON `$2` (`issue` or
700
700
  # `pr`) — shared by `issue-comment` and `pr-comment`, whose tails differed
701
701
  # only in that one word.
702
- gh_edit_or_post_comment() { if [ -n "$1" ]; then gh api -X PATCH "repos/{owner}/{repo}/issues/comments/$1" -f body="$4" >/dev/null 2>"$HOST_ERR"; else gh "$2" comment "$3" --body "$4" >/dev/null 2>"$HOST_ERR"; fi; }
702
+ gh_edit_or_post_comment() { if [ -n "$1" ]; then gh api -X PATCH "repos/{owner}/{repo}/issues/comments/$1" -f body="$4" >/dev/null 2>"$HOST_ERR"; else gh api -X POST "repos/{owner}/{repo}/issues/$3/comments" -f body="$4" >/dev/null 2>"$HOST_ERR"; fi; }
703
703
 
704
704
  # Exit 3 — reserved for "the op itself cannot proceed", distinct from `die`'s
705
705
  # generic 1. A Jenkins overlay with no instance to ask is such a case: a config
@@ -725,6 +725,10 @@ CHECKS_OF='def ck: (.conclusion // "") as $k | (.status // "") as $s | (if $s !=
725
725
  MERGEABLE_OF='def mergeable_of: if .mergeable == "CONFLICTING" or .mergeable == false or .mergeStateStatus == "DIRTY" or .mergeable_state == "dirty" then "conflicting"
726
726
  elif .mergeable == "MERGEABLE" or .mergeable == true then "mergeable" else "unknown" end;'
727
727
 
728
+ # THE ONE PROJECTION of a GraphQL-shaped PR into `pr-state`'s printed line, read by
729
+ # the GraphQL arm and by `rest_pr_state`, so the two transports print one shape.
730
+ PR_STATE_OF='{number:.number,state:.state,draft:.isDraft,url:.url,mergeCommit:(.mergeCommit.oid // ""),head:(.headRefName // ""),headSha:(.headRefOid // ""),base:(.baseRefName // ""),checks:checks_of,ciChecks:ci_checks_of,checksSha:(.headRefOid // ""),mergeable:mergeable_of,mergedAt:(.mergedAt // "")}'
731
+
728
732
  # Exit 5 — the host refused to answer FOR NOW. A rate limit, primary or
729
733
  # secondary: nothing is broken, nothing needs fixing, and the same question
730
734
  # asked later will be answered.
@@ -829,7 +833,6 @@ host_cli() { # → the CLI this backend drives, or '' where none is known
829
833
  case "$1" in
830
834
  github) echo "gh" ;;
831
835
  bitbucket) echo "bb" ;;
832
- *) echo "" ;;
833
836
  esac
834
837
  }
835
838
 
@@ -2131,7 +2134,7 @@ bb_fetch_base_bounded() {
2131
2134
  GIT_TERMINAL_PROMPT=0 git fetch -q origin "+refs/heads/$base:refs/remotes/origin/$base" 2>/dev/null & pid=$!
2132
2135
  ( sleep "$BB_FETCH_BOUND_S"; kill -TERM "-$pid" 2>/dev/null ) & watcher=$!
2133
2136
  wait "$pid" 2>/dev/null; rc=$?
2134
- kill "$watcher" 2>/dev/null; wait "$watcher" 2>/dev/null; [ "$was_m" = yes ] || set +m
2137
+ kill -TERM "-$watcher" 2>/dev/null; wait "$watcher" 2>/dev/null; [ "$was_m" = yes ] || set +m
2135
2138
  return "$rc"
2136
2139
  }
2137
2140
 
@@ -2292,7 +2295,7 @@ is_lookup_miss() {
2292
2295
  # `LC_ALL=C` for the reason `is_lookup_miss` gives: the CLI localises, and an
2293
2296
  # English-only matcher would misread every other locale.
2294
2297
  is_rate_refusal() {
2295
- LC_ALL=C grep -qiE 'rate limit|secondary rate|abuse detection|403.*forbidden' <<<"$1"
2298
+ LC_ALL=C grep -qiE 'rate[ _]limit|secondary rate|abuse detection|already exceeded|403.*forbidden' <<<"$1"
2296
2299
  }
2297
2300
 
2298
2301
  # Emits the miss payload on a genuine miss and exits non-zero on anything else,
@@ -2421,7 +2424,7 @@ graphql_budget_spent() {
2421
2424
  #
2422
2425
  # NO CALLER LEARNS THE ROUTE. The answer is consumed inside this script and
2423
2426
  # never reaches stdout, and both paths normalise to one vocabulary — see
2424
- # `rest_pr_to_state`, which exists so a REST answer is indistinguishable from a
2427
+ # `rest_pr_state`, which exists so a REST answer is indistinguishable from a
2425
2428
  # GraphQL one.
2426
2429
  #
2427
2430
  # THE CHEAP PATH IS THE DEFAULT, and this function does not change that. For 93
@@ -2530,22 +2533,32 @@ gh_route() { # $1=op → graphql|rest
2530
2533
  # `--repo` may already carry it (the caller passed `-R owner/repo`). Otherwise
2531
2534
  # `gh api` fills `{owner}/{repo}` from the git remote, with no request. A path
2532
2535
  # naming no real repository answers 404, which `is_lookup_miss` reads as NONE.
2533
- gh_rest_repo() {
2534
- if [ ${#repo_args[@]} -gt 0 ]; then echo "${repo_args[1]}"; else echo '{owner}/{repo}'; fi
2536
+ gh_rest_repo() { local d='{owner}/{repo}'; echo "${repo_args[1]:-$d}"; }
2537
+
2538
+ # ONE REST ANSWER IN GRAPHQL'S VOCABULARY: `pulls/{n}` for the PR, `check-runs` and
2539
+ # `status` for the rollup, folded through the SAME `PR_STATE_OF` the GraphQL arm
2540
+ # prints. `mergeCommit` is set for a merged PR only, because REST fills
2541
+ # `merge_commit_sha` with a test-merge sha on an open one. A rollup page that
2542
+ # holds fewer rows than `total_count` adds one QUEUED row, so a missing row can
2543
+ # make the answer `pending` and never `green`. Exit 1: the PR read failed (a 404
2544
+ # is a miss); exit 2: a later read failed, which is never a miss.
2545
+ rest_pr_state() { # $1=owner/repo $2=PR number or branch; returns 3 when the branch has no PR
2546
+ local pr sha ck='{}' st='{}'
2547
+ if [[ "$2" =~ ^[0-9]+$ ]]; then pr="$(gh_api_harvest "repos/$1/pulls/$2")" || return 1
2548
+ else pr="$(gh_api_harvest "repos/$1/pulls?head=${1%%/*}:$2&state=all&per_page=1")" || return 1; pr="$(jq -ce '.[0]' <<<"$pr")" || return 3; fi
2549
+ sha="$(jq -r '.head.sha // ""' <<<"$pr")"
2550
+ ck="$(gh_api_harvest "repos/$1/commits/$sha/check-runs?per_page=100")" && st="$(gh_api_harvest "repos/$1/commits/$sha/status?per_page=100")" || return 2
2551
+ jq -cs "$CHECKS_OF$MERGEABLE_OF"'.[0] as $p | (.[1].check_runs // []) as $c | (.[2].statuses // []) as $s | (($p.merged == true) or ($p.merged_at != null)) as $m | {number: $p.number, state: (if $m then "MERGED" else ($p.state // "" | ascii_upcase) end), isDraft: ($p.draft // false), url: ($p.html_url // ""), mergeCommit: (if $m then {oid: ($p.merge_commit_sha // "")} else null end), headRefName: ($p.head.ref // ""), headRefOid: ($p.head.sha // ""), baseRefName: ($p.base.ref // ""), mergedAt: ($p.merged_at // ""), mergeable: (if $p.mergeable == true then "MERGEABLE" elif $p.mergeable == false then "CONFLICTING" else "UNKNOWN" end), mergeStateStatus: (($p.mergeable_state // "") | ascii_upcase), statusCheckRollup: ([$c[] | {name, status: ((.status // "") | ascii_upcase), conclusion: ((.conclusion // "") | ascii_upcase)}] + [$s[] | {context, state: ((.state // "") | ascii_upcase)}] + (if ((.[1].total_count // 0) > ($c | length)) or ((.[2].total_count // 0) > ($s | length)) then [{status: "QUEUED"}] else [] end))} |'"$PR_STATE_OF" <<<"$pr$ck$st"
2535
2552
  }
2536
2553
 
2537
- rest_pr_to_state() {
2538
- jq -c "$MERGEABLE_OF"'
2539
- (if (.merged == true) or (.merged_at != null) then "MERGED"
2540
- else (.state // "" | ascii_upcase) end) as $state
2541
- | { number: .number,
2542
- state: $state,
2543
- draft: (.draft // false),
2544
- url: (.html_url // ""),
2545
- mergeCommit: (.merge_commit_sha // ""), head: (.head.ref // ""), headSha: (.head.sha // ""), base: (.base.ref // ""), checks: "unknown", mergeable: mergeable_of,
2546
- mergedAt: (.merged_at // "") }
2547
- '
2548
- }
2554
+ # `owner/repo` from the `origin` URL, with no host call. An `ssh://` URL may carry
2555
+ # a port after the host, and an scp-style remote splits host and path at its first
2556
+ # colon. Prints nothing and exits 1 where the URL names no `owner/repo`.
2557
+ gh_origin_slug() { git config --get remote.origin.url | sed -E 's#\.git/?$##; s#^.*[:/]([^/:]+/[^/:]+)$#\1#' | grep -E '^[^/]+/[^/]+$'; }
2558
+
2559
+ # `gh` as the merger identity where a Merger app token was minted, as the
2560
+ # signed-in one where none was. The token goes into `GH_TOKEN` only.
2561
+ merger_gh() { GH_TOKEN="${merger_token:-${GH_TOKEN-}}" gh "$@"; }
2549
2562
 
2550
2563
  # Bitbucket's --state vocabulary is not GitHub's, and this adapter used to
2551
2564
  # translate in one direction only: every response mapper turns DECLINED into
@@ -3025,11 +3038,15 @@ read_env_var() { # $1=name $2=file → the value, or nothing
3025
3038
  # checkout root only for a standard `git worktree add` checkout; where the
3026
3039
  # command fails, prints nothing, or its parent directory does not exist, this
3027
3040
  # falls through to "no main checkout .env" rather than inventing a path.
3041
+ #
3042
+ # An exported answer for this checkout replaces both git questions
3043
+ # (`plot_given_common_dir`); another repository's asks git.
3028
3044
  plot_env_file() {
3029
3045
  local root env_file common
3030
- root="$(git rev-parse --show-toplevel 2>/dev/null)" || root="."; env_file="$root/.env"
3046
+ . "$here/plot-desk-root.sh"
3047
+ root="$(plot_given_common_dir "$PWD" top || git rev-parse --show-toplevel 2>/dev/null)" || root="."; env_file="$root/.env"
3031
3048
  plot_env_file_qualifies "$env_file" "$1" "$2" && { printf '%s|' "$env_file"; return 0; }
3032
- common="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" && [ -n "$common" ] || return 0
3049
+ common="$(plot_given_common_dir "$PWD" || git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" && [ -n "$common" ] || return 0
3033
3050
  env_file="$(dirname "$common")/.env"
3034
3051
  plot_env_file_qualifies "$env_file" "$1" "$2" && printf "%s|the main checkout's " "$env_file"
3035
3052
  }
@@ -4033,46 +4050,22 @@ case "$op" in
4033
4050
  # learn what was just read for free.
4034
4051
  #
4035
4052
  # A number and a branch name need DIFFERENT endpoints, and their
4036
- # payload shapes differ too — see `rest_pr_to_state`, which is the one
4053
+ # payload shapes differ too — see `rest_pr_state`, which is the one
4037
4054
  # place that knows how to read either.
4038
4055
  rest_repo="$(gh_rest_repo)" || exit $?
4039
- if [[ "$ref" =~ ^[0-9]+$ ]]; then
4040
- if out="$(gh_api_harvest "repos/$rest_repo/pulls/$ref" 2>"$HOST_ERR")"; then
4041
- rm -f "$HOST_ERR"
4042
- rest_pr_to_state <<<"$out"
4043
- else
4044
- host_err
4045
- host_miss_or_fail "$err" \
4046
- '{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}' || exit $?
4047
- fi
4048
- else
4049
- # `?head=owner:branch` is the list form. AN EMPTY ARRAY IS AN ANSWER —
4050
- # the branch has no PR — while a call that never arrived is not, which
4051
- # is why the empty case is handled here and the failure goes through
4052
- # `host_miss_or_fail` like every other transport error.
4053
- #
4054
- # `state=all`, because the default is `open` and a merged PR would
4055
- # otherwise read as NONE — wrong in the reassuring direction.
4056
- rest_owner="${rest_repo%%/*}"
4057
- if out="$(gh_api_harvest "repos/$rest_repo/pulls?head=$rest_owner:$ref&state=all&per_page=1" 2>"$HOST_ERR")"; then
4058
- rm -f "$HOST_ERR"
4059
- if [ "$(jq -r 'length' <<<"$out" 2>/dev/null)" = "0" ]; then
4060
- echo '{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}'
4061
- else
4062
- jq -c '.[0]' <<<"$out" | rest_pr_to_state
4063
- fi
4064
- else
4065
- host_err
4066
- host_miss_or_fail "$err" \
4067
- '{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}' || exit $?
4068
- fi
4069
- fi
4056
+ none='{"number":0,"state":"NONE","draft":false,"url":"","mergeCommit":""}'
4057
+ rest_pr_state "$rest_repo" "$ref" 2>"$HOST_ERR" && rm -f "$HOST_ERR" || {
4058
+ rc=$?; host_err
4059
+ [ "$rc" -ne 3 ] || { echo "$none"; exit 0; }
4060
+ [ "$rc" -ne 2 ] || die3 "pr-state: the checks read failed: $err"
4061
+ host_miss_or_fail "$err" "$none" || exit $?
4062
+ }
4070
4063
  # mergeCommit is what lets a caller ask "which release contains this?" —
4071
4064
  # `git tag --contains <sha>` answers exactly, where dates cannot. It is ""
4072
4065
  # for anything unmerged, which is the honest answer rather than a guess.
4073
4066
  elif out="$(gh ${repo_args[@]+"${repo_args[@]}"} pr view "$ref" --json number,state,isDraft,url,mergeCommit,headRefName,headRefOid,baseRefName,statusCheckRollup,mergeable,mergeStateStatus,mergedAt 2>"$HOST_ERR")"; then
4074
4067
  rm -f "$HOST_ERR"
4075
- jq -c "$CHECKS_OF$MERGEABLE_OF"'{number:.number,state:.state,draft:.isDraft,url:.url,mergeCommit:(.mergeCommit.oid // ""),head:(.headRefName // ""),headSha:(.headRefOid // ""),base:(.baseRefName // ""),checks:checks_of,ciChecks:ci_checks_of,checksSha:(.headRefOid // ""),mergeable:mergeable_of,mergedAt:(.mergedAt // "")}' <<<"$out"
4068
+ jq -c "$CHECKS_OF$MERGEABLE_OF$PR_STATE_OF" <<<"$out"
4076
4069
  else
4077
4070
  host_err
4078
4071
  # REFUSED FOR RATE IS NOT ANSWERED. The budget gate above could not see
@@ -4381,8 +4374,13 @@ case "$op" in
4381
4374
  # decided here: `checkedReview` judges the list against the Review app's bot
4382
4375
  # login. The pages and the PR travel through stdin, never `--argjson` (the
4383
4376
  # 128 KB argv cap on Linux).
4384
- out="$(gh pr view "${1:?pr-review needs a PR number}" --json headRefOid,comments)" && st="$(gh api --paginate "repos/{owner}/{repo}/commits/$(jq -r .headRefOid <<<"$out")/statuses?per_page=100")" \
4385
- && printf '%s\n%s\n' "$out" "$st" | jq -cs '.[0] as $pr | [.[1:][][] | select(.context == "plot/review")] as $s | $s[0] as $m | {sha: $pr.headRefOid, state: ($m.state // "absent"), description: ($m.description // ""), time: ($m.updated_at // ""), bypass: any($pr.comments[]?; .body | startswith("review-bypass:")), statuses: [$s[] | {state, description: (.description // ""), time: (.updated_at // ""), writer: (.creator.login // "")}]}' \
4377
+ # REST ONLY: `gh pr view` is GraphQL, and its secondary limit refused three
4378
+ # reviews on 2026-11-08 while core stood at 4797 of 5000. Comments and
4379
+ # statuses are paginated, and a failed read is a failed answer, never an
4380
+ # empty list. The pages reach `jq` through `--slurpfile`, not `--argjson`.
4381
+ out="$(gh_api_harvest "repos/{owner}/{repo}/pulls/${1:?pr-review needs a PR number}")" && sha="$(jq -re '.head.sha' <<<"$out")" \
4382
+ && cm="$(gh api --paginate "repos/{owner}/{repo}/issues/$1/comments?per_page=100")" && st="$(gh api --paginate "repos/{owner}/{repo}/commits/$sha/statuses?per_page=100")" \
4383
+ && jq -nc --arg sha "$sha" --slurpfile cm <(printf '%s' "$cm") --slurpfile st <(printf '%s' "$st") '[$st[][] | select(.context == "plot/review")] as $s | $s[0] as $m | {sha: $sha, state: ($m.state // "absent"), description: ($m.description // ""), time: ($m.updated_at // ""), bypass: any($cm[][]; .body | startswith("review-bypass:")), statuses: [$s[] | {state, description: (.description // ""), time: (.updated_at // ""), writer: (.creator.login // "")}]}' \
4386
4384
  || die3 "pr-review: the read failed" ;;
4387
4385
 
4388
4386
  pr-create)
@@ -4425,10 +4423,15 @@ case "$op" in
4425
4423
  # answers 5 with its one-line notice where no key is declared: the merge
4426
4424
  # then runs as the signed-in `gh` identity. The token goes straight into
4427
4425
  # GH_TOKEN — never into argv, a file, or a log line.
4428
- merger_repo=$(gh repo view --json nameWithOwner --jq '.nameWithOwner' 2>/dev/null) || die3 "pr-merge: gh repo view could not resolve owner/repo from the current checkout"
4426
+ merger_repo="$(gh_origin_slug)" || die3 "pr-merge: the origin remote names no owner/repo; nothing was merged"
4429
4427
  merger_token=$(node "$here/plot-merger-token.mjs" "$merger_repo") || { mc=$?; [ "$mc" = 5 ] || exit "$mc"; }
4430
- args=(pr merge "$num"); [ "$squash" = 1 ] && args+=(--squash) || args+=(--merge); [ "$delbranch" = 1 ] && args+=(--delete-branch)
4431
- if [ -n "$merger_token" ]; then GH_TOKEN="$merger_token" gh "${args[@]}" --match-head-commit "$pin"; else gh "${args[@]}" --match-head-commit "$pin"; fi
4428
+ # `PUT pulls/{n}/merge` with `sha` is the head pin, and GitHub answers 409
4429
+ # for a head that moved. A 405 (not mergeable) is a different answer and
4430
+ # keeps the host's own words. The branch delete is cleanup after the merge:
4431
+ # its failure warns and does not undo or fail the merge.
4432
+ if out="$(merger_gh api -X PUT "repos/{owner}/{repo}/pulls/$num/merge" -f merge_method="$([ "$squash" = 1 ] && echo squash || echo merge)" -f sha="$pin" 2>&1)"; then
4433
+ [ "$delbranch" != 1 ] || merger_gh api -X DELETE "repos/{owner}/{repo}/git/refs/heads/$(merger_gh api "repos/{owner}/{repo}/pulls/$num" --jq 'select(.head.repo.full_name == .base.repo.full_name) | .head.ref' 2>/dev/null)" >/dev/null 2>&1 || echo "plot-host: pr-merge: PR #$num merged, but its branch was not deleted" >&2
4434
+ else [[ "$out" != *"HTTP 409"* ]] || out="--match-head: head-moved — PR #$num is no longer at $pin; nothing was merged"; echo "plot-host: pr-merge: $out" >&2; exit 1; fi
4432
4435
  # Bitbucket's merge endpoint takes no head precondition (measured 2026-10-18,
4433
4436
  # see plan Notes), so the pin is enforced by re-reading the head via bb_state_row
4434
4437
  # right before merging; it matches by prefix, 7+ hex (domain's sameCommit).
@@ -5326,7 +5329,7 @@ case "$op" in
5326
5329
  # `search/jql` takes the same params as v3 but returns
5327
5330
  # `summary`/`description` as plain strings.
5328
5331
  max="${limit:-50}"
5329
- fields="summary,created,status,assignee,issuetype"
5332
+ fields="summary,created,status,assignee,issuetype,fixVersions"
5330
5333
  if [ "$state" = closed ]; then
5331
5334
  # THE CLOSED READ REQUIRES `Ticket prefixes` AND READS NOT PLOT_JIRA_JQL.
5332
5335
  # An unscoped `resolved >=` query reads the whole instance — the hazard
@@ -5421,7 +5424,7 @@ case "$op" in
5421
5424
  url: ($base + "/browse/" + .key),
5422
5425
  createdAt: (.fields.created // ""),
5423
5426
  status: (.fields.status.name // ""),
5424
- statusCategory: (.fields.status.statusCategory.name // ""), assignees: ([.fields.assignee.emailAddress // .fields.assignee.accountId] | map(select(. != null)))
5427
+ statusCategory: (.fields.status.statusCategory.name // ""), assignees: ([.fields.assignee.emailAddress // .fields.assignee.accountId] | map(select(. != null))), releases: [.fields.fixVersions[]?.name]
5425
5428
  } + (if .fields.issuetype.name then {type: .fields.issuetype.name} else {} end) + (if .fields.updated then {updatedAt: .fields.updated} else {} end) + (if ($state == "closed") or ($state == "changed" and .fields.status.statusCategory.name == "Done") then {closedAt: (.fields.resolutiondate // "")} else {} end)),
5426
5429
  (select($paged == "1") | (.nextPageToken // empty) | {nextPageToken: .})'
5427
5430
  elif [ "$be" = "github" ]; then
@@ -5452,7 +5455,7 @@ case "$op" in
5452
5455
  # several, so a state that already uses one here is refused instead of
5453
5456
  # silently losing the title filter (open issues is the lookup's only use).
5454
5457
  [ -z "$title_has" ] || [ "$gh_state" = open ] || die "issue-list: --title-has only works with --state open"
5455
- gh_json="number,title,url,createdAt,assignees,issueType"; search_args=(); ask_state="$gh_state"
5458
+ gh_json="number,title,url,createdAt,assignees,issueType,milestone"; search_args=(); ask_state="$gh_state"
5456
5459
  [ -z "$label" ] || search_args=(--label "$label")
5457
5460
  if [ "$gh_state" = changed ]; then gh_json+=",updatedAt,state,closedAt"; ask_state=all; search_args+=(--search "updated:>=$since")
5458
5461
  elif [ "$gh_state" != open ]; then gh_json+=",closedAt,labels"; search_args+=(--search "closed:>=$since")
@@ -5473,7 +5476,7 @@ case "$op" in
5473
5476
  jq -c --arg status "$gh_state" \
5474
5477
  '.[] | ((.state // $status) | ascii_downcase) as $actual |
5475
5478
  {number:.number,title:.title,url:(.url // ""),createdAt:(.createdAt // ""),
5476
- status:$actual,statusCategory:(if $actual == "open" then "To Do" else "Done" end),assignees:[.assignees[]?.login]}
5479
+ status:$actual,statusCategory:(if $actual == "open" then "To Do" else "Done" end),assignees:[.assignees[]?.login],releases:[.milestone.title? // empty]}
5477
5480
  + (if .updatedAt then {updatedAt:.updatedAt} else {} end) + (if .issueType.name? then {type:.issueType.name} else {} end)
5478
5481
  + (if $actual == "closed" then {closedAt:(.closedAt // "")} else {} end) + (if .labels then {labels:[.labels[].name]} else {} end)' <<<"$out"
5479
5482
  else
@@ -5732,7 +5735,7 @@ case "$op" in
5732
5735
  # comment per issue and closes the issue at release; nothing reads any back,
5733
5736
  # except `issue-comment-read`, the plan-state comment's one sanctioned
5734
5737
  # read-back (D6: recovering ticket lines a write has no record to redo).
5735
- # issue-label <n> <add> [<remove,...>] adds one label, creating it first where the repo lacks it, and removes only the listed ones the issue carries, in one `gh issue edit`
5738
+ # issue-label <n> <add> [<remove,...>] adds one label, creating it first where the repo lacks it, and removes only the listed ones the issue carries, all through REST
5736
5739
  # issue-comment <n> <marker> <body> edits the comment holding <marker>, else posts; an empty <marker> always posts
5737
5740
  # issue-comment-read <n> <marker> prints the marked comment's body, or nothing where none carries it
5738
5741
  # issue-close <n>
@@ -5741,7 +5744,10 @@ case "$op" in
5741
5744
  num="${1:?$op needs an issue number}"; source_said="$(issue_source)" || exit 1
5742
5745
  [ "$be" = github ] && { [ "$source_said" = git-host ] || [ "$source_said" = $'tracker\tgithub-issues' ]; } || { echo "plot-host: $op: ${source_said#*$'\t'}" >&2; exit 4; }
5743
5746
  case "$op" in
5744
- issue-label) add="${2:?issue-label needs a label}"; carried="$(gh issue view "$num" --json labels -q '.labels[].name' 2>"$HOST_ERR")" || gh_fail; keep="$(comm -12 <(printf '%s\n' "${3-}" | tr , '\n' | sort) <(printf '%s\n' "$carried" | sort) | paste -sd, -)"; gh label create "$add" --color ededed --description "Plot plan phase: ${add#plan:}" >/dev/null 2>"$HOST_ERR" || grep -qi 'already exists' "$HOST_ERR" || gh_fail; gh issue edit "$num" --add-label "$add" ${keep:+--remove-label "$keep"} >/dev/null 2>"$HOST_ERR" || gh_fail ;;
5747
+ issue-label) add="${2:?issue-label needs a label}"; carried="$(gh api --paginate "repos/{owner}/{repo}/issues/$num/labels" -q '.[].name' 2>"$HOST_ERR")" || gh_fail
5748
+ gh api -X POST "repos/{owner}/{repo}/labels" -f name="$add" -f color=ededed -f description="Plot plan phase: ${add#plan:}" >"$HOST_ERR" 2>&1 || grep -q already_exists "$HOST_ERR" || gh_fail
5749
+ gh api -X POST "repos/{owner}/{repo}/issues/$num/labels" -f "labels[]=$add" >/dev/null 2>"$HOST_ERR" || gh_fail
5750
+ while IFS= read -r l; do [ -z "$l" ] || gh api -X DELETE "repos/{owner}/{repo}/issues/$num/labels/$(jq -rn --arg s "$l" '$s|@uri')" >/dev/null 2>"$HOST_ERR" || gh_fail; done < <(comm -12 <(printf '%s\n' "${3-}" | tr , '\n' | sort) <(printf '%s\n' "$carried" | sort)) ;;
5745
5751
  issue-close) gh issue close "$num" >/dev/null 2>"$HOST_ERR" || gh_fail ;;
5746
5752
  issue-comment)
5747
5753
  cid="${2:+$(gh_marker_comment_id "$num" "$2")}" || gh_fail
@@ -6041,7 +6047,7 @@ case "$op" in
6041
6047
  # the path, so a numeric workspace survives. An empty slug is `unsupported`.
6042
6048
  [ "$be" = "github" ] || { node "$here/plot-bitbucket-commit-status.mjs" "$(node "$here/board/plot-bitbucket-slug.mjs" "$(git config --get remote.origin.url 2>/dev/null)")" "$@" || exit $?; exit 0; }
6043
6049
  node "$here/plot-commit-status.mjs" --check "$@" || exit $?
6044
- node "$here/plot-commit-status.mjs" --repo "$(gh repo view --json nameWithOwner --jq '.nameWithOwner' 2>/dev/null || echo GH_REPO_VIEW_FAILED)" "$@" || exit $?
6050
+ node "$here/plot-commit-status.mjs" --repo "$(gh_origin_slug || echo GH_REPO_VIEW_FAILED)" "$@" || exit $?
6045
6051
  ;;
6046
6052
 
6047
6053
  pr-comment)
@@ -148,16 +148,14 @@ desk_dirt_lib="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/plot-desk-dirt.sh"
148
148
  # `plot-desk-root.sh` does: `git worktree list` prints resolved paths, and a
149
149
  # directory composed from a logical one (`/tmp` against `/private/tmp` on macOS)
150
150
  # is a prefix no worktree path starts with.
151
+ #
152
+ # AN EXPORTED ANSWER IS TAKEN WHEN IT IS THIS DIRECTORY'S, and git is asked
153
+ # otherwise: see `plot_given_common_dir` (`plot-desk-root.sh`).
151
154
  plot_main_checkout_of() { # $1=directory → the main checkout, or "" (non-zero)
152
- local at="$1" common root=''
153
- [ -n "$at" ] && [ -d "$at" ] || return 1
154
- common=$(git -C "$at" rev-parse --git-common-dir 2>/dev/null) && [ -n "$common" ] && {
155
- common=$(cd -- "$at" 2>/dev/null && cd -- "$common" 2>/dev/null && pwd -P) || common=''
156
- [ -n "$common" ] && root=$(dirname -- "$common")
157
- }
158
- [ -n "$root" ] || root=$(git -C "$at" rev-parse --show-toplevel 2>/dev/null) || return 1
159
- [ -n "$root" ] || return 1
160
- printf '%s' "$root"
155
+ local at="$1" common
156
+ [ -n "$at" ] || return 1
157
+ common=$(plot_given_common_dir "$at") || { common=$(git -C "$at" rev-parse --git-common-dir 2>/dev/null) && common=$(cd -- "$at" && cd -- "$common" && pwd -P); } || return 1
158
+ printf '%s' "${common%/*}"
161
159
  }
162
160
 
163
161
  # The `Agent registry` directory for a main checkout — `manifestDirectory`'s rule.
@@ -179,9 +177,7 @@ plot_main_checkout_of() { # $1=directory → the main checkout, or "" (non-zero)
179
177
  # so leaving the variable unset would reintroduce #1086 one layer down.
180
178
  plot_manifest_dir_for() { # $1=main checkout → prints the directory
181
179
  local root="$1" dir=''
182
- if [ -x "$_plot_wstate_config" ] || [ -r "$_plot_wstate_config" ]; then
183
- dir=$(PLOT_REPO_ROOT="$root" bash "$_plot_wstate_config" get "Agent registry" "" 2>/dev/null) || dir=''
184
- fi
180
+ dir=$(PLOT_REPO_ROOT="$root" bash "$_plot_wstate_config" get "Agent registry" "" 2>/dev/null) || dir=''
185
181
  # Whitespace alone is a key nobody filled in.
186
182
  dir=$(printf '%s' "$dir" | tr -d '[:space:]')
187
183
  [ -n "$dir" ] || dir=".plot/agents"
@@ -196,6 +192,7 @@ plot_manifest_dir_for() { # $1=main checkout → prints the directory
196
192
  # resolves its own bundle: reading `BASH_SOURCE[0]` inside a function reads the
197
193
  # CALLER's file once the function has been exported.
198
194
  _plot_wstate_config="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/plot-config.sh"
195
+ . "${_plot_wstate_config%/*}/plot-desk-root.sh"
199
196
 
200
197
  # THE DIRECTORY IS RESOLVED AT SOURCE TIME, AND THAT IS NOT A STYLE CHOICE.
201
198
  # Both callers invoke the lookup as `manifest=$(plot_manifest_for_worktree …)`,
@@ -205,13 +202,16 @@ _plot_wstate_config="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/plot-co
205
202
  #
206
203
  # A CALLER-SET VALUE WINS and is never overwritten: the dispatcher and the tests
207
204
  # set it, and they know their repo root without being asked.
208
- if [ -z "$PLOT_MANIFEST_DIR" ]; then
209
- _plot_wstate_root=$(plot_main_checkout_of "$PWD" 2>/dev/null) || _plot_wstate_root=''
210
- if [ -n "$_plot_wstate_root" ]; then
211
- PLOT_MANIFEST_DIR=$(plot_manifest_dir_for "$_plot_wstate_root")
212
- fi
213
- unset _plot_wstate_root
205
+ #
206
+ # THE COMMON DIR IS EXPORTED for every process this one starts: a child that
207
+ # sources this file in a worktree of the same repository reads it and asks git
208
+ # nothing (`plot_given_common_dir`). Each dispatch launch blanks it, so an agent
209
+ # asks for itself.
210
+ if [ -z "$PLOT_MANIFEST_DIR" ] && _plot_wstate_root=$(plot_main_checkout_of "$PWD" 2>/dev/null); then
211
+ export PLOT_GIT_COMMON_DIR="$_plot_wstate_root/.git"
212
+ PLOT_MANIFEST_DIR=$(plot_manifest_dir_for "$_plot_wstate_root")
214
213
  fi
214
+ unset _plot_wstate_root
215
215
 
216
216
  # Find the manifest for a worktree → the full path, or "" (non-zero).
217
217
  #
@@ -297,7 +297,7 @@ plot_read_manifest_pid() { # $1=manifest path → "pid\tstartedAt\tpidStartedAt"
297
297
  # `plot_pid_is_current` compares — the live process's start and a pid's own
298
298
  # recorded start use the same `ps -o lstart` shape.
299
299
  _plot_lstart_epoch() { # $1=ps -o lstart= text → epoch seconds, or "" (non-zero)
300
- date -j -f "%a %b %d %H:%M:%S %Y" "$1" +%s 2>/dev/null \
300
+ LC_ALL=C date -j -f "%a %b %d %H:%M:%S %Y" "$1" +%s 2>/dev/null \
301
301
  || date -j -f "%c" "$1" +%s 2>/dev/null \
302
302
  || date -d "$1" +%s 2>/dev/null
303
303
  }
@@ -344,10 +344,11 @@ _plot_pid_readings() { # $1=worktree → "pid\tstartedAt\tpidStartedAt" (pid emp
344
344
  # for an uncheckable pid is "unknown", which the caller turns into `ended`.
345
345
  plot_pid_is_current() { # $1=pid $2=startedAt (ISO-8601) $3=pidStartedAt (ps -o lstart text, optional) → 0 if current, 1 if stale
346
346
  local pid="$1" started="$2" pid_started="${3:-}" proc_start manifest_epoch proc_epoch recorded_epoch slack=3
347
+ local iso='^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$'
347
348
 
348
349
  # Get the process's start time from `ps -o lstart=`. This is portable across
349
350
  # macOS and Linux, though the format differs.
350
- proc_start=$(ps -o lstart= -p "$pid" 2>/dev/null | tr -d '\n')
351
+ proc_start=$(LC_ALL=C ps -o lstart= -p "$pid" 2>/dev/null | tr -d '\n')
351
352
  [ -n "$proc_start" ] || return 1 # Process does not exist.
352
353
  proc_epoch=$(_plot_lstart_epoch "$proc_start") || return 1 # Cannot parse; treat as stale.
353
354
 
@@ -363,8 +364,11 @@ plot_pid_is_current() { # $1=pid $2=startedAt (ISO-8601) $3=pidStartedAt (ps -o
363
364
  # ONE-SIDED fallback: no per-pid start recorded. Convert the manifest's
364
365
  # startedAt (ISO-8601) to epoch seconds. `date -j -f` is macOS; `date -d` is
365
366
  # GNU. Try both.
366
- manifest_epoch=$(date -j -u -f "%Y-%m-%dT%H:%M:%SZ" "$started" +%s 2>/dev/null || date -d "$started" +%s 2>/dev/null) \
367
- || return 1 # Cannot parse; treat as stale to be safe.
367
+ # ONLY THE DISPATCHER'S OWN STAMP IS READ, as `pidIsCurrent` reads it: GNU
368
+ # `date -d` also reads free text such as `yesterday`, which BSD `date` and
369
+ # the rule read as stale (decided 2026-11-09, jwloka).
370
+ [[ "$started" =~ $iso ]] && manifest_epoch=$(date -j -u -f "%Y-%m-%dT%H:%M:%SZ" "$started" +%s 2>/dev/null || date -d "$started" +%s 2>/dev/null) \
371
+ || return 1 # Not an ISO stamp, or cannot parse; treat as stale to be safe.
368
372
 
369
373
  # A process that started BEFORE the manifest's startedAt is a reused pid.
370
374
  # A process that started AT or AFTER is the real worker. The slack is 3 s:
@@ -406,32 +410,6 @@ PLOT_EDITOR_LEFTOVER='\.(tmp[0-9]*|swp|orig|rej|bak)$'
406
410
  # can hold; what it is not is a directory nobody will ever commit.
407
411
  PLOT_TOOL_SCRATCH='(^|/)\.(playwright-mcp|plot/agents|plot/state|omc/state)(/|$)'
408
412
 
409
- # Where the worker's log lives in this worktree, when one is there at all.
410
- #
411
- # THIS FILE OWNS THE RECORD'S FILENAMES, and that ownership is enforced rather
412
- # than merely intended: `workerstate.test.mjs` asserts that plot-fleet-scan.sh
413
- # never names `.plot-worker.` itself, because a read-only scan that touches the
414
- # worker record has started classifying workers again — the duplication removed
415
- # on 2026-08-18, after the two copies had already drifted.
416
- #
417
- # So the caller that needs the log's mtime asks for the PATH and reads the time
418
- # itself. The split is the same one this whole file draws: what Plot's records
419
- # are called is knowledge that lives here; what a timestamp MEANS is the
420
- # caller's question. `changed_ago_of` in plot-fleet-scan.sh is the one consumer
421
- # — the log is the only source that keeps moving while a build runs, so a
422
- # measurement of "when did anything last change" that could not see it would
423
- # report every worker mid-suite as maximally quiet.
424
- #
425
- # ABSENT IS ABSENT: no worktree, or no log in it, prints nothing and returns
426
- # non-zero. plot-dispatch writes the log only where it started the worker
427
- # itself, so a hand-started worker legitimately has none.
428
- plot_worker_log() { # $1=worktree → path to the worker log, or "" (non-zero)
429
- local wt="$1"
430
- [ -n "$wt" ] || return 1
431
- [ -e "$wt/.plot-worker.log" ] || return 1
432
- printf '%s' "$wt/.plot-worker.log"
433
- }
434
-
435
413
  # Is a person being waited on inside this worktree?
436
414
  #
437
415
  # A MARKER FILE IN THE TREE, NOT A STRING IN A FILE. A blocked worker writes a
@@ -466,14 +444,9 @@ plot_worker_log() { # $1=worktree → path to the worker log, or "" (non-zero)
466
444
  # so this does not bite in production; it is recorded here rather than papered
467
445
  # over, because the honest state is "correct under the callers' shell, noisy
468
446
  # under a shell no caller uses" — not "identical under both".
469
- plot_worker_blocked() { # $1=worktree → 0 when a person owes this branch an answer
470
- local wt="$1" f
471
- [ -n "$wt" ] && [ -d "$wt" ] || return 1
472
- for f in "$wt"/PLOT-BLOCKED*; do
473
- [ -e "$f" ] && return 0
474
- done
475
- return 1
476
- }
447
+ #
448
+ # ONE GLOB: the answer is whether `plot_worker_blocked_file` below names a file.
449
+ plot_worker_blocked() { plot_worker_blocked_file "$1" >/dev/null; } # $1=worktree → 0 when a person owes this branch an answer
477
450
 
478
451
  # WHICH file carries the question — the basename, for a caller that must name it.
479
452
  #
@@ -543,9 +516,7 @@ plot_worker_dirty() { # $1=worktree → the dirty files, one per line, leftovers
543
516
  # Best-effort: a desk that cannot take the line still works. Always returns 0.
544
517
  plot_desk_exclude() { # $1=worktree $2=the exact line to exclude
545
518
  local common excl
546
- common=$(git -C "$1" rev-parse --git-common-dir 2>/dev/null) || return 0
547
- [ -n "$common" ] || return 0
548
- case "$common" in /*) ;; *) common="$1/$common" ;; esac
519
+ common=$(plot_given_common_dir "$1" || git -C "$1" rev-parse --path-format=absolute --git-common-dir 2>/dev/null) || return 0
549
520
  excl="$common/info/exclude"
550
521
  mkdir -p "$common/info" 2>/dev/null || return 0
551
522
  grep -qxF "$2" "$excl" 2>/dev/null || printf '%s\n' "$2" >> "$excl" 2>/dev/null || true
@@ -668,12 +639,7 @@ plot_worker_tree_quiet_seconds() { # $1=worktree → seconds | unreadable
668
639
  # THE SAME FILTER THE FINGERPRINT USED, for the same reason: this script's own
669
640
  # records and the monitor's findings file are not work an agent left, and a
670
641
  # raw status would make the monitor watch itself.
671
- paths=''
672
- if command -v plot_worker_dirty_filter >/dev/null 2>&1; then
673
- paths=$(plot_worker_dirty_filter "$status")
674
- else
675
- paths=$(printf '%s' "$status" | cut -c4-)
676
- fi
642
+ paths=$(plot_worker_dirty_filter "$status")
677
643
 
678
644
  # Every path to stat, one per line, absolute. Built in awk rather than a bash
679
645
  # loop so a desk holding hundreds of dirty paths costs one fork.
@@ -794,26 +760,16 @@ plot_worker_tree_quiet_seconds() { # $1=worktree → seconds | unreadable
794
760
  # question each withhold the finding, because a failure to observe is not
795
761
  # evidence of something to see.
796
762
  plot_worker_idle_now() { # $1..$7 as above → idle | silent
797
- local pid="$1" spoken="$2" silence="$3" activity="$4" tree="$5" commits="$6" window="$7"
798
-
799
- [ "$pid" = 'alive' ] || { printf 'silent'; return 0; }
800
- [ "$spoken" = '1' ] || { printf 'silent'; return 0; }
801
-
763
+ local pid="$1" spoken="$2" silence="$3" activity="$4" tree="$5" commits="$6" window="$7" num='^[0-9]+$'
802
764
  # A non-numeric duration is a reading that was not taken. `unavailable`,
803
- # `unreadable` and an empty string all land here, and so would a filesystem
765
+ # `unreadable` and an empty string answer `silent`, and so would a filesystem
804
766
  # report that slipped past the validation above.
805
- case "$window" in ''|*[!0-9]*) printf 'silent'; return 0 ;; esac
806
- case "$silence" in ''|*[!0-9]*) printf 'silent'; return 0 ;; esac
807
- [ "$silence" -ge "$window" ] || { printf 'silent'; return 0; }
808
-
809
- [ "$activity" = 'working' ] && { printf 'silent'; return 0; }
810
-
811
- case "$tree" in ''|*[!0-9]*) printf 'silent'; return 0 ;; esac
812
- [ "$tree" -ge "$window" ] || { printf 'silent'; return 0; }
813
-
814
- [ "$commits" = 'yes' ] || { printf 'silent'; return 0; }
815
- printf 'idle'
816
- return 0
767
+ if [ "$pid" = 'alive' ] && [ "$spoken" = '1' ] && [[ "$window" =~ $num && "$silence" =~ $num && "$tree" =~ $num ]] \
768
+ && [ "$silence" -ge "$window" ] && [ "$activity" != 'working' ] && [ "$tree" -ge "$window" ] && [ "$commits" = 'yes' ]; then
769
+ printf 'idle'
770
+ else
771
+ printf 'silent'
772
+ fi
817
773
  }
818
774
 
819
775
  # ---------------------------------------------------------------------------
@@ -861,8 +817,7 @@ plot_worker_has_commits() { # $1=worktree → 0 yes | 1 no | 2 unanswerable
861
817
  # empty marker of its own is correctly not counted as work either.
862
818
  n=$(git -C "$wt" rev-list --count "$base..HEAD" -- . 2>/dev/null) || return 2
863
819
  case "$n" in ''|*[!0-9]*) return 2 ;; esac
864
- [ "$n" -gt 0 ] && return 0
865
- return 1
820
+ [ "$n" -gt 0 ]
866
821
  }
867
822
 
868
823
  # The total CPU time, in centiseconds, of a pid and every process descended from
@@ -1194,6 +1149,24 @@ plot_worker_waits_free() { # $1=worktree $2=pid → 0 when the record names $2
1194
1149
  # line per desk (`board/plot-desk-loop.mjs`). Asked once per operator command.
1195
1150
  plot_desk_loops() { PLOT_MANIFEST_DIR="${PLOT_MANIFEST_DIR:-}" node "${_plot_wstate_config%/*}/board/plot-desk-loop.mjs" "$@"; }
1196
1151
 
1152
+ # A held liveness token outranks an exit record of 128 or more → 0 when it does.
1153
+ #
1154
+ # `workerLiveness`'s order, held to it by `worker-readings.corpus.test.ts`: a
1155
+ # wrapper whose loop was killed records 128 plus the signal while the harness
1156
+ # the loop started still holds the token. The desk reads `stray-holder` until
1157
+ # `Worker bound` from `startedAt`; a code below 128 keeps its exit arm. Perl
1158
+ # reads the token as `livenessTokenFifo` does: an `lstat` FIFO opened
1159
+ # `O_RDONLY | O_NONBLOCK` is held on `EAGAIN` and released on end-of-file.
1160
+ _plot_stray_holder() { # $1=worktree $2=exit code $3=startedAt (ISO-8601, optional)
1161
+ local bound="${PLOT_WORKER_BOUND:-}" started
1162
+ [[ "$2" =~ ^[0-9]+$ ]] && [ "$2" -ge 128 ] || return 1
1163
+ perl -MFcntl -e 'lstat($ARGV[0]) && -p _ && sysopen(F, $ARGV[0], O_RDONLY | O_NONBLOCK) or exit 2; exit(defined(sysread(F, $b, 1)) ? 1 : $!{EAGAIN} ? 0 : 2)' "$1/.plot-worker.token.fifo" 2>/dev/null || return 1
1164
+ [ -n "$3" ] && started=$(date -j -u -f "%Y-%m-%dT%H:%M:%SZ" "$3" +%s 2>/dev/null || date -d "$3" +%s 2>/dev/null) || return 0
1165
+ [[ "$bound" =~ ^[0-9]+$ ]] || bound=$(PLOT_REPO_ROOT="$(plot_main_checkout_of "$1")" bash "$_plot_wstate_config" get "Worker bound" "" 2>/dev/null)
1166
+ [[ "$bound" =~ ^[0-9]+$ ]] || bound=28800
1167
+ [ "$bound" -eq 0 ] || [ $(($(date +%s) - started)) -lt "$bound" ]
1168
+ }
1169
+
1197
1170
  # Classify the worker in a worktree.
1198
1171
  #
1199
1172
  # $1 = worktree path
@@ -1383,7 +1356,8 @@ plot_worker_state() { # $1=worktree $2=pr-fact → "state\tpid\tcode"
1383
1356
  # `failed` — the guess in the other direction, calling a genuine crash
1384
1357
  # finished, is the one this must never make. A PR is the fact that
1385
1358
  # licenses it, because a PR means the work reached a reviewer.
1386
- *) if [ "$has_pr" = pr ]; then
1359
+ *) _plot_stray_holder "$wt" "$code" "$started_at" && { printf 'running\t%s\t' "$pid"; return; }
1360
+ if [ "$has_pr" = pr ]; then
1387
1361
  printf '%s\t%s\t%s' "$(plot_worker_task_state "$wt" "$has_pr")" "$pid" "$code"
1388
1362
  else
1389
1363
  printf 'failed\t%s\t%s' "$pid" "$code"
@@ -1417,18 +1391,19 @@ plot_worker_state() { # $1=worktree $2=pr-fact → "state\tpid\tcode"
1417
1391
  # and the same dirty filter. A second gathering that drifted would make the
1418
1392
  # corpus test compare this file against itself and pass while production broke.
1419
1393
  #
1420
- # Prints one TAB-separated line, six fields:
1394
+ # Prints one TAB-separated line, eight fields:
1421
1395
  #
1422
- # worktree_here pid_recorded liveness exit blocked dirty unpushed
1396
+ # worktree_here pid_recorded liveness exit blocked dirty unpushed free_wait
1423
1397
  #
1424
- # `liveness` is `live`, `stale`, `orphaned` or `dead` — `orphaned` being a pid
1398
+ # `liveness` is `live`, `stale`, `orphaned`, `stray-holder` or `dead` — `stray-holder`
1399
+ # being a dead pid whose exit record yields to a held token, `orphaned` being a pid
1425
1400
  # that answers with no agent process under it, which is a live wrapper whose
1426
1401
  # agent has gone; `exit` is the code as read, empty for
1427
1402
  # an unreadable record and the literal `-` for an absent one, because an empty
1428
1403
  # field cannot say which of the two it is and the rule answers them alike only
1429
1404
  # because it was told they differ. The PR fact is NOT here: it comes from the
1430
1405
  # caller, exactly as it does for `plot_worker_state`.
1431
- plot_worker_readings() { # $1=worktree → "here\tpid\tliveness\texit\tblocked\tdirty\tunpushed"
1406
+ plot_worker_readings() { # $1=worktree → "here\tpid\tliveness\texit\tblocked\tdirty\tunpushed\tfree_wait"
1432
1407
  local wt="$1" pid="" started_at="" pid_started_at="" manifest_data=""
1433
1408
  local here=1 pid_recorded=0 liveness=dead exit_field='-' blocked=0 dirty=0 ahead=""
1434
1409
 
@@ -1437,7 +1412,7 @@ plot_worker_readings() { # $1=worktree → "here\tpid\tliveness\texit\tblocked\t
1437
1412
  # `plot-fleet-scan.sh`, where `elsewhere` is decided before this file is
1438
1413
  # reached. A caller iterating worktrees it found never sees this arm.
1439
1414
  if [ -z "$wt" ] || [ ! -d "$wt" ]; then
1440
- printf '0\t0\tdead\t-\t0\t0\t'
1415
+ printf '0\t0\tdead\t-\t0\t0\t\t0'
1441
1416
  return
1442
1417
  fi
1443
1418
 
@@ -1493,6 +1468,7 @@ plot_worker_readings() { # $1=worktree → "here\tpid\tliveness\texit\tblocked\t
1493
1468
  if [ -f "$wt/.plot-worker.exit" ]; then
1494
1469
  exit_field=$(cat "$wt/.plot-worker.exit" 2>/dev/null | tr -d ' \n')
1495
1470
  fi
1471
+ [ "$liveness$pid_recorded" = dead1 ] && _plot_stray_holder "$wt" "$exit_field" "$started_at" && liveness=stray-holder
1496
1472
 
1497
1473
  plot_worker_blocked "$wt" && blocked=1 || blocked=0
1498
1474
  [ -n "$(plot_worker_dirty "$wt")" ] && dirty=1 || dirty=0
@@ -1501,6 +1477,6 @@ plot_worker_readings() { # $1=worktree → "here\tpid\tliveness\texit\tblocked\t
1501
1477
  # cannot be asked at all.
1502
1478
  ahead=$(git -C "$wt" rev-list --count '@{upstream}..HEAD' 2>/dev/null) || ahead=""
1503
1479
 
1504
- printf '%s\t%s\t%s\t%s\t%s\t%s\t%s' \
1505
- "$here" "$pid_recorded" "$liveness" "$exit_field" "$blocked" "$dirty" "$ahead"
1480
+ printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' \
1481
+ "$here" "$pid_recorded" "$liveness" "$exit_field" "$blocked" "$dirty" "$ahead" "$([ -n "$started_at" ] && plot_worker_waits_free "$wt" "$pid" && echo 1 || echo 0)"
1506
1482
  }