diff --git a/AGENTS.md b/AGENTS.md index 4e822dfb..ecf5619b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -134,7 +134,7 @@ the `/` slash commands. |------|---------|------------| | `intake` | Conceive a task: turn raw input into a formal, headed PyAutoMind prompt (files it; never starts dev) | `bin/pyauto-brain intake` | | `batch` | Compose one unattended shift: the BatchDecision, planned against the slot's REVIEW-MINUTE budget rather than a task count — proposes, never dispatches; 'batch collect' scores what came back into the review packet and stamps the batch record | `bin/pyauto-brain batch` | -| `community` | The ears — the organism's receptive function: scan/triage user-filed GitHub issues + PRs and review requests across the repos; drafts stay human-gated, dev work routes via start_dev_for_user (never posts) | `bin/pyauto-brain community` | +| `community` | The ears — the organism's receptive function: scan/triage the Discussions hub where users ask (PyAutoMind/policy/community_surface.md) plus user-filed GitHub issues + PRs and review requests across the repos; drafts stay human-gated, dev work routes via start_dev_for_user (never posts) | `bin/pyauto-brain community` | | `feature` | Reason over PyAutoMind feature tasks: select, size, phase, plan for start_dev | `bin/pyauto-brain feature` | | `bug` | The immune system: classify a bug/regression/Heart finding, locate the fix, plan the repair | `bin/pyauto-brain bug` | | `refactor` | The renewal function: plan behaviour-preserving restructuring — RefactorDecision; default-safe under --auto | `bin/pyauto-brain refactor` | diff --git a/agents/conductors/community/AGENTS.md b/agents/conductors/community/AGENTS.md index 42ad763c..cfd37f52 100644 --- a/agents/conductors/community/AGENTS.md +++ b/agents/conductors/community/AGENTS.md @@ -1,9 +1,9 @@ # Community agent > **Tier: conductor** — a front-door agent you *drive*. The *Ears* — the -> organism's receptive language function: it hears the community (user-filed -> GitHub issues and pull requests across every repo) and drafts what the -> organism says back; the +> organism's receptive language function: it hears the community (the +> Discussions hub where users ask, plus user-filed GitHub issues and pull +> requests across every repo) and drafts what the organism says back; the > human remains the mouth. Wernicke to the Workspace Agent's Broca: that > *Voice* speaks to users through examples and tutorials, this agent > *comprehends and converses* — it reads an outsider's issue, judges whether @@ -28,15 +28,20 @@ gates every outward message. | Mode | Surface | Consumed by | |------|---------|-------------| -| `scan` *(default)* | every `PyAutoMind/repos.yaml` repo → open issues **and PRs** authored by non-self humans (bots filtered), with **awaiting-response** detection (the conversation's last word is not ours) ranked by waiting time, plus open PRs with **review requested** from a self login (any author) | `/community` step 1; the `/wake_up` community sensory leg | -| `triage ` | one issue or PR → context-sufficiency signals (code block, traceback, versions, expected-vs-actual, data pointer), missing-signal clarifying-question seeds, comment tail, route; a PR ref adds the **change-shape block** (draft, files, +/-, requested reviewers, mergeable state, head→base) | `/community` steps 2–3 | +| `scan` *(default)* | the **Discussions hub**'s open threads (unanswered = no accepted answer and the last word is not ours) + every `PyAutoMind/repos.yaml` repo → open issues **and PRs** authored by non-self humans (bots filtered), with **awaiting-response** detection (the conversation's last word is not ours) ranked by waiting time, plus open PRs with **review requested** from a self login (any author) | `/community` step 1; the board's community sensory leg | +| `triage ` | one discussion, issue or PR → context-sufficiency signals (code block, traceback, versions, expected-vs-actual, data pointer), missing-signal clarifying-question seeds, comment tail, route; a discussion ref routes to **answer in the thread** (a confirmed bug gets an issue with a link back); a PR ref adds the **change-shape block** (draft, files, +/-, requested reviewers, mergeable state, head→base) | `/community` steps 2–3 | ``` pyauto-brain community # scan: who is waiting on us? pyauto-brain community scan --json -pyauto-brain community triage [--json] +pyauto-brain community triage [--json] ``` +The hub is `COMMUNITY_HUB` (default `PyAutoLabs/.github` — the org's +Discussions, the one surface users post to, decided in +`PyAutoMind/policy/community_surface.md`). A discussion is named by its URL on +every surface, because `owner/repo#N` reads as an issue. + Repo enumeration comes from `PyAutoMind/repos.yaml` (the body map) under `PYAUTO_ROOT`; the org is searched wholesale, non-org homes individually. GitHub access is the `gh` CLI — `COMMUNITY_GH` overrides the binary (hermetic @@ -52,6 +57,15 @@ failed search degrades honestly (`degraded:` in the surface), never silently. and presented to the human before posting. The CLI itself never mutates GitHub. Autonomy for community work is `human-required` by design; `--auto` changes nothing here. +- **Users ask on the hub; the development flow stays on issues.** That is + `PyAutoMind/policy/community_surface.md`, and this conductor is its + reader: a question, a help request or an idea is answered in its + Discussions thread; a report with a reproducer is an issue and routes to + `/start_dev_for_user`; a discussion that turns out to be a bug gets an + issue opened with a link back and the thread marked answered with the + issue link. No session can post to, answer or convert a Discussion (the + REST Discussions API is read-only, GraphQL is refused) — the human's click + is always the last step. - **Conversation state lives on GitHub + Mind, never here.** Labels (`needs-info`, `pending-release`) and the issue thread itself are the conversation's memory; in-flight dev state is the `user-facing: true` entry @@ -91,6 +105,10 @@ failed search degrades honestly (`degraded:` in the surface), never silently. ## Capability audit — what the modes read +- **Discussions hub** (`gh api repos//discussions`, `.../discussions/`, + `.../discussions//comments`): the REST Discussions surface, read-only — + state, lock, category, `answer_chosen_at`, comment count, last commenter. + Served to remote sessions through the proxy (measured 2026-09-17). - **GitHub search** (`gh api search/issues`): `org:PyAutoLabs` plus the non-org homes from `repos.yaml`; three passes per qualifier group — `is:issue is:open -author:`, `is:pr is:open -author:`, and diff --git a/agents/conductors/community/_community.py b/agents/conductors/community/_community.py index dfca2491..2680066d 100644 --- a/agents/conductors/community/_community.py +++ b/agents/conductors/community/_community.py @@ -3,17 +3,21 @@ The Ears — the organism's receptive language function (Wernicke to the Workspace Agent's Broca/Voice: that agent speaks through examples; this one -hears the community). It reads the outside world's GitHub issues and emits -deterministic surfaces the /community skill reasons over: - - scan every repos.yaml repo -> open issues AND pull requests raised by - non-self humans (awaiting-response detection, waiting-time - ranking) + open PRs with review requested from a self login - (the /wake_up community sensory leg) - triage one issue or PR -> context-sufficiency signals + routing surface; - PR refs additionally carry the change-shape block (draft, files, - additions/deletions, requested reviewers, mergeable state) - (the judgment — actionable vs ask-for-more — stays in the session) +hears the community). It reads the outside world's GitHub threads — the +Discussions hub where users ask (PyAutoMind/policy/community_surface.md) and +the issues/PRs outsiders still file — and emits deterministic surfaces the +/community skill reasons over: + + scan the hub's open discussions (unanswered = no accepted answer and + the last word is not ours) + every repos.yaml repo -> open issues + AND pull requests raised by non-self humans (awaiting-response + detection, waiting-time ranking) + open PRs with review requested + from a self login (the board's community sensory leg) + triage one discussion, issue or PR -> context-sufficiency signals + + routing surface; PR refs additionally carry the change-shape block + (draft, files, additions/deletions, requested reviewers, mergeable + state) (the judgment — actionable vs ask-for-more — stays in the + session) The conductor NEVER posts, labels or edits anything on GitHub and never writes files. Every outward message is drafted in the /community skill session and @@ -53,6 +57,11 @@ if s.strip() ] PRIMARY_ORG = "PyAutoLabs" +# The one Discussions hub users post to (PyAutoMind/policy/community_surface.md, +# decision 1): the org's Discussions, hosted on the neutral profile repo +# PyAutoLabs/.github. Every library and workspace points here; the repos +# themselves keep Discussions off. +HUB = os.environ.get("COMMUNITY_HUB", "PyAutoLabs/.github") SCAN_DETAIL_CAP = 30 # issues that get a per-issue last-commenter lookup # Pause between search-API calls — the scan makes up to six, and GitHub's # secondary rate limit trips on rapid bursts (hermetic tests set it to 0). @@ -155,6 +164,54 @@ def issue_repo(item): return "/".join(item.get("repository_url", "").split("/")[-2:]) +def list_discussions(hub): + """The hub's open discussions (REST, read-only — the only Discussions + surface a remote session is served); None when unreadable.""" + return gh_json([f"repos/{hub}/discussions", "-f", "per_page=100", "-f", "state=open"]) + + +def discussion_last_commenter(hub, number): + comments = gh_json([f"repos/{hub}/discussions/{number}/comments", "-f", "per_page=100"]) + if not comments: + return None + return (comments[-1].get("user") or {}).get("login") + + +def _discussion_entry(d, hub): + return { + "type": "discussion", + "repo": hub, + "number": d.get("number"), + "title": d.get("title", ""), + "author": (d.get("user") or {}).get("login"), + "url": d.get("html_url"), + "category": (d.get("category") or {}).get("name"), + "answered": d.get("answer_chosen_at") is not None, + "labels": [l.get("name") for l in d.get("labels", []) or []], + "comments": d.get("comments", 0), + "updated_at": d.get("updated_at"), + "waiting_days": days_since(d.get("updated_at")), + "last_actor": None, + "awaiting_response": None, + } + + +def hub_discussions(hub, degraded): + """Open, unlocked, human-authored threads on the hub. An accepted answer + settles a thread (awaiting_response=False without a comment lookup); + otherwise the last word decides, exactly as for an issue.""" + items = list_discussions(hub) + if items is None: + degraded.append(f"{hub} discussions listing failed (gh auth? Discussions off?)") + return [] + entries = [] + for d in items: + if d.get("state", "open") != "open" or d.get("locked") or is_bot(d.get("user")): + continue + entries.append(_discussion_entry(d, hub)) + return entries + + def _entry(item, kind): return { "type": kind, @@ -207,29 +264,37 @@ def build_scan(): # per-item lookups; uncapped entries keep awaiting_response=None (unknown). # Uses issue-conversation comments (PR review-thread comments are a known # v2 limit, recorded in AGENTS.md). - conversations = issues + prs + discussions = hub_discussions(HUB, degraded) + for entry in discussions: + if entry["answered"]: + entry["awaiting_response"] = False + conversations = issues + prs + [d for d in discussions if not d["answered"]] for entry in sorted( conversations, key=lambda e: e["updated_at"] or "", reverse=True )[:SCAN_DETAIL_CAP]: - actor = ( - entry["author"] - if entry["comments"] == 0 - else last_commenter(entry["repo"], entry["number"]) - ) + if entry["comments"] == 0: + actor = entry["author"] + elif entry["type"] == "discussion": + actor = discussion_last_commenter(entry["repo"], entry["number"]) + else: + actor = last_commenter(entry["repo"], entry["number"]) entry["last_actor"] = actor entry["awaiting_response"] = actor is not None and actor not in SELF_LOGINS - awaiting = [e for e in conversations if e["awaiting_response"]] + awaiting = [e for e in issues + prs + discussions if e["awaiting_response"]] awaiting.sort(key=lambda e: e["waiting_days"] or 0, reverse=True) return { "self_logins": SELF_LOGINS, "org": PRIMARY_ORG, + "hub": HUB, "extra_repos": extra, + "open_discussions": discussions, "open_external_issues": issues, "open_external_prs": prs, "awaiting_review": review_requested, "awaiting_response": awaiting, "counts": { + "open_discussions": len(discussions), "open_external": len(issues), "open_external_prs": len(prs), "awaiting_review": len(review_requested), @@ -238,8 +303,10 @@ def build_scan(): "degraded": degraded, "next_action": ( "pick an item -> `community triage ` -> the /community session " - "assesses context, drafts the reply for human approval, and routes " - "actionable work via /start_dev_for_user; this surface posts nothing" + "assesses context, drafts the reply for human approval (a discussion " + "is answered in its thread; a confirmed bug gets an issue with a link " + "back), and routes actionable work via /start_dev_for_user; this " + "surface posts nothing" ), } @@ -247,17 +314,18 @@ def build_scan(): def print_scan(s): print("== CommunityScan — the Ears (reads only; posts nothing) ==") print(f"Self logins: {', '.join(s['self_logins'])}") + print(f"Hub (discussions): {s['hub']}") print(f"Searched: org:{s['org']}" + (f" + {len(s['extra_repos'])} non-org repo(s)" if s["extra_repos"] else "")) for d in s["degraded"]: print(f"DEGRADED: {d}") c = s["counts"] + print(f"Open discussions: {c['open_discussions']} on the hub") print(f"Open external: {c['open_external']} issue(s), {c['open_external_prs']} PR(s)" - f" (awaiting our response: {c['awaiting_response']})") + f" (awaiting our response: {c['awaiting_response']} incl. discussions)") for e in s["awaiting_response"]: days = f"{e['waiting_days']:.0f}d" if e["waiting_days"] is not None else "?" - kind = "PR " if e["type"] == "pr" else "" - print(f" ! {kind}{e['repo']}#{e['number']} [{days} waiting] @{e['author']}: {e['title'][:70]}") + print(f" ! {ref_label(e)} [{days} waiting] @{e['author']}: {e['title'][:70]}") for e in s["open_external_issues"] + s["open_external_prs"]: if not e["awaiting_response"]: state = "ours-to-watch" if e["awaiting_response"] is False else "unchecked" @@ -270,14 +338,34 @@ def print_scan(s): print(f"Next action: {s['next_action']}") -def parse_issue_ref(ref): +def ref_label(entry): + """How a conversation is named on a surface (and pasted back into + `community triage`): `owner/repo#N` for an issue, `PR owner/repo#N` for + a PR, the full URL for a discussion (`#N` would read as an issue).""" + if entry["type"] == "discussion": + return entry["url"] or f"{entry['repo']}/discussions/{entry['number']}" + kind = "PR " if entry["type"] == "pr" else "" + return f"{kind}{entry['repo']}#{entry['number']}" + + +def parse_ref(ref): + """(owner/repo, number, kind) — kind is 'discussion' for a discussion + ref, else 'conversation' (issue or PR; the fetch tells them apart).""" + m = re.match(r"(?:https?://github\.com/)?([^/#\s]+/[^/#\s]+)/discussions/(\d+)/?$", ref) + if m: + return m.group(1), int(m.group(2)), "discussion" m = re.match(r"https?://github\.com/([^/]+/[^/]+)/(?:issues|pull)/(\d+)", ref) if m: - return m.group(1), int(m.group(2)) + return m.group(1), int(m.group(2)), "conversation" m = re.match(r"([^/#\s]+/[^/#\s]+)#(\d+)$", ref) if m: - return m.group(1), int(m.group(2)) - fail(5, f"cannot parse ref '{ref}' — use a full issue/PR URL or owner/repo#N") + return m.group(1), int(m.group(2)), "conversation" + fail(5, f"cannot parse ref '{ref}' — use a full issue/PR/discussion URL or owner/repo#N") + + +def parse_issue_ref(ref): + owner_repo, number, _ = parse_ref(ref) + return owner_repo, number def pr_block(owner_repo, number): @@ -300,13 +388,7 @@ def pr_block(owner_repo, number): } -def build_triage(ref): - owner_repo, number = parse_issue_ref(ref) - issue = gh_json([f"repos/{owner_repo}/issues/{number}"]) - if issue is None: - fail(4, f"cannot fetch {owner_repo}#{number} (gh auth? does it exist?)") - body = issue.get("body") or "" - +def _signals(body): low = body.lower() present = { "code_block": "```" in body, @@ -320,9 +402,11 @@ def build_triage(ref): for key, ask in TRIAGE_SIGNALS if not present[key] ] + return present, missing - comments = gh_json([f"repos/{owner_repo}/issues/{number}/comments", "-f", "per_page=100"]) or [] - tail = [ + +def _tail(comments): + return [ { "author": (c.get("user") or {}).get("login"), "created_at": c.get("created_at"), @@ -330,6 +414,67 @@ def build_triage(ref): } for c in comments[-3:] ] + + +def build_discussion_triage(owner_repo, number): + d = gh_json([f"repos/{owner_repo}/discussions/{number}"]) + if d is None: + fail(4, f"cannot fetch discussion {owner_repo}/discussions/{number} " + "(gh auth? Discussions enabled there?)") + body = d.get("body") or "" + present, missing = _signals(body) + comments = gh_json([f"repos/{owner_repo}/discussions/{number}/comments", "-f", "per_page=100"]) or [] + tail = _tail(comments) + last = tail[-1]["author"] if tail else (d.get("user") or {}).get("login") + answered = d.get("answer_chosen_at") is not None + return { + "type": "discussion", + "pr": None, + "repo": owner_repo, + "number": number, + "url": d.get("html_url"), + "title": d.get("title", ""), + "author": (d.get("user") or {}).get("login"), + "author_is_external": not is_self(d.get("user")), + "state": d.get("state"), + "category": (d.get("category") or {}).get("name"), + "answered": answered, + "labels": [l.get("name") for l in d.get("labels", []) or []], + "body": body, + "signals_present": present, + "signals_missing": missing, + "comment_tail": tail, + "awaiting_response": (not answered) and last not in SELF_LOGINS, + "route": ( + f"answer in the thread {d.get('html_url')} — the session drafts the " + "reply, the human posts it and marks the answer; a confirmed bug -> " + "open the issue on the target repo with a link back, route it via " + "/start_dev_for_user, and mark the thread answered with the issue link" + ), + "reminders": [ + "the session judges sufficiency — these signals are heuristics, not a verdict", + "every outward reply is drafted and shown to the human before posting", + "a discussion is the user's surface: never convert it to an issue in place — " + "open the issue (reproducer required) and link both ways", + "no session can post to, answer or convert a Discussion (REST is read-only, " + "GraphQL is refused) — the human's click is the last step", + ], + } + + +def build_triage(ref): + owner_repo, number, kind = parse_ref(ref) + if kind == "discussion": + return build_discussion_triage(owner_repo, number) + issue = gh_json([f"repos/{owner_repo}/issues/{number}"]) + if issue is None: + fail(4, f"cannot fetch {owner_repo}#{number} (gh auth? does it exist?)") + body = issue.get("body") or "" + + present, missing = _signals(body) + + comments = gh_json([f"repos/{owner_repo}/issues/{number}/comments", "-f", "per_page=100"]) or [] + tail = _tail(comments) last = tail[-1]["author"] if tail else (issue.get("user") or {}).get("login") is_pr = "pull_request" in issue @@ -366,12 +511,14 @@ def build_triage(ref): def print_triage(t): - kind = "PR" if t["type"] == "pr" else "issue" + kind = t["type"] if t["type"] == "discussion" else ("PR" if t["type"] == "pr" else "issue") print(f"== CommunityTriage — {t['repo']}#{t['number']} ({kind}) ==") print(f"Title: {t['title']}") print(f"Author: @{t['author']}" + (" (external)" if t["author_is_external"] else " (self)")) print(f"State: {t['state']} Labels: {', '.join(t['labels']) or '(none)'}") + if t["type"] == "discussion": + print(f"Category: {t['category'] or '(none)'} Answered: {t['answered']}") if t["pr"]: p = t["pr"] reviewers = ", ".join(p["requested_reviewers"]) or "(none)" @@ -401,7 +548,7 @@ def main(): parser.add_argument("mode", nargs="?", default="scan", help="scan (default) | triage ") parser.add_argument("ref", nargs="?", default=None, - help="triage only: issue/PR URL or owner/repo#N") + help="triage only: issue/PR/discussion URL or owner/repo#N") parser.add_argument("--json", action="store_true") args = parser.parse_args(argv) @@ -410,7 +557,7 @@ def main(): print(json.dumps(surface, indent=2)) if args.json else print_scan(surface) elif args.mode == "triage": if not args.ref: - fail(5, "triage needs an issue ref — a full URL or owner/repo#N") + fail(5, "triage needs a ref — an issue/PR/discussion URL or owner/repo#N") surface = build_triage(args.ref) print(json.dumps(surface, indent=2)) if args.json else print_triage(surface) else: diff --git a/agents/conductors/community/community.sh b/agents/conductors/community/community.sh index b1695ede..63dd145b 100644 --- a/agents/conductors/community/community.sh +++ b/agents/conductors/community/community.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash # agents/conductors/community/community.sh — the Community Agent (a PyAutoBrain # reasoning conductor). Organism-facing name: the Ears — the organism's -# receptive language function: it hears the community (user-filed GitHub -# issues) and drafts what the organism says back; the human remains the mouth. +# receptive language function: it hears the community (the Discussions hub +# where users ask, plus user-filed GitHub issues and PRs) and drafts what the +# organism says back; the human remains the mouth. # (Wernicke to the Workspace Agent's Broca — that Voice speaks through # examples; this agent comprehends and converses.) # @@ -12,13 +13,15 @@ # labels, edits or writes anything. # # Usage: -# community.sh # scan (default): open external issues -# # + PRs, awaiting-response ranking, -# # review requests +# community.sh # scan (default): the hub's open +# # discussions + external issues/PRs, +# # awaiting-response ranking, review +# # requests # community.sh scan # same, explicit -# community.sh triage # one issue/PR -> context-sufficiency -# # surface (+ PR change-shape block); -# # = issue/PR URL or owner/repo#N +# community.sh triage # one discussion/issue/PR -> context- +# # sufficiency surface (+ PR change-shape +# # block); = a discussion/issue/PR +# # URL or owner/repo#N # community.sh ... --json # machine-readable output set -uo pipefail diff --git a/bin/pyauto-brain b/bin/pyauto-brain index 528f635d..377155b6 100755 --- a/bin/pyauto-brain +++ b/bin/pyauto-brain @@ -12,7 +12,7 @@ # CONSULT (they only opine; never dispatch or # mutate). Runnable directly for a quick read. # -# pyauto-brain community [args] (conductor) the Ears: scan/triage user-filed issues + PRs across the repos — read-only surfaces, replies stay human-gated +# pyauto-brain community [args] (conductor) the Ears: scan/triage the Discussions hub + user-filed issues/PRs across the repos — read-only surfaces, replies stay human-gated # pyauto-brain feature [args] (conductor) reason over PyAutoMind tasks, plan growth # pyauto-brain refactor [args] (conductor) plan behaviour-preserving restructuring (default-safe) # pyauto-brain workspace [args] (conductor) the Voice: plan/survey workspace + HowTo example authorship — WorkspaceDecision (writes nothing) @@ -81,7 +81,7 @@ declare -A AGENT_SCRIPT=( declare -A AGENT_DESC=( [intake]="Conceive a task: turn raw input into a formal, headed PyAutoMind prompt (files it; never starts dev)" [batch]="Compose one unattended shift: the BatchDecision, planned against the slot's REVIEW-MINUTE budget rather than a task count — proposes, never dispatches; 'batch collect' scores what came back into the review packet and stamps the batch record" - [community]="The ears — the organism's receptive function: scan/triage user-filed GitHub issues + PRs and review requests across the repos; drafts stay human-gated, dev work routes via start_dev_for_user (never posts)" + [community]="The ears — the organism's receptive function: scan/triage the Discussions hub where users ask (PyAutoMind/policy/community_surface.md) plus user-filed GitHub issues + PRs and review requests across the repos; drafts stay human-gated, dev work routes via start_dev_for_user (never posts)" [feature]="Reason over PyAutoMind feature tasks: select, size, phase, plan for start_dev" [bug]="The immune system: classify a bug/regression/Heart finding, locate the fix, plan the repair" [refactor]="The renewal function: plan behaviour-preserving restructuring — RefactorDecision; default-safe under --auto" diff --git a/board/_board.py b/board/_board.py index 134022d3..10c7a991 100755 --- a/board/_board.py +++ b/board/_board.py @@ -324,6 +324,15 @@ def fetch_badge(pages_base, repo): COMMUNITY_STALE_DAYS = 7 +def community_ref(e): + """The ref a `/community triage` chip carries: `owner/repo#N` for an + issue or PR, the thread URL for a discussion (`#N` would read as an + issue — see the conductor's `parse_ref`).""" + if e.get("type") == "discussion": + return e.get("url") or f"{e['repo']}/discussions/{e['number']}" + return f"{e['repo']}#{e['number']}" + + def _local_published_json(repo, name): """The same surface from a sibling checkout, when one is here. @@ -1114,18 +1123,19 @@ def render_md(data): c = data["community"] if c: counts = c["counts"] - L.append(f"- {counts['open_external']} external issue(s), " + L.append(f"- {counts.get('open_discussions', 0)} discussion(s) on the hub, " + f"{counts['open_external']} external issue(s), " f"{counts['open_external_prs']} external PR(s) open — " f"**{counts['awaiting_response']} awaiting our reply** " "(respond via `/community`; never auto-reply)") - awaiting_keys = {(e["repo"], e["number"]) for e in c["awaiting_response"]} + awaiting_keys = {(e.get("type"), e["repo"], e["number"]) for e in c["awaiting_response"]} for e in c["awaiting_response"]: days = (f"{e['waiting_days']:.0f}d" if e.get("waiting_days") is not None else "?") - L.append(f" - `/community triage {e['repo']}#{e['number']}` " + L.append(f" - `/community triage {community_ref(e)}` " f"[{days} waiting] @{e['author']}: {e['title'][:70]}") for e in c["open_external_issues"] + c["open_external_prs"]: - if (e["repo"], e["number"]) in awaiting_keys: + if (e.get("type"), e["repo"], e["number"]) in awaiting_keys: continue note = ("ours to watch" if e.get("awaiting_response") is False else "unchecked") @@ -1457,7 +1467,8 @@ def render_html(data): counts = c["counts"] H.append(_row( 'Replies stay human-gated in /community.' - + pills((f'{counts["open_external"]} issue(s)', ""), + + pills((f'{counts.get("open_discussions", 0)} discussion(s)', ""), + (f'{counts["open_external"]} issue(s)', "n"), (f'{counts["open_external_prs"]} PR(s)', "n"), (f'{counts["awaiting_response"]} awaiting our reply', "y" if counts["awaiting_response"] else "g")), @@ -1472,22 +1483,23 @@ def community_row(e, note, tone): """ url = e.get("url") or "" title = esc(e.get("title", "")[:80]) - kind = "PR" if e.get("type") == "pr" else "issue" + kind = e.get("type") if e.get("type") == "discussion" \ + else ("PR" if e.get("type") == "pr" else "issue") link = f'{esc(e["repo"])}#{e["number"]}' \ if url else f'{esc(e["repo"])}#{e["number"]}' return _row( f'{link} @{esc(e["author"])}: {title}' + pills((kind, ""), (note, tone)), - f"/community triage {e['repo']}#{e['number']}") + f"/community triage {community_ref(e)}") - awaiting_keys = {(e["repo"], e["number"]) for e in c["awaiting_response"]} + awaiting_keys = {(e.get("type"), e["repo"], e["number"]) for e in c["awaiting_response"]} for e in c["awaiting_response"]: waited = e.get("waiting_days") days = f"{waited:.0f}d waiting" if waited is not None else "waiting" H.append(community_row( e, days, "r" if (waited or 0) >= COMMUNITY_STALE_DAYS else "y")) for e in c["open_external_issues"] + c["open_external_prs"]: - if (e["repo"], e["number"]) in awaiting_keys: + if (e.get("type"), e["repo"], e["number"]) in awaiting_keys: continue note = ("ours to watch" if e.get("awaiting_response") is False else "unchecked") diff --git a/skills/COMMANDS.md b/skills/COMMANDS.md index 6e788e5a..fc32d518 100644 --- a/skills/COMMANDS.md +++ b/skills/COMMANDS.md @@ -31,7 +31,7 @@ readiness gate, or execution — those belong to the organs. |---------|-------|-------| | `/intake` | Intake Agent | `bin/pyauto-brain intake` → files a PyAutoMind prompt (**before** `start_dev`); `census`/`dashboard` = backlog inventory / `PyAutoMind/dashboard.md` | | `/batch` | Batch Agent | `bin/pyauto-brain batch` → the BatchDecision for one unattended shift, budgeted in review minutes; proposes only — the human's approval in the slot dispatches it; `batch collect` scores what came back | -| `/community` | Community Agent | `bin/pyauto-brain community` → scan/triage user-filed issues (read-only surfaces) → session drafts replies for human approval → `/start_dev_for_user` | +| `/community` | Community Agent | `bin/pyauto-brain community` → scan/triage the Discussions hub + user-filed issues/PRs (read-only surfaces) → session drafts replies for human approval → answer in the thread, or `/start_dev_for_user` for a report with a reproducer | | `/feature` | Feature Agent | `bin/pyauto-brain feature` → `start_dev` → `ship_*` | | `/bug` | Bug Agent | `bin/pyauto-brain bug` → `start_dev` → `ship_*` (health mode → vitals + Heart issues) | | `/refactor` | Refactor Agent | `bin/pyauto-brain refactor` → `start_dev [--auto]` → `ship_*` (behaviour-preserving; default-safe) | diff --git a/skills/GITHUB_ACCESS.md b/skills/GITHUB_ACCESS.md index 9f91fa7d..a240cbc5 100644 --- a/skills/GITHUB_ACCESS.md +++ b/skills/GITHUB_ACCESS.md @@ -113,6 +113,8 @@ leave it that way. | Create a branch | `gh api -X POST .../git/refs` | `create_branch` | | Releases | `gh release view/list` | `get_latest_release`, `list_releases`, `get_release_by_tag` | | Who am I | `gh api user` | `get_me` | +| Read the Discussions hub (list, one thread, its comments) | `gh api repos///discussions[/[/comments]]` | *(no MCP tool)* — raw REST with the session token works, see below | +| Create, answer or convert a Discussion | `gh api graphql` (`createDiscussion`) / the issue sidebar | **nobody in a session** — REST Discussions is read-only, GraphQL is refused; the human clicks (`PyAutoMind/policy/community_surface.md`) | | Be woken by CI / comments on a PR | *(no equivalent — a CLI polls)* | `subscribe_pr_activity`, `unsubscribe_pr_activity` exist but are **not to be armed** — sessions end at their deliverable; use `unsubscribe_pr_activity` only to clear a stale subscription | Tool names are given unprefixed; the harness exposes them as @@ -129,6 +131,22 @@ re-run of `/prm`, not a timer this session leaves running; `unsubscribe_pr_activity` is here only to clear a stale subscription an older run left behind. +## Measured again, 2026-09-17: raw REST works for attached repos + +The 2026-08-27 table above was measured through an installed `gh`. From a +remote session's own shell, `curl https://api.github.com/repos///...` +with `Authorization: bearer $GH_TOKEN` (the token the harness sets) **is +served** for every repository attached to the session — issues, comments, +the repo record, and the read-only Discussions endpoints +(`.../discussions`, `.../discussions/`, `.../discussions//comments`). +What is still refused, each with its own message: `api.github.com/graphql` +(every query), `search/issues` (not repository-scoped), any repo not attached +to the session, `github.com/...` HTML (403), and `POST .../discussions` (a +GitHub 404 — the REST Discussions API is read-only). So a conductor written +against `gh api repos/...` REST paths runs in a remote session by pointing +`COMMUNITY_GH` at a two-line `curl` shim; one written against GraphQL or +`search/` does not. The rule stands: do not install `gh`. + ## What the MCP surface cannot do - **Delete a remote branch.** There is no MCP tool for it, and in a proxied web diff --git a/skills/community/SKILL.md b/skills/community/SKILL.md index 27555d67..e4212ebe 100644 --- a/skills/community/SKILL.md +++ b/skills/community/SKILL.md @@ -1,6 +1,6 @@ --- name: community -description: Hear and answer the PyAuto community through the PyAutoBrain Community Agent — scan every repo for user-filed issues awaiting a response, triage one issue's context sufficiency, then draft human-approved replies and route actionable work via start_dev_for_user. Use when responding to external users' GitHub issues or checking what the community is waiting on. +description: Hear and answer the PyAuto community through the PyAutoBrain Community Agent — scan the Discussions hub and every repo for user threads awaiting a response, triage one discussion or issue's context sufficiency, then draft human-approved replies and route actionable work via start_dev_for_user. Use when responding to external users' GitHub discussions or issues, or checking what the community is waiting on. --- # Community diff --git a/skills/community/community.md b/skills/community/community.md index 7bf1a8c4..a36cc0bd 100644 --- a/skills/community/community.md +++ b/skills/community/community.md @@ -16,18 +16,22 @@ docs: `bin/pyauto-brain help community`. bin/pyauto-brain community # default mode ``` - Emits a **CommunityScan**: open issues **and PRs** authored by non-self - humans across every `repos.yaml` repo, with awaiting-response detection - (the conversation's last word is not ours) ranked by waiting time, plus - open PRs with review requested from you. `/wake_up` runs this same scan - as its community step. + Emits a **CommunityScan**: the Discussions hub's open threads (the + surface users post to — `PyAutoMind/policy/community_surface.md`; + unanswered = no accepted answer and the last word is not ours), plus open + issues **and PRs** authored by non-self humans across every `repos.yaml` + repo, with awaiting-response detection ranked by waiting time, plus open + PRs with review requested from you. The Brain board runs this same scan + as its community leg. 2. **Triage** the item the human picks: ```bash - bin/pyauto-brain community triage + bin/pyauto-brain community triage ``` + A discussion is named by its URL (`owner/repo#N` reads as an issue). + Emits context-sufficiency signals (code block, traceback, versions, expected-vs-actual, data pointer), clarifying-question seeds for whatever is missing, and the comment tail; a PR ref adds the change-shape block @@ -35,6 +39,15 @@ docs: `bin/pyauto-brain help community`. heuristics — **you** read the actual issue or PR and judge. 3. **Converse — drafts only.** Based on your judgment: + - **A discussion** → answer **in the thread**: draft the reply, the human + posts it and marks it as the answer. If the thread is a bug with a + reproducer, open the issue on the target repo (quote the thread, link + it), route that issue via `/start_dev_for_user`, and have the human mark + the thread answered with the issue link. Never convert a thread in + place, and never ask a user to re-file: the hub is *their* surface. + No session can post to, answer or convert a Discussion — the REST API + is read-only and GraphQL is refused — so the human's click is the last + step of every discussion round. - **Actionable** → route into `/start_dev_for_user ` — it owns the receipt comment, the clarification gate, the plan comment and the milestone cadence. Do not re-implement its templates here. diff --git a/tests/test_community_conductor.py b/tests/test_community_conductor.py index 8825a7eb..422e2cd5 100644 --- a/tests/test_community_conductor.py +++ b/tests/test_community_conductor.py @@ -17,9 +17,9 @@ BRAIN = BRAIN_HOME / "bin" / "pyauto-brain" SCAN_KEYS = { - "self_logins", "org", "extra_repos", "open_external_issues", - "open_external_prs", "awaiting_review", "awaiting_response", "counts", - "degraded", "next_action", + "self_logins", "org", "hub", "extra_repos", "open_discussions", + "open_external_issues", "open_external_prs", "awaiting_review", + "awaiting_response", "counts", "degraded", "next_action", } TRIAGE_KEYS = { "type", "pr", "repo", "number", "url", "title", "author", @@ -44,9 +44,30 @@ "search_org_review.json": {"items": []}, "search_extra.json": {"items": []}, "comments.json": [], + "discussions.json": [], + "discussion_comments.json": [], } +def _discussion(hub, number, login, title, comments=0, answered=False, + category="Q&A", state="open", locked=False): + return { + "number": number, + "title": title, + "user": {"login": login, "type": "User"}, + "html_url": f"https://github.com/{hub}/discussions/{number}", + "category": {"name": category, "slug": category.lower(), "is_answerable": True}, + "answer_chosen_at": "2026-07-11T00:00:00Z" if answered else None, + "labels": [], + "comments": comments, + "state": state, + "locked": locked, + "body": "", + "updated_at": "2026-07-10T00:00:00Z", + "repository_url": f"https://api.github.com/repos/{hub}", + } + + def _item(repo, number, login, title, comments=0, user_type="User"): return { "number": number, @@ -81,6 +102,9 @@ def _fabricate(tmp_path, fixtures): q=org:*is:issue*) cat "{fixture_dir}/search_org_issues.json"; exit 0 ;; q=org:*is:pr*) cat "{fixture_dir}/search_org_prs.json"; exit 0 ;; q=repo:*) cat "{fixture_dir}/search_extra.json"; exit 0 ;; + repos/*/discussions/*/comments) cat "{fixture_dir}/discussion_comments.json"; exit 0 ;; + repos/*/discussions/*) cat "{fixture_dir}/discussion.json"; exit 0 ;; + repos/*/discussions) cat "{fixture_dir}/discussions.json"; exit 0 ;; */comments) cat "{fixture_dir}/comments.json"; exit 0 ;; repos/*/pulls/*) cat "{fixture_dir}/pull.json"; exit 0 ;; repos/*/issues/*) cat "{fixture_dir}/issue.json"; exit 0 ;; @@ -122,7 +146,7 @@ def test_scan_json_is_a_complete_surface_and_filters_bots(tmp_path): assert [e["author"] for e in s["open_external_issues"]] == ["some_user"] assert s["open_external_issues"][0]["type"] == "issue" assert s["counts"] == { - "open_external": 1, "open_external_prs": 0, + "open_discussions": 0, "open_external": 1, "open_external_prs": 0, "awaiting_review": 0, "awaiting_response": 1, } # Uncommented external issue: the author had the last word -> awaiting us. @@ -245,5 +269,76 @@ def test_scan_degrades_honestly_when_search_fails(tmp_path): assert r.returncode == 0, r.stderr s = json.loads(r.stdout) assert s["counts"]["open_external"] == 0 - # 2 qualifier groups (org + non-org) x 3 searches (issue, pr, review). - assert len(s["degraded"]) == 6 + # 2 qualifier groups (org + non-org) x 3 searches (issue, pr, review), + # plus the hub's discussions listing. + assert len(s["degraded"]) == 7 + assert any("discussions" in d for d in s["degraded"]) + + +HUB = "PyAutoLabs/.github" + + +def test_scan_hears_the_hub_and_only_unanswered_threads_await(tmp_path): + """The Discussions hub (policy/community_surface.md) is scanned beside + the trackers: an accepted answer settles a thread without a comment + lookup; otherwise the last word decides, as for an issue. Closed, + locked and bot threads never surface.""" + stub = _fabricate(tmp_path, { + **EMPTY_SEARCHES, + "discussions.json": [ + _discussion(HUB, 11, "asker", "how do I mask my data?"), + _discussion(HUB, 12, "asker", "answered already", comments=2, answered=True), + _discussion(HUB, 13, "asker", "we replied last", comments=1), + _discussion(HUB, 14, "asker", "converted issue", state="closed"), + _discussion(HUB, 15, "asker", "locked thread", locked=True), + {**_discussion(HUB, 16, "dependabot[bot]", "bot post"), + "user": {"login": "dependabot[bot]", "type": "Bot"}}, + ], + "discussion_comments.json": [{"user": {"login": "Jammy2211"}, "body": "hi"}], + }) + r = _run(["scan", "--json"], tmp_path, stub) + assert r.returncode == 0, r.stderr + s = json.loads(r.stdout) + assert s["hub"] == HUB + assert s["counts"]["open_discussions"] == 3 + assert {d["number"] for d in s["open_discussions"]} == {11, 12, 13} + by_number = {d["number"]: d for d in s["open_discussions"]} + assert by_number[11]["awaiting_response"] is True + assert by_number[12]["awaiting_response"] is False and by_number[12]["answered"] + assert by_number[13]["awaiting_response"] is False + assert [e["number"] for e in s["awaiting_response"]] == [11] + assert s["awaiting_response"][0]["type"] == "discussion" + assert s["awaiting_response"][0]["url"].endswith("/discussions/11") + # The human-readable surface names a discussion by its URL — `#N` + # would read as an issue when pasted back into `triage`. + text = _run(["scan"], tmp_path, stub).stdout + assert f"https://github.com/{HUB}/discussions/11" in text + assert "Open discussions: 3 on the hub" in text + + +def test_triage_discussion_ref_routes_to_the_thread(tmp_path): + stub = _fabricate(tmp_path, { + **EMPTY_SEARCHES, + "discussion.json": _discussion( + HUB, 11, "asker", "how do I mask my data?", comments=1), + "discussion_comments.json": [ + {"user": {"login": "asker"}, "created_at": "2026-07-10T01:00:00Z", + "body": "still stuck"}, + ], + }) + for ref in (f"https://github.com/{HUB}/discussions/11", f"{HUB}/discussions/11"): + r = _run(["triage", ref, "--json"], tmp_path, stub) + assert r.returncode == 0, r.stderr + t = json.loads(r.stdout) + assert set(t) >= TRIAGE_KEYS | {"category", "answered"} + assert t["type"] == "discussion" and t["pr"] is None + assert t["repo"] == HUB and t["number"] == 11 + assert t["author_is_external"] and t["awaiting_response"] + assert t["category"] == "Q&A" and t["answered"] is False + assert "answer in the thread" in t["route"] + assert "/start_dev_for_user" in t["route"] + # Nothing in the run hit the issues endpoints for a discussion ref. + calls = (tmp_path / "gh_calls.log").read_text() + assert "/issues/" not in calls + text = _run(["triage", f"{HUB}/discussions/11"], tmp_path, stub).stdout + assert "(discussion)" in text and "Category: Q&A" in text