@plot-pm/board 0.23.1 → 0.25.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
@@ -111,22 +111,37 @@
111
111
  # (exit 0) where none merged. The same query
112
112
  # `pr-merge-commit` runs. EXIT 3 is the question
113
113
  # failing.
114
- # pr-review <number> one JSON line `{"sha","state","bypass"}`: the PR's
115
- # head sha, the newest `plot/review` status on it
116
- # (`success|failure|pending|error`, or `absent`),
117
- # and whether a comment starts `review-bypass:`.
118
- # Bitbucket reads the same words from the
114
+ # pr-review <number> one JSON line `{"sha","state","description","time","bypass","statuses"}`:
115
+ # the PR's head sha, the newest `plot/review`
116
+ # status on it from ANY writer
117
+ # (`success|failure|pending|error`, or
118
+ # `absent`), that status's description and
119
+ # time (both `""` where state is `absent`),
120
+ # whether a comment starts `review-bypass:`, and
121
+ # `statuses`: every `plot/review` status on the
122
+ # head, newest first, as `{"state",
123
+ # "description","time","writer"}` where
124
+ # `writer` is `creator.login` (`""` where the
125
+ # host names none). GitHub reads every page of
126
+ # the head's statuses. The op reports and
127
+ # decides nothing: `checkedReview` judges
128
+ # `statuses` against the Review app's bot login.
129
+ # Bitbucket reads the same state words from the
119
130
  # `plot/review` commit status (SUCCESSFUL,
120
- # FAILED, INPROGRESS, STOPPED). EXIT 3 is the
121
- # question failing.
131
+ # FAILED, INPROGRESS, STOPPED), its
132
+ # `description`, and its `updated_on` as the
133
+ # time — `commit-status` writes that status
134
+ # through `plot-bitbucket-commit-status.mjs`.
135
+ # EXIT 3 is the question failing.
122
136
  # pr-create --title T [--body B] [--base BR] [--head BR] [--draft]
123
137
  # create a PR, print its URL
124
138
  # pr-merge <number> [--squash] [--delete-branch] --match-head <sha>
139
+ # merge the PR. --match-head is
125
140
  # mandatory on every backend. bitbucket
126
141
  # re-reads the head before merging; a
127
142
  # mismatch refuses `head-moved` (exit 1).
128
143
  # pr-ready <number> take a PR out of draft
129
- # merge the PR
144
+ # pr-close <number> close a PR unmerged (bitbucket: decline)
130
145
  # pr-list [--state open|merged|closed|all|settled] [--limit N] [--rich|--rich-open]
131
146
  # settled is merged+declined on bitbucket (no
132
147
  # open sweep) and --state all on github, which
@@ -470,6 +485,9 @@
470
485
  # issue-comment <number> <marker> <body> (github)
471
486
  # edits the comment holding <marker>, else posts
472
487
  # one; an empty <marker> always posts, not idempotent.
488
+ # issue-comment-read <number> <marker> (github) prints the body of
489
+ # the comment holding <marker>, or nothing where
490
+ # none does. The plan-state write's one read-back.
473
491
  # issue-list --label <label> keeps open issues carrying the label (github
474
492
  # only; exit 4 on Bitbucket and on Jira).
475
493
  # issue-list --title-has <text> keeps open issues whose title contains <text>,
@@ -626,7 +644,7 @@
626
644
  # - no auto-merge / merge queues — pr-merge merges immediately or fails
627
645
  # - "closed" state is Bitbucket's DECLINED (normalized to CLOSED here)
628
646
  # - pr-state by BRANCH resolves via pr-list filtering (one extra call)
629
- # - draft flag support depends on the bb CLI version (--draft / --ready)
647
+ # - draft flag support: `bb pr create --draft`, `bb pr edit <n> --ready`
630
648
  # Small-model consumption: structured output, no interpretation, exit 0 with
631
649
  # state NONE rather than nonzero on lookup misses.
632
650
 
@@ -668,27 +686,20 @@ host_err() { err="$(cat "$HOST_ERR" 2>/dev/null)"; rm -f "$HOST_ERR"; }
668
686
 
669
687
  # THE ONE MARKER LOOKUP, shared by `pr-comment` and `issue-comment` — GitHub's
670
688
  # REST comments endpoint is `issues/$num/comments` for both, since a PR is an
671
- # issue under the hood. Prints the id of the comment holding `$2` (a
672
- # substring), scoped to the comment's `.user.login` (the REST field; `gh pr
673
- # list --json` answers `.author.login` instead, but this is the REST path) —
674
- # so a PR participant who pastes the same marker into their own comment is
675
- # never mistaken for this script's own prior post. Prints empty on no match.
676
- #
677
- # SCOPED TO THE LOGIN `gh api user` ANSWERS for the token this call writes
678
- # with (`host.ts:358`), asked once per lookup. Not `budget_account`: it reads
679
- # `hosts.yml` or `PLOT_BUDGET_ACCOUNT`, and neither names the author when
680
- # `GH_TOKEN` is set or the account is a grouping name, so every lookup missed
681
- # and posted a new comment.
682
- #
683
- # NO LOGIN, NO SCOPE. When `gh api user` fails or answers no valid login (an
684
- # App installation token gets 403 there), the match falls back to the marker
685
- # alone, as it was before #2661. A comment with no `user` field cannot be
686
- # attributed and also matches on the marker alone.
689
+ # issue under the hood. Prints the id of the oldest comment holding `$2` (a
690
+ # substring), whatever its author, or nothing. The marker alone decides: a
691
+ # lookup scoped to the writer's login posted a second comment whenever another
692
+ # account (a person's machine, fleetd's token) wrote the same marked comment.
687
693
  #
688
694
  # A FAILED LISTING EXITS 3 THROUGH `gh_fail`, same as a failed edit. `set -o
689
695
  # pipefail` (above) makes the pipeline's exit code `gh api`'s own, so a lookup
690
696
  # that cannot be read never falls through to "no marker found, post new".
691
- gh_marker_comment_id() { gh api --paginate "repos/{owner}/{repo}/issues/$1/comments" 2>"$HOST_ERR" | jq -rs --arg m "$2" --arg who "$(gh api user -q .login 2>/dev/null | grep -E '^[A-Za-z0-9][A-Za-z0-9-]*(\[bot\])?$')" '[.[][] | select($who == "" or (.user.login // "") == "" or .user.login == $who) | select(.body | contains($m))][0].id // empty'; }
697
+ gh_marker_comment_id() { gh api --paginate "repos/{owner}/{repo}/issues/$1/comments" 2>"$HOST_ERR" | jq -rs --arg m "$2" '[.[][] | select(.body | contains($m))][0].id // empty'; }
698
+
699
+ # EDITS THE COMMENT `$1` HOLDS, OR POSTS `$4` TO `$3` ON `$2` (`issue` or
700
+ # `pr`) — shared by `issue-comment` and `pr-comment`, whose tails differed
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; }
692
703
 
693
704
  # Exit 3 — reserved for "the op itself cannot proceed", distinct from `die`'s
694
705
  # generic 1. A Jenkins overlay with no instance to ask is such a case: a config
@@ -703,8 +714,8 @@ CHECKS_OF='def ck: (.conclusion // "") as $k | (.status // "") as $s | (if $s !=
703
714
  if $k != "" and ($s|IN("","COMPLETED")) then (if ($k|IN("SUCCESS","NEUTRAL","SKIPPED")) then "ok" else "bad" end)
704
715
  elif ($w|IN("","QUEUED","IN_PROGRESS","WAITING","REQUESTED","PENDING","EXPECTED")) then "wait"
705
716
  elif $s == "" and $w == "SUCCESS" then "ok" else "bad" end;
706
- def checks_of: if (.statusCheckRollup|length) == 0 then "none" elif any(.statusCheckRollup[]; ck == "bad") then "failing"
707
- elif any(.statusCheckRollup[]; ck == "wait") then "pending" else "green" end;'
717
+ def colour_of($r): if ($r|length) == 0 then "none" elif any($r[]; ck == "bad") then "failing" elif any($r[]; ck == "wait") then "pending" else "green" end;
718
+ def checks_of: colour_of(.statusCheckRollup // []); def ci_checks_of: colour_of([.statusCheckRollup[]? | select((.context // .name // "") != "plot/review")]);'
708
719
 
709
720
  # THE ONE FOLD of a PR's mergeability into a word, for `pr-list --rich` and both
710
721
  # `pr-state` transports. GraphQL says `mergeable` CONFLICTING|MERGEABLE|UNKNOWN
@@ -857,15 +868,11 @@ pr_list_failed() { # $1=stderr text
857
868
  # NO REPAIR NAMED, AND THAT IS THE ANSWER. A burst refusal clears in
858
869
  # seconds and nothing is broken, so `$cli auth login` here would send a
859
870
  # reader to fix a login that is already fine. The decision is the wait.
860
- echo "plot-host: pr-list: host refused a burst — ${err:-the host refused the request and said nothing}" >&2
861
- echo " Nothing is wrong and nothing needs fixing: this limit bounds calls at" >&2
862
- echo " once, not per hour. Retry shortly, with fewer at a time." >&2
871
+ printf '%s\n' "plot-host: pr-list: host refused a burst — ${err:-the host refused the request and said nothing}" " Nothing is wrong and nothing needs fixing: this limit bounds calls at" " once, not per hour. Retry shortly, with fewer at a time." >&2
863
872
  exit 6
864
873
  ;;
865
874
  throttled)
866
- echo "plot-host: pr-list: host throttled — ${err:-the host refused the request and said nothing}" >&2
867
- echo " The window's quota is spent. Wait for the reset the message names," >&2
868
- echo " or run against an account with quota left. No login will help." >&2
875
+ printf '%s\n' "plot-host: pr-list: host throttled — ${err:-the host refused the request and said nothing}" " The window's quota is spent. Wait for the reset the message names," " or run against an account with quota left. No login will help." >&2
869
876
  exit 5
870
877
  ;;
871
878
  timeout)
@@ -873,9 +880,7 @@ pr_list_failed() { # $1=stderr text
873
880
  # 504 means the server took too long, not that the credential is bad, so
874
881
  # `host_repair`'s `gh auth login` would send a reader to fix a login
875
882
  # that was never broken. The decision is to ask again, not to log in.
876
- echo "plot-host: pr-list: host timed out — ${err:-the host took too long and said nothing}" >&2
877
- echo " Nothing is wrong with the login: the server took too long to answer." >&2
878
- echo " The next refresh asks again." >&2
883
+ printf '%s\n' "plot-host: pr-list: host timed out — ${err:-the host took too long and said nothing}" " Nothing is wrong with the login: the server took too long to answer." " The next refresh asks again." >&2
879
884
  exit 3
880
885
  ;;
881
886
  esac
@@ -1897,10 +1902,7 @@ jenkins_instance() {
1897
1902
  # only a person can fix, and deliberately NOT exit 4: a `CI: jenkins` repository
1898
1903
  # CAN be asked about builds, it just has not said where.
1899
1904
  jenkins_no_instance() {
1900
- echo "plot-host: CI is jenkins but no Jenkins instance is configured" >&2
1901
- echo " Add a 'Jenkins instance' key to the ## Plot Config section of CLAUDE.md," >&2
1902
- echo " naming the instance \`jen\` knows, or set JENKINS_INSTANCE." >&2
1903
- echo " Or drop the 'CI: jenkins' key to read build status from the git host." >&2
1905
+ printf '%s\n' "plot-host: CI is jenkins but no Jenkins instance is configured" " Add a 'Jenkins instance' key to the ## Plot Config section of CLAUDE.md," " naming the instance \`jen\` knows, or set JENKINS_INSTANCE." " Or drop the 'CI: jenkins' key to read build status from the git host." >&2
1904
1906
  exit 3
1905
1907
  }
1906
1908
 
@@ -1914,26 +1916,6 @@ jenkins_no_instance() {
1914
1916
  # estimate for. This draws it one step earlier, for a connector that does not
1915
1917
  # exist at all — and `resultOf` (`adapters/run-script.ts:211`) maps exit 4 onto
1916
1918
  # `unaskable`, which is the word the build port already answers with.
1917
- # The Jenkins REST credential: JENKINS_USER + JENKINS_API_TOKEN from the
1918
- # environment, then `plot_env_file`, then the macOS keychain where `jen`
1919
- # already stores it — the environment wins outright, same order and the same
1920
- # both-or-neither rule as `jira_load_env_file`.
1921
- #
1922
- # NOT THE KEYCLOAK BEARER. `jen auth token` prints one and Jenkins answers it
1923
- # with an HTML login redirect — measured 2026-09-10. Jenkins' own API takes
1924
- # BASIC auth with a user and an API token.
1925
- #
1926
- # Prints `user:token` and nothing else, or nothing at all — never the value
1927
- # on a failure path. Empty means no source held a full pair; the caller turns
1928
- # that into exit 4, *cannot be asked*.
1929
- jenkins_rest_credential() { # $1 = the bare host
1930
- local u="${JENKINS_USER:-}" t="${JENKINS_API_TOKEN:-}" src="the environment" found env_file
1931
- [ -n "$u" ] || [ -n "$t" ] || { found="$(plot_env_file JENKINS_USER JENKINS_API_TOKEN)"; [ -n "$found" ] && env_file="${found%|*}" && src="${found#*|}.env" && u="$(read_env_var JENKINS_USER "$env_file")" && t="$(read_env_var JENKINS_API_TOKEN "$env_file")"; }
1932
- [ -n "$u" ] && [ -n "$t" ] && { echo "plot-host: JENKINS_USER and JENKINS_API_TOKEN read from $src" >&2; printf '%s:%s' "$u" "$t"; return 0; }
1933
- command -v security >/dev/null 2>&1 || return 1; u=$(security find-generic-password -s jen -a "jenkins-user:$1" -w 2>/dev/null) || return 1
1934
- t=$(security find-generic-password -s jen -a "jenkins-token:$1" -w 2>/dev/null) || return 1
1935
- [ -n "$u" ] && [ -n "$t" ] || return 1; printf '%s:%s' "$u" "$t"
1936
- }
1937
1919
 
1938
1920
  # A job path as Jenkins' REST API spells it: every segment under `job/`.
1939
1921
  #
@@ -1950,20 +1932,6 @@ jenkins_job_url_path() { # $1 = job path, $2 = branch or ""
1950
1932
  printf '%s' "$out"
1951
1933
  }
1952
1934
 
1953
- # The REST host for the Jenkins slug $1, read off `jen -I <slug> auth status`'s
1954
- # `Instance:` line rather than reinvented here — `jen` already turns a slug
1955
- # like `ewz` into `jenkins-ci-ewz.internal.quatico.dev` and keys its stored
1956
- # credential by that resolved host, so a literal slug sent to `curl` or to
1957
- # `jenkins_rest_credential` can only fail. Prints nothing and exits 1 when
1958
- # `jen` is missing, unparseable, or the line is absent; exits 2 when the line
1959
- # names no parenthesized host. The caller decides what an unresolved host
1960
- # means, same contract as every other helper here.
1961
- jenkins_resolve_host() {
1962
- local line; line=$(jen -I "$1" auth status 2>&1 | grep -iE '^Instance:' | head -1)
1963
- [ -n "$line" ] || return 1
1964
- sed -nE 's/.*\(https?:\/\/([^)\/]+).*/\1/p' <<<"$line" | grep . || return 2
1965
- }
1966
-
1967
1935
  # Every Jenkins build of one job, as a JSON array (newest first), or exit 3
1968
1936
  # (no instance) / exit 4 (cannot be asked). Shared by `run-for-sha`,
1969
1937
  # `runs-for-sha` and `runs`, so the instance, the credential and the
@@ -1975,10 +1943,11 @@ jenkins_resolve_host() {
1975
1943
  # Run it in `$(...)` and read the exit code with `|| exit $?`: it exits rather
1976
1944
  # than returns, and a subshell's exit is the code the caller sees.
1977
1945
  #
1978
- # THE SHA IS IN JENKINS AND `jen` IS NOT THE TRANSPORT. Measured 2026-09-10: a
1979
- # `jen build list --json` entry carries no sha, so Jenkins' REST API answers it
1980
- # at `actions[].lastBuiltRevision.SHA1`. One `tree=` query returns a whole
1981
- # history, so this costs one round trip like the GitHub arm.
1946
+ # Plot reaches Jenkins only through `jen`; `jen api` carries the sha through
1947
+ # `tree=` in one round trip. Measured 2026-09-10: a `jen build list --json`
1948
+ # entry carries no sha, so Jenkins' REST API answers it at
1949
+ # `actions[].lastBuiltRevision.SHA1`, and `jen api <path>` (jen 0.4.0) is the
1950
+ # raw passthrough that reaches it with the proxy's own auth headers.
1982
1951
  #
1983
1952
  # A BRANCH IS A JOB SEGMENT ON A MULTIBRANCH JOB AND NOT ON A PLAIN ONE, and no
1984
1953
  # reading of the configured path says which this is. The multibranch URL is
@@ -1990,10 +1959,9 @@ jenkins_resolve_host() {
1990
1959
  # path segment, as `jenkins_build_map` keys it). A multibranch container that
1991
1960
  # answers `jobs` and no `builds` has not indexed the branch: an empty history.
1992
1961
  #
1993
- # NO CREDENTIAL IS *CANNOT BE ASKED*, never *no run*: the keychain is macOS-only
1994
- # and a Linux agent legitimately has none. AN UNREACHABLE INSTANCE IS NOT AN
1995
- # EMPTY HISTORY: a refused or redirected request answers HTML, which fails the
1996
- # `builds` test.
1962
+ # A `jen` THAT CANNOT AUTHENTICATE IS *CANNOT BE ASKED*, never *no run*; an
1963
+ # unreachable instance is not an empty history. A refused or redirected
1964
+ # request answers HTML, which fails the `builds` test.
1997
1965
  #
1998
1966
  # A BRANCH THE MULTIBRANCH JOB NEVER INDEXED IS AN EMPTY HISTORY, NOT A
1999
1967
  # REFUSAL. Measured live on ewz-kus-portal: `develop` builds in a separate job
@@ -2038,8 +2006,8 @@ jenkins_resolve_host() {
2038
2006
  # the cut silently shrinks the answer — `runs --limit 3` over five builds where
2039
2007
  # two are `NOT_BUILT` returning 1 row instead of 3. The over-fetch factor is
2040
2008
  # fixed at 3x, uncapped: it costs response BYTES, never an extra round trip or
2041
- # rate-budget slot (`host_slot_take`/`budget_record_call` below run once per
2042
- # path regardless of `limit`), and a single multibranch job's full history is
2009
+ # rate-budget slot (the `jen()` wrapper records one ledger row per path
2010
+ # regardless of `limit`), and a single multibranch job's full history is
2043
2011
  # small enough that 3x of any realistic `--limit` stays well under what one
2044
2012
  # `tree=` query already returns today (measured 2026-09-10: 4855 bytes for
2045
2013
  # five builds).
@@ -2048,35 +2016,24 @@ jenkins_resolve_host() {
2048
2016
  # is tried first; if it answers real JSON with no `builds` key, Jenkins
2049
2017
  # reached the job and simply has no such branch, and the refusal says so.
2050
2018
  # Only the root-path retry's container check (above) can turn that into an
2051
- # empty-history read instead. A host that never answers at all — curl
2052
- # failure, HTML, empty body — gets the generic "did not answer" refusal,
2053
- # since nothing there proves Jenkins was even reached.
2019
+ # empty-history read instead. A host that never answers at all — a failed
2020
+ # `jen api` request, HTML, empty body — gets the generic "did not answer"
2021
+ # refusal, since nothing there proves Jenkins was even reached.
2054
2022
  jenkins_sha_runs() {
2055
- local op="$1" branch="$2" limit="$3" sha="$4" instance slug host job cred tree body try path plain="" default_job root_path branch_path branch_answered=""
2023
+ local op="$1" branch="$2" limit="$3" sha="$4" instance slug job tree body try path plain="" default_job root_path branch_path branch_answered="" err_tmp err_line
2056
2024
  instance="$(jenkins_instance)"; [ -n "$instance" ] || jenkins_no_instance
2057
2025
  slug="${instance%%/*}"; job="${instance#*/}"; [ "$job" = "$instance" ] && job=""
2058
2026
  default_job=$(bash "$here/plot-config.sh" get "Default branch job" "" 2>/dev/null || true); [ -n "$default_job" ] && [ "$branch" = "$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's#^origin/##')" ] && job="$default_job"
2059
2027
  [ -n "${PLOT_JENKINS_JOB:-}" ] && job="$PLOT_JENKINS_JOB"; [ -n "$job" ] || { echo "plot-host: $op — the Jenkins instance names no job path; a sha lives in a job's builds, so it must be <slug>/<job/path>, not a bare host" >&2; exit 4; }
2060
- # A dotted slug IS a host already, `jen`'s own passthrough rule — only a
2061
- # bare slug (`ewz`) needs resolving to the host its credential is keyed by.
2062
- case "$slug" in *.*) host="$slug" ;; *) host="$(jenkins_resolve_host "$slug")" || {
2063
- [ $? = 2 ] && printf '%s\n' "plot-host: $op — cannot resolve Jenkins instance '$slug' to a host" " \`jen -I $slug auth status\` answered an 'Instance:' line that names no (https://…) host; run it directly to see what it names." >&2 || printf '%s\n' "plot-host: $op — cannot resolve Jenkins instance '$slug' to a host" " \`jen -I $slug auth status\` did not answer an 'Instance:' line; run it directly to see why." >&2
2064
- exit 4; } ;; esac
2065
- cred="$(jenkins_rest_credential "$host")" || {
2066
- echo "plot-host: $op — no Jenkins API credential for '$host'" >&2
2067
- echo " Jenkins' REST API takes basic auth with an API token, which \`jen auth login\` stores in the login keychain. The Keycloak bearer from \`jen auth token\` is NOT it." >&2
2068
- exit 4
2069
- }
2070
2028
  tree="tree=builds%5Bnumber,result,building,timestamp,url,actions%5BlastBuiltRevision%5BSHA1,branch%5Bname%5D%5D%5D%5D%7B0,$((limit * 3))%7D"
2071
2029
  body=""; root_path="$(jenkins_job_url_path "$job" "")"; branch_path="$(jenkins_job_url_path "$job" "$branch")"
2072
2030
  for path in "$branch_path" "$root_path"; do
2073
- host_slot_take jenkins ''
2074
- try=$(curl -sg --max-time 30 -u "$cred" "https://$host$path/api/json?$tree" 2>/dev/null) || true
2075
- host_slot_give; budget_record_call jenkins ''
2031
+ plot_tmpfile err_tmp host-jenkins-sha-err || { echo "plot-host: $op — no temp file could be made under ${TMPDIR:-/tmp}" >&2; exit 3; }
2032
+ try=$(PLOT_JEN_BOUND_S="${PLOT_JENKINS_SHA_BOUND_S:-30}" jen -I "$slug" api "$path/api/json?$tree" 2>"$err_tmp") || true
2076
2033
  if printf '%s' "$try" | jq -e 'has("builds")' >/dev/null 2>&1; then body="$try"; break; fi
2077
2034
  # A branch path that came back as REAL JSON (jq could parse and evaluate
2078
2035
  # it, just found no `builds` key) means Jenkins answered and indexed no
2079
- # such branch — distinct from curl failing outright or answering HTML,
2036
+ # such branch — distinct from `jen` failing outright or answering HTML,
2080
2037
  # where jq's own exit code is 4 (empty input) or 5 (parse error) rather
2081
2038
  # than the 1 a successfully-evaluated `false` reports.
2082
2039
  [ "$path" = "$branch_path" ] && printf '%s' "$try" | jq -e . >/dev/null 2>&1 && branch_answered=1
@@ -2090,8 +2047,23 @@ jenkins_sha_runs() {
2090
2047
  [ "$path" = "$root_path" ] && printf '%s' "$try" | jq -e '._class == "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject"' >/dev/null 2>&1 && { body='{"builds":[]}'; break; }
2091
2048
  plain=1
2092
2049
  done
2093
- cred=""
2094
- [ -n "$body" ] || { [ -n "$branch_answered" ] && echo "plot-host: $op — Jenkins has no branch '$branch' indexed for '$job'" >&2 || echo "plot-host: $op — Jenkins did not answer for '$host'" >&2; exit 4; }
2050
+ if [ -z "$body" ]; then
2051
+ if [ -n "$branch_answered" ]; then
2052
+ echo "plot-host: $op — Jenkins has no branch '$branch' indexed for '$job'" >&2
2053
+ else
2054
+ err_line="$(grep -m1 '^error:' "$err_tmp" 2>/dev/null || true)"
2055
+ if grep -qi 'unknown command: api' "$err_tmp" 2>/dev/null; then
2056
+ echo "plot-host: $op — the sha read needs jen 0.4.0 or later with \`api\`" >&2
2057
+ elif grep -qiE 'command not found|no such file or directory' "$err_tmp" 2>/dev/null; then
2058
+ echo "plot-host: $op — \`jen\` is not installed; the sha read needs jen 0.4.0 or later with \`api\`" >&2
2059
+ else
2060
+ printf '%s\n' "plot-host: $op — Jenkins did not answer for Jenkins instance '$slug'" >&2
2061
+ [ -n "$err_line" ] && printf ' jen: %s\n' "$err_line" >&2
2062
+ printf ' Plot reaches Jenkins only through `jen`; run `jen auth login`.\n' >&2
2063
+ fi
2064
+ fi
2065
+ exit 4
2066
+ fi
2095
2067
  printf '%s' "$body" | jq -c --arg sha "$sha" --arg job "$job" --arg branch "$branch" --arg plain "$plain" --argjson limit "$limit" 'def headsha($records): ($records | map(select(any(.branches[]; . == $branch))) | first.sha) // (if [$records[].branches[]] | length == 0 then $records | last.sha // "" else "" end);
2096
2068
  [ .builds[]
2097
2069
  | { records: [ .actions[]? | select(.lastBuiltRevision) | .lastBuiltRevision
@@ -2246,13 +2218,9 @@ bb_state_row() {
2246
2218
  ci_unaskable() { # $1 = the op's name, $2 = the CI word (may be empty)
2247
2219
  local ci_word="${2:-}"
2248
2220
  if [ -z "$ci_word" ] || [ "$ci_word" = none ]; then
2249
- echo "plot-host: $1 — this repository declares no CI system, so there is nothing to ask" >&2
2250
- echo " Add a 'CI' key to the ## Plot Config section of CLAUDE.md naming the" >&2
2251
- echo " system that builds this repository — \`github-actions\` or \`jenkins\`." >&2
2221
+ printf '%s\n' "plot-host: $1 — this repository declares no CI system, so there is nothing to ask" " Add a 'CI' key to the ## Plot Config section of CLAUDE.md naming the" " system that builds this repository — \`github-actions\` or \`jenkins\`." >&2
2252
2222
  else
2253
- echo "plot-host: $1 — no connector for CI system '$ci_word'" >&2
2254
- echo " Plot answers this op for \`github-actions\` and \`jenkins\`. An unknown" >&2
2255
- echo " system cannot be asked, which is not the same as having no runs." >&2
2223
+ printf '%s\n' "plot-host: $1 — no connector for CI system '$ci_word'" " Plot answers this op for \`github-actions\` and \`jenkins\`. An unknown" " system cannot be asked, which is not the same as having no runs." >&2
2256
2224
  fi
2257
2225
  exit 4
2258
2226
  }
@@ -2559,16 +2527,11 @@ gh_route() { # $1=op → graphql|rest
2559
2527
  # `gh pr view 7` infers the repo from the git remote, but `gh api repos/.../pulls/7`
2560
2528
  # has to be told. So the fallback needs one more fact than the path it replaces.
2561
2529
  #
2562
- # `--repo` may already carry it (the caller passed `-R owner/repo`), in which
2563
- # case no call is needed at all. Otherwise it has to be resolved.
2564
- #
2565
- # TODO(decision): resolve the repo when `--repo` was not supplied.
2530
+ # `--repo` may already carry it (the caller passed `-R owner/repo`). Otherwise
2531
+ # `gh api` fills `{owner}/{repo}` from the git remote, with no request. A path
2532
+ # naming no real repository answers 404, which `is_lookup_miss` reads as NONE.
2566
2533
  gh_rest_repo() {
2567
- if [ ${#repo_args[@]} -gt 0 ]; then
2568
- echo "${repo_args[1]}"
2569
- return 0
2570
- fi
2571
- echo "TODO"
2534
+ if [ ${#repo_args[@]} -gt 0 ]; then echo "${repo_args[1]}"; else echo '{owner}/{repo}'; fi
2572
2535
  }
2573
2536
 
2574
2537
  rest_pr_to_state() {
@@ -2579,7 +2542,7 @@ rest_pr_to_state() {
2579
2542
  state: $state,
2580
2543
  draft: (.draft // false),
2581
2544
  url: (.html_url // ""),
2582
- mergeCommit: (.merge_commit_sha // ""), headSha: (.head.sha // ""), base: (.base.ref // ""), checks: "unknown", mergeable: mergeable_of,
2545
+ mergeCommit: (.merge_commit_sha // ""), head: (.head.ref // ""), headSha: (.head.sha // ""), base: (.base.ref // ""), checks: "unknown", mergeable: mergeable_of,
2583
2546
  mergedAt: (.merged_at // "") }
2584
2547
  '
2585
2548
  }
@@ -3109,10 +3072,7 @@ jira_require_config() {
3109
3072
  [ -n "$(tracker_base_url)" ] || die3 "Tracker is jira but no base URL is configured (write 'Tracker: jira https://your.atlassian.net' or set PLOT_JIRA_BASE_URL)"
3110
3073
  jira_load_env_file
3111
3074
  if [ -z "${JIRA_EMAIL:-}" ] || [ -z "${JIRA_API_TOKEN:-}" ]; then
3112
- echo "plot-host: Jira needs JIRA_EMAIL and JIRA_API_TOKEN in the environment — an unauthenticated Jira must not read as an empty inbox" >&2
3113
- echo " Create a token at https://id.atlassian.com/manage-profile/security/api-tokens" >&2
3114
- echo " then export JIRA_EMAIL=<your account email> and JIRA_API_TOKEN=<the token>," >&2
3115
- echo " or put both in this repository's .env (which .gitignore already excludes)." >&2
3075
+ printf '%s\n' "plot-host: Jira needs JIRA_EMAIL and JIRA_API_TOKEN in the environment — an unauthenticated Jira must not read as an empty inbox" " Create a token at https://id.atlassian.com/manage-profile/security/api-tokens" " then export JIRA_EMAIL=<your account email> and JIRA_API_TOKEN=<the token>," " or put both in this repository's .env (which .gitignore already excludes)." >&2
3116
3076
  exit 3
3117
3077
  fi
3118
3078
  }
@@ -3918,8 +3878,20 @@ bb() {
3918
3878
 
3919
3879
  jen() {
3920
3880
  host_slot_take jenkins ''
3921
- command jen "$@"
3922
- local rc=$?
3881
+ local rc
3882
+ if [ -n "${PLOT_JEN_BOUND_S:-}" ]; then
3883
+ local pid watcher was_m
3884
+ case $- in *m*) was_m=yes ;; *) was_m=no ;; esac; set -m
3885
+ command jen "$@" & pid=$!
3886
+ ( sleep "$PLOT_JEN_BOUND_S"; kill -TERM "-$pid" ) >/dev/null 2>&1 & watcher=$!
3887
+ wait "$pid"; rc=$?
3888
+ kill "$watcher" 2>/dev/null; wait "$watcher" 2>/dev/null
3889
+ [ "$was_m" = yes ] || set +m
3890
+ [ $rc = 143 ] && echo "jen api gave no answer within ${PLOT_JEN_BOUND_S} s" >&2
3891
+ else
3892
+ command jen "$@"
3893
+ rc=$?
3894
+ fi
3923
3895
  host_slot_give
3924
3896
  # Jenkins is the CI axis, a connector of its own — this repo is GitHub +
3925
3897
  # Actions while `ekzweb` is Bitbucket + Jenkins, so a `jen` call spends
@@ -3958,6 +3930,8 @@ be="$(backend)" || exit $?
3958
3930
  # emptiness is the honest value — there is no route where there is no fork.
3959
3931
  route=""
3960
3932
  [ "$be" = "github" ] && route="$(gh_route "$op")"
3933
+ # THE HOST CLI FOR OPS WHOSE TWO ARMS DIFFER ONLY IN ITS NAME.
3934
+ cli=gh; [ "$be" = "github" ] || cli=bb
3961
3935
 
3962
3936
  case "$op" in
3963
3937
  backend)
@@ -4096,9 +4070,9 @@ case "$op" in
4096
4070
  # mergeCommit is what lets a caller ask "which release contains this?" —
4097
4071
  # `git tag --contains <sha>` answers exactly, where dates cannot. It is ""
4098
4072
  # for anything unmerged, which is the honest answer rather than a guess.
4099
- elif out="$(gh ${repo_args[@]+"${repo_args[@]}"} pr view "$ref" --json number,state,isDraft,url,mergeCommit,headRefOid,baseRefName,statusCheckRollup,mergeable,mergeStateStatus,mergedAt 2>"$HOST_ERR")"; then
4073
+ 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
4100
4074
  rm -f "$HOST_ERR"
4101
- jq -c "$CHECKS_OF$MERGEABLE_OF"'{number:.number,state:.state,draft:.isDraft,url:.url,mergeCommit:(.mergeCommit.oid // ""),headSha:(.headRefOid // ""),base:(.baseRefName // ""),checks:checks_of,checksSha:(.headRefOid // ""),mergeable:mergeable_of,mergedAt:(.mergedAt // "")}' <<<"$out"
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"
4102
4076
  else
4103
4077
  host_err
4104
4078
  # REFUSED FOR RATE IS NOT ANSWERED. The budget gate above could not see
@@ -4403,8 +4377,12 @@ case "$op" in
4403
4377
  && printf '%s\n%s\n%s\n' "$sha" "$st" "$cm" | node "$here/board/plot-jenkins-pr-checks.mjs" review \
4404
4378
  || die3 "pr-review: the read failed"
4405
4379
  exit 0; fi
4406
- out="$(gh pr view "${1:?pr-review needs a PR number}" --json headRefOid,comments)" && st="$(gh api "repos/{owner}/{repo}/commits/$(jq -r .headRefOid <<<"$out")/statuses")" \
4407
- && jq -c --argjson st "$st" '{sha: .headRefOid, state: ([$st[] | select(.context == "plot/review")][0].state // "absent"), bypass: any(.comments[]?; .body | startswith("review-bypass:"))}' <<<"$out" \
4380
+ # EVERY `plot/review` STATUS IS REPORTED WITH ITS WRITER, and nothing is
4381
+ # decided here: `checkedReview` judges the list against the Review app's bot
4382
+ # login. The pages and the PR travel through stdin, never `--argjson` (the
4383
+ # 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 // "")}]}' \
4408
4386
  || die3 "pr-review: the read failed" ;;
4409
4387
 
4410
4388
  pr-create)
@@ -4461,21 +4439,23 @@ case "$op" in
4461
4439
  fi
4462
4440
  ;;
4463
4441
 
4464
- pr-ready)
4465
- # TAKE A PR OUT OF DRAFT. One call, and the ONE place that talks to the host
4466
- # CLI keeps that property — `plot-approve.sh` needs this before it merges,
4467
- # and reaching for `gh` there would put a second host caller in the estate.
4442
+ pr-ready|pr-close)
4443
+ # TAKE A PR OUT OF DRAFT (`pr-ready`) OR CLOSE IT WITHOUT MERGING (`pr-close`;
4444
+ # `bb pr close` declines). One call each, and the ONE place that talks to the
4445
+ # host CLI keeps that property — `plot-approve.sh` needs the first before it
4446
+ # merges, and the repair arm closes the fix and revert PRs of an episode with
4447
+ # the second; reaching for `gh` there would put a second host caller in the
4448
+ # estate.
4468
4449
  #
4469
- # Bitbucket's support depends on the bb CLI version (see the caveat list at
4470
- # the top of this file, which already names `--draft`/`--ready`), so a
4471
- # failure here surfaces as the CLI's own message rather than being
4472
- # swallowed: the caller must be able to tell *the host refused* from *the
4473
- # PR is now ready*.
4474
- num="${1:?pr-ready needs a PR number}"; shift
4475
- if [ "$be" = "github" ]; then
4476
- gh pr ready "$num"
4450
+ # Bitbucket runs `bb pr edit <n> --ready` (see the caveat list at the top of
4451
+ # this file), so a failure here surfaces as the CLI's own message rather
4452
+ # than being swallowed: the caller must be able to tell *the host refused*
4453
+ # from *the PR is now ready or closed*.
4454
+ num="${1:?$op needs a PR number}"
4455
+ if [ "$op" = "pr-ready" ] && [ "$cli" = "bb" ]; then
4456
+ bb pr edit "$num" --ready
4477
4457
  else
4478
- bb pr update "$num" --ready
4458
+ "$cli" pr "${op#pr-}" "$num"
4479
4459
  fi
4480
4460
  ;;
4481
4461
 
@@ -4802,15 +4782,14 @@ case "$op" in
4802
4782
  | jq -c "$CHECKS_OF$MERGEABLE_OF"'.[] | {
4803
4783
  number:.number, title:.title, state:.state, head:.headRefName,
4804
4784
  draft:.isDraft,
4805
- checks:checks_of,
4806
- mergeable:mergeable_of,
4785
+ checks:checks_of, mergeable:mergeable_of,
4807
4786
  review:(.reviewDecision // ""),
4808
4787
  url:.url,
4809
4788
  updatedAt:(.updatedAt // ""),headSha:(.headRefOid // ""),checksSha:(.headRefOid // ""),mergedAt:(.mergedAt // ""),
4810
4789
  author:(.author.login // ""),
4811
4790
  failing_checks:[
4812
- .statusCheckRollup[]? | select(ck == "bad") | (.name // .context // "")] | map(select(. != ""))
4813
- }'
4791
+ .statusCheckRollup[]? | select(ck == "bad") | (.name // .context // "")] | map(select(. != "")), ciChecks:ci_checks_of
4792
+ } + (([.statusCheckRollup[]? | select((.context // "") == "plot/review")] | .[0]) as $pr | if $pr == null then {plotReview:"absent"} else {plotReview:($pr.state // "" | ascii_downcase), plotReviewSha:(.headRefOid // ""), plotReviewAt:($pr.startedAt // "")} end)'
4814
4793
  fi
4815
4794
  else
4816
4795
  # `isDraft`, `url` AND `updatedAt` TRAVEL ON THE PLAIN ARM TOO, and they
@@ -4986,7 +4965,7 @@ case "$op" in
4986
4965
  fi
4987
4966
  else
4988
4967
  pr_list_states bitbucket "$limit" "$bb_states" \
4989
- '.[] | {number:.id,title:.title,state:(if .state=="DECLINED" then "CLOSED" else .state end),head:.source.branch.name,author:(.author.nickname // "")}' \
4968
+ '.[] | {number:.id,title:.title,state:(if .state=="DECLINED" then "CLOSED" else .state end),head:.source.branch.name,draft:(.draft // false),url:(.links.html.href // ""),updatedAt:(.updated_on // ""),headSha:(.source.commit.hash // ""),mergedAt:(if .state=="MERGED" then (.updated_on // "") else "" end),author:(.author.nickname // ""),base:(.destination.branch.name // "")}' \
4990
4969
  "${bb_cmd[@]}" || exit $?
4991
4970
  fi
4992
4971
  fi
@@ -5034,9 +5013,7 @@ case "$op" in
5034
5013
  # `CI: github-actions` on a Bitbucket remote has declared something
5035
5014
  # `gh` cannot reach — an unaskable configuration, not an empty history.
5036
5015
  if [ "$be" != "github" ]; then
5037
- echo "plot-host: runs — CI is github-actions but the git host is '$be'" >&2
5038
- echo " \`gh run list\` reads the runs of the repository its remote names," >&2
5039
- echo " so there is no GitHub repository here to ask about." >&2
5016
+ printf '%s\n' "plot-host: runs — CI is github-actions but the git host is '$be'" " \`gh run list\` reads the runs of the repository its remote names," " so there is no GitHub repository here to ask about." >&2
5040
5017
  exit 4
5041
5018
  fi
5042
5019
  gh run list --branch "$branch" --limit "$limit" \
@@ -5119,20 +5096,17 @@ case "$op" in
5119
5096
  _ci="$(ci_scheme)"
5120
5097
  case "$_ci" in
5121
5098
  jenkins)
5122
- # THE SHA IS IN JENKINS AND `jen` IS NOT THE TRANSPORT. Measured
5099
+ # `jen api` IS THE RAW PASSTHROUGH AND THE ONLY TRANSPORT. Measured
5123
5100
  # 2026-09-10 against a live instance: a build entry from `jen build
5124
5101
  # list --json` carries `id`, `status`, timings and stages, and a search
5125
5102
  # of the whole payload for `sha|commit|revision|scm` matches nothing.
5126
- # `jen` has no changesets subcommand and no raw-API passthrough.
5127
- #
5128
- # JENKINS' OWN REST API ANSWERS IT, at
5129
- # `actions[].lastBuiltRevision.SHA1`, paired with the branch. One
5103
+ # Jenkins' own REST API answers it at
5104
+ # `actions[].lastBuiltRevision.SHA1`, paired with the branch, and
5105
+ # `jen api <path>` reaches it with the instance's own auth headers. One
5130
5106
  # `tree=` query returns a whole history — 4855 bytes for five builds —
5131
5107
  # so this costs one round trip like the GitHub arm does.
5132
5108
  #
5133
- # THIS ARM EXITED 4 UNTIL 2026-09-11, and the refusal was honest for
5134
- # the transport it had. What changed is the transport, not the rule.
5135
- # The fetch, credential and match rule live in `jenkins_sha_runs`, which
5109
+ # THE FETCH AND MATCH RULE LIVE IN `jenkins_sha_runs`, which
5136
5110
  # `runs-for-sha` shares. `|| exit $?` keeps exit 3 (no instance) apart
5137
5111
  # from exit 4 (cannot be asked).
5138
5112
  _jen_all=$(jenkins_sha_runs "$op" "$branch" "$limit" "$sha") || exit $?
@@ -5151,9 +5125,7 @@ case "$op" in
5151
5125
  # SAME SECOND CONDITION AS `runs`: `gh run list` reads the repository its
5152
5126
  # remote names, so `CI: github-actions` on a non-GitHub remote names runs
5153
5127
  # that cannot be reached from here.
5154
- echo "plot-host: $op — CI is github-actions but the git host is '$be'" >&2
5155
- echo " \`gh run list\` reads the runs of the repository its remote names," >&2
5156
- echo " so there is no GitHub repository here to ask about." >&2
5128
+ printf '%s\n' "plot-host: $op — CI is github-actions but the git host is '$be'" " \`gh run list\` reads the runs of the repository its remote names," " so there is no GitHub repository here to ask about." >&2
5157
5129
  exit 4
5158
5130
  fi
5159
5131
  # From here the CI system is `github-actions` and the git host is GitHub;
@@ -5207,6 +5179,23 @@ case "$op" in
5207
5179
  '$match[0] + {jobs: [$run[0].jobs[] | {conclusion, startedAt, completedAt, steps: [(.steps // [])[].conclusion]}]}' || exit 4
5208
5180
  ;;
5209
5181
 
5182
+ rerun-failed|rerun-all)
5183
+ # `rerun-failed` re-runs the failed jobs of every concluded-red run for ONE
5184
+ # sha; `rerun-all` re-runs every job of every run for it, whatever each
5185
+ # concluded. GitHub resets a re-run run's `startedAt` to the new attempt.
5186
+ # Exit 4 is *cannot be asked*: any CI but GitHub Actions on GitHub, and a
5187
+ # failing `gh`. Exit 1 is `rerun-all` matching no run for the sha: nothing
5188
+ # was re-run, so a caller waiting for a new attempt would wait forever.
5189
+ branch="${1:?$op needs a branch}"; sha="${2:?$op needs a sha}"
5190
+ [ "$(ci_scheme)" = github-actions ] && [ "$be" = github ] || exit 4
5191
+ # Empty for `rerun-all`; non-empty, and so `--failed` below, for `rerun-failed`.
5192
+ _failed_only=${op#rerun-all}
5193
+ _ids=$(gh run list --branch "$branch" --limit 50 --json headSha,conclusion,databaseId \
5194
+ --jq ".[] | select(.headSha == \"$sha\" and (\"$_failed_only\" == \"\" or .conclusion == \"failure\")) | .databaseId" 2>/dev/null) || exit 4
5195
+ [ -n "$_ids$_failed_only" ] || exit 1
5196
+ for _id in $_ids; do gh run rerun "$_id" ${_failed_only:+--failed} >/dev/null 2>&1 || exit 4; done
5197
+ ;;
5198
+
5210
5199
  issue-list)
5211
5200
  # Open tracker issues — the board's inbox, and READ-ONLY in both
5212
5201
  # directions. Nothing here writes a label, an assignee or a close: the
@@ -5466,7 +5455,7 @@ case "$op" in
5466
5455
  gh_json="number,title,url,createdAt,assignees,issueType"; search_args=(); ask_state="$gh_state"
5467
5456
  [ -z "$label" ] || search_args=(--label "$label")
5468
5457
  if [ "$gh_state" = changed ]; then gh_json+=",updatedAt,state,closedAt"; ask_state=all; search_args+=(--search "updated:>=$since")
5469
- elif [ "$gh_state" != open ]; then gh_json+=",closedAt"; search_args+=(--search "closed:>=$since")
5458
+ elif [ "$gh_state" != open ]; then gh_json+=",closedAt,labels"; search_args+=(--search "closed:>=$since")
5470
5459
  # TITLE SEARCH NARROWS, IT DOES NOT REPLACE THE LABEL FILTER: both are
5471
5460
  # qualifiers `gh` combines in one `--search` string, so a backlog's
5472
5461
  # label stays the safety net while the title cuts the read to the one PR
@@ -5486,7 +5475,7 @@ case "$op" in
5486
5475
  {number:.number,title:.title,url:(.url // ""),createdAt:(.createdAt // ""),
5487
5476
  status:$actual,statusCategory:(if $actual == "open" then "To Do" else "Done" end),assignees:[.assignees[]?.login]}
5488
5477
  + (if .updatedAt then {updatedAt:.updatedAt} else {} end) + (if .issueType.name? then {type:.issueType.name} else {} end)
5489
- + (if $actual == "closed" then {closedAt:(.closedAt // "")} else {} end)' <<<"$out"
5478
+ + (if $actual == "closed" then {closedAt:(.closedAt // "")} else {} end) + (if .labels then {labels:[.labels[].name]} else {} end)' <<<"$out"
5490
5479
  else
5491
5480
  # NO empty-list fallback. `host_miss_or_fail` exists for a lookup whose
5492
5481
  # subject is absent — one PR that does not exist. A LIST has no absent
@@ -5567,7 +5556,7 @@ case "$op" in
5567
5556
  # exit codes are deliberately THE SAME ONES — a consumer that already maps
5568
5557
  # 4 to `unsupported` and anything else to `failed` must not need a second
5569
5558
  # table to read this op.
5570
- num="${1:?issue-view needs an issue number}"; shift
5559
+ num="${1:?issue-view needs an issue number}"
5571
5560
  # Asked once, before the arms, exactly as issue-list does — the same
5572
5561
  # question with the same three answers and the same exit codes. A consumer
5573
5562
  # that maps 4 to `unsupported` needs no second table to read this op.
@@ -5738,12 +5727,15 @@ case "$op" in
5738
5727
  *) echo "plot-host: issue-open: ${source_said#*$'\t'}" >&2; exit 4 ;;
5739
5728
  esac ;;
5740
5729
 
5741
- issue-label|issue-comment|issue-close)
5730
+ issue-label|issue-comment|issue-comment-read|issue-close)
5742
5731
  # THE PLAN-STATE WRITES, and one-way: Plot sets a `plan:*` label, keeps one
5743
- # comment per issue and closes the issue at release; nothing reads any back.
5744
- # 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`
5745
- # issue-comment <n> <marker> <body> edits the comment holding <marker>, else posts; an empty <marker> always posts
5746
- # issue-close <n>
5732
+ # comment per issue and closes the issue at release; nothing reads any back,
5733
+ # except `issue-comment-read`, the plan-state comment's one sanctioned
5734
+ # 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`
5736
+ # issue-comment <n> <marker> <body> edits the comment holding <marker>, else posts; an empty <marker> always posts
5737
+ # issue-comment-read <n> <marker> prints the marked comment's body, or nothing where none carries it
5738
+ # issue-close <n>
5747
5739
  # GitHub issues only, dispatched on `issue_source` like issue-open. Exit 4,
5748
5740
  # with the reason, for a source that cannot be asked.
5749
5741
  num="${1:?$op needs an issue number}"; source_said="$(issue_source)" || exit 1
@@ -5752,9 +5744,11 @@ case "$op" in
5752
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 ;;
5753
5745
  issue-close) gh issue close "$num" >/dev/null 2>"$HOST_ERR" || gh_fail ;;
5754
5746
  issue-comment)
5755
- cid=""; [ -z "${2-}" ] || cid="$(gh_marker_comment_id "$num" "$2")" || gh_fail
5756
- if [ -n "$cid" ]; then gh api -X PATCH "repos/{owner}/{repo}/issues/comments/$cid" -f body="${3-}" >/dev/null 2>"$HOST_ERR"
5757
- else gh issue comment "$num" --body "${3-}" >/dev/null 2>"$HOST_ERR"; fi || gh_fail ;;
5747
+ cid="${2:+$(gh_marker_comment_id "$num" "$2")}" || gh_fail
5748
+ gh_edit_or_post_comment "$cid" issue "$num" "${3-}" || gh_fail ;;
5749
+ issue-comment-read)
5750
+ cid="$(gh_marker_comment_id "$num" "${2:?issue-comment-read needs a marker}")" || gh_fail
5751
+ [ -z "$cid" ] || gh api "repos/{owner}/{repo}/issues/comments/$cid" -q .body 2>"$HOST_ERR" || gh_fail ;;
5758
5752
  esac
5759
5753
  rm -f "$HOST_ERR" ;;
5760
5754
 
@@ -5777,11 +5771,7 @@ case "$op" in
5777
5771
  esac
5778
5772
  done
5779
5773
  [ -n "$body" ] || die "pr-body needs --body"
5780
- if [ "$be" = "github" ]; then
5781
- gh pr edit "$num" --body "$body"
5782
- else
5783
- bb pr edit "$num" --body "$body"
5784
- fi
5774
+ "$cli" pr edit "$num" --body "$body"
5785
5775
  ;;
5786
5776
 
5787
5777
  rate-limit)
@@ -6058,11 +6048,11 @@ case "$op" in
6058
6048
  # KEYED BY PR NUMBER, NOT A SHA — unlike commit-status, this writes through
6059
6049
  # the signed-in CLI identity, so it needs no App credentials and no Node
6060
6050
  # helper.
6061
- [ "$be" = "github" ] || { echo "plot-host: pr-comment: bitbucket has no verified pr-comment write" >&2; exit 4; }; num="${1:?pr-comment needs a PR number}"; cid=""
6062
- [ -z "${3-}" ] || cid="$(gh_marker_comment_id "$num" "$3")" || gh_fail
6063
- if [ -n "$cid" ]; then gh api -X PATCH "repos/{owner}/{repo}/issues/comments/$cid" -f body="${2:?pr-comment needs a body}" >/dev/null 2>"$HOST_ERR"; else gh pr comment "$num" --body "${2:?pr-comment needs a body}" >/dev/null 2>"$HOST_ERR"; fi || gh_fail; rm -f "$HOST_ERR" ;;
6051
+ [ "$be" = "github" ] || { echo "plot-host: pr-comment: bitbucket has no verified pr-comment write" >&2; exit 4; }; num="${1:?pr-comment needs a PR number}"
6052
+ cid="${3:+$(gh_marker_comment_id "$num" "$3")}" || gh_fail
6053
+ gh_edit_or_post_comment "$cid" pr "$num" "${2:?pr-comment needs a body}" || gh_fail; rm -f "$HOST_ERR" ;;
6064
6054
 
6065
6055
  *)
6066
- die "unknown op '$op' (backend|default-branch|pr-state|pr-create|pr-merge|pr-list|issue-list|issue-view|issue-status|issue-open|issue-label|issue-comment|issue-close|version-list|pr-body|pr-review|rate-limit|limit|ci-limit|spend-rate|commit-status|pr-comment)"
6056
+ die "unknown op '$op' (backend|default-branch|pr-state|pr-create|pr-merge|pr-list|issue-list|issue-view|issue-status|issue-open|issue-label|issue-comment|issue-comment-read|issue-close|version-list|pr-body|pr-review|rate-limit|limit|ci-limit|spend-rate|commit-status|pr-comment)"
6067
6057
  ;;
6068
6058
  esac