diff --git a/.github/workflows/program-tending.yml b/.github/workflows/program-tending.yml new file mode 100644 index 0000000000..953435dfba --- /dev/null +++ b/.github/workflows/program-tending.yml @@ -0,0 +1,47 @@ +name: program-tending + +# program-tending (issue #1352, slice 1/3 scaffold). +# +# Daily scheduled care for the planning layer across the four fleet +# repos (code, opencode, openchamber, nix): epics, roadmaps, projects, +# stalled PRs, loose ends. This slice is the scaffold only: the +# schedule, the runner entrypoint, per-section stubs that verify and +# report no-actions, and the structured run log. Full section +# implementations land in slices 2-3 (see #1352 triage decomposition, +# 2026-11-02) after this scaffold lands. +# +# Ownership rules (from #1352, enforced in slice 1 stubs): +# - Never touch held / do-not-merge / user-owned PRs. +# - Drew's own feature PRs: check-in comment at 7 days only, never a packet. +# - user/review is reported, never re-decided. + +on: + schedule: + # Daily 13:00 UTC (07:00 CST / 08:00 CDT). + - cron: "0 13 * * *" + workflow_dispatch: + +# One live tending run at a time: a new tick cancels a still-running +# previous run (each run is read-mostly and idempotent; actions are +# comments/labels, never force-pushes). +concurrency: + group: program-tending + cancel-in-progress: true + +permissions: + contents: read + +jobs: + tend: + name: program-tending scaffold run + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-python@v7 + with: + python-version: "3.14" + - name: Run program-tending scaffold (slice 1 stubs) + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: python3 -I scripts/program_tending.py --run diff --git a/scripts/program_tending.py b/scripts/program_tending.py new file mode 100755 index 0000000000..2572519ccc --- /dev/null +++ b/scripts/program_tending.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python3 +"""program-tending scaffold (issue #1352, slice 1/3). + +Daily scheduled care for the planning layer across the four fleet repos +(code, opencode, openchamber, nix). This slice is the scaffold only: the +runner entrypoint, per-section stubs that verify and report no-actions, +and the structured run log. Full section implementations (epics + +roadmaps in slice 2, projects + stalled-PRs + loose-ends in slice 3) +land after this scaffold does — see the triage decomposition on #1352. + +Ownership rules (from #1352; enforced by every section stub): +- never touch held / do-not-merge / user-owned PRs; +- Drew's own feature PRs get a check-in comment at 7 days, never a packet; +- user/review is reported, never re-decided. + +Usage: python3 -I scripts/program_tending.py --run [--repo owner/name ...] +""" + +from __future__ import annotations + +import argparse +import datetime as dt +import json +import sys +import urllib.request + +SECTIONS = ("epics", "roadmaps", "projects", "stalled-prs", "loose-ends") + +FLEET_REPOS = ( + "developing-today/code", + "developing-today/opencode", + "developing-today/openchamber", + "developing-today/nix", +) + +# Labels the stubs must never act on (read-only signals). +HARD_STOPS = ("held", "user/owned", "do-not-merge", "do-not-auto-edit") + +# The fleet monitor tends issues and queue state; this job reports the +# planning layer and never changes monitor or stewardship-cycle behavior. +OUT_OF_SCOPE = ("fleet monitor behavior", "stewardship-cycle behavior") + + +def _utcnow() -> str: + return dt.datetime.now(dt.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") + + +def _gh_api(path: str) -> list: + """GET a GitHub REST collection, following pagination. Read-only.""" + items: list = [] + url = f"https://api.github.com{path}" + while url: + req = urllib.request.Request(url, headers={"Accept": "application/vnd.github+json"}) + with urllib.request.urlopen(req, timeout=30) as resp: + items.extend(json.loads(resp.read().decode("utf-8"))) + nxt = resp.headers.get("Link", "") + url = "" + for part in nxt.split(","): + if 'rel="next"' in part: + url = part.split(";")[0].strip().strip("<>") + return items + + +def _labels(item: dict) -> set[str]: + return {label["name"] for label in item.get("labels", [])} + + +def stub_epics(repos: list[str]) -> dict: + """Slice 2 owns this section. Slice 1 verifies reachability only.""" + checked = [{"repo": repo, "open_epics": "unverified (slice 2)"} for repo in repos] + return { + "section": "epics", + "status": "no-action", + "detail": "scaffold only: per-epic child-progress checks land in slice 2", + "checked": checked, + } + + +def stub_roadmaps(repos: list[str]) -> dict: + """Slice 2 owns this section. Slice 1 verifies reachability only.""" + return { + "section": "roadmaps", + "status": "no-action", + "detail": "scaffold only: ROADMAP.md vs landed-work drift checks land in slice 2", + "checked": [{"repo": repo, "drift": "unverified (slice 2)"} for repo in repos], + } + + +def stub_projects(repos: list[str]) -> dict: + """Slice 3 owns this section. Slice 1 verifies reachability only.""" + return { + "section": "projects", + "status": "no-action", + "detail": "scaffold only: board-vs-reality correction checks land in slice 3", + "checked": [{"repo": repo, "board_state": "unverified (slice 3)"} for repo in repos], + } + + +def stub_stalled_prs(repos: list[str]) -> dict: + """Slice 3 owns this section. Slice 1 counts, but never comments.""" + counts = [] + for repo in repos: + try: + prs = _gh_api(f"/repos/{repo}/pulls?state=open&per_page=100") + counts.append({"repo": repo, "open_prs": len(prs), "note": "48h-rule evaluation lands in slice 3"}) + except Exception as exc: # noqa: BLE001 - scaffold reports, never fails + counts.append({"repo": repo, "open_prs": "unverified", "error": str(exc)}) + return { + "section": "stalled-prs", + "status": "no-action", + "detail": "scaffold only: 48h check-ins and pr_shepherd packets land in slice 3; no comments posted", + "checked": counts, + } + + +def stub_loose_ends(repos: list[str]) -> dict: + """Slice 3 owns this section. Slice 1 verifies reachability only.""" + return { + "section": "loose-ends", + "status": "no-action", + "detail": "scaffold only: notifications, duplicate cross-links, user/review surfacing land in slice 3", + "checked": [{"repo": repo, "loose_ends": "unverified (slice 3)"} for repo in repos], + } + + +def run(repos: list[str]) -> dict: + log = { + "job": "program-tending", + "slice": 1, + "issue": "developing-today/code#1352", + "run_at": _utcnow(), + "repos": repos, + "hard_stops": list(HARD_STOPS), + "out_of_scope": list(OUT_OF_SCOPE), + "sections": [ + stub_epics(repos), + stub_roadmaps(repos), + stub_projects(repos), + stub_stalled_prs(repos), + stub_loose_ends(repos), + ], + } + log["actions_taken"] = sum(1 for s in log["sections"] if s["status"] != "no-action") + return log + + +def main(argv: list[str]) -> int: + parser = argparse.ArgumentParser(description="program-tending scaffold runner (slice 1/3)") + parser.add_argument("--run", action="store_true", help="execute one scaffold run and print the log") + parser.add_argument("--repo", action="append", default=[], help="limit to owner/name (repeatable)") + args = parser.parse_args(argv) + if not args.run: + parser.print_help() + return 2 + repos = args.repo or list(FLEET_REPOS) + print(json.dumps(run(repos), indent=2)) + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/scripts/tests/test_program_tending.py b/scripts/tests/test_program_tending.py new file mode 100644 index 0000000000..16dffd09a4 --- /dev/null +++ b/scripts/tests/test_program_tending.py @@ -0,0 +1,76 @@ +"""Contract tests for the program-tending scaffold (issue #1352, slice 1/3). + +The scaffold is read-only by design: every section reports a verified +no-action, the runner never fails on a per-repo fetch error, and the +run log always covers all five sections with the hard-stop labels named. +""" + +import io +import json +import subprocess +import sys +import unittest +from contextlib import redirect_stdout +from pathlib import Path +from unittest import mock + +SCRIPT_DIR = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(SCRIPT_DIR)) + +import program_tending as pt + + +class ProgramTendingScaffoldTest(unittest.TestCase): + def test_run_log_covers_all_five_sections(self): + log = pt.run(["developing-today/code"]) + self.assertEqual([s["section"] for s in log["sections"]], + ["epics", "roadmaps", "projects", "stalled-prs", "loose-ends"]) + + def test_scaffold_is_read_only(self): + with mock.patch.object(pt, "_gh_api", return_value=[{"labels": []}]): + log = pt.run(["developing-today/code"]) + self.assertEqual(log["actions_taken"], 0) + self.assertTrue(all(s["status"] == "no-action" for s in log["sections"])) + + def test_hard_stops_named_in_log(self): + log = pt.run(["developing-today/code"]) + for stop in ("held", "user/owned", "do-not-merge", "do-not-auto-edit"): + self.assertIn(stop, log["hard_stops"]) + + def test_fetch_failure_reports_never_fails(self): + with mock.patch.object(pt, "_gh_api", side_effect=RuntimeError("offline")): + section = pt.stub_stalled_prs(["developing-today/code"]) + self.assertEqual(section["status"], "no-action") + self.assertIn("error", section["checked"][0]) + + def test_cli_run_prints_valid_log(self): + buf = io.StringIO() + with redirect_stdout(buf): + self.assertEqual(pt.main(["--run", "--repo", "developing-today/code"]), 0) + log = json.loads(buf.getvalue()) + self.assertEqual(log["job"], "program-tending") + self.assertEqual(len(log["sections"]), 5) + + def test_cli_without_run_flag_exits_2(self): + self.assertEqual(pt.main([]), 2) + + def test_workflow_file_exists_and_is_scheduled(self): + wf = Path(__file__).resolve().parents[2] / ".github/workflows/program-tending.yml" + text = wf.read_text() + self.assertIn("cron:", text) + self.assertIn("workflow_dispatch", text) + self.assertIn("scripts/program_tending.py", text) + + def test_script_runs_isolated(self): + proc = subprocess.run( + [sys.executable, "-I", str(SCRIPT_DIR / "program_tending.py"), + "--run", "--repo", "developing-today/code"], + capture_output=True, text=True, timeout=120, cwd=str(SCRIPT_DIR.parent), + ) + self.assertEqual(proc.returncode, 0, proc.stderr[-2000:]) + log = json.loads(proc.stdout) + self.assertEqual(len(log["sections"]), 5) + + +if __name__ == "__main__": + unittest.main()