From 3d55e8c8f49aa0e7dc6cc79e9cbc62bde69236ea Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 14:57:15 +0100 Subject: [PATCH 1/3] feat: ytstack-status --phases with a denominator log outside the tree (#81) Done, in review and total per milestone roadmap and in total; a changed total names its cause, every change is logged under the state base. coordinate Step 11 points at it. Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 19 +++++ .ytstack/spec/hooks-and-state.md | 7 +- CHANGELOG.md | 9 +++ bin/ytstack-status | 117 +++++++++++++++++++++++++++++++ docs/statusline.md | 13 ++++ skills/coordinate/SKILL.md | 4 +- tests/ytstack-status.test.sh | 62 ++++++++++++++++ 7 files changed, 227 insertions(+), 4 deletions(-) diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index 80459004..280f5181 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1218,3 +1218,22 @@ Plus: ops-layer split during the same session (yopstack created as own public re **Chose:** A roadmap status `backlog` (frontmatter and the global ROADMAP column): planned, kept, not picked by `ytstack-frontier` while no milestone is current. Making it current sets `status: planned` and `current_milestone` again. **Supersedes:** None. Extends the roadmap state values in `docs/ux/skill-structure.md`. + +## 2026-11-15: Progress per phase counts slices of each roadmap; the denominator log lives outside the tree (issue #81) + +**Context:** Issue #81: in a four-day coordinator run the human asked for "% per phase" 37 times and the coordinator drew 22 charts by hand. Rows were added to phases, their denominators grew and progress looked negative. The issue asked for a report per phase and a log of every denominator change with its cause, kept out of the repository. + +**Options considered:** +- A) Rows are tasks (`M###-S##-PLAN.md` checkboxes). +- B) Rows are the slices of each `M###-ROADMAP.md`, the unit a lane works on; done from the checkbox or a `merged` lane, in review from the lane status. +- C) The log in `.ytstack/` (committed history). + +**Chose:** B, with the log under `/repos//phases/` (`snapshot`, `denominator.log`, the state base of `yt_state_base`). Each `--phases` run compares the slice ids per phase with the run before and appends one line per change (`first report`, `new phase`, `added S05`, `removed S04`, `phase left the report`). A `dropped` roadmap is left out. + +**Reason:** A coordinator dispatches and finishes slices, and `LANES.md` says which are in review; tasks have no lane status. The log records when a report saw a change, not a host fact or a plan state, and it changes on every report: committed, it would make every status a diff in the tree (the issue asked for it to stay out). Keying by the repository makes linked worktrees share one log. + +**How to apply:** +- A status with progress uses `ytstack-status --phases`, never a count by hand (`coordinate` Step 11). +- The change shown is the one since the previous `--phases` run; a second run without a change shows none. + +**Supersedes:** None. diff --git a/.ytstack/spec/hooks-and-state.md b/.ytstack/spec/hooks-and-state.md index 603d796b..b860feb3 100644 --- a/.ytstack/spec/hooks-and-state.md +++ b/.ytstack/spec/hooks-and-state.md @@ -103,6 +103,8 @@ Kimi's native `sessionStart.skill` supplies the static directive. `bin/ytstack-k See `docs/statusline.md`. It was read against `bin/ytstack-status` at `verified_at` and matches. +`ytstack-status --phases [--json]` (issue #81) prints done, in review and total per milestone roadmap that is not dropped, and the total, from the checkout's files. It keeps the slice ids of the last run and a log of every change of a total with its cause under `/repos//phases/` (`snapshot`, `denominator.log`), outside the tree; a run that cannot create that directory prints `log none` and writes nothing. + ## Interfaces and contracts - `hooks/hooks.json` registers the nine lifecycle hooks, `version-notice` and `pr-watch` for Claude Code: event, matcher, timeout. The Codex and Kimi registrations are in the `host-adapters` area. @@ -113,7 +115,7 @@ See `docs/statusline.md`. It was read against `bin/ytstack-status` at `verified_ ## Invariants and security boundaries - No hook resolves its target from `CLAUDE_PROJECT_DIR`. `bin/ytstack-check` fails on that name in a hook script, on `[ -d .git ]` and on a basename slug. -- Volatile state (automatic handoff, journal, Kimi pending context, the session's plugin version) is written outside the tree. `version-notice` writes only `plugin-version` and `notified-` under `/sessions//`, keyed by the session and not by the checkout, and only for a session id of letters, digits, `.`, `_` and `-`. The only in-tree location is the `.ytstack/.local` fallback. +- Volatile state (automatic handoff, journal, Kimi pending context, the session's plugin version, the phase snapshot and denominator log of `ytstack-status --phases`) is written outside the tree. `version-notice` writes only `plugin-version` and `notified-` under `/sessions//`, keyed by the session and not by the checkout, and only for a session id of letters, digits, `.`, `_` and `-`. The only in-tree location is the `.ytstack/.local` fallback. - No hook creates or changes `.ytstack/HANDOFF.md` or `STATE.md`. - Two hooks write deliberate artifacts into the resolved `.ytstack`: `post-tool-use-bash` (the draft stub) and `task-completed` (auto summary, checkbox). Both write into the checkout the payload names, so a session that works in a linked worktree leaves the main checkout unchanged. - `session-start`, `stop`, `pre-tool-use-edit`, `task-created` and `teammate-idle` write no files. Plain mode does not change this; the Kimi helper owns the pending write. @@ -148,7 +150,7 @@ See `docs/statusline.md`. It was read against `bin/ytstack-status` at `verified_ - `hooks/lib/git-ctx.sh` -- resolver, state directories, preferences, lint, progress parser, brownfield signals, commit discovery - `hooks/hooks.json` -- registration - `hooks/session-start`, `hooks/version-notice`, `hooks/pre-compact`, `hooks/session-end`, `hooks/stop`, `hooks/pre-tool-use-edit`, `hooks/post-tool-use-bash`, `hooks/task-created`, `hooks/task-completed`, `hooks/teammate-idle` -- `bin/ytstack-status` -- status line segment +- `bin/ytstack-status` -- status line segment, and progress per phase (`--phases`) - `bin/ytstack-check` (`check_resolver_contract`) -- banned patterns - Tests: `tests/git-ctx.test.sh`, `tests/hooks-json.test.sh`, `tests/hooks-readonly.test.sh`, `tests/hooks-stop.test.sh`, `tests/hooks-worktree.test.sh`, `tests/hooks-concurrency.test.sh`, `tests/post-tool-use-bash.test.sh`, `tests/pre-compact.test.sh`, `tests/session-end.test.sh`, `tests/session-notices.test.sh`, `tests/ytstack-status.test.sh`, `tests/kimi_lifecycle_test.py` @@ -185,6 +187,7 @@ python3 -m unittest discover -s tests -p 'kimi_lifecycle_test.py' -v - DECISIONS.md -- "2026-11-07: Ceremony scales with the change -- granularity, autonomy, quick lane and minimal-code guard are project preferences with loud defaults" - DECISIONS.md -- "2026-11-07: Brownfield adoption is a reference-first distillation, never a pitch" - DECISIONS.md -- "2026-11-11: Status line progress is one optional `progress` block in STATE.md, read by a plugin script (M021, issue #31)" +- DECISIONS.md -- "2026-11-15: Progress per phase counts slices of each roadmap; the denominator log lives outside the tree (issue #81)" - DECISIONS.md -- "2026-11-13: `STATE.md` is a pointer with a size bound; history leaves it through `reconcile`, a closed milestone is folded into the spec (M022-S03)" (lint W8 and W9, the cut excerpt in the injection) - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)" (the closing line of the injection names `spec/SPEC.md`) - DECISIONS.md -- "2026-11-14: The six gstack skills become ytstack's own adaptations, synced with upstream; no gstack install" (the library has no gstack functions) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43e54aa0..fc82a4ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- **Progress per phase** (issue #81): `ytstack-status --phases [--json]` + prints done, in review and total per milestone and in total. When a total + changed since the last report, the line says by how much and why (slices + added or removed), and every change goes to a log outside the repository, + so a grown total no longer reads as negative progress. `coordinate` Step 11 + points at it; the JSON is what a chart is drawn from. + ## [0.11.0] - 2026-11-15 ### Added diff --git a/bin/ytstack-status b/bin/ytstack-status index 0e86032d..f4601214 100755 --- a/bin/ytstack-status +++ b/bin/ytstack-status @@ -19,11 +19,128 @@ # (the checkout's copy only when the slice plan does not exist there yet). # The task pointer is always the local one. # Local refs only: no network, no gh. See docs/statusline.md. +# +# ytstack-status --phases [--json] [-C DIR] (issue #81) +# +# Progress per phase for a status report or a chart, from the files of the +# checkout of DIR (default: $PWD; no stdin): one line per milestone roadmap +# that is not dropped, " / done (%) in review", tab +# separated, then "total" and "read , log ". Rows are the roadmap's +# slices; done is a checked slice or a merged LANES.md row, in review a row +# in reported, in-review or ready. A total that changed since the last +# --phases run says by how much and why (slices added, removed); every such +# change is appended to a log outside the tree, +# /repos//phases/denominator.log (yt_state_base), so a +# grown denominator is never read as lost progress. --json prints the same as +# one object. Exit 0; 1 no .ytstack or no roadmap; 64 usage. set -uo pipefail . "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/hooks/lib/git-ctx.sh" +# ---- --phases ------------------------------------------------------------------ +phases() { + local dir="$PWD" json="" f m st rows ph now snap log + while [ $# -gt 0 ]; do + case "$1" in + --json) json=1; shift ;; + -C) [ $# -ge 2 ] && [ -d "$2" ] || { echo "ytstack-status: -C needs a directory" >&2; return 64; }; dir=$2; shift 2 ;; + *) echo "usage: ytstack-status --phases [--json] [-C DIR]" >&2; return 64 ;; + esac + done + yt_git_ctx "$dir"; yt_resolve_yt_dir >/dev/null + [ -n "$YT_DIR" ] || { echo "ytstack-status: no .ytstack directory for $dir" >&2; return 1; } + # " " per roadmap, tab separated + rows=$(yt_find_artifacts "$YT_DIR" 'M[0-9][0-9][0-9]-ROADMAP.md' | sort | while IFS= read -r f; do + m=$(basename "$f" -ROADMAP.md) + st=$(sed -n 's/^status:[ ]*\([A-Za-z-]*\).*/\1/p' "$f" | head -1) + [ "$st" != dropped ] || continue + awk -v m="$m" -v st="${st:--}" -v lanes="$YT_DIR/LANES.md" ' + BEGIN { + # the first table of LANES.md: lane -> status + while ((getline x < lanes) > 0) { + if (x !~ /^\|/) { if (n) break; continue } + if (++n > 2) { split(x, c, "|"); l = c[2]; s = c[4]; gsub(/^[ \t]+|[ \t]+$/, "", l); gsub(/^[ \t]+|[ \t]+$/, "", s); lane[l] = s } + } + } + /^- \[[ xX]\] S[0-9][0-9]( |$)/ { + id = substr($0, 7, 3); s = lane[m "-" id]; t++; ids = ids (ids == "" ? "" : " ") id + if (substr($0, 4, 1) != " " || s == "merged") d++ + else if (s == "reported" || s == "in-review" || s == "ready") r++ + } + END { printf "%s\t%s\t%d\t%d\t%d\t%s\n", m, st, d, r, t, ids } + ' "$f" + done) + [ -n "$rows" ] || { echo "ytstack-status: no milestone roadmap in $YT_DIR" >&2; return 1; } + + # The last report's slice ids per phase, and the log, outside the tree. + ph="$(yt_state_base)/repos/${YT_REPO_KEY:-unknown}/phases" + snap="$ph/snapshot"; log="$ph/denominator.log" + now=$(date -u +%Y-%m-%dT%H:%MZ) + mkdir -p "$ph" 2>/dev/null || { log="none (cannot write $ph)"; snap=/dev/null; } + printf '%s\n' "$rows" | awk -F'\t' -v now="$now" -v json="$json" -v snap="$snap" -v logf="$log" ' + BEGIN { + while ((getline x < snap) > 0) { + split(x, a, "\t"); old[a[1]] = a[2]; had[a[1]] = 1; oldn[a[1]] = (a[2] == "" ? 0 : split(a[2], y, " ")); any = 1 + } + } + function pct(d, t) { return t ? int(d * 100 / t) : 0 } + function esc(s) { gsub(/\\/, "\\\\", s); gsub(/"/, "\\\"", s); return s } + function jlist(s, a, n, i, o) { n = split(s, a, " "); o = ""; for (i = 1; i <= n; i++) o = o (i > 1 ? "," : "") "\"" a[i] "\""; return "[" o "]" } + # diff old new: sets ADD and DEL (space separated ids) + function diff(o, w, a, b, n, i, seen) { + ADD = ""; DEL = ""; split("", seen) + n = split(o, a, " "); for (i = 1; i <= n; i++) seen[a[i]] = 1 + n = split(w, b, " "); for (i = 1; i <= n; i++) if (!(b[i] in seen)) ADD = ADD (ADD == "" ? "" : " ") b[i]; else delete seen[b[i]] + for (i = 1; i <= split(o, a, " "); i++) if (a[i] in seen) DEL = DEL (DEL == "" ? "" : " ") a[i] + } + function cause( c) { + c = "" + if (ADD != "") { c = ADD; gsub(/ /, ", ", c); c = "added " c } + if (DEL != "") { d = DEL; gsub(/ /, ", ", d); c = c (c == "" ? "" : "; ") "removed " d } + return c + } + { + m = $1; n++; P[n] = m; S[m] = $2; D[m] = $3; R[m] = $4; T[m] = $5; I[m] = $6 + td += $3; tr += $4; tt += $5; cur[m] = 1 + if (!(m in had)) { L = L now "\t" m "\t-\t" $5 "\t" (any ? "new phase" : "first report") "\n"; next } + tb += oldn[m] + if (old[m] != $6) { + diff(old[m], $6); c = cause() + if (c != "") { C[m] = c; B[m] = oldn[m]; L = L now "\t" m "\t" oldn[m] "\t" $5 "\t" c "\n" } + } + } + END { + for (m in had) if (!(m in cur)) { L = L now "\t" m "\t" oldn[m] "\t-\tphase left the report\n"; tb += oldn[m]; gone = 1 } + tchg = any && (tb != tt) + if (snap != "/dev/null") { + printf "%s", L >> logf + for (i = 1; i <= n; i++) printf "%s\t%s\n", P[i], I[P[i]] > (snap ".tmp") + close(snap ".tmp") + } + if (json) { + printf "{\"read\":\"%s\",\"log\":\"%s\",\"phases\":[", now, esc(logf) + for (i = 1; i <= n; i++) { + m = P[i] + printf "%s{\"phase\":\"%s\",\"status\":\"%s\",\"done\":%d,\"in_review\":%d,\"total\":%d,\"percent\":%d,\"change\":", (i > 1 ? "," : ""), m, S[m], D[m], R[m], T[m], pct(D[m], T[m]) + if (m in C) { diff(old[m], I[m]); printf "{\"before\":%d,\"added\":%s,\"removed\":%s}}", B[m], jlist(ADD), jlist(DEL) } + else printf "null}" + } + printf "],\"total\":{\"done\":%d,\"in_review\":%d,\"total\":%d,\"percent\":%d,\"change\":%s}}\n", td, tr, tt, pct(td, tt), (tchg ? "{\"before\":" tb "}" : "null") + exit + } + for (i = 1; i <= n; i++) { + m = P[i] + printf "%s\t%d/%d done (%d%%)\t%d in review%s\n", m, D[m], T[m], pct(D[m], T[m]), R[m], (m in C ? "\ttotal " B[m] " -> " T[m] " since the last report: " C[m] : "") + } + printf "total\t%d/%d done (%d%%)\t%d in review%s\n", td, tt, pct(td, tt), tr, (tchg ? "\ttotal " tb " -> " tt " since the last report" : "") + printf "read %s, log %s\n", now, logf + } + ' || return 1 + [ ! -f "$snap.tmp" ] || mv "$snap.tmp" "$snap" +} +if [ "${1:-}" = --phases ]; then shift; phases "$@"; exit $?; fi + COLOR=yes [ -z "${NO_COLOR:-}" ] || COLOR=no [ "${1:-}" != "--no-color" ] || COLOR=no diff --git a/docs/statusline.md b/docs/statusline.md index b1720fd0..2c29e176 100644 --- a/docs/statusline.md +++ b/docs/statusline.md @@ -55,6 +55,19 @@ Plan progress belongs to the repository, the task pointer to the checkout. Only local refs are read. The script makes no network calls and does not use `gh`; one run takes well under a tenth of a second. +## Progress per phase + +`ytstack-status --phases [--json] [-C DIR]` is for a status report or a chart, not for the status line. It reads the files of the checkout (no stdin, no default-branch lookup) and prints one line per milestone roadmap that is not `dropped`, the total and the time of the read: + +``` +M004 2/5 done (40%) 1 in review total 4 -> 5 since the last report: added S05, S06; removed S04 +M006 0/1 done (0%) 0 in review +total 2/6 done (33%) 1 in review total 5 -> 6 since the last report +read 2026-11-15T10:42Z, log ~/.local/state/ytstack/repos//phases/denominator.log +``` + +A row is a slice of the roadmap. It is done when its checkbox is ticked or its `LANES.md` row is `merged`, in review when its row is `reported`, `in-review` or `ready`. Each run compares the slices per phase with the run before and names what changed the total. A grown total is then read as new work, not as lost progress. Every change is appended to `denominator.log` (UTC time, phase, total before, total after, cause: `first report`, `new phase`, `added S05`, `removed S04`, `phase left the report`) under the state base of `hooks/lib/git-ctx.sh` (`CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, `$XDG_STATE_HOME/ytstack` or `~/.local/state/ytstack`), keyed by the repository, never in the tree. `--json` prints the same as one object (`read`, `log`, `phases[]` with `phase`, `status`, `done`, `in_review`, `total`, `percent`, `change` with `before`, `added`, `removed` or `null`, and `total`), from which a chart is drawn. Exit 1 without `.ytstack/` or without a roadmap. + ## Integration in Claude Code Your status line script receives a JSON object on stdin. Pass it on and append the output. In a bash script: diff --git a/skills/coordinate/SKILL.md b/skills/coordinate/SKILL.md index 757c29f5..df3bf47e 100644 --- a/skills/coordinate/SKILL.md +++ b/skills/coordinate/SKILL.md @@ -3,7 +3,7 @@ name: coordinate description: "Coordinator mode for the session that owns a plan and delegates all of it, writing no product code itself. Use when many lanes are in flight, when a plan has dozens of work packages, when a session with open lanes continues after a compaction or a resume, or when the user says coordinate this, run the plan, you are the coordinator, keep the lanes moving, where does each lane stand. Not for one milestone with a handful of independent slices (spawn-milestone-team) and not for doing a task yourself (plan-task)." metadata: tier: task - version: 0.5.0 + version: 0.6.0 allowed-tools: - Bash - Read @@ -258,7 +258,7 @@ An `asked` question is never asked again: name it as waiting since its time. Whe **Step 10 -- Stop loops that do not converge.** A lane gets the rounds `ytstack:code-review` allows ("Bounded review": round 1 complete, round 2 the fix, no third). A lane that failed verification twice, or that would need a third review, is not dispatched again: `ytstack-frontier set --status blocked --next "Q### with the human"`, and a question file with the diagnosis (the plan never decided the point, two rules conflict, or each fix moved the problem). -**Step 11 -- Report status.** Only when something changed that the human acts on (a question, a blocker, a finished plan, a lane that waits for his merge), or at a boundary he set in a standing instruction. No interim reports that work is running. A lane that merged without a person is no reason for a status of its own: the next status that is due names it in one line, with its class and the ceiling it merged under. A status is two to four full sentences with pointers (files, commits, pull request numbers). When the plan has gates it carries two numbers side by side, closed by work and accepted, as `ytstack:reassess-roadmap` counts them. When `LESSONS` counts open lessons, the status names them in one line as the preamble prints them (`lessons: 3 open (1 proposals, 2 checks to build)`), with the class of each one that counts 2 or more. Every host fact in it comes from a read made for this status and carries `read `. When the human asks where the lanes stand, answer per lane instead: the status and the next action of its row as written, then the open and asked questions with what they block. +**Step 11 -- Report status.** Only when something changed that the human acts on (a question, a blocker, a finished plan, a lane that waits for his merge), or at a boundary he set in a standing instruction. No interim reports that work is running. A lane that merged without a person is no reason for a status of its own: the next status that is due names it in one line, with its class and the ceiling it merged under. A status is two to four full sentences with pointers (files, commits, pull request numbers). When the plan has gates it carries two numbers side by side, closed by work and accepted, as `ytstack:reassess-roadmap` counts them. Progress per phase comes from `ytstack-status --phases` (`--json` for a chart), never from a count by hand: it names every change of a total since the last report with its cause, so a grown total is not read as lost progress. When `LESSONS` counts open lessons, the status names them in one line as the preamble prints them (`lessons: 3 open (1 proposals, 2 checks to build)`), with the class of each one that counts 2 or more. Every host fact in it comes from a read made for this status and carries `read `. When the human asks where the lanes stand, answer per lane instead: the status and the next action of its row as written, then the open and asked questions with what they block. **Step 12 -- Rotate.** When the session has been compacted once (a summary stands where the conversation was, or `HANDOFF_AUTO` is from this session), or its context is large by the host's indicator, rotate now. Do not wait for a quiet moment, for workers to report or for checks to finish: under load there is none, and a second compaction costs more than a rotation. It is one step, done in this order without dispatching anything in between: diff --git a/tests/ytstack-status.test.sh b/tests/ytstack-status.test.sh index 336501e2..45369f46 100644 --- a/tests/ytstack-status.test.sh +++ b/tests/ytstack-status.test.sh @@ -11,6 +11,9 @@ # branch (linked worktree), task pointer always local # - nothing outside a ytstack project and nothing for a malformed block # - colour by default, none with NO_COLOR or --no-color +# - --phases (issue #81): done / in review / total per roadmap that is not +# dropped and in total; a changed total names its cause, and every change +# goes to a log under the plugin data dir, never into the tree; --json # # Run: /bin/bash tests/ytstack-status.test.sh (exit 0 = all pass; macOS bash 3.2) @@ -174,6 +177,65 @@ eq "no main/master/origin: working tree" "0|V2 76% 138/180 · M003" "$(seg "$ G="$TMP/nogit"; mkdir -p "$G/.ytstack"; state "$G" M003 none none "$BLOCK" eq "not a git repository: working tree" "0|V2 76% 138/180 · M003" "$(seg "$G")" +# ---- 6. --phases: progress per milestone, the denominator log out of tree --- +echo "# phases" +export CLAUDE_PLUGIN_DATA="$TMP/data" +TAB=' ' +# road : "x S01" checked, "- S02" open +road() { + local f="$1/.ytstack/$2-ROADMAP.md" s; printf -- '---\nmilestone: %s\nstatus: %s\n---\n\n# %s Roadmap\n\n## Slices\n\n' "$2" "$3" "$2" > "$f"; shift 3 + for s in "$@"; do case "$s" in x\ *) echo "- [x] ${s#x } -- goal" ;; *) echo "- [ ] ${s#- } -- goal" ;; esac; done >> "$f" +} +# ph [args]: OUT and EC of --phases, run from elsewhere +ph() { local d="$1"; shift; OUT=$(cd "$ELSEWHERE" && bash "$BIN" --phases -C "$d" "$@" &1); EC=$?; } +P=$(new_repo phases); state "$P" M004 none none +road "$P" M003 done "x S01" "x S02" +road "$P" M004 active "x S01" "- S02" "- S03" "- S04" +road "$P" M005 dropped "- S01" +printf -- '---\nupdated: 2026-11-15T10:00:00Z\n---\n\n# Lanes\n\n| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n|---|---|---|---|---|---|---|---|---|---|\n| M004-S02 | implement | merged | w 2026-11-15T08:00Z | - | - | 3 | abc1234 | 1 | - |\n| M004-S03 | implement | in-review | w 2026-11-15T09:00Z | - | - | 4 | - | 1 | - |\n' > "$P/.ytstack/LANES.md" +ph "$P" +eq "--phases: exit 0" 0 "$EC" +eq "one line per phase, a dropped one left out, the total, the read line" \ +"M003${TAB}2/2 done (100%)${TAB}0 in review +M004${TAB}2/4 done (50%)${TAB}1 in review +total${TAB}4/6 done (66%)${TAB}1 in review" "$(printf '%s\n' "$OUT" | sed '$d')" +LOG=$(find "$TMP/data" -name denominator.log | head -1) +like() { if printf '%s\n' "$3" | grep -E -- "$2" >/dev/null; then ok "$1"; else bad "$1" "no line matches /$2/ in: $3"; fi; } +like "the last line: read time and the log" "^read [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}Z, log .*/repos/[0-9a-f]+/phases/denominator.log\$" "$OUT" +case "$LOG" in "$TMP/data/repos/"*) ok "the log lives in the plugin data dir, keyed by repository" ;; *) bad "log location" "$LOG" ;; esac +eq "the first report logs each phase once" "M003 - 2 first report|M004 - 4 first report" "$(awk -F'\t' '{ printf "%s%s %s %s %s", (NR > 1 ? "|" : ""), $2, $3, $4, $5 }' "$LOG")" +eq "nothing is written into the tree" "" "$(git -C "$P" status --porcelain --untracked-files=all | grep -v -e LANES.md -e ROADMAP.md -e STATE.md -e PLAN.md)" +road "$P" M004 active "x S01" "- S02" "- S03" "- S05" "- S06" +ph "$P" +eq "a changed denominator is named with its cause" \ +"M004${TAB}2/5 done (40%)${TAB}1 in review${TAB}total 4 -> 5 since the last report: added S05, S06; removed S04" "$(printf '%s\n' "$OUT" | grep '^M004')" +eq "the total carries the change too" "total${TAB}4/7 done (57%)${TAB}1 in review${TAB}total 6 -> 7 since the last report" "$(printf '%s\n' "$OUT" | grep '^total')" +eq "and the log has one line for it" "M004 4 5 added S05, S06; removed S04" "$(awk -F'\t' 'END { print $2, $3, $4, $5 }' "$LOG")" +ph "$P" +hasnt() { case "$3" in *"$2"*) bad "$1" "unexpected '$2' in: $3" ;; *) ok "$1" ;; esac; } +hasnt "no change: no change shown" "since the last report" "$OUT" +eq "and nothing logged" 3 "$(awk 'END { print NR }' "$LOG")" +road "$P" M006 planned "- S01"; road "$P" M003 dropped "x S01" "x S02" +ph "$P" +eq "a new phase and a dropped one are logged" "M006 - 1 new phase|M003 2 - phase left the report" "$(awk -F'\t' 'NR > 3 { printf "%s%s %s %s %s", (NR > 4 ? "|" : ""), $2, $3, $4, $5 }' "$LOG")" +if command -v jq >/dev/null 2>&1; then + road "$P" M004 active "x S01" "- S02" "- S03" "- S05" "- S06" "- S07" + ph "$P" --json + eq "--json: exit 0" 0 "$EC" + eq "--json: phases, counts and the change" "M004 active 2 1 6 33 5 S07|M006 planned 0 0 1 0 null|2 1 7 28 6" \ + "$(printf '%s' "$OUT" | jq -r '(.phases[] | "\(.phase) \(.status) \(.done) \(.in_review) \(.total) \(.percent) \(if .change then "\(.change.before) \(.change.added | join(","))" else "null" end)"), "\(.total.done) \(.total.in_review) \(.total.total) \(.total.percent // "null") \(.total.change.before)"' | paste -sd'|' -)" + case "$(printf '%s' "$OUT" | jq -r '.read + " " + .log')" in 20*" $LOG") ok "--json: read time and log path" ;; *) bad "--json: read and log" "$OUT" ;; esac +else + ok "--json: skipped, no jq" +fi +N2=$(new_repo noroad); state "$N2" none none none +ph "$N2" +eq "no roadmap: exit 1" 1 "$EC" +ph "$TMP/plain" +eq "no .ytstack: exit 1" 1 "$EC" +OUT=$(bash "$BIN" --phases --bogus 2>&1); EC=$? +eq "unknown option: exit 64" 64 "$EC" + echo echo "$PASS passed, $FAIL failed" [ "$FAIL" -eq 0 ] From 7bb019d58d4f384cde6f1a887e7720ee5b58d05b Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 15:16:04 +0100 Subject: [PATCH 2/3] feat: lane liveness in frontier check, worktree inventory, peers in LANES.md (#84) ytstack-frontier check prints stale: lines (exit 2) for running lanes whose worker reported or went silent and ready lanes nobody claimed; peer set / peer list keep a ## Peers section. ytstack-upkeep lists stale lanes and gets --worktrees, which prints remove commands and runs none. coordinate prints peers in its preamble and Rotation block. Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 21 ++++ .ytstack/spec/artifacts.md | 2 +- .ytstack/spec/checks-and-evals.md | 6 +- .ytstack/spec/hooks-and-state.md | 2 +- .ytstack/spec/skills.md | 4 +- CHANGELOG.md | 13 +++ bin/ytstack-frontier | 178 +++++++++++++++++++++++++++--- bin/ytstack-upkeep | 116 ++++++++++++++++++- docs/recipes/recurring-upkeep.md | 4 +- docs/ux/coordinator-format.md | 33 +++++- skills/coordinate/SKILL.md | 9 +- tests/skill-preambles.test.sh | 10 ++ tests/ytstack-frontier.test.sh | 104 ++++++++++++++++- tests/ytstack-upkeep.test.sh | 65 ++++++++++- 14 files changed, 532 insertions(+), 35 deletions(-) diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index 280f5181..72107683 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1237,3 +1237,24 @@ Plus: ops-layer split during the same session (yopstack created as own public re - The change shown is the one since the previous `--phases` run; a second run without a change shows none. **Supersedes:** None. + +## 2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84) + +**Context:** Issue #84: in a four-day coordinator run lanes finished and nobody took them over overnight, 97 worktrees piled up, and after a compaction the coordinator sent a production request to the wrong session of another repository. `ytstack-upkeep` flagged only lanes held for more than 24 hours. + +**Options considered:** +- A) A new command for liveness; `check` stays a format check. +- B) `check` reads a well-formed table for stalled lanes, one `stale:` line each, exit 2 (format problems keep exit 1 and skip the liveness read). +- For "the worker reported": a report file the worker writes, or what the files already show. +- For peers: a second Markdown table in `LANES.md`, or list lines. + +**Chose:** B with N = 60 minutes (`--minutes`). A running row counts as reported when its row carries a pull request or its worktree no longer exists; silent when its branch had no commit for N minutes, counted from the claim when that is newer. A ready lane is stale when nobody claimed it for N minutes since a check first saw it ready; that first sight is kept outside the tree in `/repos//frontier-ready`. `ytstack-upkeep --worktrees` prints the inventory and the `git worktree remove` / `git branch -D` commands for merged or closed, clean, unlocked, unheld ones and runs none. Peers are `- | |
| ` lines under `## Peers`, keyed by role and repository. + +**Reason:** The issue names `check`, and the coordinator already runs it at a rotation and upkeep on a schedule; a separate exit code keeps upkeep and every caller able to tell a broken table from a slow lane. Workers do not push and leave no report on disk, so a pull request in the row and a removed worktree are the local traces a report leaves; anything else would need the host. 60 minutes is longer than one task commit of a worker and much shorter than the overnight gap of the issue. The first sight of a ready lane changes with every check and is no plan state, so it stays out of the tree like the other volatile state. Printing commands instead of running them keeps a removal with a person (`rm -r` and branch deletion of parallel sessions are irreversible), and a locked worktree is a running session on Claude Code. Every existing reader of `LANES.md` (finish-lane, lane-retro, upkeep, the preambles) takes every line that starts with `|` as a lane row; list lines are invisible to all of them. + +**How to apply:** +- A `stale:` line is a prompt to read the branch and set the row, or to dispatch; no script releases a lane by itself. +- A message to a session of another repository goes to the address under `## Peers`, and `peer set` runs after each contact. +- A new reader of `LANES.md` reads the lanes table only from lines that start with `|`. + +**Supersedes:** None. Extends "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)". diff --git a/.ytstack/spec/artifacts.md b/.ytstack/spec/artifacts.md index 1fca8aa1..6a968b8e 100644 --- a/.ytstack/spec/artifacts.md +++ b/.ytstack/spec/artifacts.md @@ -64,7 +64,7 @@ The `.ytstack/` artifact model: the Markdown files that hold a project's memory | `codebase/{stack,architecture,conventions,concerns}.md`, `backlog/README.md` | `adopt-brownfield` | refreshed by deleting the file and running the skill again | | `spec/SPEC.md`, `spec/.md` | `init-project` (every area `planned`), `adopt-brownfield` (pointer-only over existing documents; also for a project that has `.ytstack/` and no spec) | the task that changes the area, in its own commits; `reassess-roadmap` sets `verified_at` when it answers the drift report | | `HANDOFF.md` | `handoff-session`; `coordinate` when it rotates (its format with the "Rotation" block of `docs/ux/coordinator-format.md`) | the user; the rotating coordinator appends its workers' reports under "Reports after the rotation"; no hook writes it | -| `LANES.md` | `bin/ytstack-frontier claim` (first claim) | `bin/ytstack-frontier` (`set`, `release`), one row per call; called by `spawn-milestone-team`, `coordinate`, `finish-lane` | +| `LANES.md` | `bin/ytstack-frontier claim` or `peer set` (first write) | `bin/ytstack-frontier` (`set`, `release`), one row per call; called by `spawn-milestone-team`, `coordinate`, `finish-lane`; its `## Peers` lines (sessions in other repositories) by `ytstack-frontier peer set` from `coordinate` | | `questions/Q###-.md` | `bin/ytstack-questions new` (from `coordinate`, `reassess-roadmap`, `review-lessons` (a proposed line for a role file, `blocks:` the finding), and from `bin/ytstack-upkeep --question`, which keeps at most one open or asked file titled `Upkeep found ...`) | the agent fills Context, Options, Recommendation; `ask` and `answer` change the state; the answer text is the human's | | `standing/-.md`, `STANDING.md` | `coordinate`, when the human gives an instruction that holds beyond the task: a new file with `given`, `scope`, `supersedes` (`docs/ux/coordinator-format.md`); appended to `STANDING.md` only where no `standing/` exists | an entry is never edited; a newer one supersedes it by name, readers skip it; `STANDING.md` alone stays valid, also as an index, and is read beside the directory | | `handover/-.sh` and its receipt | `handover-step` through `bin/ytstack-handover new`; the receipt by the script when the human runs it | a script that ran is not edited | diff --git a/.ytstack/spec/checks-and-evals.md b/.ytstack/spec/checks-and-evals.md index 5eb5af9d..79f00455 100644 --- a/.ytstack/spec/checks-and-evals.md +++ b/.ytstack/spec/checks-and-evals.md @@ -79,7 +79,7 @@ Everything that tells a contributor whether a change is acceptable: the static c - `new` records a finding once: a second sighting of the key raises its count, a sighting of a `fixed` one writes a regression with `reopens:`, a `dismissed` one stays dismissed; writes under a noclobber lock. `list`, `set`, `incident new`, `check` (findings and incident records; every mitigation names a handover script that passes `bin/ytstack-handover check` unless declined). - `--kind review` records an escaped review-bot finding (key `review::`) without a "Signals" source; `review-checked` records and asks which merged pull request had its escape check, in `signals/review-checks`; `--tally` adds caught/escaped per role as a fourth field, which `check` validates. `lesson new` records a lesson (`kind: lesson`, key `lesson::`, a `target` of `check`, `knowledge`, `contract` or `proposal`, never `AGENTS.md` or `CLAUDE.md`; a repeat raises the count) and links it into an incident record with `--incident`; `lesson list [--since]` lists them; `check` fails on a closed incident without a recorded lesson and on a `fixed` lesson whose target is a proposal or a missing file. -**`bin/ytstack-upkeep`**: one read-only run over `.ytstack/` with eight counted sections (spec, state, gates, questions, lanes, runtime, review policy, review checks) and a ninth, `factory tools`, that lists the lines of `yt_factory_notices` (a factory tool that is off although the project would use it, `hooks-and-state`) and is never counted; exit 0 with `nothing needs a look`, 10 otherwise. `review checks` lists, only when `REVIEW.md` declares own reviewers, the merged pull requests without a line in `signals/review-checks` (an anchored window from 14 days before the earliest time in that file, or 14 days ago without one, at most 90 days back; cut at 500 with a notice), from one `gh pr list --search merged:>=` (one call per 100) (plus one `gh repo view` when `origin` is not a GitHub URL); a failed read is an item, a missing `gh` or `jq` a note. `--question` writes one question file and none while an earlier `Upkeep found ...` is open or asked. `docs/recipes/recurring-upkeep.md` puts it on a schedule. +**`bin/ytstack-upkeep`**: one read-only run over `.ytstack/` with eight counted sections (spec, state, gates, questions, lanes, runtime, review policy, review checks) and a ninth, `factory tools`, that lists the lines of `yt_factory_notices` (a factory tool that is off although the project would use it, `hooks-and-state`) and is never counted; exit 0 with `nothing needs a look`, 10 otherwise. `review checks` lists, only when `REVIEW.md` declares own reviewers, the merged pull requests without a line in `signals/review-checks` (an anchored window from 14 days before the earliest time in that file, or 14 days ago without one, at most 90 days back; cut at 500 with a notice), from one `gh pr list --search merged:>=` (one call per 100) (plus one `gh repo view` when `origin` is not a GitHub URL); a failed read is an item, a missing `gh` or `jq` a note. `--question` writes one question file and none while an earlier `Upkeep found ...` is open or asked. `lanes` also lists the `stale:` lines of `ytstack-frontier check`, once per lane. `--worktrees` prints instead the linked worktrees and local branches with the state of their newest pull request (one `gh pr list --state all`), the age of the last commit, uncommitted changes, a lock and the held lane that names the branch, then the `git worktree remove` / `git branch -D` commands for the merged or closed, clean, unlocked and unheld ones, never run; none without the PR state; exit 10 with a command. `docs/recipes/recurring-upkeep.md` puts it on a schedule. **`bin/ytstack-upstream`** (`docs/ux/upstream-feedback.md`): `mode` prints the effective `upstream_feedback` through `yt_upstream_feedback`, the repository and the path of the rules, and asks `gh auth status` only for `file` (without a login: `mode: suggest` and a note); `draft` writes an issue body with `TODO:` lines, the ytstack version, host and OS under `$TMPDIR` (never inside a git checkout) and never calls `gh`; `check` exits 1 on a `TODO:` left, an empty "Evidence", no filled `Searched:` line, an email address (not `noreply`), a token-looking string (the rule of `bin/ytstack-handover`) or a home directory path. It never posts; the agent does, after `check`. @@ -91,7 +91,7 @@ Everything that tells a contributor whether a change is acceptable: the static c **The coordinator scripts** (formats and rules: `docs/ux/coordinator-format.md`; each has a suite of the same name under `tests/`) -- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder; `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). +- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder; `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row with a pull request in it, with a worktree that no longer exists, or whose branch had no commit for `--minutes` (default 60, from the claim when that is newer), and a `ready` lane nobody claimed for `--minutes` since a check first saw it (kept in `/repos//frontier-ready`, outside the tree); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). - `bin/ytstack-plans` (`docs/ux/external-plans.md`): `scan` counts the work rows (task-list items, rows of tables with a status or checkbox column, nothing in a code fence) of `plans/`, `roadmap/` and their variants and prints one line per directory with `verdict=large` from 10 open rows and the answer recorded in `PREFERENCES.md`; exit 0 only for a large directory without an answer. `rows` prints `path:line`, state, id, section and title per row; a relative PATH is read from where the command was started, else from the repository root, and the output names files relative to the root. It writes nothing; the mapping is the agent's (`reconcile`, `adopt-brownfield`). - `bin/ytstack-questions`: `new`, `list`, `next`, `ask` (once), `answer` (refused without text under "Answer"), `check`. - `bin/ytstack-finish-lane`: one step per call (`leftovers`, `commit`, `push`, `open-pr`, `wait-head`, `body-check`, `gates`, `merge`, `route`); every gate is read from GitHub through `gh` at the moment of the call, and `merge` passes the reviewed commit to the host so that a moved head cannot be merged. `route --lane [--pr ]` reads the lane's worker (the author) and plan from `LANES.md` and runs `bin/ytstack-risk route`; with `--pr` it passes the pull request on, and a lane without a plan file is routed from the host's reviews. `leftovers` and `commit` leave the evidence directory out. Its suite uses a stand-in for `gh` and a local bare remote. @@ -184,7 +184,7 @@ Not covered by these checks: `claude plugin eval` (costs money). `bash tests/run - DECISIONS.md -- "2026-11-14: Kimi uses native plugin bootstrap and pending lifecycle context (M020)". Source of the offline Kimi CI checks and the separately run native suite. - DECISIONS.md -- "2026-11-13: Whether a person looks at a change is decided per change: a floor from the diff, the class an independent reviewer states, a ceiling per area, lenses per kind of change (M025)". Source of `bin/ytstack-risk` and the lint rules for `auto_merge` and `REVIEW.md`. Extended by "2026-11-15: The risk route reads the review round from the review on the host first; the plan is the fallback (M031-S02, issue #54)". - DECISIONS.md -- "2026-11-13: `RUNTIME.md` has three sections with a fixed line format, read only through `bin/ytstack-runtime` (M025-S01)" -- DECISIONS.md -- "2026-11-13: After a merge the release is watched, not driven; upkeep is a script and a recipe, not a skill (M026)". Source of `release` and `bin/ytstack-upkeep`. +- DECISIONS.md -- "2026-11-13: After a merge the release is watched, not driven; upkeep is a script and a recipe, not a skill (M026)". Source of `release` and `bin/ytstack-upkeep`. Extended by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)": the `stale:` lines, `ytstack-upkeep --worktrees`, `peer set` and `peer list`. - DECISIONS.md -- "2026-11-13: Production findings and incidents are skill work on read-only access; a mitigation is a handover script a person runs (M027)". Source of `bin/ytstack-signals`. "2026-11-15: Feedback about ytstack itself goes through one channel with a setting; a script checks the body, the agent posts (M033-S01, issue #55)" is the source of `bin/ytstack-upstream`. - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)". Source of `bin/ytstack-spec` and the two spec checks. - DECISIONS.md -- "2026-11-13: Verification, review and orchestration work are bounded like code (M023, issue #35)". Source of `bin/ytstack-brief`. diff --git a/.ytstack/spec/hooks-and-state.md b/.ytstack/spec/hooks-and-state.md index b860feb3..dfbb5080 100644 --- a/.ytstack/spec/hooks-and-state.md +++ b/.ytstack/spec/hooks-and-state.md @@ -115,7 +115,7 @@ See `docs/statusline.md`. It was read against `bin/ytstack-status` at `verified_ ## Invariants and security boundaries - No hook resolves its target from `CLAUDE_PROJECT_DIR`. `bin/ytstack-check` fails on that name in a hook script, on `[ -d .git ]` and on a basename slug. -- Volatile state (automatic handoff, journal, Kimi pending context, the session's plugin version, the phase snapshot and denominator log of `ytstack-status --phases`) is written outside the tree. `version-notice` writes only `plugin-version` and `notified-` under `/sessions//`, keyed by the session and not by the checkout, and only for a session id of letters, digits, `.`, `_` and `-`. The only in-tree location is the `.ytstack/.local` fallback. +- Volatile state (automatic handoff, journal, Kimi pending context, the session's plugin version, the phase snapshot and denominator log of `ytstack-status --phases`, the first time `ytstack-frontier check` saw a lane ready) is written outside the tree. `version-notice` writes only `plugin-version` and `notified-` under `/sessions//`, keyed by the session and not by the checkout, and only for a session id of letters, digits, `.`, `_` and `-`. The only in-tree location is the `.ytstack/.local` fallback. - No hook creates or changes `.ytstack/HANDOFF.md` or `STATE.md`. - Two hooks write deliberate artifacts into the resolved `.ytstack`: `post-tool-use-bash` (the draft stub) and `task-completed` (auto summary, checkbox). Both write into the checkout the payload names, so a session that works in a linked worktree leaves the main checkout unchanged. - `session-start`, `stop`, `pre-tool-use-edit`, `task-created` and `teammate-idle` write no files. Plain mode does not change this; the Kimi helper owns the pending write. diff --git a/.ytstack/spec/skills.md b/.ytstack/spec/skills.md index db359330..6013edc3 100644 --- a/.ytstack/spec/skills.md +++ b/.ytstack/spec/skills.md @@ -105,7 +105,7 @@ Read from `PREFERENCES.md` in the resolved `.ytstack` directory by `yt_prefs` in Formats: `docs/ux/coordinator-format.md`. The four skills below are for the session that owns a plan and delegates all of it; none of them writes product code. -- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), `LANES.md`, the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), ask one question at a time from a question file, write a standing instruction down when it is given (a new file in `standing/`; `STANDING.md` only where no `standing/` exists), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. +- `coordinate` is a loop with a fixed order: start from the standing instructions (the entries of `standing/` in the resolved `YT_DIR`, project or user scope, newest first without superseded ones, and `STANDING.md`), `LANES.md`, the frontier and the questions (never from a conversation summary), read host facts fresh and stamp them with their read time, claim a lane before dispatching it, finish lanes through `finish-lane`, run the factory tools of Step 7 (one table of command, when and skip condition; the preamble prints `MERGE_BY`, `REVIEW_POLICY`, `OWN_REVIEWERS`, `PR_WATCH` with the heartbeat age, `RELEASE` and `SIGNALS`): the route before every merge, also one it makes itself outside `finish-lane` (then through `ytstack-finish-lane merge` and `finish-lane`'s rule of who merges), with the PR watch on (flag set and a worker heartbeat under 10 minutes old) register the repository's open pull requests to itself as their owning session (`ytstack-pr-watch register --all-open` without `--session`, at the start, after every restart or rotation and after a worker opened one) and otherwise poll through `bin/ytstack-watch`, `ytstack-watch release` after every merge to production, `signal-intake` / `incident` for signals and `review-lessons` after a merge with a bot finding, `lesson` on a red `main` and on every slip of a lane or its own (the open lessons in every status from the preamble's `LESSONS` line, a lesson proposal asked with the daily question, lesson lanes `lesson-F###` dispatched from the frontier with `ytstack-brief render --lesson` and set `fixed` after their merge), ask one question at a time from a question file, write a standing instruction down when it is given (a new file in `standing/`; `STANDING.md` only where no `standing/` exists), stop a lane that failed verification twice or needs a third review, and rotate after the first compaction in one step while lanes run: a handoff written from the files with the "Rotation" block of `docs/ux/coordinator-format.md` (PR watch session, background watches, each running worker's address), the successor's Step 3 takes the PR watches over with `ytstack-pr-watch handover --from `, and the old session stays open only as a relay that appends its workers' reports to `HANDOFF.md`. It also prints the sessions in other repositories it works with between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`, the `## Peers` lines of `LANES.md`), carries them under `Peers:` in the Rotation block, and takes progress per phase for a status from `ytstack-status --phases` (issues #81, #84). - `spawn-milestone-team` claims each lane with `bin/ytstack-frontier` before it dispatches, keeps the lane's row current, and looks at the frontier again whenever a lane is verified or merged. - `finish-lane` takes a reported lane to a merged pull request with `bin/ytstack-finish-lane`: review pinned to the host's head, the required lenses, `route`, the gates read from the host, the merge decided by `merge_by` and the route, then `bin/ytstack-watch release` on the merge commit when `RUNTIME.md` has a "Release" section (in the background; the receipt goes into the report, nothing is rolled back). A merge without a person is reported in one line with class, ceiling and lenses. After a merge it made itself, and when `REVIEW.md` declares own reviewers, it invokes `review-lessons` for the pull request. Before a lane goes back for a review that requested changes, a failed lens or a failed check, it invokes `lesson` (its Step 14). These two are the skills it may invoke. The pipeline supports GitHub through `gh` only; on another host the skill stops after the route. - **The class of a change.** `code-review` prints the floor of `bin/ytstack-risk` and has a reviewer that is not the author end with `Risk:`, `Severity:`, `Reach:` and `Invariants touched:`, read against "Invariants and security boundaries" and "Decisions that apply now" of the touched areas, also when only code moved. The round line records class, invariants and reviewer; a session reviewing its own change writes `by: self`, which routes to a person. On a pull request `finish-lane` and `code-review` post the round and lens lines in the body of a review on the reviewed head, and `finish-lane` routes with `--pr`: the record needs no commit that would move the head away from a head-bound review. Each lens the floor names gets a separate fresh reviewer with the lens brief (`bin/ytstack-brief render --kind review --lens `) and one lens line. @@ -196,5 +196,5 @@ Formats: `docs/ux/coordinator-format.md`. The four skills below are for the sess - DECISIONS.md -- "2026-10-13: Remove generated Codex copies; load the existing skills directly" (one skill tree for both hosts) - DECISIONS.md -- "2026-11-13: The technical spec is a set of artifacts of its own under `.ytstack/spec/` (M022, issue #36)" (the spec steps in the loop) - DECISIONS.md -- "2026-11-13: Verification, review and orchestration work are bounded like code (M023, issue #35)" (the work contract; extends the ceremony entry of 2026-11-07 from code to evidence and review) -- DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)", extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)" +- DECISIONS.md -- "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)", extended by "2026-11-14: Standing instructions are one file per entry in `.ytstack/standing/`; `STANDING.md` stays valid (issue #57)" and by "2026-11-15: Lane liveness is part of `ytstack-frontier check`, worktree cleanup only prints commands, peers are list lines in `LANES.md` (issue #84)" (the peers of `coordinate`) - DECISIONS.md -- "2026-11-13: `STATE.md` is a pointer with a size bound; history leaves it through `reconcile`, a closed milestone is folded into the spec (M022-S03)" diff --git a/CHANGELOG.md b/CHANGELOG.md index fc82a4ef..9434b669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 added or removed), and every change goes to a log outside the repository, so a grown total no longer reads as negative progress. `coordinate` Step 11 points at it; the JSON is what a chart is drawn from. +- **Lanes that stall are named** (issue #84): `ytstack-frontier check` + prints a `stale:` line (exit 2) for a running lane whose worker reported + (a pull request in its row, its worktree gone) or whose branch had no + commit for 60 minutes (`--minutes`), and for a ready lane nobody claimed + for that long. `ytstack-upkeep` lists them under `lanes`. +- **Worktree cleanup** (issue #84): `ytstack-upkeep --worktrees` lists the + worktrees and branches with their pull request state, age and uncommitted + changes, and prints the `git worktree remove` / `git branch -D` commands + for the merged or closed ones. It runs none of them. +- **Peers** (issue #84): sessions in other repositories go into a + `## Peers` section of `LANES.md` (`ytstack-frontier peer set` / `peer + list`); `coordinate` prints them in its preamble and its Rotation block, + so a compaction no longer loses which session is which. ## [0.11.0] - 2026-11-15 diff --git a/bin/ytstack-frontier b/bin/ytstack-frontier index f5b51082..1d18cd50 100755 --- a/bin/ytstack-frontier +++ b/bin/ytstack-frontier @@ -6,7 +6,9 @@ # ytstack-frontier [-C DIR] claim --by [--kind implement|review|prepare] [--branch B] [--worktree W] # ytstack-frontier [-C DIR] set [--status S] [--next TEXT] [--pr N] [--head SHA] [--round N] [--branch B] [--worktree W] # ytstack-frontier [-C DIR] release -# ytstack-frontier [-C DIR] check +# ytstack-frontier [-C DIR] check [--minutes N] +# ytstack-frontier [-C DIR] peer set --repo R --address A [--contact UTC] +# ytstack-frontier [-C DIR] peer list # # list one line per slice of the milestone (default: current_milestone of # STATE.md; with "none" the highest M###-ROADMAP.md that is not done, @@ -31,7 +33,21 @@ # set changes the named cells of one existing row. # release "Claimed by" becomes "-", the status "dropped" unless it is "merged". # check LANES.md has the ten columns, unique lanes, listed Status and Kind -# values, and a claim time on every held lane. +# values, a claim time on every held lane, and four cells in every +# line under "## Peers". A well-formed file is then read for lanes +# that stall (issue #84), one "stale: : ..." line each: +# a running row whose worker reported (a PR in its row, or its +# worktree no longer exists), or whose branch had no commit for +# --minutes (default 60; counted from the claim when that is newer, +# or when the row has no branch); +# a ready lane of `list` that nobody claimed for --minutes since a +# check first saw it ready. That first sight is kept outside the +# tree: /repos//frontier-ready (yt_state_base). +# peer the sessions in other repositories this coordinator works with, +# one line each under "## Peers" in LANES.md: +# - | |
| +# set adds the line of role and repository or replaces it (the last +# contact: --contact, else now), list prints them tab separated. # # LANES.md lives in the .ytstack directory of DIR (default: $PWD). A write # changes one row and the "updated:" line, under a lock, through a temporary @@ -42,7 +58,9 @@ # claim 0 claimed; 1 refused (says who holds the lane since when) # set 0; 1 the lane has no row, or nobody holds it and the status needs a holder # release 0; 1 the lane has no row -# check 0 "lanes ok" or "no lanes file"; 1 one line per problem +# check 0 "lanes ok" or "no lanes file"; 1 one line per problem; 2 the +# file is well-formed and some lanes are stale +# peer 0 # 64 usage, or a cell value with "|" or a newline set -uo pipefail @@ -57,7 +75,7 @@ KINDS='implement|review|prepare' NL=' ' -usage() { sed -n '5,9p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } +usage() { sed -n '5,11p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } die() { echo "ytstack-frontier: $*" >&2; exit 1; } # listed listed() { case "|$2|" in *"|$1|"*) return 0 ;; esac; return 1; } @@ -72,7 +90,7 @@ DIR="$PWD" if [ "${1:-}" = "-C" ]; then DIR="${2:-}"; shift 2 || true; fi CMD=list case "${1:-}" in - list|claim|set|release|check) CMD=$1; shift ;; + list|claim|set|release|check|peer) CMD=$1; shift ;; -h|--help|help) usage; exit 0 ;; ""|--*) ;; *) usage >&2; exit 64 ;; @@ -172,6 +190,15 @@ open_table() { [ -f "$LANES" ] || return 1 table_ok || die "$LANES has no lanes table in the documented format; run 'ytstack-frontier check'" } +# new_table: LANES.md with the empty lanes table (under the lock). +new_table() { + { printf -- '---\nupdated: -\n---\n\n# Lanes\n\n' + echo "| $(printf '%s' "$COLS" | sed 's/|/ | /g') |" + echo '|---|---|---|---|---|---|---|---|---|---|' + } > "$LANES.tmp" && mv "$LANES.tmp" "$LANES" || die "could not write $LANES" +} +# utc : the UTC time to the minute (BSD date, then GNU and BusyBox) +utc() { date -u -r "$1" +%Y-%m-%dT%H:%MZ 2>/dev/null || date -u -d "@$1" +%Y-%m-%dT%H:%MZ; } # ---- list ------------------------------------------------------------------------ # open_milestone: the highest milestone whose roadmap is still open. @@ -345,12 +372,7 @@ cmd_claim() { done [ -n "$by" ] && listed "${kind:-implement}" "$KINDS" || { usage >&2; return 64; } need_yt - if ! open_table; then - { printf -- '---\nupdated: -\n---\n\n# Lanes\n\n' - echo "| $(printf '%s' "$COLS" | sed 's/|/ | /g') |" - echo '|---|---|---|---|---|---|---|---|---|---|' - } > "$LANES.tmp" && mv "$LANES.tmp" "$LANES" || die "could not write $LANES" - fi + open_table || new_table YTF_C3=claimed; YTF_C4="$by $(date -u +%Y-%m-%dT%H:%MZ)"; YTF_C5=$branch; YTF_C6=$wt if get_row "$lane"; then if listed "$R_STATUS" "$HELD"; then @@ -412,12 +434,24 @@ cmd_release() { # ---- check ----------------------------------------------------------------------- cmd_check() { - [ $# -eq 0 ] || { usage >&2; return 64; } + local min=60 out + case "$#:${1:-}" in + 0:) ;; + 2:--minutes) case "$2" in ''|*[!0-9]*) usage >&2; return 64 ;; esac; min=$((10#$2)) ;; + *) usage >&2; return 64 ;; + esac [ -n "$YT_DIR" ] && [ -f "$LANES" ] || { echo "no lanes file"; return 0; } awk -v want="$COLS" -v statuses="$STATUSES" -v held="$HELD" -v kinds="$KINDS" ' function trim(s) { gsub(/^[ \t]+|[ \t]+$/, "", s); return s } function listed(v, list) { return index("|" list "|", "|" v "|") > 0 } function p(msg) { print msg; bad = 1 } + $0 == "## Peers" { peers = 1; next } + peers && /^## / { peers = 0 } + peers && /^- / { + if (split($0, c, "|") != 4 || trim(c[4]) !~ /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9](:[0-9][0-9])?Z$/) + p("line " NR ": peer line is not \"- | |
| \"") + next + } !/^\|/ { next } ++n == 1 { h = $0; gsub(/[ \t]*\|[ \t]*/, "|", h) @@ -438,16 +472,132 @@ cmd_check() { } END { if (!n) p("no lanes table") - if (bad) exit 1 - print "lanes ok" + exit (bad ? 1 : 0) + } + ' "$LANES" || return 1 + out=$(stale "$min") + [ -n "$out" ] || { echo "lanes ok"; return 0; } + printf '%s\n' "$out" + return 2 +} + +# stale : one "stale:" line per lane that stalls (see the header). +stale() { + local lim=$(($1 * 60)) now top lane st by br wt pr t since c f ready seen keep="" + now=$(date -u +%s) + top=${YT_MAIN_TOPLEVEL:-$YT_TOPLEVEL} + while IFS=' ' read -r lane _ st by br wt pr _; do + [ "$st" = running ] || continue + if [ "$pr" != - ]; then + echo "stale: $lane: running, but PR $pr is in its row: the worker reported; set the status"; continue + fi + case "$wt" in /*) f=$wt ;; *) f="$top/$wt" ;; esac + if [ "$wt" != - ] && [ ! -d "$f" ]; then + echo "stale: $lane: running, but its worktree $wt does not exist: the worker ended; read its branch and set the status"; continue + fi + t=${by##* }; case "$t" in *T[0-9][0-9]:[0-9][0-9]Z) t="${t%Z}:00Z" ;; esac + since=$(yt_epoch "$t"); [ -n "$since" ] || continue + c="" + [ "$br" = - ] || [ "$YT_IS_GIT" != yes ] || c=$(git -C "$YT_TOPLEVEL" log -1 --format=%ct "$br" -- 2>/dev/null) + [ -z "$c" ] || [ "$c" -le "$since" ] || since=$c + [ $((now - since)) -gt "$lim" ] || continue + if [ "$br" = - ]; then echo "stale: $lane: running, no branch in its row, claimed $(((now - since) / 60)) minutes ago" + else echo "stale: $lane: running, no commit on $br for $(((now - since) / 60)) minutes (since $(utc "$since"))"; fi + done </dev/null) || ready="" + f="$(yt_state_base)/repos/${YT_REPO_KEY:-unknown}/frontier-ready" + [ -n "$ready" ] || [ -f "$f" ] || return 0 + mkdir -p "${f%/*}" 2>/dev/null || return 0 + for lane in $ready; do + seen=$(awk -F'\t' -v l="$lane" '$1 == l { print $2; exit }' "$f" 2>/dev/null) + case "$seen" in ''|*[!0-9]*) seen=$now ;; esac + keep="$keep$lane $seen$NL" + [ $((now - seen)) -le "$lim" ] || echo "stale: $lane: ready, nobody claimed it for $(((now - seen) / 60)) minutes (first seen $(utc "$seen"))" + done + printf '%s' "$keep" > "$f.tmp" 2>/dev/null && mv "$f.tmp" "$f" +} + +# ---- peers ----------------------------------------------------------------------- +# peer_lines: the lines under "## Peers", four tab separated cells each. +peer_lines() { + awk ' + $0 == "## Peers" { s = 1; next } + s && /^## / { exit } + s && /^- / { + n = split(substr($0, 3), c, "|"); out = "" + for (i = 1; i <= n; i++) { gsub(/^[ \t]+|[ \t]+$/, "", c[i]); out = out (i > 1 ? "\t" : "") c[i] } + print out } ' "$LANES" } +cmd_peer() { + local role repo="" addr="" contact="" + case "${1:-}" in + list) + [ $# -eq 1 ] || { usage >&2; return 64; } + [ -n "$YT_DIR" ] && [ -f "$LANES" ] || return 0 + peer_lines; return 0 ;; + set) shift ;; + *) usage >&2; return 64 ;; + esac + role="${1:-}" + case "$role" in ""|-*) usage >&2; return 64 ;; esac + cell "$role"; shift + while [ $# -gt 0 ]; do + [ $# -ge 2 ] || { usage >&2; return 64; } + cell "$2" + case "$1" in + --repo) repo=$2 ;; + --address) addr=$2 ;; + --contact) contact=$2 ;; + *) usage >&2; return 64 ;; + esac + shift 2 + done + [ -n "$repo" ] && [ -n "$addr" ] || { usage >&2; return 64; } + [ -n "$contact" ] || contact=$(date -u +%Y-%m-%dT%H:%MZ) + case "$contact" in + [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]Z|[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z) ;; + *) echo "ytstack-frontier: --contact takes a UTC time (YYYY-MM-DDTHH:MMZ)" >&2; return 64 ;; + esac + need_yt + open_table || new_table + # The line of role and repository is replaced in place, a new one goes after + # the last peer line; without the section, it is appended to the file. + YTF_PEER="- $role | $repo | $addr | $contact" YTF_ROLE=$role YTF_REPO=$repo \ + awk -v now="$(date -u +%Y-%m-%dT%H:%M:%SZ)" ' + function trim(s) { gsub(/^[ \t]+|[ \t]+$/, "", s); return s } + { L[++n] = $0 } + END { + for (i = 1; i <= n; i++) { + if (L[i] == "## Peers") { sec = i; continue } + if (sec && L[i] ~ /^## /) break + if (sec && L[i] ~ /^- /) { + split(substr(L[i], 3), c, "|"); last = i + if (!hit && trim(c[1]) == ENVIRON["YTF_ROLE"] && trim(c[2]) == ENVIRON["YTF_REPO"]) { L[i] = ENVIRON["YTF_PEER"]; hit = 1 } + } + } + for (i = 1; i <= n; i++) { + if (i == 1 && L[i] == "---") { fm = 1; print L[i]; continue } + if (fm && L[i] == "---") { if (!stamped) print "updated: " now; fm = 0; print L[i]; continue } + if (fm && L[i] ~ /^updated:/) { print "updated: " now; stamped = 1; continue } + print L[i] + if (!hit && sec && i == (last ? last : sec)) { if (!last) print ""; print ENVIRON["YTF_PEER"] } + } + if (!sec) { print ""; print "## Peers"; print ""; print ENVIRON["YTF_PEER"] } + } + ' "$LANES" > "$LANES.tmp" && mv "$LANES.tmp" "$LANES" || die "could not write $LANES" +} + case "$CMD" in list) cmd_list "$@" ;; claim) cmd_claim "$@" ;; set) cmd_set "$@" ;; release) cmd_release "$@" ;; check) cmd_check "$@" ;; + peer) cmd_peer "$@" ;; esac diff --git a/bin/ytstack-upkeep b/bin/ytstack-upkeep index fdc5999f..16ec3458 100755 --- a/bin/ytstack-upkeep +++ b/bin/ytstack-upkeep @@ -3,6 +3,7 @@ # .ytstack directory. Meant for a schedule: docs/recipes/recurring-upkeep.md. # # ytstack-upkeep [-C DIR] [--question] [--open-days N] [--asked-days N] [--lane-hours N] +# ytstack-upkeep [-C DIR] --worktrees # # Prints one report for the project of DIR (default: $PWD): a first line with # the directory and the UTC time of the read, nine sections with a count and @@ -16,8 +17,9 @@ # asked; asked more than --asked-days days ago (default 7) # and not answered # lanes rows of LANES.md in a held status that were claimed more -# than --lane-hours hours ago (default 24); the problems of -# `ytstack-frontier check` instead when the table has some +# than --lane-hours hours ago (default 24), and the "stale:" +# lines of `ytstack-frontier check` (once per lane); the +# problems of that check instead when the table has some # runtime the problems of `ytstack-runtime check` # review policy the problems of `ytstack-risk check`, when that script is # part of this installation (the spec lint repeats them; they @@ -35,6 +37,17 @@ # routing, PR watch, the "Release" and "Signals" sections of # RUNTIME.md); listed, not counted: a setting is not a finding # +# --worktrees prints, instead of the report, the linked worktrees and the +# local branches without one (not the default branch) of DIR's repository +# (issue #84): branch, pull request state (the newest pull request of the +# branch, from one `gh pr list --state all`), age of the last commit, +# uncommitted changes, and the lane of LANES.md that holds the branch. Then +# "commands (not run): N" and the `git worktree remove` / `git branch -D` +# commands for every one whose pull request is merged or closed, that has no +# uncommitted changes, is not locked and no held lane names. It runs none of +# them. Without the PR state (no gh or jq, a failed read) it prints none. +# Exit 10 when it printed a command, 0 otherwise, 1 outside a git repository. +# # It only reads. With --question, and only when something needs a look, it # writes ONE question file through `ytstack-questions new` ("Upkeep found N # things that need a look") with the report under "## Context", and prints @@ -52,17 +65,18 @@ set -uo pipefail BIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" . "$BIN/../hooks/lib/git-ctx.sh" -usage() { sed -n '5p' "${BASH_SOURCE[0]}" | sed 's/^# *//'; } +usage() { sed -n '5,6p' "${BASH_SOURCE[0]}" | sed 's/^# *//'; } bad_usage() { [ $# -eq 0 ] || echo "ytstack-upkeep: $*" >&2; usage >&2; exit 64; } die() { echo "ytstack-upkeep: $*" >&2; exit 1; } -DIR="$PWD"; QUESTION=no; OPEN_DAYS=3; ASKED_DAYS=7; LANE_HOURS=24 +DIR="$PWD"; QUESTION=no; WORKTREES=no; OPEN_DAYS=3; ASKED_DAYS=7; LANE_HOURS=24 MERGED_LIMIT=500 # merged pull requests one run lists (gh pages: one call per 100) MERGED_DAYS=14 # lookback before the first review-checks line (and without one) MERGED_MAX_DAYS=90 # the window never reaches further back than this while [ $# -gt 0 ]; do case "$1" in --question) QUESTION=yes; shift; continue ;; + --worktrees) WORKTREES=yes; shift; continue ;; -h|--help|help) usage; exit 0 ;; -C|--open-days|--asked-days|--lane-hours) [ $# -ge 2 ] || bad_usage "$1 needs a value" ;; *) bad_usage "unknown argument '$1'" ;; @@ -83,7 +97,7 @@ done yt_git_ctx "$DIR" yt_resolve_yt_dir >/dev/null -[ -n "$YT_DIR" ] || die "no .ytstack directory for $DIR" +[ -n "$YT_DIR" ] || [ "$WORKTREES" = yes ] || die "no .ytstack directory for $DIR" NL=' ' @@ -117,6 +131,86 @@ age() { [ -z "$e" ] || echo $((NOW - e)) } +# ---- --worktrees (issue #84) ------------------------------------------------------- +# q : single-quoted for a shell +q() { printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"; } +# since : "N hours ago" below two days, "N days ago" above +since() { + local s=$((NOW - $1)) + if [ "$s" -lt $((2 * 86400)) ]; then echo "$((s / 3600)) hours ago"; else echo "$((s / 86400)) days ago"; fi +} +worktrees() { + local top=${YT_MAIN_TOPLEVEL:-$YT_TOPLEVEL} def prs="" note="" held="" path br lock wl="" bl="" cmds="" n=0 used=" " ct extra + [ "$YT_IS_GIT" = yes ] || die "$DIR is not a git repository" + def=$(git -C "$top" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null); def=${def#origin/} + [ -n "$def" ] || def=$(git -C "$top" symbolic-ref --quiet --short HEAD 2>/dev/null) + # The newest pull request per head branch: " " + if ! command -v gh >/dev/null 2>&1 || ! command -v jq >/dev/null 2>&1; then + note="PR state not read: gh or jq is not available" + elif ! prs=$(cd "$top" && gh pr list --state all --limit 500 --json number,state,headRefName 2>&1); then + note="PR state not read: $(printf '%s\n' "$prs" | sed -n 1p)"; prs="" + else + prs=$(printf '%s' "$prs" | jq -r 'group_by(.headRefName) | .[] | max_by(.number) | "\(.headRefName)\t\(.state | ascii_downcase)\t\(.number)"' 2>/dev/null) \ + || { note="PR state not read: gh gave no JSON"; prs=""; } + fi + # Branches a held lane names: " ()" + [ -z "$YT_DIR" ] || [ ! -f "$YT_DIR/LANES.md" ] || held=$(awk -v tab="$TAB" ' + /^\|/ && ++n > 2 { + split($0, c, "|"); for (i = 2; i <= 6; i++) gsub(/^[ \t]+|[ \t]+$/, "", c[i]) + if (c[4] ~ /^(claimed|running|reported|in-review|ready)$/ && c[6] != "-" && c[6] != "") print c[6] tab c[2] " (" c[4] ")" + }' "$YT_DIR/LANES.md") + # info : PR, held lane; sets ok=yes when the branch may go + info() { + local p l + p=$(printf '%s\n' "$prs" | awk -F'\t' -v b="$1" '$1 == b { print "PR #" $3 " " $2; exit }') + l=$(printf '%s\n' "$held" | awk -F'\t' -v b="$1" '$1 == b { print $2; exit }') + ok=no + case "$p" in *" merged"|*" closed") [ -n "$l" ] || ok=yes ;; esac + [ -n "$note" ] && p="PR state not read" || p=${p:-no pull request} + INFO="$p${2:+, last commit $2}${3:+, $3}${l:+, held by lane $l}" + } + while IFS="$TAB" read -r path br lock; do + [ -n "$path" ] || continue + n=$((n + 1)); [ "$n" -gt 1 ] || { used="$used$br "; continue; } # the main worktree + used="$used$br "; extra="" + if [ ! -d "$path" ]; then extra="missing" + else + ct=$(git -C "$path" log -1 --format=%ct HEAD 2>/dev/null) + [ -z "$(git -C "$path" status --porcelain 2>/dev/null | sed -n 1p)" ] || extra="uncommitted changes" + fi + [ -z "$lock" ] || extra="${extra:+$extra, }locked" + info "$br" "${ct:+$(since "$ct")}" "$extra" + wl="$wl$path: ${br:-detached}, $INFO$NL" + if [ "$ok" = yes ] && [ -z "$extra" ]; then + cmds="$cmds git -C $(q "$top") worktree remove $(q "$path")$NL" + [ -z "$br" ] || cmds="$cmds git -C $(q "$top") branch -D $(q "$br")$NL" + fi + done </dev/null | awk -v tab="$TAB" ' + /^worktree / { if (p != "") print p tab b tab l; p = substr($0, 10); b = ""; l = "" } + /^branch refs\/heads\// { b = substr($0, 19) } + /^locked/ { l = "locked" } + END { if (p != "") print p tab b tab l }') +EOF + while IFS="$TAB" read -r br ct; do + [ -n "$br" ] && [ "$br" != "$def" ] || continue + case "$used" in *" $br "*) continue ;; esac + info "$br" "$(since "$ct")" "" + bl="$bl$br: $INFO$NL" + [ "$ok" = no ] || cmds="$cmds git -C $(q "$top") branch -D $(q "$br")$NL" + done </dev/null | sed 's/ [-+][0-9]*$//') +EOF + REPORT="ytstack upkeep --worktrees: $top, read $READ" + section worktrees "$wl" "$note" + section branches "$bl" + printf '%s\n' "$REPORT" + [ -n "$cmds" ] || { echo "commands (not run): 0"; return 0; } + printf 'commands (not run): %s\n%s' "$(printf '%s' "$cmds" | awk 'END { print NR }')" "$cmds" + return 10 +} +[ "$WORKTREES" = no ] || { worktrees; exit $?; } + # ---- review policy (read first, reported last) ------------------------------------- # bin/ytstack-risk came after this script; an installation may not have it. POLICY=""; POLICY_NOTE="" @@ -188,7 +282,9 @@ section questions "$items" # the slices of one milestone, and a lane may be a task or a named piece. items="" if [ -f "$YT_DIR/LANES.md" ]; then - if out=$(tool ytstack-frontier check 2>&1); then + out=$(tool ytstack-frontier check 2>&1); ec=$? + # 2: well-formed, with stale lanes; those lines are items below. + if [ "$ec" -eq 0 ] || [ "$ec" -eq 2 ]; then while IFS="$TAB" read -r lane st by next; do [ -n "$lane" ] || continue a=$(age "${by##* }") @@ -201,6 +297,14 @@ $(awk -v tab="$TAB" ' for (i = 2; i <= 11; i++) { gsub(/^[ \t]+|[ \t]+$/, "", c[i]); if (c[i] == "") c[i] = "-" } if (c[4] ~ /^(claimed|running|reported|in-review|ready)$/) print c[2] tab c[4] tab c[5] tab c[11] }' "$YT_DIR/LANES.md") +EOF + # A stale lane (issue #84) is listed once: not again when it is listed above. + while IFS= read -r l; do + case "$l" in stale:\ *) l=${l#stale: } ;; *) continue ;; esac + case "$NL$items" in *"$NL${l%%: *}: "*) continue ;; esac + items="$items$l$NL" + done <-things-that-need-a-look.md`, with the report in it, and no second one while the first is open or asked. In CI one issue instead. Never a change to the product, never a commit, never a merge. What happens with a finding stays with a person, or with a session a person started. +`ytstack-upkeep --worktrees` is a separate run for the cleanup of a checkout: it lists the linked worktrees and local branches with the state of their newest pull request, their age, uncommitted changes and the lane that holds them, and prints the `git worktree remove` / `git branch -D` commands for the merged or closed, clean ones. It runs none of them; a person or a session a person started does. + +**What a run may leave behind.** By default nothing in the tree; outside it, `ytstack-frontier check` keeps the time it first saw each ready lane (for the `stale:` lines under `lanes`). With `--question` one file, `.ytstack/questions/Q###-upkeep-found--things-that-need-a-look.md`, with the report in it, and no second one while the first is open or asked. In CI one issue instead. Never a change to the product, never a commit, never a merge. What happens with a finding stays with a person, or with a session a person started. ## Plain CI or cron: the default diff --git a/docs/ux/coordinator-format.md b/docs/ux/coordinator-format.md index 89685b60..92cb5477 100644 --- a/docs/ux/coordinator-format.md +++ b/docs/ux/coordinator-format.md @@ -40,6 +40,19 @@ updated: 2026-11-13T10:42:00Z A lane that was never claimed has no row. `bin/ytstack-frontier` is the only writer besides a human: it changes one row per call, takes a lock for the write (the file `LANES.md.lock`, so that claims sent together do not lose a row) and rewrites `updated`. Cells contain no `|`. A held lane is released before it can be claimed again. +### Peers + +The sessions in other repositories that the coordinator works with (a session that deploys, one that owns a shared service) are part of its state, so a compaction does not drop who is who. They stand in a `## Peers` section after the lanes table, one list line each: + +```markdown +## Peers + +- prod deploy | Yesterday-AI/cloud | claude:6f1c2d0e-1b7a-4c55-9a1e-0c3d5e7f9a21 | 2026-11-15T09:12Z +- review bot owner | acme/app | agent b7e2 | 2026-11-15T08:40Z +``` + +The cells are the role, the repository, the address (what the host gives to reach that session) and the UTC time of the last contact. Role and repository together name a peer. `ytstack-frontier peer set --repo --address
[--contact ]` adds the line or replaces it, with the last contact now unless `--contact` gives one; `ytstack-frontier peer list` prints the lines tab separated. A message to another session goes to the address listed here, never to one remembered from the conversation, and `peer set` runs after every contact. The lines are list items, not table rows, so every reader of the lanes table leaves them alone. + ## Blocking edges and the frontier A slice plan names what has to be finished before it can start, directly under its goal: @@ -65,6 +78,19 @@ The list also reads the lanes table: a row with Status `merged` counts as done e A claim is written before the work is dispatched: `ytstack-frontier claim --by `. Claiming a lane that is already held fails and names the holder. That is what keeps a second message to a running lane from starting the same work twice. The coordinator dispatches again whenever the frontier changes, not once per milestone. +### Lanes that stall + +`ytstack-frontier check [--minutes N]` reads a well-formed table for lanes that nobody moves, one line each, and exits 2 when it prints one: + +``` +stale: M004-S02: running, no commit on ytstack/M004-S02 for 95 minutes (since 2026-11-15T08:40Z) +stale: M004-S03: running, but PR 12 is in its row: the worker reported; set the status +stale: M004-S05: running, but its worktree .claude/worktrees/m004-s05 does not exist: the worker ended; read its branch and set the status +stale: M004-S06: ready, nobody claimed it for 70 minutes (first seen 2026-11-15T09:00Z) +``` + +A `running` row is stale when its worker reported (a pull request in its row, or its worktree no longer exists) or when its branch had no commit for N minutes (default 60), counted from the claim when that is newer or the row names no branch. A `ready` lane of the frontier is stale when nobody claimed it for N minutes since a check first saw it ready; that first sight is kept outside the tree (`/repos//frontier-ready`, the base of `yt_state_base`). `bin/ytstack-upkeep` lists these lines under `lanes`. A stale line is a prompt to read the lane's branch and set its row, or to dispatch the ready lane; it never releases a lane by itself. + ### Lesson lanes Every incident ends with a lesson (`docs/ux/signal-format.md`, "Lessons"). A lesson whose target is a check that nobody built yet, `open` or `planned`, is work that may start like a slice. The frontier lists it after the slices of the milestone, also when no milestone is open: @@ -210,6 +236,8 @@ Rotation at 2026-11-15T09:12Z. Lanes, frontier, questions and standing instructi - Running workers: - M004-S02 | impl-M004-S02 | address: agent a3f9c1 | worktree: .claude/worktrees/m004-s02 | branch: ytstack/M004-S02 | dispatched 2026-11-15T08:40Z - review-pr-43 | review-pr-43 | address: codex pid 81234, log /tmp/review-pr-43.log | worktree: .worktrees/review-pr-43 | branch: - | dispatched 2026-11-15T09:01Z +- Peers: + - prod deploy | Yesterday-AI/cloud | claude:6f1c2d0e-1b7a-4c55-9a1e-0c3d5e7f9a21 | 2026-11-15T09:12Z ``` | Line | Holds | @@ -217,12 +245,15 @@ Rotation at 2026-11-15T09:12Z. Lanes, frontier, questions and standing instructi | `PR watch session:` | The old session's id as the PR watch stores it (`claude:`, or the Codex thread id), or `none` when the PR watch is off. The successor runs `ytstack-pr-watch handover --from ` (`docs/pr-watch.md`). | | `Background watches:` | The command of every `ytstack-watch` the old session runs, so that the successor starts them again. `none` when there are none. | | `Running workers:` | One line per dispatched worker that has not reported: lane, name, address, worktree, branch, dispatch time. The address is what the host gave the dispatcher to reach the worker. A worker reports to the session that started it. | +| `Peers:` | The lines of `ytstack-frontier peer list` (`LANES.md`, "Peers"): role, repository, address, last contact. `none` when there are none. The successor writes to these addresses, never to one from a summary. | The old session stays open as a relay until every listed worker has reported. Per report it runs `ytstack-brief check`, sets the row to `reported` and appends the report's labelled lines, with the UTC time, under `## Reports after the rotation` at the end of `HANDOFF.md`. It does nothing else. The successor leaves the rows of the listed workers alone until their reports are there, or until the person says the old session is closed. ## Checked mechanically -- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time. +- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` has four cells and a UTC time; then the lanes that stall ("Lanes that stall", exit 2). +- `bin/ytstack-upkeep --worktrees`: the linked worktrees and local branches with the state of their newest pull request, the age of the last commit, uncommitted changes and the lane that holds them, and the `git worktree remove` / `git branch -D` commands for the merged or closed, clean, unlocked and unheld ones. It prints the commands and runs none. +- `bin/ytstack-status --phases [--json]`: done, in review and total per milestone and in total, with each change of a total since the last report and its cause (`docs/statusline.md`, "Progress per phase"). - `bin/ytstack-questions check`: ids are unique and match the file name, `state` holds a listed value, `asked` and `answered` are set exactly when the state says so, an answered file has text under `## Answer`. - `bin/ytstack-brief check`: the report labels, the three `Status:` values and their consistency with `Blockers:`. - `bin/ytstack-handover check`: the staged script of a human-only step (see `skills/handover-step/SKILL.md`). diff --git a/skills/coordinate/SKILL.md b/skills/coordinate/SKILL.md index df3bf47e..08d55712 100644 --- a/skills/coordinate/SKILL.md +++ b/skills/coordinate/SKILL.md @@ -161,6 +161,13 @@ else fi echo "FRONTIER_END" +# Sessions in other repositories (LANES.md "## Peers"): write only to these addresses, `ytstack-frontier peer set` after each contact. +echo "PEERS_BEGIN" +_PEERS="" +[ -n "$_YT_DIR" ] && [ -f "$_FRONTIER" ] && _PEERS=$(bash "$_FRONTIER" peer list 2>/dev/null) +echo "${_PEERS:-no peers}" +echo "PEERS_END" + echo "QUESTIONS_BEGIN" _QN=0 for _f in "$_YT_DIR"/questions/Q[0-9]*.md; do @@ -263,7 +270,7 @@ An `asked` question is never asked again: name it as waiting since its time. Whe **Step 12 -- Rotate.** When the session has been compacted once (a summary stands where the conversation was, or `HANDOFF_AUTO` is from this session), or its context is large by the host's indicator, rotate now. Do not wait for a quiet moment, for workers to report or for checks to finish: under load there is none, and a second compaction costs more than a rotation. It is one step, done in this order without dispatching anything in between: 1. Bring the rows' next actions up to date, run `ytstack-frontier check` and `ytstack-questions check`, and make sure the standing instructions hold every instruction given so far. -2. Write `$_YT_DIR/HANDOFF.md` yourself in the format of `ytstack:handoff-session` (its Step 7), without its questions: the answers are in the files, and the handoff points at them. Its "In-flight work" carries the "Rotation" block of `docs/ux/coordinator-format.md`: `PR watch session:` with this session's id as the PR watch stores it (`echo "${CODEX_THREAD_ID:-claude:$CLAUDE_CODE_SESSION_ID}"`; `none` when `PR_WATCH` is `off`), `Background watches:` with the command of every `ytstack-watch` that runs in this session, and under `Running workers:` one line per worker that has not reported: lane, name, address (what the host gave you to reach it: the agent's id or name in Claude Code, another host's process id and log file), worktree, branch, dispatch time. Its "Next action": start `ytstack:coordinate` in a fresh session; its Step 3 runs `ytstack-pr-watch handover --from `. +2. Write `$_YT_DIR/HANDOFF.md` yourself in the format of `ytstack:handoff-session` (its Step 7), without its questions: the answers are in the files, and the handoff points at them. Its "In-flight work" carries the "Rotation" block of `docs/ux/coordinator-format.md`: `PR watch session:` with this session's id as the PR watch stores it (`echo "${CODEX_THREAD_ID:-claude:$CLAUDE_CODE_SESSION_ID}"`; `none` when `PR_WATCH` is `off`), `Background watches:` with the command of every `ytstack-watch` that runs in this session, and under `Running workers:` one line per worker that has not reported: lane, name, address (what the host gave you to reach it: the agent's id or name in Claude Code, another host's process id and log file), worktree, branch, dispatch time, and under `Peers:` the lines between `PEERS_BEGIN` and `PEERS_END` (`ytstack-frontier peer list`), so the successor writes to the right session of another repository. Its "Next action": start `ytstack:coordinate` in a fresh session; its Step 3 runs `ytstack-pr-watch handover --from `. 3. Tell the user in one line: start a fresh session with `ytstack:coordinate`, and leave this one open until the workers listed in the handoff have reported (a closed session ends its background workers on most hosts). 4. From then on this session is a relay and nothing else. When one of its workers reports: `ytstack-brief check`, `ytstack-frontier set --status reported --next ""`, and append the report's labelled lines with the UTC time under `## Reports after the rotation` at the end of `HANDOFF.md`. It dispatches nothing, merges nothing, asks nothing and acts on no watch line or PR watch notice; the PR watch delivers to the successor after the handover anyway. When the last listed worker has reported, it says so in one line: the session can be closed. diff --git a/tests/skill-preambles.test.sh b/tests/skill-preambles.test.sh index ee003745..bd5bc24d 100644 --- a/tests/skill-preambles.test.sh +++ b/tests/skill-preambles.test.sh @@ -318,6 +318,16 @@ STANDING_ENTRIES_END" has "$s: bare fixture -> PR watch off" "$OUT" "PR_WATCH: off" has "$s: bare fixture -> no release section" "$OUT" "RELEASE: no" has "$s: bare fixture -> no signal sources" "$OUT" "SIGNALS: 0" + # peers in other repositories (issue #84): from LANES.md "## Peers" + has "$s: no peers" "$OUT" "PEERS_BEGIN +no peers +PEERS_END" + bash "$ROOT/bin/ytstack-frontier" -C "$WT" peer set prod --repo acme/cloud --address claude:abc --contact 2026-11-15T09:00Z >/dev/null 2>&1 + run_pre "$P" "$WT" + has "$s: a peer is listed" "$OUT" "PEERS_BEGIN +prod acme/cloud claude:abc 2026-11-15T09:00Z +PEERS_END" + rm -f "$WT/.ytstack/LANES.md" # the open lessons (M032): counted in the status, a proposal for the daily question, a check for a lane has "$s: bare fixture -> no open lesson" "$OUT" "LESSONS: 0 open (0 proposals, 0 checks to build)" printf 'x\n' | bash "$ROOT/bin/ytstack-signals" -C "$WT" lesson new --area ci --class flaky-order --title "Order" --target check:tests/order.sh >/dev/null diff --git a/tests/ytstack-frontier.test.sh b/tests/ytstack-frontier.test.sh index 863e70fd..5b3d00df 100644 --- a/tests/ytstack-frontier.test.sh +++ b/tests/ytstack-frontier.test.sh @@ -13,7 +13,13 @@ # set changes the named cells of one row, every other row stays # byte-identical, "updated:" is rewritten # release "Claimed by" becomes "-", status "dropped" unless "merged" -# check a well-formed file passes; each defect is named, exit 1 +# check a well-formed file passes; each defect is named, exit 1; with a +# well-formed file, "stale:" lines for running rows whose worker +# reported (PR in the row, worktree gone) or whose branch had no +# commit for --minutes, and for ready lanes nobody claimed for +# --minutes since check first saw them (state outside the tree): exit 2 +# peer set adds or updates one "## Peers" line per role and repository, +# list prints them; the lanes table is untouched # refused a value with "|" or a newline, and usage errors: exit 64 # # Run: /bin/bash tests/ytstack-frontier.test.sh (exit 0 = all pass; macOS bash 3.2) @@ -29,6 +35,8 @@ bad() { FAIL=$((FAIL+1)); echo " FAIL - $1${2:+ ($2)}"; } eq() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "expected '$2' got '$3'"; fi; } has() { case "$3" in *"$2"*) ok "$1" ;; *) bad "$1" "no '$2' in: $3" ;; esac; } hasnt() { case "$3" in *"$2"*) bad "$1" "unexpected '$2' in: $3" ;; *) ok "$1" ;; esac; } +# like : one line of the text matches +like() { if printf '%s\n' "$3" | grep -E -- "$2" >/dev/null; then ok "$1"; else bad "$1" "no line matches /$2/ in: $3"; fi; } if [ ! -x "$BIN" ]; then bad "bin/ytstack-frontier exists and is executable" @@ -39,6 +47,8 @@ fi TMP=$(mktemp -d "${TMPDIR:-/tmp}/ytfrontier.XXXXXX"); TMP=$(cd "$TMP" && pwd -P) trap 'rm -rf "$TMP"' EXIT TAB=' ' +# Out-of-tree state (the first sight of a ready lane) goes here, never to the real one. +export CLAUDE_PLUGIN_DATA="$TMP/data" # run : sets OUT (stdout + stderr) and EC run() { local d="$1"; shift; OUT=$(bash "$BIN" -C "$d" "$@" 2>&1); EC=$?; } @@ -362,8 +372,8 @@ R=$(new_repo check M004); L="$R/.ytstack/LANES.md" run "$R" check eq "no LANES.md: exit 0" 0 "$EC" eq "and says so" "no lanes file" "$OUT" -lanes "$R" -run "$R" check +lanes "$R"; mkdir -p "$R/.claude/worktrees/m004-s02" +run "$R" check --minutes 100000000 eq "the example of the format document: exit 0" 0 "$EC" eq "and says so" "lanes ok" "$OUT" # defect @@ -394,6 +404,94 @@ run "$R" claim M004-S03 --by impl-M004-S03 eq "no write into a table that is not in the format: exit 1" 1 "$EC" has "points at check" "ytstack-frontier check" "$OUT" +# ---- 5b. check: liveness (issue #84) -------------------------------------------- +echo "# liveness" +NOW=$(date -u +%s) +# utc [seconds]: a UTC time that long ago, with or without seconds +utc() { + local e=$((NOW - $1)) f='%Y-%m-%dT%H:%MZ' + [ -z "${2:-}" ] || f='%Y-%m-%dT%H:%M:%SZ' + date -u -r "$e" +"$f" 2>/dev/null || date -u -d "@$e" +"$f" +} +R=$(new_repo live M004); L="$R/.ytstack/LANES.md" +roadmap "$R" M004 in-progress "- S01" "- S02" "- S03" "- S04" "- S05" "- S06" +for s in S01 S02 S03 S04 S05 S06; do plan "$R" "M004-$s" none; done +( cd "$R" && git add -A && GIT_COMMITTER_DATE="$(utc 30000 s)" GIT_AUTHOR_DATE="$(utc 30000 s)" git commit -qm base ) >/dev/null 2>&1 +# S01: silent for two hours; S02: a commit ten minutes ago; S03: a pull request +# in the row; S04: its worktree is gone; S05 is claimed, not running; S06 ready +git -C "$R" branch work/s01; git -C "$R" branch work/s02 +( cd "$R" && git checkout -q work/s01 && GIT_COMMITTER_DATE="$(utc 7200 s)" git commit -q --allow-empty -m one \ + && git checkout -q work/s02 && GIT_COMMITTER_DATE="$(utc 600 s)" git commit -q --allow-empty -m two && git checkout -q main ) >/dev/null 2>&1 +mkdir -p "$R/wt/s01" "$R/wt/s02" "$R/wt/s03" +{ printf -- '---\nupdated: 2026-11-15T10:00:00Z\n---\n\n# Lanes\n\n' + echo '| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |' + echo '|---|---|---|---|---|---|---|---|---|---|' + echo "| M004-S01 | implement | running | w1 $(utc 10800) | work/s01 | wt/s01 | - | - | 0 | wait |" + echo "| M004-S02 | implement | running | w2 $(utc 10800) | work/s02 | wt/s02 | - | - | 0 | wait |" + echo "| M004-S03 | implement | running | w3 $(utc 600) | - | wt/s03 | 12 | - | 0 | wait |" + echo "| M004-S04 | implement | running | w4 $(utc 600) | - | wt/gone | - | - | 0 | wait |" + echo "| M004-S05 | implement | claimed | w5 $(utc 10800) | - | - | - | - | 0 | - |" +} > "$L" +run "$R" check +eq "liveness findings: exit 2" 2 "$EC" +like "silent for two hours: no commit on its branch" "^stale: M004-S01: running, no commit on work/s01 for 1[12][0-9] minutes \(since [0-9T:-]+Z\)\$" "$OUT" +hasnt "a commit ten minutes ago keeps a lane alive" "M004-S02" "$OUT" +has "a pull request in the row: the worker reported" "stale: M004-S03: running, but PR 12 is in its row: the worker reported; set the status" "$OUT" +has "its worktree is gone: the worker ended" "stale: M004-S04: running, but its worktree wt/gone does not exist" "$OUT" +hasnt "a claimed lane is not looked at" "M004-S05" "$OUT" +hasnt "a ready lane seen for the first time is not flagged" "M004-S06" "$OUT" +hasnt "no format problem" "line " "$OUT" +run "$R" check --minutes 180 +hasnt "--minutes moves the limit" "M004-S01" "$OUT" +READY=$(find "$CLAUDE_PLUGIN_DATA" -name frontier-ready -exec grep -l '^M004-S06 ' {} + | head -1) +case "$READY" in "$CLAUDE_PLUGIN_DATA/repos/"*) ok "the first sight of a ready lane is kept outside the tree" ;; *) bad "ready state location" "$READY" ;; esac +eq "one line for the ready lane" "M004-S06" "$(cut -f1 "$READY")" +printf 'M004-S06\t%s\n' "$((NOW - 7200))" > "$READY" +run "$R" check +like "a ready lane nobody claimed for two hours" "^stale: M004-S06: ready, nobody claimed it for 1[12][0-9] minutes \(first seen [0-9T:-]+Z\)\$" "$OUT" +run "$R" claim M004-S06 --by w6 +run "$R" check +hasnt "claimed: no longer flagged" "M004-S06" "$OUT" +eq "and forgotten" "" "$(cut -f1 "$READY")" +git -C "$R" status --porcelain --untracked-files=all > "$TMP/st" +hasnt "check writes nothing into the tree" "frontier-ready" "$(cat "$TMP/st")" +run "$R" check --minutes x; eq "--minutes takes a number: exit 64" 64 "$EC" +sed 's/| running | w1/| working | w1/' "$L" > "$L.x" && mv "$L.x" "$L" +run "$R" check +eq "a format problem: exit 1, liveness not read" "1" "$EC" +hasnt "no stale line then" "stale:" "$OUT" + +# ---- 5c. peers (issue #84) ------------------------------------------------------ +echo "# peers" +R=$(new_repo peers M004); L="$R/.ytstack/LANES.md"; roadmap "$R" M004 in-progress "- S01" "- S02" +run "$R" peer list +eq "no LANES.md: no peers, exit 0" "0 " "$EC $OUT" +run "$R" peer set prod --repo Yesterday-AI/cloud --address claude:6f1c2d0e +eq "peer set without a lanes file: exit 0" 0 "$EC" +has "creates the lanes table" "| Lane | Kind | Status |" "$(cat "$L")" +has "and a Peers section" "## Peers" "$(cat "$L")" +like "one line: role, repository, address, last contact (now)" "^- prod \| Yesterday-AI/cloud \| claude:6f1c2d0e \| [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}Z\$" "$(cat "$L")" +run "$R" claim M004-S01 --by w1 +run "$R" peer set review --repo acme/app --address "agent b7" --contact 2026-11-15T09:00Z +run "$R" peer set prod --repo Yesterday-AI/cloud --address claude:99aa --contact 2026-11-15T09:30Z +eq "list: one line per peer, tab separated, an update in place" "prod${TAB}Yesterday-AI/cloud${TAB}claude:99aa${TAB}2026-11-15T09:30Z +review${TAB}acme/app${TAB}agent b7${TAB}2026-11-15T09:00Z" "$(bash "$BIN" -C "$R" peer list)" +run "$R" peer set prod --repo acme/app --address x --contact 2026-11-15T09:40Z +eq "the same role in another repository is another peer" 3 "$(bash "$BIN" -C "$R" peer list | awk 'END { print NR }')" +run "$R" list +has "the lanes table still reads" "M004-S01${TAB}claimed${TAB}w1" "$OUT" +run "$R" claim M004-S02 --by w2 +eq "a claim after the peers keeps both" "2 3" "$(grep -c '^| M004-' "$L") $(grep -c '^- ' "$L")" +run "$R" check +eq "check passes with peers" "0 lanes ok" "$EC $OUT" +printf '%s\n' '- broken | line' >> "$L" +run "$R" check +has "a peer line without four cells is named" "peer line" "$OUT" +run "$R" peer set prod --repo "a|b" --address x; eq "a | in a peer value: exit 64" 64 "$EC" +run "$R" peer set prod --address x; eq "peer set without --repo: exit 64" 64 "$EC" +run "$R" peer set prod --repo r --address x --contact soon; eq "a contact that is no UTC time: exit 64" 64 "$EC" +run "$R" peer drop prod; eq "an unknown peer command: exit 64" 64 "$EC" + # ---- 6. refused values and usage ---------------------------------------------- echo "# refused" R=$(new_repo refused M004); lanes "$R"; L="$R/.ytstack/LANES.md" diff --git a/tests/ytstack-upkeep.test.sh b/tests/ytstack-upkeep.test.sh index 92b79287..cdbee3e1 100644 --- a/tests/ytstack-upkeep.test.sh +++ b/tests/ytstack-upkeep.test.sh @@ -16,7 +16,12 @@ # --asked-days days ago (default 7); answered ones never # lanes held rows of LANES.md claimed more than --lane-hours hours ago # (default 24), also lanes that are no slice; a table that fails -# `ytstack-frontier check` is reported and not read +# `ytstack-frontier check` is reported and not read; its "stale:" +# lines are items too, once per lane +# --worktrees linked worktrees and local branches with PR state (one +# `gh pr list`), age, uncommitted changes and the lane that holds +# them; the remove commands for merged or closed, clean, unheld +# ones are printed and never run (exit 10), none without PR state # runtime the problems of `ytstack-runtime check` # review policy the problems of `ytstack-risk check` when the script exists # beside ytstack-upkeep, a note when it does not @@ -59,6 +64,8 @@ fi TMP=$(mktemp -d "${TMPDIR:-/tmp}/ytupkeep.XXXXXX"); TMP=$(cd "$TMP" && pwd -P) trap 'rm -rf "$TMP"' EXIT STAMP='[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z' +# ytstack-frontier check keeps out-of-tree state; never in the real data dir +export CLAUDE_PLUGIN_DATA="$TMP/data" NOW=$(date -u +%s) UP="$BIN" @@ -235,7 +242,14 @@ hasnt "a lane claimed an hour ago is not listed" "M004-S03" "$OUT" hasnt "a merged lane is not listed" "M004-S01" "$OUT" hasnt "a blocked lane is not held" "M004-S04" "$OUT" run "$D" --lane-hours 100 -eq "a higher limit: nothing needs a look" "0:0" "$EC:$(count lanes)" +eq "a higher limit: only the stale running lane is left" "10:1" "$EC:$(count lanes)" +like "as ytstack-frontier check names it" "^ - M004-S02: running, no branch in its row|^ - M004-S02: running, no commit on ytstack/M004-S02 for [0-9]+ minutes" "$OUT" +lanes \ + "| M004-S06 | implement | running | impl-e $(claim $((2 * HOUR))) | - | - | 7 | - | 0 | wait |" \ + "| M004-S07 | implement | claimed | impl-f $(claim $((2 * HOUR))) | - | - | - | - | 0 | - |" +run "$D" +eq "a stale lane under the hour limit is listed (issue #84)" "10:1" "$EC:$(count lanes)" +has "with the line of the check" " - M004-S06: running, but PR 7 is in its row: the worker reported; set the status" "$OUT" lanes \ "| M004-S02 | implement | running | impl-b $(claim $((30 * HOUR))) | ytstack/M004-S02 | - | - | - | 0 |" \ "| M004-S03 | implement | sleeping | impl-c $(claim $((30 * HOUR))) | - | - | - | - | 0 | - |" @@ -434,6 +448,53 @@ run "$D" eq "without own reviewers: no host call" "0|0" "$(count "review checks")|$(awk 'END { print NR }' "$GHLOG")" PATH=$OLDPATH +# ---- 10b. --worktrees: the inventory and the commands, never run (issue #84) -------- +echo "# worktrees" +project wtinv +( cd "$D" && git init -q -b main && git config user.email t@t.t && git config user.name t && git config commit.gpgsign false \ + && git add -A && GIT_COMMITTER_DATE="$(ago $((3 * DAY)))" git commit -qm base \ + && for b in one two three four five six; do git branch "feat/$b"; done \ + && git worktree add -q "$D/.wt/one" feat/one && git worktree add -q "$D/.wt/two" feat/two && git worktree add -q "$D/.wt/six" feat/six ) >/dev/null 2>&1 || { echo "FATAL fixture"; exit 2; } +echo dirty > "$D/.wt/two/new.txt" +printf -- '---\nupdated: x\n---\n\n# Lanes\n\n| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n|---|---|---|---|---|---|---|---|---|---|\n| M004-S06 | implement | reported | w %s | feat/six | .wt/six | 9 | - | 0 | review |\n' "$(ago 600)" > "$Y/LANES.md" +cat > "$TMP/fakebin/gh" <<'EOF' +#!/usr/bin/env bash +echo "$*" >> "$GHLOG" +[ -z "${GH_FAIL:-}" ] || { echo "HTTP 502: bad gateway" >&2; exit 1; } +printf '%s' '[{"number":5,"state":"MERGED","headRefName":"feat/one"},{"number":6,"state":"MERGED","headRefName":"feat/two"}, + {"number":3,"state":"OPEN","headRefName":"feat/three"},{"number":7,"state":"CLOSED","headRefName":"feat/three"}, + {"number":8,"state":"OPEN","headRefName":"feat/five"},{"number":9,"state":"MERGED","headRefName":"feat/six"}]' +EOF +chmod +x "$TMP/fakebin/gh"; : > "$GHLOG" +PATH="$TMP/fakebin:$OLDPATH" +BEFORE=$(cd "$D" && git worktree list --porcelain; git branch --list) +run "$D" --worktrees +eq "commands to print: exit 10" 10 "$EC" +like "the first line: the checkout and the time of the read" "^ytstack upkeep --worktrees: $D, read $STAMP\$" "$(printf '%s\n' "$OUT" | sed -n 1p)" +has "worktrees: 3" "worktrees: 3" "$OUT" +like "a worktree with its branch, PR state and age" "^ - $D/\.wt/one: feat/one, PR #5 merged, last commit 3 days ago\$" "$OUT" +like "uncommitted changes are named" "^ - $D/\.wt/two: feat/two, PR #6 merged, last commit 3 days ago, uncommitted changes\$" "$OUT" +like "a branch a lane holds is named" "^ - $D/\.wt/six: feat/six, PR #9 merged, last commit 3 days ago, held by lane M004-S06 \(reported\)\$" "$OUT" +has "branches without a worktree: 3" "branches: 3" "$OUT" +like "the newest PR of a branch counts" "^ - feat/three: PR #7 closed, last commit 3 days ago\$" "$OUT" +like "a branch without a PR" "^ - feat/four: no pull request, last commit 3 days ago\$" "$OUT" +like "an open PR" "^ - feat/five: PR #8 open, last commit 3 days ago\$" "$OUT" +hasnt "the default branch is not listed" " - main" "$OUT" +eq "the commands, not run: merged or closed, clean, not held" "commands (not run): 3 + git -C '$D' worktree remove '$D/.wt/one' + git -C '$D' branch -D 'feat/one' + git -C '$D' branch -D 'feat/three'" "$(printf '%s\n' "$OUT" | sed -n '/^commands (not run)/,$p')" +eq "one gh call" "pr list --state all --limit 500 --json number,state,headRefName" "$(cat "$GHLOG")" +eq "nothing was removed" "$BEFORE" "$(cd "$D" && git worktree list --porcelain; git branch --list)" +GH_FAIL=1 run "$D" --worktrees +eq "gh fails: nothing to remove, exit 0" 0 "$EC" +has "and the reason" "PR state not read: HTTP 502: bad gateway" "$OUT" +hasnt "no command without the PR state" "branch -D" "$OUT" +PATH=$OLDPATH +project wtplain +run "$D" --worktrees +eq "--worktrees outside git: exit 1" 1 "$EC" + # ---- 11. usage and errors --------------------------------------------------------- echo "# usage" project usage From 314130f0ed6e249cbbb5beeca4370cbc000404e0 Mon Sep 17 00:00:00 2001 From: Alex Wegener Date: Sun, 15 Nov 2026 15:58:48 +0100 Subject: [PATCH 3/3] fix: address the PR #90 review (fix rounds, lane kinds, safe cleanup, phase reports) - frontier check: a PR in a running row is a fix round, checked for commits from its first sight; review and prepare lanes get a time-only rule (3 x N); first sights in frontier-seen under a lock with a mktemp file; a table row under ## Peers is named as such - upkeep --worktrees: no command with an open PR or unpushed commits; the current worktree is left out; LANES.md from the main checkout; ct reset - status --phases: only the text report advances snapshot and log (locked, mktemp); joined and left phases named in text and JSON; done and shipped-informally count all slices, backlog left out Co-Authored-By: Claude Opus 5.5 --- .ytstack/DECISIONS.md | 4 ++ .ytstack/spec/checks-and-evals.md | 4 +- .ytstack/spec/hooks-and-state.md | 2 +- CHANGELOG.md | 14 +++-- bin/ytstack-frontier | 78 +++++++++++++++++-------- bin/ytstack-status | 94 ++++++++++++++++++++++--------- bin/ytstack-upkeep | 59 ++++++++++++------- docs/recipes/recurring-upkeep.md | 2 +- docs/statusline.md | 9 +-- docs/ux/coordinator-format.md | 10 ++-- tests/ytstack-frontier.test.sh | 55 ++++++++++++------ tests/ytstack-status.test.sh | 42 ++++++++++++-- tests/ytstack-upkeep.test.sh | 41 ++++++++++---- 13 files changed, 290 insertions(+), 124 deletions(-) diff --git a/.ytstack/DECISIONS.md b/.ytstack/DECISIONS.md index 72107683..71c0a4e0 100644 --- a/.ytstack/DECISIONS.md +++ b/.ytstack/DECISIONS.md @@ -1235,6 +1235,8 @@ Plus: ops-layer split during the same session (yopstack created as own public re **How to apply:** - A status with progress uses `ytstack-status --phases`, never a count by hand (`coordinate` Step 11). - The change shown is the one since the previous `--phases` run; a second run without a change shows none. +- Only the text report advances the snapshot and appends to the log; `--json` shows the same change and writes nothing, so drawing a chart never uses up the delta a status needs. Snapshot and log are written under a noclobber lock with a `mktemp` file (PR #90 review; refines the bullet above: "run" means text report). +- A phase that joins or leaves is named on its own line, in the total and in the JSON (`joined`, `left`), also when the total stays equal. A `done` or `shipped-informally` milestone counts all its slices as done; a `backlog` roadmap is left out like a `dropped` one (PR #90 review). **Supersedes:** None. @@ -1256,5 +1258,7 @@ Plus: ops-layer split during the same session (yopstack created as own public re - A `stale:` line is a prompt to read the branch and set the row, or to dispatch; no script releases a lane by itself. - A message to a session of another repository goes to the address under `## Peers`, and `peer set` runs after each contact. - A new reader of `LANES.md` reads the lanes table only from lines that start with `|`. +- A running row with a pull request is a fix round (`finish-lane`, `spawn-milestone-team`), not a report: it is checked for commits like any implement lane, counted from the first time a check sees that pull request and round in the row; a new round restarts the clock. The only "the worker ended" signal left is a worktree that no longer exists. A `review` or `prepare` lane commits nothing: it is stale after 3 x N minutes since its claim. First sights of ready lanes and fix rounds share `/repos//frontier-seen`, written under a noclobber lock with a `mktemp` file (PR #90 review; replaces "a pull request in its row" as a report signal and the file name `frontier-ready` above). +- `--worktrees` prints no command for a branch with any open pull request, or whose local head is in neither the pull request head nor `origin/` (unpushed commits). It leaves out the worktree it runs in and reads `LANES.md` from the main checkout (PR #90 review). **Supersedes:** None. Extends "2026-11-13: Coordinator mode keeps lanes, questions and standing instructions in files and reads host facts fresh (M024, issue #34)". diff --git a/.ytstack/spec/checks-and-evals.md b/.ytstack/spec/checks-and-evals.md index 79f00455..452bbd34 100644 --- a/.ytstack/spec/checks-and-evals.md +++ b/.ytstack/spec/checks-and-evals.md @@ -79,7 +79,7 @@ Everything that tells a contributor whether a change is acceptable: the static c - `new` records a finding once: a second sighting of the key raises its count, a sighting of a `fixed` one writes a regression with `reopens:`, a `dismissed` one stays dismissed; writes under a noclobber lock. `list`, `set`, `incident new`, `check` (findings and incident records; every mitigation names a handover script that passes `bin/ytstack-handover check` unless declined). - `--kind review` records an escaped review-bot finding (key `review::`) without a "Signals" source; `review-checked` records and asks which merged pull request had its escape check, in `signals/review-checks`; `--tally` adds caught/escaped per role as a fourth field, which `check` validates. `lesson new` records a lesson (`kind: lesson`, key `lesson::`, a `target` of `check`, `knowledge`, `contract` or `proposal`, never `AGENTS.md` or `CLAUDE.md`; a repeat raises the count) and links it into an incident record with `--incident`; `lesson list [--since]` lists them; `check` fails on a closed incident without a recorded lesson and on a `fixed` lesson whose target is a proposal or a missing file. -**`bin/ytstack-upkeep`**: one read-only run over `.ytstack/` with eight counted sections (spec, state, gates, questions, lanes, runtime, review policy, review checks) and a ninth, `factory tools`, that lists the lines of `yt_factory_notices` (a factory tool that is off although the project would use it, `hooks-and-state`) and is never counted; exit 0 with `nothing needs a look`, 10 otherwise. `review checks` lists, only when `REVIEW.md` declares own reviewers, the merged pull requests without a line in `signals/review-checks` (an anchored window from 14 days before the earliest time in that file, or 14 days ago without one, at most 90 days back; cut at 500 with a notice), from one `gh pr list --search merged:>=` (one call per 100) (plus one `gh repo view` when `origin` is not a GitHub URL); a failed read is an item, a missing `gh` or `jq` a note. `--question` writes one question file and none while an earlier `Upkeep found ...` is open or asked. `lanes` also lists the `stale:` lines of `ytstack-frontier check`, once per lane. `--worktrees` prints instead the linked worktrees and local branches with the state of their newest pull request (one `gh pr list --state all`), the age of the last commit, uncommitted changes, a lock and the held lane that names the branch, then the `git worktree remove` / `git branch -D` commands for the merged or closed, clean, unlocked and unheld ones, never run; none without the PR state; exit 10 with a command. `docs/recipes/recurring-upkeep.md` puts it on a schedule. +**`bin/ytstack-upkeep`**: one read-only run over `.ytstack/` with eight counted sections (spec, state, gates, questions, lanes, runtime, review policy, review checks) and a ninth, `factory tools`, that lists the lines of `yt_factory_notices` (a factory tool that is off although the project would use it, `hooks-and-state`) and is never counted; exit 0 with `nothing needs a look`, 10 otherwise. `review checks` lists, only when `REVIEW.md` declares own reviewers, the merged pull requests without a line in `signals/review-checks` (an anchored window from 14 days before the earliest time in that file, or 14 days ago without one, at most 90 days back; cut at 500 with a notice), from one `gh pr list --search merged:>=` (one call per 100) (plus one `gh repo view` when `origin` is not a GitHub URL); a failed read is an item, a missing `gh` or `jq` a note. `--question` writes one question file and none while an earlier `Upkeep found ...` is open or asked. `lanes` also lists the `stale:` lines of `ytstack-frontier check`, once per lane. `--worktrees` prints instead the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest; one `gh pr list --state all`), the age of the last commit, uncommitted changes, unpushed commits (the local head in neither the PR head nor `origin/`), a lock and the held lane of the main checkout's `LANES.md` that names the branch, then the `git worktree remove` / `git branch -D` commands for the merged or closed ones with none of those, never run; none without the PR state; exit 10 with a command. `docs/recipes/recurring-upkeep.md` puts it on a schedule. **`bin/ytstack-upstream`** (`docs/ux/upstream-feedback.md`): `mode` prints the effective `upstream_feedback` through `yt_upstream_feedback`, the repository and the path of the rules, and asks `gh auth status` only for `file` (without a login: `mode: suggest` and a note); `draft` writes an issue body with `TODO:` lines, the ytstack version, host and OS under `$TMPDIR` (never inside a git checkout) and never calls `gh`; `check` exits 1 on a `TODO:` left, an empty "Evidence", no filled `Searched:` line, an email address (not `noreply`), a token-looking string (the rule of `bin/ytstack-handover`) or a home directory path. It never posts; the agent does, after `check`. @@ -91,7 +91,7 @@ Everything that tells a contributor whether a change is acceptable: the static c **The coordinator scripts** (formats and rules: `docs/ux/coordinator-format.md`; each has a suite of the same name under `tests/`) -- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder; `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row with a pull request in it, with a worktree that no longer exists, or whose branch had no commit for `--minutes` (default 60, from the claim when that is newer), and a `ready` lane nobody claimed for `--minutes` since a check first saw it (kept in `/repos//frontier-ready`, outside the tree); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). +- `bin/ytstack-frontier`: `list` prints lane, state and detail per slice (done, claimed, blocked, ready) of the current milestone (with `none`: the highest roadmap not `done`, `dropped`, `shipped-informally` or `backlog`), then one lesson lane `lesson-F###` per open or planned lesson whose target is a check (blocked without non-empty "Files" and "Verification" in the lesson; listed also without a milestone); `claim` refuses a held lane and names the holder; `claim`, `set` and `release` change one row of `LANES.md` under a lock; `check` validates the file and then prints one `stale:` line per lane that stalls, exit 2 (issue #84): a `running` row whose worktree no longer exists, an `implement` row whose branch had no commit for `--minutes` (default 60, from the claim when that is newer, or from the first sight of its fix round when the row carries a pull request), a `review` or `prepare` row running 3 x `--minutes` since its claim, and a `ready` lane nobody claimed for `--minutes` since a check first saw it (first sights in `/repos//frontier-seen`, outside the tree, under a noclobber lock); `peer set` and `peer list` keep the `## Peers` lines of `LANES.md` (role, repository, address, last contact), list items that no table reader sees. The lock is the file `LANES.md.lock`, created by the shell under noclobber and not by `mkdir`, which is no lock on Ubuntu 26.04 (see `.ytstack/KNOWLEDGE.md`). - `bin/ytstack-plans` (`docs/ux/external-plans.md`): `scan` counts the work rows (task-list items, rows of tables with a status or checkbox column, nothing in a code fence) of `plans/`, `roadmap/` and their variants and prints one line per directory with `verdict=large` from 10 open rows and the answer recorded in `PREFERENCES.md`; exit 0 only for a large directory without an answer. `rows` prints `path:line`, state, id, section and title per row; a relative PATH is read from where the command was started, else from the repository root, and the output names files relative to the root. It writes nothing; the mapping is the agent's (`reconcile`, `adopt-brownfield`). - `bin/ytstack-questions`: `new`, `list`, `next`, `ask` (once), `answer` (refused without text under "Answer"), `check`. - `bin/ytstack-finish-lane`: one step per call (`leftovers`, `commit`, `push`, `open-pr`, `wait-head`, `body-check`, `gates`, `merge`, `route`); every gate is read from GitHub through `gh` at the moment of the call, and `merge` passes the reviewed commit to the host so that a moved head cannot be merged. `route --lane [--pr ]` reads the lane's worker (the author) and plan from `LANES.md` and runs `bin/ytstack-risk route`; with `--pr` it passes the pull request on, and a lane without a plan file is routed from the host's reviews. `leftovers` and `commit` leave the evidence directory out. Its suite uses a stand-in for `gh` and a local bare remote. diff --git a/.ytstack/spec/hooks-and-state.md b/.ytstack/spec/hooks-and-state.md index dfbb5080..07914208 100644 --- a/.ytstack/spec/hooks-and-state.md +++ b/.ytstack/spec/hooks-and-state.md @@ -103,7 +103,7 @@ Kimi's native `sessionStart.skill` supplies the static directive. `bin/ytstack-k See `docs/statusline.md`. It was read against `bin/ytstack-status` at `verified_at` and matches. -`ytstack-status --phases [--json]` (issue #81) prints done, in review and total per milestone roadmap that is not dropped, and the total, from the checkout's files. It keeps the slice ids of the last run and a log of every change of a total with its cause under `/repos//phases/` (`snapshot`, `denominator.log`), outside the tree; a run that cannot create that directory prints `log none` and writes nothing. +`ytstack-status --phases [--json]` (issue #81) prints done, in review and total per milestone roadmap that is not dropped or backlog (a done or shipped-informally one counts all its slices), the phases that joined or left, and the total, from the checkout's files. A text report keeps the slice ids and a log of every change with its cause under `/repos//phases/` (`snapshot`, `denominator.log`), outside the tree, under a noclobber lock with a `mktemp` file; `--json` reads them and writes nothing; a run that cannot create that directory prints `log none` and writes nothing. ## Interfaces and contracts diff --git a/CHANGELOG.md b/CHANGELOG.md index 9434b669..aeaef0c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,13 +13,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 prints done, in review and total per milestone and in total. When a total changed since the last report, the line says by how much and why (slices added or removed), and every change goes to a log outside the repository, - so a grown total no longer reads as negative progress. `coordinate` Step 11 - points at it; the JSON is what a chart is drawn from. + so a grown total no longer reads as negative progress. Phases that join or + leave are named, a done milestone counts all its slices, a backlog one is + left out. `coordinate` Step 11 points at it; the JSON is what a chart is + drawn from, and it does not use up the change: only the text report does. - **Lanes that stall are named** (issue #84): `ytstack-frontier check` - prints a `stale:` line (exit 2) for a running lane whose worker reported - (a pull request in its row, its worktree gone) or whose branch had no - commit for 60 minutes (`--minutes`), and for a ready lane nobody claimed - for that long. `ytstack-upkeep` lists them under `lanes`. + prints a `stale:` line (exit 2) for a running lane whose worktree is gone + or whose branch had no commit for 60 minutes (`--minutes`; a fix round + counts from its start), a review or prepare lane running three times as + long without a report, and a ready lane nobody claimed for 60 minutes. `ytstack-upkeep` lists them under `lanes`. - **Worktree cleanup** (issue #84): `ytstack-upkeep --worktrees` lists the worktrees and branches with their pull request state, age and uncommitted changes, and prints the `git worktree remove` / `git branch -D` commands diff --git a/bin/ytstack-frontier b/bin/ytstack-frontier index 1d18cd50..39954fe3 100755 --- a/bin/ytstack-frontier +++ b/bin/ytstack-frontier @@ -36,13 +36,16 @@ # values, a claim time on every held lane, and four cells in every # line under "## Peers". A well-formed file is then read for lanes # that stall (issue #84), one "stale: : ..." line each: -# a running row whose worker reported (a PR in its row, or its -# worktree no longer exists), or whose branch had no commit for -# --minutes (default 60; counted from the claim when that is newer, -# or when the row has no branch); +# a running row whose worktree no longer exists (the worker ended); +# an implement row whose branch had no commit for --minutes +# (default 60), counted from the claim when that is newer, or from +# the start of its fix round when the row carries a PR (the round +# starts when a check first sees the PR and round in the row); +# a review or prepare row (they commit nothing) running for 3 x +# --minutes since its claim; # a ready lane of `list` that nobody claimed for --minutes since a -# check first saw it ready. That first sight is kept outside the -# tree: /repos//frontier-ready (yt_state_base). +# check first saw it ready. First sights are kept outside the +# tree, under a lock: /repos//frontier-seen. # peer the sessions in other repositories this coordinator works with, # one line each under "## Peers" in LANES.md: # - | |
| @@ -452,6 +455,7 @@ cmd_check() { p("line " NR ": peer line is not \"- | |
| \"") next } + peers && /^\|/ { p("line " NR ": under ## Peers a peer is a list line \"- | |
| \", not a table row"); next } !/^\|/ { next } ++n == 1 { h = $0; gsub(/[ \t]*\|[ \t]*/, "|", h) @@ -482,21 +486,52 @@ cmd_check() { } # stale : one "stale:" line per lane that stalls (see the header). +# First sights live in /repos//frontier-seen, one +# "\t" line each: "ready:" and "fix::". +REVIEW_FACTOR=3 # a review or prepare lane commits nothing: it gets 3 x N stale() { - local lim=$(($1 * 60)) now top lane st by br wt pr t since c f ready seen keep="" + local lim=$(($1 * 60)) now top lane kind st by br wt pr rnd t since c f tmp ready keep="" n=0 now=$(date -u +%s) top=${YT_MAIN_TOPLEVEL:-$YT_TOPLEVEL} - while IFS=' ' read -r lane _ st by br wt pr _; do - [ "$st" = running ] || continue - if [ "$pr" != - ]; then - echo "stale: $lane: running, but PR $pr is in its row: the worker reported; set the status"; continue + f="$(yt_state_base)/repos/${YT_REPO_KEY:-unknown}/frontier-seen" + ready=$(cmd_list --ready 2>/dev/null) || ready="" + # One check at a time reads and rewrites the file (noclobber, not mkdir: + # .ytstack/KNOWLEDGE.md); without the directory or the lock no first sight + # is kept, and every lane counts from now. + SEEN=""; tmp=""; locked=no + if mkdir -p "${f%/*}" 2>/dev/null; then + until ( set -o noclobber; : > "$f.lock" ) 2>/dev/null; do + n=$((n + 1)); [ "$n" -le 50 ] || break + sleep 0.1 2>/dev/null || sleep 1 + done + if [ "$n" -le 50 ]; then + locked=yes; SEEN_LOCK="$f.lock" + trap 'rm -f "$SEEN_LOCK"' EXIT + SEEN=$(cat "$f" 2>/dev/null) + tmp=$(mktemp "$f.XXXXXX" 2>/dev/null) || tmp="" fi - case "$wt" in /*) f=$wt ;; *) f="$top/$wt" ;; esac - if [ "$wt" != - ] && [ ! -d "$f" ]; then + fi + # seen : SEEN_AT, the first sight of key; kept for the next file + seen() { + SEEN_AT=$(printf '%s\n' "$SEEN" | awk -F'\t' -v k="$1" '$1 == k { print $2; exit }') + case "$SEEN_AT" in ''|*[!0-9]*) SEEN_AT=$now ;; esac + keep="$keep$1 $SEEN_AT$NL" + } + while IFS=' ' read -r lane kind st by br wt pr _ rnd _; do + [ "$st" = running ] || continue + case "$wt" in /*) c=$wt ;; *) c="$top/$wt" ;; esac + if [ "$wt" != - ] && [ ! -d "$c" ]; then echo "stale: $lane: running, but its worktree $wt does not exist: the worker ended; read its branch and set the status"; continue fi t=${by##* }; case "$t" in *T[0-9][0-9]:[0-9][0-9]Z) t="${t%Z}:00Z" ;; esac since=$(yt_epoch "$t"); [ -n "$since" ] || continue + if [ "$kind" != implement ]; then + [ $((now - since)) -gt $((lim * REVIEW_FACTOR)) ] \ + && echo "stale: $lane: running $kind lane, no report for $(((now - since) / 60)) minutes (claimed $(utc "$since"))" + continue + fi + # A PR in the row: a fix round. It starts when a check first sees it. + if [ "$pr" != - ]; then seen "fix:$lane:$rnd"; [ "$SEEN_AT" -le "$since" ] || since=$SEEN_AT; fi c="" [ "$br" = - ] || [ "$YT_IS_GIT" != yes ] || c=$(git -C "$YT_TOPLEVEL" log -1 --format=%ct "$br" -- 2>/dev/null) [ -z "$c" ] || [ "$c" -le "$since" ] || since=$c @@ -506,18 +541,15 @@ stale() { done </dev/null) || ready="" - f="$(yt_state_base)/repos/${YT_REPO_KEY:-unknown}/frontier-ready" - [ -n "$ready" ] || [ -f "$f" ] || return 0 - mkdir -p "${f%/*}" 2>/dev/null || return 0 for lane in $ready; do - seen=$(awk -F'\t' -v l="$lane" '$1 == l { print $2; exit }' "$f" 2>/dev/null) - case "$seen" in ''|*[!0-9]*) seen=$now ;; esac - keep="$keep$lane $seen$NL" - [ $((now - seen)) -le "$lim" ] || echo "stale: $lane: ready, nobody claimed it for $(((now - seen) / 60)) minutes (first seen $(utc "$seen"))" + seen "ready:$lane"; c=$SEEN_AT + [ $((now - c)) -le "$lim" ] || echo "stale: $lane: ready, nobody claimed it for $(((now - c) / 60)) minutes (first seen $(utc "$c"))" done - printf '%s' "$keep" > "$f.tmp" 2>/dev/null && mv "$f.tmp" "$f" + if [ -n "$tmp" ]; then + { printf '%s' "$keep" > "$tmp" && mv "$tmp" "$f"; } 2>/dev/null || rm -f "$tmp" + tmp="" + fi + [ "$locked" = no ] || rm -f "$f.lock" } # ---- peers ----------------------------------------------------------------------- diff --git a/bin/ytstack-status b/bin/ytstack-status index f4601214..24f85311 100755 --- a/bin/ytstack-status +++ b/bin/ytstack-status @@ -24,15 +24,20 @@ # # Progress per phase for a status report or a chart, from the files of the # checkout of DIR (default: $PWD; no stdin): one line per milestone roadmap -# that is not dropped, " / done (%) in review", tab -# separated, then "total" and "read , log ". Rows are the roadmap's -# slices; done is a checked slice or a merged LANES.md row, in review a row -# in reported, in-review or ready. A total that changed since the last -# --phases run says by how much and why (slices added, removed); every such -# change is appended to a log outside the tree, +# that is not dropped or backlog, " / done (%) in +# review", tab separated, then one line per phase that left the report, +# "total" and "read , log ". Rows are the roadmap's slices; done +# is a checked slice or a merged LANES.md row (every slice of a done or +# shipped-informally milestone), in review a row in reported, in-review or +# ready. A phase whose slices changed since the last text report says by how +# much and why (slices added, removed), a new phase says so, and the total +# names both and the phases that joined or left, also when it stays equal. +# Every change is appended to a log outside the tree, # /repos//phases/denominator.log (yt_state_base), so a -# grown denominator is never read as lost progress. --json prints the same as -# one object. Exit 0; 1 no .ytstack or no roadmap; 64 usage. +# grown denominator is never read as lost progress. Only the text report +# advances the snapshot and the log, under a lock; --json prints the same +# change as one object and writes nothing, so a chart never uses it up. +# Exit 0; 1 no .ytstack or no roadmap; 64 usage. set -uo pipefail @@ -40,7 +45,7 @@ set -uo pipefail # ---- --phases ------------------------------------------------------------------ phases() { - local dir="$PWD" json="" f m st rows ph now snap log + local dir="$PWD" json="" f m st rows ph now snap log tmp n while [ $# -gt 0 ]; do case "$1" in --json) json=1; shift ;; @@ -54,7 +59,8 @@ phases() { rows=$(yt_find_artifacts "$YT_DIR" 'M[0-9][0-9][0-9]-ROADMAP.md' | sort | while IFS= read -r f; do m=$(basename "$f" -ROADMAP.md) st=$(sed -n 's/^status:[ ]*\([A-Za-z-]*\).*/\1/p' "$f" | head -1) - [ "$st" != dropped ] || continue + # (no `case` here: bash 3.2 misparses its ")" inside $( )) + [ "$st" != dropped ] && [ "$st" != backlog ] || continue awk -v m="$m" -v st="${st:--}" -v lanes="$YT_DIR/LANES.md" ' BEGIN { # the first table of LANES.md: lane -> status @@ -68,17 +74,33 @@ phases() { if (substr($0, 4, 1) != " " || s == "merged") d++ else if (s == "reported" || s == "in-review" || s == "ready") r++ } - END { printf "%s\t%s\t%d\t%d\t%d\t%s\n", m, st, d, r, t, ids } + # A closed milestone counts all its slices as done, ticked or not. + END { if (st == "done" || st == "shipped-informally") { d = t; r = 0 }; printf "%s\t%s\t%d\t%d\t%d\t%s\n", m, st, d, r, t, ids } ' "$f" done) [ -n "$rows" ] || { echo "ytstack-status: no milestone roadmap in $YT_DIR" >&2; return 1; } - # The last report's slice ids per phase, and the log, outside the tree. + # The last text report's slice ids per phase, and the log, outside the tree. + # Only a text report advances them, under a lock (noclobber, not mkdir: + # .ytstack/KNOWLEDGE.md); --json reads them and changes nothing. ph="$(yt_state_base)/repos/${YT_REPO_KEY:-unknown}/phases" - snap="$ph/snapshot"; log="$ph/denominator.log" + snap="$ph/snapshot"; log="$ph/denominator.log"; tmp="" now=$(date -u +%Y-%m-%dT%H:%MZ) - mkdir -p "$ph" 2>/dev/null || { log="none (cannot write $ph)"; snap=/dev/null; } - printf '%s\n' "$rows" | awk -F'\t' -v now="$now" -v json="$json" -v snap="$snap" -v logf="$log" ' + if [ -n "$json" ]; then + [ -d "$ph" ] || log="none (no text report yet)" + elif mkdir -p "$ph" 2>/dev/null; then + n=0 + until ( set -o noclobber; : > "$ph/lock" ) 2>/dev/null; do + n=$((n + 1)); [ "$n" -le 50 ] || { echo "ytstack-status: $ph/lock exists: another report is writing. Remove the file if none is." >&2; return 1; } + sleep 0.1 2>/dev/null || sleep 1 + done + PH_LOCK="$ph/lock"; trap 'rm -f "$PH_LOCK" ${PH_TMP:+"$PH_TMP"}' EXIT + tmp=$(mktemp "$snap.XXXXXX") || return 1 + PH_TMP=$tmp + else + log="none (cannot write $ph)" + fi + printf '%s\n' "$rows" | awk -F'\t' -v now="$now" -v json="$json" -v snap="$snap" -v logf="$log" -v tmp="$tmp" ' BEGIN { while ((getline x < snap) > 0) { split(x, a, "\t"); old[a[1]] = a[2]; had[a[1]] = 1; oldn[a[1]] = (a[2] == "" ? 0 : split(a[2], y, " ")); any = 1 @@ -103,7 +125,11 @@ phases() { { m = $1; n++; P[n] = m; S[m] = $2; D[m] = $3; R[m] = $4; T[m] = $5; I[m] = $6 td += $3; tr += $4; tt += $5; cur[m] = 1 - if (!(m in had)) { L = L now "\t" m "\t-\t" $5 "\t" (any ? "new phase" : "first report") "\n"; next } + if (!(m in had)) { + L = L now "\t" m "\t-\t" $5 "\t" (any ? "new phase" : "first report") "\n" + if (any) { J[m] = 1; joined = joined (joined == "" ? "" : " ") m } + next + } tb += oldn[m] if (old[m] != $6) { diff(old[m], $6); c = cause() @@ -111,33 +137,49 @@ phases() { } } END { - for (m in had) if (!(m in cur)) { L = L now "\t" m "\t" oldn[m] "\t-\tphase left the report\n"; tb += oldn[m]; gone = 1 } - tchg = any && (tb != tt) - if (snap != "/dev/null") { + # phases that left, in phase order + nl = 0 + for (m in had) if (!(m in cur)) { G[++nl] = m } + for (i = 1; i <= nl; i++) for (k = i + 1; k <= nl; k++) if (G[k] < G[i]) { x = G[i]; G[i] = G[k]; G[k] = x } + for (i = 1; i <= nl; i++) { m = G[i]; L = L now "\t" m "\t" oldn[m] "\t-\tphase left the report\n"; tb += oldn[m]; left = left (left == "" ? "" : " ") m } + tchg = any && (tb != tt || joined != "" || left != "") + if (tmp != "") { printf "%s", L >> logf - for (i = 1; i <= n; i++) printf "%s\t%s\n", P[i], I[P[i]] > (snap ".tmp") - close(snap ".tmp") + for (i = 1; i <= n; i++) printf "%s\t%s\n", P[i], I[P[i]] > tmp + close(tmp) } if (json) { printf "{\"read\":\"%s\",\"log\":\"%s\",\"phases\":[", now, esc(logf) for (i = 1; i <= n; i++) { m = P[i] printf "%s{\"phase\":\"%s\",\"status\":\"%s\",\"done\":%d,\"in_review\":%d,\"total\":%d,\"percent\":%d,\"change\":", (i > 1 ? "," : ""), m, S[m], D[m], R[m], T[m], pct(D[m], T[m]) - if (m in C) { diff(old[m], I[m]); printf "{\"before\":%d,\"added\":%s,\"removed\":%s}}", B[m], jlist(ADD), jlist(DEL) } + if (m in J) printf "{\"before\":0,\"added\":%s,\"removed\":[],\"joined\":true}}", jlist(I[m]) + else if (m in C) { diff(old[m], I[m]); printf "{\"before\":%d,\"added\":%s,\"removed\":%s,\"joined\":false}}", B[m], jlist(ADD), jlist(DEL) } else printf "null}" } - printf "],\"total\":{\"done\":%d,\"in_review\":%d,\"total\":%d,\"percent\":%d,\"change\":%s}}\n", td, tr, tt, pct(td, tt), (tchg ? "{\"before\":" tb "}" : "null") + printf "],\"left\":[" + for (i = 1; i <= nl; i++) printf "%s{\"phase\":\"%s\",\"before\":%d}", (i > 1 ? "," : ""), G[i], oldn[G[i]] + printf "],\"total\":{\"done\":%d,\"in_review\":%d,\"total\":%d,\"percent\":%d,\"change\":", td, tr, tt, pct(td, tt) + if (tchg) printf "{\"before\":%d,\"joined\":%s,\"left\":%s}}}\n", tb, jlist(joined), jlist(left) + else printf "null}}\n" exit } for (i = 1; i <= n; i++) { m = P[i] - printf "%s\t%d/%d done (%d%%)\t%d in review%s\n", m, D[m], T[m], pct(D[m], T[m]), R[m], (m in C ? "\ttotal " B[m] " -> " T[m] " since the last report: " C[m] : "") + printf "%s\t%d/%d done (%d%%)\t%d in review%s\n", m, D[m], T[m], pct(D[m], T[m]), R[m], (m in J ? "\tnew since the last report" : (m in C ? "\ttotal " B[m] " -> " T[m] " since the last report: " C[m] : "")) + } + for (i = 1; i <= nl; i++) printf "%s\tleft the report since the last report (was %d rows)\n", G[i], oldn[G[i]] + s = "" + if (tchg) { + s = "\ttotal " tb " -> " tt " since the last report" + if (joined != "") { x = joined; gsub(/ /, ", ", x); s = s "; joined " x } + if (left != "") { x = left; gsub(/ /, ", ", x); s = s "; left " x } } - printf "total\t%d/%d done (%d%%)\t%d in review%s\n", td, tt, pct(td, tt), tr, (tchg ? "\ttotal " tb " -> " tt " since the last report" : "") + printf "total\t%d/%d done (%d%%)\t%d in review%s\n", td, tt, pct(td, tt), tr, s printf "read %s, log %s\n", now, logf } ' || return 1 - [ ! -f "$snap.tmp" ] || mv "$snap.tmp" "$snap" + if [ -n "$tmp" ]; then mv "$tmp" "$snap" || return 1; PH_TMP=""; rm -f "$PH_LOCK"; fi } if [ "${1:-}" = --phases ]; then shift; phases "$@"; exit $?; fi diff --git a/bin/ytstack-upkeep b/bin/ytstack-upkeep index 16ec3458..509f8d22 100755 --- a/bin/ytstack-upkeep +++ b/bin/ytstack-upkeep @@ -39,12 +39,14 @@ # # --worktrees prints, instead of the report, the linked worktrees and the # local branches without one (not the default branch) of DIR's repository -# (issue #84): branch, pull request state (the newest pull request of the -# branch, from one `gh pr list --state all`), age of the last commit, -# uncommitted changes, and the lane of LANES.md that holds the branch. Then -# "commands (not run): N" and the `git worktree remove` / `git branch -D` -# commands for every one whose pull request is merged or closed, that has no -# uncommitted changes, is not locked and no held lane names. It runs none of +# (issue #84), leaving out the main worktree and the one DIR is in: branch, +# pull request state (an open pull request of the branch if there is one, +# else the newest, from one `gh pr list --state all`), age of the last +# commit, uncommitted changes, unpushed commits (the local head is in +# neither the PR head nor origin/), and the lane of the main +# checkout's LANES.md that holds the branch. Then "commands (not run): N" and +# the `git worktree remove` / `git branch -D` commands for every one whose +# pull request is merged or closed, with none of the above. It runs none of # them. Without the PR state (no gh or jq, a failed read) it prints none. # Exit 10 when it printed a command, 0 otherwise, 1 outside a git repository. # @@ -140,39 +142,56 @@ since() { if [ "$s" -lt $((2 * 86400)) ]; then echo "$((s / 3600)) hours ago"; else echo "$((s / 86400)) days ago"; fi } worktrees() { - local top=${YT_MAIN_TOPLEVEL:-$YT_TOPLEVEL} def prs="" note="" held="" path br lock wl="" bl="" cmds="" n=0 used=" " ct extra + local top=${YT_MAIN_TOPLEVEL:-$YT_TOPLEVEL} def prs="" note="" held="" path br lock wl="" bl="" cmds="" n=0 used=" " ct extra lanes [ "$YT_IS_GIT" = yes ] || die "$DIR is not a git repository" def=$(git -C "$top" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null); def=${def#origin/} [ -n "$def" ] || def=$(git -C "$top" symbolic-ref --quiet --short HEAD 2>/dev/null) - # The newest pull request per head branch: " " + # One pull request per head branch: an open one if there is any, else the + # newest. " " if ! command -v gh >/dev/null 2>&1 || ! command -v jq >/dev/null 2>&1; then note="PR state not read: gh or jq is not available" - elif ! prs=$(cd "$top" && gh pr list --state all --limit 500 --json number,state,headRefName 2>&1); then + elif ! prs=$(cd "$top" && gh pr list --state all --limit 500 --json number,state,headRefName,headRefOid 2>&1); then note="PR state not read: $(printf '%s\n' "$prs" | sed -n 1p)"; prs="" else - prs=$(printf '%s' "$prs" | jq -r 'group_by(.headRefName) | .[] | max_by(.number) | "\(.headRefName)\t\(.state | ascii_downcase)\t\(.number)"' 2>/dev/null) \ + prs=$(printf '%s' "$prs" | jq -r 'group_by(.headRefName) | .[] + | ((map(select(.state == "OPEN")) | max_by(.number)) // max_by(.number)) + | "\(.headRefName)\t\(.state | ascii_downcase)\t\(.number)\t\(.headRefOid // "")"' 2>/dev/null) \ || { note="PR state not read: gh gave no JSON"; prs=""; } fi - # Branches a held lane names: " ()" - [ -z "$YT_DIR" ] || [ ! -f "$YT_DIR/LANES.md" ] || held=$(awk -v tab="$TAB" ' + # Branches a held lane names: " ()", from the + # LANES.md of the main checkout (a linked worktree carries a stale copy). + lanes="$top/.ytstack/LANES.md"; [ -f "$lanes" ] || lanes="$YT_DIR/LANES.md" + [ ! -f "$lanes" ] || held=$(awk -v tab="$TAB" ' /^\|/ && ++n > 2 { split($0, c, "|"); for (i = 2; i <= 6; i++) gsub(/^[ \t]+|[ \t]+$/, "", c[i]) if (c[4] ~ /^(claimed|running|reported|in-review|ready)$/ && c[6] != "-" && c[6] != "") print c[6] tab c[2] " (" c[4] ")" - }' "$YT_DIR/LANES.md") - # info : PR, held lane; sets ok=yes when the branch may go + }' "$lanes") + # info : INFO, and ok=yes when the branch may go: its + # pull request is merged or closed, none is open, no lane holds it, and its + # local head is contained in the PR head or in origin/. info() { - local p l - p=$(printf '%s\n' "$prs" | awk -F'\t' -v b="$1" '$1 == b { print "PR #" $3 " " $2; exit }') + local p l sha oid x="$3" + p=$(printf '%s\n' "$prs" | awk -F'\t' -v b="$1" '$1 == b { print "PR #" $3 " " $2 "\t" $4; exit }') + oid=${p#*"$TAB"}; p=${p%%"$TAB"*} l=$(printf '%s\n' "$held" | awk -F'\t' -v b="$1" '$1 == b { print $2; exit }') ok=no - case "$p" in *" merged"|*" closed") [ -n "$l" ] || ok=yes ;; esac + case "$p" in *" merged"|*" closed") + sha=$(git -C "$top" rev-parse --verify --quiet "refs/heads/$1" 2>/dev/null) + if [ -n "$sha" ] && { { [ -n "$oid" ] && git -C "$top" merge-base --is-ancestor "$sha" "$oid" 2>/dev/null; } \ + || git -C "$top" merge-base --is-ancestor "$sha" "refs/remotes/origin/$1" 2>/dev/null; }; then + [ -n "$l" ] || ok=yes + else + x="${x:+$x, }unpushed commits" + fi ;; + esac [ -n "$note" ] && p="PR state not read" || p=${p:-no pull request} - INFO="$p${2:+, last commit $2}${3:+, $3}${l:+, held by lane $l}" + INFO="$p${2:+, last commit $2}${x:+, $x}${l:+, held by lane $l}" } while IFS="$TAB" read -r path br lock; do [ -n "$path" ] || continue - n=$((n + 1)); [ "$n" -gt 1 ] || { used="$used$br "; continue; } # the main worktree - used="$used$br "; extra="" + n=$((n + 1)); used="$used$br "; extra=""; ct="" + # the main worktree and the one this runs in are not offered + [ "$n" -gt 1 ] && [ "$(yt_canon "$path")" != "$YT_TOPLEVEL" ] || continue if [ ! -d "$path" ]; then extra="missing" else ct=$(git -C "$path" log -1 --format=%ct HEAD 2>/dev/null) diff --git a/docs/recipes/recurring-upkeep.md b/docs/recipes/recurring-upkeep.md index 8fce8f21..39da6e5f 100644 --- a/docs/recipes/recurring-upkeep.md +++ b/docs/recipes/recurring-upkeep.md @@ -2,7 +2,7 @@ `bin/ytstack-upkeep` reads a project's `.ytstack/` and prints what needs a look: spec failures and drift, the STATE lint, open and lapsed gates, questions nobody put or answered, lanes without movement, a `RUNTIME.md` or a review policy that fails its check, and, when `REVIEW.md` declares own reviewers, merged pull requests that had no escape check yet (`ytstack:review-lessons`). A last section, `factory tools`, lists the factory tools that are off although the project would use them (risk routing, the PR watch, the "Release" and "Signals" sections of `RUNTIME.md`; the same lines a session sees once at its start); they are settings, not findings, so they never count and never raise a question. It exits 0 with `nothing needs a look` and 10 when something does. It needs bash and git, and no model; the review checks section also needs `gh` and `jq` and costs one `gh pr list` per run, one call per 100 merged pull requests in its window (from 14 days before the first escape check, or 14 days ago before there is one, never more than 90 days back; cut at 500 with a notice) (plus one `gh repo view` when `origin` is not a GitHub URL). In the CI job below the job's own token reads the pull requests. This recipe puts it on a schedule. -`ytstack-upkeep --worktrees` is a separate run for the cleanup of a checkout: it lists the linked worktrees and local branches with the state of their newest pull request, their age, uncommitted changes and the lane that holds them, and prints the `git worktree remove` / `git branch -D` commands for the merged or closed, clean ones. It runs none of them; a person or a session a person started does. +`ytstack-upkeep --worktrees` is a separate run for the cleanup of a checkout: it lists the linked worktrees and local branches with the state of their pull request, their age, uncommitted or unpushed changes and the lane that holds them, and prints the `git worktree remove` / `git branch -D` commands for the merged or closed ones with none of those and no open pull request. It runs none of them; a person or a session a person started does. **What a run may leave behind.** By default nothing in the tree; outside it, `ytstack-frontier check` keeps the time it first saw each ready lane (for the `stale:` lines under `lanes`). With `--question` one file, `.ytstack/questions/Q###-upkeep-found--things-that-need-a-look.md`, with the report in it, and no second one while the first is open or asked. In CI one issue instead. Never a change to the product, never a commit, never a merge. What happens with a finding stays with a person, or with a session a person started. diff --git a/docs/statusline.md b/docs/statusline.md index 2c29e176..a6460dbd 100644 --- a/docs/statusline.md +++ b/docs/statusline.md @@ -57,16 +57,17 @@ Only local refs are read. The script makes no network calls and does not use `gh ## Progress per phase -`ytstack-status --phases [--json] [-C DIR]` is for a status report or a chart, not for the status line. It reads the files of the checkout (no stdin, no default-branch lookup) and prints one line per milestone roadmap that is not `dropped`, the total and the time of the read: +`ytstack-status --phases [--json] [-C DIR]` is for a status report or a chart, not for the status line. It reads the files of the checkout (no stdin, no default-branch lookup) and prints one line per milestone roadmap that is not `dropped` or `backlog`, one line per phase that left the report, the total and the time of the read: ``` M004 2/5 done (40%) 1 in review total 4 -> 5 since the last report: added S05, S06; removed S04 -M006 0/1 done (0%) 0 in review -total 2/6 done (33%) 1 in review total 5 -> 6 since the last report +M006 0/1 done (0%) 0 in review new since the last report +M003 left the report since the last report (was 2 rows) +total 2/6 done (33%) 1 in review total 6 -> 6 since the last report; joined M006; left M003 read 2026-11-15T10:42Z, log ~/.local/state/ytstack/repos//phases/denominator.log ``` -A row is a slice of the roadmap. It is done when its checkbox is ticked or its `LANES.md` row is `merged`, in review when its row is `reported`, `in-review` or `ready`. Each run compares the slices per phase with the run before and names what changed the total. A grown total is then read as new work, not as lost progress. Every change is appended to `denominator.log` (UTC time, phase, total before, total after, cause: `first report`, `new phase`, `added S05`, `removed S04`, `phase left the report`) under the state base of `hooks/lib/git-ctx.sh` (`CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, `$XDG_STATE_HOME/ytstack` or `~/.local/state/ytstack`), keyed by the repository, never in the tree. `--json` prints the same as one object (`read`, `log`, `phases[]` with `phase`, `status`, `done`, `in_review`, `total`, `percent`, `change` with `before`, `added`, `removed` or `null`, and `total`), from which a chart is drawn. Exit 1 without `.ytstack/` or without a roadmap. +A row is a slice of the roadmap. It is done when its checkbox is ticked or its `LANES.md` row is `merged`; every slice of a `done` or `shipped-informally` milestone counts as done. A row is in review when its lane is `reported`, `in-review` or `ready`. Each text report compares the slices per phase with the text report before and names what changed the total, and which phases joined or left, also when the total stays the same. A grown total is then read as new work, not as lost progress. Only the text report moves that baseline, under a lock; `--json` shows the same change and writes nothing, so drawing a chart does not use it up. Every change is appended to `denominator.log` (UTC time, phase, total before, total after, cause: `first report`, `new phase`, `added S05`, `removed S04`, `phase left the report`) under the state base of `hooks/lib/git-ctx.sh` (`CLAUDE_PLUGIN_DATA`, `PLUGIN_DATA`, `$XDG_STATE_HOME/ytstack` or `~/.local/state/ytstack`), keyed by the repository, never in the tree. `--json` prints the same as one object (`read`, `log`, `phases[]` with `phase`, `status`, `done`, `in_review`, `total`, `percent`, `change` with `before`, `added`, `removed`, `joined` or `null`, `left[]` with `phase` and `before`, and `total` whose `change` carries `before`, `joined[]` and `left[]`), from which a chart is drawn. Exit 1 without `.ytstack/` or without a roadmap. ## Integration in Claude Code diff --git a/docs/ux/coordinator-format.md b/docs/ux/coordinator-format.md index 92cb5477..ff65d293 100644 --- a/docs/ux/coordinator-format.md +++ b/docs/ux/coordinator-format.md @@ -84,12 +84,12 @@ A claim is written before the work is dispatched: `ytstack-frontier claim ``` stale: M004-S02: running, no commit on ytstack/M004-S02 for 95 minutes (since 2026-11-15T08:40Z) -stale: M004-S03: running, but PR 12 is in its row: the worker reported; set the status stale: M004-S05: running, but its worktree .claude/worktrees/m004-s05 does not exist: the worker ended; read its branch and set the status +stale: review-pr-43: running review lane, no report for 200 minutes (claimed 2026-11-15T06:00Z) stale: M004-S06: ready, nobody claimed it for 70 minutes (first seen 2026-11-15T09:00Z) ``` -A `running` row is stale when its worker reported (a pull request in its row, or its worktree no longer exists) or when its branch had no commit for N minutes (default 60), counted from the claim when that is newer or the row names no branch. A `ready` lane of the frontier is stale when nobody claimed it for N minutes since a check first saw it ready; that first sight is kept outside the tree (`/repos//frontier-ready`, the base of `yt_state_base`). `bin/ytstack-upkeep` lists these lines under `lanes`. A stale line is a prompt to read the lane's branch and set its row, or to dispatch the ready lane; it never releases a lane by itself. +A `running` row is stale when its worktree no longer exists (the worker ended) or, for an `implement` lane, when its branch had no commit for N minutes (default 60), counted from the claim when that is newer or the row names no branch. A running row with a pull request in it is a fix round (`finish-lane`), not a report: its clock starts when a check first sees that pull request and round in the row, and a new round starts it again. A `review` or `prepare` lane commits nothing; it is stale after 3 x N minutes since its claim without a report. A `ready` lane of the frontier is stale when nobody claimed it for N minutes since a check first saw it ready. First sights are kept outside the tree, one writer at a time (`/repos//frontier-seen`, the base of `yt_state_base`). `bin/ytstack-upkeep` lists these lines under `lanes`. A stale line is a prompt to read the lane's branch and set its row, or to dispatch the ready lane; it never releases a lane by itself. ### Lesson lanes @@ -251,9 +251,9 @@ The old session stays open as a relay until every listed worker has reported. Pe ## Checked mechanically -- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` has four cells and a UTC time; then the lanes that stall ("Lanes that stall", exit 2). -- `bin/ytstack-upkeep --worktrees`: the linked worktrees and local branches with the state of their newest pull request, the age of the last commit, uncommitted changes and the lane that holds them, and the `git worktree remove` / `git branch -D` commands for the merged or closed, clean, unlocked and unheld ones. It prints the commands and runs none. -- `bin/ytstack-status --phases [--json]`: done, in review and total per milestone and in total, with each change of a total since the last report and its cause (`docs/statusline.md`, "Progress per phase"). +- `bin/ytstack-frontier check`: `LANES.md` has the ten columns, lane references are unique, `Status` and `Kind` hold listed values, a held lane has a claim time, every line under `## Peers` is a list line with four cells and a UTC time (a table row there is named as one); then the lanes that stall ("Lanes that stall", exit 2). +- `bin/ytstack-upkeep --worktrees`: the linked worktrees (not the main one, not the one it runs in) and local branches with the state of their pull request (an open one first, else the newest), the age of the last commit, uncommitted changes, unpushed commits and the lane of the main checkout's `LANES.md` that holds them, and the `git worktree remove` / `git branch -D` commands for those whose pull request is merged or closed, with no open one, nothing unpushed, clean, unlocked and unheld. It prints the commands and runs none. +- `bin/ytstack-status --phases [--json]`: done, in review and total per milestone and in total, with each change since the last text report, its cause and the phases that joined or left (`docs/statusline.md`, "Progress per phase"). - `bin/ytstack-questions check`: ids are unique and match the file name, `state` holds a listed value, `asked` and `answered` are set exactly when the state says so, an answered file has text under `## Answer`. - `bin/ytstack-brief check`: the report labels, the three `Status:` values and their consistency with `Blockers:`. - `bin/ytstack-handover check`: the staged script of a human-only step (see `skills/handover-step/SKILL.md`). diff --git a/tests/ytstack-frontier.test.sh b/tests/ytstack-frontier.test.sh index 5b3d00df..23891296 100644 --- a/tests/ytstack-frontier.test.sh +++ b/tests/ytstack-frontier.test.sh @@ -14,10 +14,11 @@ # byte-identical, "updated:" is rewritten # release "Claimed by" becomes "-", status "dropped" unless "merged" # check a well-formed file passes; each defect is named, exit 1; with a -# well-formed file, "stale:" lines for running rows whose worker -# reported (PR in the row, worktree gone) or whose branch had no -# commit for --minutes, and for ready lanes nobody claimed for -# --minutes since check first saw them (state outside the tree): exit 2 +# well-formed file, "stale:" lines for running rows whose worktree +# is gone or whose branch had no commit for --minutes (a fix round +# from its first sight), review and prepare rows after 3 x +# --minutes, and ready lanes nobody claimed for --minutes since +# check first saw them (state outside the tree, locked): exit 2 # peer set adds or updates one "## Peers" line per role and repository, # list prints them; the lanes table is untouched # refused a value with "|" or a newline, and usage errors: exit 64 @@ -414,47 +415,62 @@ utc() { date -u -r "$e" +"$f" 2>/dev/null || date -u -d "@$e" +"$f" } R=$(new_repo live M004); L="$R/.ytstack/LANES.md" -roadmap "$R" M004 in-progress "- S01" "- S02" "- S03" "- S04" "- S05" "- S06" -for s in S01 S02 S03 S04 S05 S06; do plan "$R" "M004-$s" none; done +roadmap "$R" M004 in-progress "- S01" "- S02" "- S03" "- S04" "- S05" "- S06" "- S07" "- S08" +for s in S01 S02 S03 S04 S05 S06 S07 S08; do plan "$R" "M004-$s" none; done ( cd "$R" && git add -A && GIT_COMMITTER_DATE="$(utc 30000 s)" GIT_AUTHOR_DATE="$(utc 30000 s)" git commit -qm base ) >/dev/null 2>&1 -# S01: silent for two hours; S02: a commit ten minutes ago; S03: a pull request -# in the row; S04: its worktree is gone; S05 is claimed, not running; S06 ready -git -C "$R" branch work/s01; git -C "$R" branch work/s02 +# S01: silent for two hours; S02: a commit ten minutes ago; S03: a fix round +# (a PR in the row, round 1), its last commit three hours old; S04: its +# worktree is gone; S05 is claimed, not running; S06 ready; S07: a review lane +# running four hours; S08: a prepare lane running one hour +git -C "$R" branch work/s01; git -C "$R" branch work/s02; git -C "$R" branch work/s03 ( cd "$R" && git checkout -q work/s01 && GIT_COMMITTER_DATE="$(utc 7200 s)" git commit -q --allow-empty -m one \ - && git checkout -q work/s02 && GIT_COMMITTER_DATE="$(utc 600 s)" git commit -q --allow-empty -m two && git checkout -q main ) >/dev/null 2>&1 + && git checkout -q work/s02 && GIT_COMMITTER_DATE="$(utc 600 s)" git commit -q --allow-empty -m two \ + && git checkout -q work/s03 && GIT_COMMITTER_DATE="$(utc 10800 s)" git commit -q --allow-empty -m three && git checkout -q main ) >/dev/null 2>&1 mkdir -p "$R/wt/s01" "$R/wt/s02" "$R/wt/s03" { printf -- '---\nupdated: 2026-11-15T10:00:00Z\n---\n\n# Lanes\n\n' echo '| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |' echo '|---|---|---|---|---|---|---|---|---|---|' echo "| M004-S01 | implement | running | w1 $(utc 10800) | work/s01 | wt/s01 | - | - | 0 | wait |" echo "| M004-S02 | implement | running | w2 $(utc 10800) | work/s02 | wt/s02 | - | - | 0 | wait |" - echo "| M004-S03 | implement | running | w3 $(utc 600) | - | wt/s03 | 12 | - | 0 | wait |" + echo "| M004-S03 | implement | running | w3 $(utc 10800) | work/s03 | wt/s03 | 12 | abc1234 | 1 | wait for the fix report |" echo "| M004-S04 | implement | running | w4 $(utc 600) | - | wt/gone | - | - | 0 | wait |" echo "| M004-S05 | implement | claimed | w5 $(utc 10800) | - | - | - | - | 0 | - |" + echo "| M004-S07 | review | running | r7 $(utc 14400) | - | - | 13 | - | 1 | wait for the verdict |" + echo "| M004-S08 | prepare | running | p8 $(utc 3600) | - | - | - | - | 0 | wait |" } > "$L" run "$R" check eq "liveness findings: exit 2" 2 "$EC" like "silent for two hours: no commit on its branch" "^stale: M004-S01: running, no commit on work/s01 for 1[12][0-9] minutes \(since [0-9T:-]+Z\)\$" "$OUT" hasnt "a commit ten minutes ago keeps a lane alive" "M004-S02" "$OUT" -has "a pull request in the row: the worker reported" "stale: M004-S03: running, but PR 12 is in its row: the worker reported; set the status" "$OUT" +hasnt "a fix round (a PR in the row) is no report, and its round starts when check first sees it" "M004-S03" "$OUT" has "its worktree is gone: the worker ended" "stale: M004-S04: running, but its worktree wt/gone does not exist" "$OUT" hasnt "a claimed lane is not looked at" "M004-S05" "$OUT" hasnt "a ready lane seen for the first time is not flagged" "M004-S06" "$OUT" +like "a review lane commits nothing: time only, three times the limit" "^stale: M004-S07: running review lane, no report for 2[34][0-9] minutes \(claimed [0-9T:-]+Z\)\$" "$OUT" +hasnt "a prepare lane under three times the limit is not flagged" "M004-S08" "$OUT" hasnt "no format problem" "line " "$OUT" run "$R" check --minutes 180 hasnt "--minutes moves the limit" "M004-S01" "$OUT" -READY=$(find "$CLAUDE_PLUGIN_DATA" -name frontier-ready -exec grep -l '^M004-S06 ' {} + | head -1) -case "$READY" in "$CLAUDE_PLUGIN_DATA/repos/"*) ok "the first sight of a ready lane is kept outside the tree" ;; *) bad "ready state location" "$READY" ;; esac -eq "one line for the ready lane" "M004-S06" "$(cut -f1 "$READY")" -printf 'M004-S06\t%s\n' "$((NOW - 7200))" > "$READY" +SEEN=$(find "$CLAUDE_PLUGIN_DATA" -name frontier-seen -exec grep -l '^ready:M004-S06 ' {} + | head -1) +case "$SEEN" in "$CLAUDE_PLUGIN_DATA/repos/"*) ok "first sights are kept outside the tree" ;; *) bad "seen state location" "$SEEN" ;; esac +eq "one line for the ready lane, one for the fix round" "fix:M004-S03:1 ready:M004-S06" "$(cut -f1 "$SEEN" | sort | paste -sd' ' -)" +printf 'ready:M004-S06\t%s\nfix:M004-S03:1\t%s\n' "$((NOW - 7200))" "$((NOW - 7200))" > "$SEEN" run "$R" check like "a ready lane nobody claimed for two hours" "^stale: M004-S06: ready, nobody claimed it for 1[12][0-9] minutes \(first seen [0-9T:-]+Z\)\$" "$OUT" +like "a fix round without a commit since it started" "^stale: M004-S03: running, no commit on work/s03 for 1[12][0-9] minutes \(since [0-9T:-]+Z\)\$" "$OUT" +run "$R" set M004-S03 --round 2 +run "$R" check +hasnt "a new round starts the clock again" "M004-S03" "$OUT" run "$R" claim M004-S06 --by w6 run "$R" check hasnt "claimed: no longer flagged" "M004-S06" "$OUT" -eq "and forgotten" "" "$(cut -f1 "$READY")" +eq "and forgotten" "fix:M004-S03:2" "$(cut -f1 "$SEEN")" git -C "$R" status --porcelain --untracked-files=all > "$TMP/st" -hasnt "check writes nothing into the tree" "frontier-ready" "$(cat "$TMP/st")" +hasnt "check writes nothing into the tree" "frontier-seen" "$(cat "$TMP/st")" +# Concurrent checks: no lost or torn state file, no temporary file left +for i in 1 2 3 4 5 6; do bash "$BIN" -C "$R" check >/dev/null 2>&1 & done; wait +eq "after six checks at once: the state file is whole" "fix:M004-S03:2" "$(cut -f1 "$SEEN")" +eq "and no temporary or lock file is left" "frontier-seen" "$(ls "$(dirname "$SEEN")" | grep frontier | paste -sd' ' -)" run "$R" check --minutes x; eq "--minutes takes a number: exit 64" 64 "$EC" sed 's/| running | w1/| working | w1/' "$L" > "$L.x" && mv "$L.x" "$L" run "$R" check @@ -487,6 +503,9 @@ eq "check passes with peers" "0 lanes ok" "$EC $OUT" printf '%s\n' '- broken | line' >> "$L" run "$R" check has "a peer line without four cells is named" "peer line" "$OUT" +printf '%s\n' '| prod | a/b | x | 2026-11-15T09:00Z |' >> "$L" +run "$R" check +has "a table row under ## Peers points at the peer format" "under ## Peers a peer is a list line" "$OUT" run "$R" peer set prod --repo "a|b" --address x; eq "a | in a peer value: exit 64" 64 "$EC" run "$R" peer set prod --address x; eq "peer set without --repo: exit 64" 64 "$EC" run "$R" peer set prod --repo r --address x --contact soon; eq "a contact that is no UTC time: exit 64" 64 "$EC" diff --git a/tests/ytstack-status.test.sh b/tests/ytstack-status.test.sh index 45369f46..fe87b7cf 100644 --- a/tests/ytstack-status.test.sh +++ b/tests/ytstack-status.test.sh @@ -189,13 +189,15 @@ road() { # ph [args]: OUT and EC of --phases, run from elsewhere ph() { local d="$1"; shift; OUT=$(cd "$ELSEWHERE" && bash "$BIN" --phases -C "$d" "$@" &1); EC=$?; } P=$(new_repo phases); state "$P" M004 none none -road "$P" M003 done "x S01" "x S02" +# M003 is done with a checkbox left open: a done milestone counts every slice +road "$P" M003 done "x S01" "- S02" road "$P" M004 active "x S01" "- S02" "- S03" "- S04" road "$P" M005 dropped "- S01" +road "$P" M007 backlog "- S01" "- S02" printf -- '---\nupdated: 2026-11-15T10:00:00Z\n---\n\n# Lanes\n\n| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n|---|---|---|---|---|---|---|---|---|---|\n| M004-S02 | implement | merged | w 2026-11-15T08:00Z | - | - | 3 | abc1234 | 1 | - |\n| M004-S03 | implement | in-review | w 2026-11-15T09:00Z | - | - | 4 | - | 1 | - |\n' > "$P/.ytstack/LANES.md" ph "$P" eq "--phases: exit 0" 0 "$EC" -eq "one line per phase, a dropped one left out, the total, the read line" \ +eq "one line per phase, dropped and backlog left out, done counts all, the total, the read line" \ "M003${TAB}2/2 done (100%)${TAB}0 in review M004${TAB}2/4 done (50%)${TAB}1 in review total${TAB}4/6 done (66%)${TAB}1 in review" "$(printf '%s\n' "$OUT" | sed '$d')" @@ -215,19 +217,47 @@ ph "$P" hasnt() { case "$3" in *"$2"*) bad "$1" "unexpected '$2' in: $3" ;; *) ok "$1" ;; esac; } hasnt "no change: no change shown" "since the last report" "$OUT" eq "and nothing logged" 3 "$(awk 'END { print NR }' "$LOG")" -road "$P" M006 planned "- S01"; road "$P" M003 dropped "x S01" "x S02" +# Same total (7): M006 joins with 2 slices, M003 (2) leaves as dropped +road "$P" M006 planned "- S01" "- S02"; road "$P" M003 dropped "x S01" "x S02" +ph "$P" +eq "a new phase and a dropped one are logged" "M006 - 2 new phase|M003 2 - phase left the report" "$(awk -F'\t' 'NR > 3 { printf "%s%s %s %s %s", (NR > 4 ? "|" : ""), $2, $3, $4, $5 }' "$LOG")" +eq "the new phase is named on its line" "M006${TAB}0/2 done (0%)${TAB}0 in review${TAB}new since the last report" "$(printf '%s\n' "$OUT" | grep '^M006')" +eq "the phase that left has a line" "M003${TAB}left the report since the last report (was 2 rows)" "$(printf '%s\n' "$OUT" | grep '^M003')" +eq "the total names both, also when it stays equal" "total${TAB}2/7 done (28%)${TAB}1 in review${TAB}total 7 -> 7 since the last report; joined M006; left M003" "$(printf '%s\n' "$OUT" | grep '^total')" +road "$P" M006 backlog "- S01" "- S02" +ph "$P" +eq "a phase parked on the backlog leaves the report" "M006${TAB}left the report since the last report (was 2 rows)" "$(printf '%s\n' "$OUT" | grep '^M006')" +road "$P" M006 planned "- S01" "- S02" ph "$P" -eq "a new phase and a dropped one are logged" "M006 - 1 new phase|M003 2 - phase left the report" "$(awk -F'\t' 'NR > 3 { printf "%s%s %s %s %s", (NR > 4 ? "|" : ""), $2, $3, $4, $5 }' "$LOG")" if command -v jq >/dev/null 2>&1; then road "$P" M004 active "x S01" "- S02" "- S03" "- S05" "- S06" "- S07" + road "$P" M008 planned "- S01" ph "$P" --json eq "--json: exit 0" 0 "$EC" - eq "--json: phases, counts and the change" "M004 active 2 1 6 33 5 S07|M006 planned 0 0 1 0 null|2 1 7 28 6" \ - "$(printf '%s' "$OUT" | jq -r '(.phases[] | "\(.phase) \(.status) \(.done) \(.in_review) \(.total) \(.percent) \(if .change then "\(.change.before) \(.change.added | join(","))" else "null" end)"), "\(.total.done) \(.total.in_review) \(.total.total) \(.total.percent // "null") \(.total.change.before)"' | paste -sd'|' -)" + J='(.phases[] | "\(.phase) \(.status) \(.done) \(.in_review) \(.total) \(.percent) \(if .change then "\(.change.before) \(.change.added | join(",")) \(.change.joined)" else "null" end)"), "\(.total.done) \(.total.in_review) \(.total.total) \(.total.percent // "null") \(.total.change.before) \(.total.change.joined | join(","))"' + WANT="M004 active 2 1 6 33 5 S07 false|M006 planned 0 0 2 0 null|M008 planned 0 0 1 0 0 S01 true|2 1 9 22 7 M008" + eq "--json: phases, counts, the change and a joined phase" "$WANT" "$(printf '%s' "$OUT" | jq -r "$J" | paste -sd'|' -)" case "$(printf '%s' "$OUT" | jq -r '.read + " " + .log')" in 20*" $LOG") ok "--json: read time and log path" ;; *) bad "--json: read and log" "$OUT" ;; esac + LINES=$(awk 'END { print NR }' "$LOG") + ph "$P" --json + eq "--json does not use up the change: a second --json shows it again" "$WANT" "$(printf '%s' "$OUT" | jq -r "$J" | paste -sd'|' -)" + eq "and logs nothing" "$LINES" "$(awk 'END { print NR }' "$LOG")" + road "$P" M006 dropped "- S01" "- S02" + ph "$P" --json + eq "--json: a phase that left" "M006 2" "$(printf '%s' "$OUT" | jq -r '.left[] | "\(.phase) \(.before)"')" + road "$P" M006 planned "- S01" "- S02" + ph "$P" + ph "$P" --json + eq "after a text report the change is used up" "null" "$(printf '%s' "$OUT" | jq -r '.total.change')" else ok "--json: skipped, no jq" fi +# Concurrent text reports: the log gets each change once, no temporary or lock file stays +road "$P" M004 active "x S01" "- S02" "- S03" "- S05" "- S06" "- S07" "- S09" +B4=$(awk 'END { print NR }' "$LOG") +for i in 1 2 3 4 5 6; do ( cd "$ELSEWHERE" && bash "$BIN" --phases -C "$P" >/dev/null 2>&1 ) & done; wait +eq "six reports at once log the change once" "$((B4 + 1))" "$(awk 'END { print NR }' "$LOG")" +eq "and leave only the snapshot and the log" "denominator.log snapshot" "$(ls "$(dirname "$LOG")" | paste -sd' ' -)" N2=$(new_repo noroad); state "$N2" none none none ph "$N2" eq "no roadmap: exit 1" 1 "$EC" diff --git a/tests/ytstack-upkeep.test.sh b/tests/ytstack-upkeep.test.sh index cdbee3e1..d3e6dea4 100644 --- a/tests/ytstack-upkeep.test.sh +++ b/tests/ytstack-upkeep.test.sh @@ -21,7 +21,9 @@ # --worktrees linked worktrees and local branches with PR state (one # `gh pr list`), age, uncommitted changes and the lane that holds # them; the remove commands for merged or closed, clean, unheld -# ones are printed and never run (exit 10), none without PR state +# ones with no open PR and nothing unpushed are printed and never +# run (exit 10), none without PR state; from a linked worktree +# that worktree is left out and LANES.md is the main checkout's # runtime the problems of `ytstack-runtime check` # review policy the problems of `ytstack-risk check` when the script exists # beside ytstack-upkeep, a note when it does not @@ -245,11 +247,11 @@ run "$D" --lane-hours 100 eq "a higher limit: only the stale running lane is left" "10:1" "$EC:$(count lanes)" like "as ytstack-frontier check names it" "^ - M004-S02: running, no branch in its row|^ - M004-S02: running, no commit on ytstack/M004-S02 for [0-9]+ minutes" "$OUT" lanes \ - "| M004-S06 | implement | running | impl-e $(claim $((2 * HOUR))) | - | - | 7 | - | 0 | wait |" \ + "| M004-S06 | implement | running | impl-e $(claim $((2 * HOUR))) | - | wt/gone | - | - | 0 | wait |" \ "| M004-S07 | implement | claimed | impl-f $(claim $((2 * HOUR))) | - | - | - | - | 0 | - |" run "$D" eq "a stale lane under the hour limit is listed (issue #84)" "10:1" "$EC:$(count lanes)" -has "with the line of the check" " - M004-S06: running, but PR 7 is in its row: the worker reported; set the status" "$OUT" +has "with the line of the check" " - M004-S06: running, but its worktree wt/gone does not exist" "$OUT" lanes \ "| M004-S02 | implement | running | impl-b $(claim $((30 * HOUR))) | ytstack/M004-S02 | - | - | - | 0 |" \ "| M004-S03 | implement | sleeping | impl-c $(claim $((30 * HOUR))) | - | - | - | - | 0 | - |" @@ -453,17 +455,24 @@ echo "# worktrees" project wtinv ( cd "$D" && git init -q -b main && git config user.email t@t.t && git config user.name t && git config commit.gpgsign false \ && git add -A && GIT_COMMITTER_DATE="$(ago $((3 * DAY)))" git commit -qm base \ - && for b in one two three four five six; do git branch "feat/$b"; done \ + && for b in one two three four five six seven eight; do git branch "feat/$b"; done \ && git worktree add -q "$D/.wt/one" feat/one && git worktree add -q "$D/.wt/two" feat/two && git worktree add -q "$D/.wt/six" feat/six ) >/dev/null 2>&1 || { echo "FATAL fixture"; exit 2; } +BASE=$(git -C "$D" rev-parse HEAD) +# feat/seven: one commit more than its merged pull request (unpushed work) +( cd "$D" && git checkout -q feat/seven && GIT_COMMITTER_DATE="$(ago $((3 * DAY)))" git commit -q --allow-empty -m unpushed && git checkout -q main ) >/dev/null 2>&1 echo dirty > "$D/.wt/two/new.txt" printf -- '---\nupdated: x\n---\n\n# Lanes\n\n| Lane | Kind | Status | Claimed by | Branch | Worktree | PR | Reviewed head | Round | Next action |\n|---|---|---|---|---|---|---|---|---|---|\n| M004-S06 | implement | reported | w %s | feat/six | .wt/six | 9 | - | 0 | review |\n' "$(ago 600)" > "$Y/LANES.md" +WTJSON="$TMP/wt.json"; export WTJSON +printf '[{"number":5,"state":"MERGED","headRefName":"feat/one","headRefOid":"%s"},{"number":6,"state":"MERGED","headRefName":"feat/two","headRefOid":"%s"}, + {"number":3,"state":"OPEN","headRefName":"feat/three","headRefOid":"%s"},{"number":7,"state":"CLOSED","headRefName":"feat/three","headRefOid":"%s"}, + {"number":8,"state":"OPEN","headRefName":"feat/five","headRefOid":"%s"},{"number":9,"state":"MERGED","headRefName":"feat/six","headRefOid":"%s"}, + {"number":10,"state":"MERGED","headRefName":"feat/seven","headRefOid":"%s"},{"number":11,"state":"CLOSED","headRefName":"feat/eight","headRefOid":"%s"}]' \ + "$BASE" "$BASE" "$BASE" "$BASE" "$BASE" "$BASE" "$BASE" "$BASE" > "$WTJSON" cat > "$TMP/fakebin/gh" <<'EOF' #!/usr/bin/env bash echo "$*" >> "$GHLOG" [ -z "${GH_FAIL:-}" ] || { echo "HTTP 502: bad gateway" >&2; exit 1; } -printf '%s' '[{"number":5,"state":"MERGED","headRefName":"feat/one"},{"number":6,"state":"MERGED","headRefName":"feat/two"}, - {"number":3,"state":"OPEN","headRefName":"feat/three"},{"number":7,"state":"CLOSED","headRefName":"feat/three"}, - {"number":8,"state":"OPEN","headRefName":"feat/five"},{"number":9,"state":"MERGED","headRefName":"feat/six"}]' +cat "$WTJSON" EOF chmod +x "$TMP/fakebin/gh"; : > "$GHLOG" PATH="$TMP/fakebin:$OLDPATH" @@ -475,17 +484,25 @@ has "worktrees: 3" "worktrees: 3" "$OUT" like "a worktree with its branch, PR state and age" "^ - $D/\.wt/one: feat/one, PR #5 merged, last commit 3 days ago\$" "$OUT" like "uncommitted changes are named" "^ - $D/\.wt/two: feat/two, PR #6 merged, last commit 3 days ago, uncommitted changes\$" "$OUT" like "a branch a lane holds is named" "^ - $D/\.wt/six: feat/six, PR #9 merged, last commit 3 days ago, held by lane M004-S06 \(reported\)\$" "$OUT" -has "branches without a worktree: 3" "branches: 3" "$OUT" -like "the newest PR of a branch counts" "^ - feat/three: PR #7 closed, last commit 3 days ago\$" "$OUT" +has "branches without a worktree: 5" "branches: 5" "$OUT" +like "an open PR of a branch wins over a newer closed one" "^ - feat/three: PR #3 open, last commit 3 days ago\$" "$OUT" like "a branch without a PR" "^ - feat/four: no pull request, last commit 3 days ago\$" "$OUT" like "an open PR" "^ - feat/five: PR #8 open, last commit 3 days ago\$" "$OUT" +like "a branch ahead of its merged PR head" "^ - feat/seven: PR #10 merged, last commit 3 days ago, unpushed commits\$" "$OUT" +like "a closed PR at the branch head" "^ - feat/eight: PR #11 closed, last commit 3 days ago\$" "$OUT" hasnt "the default branch is not listed" " - main" "$OUT" -eq "the commands, not run: merged or closed, clean, not held" "commands (not run): 3 +eq "the commands, not run: merged or closed, no open PR, nothing unpushed, clean, not held" "commands (not run): 3 git -C '$D' worktree remove '$D/.wt/one' git -C '$D' branch -D 'feat/one' - git -C '$D' branch -D 'feat/three'" "$(printf '%s\n' "$OUT" | sed -n '/^commands (not run)/,$p')" -eq "one gh call" "pr list --state all --limit 500 --json number,state,headRefName" "$(cat "$GHLOG")" + git -C '$D' branch -D 'feat/eight'" "$(printf '%s\n' "$OUT" | sed -n '/^commands (not run)/,$p')" +eq "one gh call" "pr list --state all --limit 500 --json number,state,headRefName,headRefOid" "$(cat "$GHLOG")" eq "nothing was removed" "$BEFORE" "$(cd "$D" && git worktree list --porcelain; git branch --list)" +# From a linked worktree: that worktree is left out, LANES.md comes from the main checkout +run "$D/.wt/one" --worktrees +hasnt "the current worktree is not listed" "$D/.wt/one:" "$OUT" +hasnt "and no command removes it" "remove '$D/.wt/one'" "$OUT" +has "the lane of the main checkout's LANES.md still holds feat/six" "held by lane M004-S06 (reported)" "$OUT" +like "the first line names the main checkout" "^ytstack upkeep --worktrees: $D, read " "$(printf '%s\n' "$OUT" | sed -n 1p)" GH_FAIL=1 run "$D" --worktrees eq "gh fails: nothing to remove, exit 0" 0 "$EC" has "and the reason" "PR state not read: HTTP 502: bad gateway" "$OUT"