@plot-pm/board 0.22.1 → 0.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plot-pm/board",
3
- "version": "0.22.1",
3
+ "version": "0.23.0",
4
4
  "description": "Local Kanban board for Plot — a glanceable view of plan phases from docs/plans, with sprint and story filters",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/plot-config.sh CHANGED
@@ -106,6 +106,13 @@
106
106
  # carry no prefix; `plot-wt-*` desks an older dispatch made
107
107
  # beside the repo stay there. Every "which worktree holds
108
108
  # this branch" read asks `git worktree list` instead.
109
+ # Fleet label the launchd/systemd label this checkout's supervisor
110
+ # loads under. Read by `plot-fleetctl.sh --start`, which
111
+ # checks `PLOT_FLEET_LABEL` first when set and non-empty,
112
+ # then this key, then the default `com.plot-pm.fleetd` —
113
+ # so a second checkout can declare the key instead of
114
+ # exporting the env var. Absent or empty = the default,
115
+ # unaffecting a single-checkout project.
109
116
  # Agent-runner keys (optional; Plot hardcodes no agent tooling, Principle 5):
110
117
  # Worker command how /plot-dispatch runs an agent headless on a worktree.
111
118
  # /plot-init writes `PLOT_UNATTENDED=1 plot-worker-loop.sh`;
@@ -266,7 +273,7 @@ default="${3:-}"
266
273
 
267
274
  # Parenthetical prose, markdown backticks, list separators — in that order.
268
275
  prose='s/\([^)]*\)//g; s/`//g; s/[[:space:]]*,[[:space:]]*/, /g;'
269
- case "$cmd" in get) ;; get-raw) prose='s/`//g;' ;; *) echo "plot-config: unknown subcommand '$cmd' (only 'get' and 'get-raw' are supported)" >&2; exit 1 ;; esac
276
+ case "$cmd" in get) ;; get-raw) prose='s/^`([^`]*)`.*/\1/; s/`//g;' ;; *) echo "plot-config: unknown subcommand '$cmd' (only 'get' and 'get-raw' are supported)" >&2; exit 1 ;; esac
270
277
 
271
278
  # THE CALLER'S ROOT IS TAKEN WHERE IT OFFERS ONE. `git rev-parse` is ~5 ms and
272
279
  # this script runs once per config key, so a caller reading several keys pays
package/plot-dispatch.sh CHANGED
@@ -287,6 +287,7 @@ release_branch=""
287
287
  # decision that has one home. It is filled from the rule below.
288
288
  start_count=""
289
289
  offline=""
290
+ claim_only=""
290
291
  allow_local=0
291
292
  allow_waiting=0
292
293
  max=0
@@ -320,6 +321,9 @@ while [ $# -gt 0 ]; do
320
321
  --restart) mode=restart; case "${2:-}" in */*) restart_branch="$2"; shift ;; esac ;;
321
322
  # The same rule once more: a bare `--release <slug>` must not delete a ref
322
323
  # named after a plan slug.
324
+ # `--claim-only` skips the host's PR question for a caller holding local
325
+ # evidence that the branch carries only its claim; step 3 still refuses work.
326
+ --claim-only) claim_only=1 ;;
323
327
  --release) mode=release; case "${2:-}" in */*) release_branch="$2"; shift ;; esac ;;
324
328
  # `--start [N]` brings FREE agents into existence — registered, waiting, and
325
329
  # holding no slice. The count is OPTIONAL and only a bare number is consumed,
@@ -823,6 +827,13 @@ request_brief() { # $1 = branch, $2 = slug → 0 if a command was started
823
827
  # which `${VAR:+…}` reads as nothing — so a broken config cannot stop a brief
824
828
  # being written.
825
829
  _brief_settings="$(bash "$(dirname "${BASH_SOURCE[0]}")/plot-agent-settings.sh" 2>/dev/null || echo "")"
830
+ # THE SPAWN CONTRACT, READ FROM THE BUNDLE — not hand-constructed, so a gate
831
+ # version bump changes one number in one file (spawn-contract.ts) and every
832
+ # spawner, including this shell one, picks it up with no shell edit. `export`
833
+ # ahead of `exec`, never a `${var:+VAR=...}` prefix: bash recognises an
834
+ # assignment prefix before expanding parameters, so that conditional form is
835
+ # not an assignment at all and fails `command not found` on the non-empty case.
836
+ export PLOT_SPAWN_CONTRACT="$(node "$script_dir/board/plot-prompt.mjs" --background-gate 2>/dev/null | sed -n "s/^export PLOT_SPAWN_CONTRACT='\\(.*\\)'$/\\1/p")"
826
837
  ( set -m; cd "$repo_root" \
827
838
  && PLOT_UNATTENDED=1 PLOT_MAIN_CHECKOUT_WRITER=1 PLOT_PLAN_SLUG="$bslug" PLOT_BRIEF_BRANCH="$branch" \
828
839
  PLOT_AGENT_SETTINGS="$_brief_settings" \
@@ -981,80 +992,6 @@ resolve_launch() { # $1 = repo root, $2 = agent name ('' when none)
981
992
  return 0
982
993
  }
983
994
 
984
- # WHETHER A DESK MAY BE HANDED TO A NEW WORKER — the ONE gate, two callers.
985
- #
986
- # EXTRACTED RATHER THAN COPIED, and that is the point. `--restart` asked these
987
- # three questions inline; `--absent` asks the same three over every orphaned
988
- # desk. A second, laxer set written for the sweep is the failure
989
- # `plot-dispatch --stop` already argues against for stop rules, and it matters
990
- # more here because the sweep runs with nobody watching.
991
- #
992
- # IT RETURNS RATHER THAN EXITS, which is the only change the extraction makes.
993
- # A verb acting on one branch exits on a refusal; a sweep over several must
994
- # refuse one desk and carry on to the next. The caller decides which.
995
- #
996
- # THE ORDER IS LOAD-BEARING AND IT IS THE MEASURED ONE:
997
- #
998
- # 1. THE PR, BEFORE THE STATE WORD. Five of five `failed` worktrees in this
999
- # estate held a PR — four open, one already merged. `plot-worker-state.sh`
1000
- # refines `finished` by the tree but deliberately does NOT refine `failed`,
1001
- # `ended` or `none`, because a recorded non-zero exit is already a specific
1002
- # answer about the PROCESS — and silent about the WORK. A gate written on
1003
- # the state word alone would have restarted all five and discarded exactly
1004
- # what the `finished` refusal exists to protect.
1005
- # 2. A LIVE WORKER. There is no --force: a flag overriding this is the flag
1006
- # typed reflexively, and what it would override is another agent's work in
1007
- # progress.
1008
- # 3. A `PLOT-BLOCKED` MARKER. A person owes this branch an answer, and a new
1009
- # worker meets the same question and writes the same marker. Asked through
1010
- # `plot_worker_blocked_file`, never re-globbed: the marker's spelling lives
1011
- # with the classification in `plot-worker-state.sh` and only there.
1012
- #
1013
- # `stalled`, `failed`, `ended` and `no worker` all pass. The PR question is what
1014
- # makes `failed` safe to include — and including it is the point: a gate that
1015
- # simply refused `failed` would pass every refusal test and leave the verb
1016
- # unable to do the one thing it exists for.
1017
- handover_refusal() { # $1=branch $2=worktree $3=state $4=plot_desk_loops line → 0 may hand over, 1 refused
1018
- local branch="$1" wt="$2" state="$3" loop="${4:-none}" pr_json pr_num pr_state marker lpid lsrc lwait
1019
-
1020
- if reached_review "$branch"; then
1021
- pr_json=$("$script_dir/plot-host.sh" pr-state "$branch" </dev/null 2>/dev/null || true)
1022
- pr_num=$(printf '%s' "$pr_json" | sed -n 's/.*"number":\([0-9]*\).*/\1/p')
1023
- pr_state=$(printf '%s' "$pr_json" | sed -n 's/.*"state":"\([A-Z]*\)".*/\1/p')
1024
- echo "plot-dispatch: $branch has a pull request (#${pr_num:-?}, ${pr_state:-OPEN}) — refusing." >&2
1025
- echo " The work reached review, whatever the worker's exit code says. A" >&2
1026
- echo " restart here redoes work someone is already looking at." >&2
1027
- echo " Review it, or reap the worktree once it merges." >&2
1028
- return 1
1029
- fi
1030
-
1031
- # A LIVE LOOP REFUSES WHATEVER THE STATE WORD SAYS (#1450). A loop sleeping on
1032
- # checks, on a usage limit or between passes has no agent beneath it and reads
1033
- # `stalled` or `finished`, yet a second loop beside it shares the desk.
1034
- # `deskLoopAlive` reads all three recorded pids; an unread answer refuses too.
1035
- case "$loop" in
1036
- none) ;;
1037
- alive*) IFS=$'\t' read -r _ lpid lsrc lwait <<<"$loop"
1038
- [ "$lwait" = free ] && printf 'plot-dispatch: a free agent is waiting on %s (pid %s) — refusing.\n Its loop is idle, polling for a hand-over. Confirm before replacing it:\n plot-dispatch.sh --stop %s\n' "$branch" "$lpid" "$branch" >&2 && return 1
1039
- case "$state" in running*) ;; *) printf 'plot-dispatch: a loop is alive on %s (pid %s, from %s) — refusing.\n It reads %s, which --stop leaves alone, as the reaper does. Let it\n finish its pass, or end pid %s yourself if you mean to replace it.\n' "$branch" "$lpid" "$lsrc" "${state%% *}" "$lpid" >&2; return 1 ;; esac ;;
1040
- *) printf 'plot-dispatch: could not read whether a loop is alive on %s — refusing.\n' "$branch" >&2; return 1 ;;
1041
- esac
1042
- case "$state" in
1043
- running*)
1044
- printf 'plot-dispatch: a worker is alive on %s (pid %s) — refusing.\n Stop it first if you mean to replace it:\n plot-dispatch.sh --stop %s\n' "$branch" "${state#running }" "$branch" >&2
1045
- return 1
1046
- ;;
1047
- waiting*)
1048
- marker=$(plot_worker_blocked_file "$wt" || true)
1049
- echo "plot-dispatch: $branch is blocked on a question — refusing." >&2
1050
- echo " the question is in $wt/${marker:-the marker file}" >&2
1051
- echo " Answer it and delete the marker, then restart." >&2
1052
- return 1
1053
- ;;
1054
- esac
1055
- return 0
1056
- }
1057
-
1058
995
  # WHICH COMMAND STARTS THIS AGENT is the domain's answer: `startCommand`, asked
1059
996
  # through `board/plot-start-command.mjs`. An absent `Worker command` is not set
1060
997
  # up and starts nothing, `none` is declined, and a free agent refuses a command
@@ -1096,8 +1033,7 @@ ask_start_command() { # $1 = free | assigned
1096
1033
  }
1097
1034
 
1098
1035
  start_worker() {
1099
- local branch="$1" wt="$2"
1100
- local cmd
1036
+ local branch="$1" wt="$2" cmd
1101
1037
 
1102
1038
  # THE PLAN IS THE DEFAULT AND THE FLAG IS THE OVERRIDE.
1103
1039
  #
@@ -1565,9 +1501,10 @@ start_worker() {
1565
1501
  PLOT_STAMP_STARTED="$stamp_now" \
1566
1502
  PLOT_AGENT_MONITOR="$agent_monitor" \
1567
1503
  PLOT_EXIT_FILE="$wt/.plot-worker.exit" PLOT_PID_FILE="$wt/.plot-worker.pid" \
1504
+ PLOT_PID_STARTED_FILE="$wt/.plot-worker.pid.startedAt" \
1568
1505
  PLOT_WRAPPER_PID_FILE="$wt/.plot-worker.wrapper.pid" \
1569
1506
  PLOT_SCRIPT_DIR="$script_dir" \
1570
- exec nohup sh -c 'printf "%s" "$$" > "$PLOT_WRAPPER_PID_FILE"; wmon=""; amon=""; if [ -n "$PLOT_AGENT_MONITOR" ]; then "$PLOT_AGENT_MONITOR" & amon=$!; fi; PATH="$PLOT_SCRIPT_DIR:$PATH"; export PATH; ( '"$cmd"' ) & agent=$!; trap "" TERM; printf "%s" "$agent" > "$PLOT_PID_FILE"; if [ -f "$PLOT_MANIFEST_FILE" ]; then awk -v pid="$agent" -v started="$PLOT_STAMP_STARTED" -v wrapper="$$" -v wmon="$wmon" -v amon="$amon" '"'"'
1507
+ exec nohup sh -c 'printf "%s" "$$" > "$PLOT_WRAPPER_PID_FILE"; wrapperstarted=$(ps -o lstart= -p "$$" 2>/dev/null); wmon=""; amon=""; if [ -n "$PLOT_AGENT_MONITOR" ]; then "$PLOT_AGENT_MONITOR" & amon=$!; fi; PATH="$PLOT_SCRIPT_DIR:$PATH"; export PATH; ( '"$cmd"' ) & agent=$!; trap "" TERM; printf "%s" "$agent" > "$PLOT_PID_FILE"; agentstarted=$(ps -o lstart= -p "$agent" 2>/dev/null); printf "%s" "$agentstarted" > "$PLOT_PID_STARTED_FILE"; if [ -f "$PLOT_MANIFEST_FILE" ]; then awk -v pid="$agent" -v pidstarted="$agentstarted" -v started="$PLOT_STAMP_STARTED" -v wrapper="$$" -v wrapperstarted="$wrapperstarted" -v wmon="$wmon" -v amon="$amon" '"'"'
1571
1508
  BEGIN { relaunch = 0; count = 1; stamped = 0 }
1572
1509
  FNR == NR {
1573
1510
  if ($0 ~ /^ "pid": "[^"]*",$/) {
@@ -1582,7 +1519,9 @@ start_worker() {
1582
1519
  !stamped && $0 ~ /^ "pid": "[^"]*",$/ {
1583
1520
  stamped = 1
1584
1521
  print " \"pid\": \"" pid "\","
1522
+ print " \"pidStartedAt\": \"" pidstarted "\","
1585
1523
  print " \"wrapperPid\": \"" wrapper "\","
1524
+ print " \"wrapperPidStartedAt\": \"" wrapperstarted "\","
1586
1525
  print " \"workerMonitorPid\": \"" wmon "\","
1587
1526
  print " \"agentMonitorPid\": \"" amon "\","
1588
1527
  if (relaunch) {
@@ -1591,7 +1530,9 @@ start_worker() {
1591
1530
  }
1592
1531
  next
1593
1532
  }
1533
+ $0 ~ /^ "pidStartedAt": "[^"]*",$/ { next }
1594
1534
  $0 ~ /^ "wrapperPid": "[^"]*",$/ { next }
1535
+ $0 ~ /^ "wrapperPidStartedAt": "[^"]*",$/ { next }
1595
1536
  $0 ~ /^ "workerMonitorPid": "[^"]*",$/ { next }
1596
1537
  $0 ~ /^ "agentMonitorPid": "[^"]*",$/ { next }
1597
1538
  relaunch && $0 ~ /^ "previousPid": "[^"]*",$/ { next }
@@ -1886,101 +1827,19 @@ if [ "$mode" = "stop" ]; then
1886
1827
  fi
1887
1828
 
1888
1829
  if [ "$mode" = "restart" ]; then
1889
- # THE COUNTERPART TO --stop, AND THE WHOLE FEATURE. `--stop` kills a worker;
1890
- # nothing started one on a branch that already holds a claim, because the
1891
- # dispatcher asks the scan for `--next` and `--next` fills claimable[] only
1892
- # where the branch is `open` — meaning NO REF EXISTS. A branch that has ever
1893
- # been claimed is `claimed` or `wip`, so it was never offered and
1894
- # `plot-dispatch.sh <slug>` answered `dispatched=0`: not a refusal with a
1895
- # reason, an empty set, which has nothing to say about what it filtered out.
1896
- #
1897
- # That `open`-only rule is Plot's LOCK and must not widen — three callers
1898
- # consume `--next`, and the board's auto-dispatch would begin restarting
1899
- # stalled work on a five-second timer with nobody deciding anything. So this
1900
- # is a SECOND QUESTION, asked only when a person asks it.
1901
- #
1902
- # HERE, BESIDE --stop AND BEFORE THE PHASE GATE, for the reason that block
1903
- # already gives: a branch that is already claimed and already has a worktree
1904
- # is work in flight, and the plan's phase says nothing about whether a
1905
- # stopped worker on it should be replaced. Refusing on phase would strand
1906
- # exactly the branch this exists to rescue.
1830
+ # A LAUNCHER: `board/plot-restart-command.mjs` holds the rule (`restartWorker`),
1831
+ # the start and the refusals. The worktree is git's answer, passed in so a
1832
+ # checkout with no bridged pulse still restarts. `--offline` is passed the
1833
+ # same way `reached_review()` above honours it: the PR question is never
1834
+ # put, and the restart reads no PR rather than an unanswered one.
1907
1835
  if [ -z "$restart_branch" ]; then
1908
- printf 'plot-dispatch: --restart needs a branch name, e.g. --restart feature/x\n A slug is not enough: which stopped branch to hand to a new worker\n is your call, not something this should guess.\n' >&2
1836
+ echo "plot-dispatch: --restart needs a branch name, e.g. --restart feature/x" >&2
1909
1837
  exit 1
1910
1838
  fi
1911
-
1912
- # ASK GIT WHICH WORKTREE HOLDS THE BRANCH — never rebuild the path from the
1913
- # name. This file's own rule (see resolve_wt_root): path-guessing is confined
1914
- # to CREATION, because a second naming convention gives it a second way to be
1915
- # wrong. It matters more here than anywhere: the population this verb serves
1916
- # includes the worktree a person made by hand after the tool had no verb for
1917
- # them, and a hand-made worktree rarely follows dispatch's naming.
1918
- restart_wt=$(worktree_holding_branch "$restart_branch")
1919
- if [ -z "$restart_wt" ] || [ ! -d "$restart_wt" ]; then
1920
- printf "plot-dispatch: no worktree holds '%s' — nothing to restart.\n --restart hands an EXISTING checkout to a new worker; it creates none.\n To start this branch fresh, dispatch its plan.\n" "$restart_branch" >&2
1921
- exit 1
1922
- fi
1923
-
1924
- # THE PR IS ASKED FIRST, BEFORE THE STATE WORD. This ordering is the round-one
1925
- # correction to the plan, and it comes from a measurement: five of five
1926
- # `failed` worktrees in this estate held a PR — four open, one already merged.
1927
- #
1928
- # `plot-worker-state.sh` refines `finished` by the TREE (an open or merged PR
1929
- # turns it into "the work reached review") but deliberately does NOT refine
1930
- # `failed`, `ended` or `none`, because "a recorded non-zero exit is already a
1931
- # specific answer about the process." True about the PROCESS, and silent about
1932
- # the WORK: a worker that opened its PR and then exited non-zero reads
1933
- # `failed` with nothing left to redo. A gate written on the state word alone
1934
- # would have restarted all five and discarded exactly what the `finished`
1935
- # refusal exists to protect.
1936
- #
1937
- # Same lesson plot-reap.sh learned from the other side: it reads `mergedAt`
1938
- # and never `state`, because a merged PR reports CLOSED. There the state word
1939
- # lies about merging; here the exit code lies about completion.
1940
-
1941
- # Only now the process. `worker_state` is the ONE answer to "is a worker
1942
- # running here" — asked rather than re-derived, so this cannot drift from
1943
- # `--status` and the scan the way five of six states already did once.
1944
- restart_state=$(worker_state "$restart_wt" "$restart_branch")
1945
- restart_loop=$(printf '%s\n' "$restart_wt" | plot_desk_loops) || restart_loop="unread"
1946
- handover_refusal "$restart_branch" "$restart_wt" "$restart_state" "${restart_loop:-unread}" || exit 1
1947
- # `stalled`, `failed`, `ended` and `no worker` all restart. The PR question
1948
- # above is what makes `failed` safe to include — and including it is the
1949
- # point: a gate that simply refused `failed` would pass every refusal test
1950
- # here and leave the verb unable to do the one thing it exists for.
1951
-
1952
- echo "restarting $restart_branch ($restart_state)"
1953
- echo " worktree: $restart_wt"
1954
-
1955
- # THE TREE IS INHERITED EXACTLY AS IT STANDS. A `stalled` worktree holds
1956
- # uncommitted work — that is what `stalled` MEANS, and a measured stall in
1957
- # this repo left 324 finished lines on the floor. Nothing here cleans,
1958
- # resets or stashes: a restart that discards that is worse than the missing
1959
- # affordance, because it looks like a supported operation. The new worker's
1960
- # brief already tells it to commit and push before verifying.
1961
- # A REBUILT BUNDLE ALONE IS NOT "UNCOMMITTED WORK". `main` rebuilds and
1962
- # pushes every generated board bundle (`bug/main-builds-its-bundles`, #1249),
1963
- # so a desk that locally rebuilt one to test says nothing an agent left on
1964
- # the floor — excused path by path, same reading `desk_dirt` applies.
1965
- if [ -n "$(git -C "$restart_wt" status --porcelain </dev/null 2>/dev/null | exclude_bundle_paths "$restart_wt")" ]; then
1966
- echo " uncommitted work in the tree is kept — the new worker inherits it"
1967
- fi
1968
-
1969
- # start_worker is the ORDINARY DISPATCH PATH, and reusing it is half this
1970
- # feature. The bypass this plan replaces produced an unregistered agent, so
1971
- # the board showed a branch name in the agent-name slot; a restart that
1972
- # spawned a worker without a manifest would reproduce the exact defect it
1973
- # exists to prevent. One writer, so the two cannot drift.
1974
- #
1975
- # These two globals are set below the phase gate, which this path exits
1976
- # before reaching. `slug` stays empty on purpose: a restart is not a plan
1977
- # fan-out, and the manifest records what this line actually knows.
1978
- repo_root="$repo_root_early"
1979
- worker_cmd_declined=0
1980
- case "$("$script_dir/plot-config.sh" get "Worker command" "")" in
1981
- none|NONE|None) worker_cmd_declined=1 ;;
1982
- esac
1983
- start_worker "$restart_branch" "$restart_wt" || exit 1
1839
+ PLOT_RESTART_WORKTREE=$(worktree_holding_branch "$restart_branch") \
1840
+ PLOT_RESTART_OFFLINE=$([ -n "$offline" ] && echo 1 || echo 0) \
1841
+ node "$script_dir/board/plot-restart-command.mjs" "$restart_branch" || exit 1
1842
+ spend_action_receipt "restart"
1984
1843
  exit 0
1985
1844
  fi
1986
1845
 
@@ -2011,7 +1870,6 @@ if [ "$mode" = "release" ]; then
2011
1870
  [ -n "$MAIN" ] || MAIN=$(default_branch)
2012
1871
  if [ -z "$MAIN" ]; then
2013
1872
  echo "plot-dispatch: cannot resolve the default branch — refusing to release $br." >&2
2014
- echo " Nothing was written." >&2
2015
1873
  exit 1
2016
1874
  fi
2017
1875
 
@@ -2021,7 +1879,6 @@ if [ "$mode" = "release" ]; then
2021
1879
  if ! git fetch -q --prune origin </dev/null 2>/dev/null; then
2022
1880
  echo "plot-dispatch: cannot fetch origin — refusing to release $br." >&2
2023
1881
  echo " Without a fresh reading this cannot tell a claim from pushed work." >&2
2024
- echo " Nothing was written." >&2
2025
1882
  exit 1
2026
1883
  fi
2027
1884
  ref_present=0
@@ -2036,36 +1893,36 @@ if [ "$mode" = "release" ]; then
2036
1893
  # which is right for a rendering and wrong here: a deleted ref cannot be
2037
1894
  # re-created, so a host that cannot be asked refuses. `--offline` promises no
2038
1895
  # host call, so it refuses too.
2039
- if [ -n "$offline" ]; then
2040
- echo "plot-dispatch: --release asks the host whether $br has a PR, and --offline forbids that — refusing." >&2
2041
- echo " Nothing was written." >&2
2042
- exit 1
2043
- fi
2044
- if ! pr_json=$("$script_dir/plot-host.sh" pr-state "$br" </dev/null 2>/dev/null); then
2045
- echo "plot-dispatch: the host could not be asked whether $br has a PR — refusing." >&2
2046
- echo " A release deletes a ref that cannot be re-created, so silence is not" >&2
2047
- echo " permission. Check the host (plot-host.sh pr-state $br) and retry." >&2
2048
- echo " Nothing was written." >&2
2049
- exit 1
2050
- fi
2051
- pr_state=$(printf '%s' "$pr_json" | sed -n 's/.*"state":"\([A-Z]*\)".*/\1/p')
2052
- pr_num=$(printf '%s' "$pr_json" | sed -n 's/.*"number":\([0-9]*\).*/\1/p')
2053
- # ANY MERGED PR, NOT ONLY THE NEWEST — `pr-merged` reads `mergedAt` over every
2054
- # PR for the branch, because a newer unmerged PR can mask a merged one.
2055
- merged_answer=$("$script_dir/plot-host.sh" pr-merged "$br" </dev/null 2>/dev/null) || merged_answer=unknown
2056
- case "$pr_state:$merged_answer" in
2057
- OPEN:*|MERGED:*|*:merged)
2058
- echo "plot-dispatch: $br has a pull request (#${pr_num:-?}, ${pr_state:-MERGED}) — refusing." >&2
2059
- echo " An open PR is work under review; a merged branch's ref is released by" >&2
2060
- echo " plot-release-refs.sh when its plan is delivered. Nothing was written." >&2
1896
+ if [ -z "$claim_only" ]; then
1897
+ if [ -n "$offline" ]; then
1898
+ echo "plot-dispatch: --release asks the host whether $br has a PR, and --offline forbids that — refusing." >&2
2061
1899
  exit 1
2062
- ;;
2063
- *:unknown|*:)
2064
- echo "plot-dispatch: the host could not say whether $br ever merged — refusing." >&2
2065
- echo " Check it (plot-host.sh pr-merged $br) and retry. Nothing was written." >&2
1900
+ fi
1901
+ if ! pr_json=$("$script_dir/plot-host.sh" pr-state "$br" </dev/null 2>/dev/null); then
1902
+ echo "plot-dispatch: the host could not be asked whether $br has a PR — refusing." >&2
1903
+ echo " A release deletes a ref that cannot be re-created, so silence is not" >&2
1904
+ echo " permission. Check the host (plot-host.sh pr-state $br) and retry." >&2
2066
1905
  exit 1
2067
- ;;
2068
- esac
1906
+ fi
1907
+ pr_state=$(printf '%s' "$pr_json" | sed -n 's/.*"state":"\([A-Z]*\)".*/\1/p')
1908
+ pr_num=$(printf '%s' "$pr_json" | sed -n 's/.*"number":\([0-9]*\).*/\1/p')
1909
+ # ANY MERGED PR, NOT ONLY THE NEWEST — `pr-merged` reads `mergedAt` over every
1910
+ # PR for the branch, because a newer unmerged PR can mask a merged one.
1911
+ merged_answer=$("$script_dir/plot-host.sh" pr-merged "$br" </dev/null 2>/dev/null) || merged_answer=unknown
1912
+ case "$pr_state:$merged_answer" in
1913
+ OPEN:*|MERGED:*|*:merged)
1914
+ echo "plot-dispatch: $br has a pull request (#${pr_num:-?}, ${pr_state:-MERGED}) — refusing." >&2
1915
+ echo " An open PR is work under review; a merged branch's ref is released by" >&2
1916
+ echo " plot-release-refs.sh when its plan is delivered. Nothing was written." >&2
1917
+ exit 1
1918
+ ;;
1919
+ *:unknown|*:)
1920
+ echo "plot-dispatch: the host could not say whether $br ever merged — refusing." >&2
1921
+ echo " Check it (plot-host.sh pr-merged $br) and retry. Nothing was written." >&2
1922
+ exit 1
1923
+ ;;
1924
+ esac
1925
+ fi
2069
1926
 
2070
1927
  # THE DESK, ASKED OF GIT — never rebuilt from the branch name, the rule every
2071
1928
  # other verb here follows. A manifest naming this branch may name a desk git
@@ -2109,7 +1966,6 @@ if [ "$mode" = "release" ]; then
2109
1966
  if [ "$answer" = "held-by-agent" ]; then
2110
1967
  echo "plot-dispatch: $br is held by a live agent — refusing." >&2
2111
1968
  printf '%s\n' "$holder_lines" | while IFS=$'\t' read -r h_session h_wt; do echo " $h_session (desk $h_wt)" >&2; done
2112
- echo " Nothing was written." >&2
2113
1969
  exit 1
2114
1970
  fi
2115
1971
 
@@ -2123,7 +1979,6 @@ if [ "$mode" = "release" ]; then
2123
1979
  echo "plot-dispatch: a worker is alive on $br (pid $(printf '%s' "$release_state" | cut -f2)) — refusing." >&2
2124
1980
  echo " A live worker has not abandoned its claim. Stop it first if you mean to:" >&2
2125
1981
  echo " plot-dispatch.sh --stop $br" >&2
2126
- echo " Nothing was written." >&2
2127
1982
  exit 1
2128
1983
  ;;
2129
1984
  esac
@@ -2139,7 +1994,6 @@ if [ "$mode" = "release" ]; then
2139
1994
  remote_work=$(git rev-list --count "refs/remotes/origin/$MAIN..refs/remotes/origin/$br" -- . </dev/null 2>/dev/null) || remote_work=""
2140
1995
  if [ -z "$remote_work" ]; then
2141
1996
  echo "plot-dispatch: cannot count the commits on origin/$br — refusing." >&2
2142
- echo " Nothing was written." >&2
2143
1997
  exit 1
2144
1998
  fi
2145
1999
  if [ "$remote_work" -gt 0 ]; then
@@ -469,7 +469,7 @@ fi
469
469
  # small fixture — a cap of 2000 is otherwise unreachable in a test. It is a
470
470
  # seam, not a knob: nothing in Plot sets it, and lowering it in real use buys
471
471
  # nothing but the silent misses described above.
472
- MERGE_SCAN_LIMIT=${PLOT_MERGE_SCAN_LIMIT:-2000}
472
+ MERGE_SCAN_LIMIT=${PLOT_MERGE_SCAN_LIMIT:-20000}
473
473
  # `%H %s` RATHER THAN `%s`, because the age rule needs the merge COMMIT and not
474
474
  # only its sentence: a subject proves a branch for a plan only when its merge is
475
475
  # not contained in the commit that added the plan file, and that is an ancestry
@@ -1041,9 +1041,9 @@ prefill_pr_states() {
1041
1041
  # missing from the rich payload has NO row at all once the plain payload's
1042
1042
  # OPEN rows are dropped below, and a missing row reads as "no PR".
1043
1043
  #
1044
- # OPEN FIRST, THEN ALL. A PR that merges between the two calls then carries
1045
- # a rich OPEN row and a plain MERGED one, and the rank keeps OPEN — stale by
1046
- # seconds, and the next scan corrects it.
1044
+ # OPEN FIRST, THEN SETTLED. A PR that merges between the two calls then
1045
+ # carries a rich OPEN row and a plain MERGED one, and the rank keeps OPEN —
1046
+ # stale by seconds, and the next scan corrects it.
1047
1047
  open_err=$("$script_dir/plot-host.sh" pr-list --state open --limit "$PR_LIST_LIMIT" --rich \
1048
1048
  ${_branch_args[@]+"${_branch_args[@]}"} \
1049
1049
  </dev/null 2>&1 >"$open_list_out"); rc_open=$?
@@ -1060,7 +1060,7 @@ prefill_pr_states() {
1060
1060
  # throttled host it would spend quota on a payload nothing reads.
1061
1061
  pr_list_verdict "$rc_open" "$open_err"; _v_open=$_plv
1062
1062
  case "$_v_open" in ok|partial) ;; *) HOST_VERDICT=$_v_open; return 0 ;; esac
1063
- host_err=$("$script_dir/plot-host.sh" pr-list --state all --limit "$PR_LIST_LIMIT" \
1063
+ host_err=$("$script_dir/plot-host.sh" pr-list --state settled --limit "$PR_LIST_LIMIT" \
1064
1064
  ${_branch_args[@]+"${_branch_args[@]}"} \
1065
1065
  </dev/null 2>&1 >"$host_list_out"); rc=$?
1066
1066
  pr_list_verdict "$rc" "$host_err"; _v_all=$_plv
@@ -1069,16 +1069,16 @@ prefill_pr_states() {
1069
1069
  if [ "$_r_open" -gt "$_plr" ]; then HOST_VERDICT=$_v_open; else HOST_VERDICT=$_v_all; fi
1070
1070
  case "$HOST_VERDICT" in ok|partial) ;; *) return 0 ;; esac
1071
1071
  # THE MERGE, AND THE TRAP IT AVOIDS. An open PR is in BOTH payloads — rich
1072
- # from the `open` call, plain from the `all` call — and both rows rank 1 in
1073
- # the dedup below. With the sort key exhausted, `sort` compares whole lines,
1074
- # and the plain row's `-` sentinel (0x2D) sorts before any letter: the plain
1075
- # row wins every time and the rollup is lost for 100% of open PRs.
1072
+ # from the `open` call, plain from the `settled` call — and both rows rank 1
1073
+ # in the dedup below. With the sort key exhausted, `sort` compares whole
1074
+ # lines, and the plain row's `-` sentinel (0x2D) sorts before any letter: the
1075
+ # plain row wins every time and the rollup is lost for 100% of open PRs.
1076
1076
  #
1077
- # So the `all` payload's OPEN rows are dropped before the concatenation, and
1078
- # each branch contributes one OPEN row at most. Those rows are unused: the
1079
- # `open` call already answered for every open PR, with its rollup.
1077
+ # So the `settled` payload's OPEN rows are dropped before the concatenation,
1078
+ # and each branch contributes one OPEN row at most. Those rows are unused:
1079
+ # the `open` call already answered for every open PR, with its rollup.
1080
1080
  #
1081
- # THE COMPLETENESS COUNT IS TAKEN FROM THE `all` PAYLOAD BEFORE THE FILTER.
1081
+ # THE COMPLETENESS COUNT IS TAKEN FROM THE `settled` PAYLOAD BEFORE THE FILTER.
1082
1082
  # `.list-complete` compares a row count against `PR_LIST_LIMIT`, and a count
1083
1083
  # taken after the filter can fall below the limit for a list that reached it
1084
1084
  # — a truncated list then reads as whole, and a cache miss derives `NONE` for
@@ -3378,14 +3378,12 @@ if [ -n "$slug" ]; then
3378
3378
  # Same precedence as the worktree form: the dated plan file first, then the
3379
3379
  # active index, then delivered. `ref_ls` is filtered rather than globbed
3380
3380
  # because the ref has no shell to expand `*`.
3381
- found=0
3382
3381
  for cand in $(ref_ls "$PLAN_DIR" | grep "$slug\.md$") \
3383
3382
  $(ref_ls "$ACTIVE_DIR" | grep "/$slug\.md$") \
3384
3383
  $(ref_ls "$DELIVERED_DIR" | grep "/$slug\.md$"); do
3385
3384
  add_ref_plan "$cand"
3386
- [ ${#plans[@]} -gt 0 ] && { found=1; break; }
3385
+ [ ${#plans[@]} -gt 0 ] && break
3387
3386
  done
3388
- [ "$found" = 1 ] || true
3389
3387
  else
3390
3388
  for cand in "$PLAN_DIR"*"$slug".md "$ACTIVE_DIR$slug.md" "$DELIVERED_DIR$slug.md"; do
3391
3389
  [ -e "$cand" ] && {