closing-issues
Close a GitHub issue with a synthesis comment as a flowing graph — validate the synthesis, post the closing comment, close, then run a pluggable callback (e.g. memory store) detached. Use when closing an issue should also capture the LEARNING (not just the diff log) and when the
Install
npx skills add https://github.com/oaustegard/claude-skills/tree/main/plugins/github-and-git/skills/closing-issues
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install oaustegard-claude-skills@llmmart
git clone https://github.com/oaustegard/claude-skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole oaustegard/claude-skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Closing Issues
A flowing graph that turns "close GitHub issue + capture what I learned"
into a structural DAG. The synthesis text is validated upfront, the close
happens against the GitHub API, and an optional post-close callback runs
detached so the close ack is unblocked.
from closing_issues import close_issue
result = close_issue(
repo="owner/repo",
number=42,
synthesis=(
"Pattern X works because of Y. Constraint: don't apply to Z. "
"Future note: revisit when feature Q lands."
),
)
print(result["issue_url"]) # https://github.com/.../issues/42
print(result["comment_url"]) # ...#issuecomment-...
Why a synthesis, not a "done" comment
Closing an issue produces two artifacts:
- The Issue itself — implementation log. The diff and commit history already show what was done.
- The closing comment / synthesis — what was learned. Lasts longer than the diff in mental cache.
Good closing comments lead with why, not what. Failure modes, constraints discovered, alternatives rejected. The synthesis is the seed of an institutional memory.
Internal shape
prepare_synthesis ──▶ close_github_issue [terminal]
│
└──▶ post_close_callback [detached, when=callback]
validate=must_have_synthesis_textruns against the raw input string. Empty or whitespace-only → FAILED with no GitHub API call. This is structural: callers can't accidentally close-with-no-text.close_github_issueposts the synthesis as a comment, then PATCHes the issue tostate=closed, state_reason=completed. Returns the issue URL and comment URL.post_close_callback(optional) runs detached. Caller plugs in any extra work — store synthesis in a memory system, ping a tracker, emit a webhook. Failure here lands inresult["detached_failures"]and does NOT bubble up as a close failure. Skipped viawhen=if the callback isn't provided.
Pluggable post-close callback
def store_in_my_memory(synthesis: str, issue_url: str, repo: str, number: int):
# Whatever your memory layer is — Turso, sqlite, a JSON file, etc.
db.execute("INSERT INTO learnings (issue, synthesis) VALUES (?, ?)",
(issue_url, synthesis))
return {"stored": True}
result = close_issue(
repo="owner/repo",
number=42,
synthesis="...",
post_close_callback=store_in_my_memory,
)
if result["callback_result"] is None and result["detached_failures"]:
# The callback failed but the issue is still closed.
print("Memory store failed:", result["detached_failures"])
The callback receives keyword arguments: synthesis, issue_url,
repo, number. Anything it returns goes into
result["callback_result"].
Result shape
{
"issue_url": "https://github.com/owner/repo/issues/N",
"comment_url": "https://github.com/.../issues/N#issuecomment-...",
"comment_id": 12345,
"callback_result": <whatever the callback returned, or None>,
"detached_failures": [], # populated if callback raised
}
Raises RuntimeError only if the GitHub close itself fails. Callback
failures are detached.
Auth
Requires GH_TOKEN (or GITHUB_TOKEN) in the environment. Classic PAT
or fine-grained PAT with repo scope (specifically issues:write).
When NOT to use
- Closing an issue without a synthesis. If you genuinely have nothing
to say beyond "done," just
gh issue close Ndirectly. This skill is for the synthesis use case. - Closing many issues at once (use a script that calls this in a loop — fine, but the flow setup cost per call is small but not zero).
See also
flowing— the DAG runner this skill is built onopening-prs— the symmetric "open and merge" flow
Files (claude-skills)
-
scripts
-
closing_issues.py 5.5 KB
""" closing_issues — close a GitHub issue with a synthesis comment as a flowing graph, with an optional pluggable post-close callback. The synthesis text is `validate=`d upfront; the close happens against the GitHub API; an optional callback runs `detached=True` so its failure doesn't bubble up as a close failure. See SKILL.md for the full picture. """ from __future__ import annotations import json import os import urllib.request from collections.abc import Callable # The flowing skill is canonical. Try the package layout first; fall # back to importing it from the canonical install path. try: from flowing import Flow, StepState, task # type: ignore except ImportError: # pragma: no cover — defensive only import importlib.util as _ilu import sys as _sys _SKILL = "/mnt/skills/user/flowing/scripts/flowing.py" if not os.path.exists(_SKILL): raise ImportError( "closing_issues requires the flowing skill at " f"{_SKILL} or `from flowing import ...` on the python path" ) _spec = _ilu.spec_from_file_location("flowing", _SKILL) _flow = _ilu.module_from_spec(_spec) _sys.modules["flowing"] = _flow _spec.loader.exec_module(_flow) task, Flow, StepState = _flow.task, _flow.Flow, _flow.StepState # ── GitHub helpers ───────────────────────────────────────────────── GITHUB_USER_AGENT = "closing-issues" def _gh_token() -> str: return os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN") or "" def _gh_api(method: str, endpoint: str, data: dict | None = None) -> dict: token = _gh_token() if not token: raise RuntimeError( "GH_TOKEN (or GITHUB_TOKEN) not set — closing-issues needs an " "authenticated PAT. See SKILL.md > Auth." ) url = f"https://api.github.com{endpoint}" if endpoint.startswith("/") else endpoint body = json.dumps(data).encode() if data else None req = urllib.request.Request(url, data=body, method=method, headers={ "User-Agent": GITHUB_USER_AGENT, "Authorization": f"token {token}", "Content-Type": "application/json", "Accept": "application/vnd.github+json", }) return json.loads(urllib.request.urlopen(req).read()) def _post_close_comment(repo: str, number: int, body: str) -> dict: return _gh_api("POST", f"/repos/{repo}/issues/{number}/comments", {"body": body}) def _close_issue(repo: str, number: int, state_reason: str = "completed") -> dict: return _gh_api( "PATCH", f"/repos/{repo}/issues/{number}", {"state": "closed", "state_reason": state_reason}, ) # ── Public API ───────────────────────────────────────────────────── def close_issue( repo: str, number: int, synthesis: str, *, post_close_callback: Callable | None = None, state_reason: str = "completed", ) -> dict: """Close a GitHub issue with a synthesis comment. See SKILL.md for full argument and result shape documentation. """ def must_have_synthesis_text(**deps): if not synthesis or not synthesis.strip(): raise ValueError( "synthesis is empty or whitespace — close_issue needs the " "LEARNING text. The diff already shows what was done." ) @task(name="prepare_synthesis", validate=must_have_synthesis_text) def prepare_synthesis(): return synthesis.strip() @task(name="close_github_issue", depends_on=[prepare_synthesis]) def close_github_issue(prepare_synthesis): comment = _post_close_comment(repo, number, prepare_synthesis) _close_issue(repo, number, state_reason=state_reason) return { "issue_url": f"https://github.com/{repo}/issues/{number}", "comment_url": comment.get("html_url"), "comment_id": comment.get("id"), } @task( name="post_close_callback", depends_on=[close_github_issue, prepare_synthesis], when=lambda **_: post_close_callback is not None, detached=True, ) def post_close_callback_node(close_github_issue, prepare_synthesis): # mypy-style guard: when= would have skipped if None. cb = post_close_callback return cb( synthesis=prepare_synthesis, issue_url=close_github_issue["issue_url"], repo=repo, number=number, ) flow = Flow(close_github_issue) flow.run() close_state = flow.results.get(close_github_issue.name) if close_state is None or close_state.state != StepState.SUCCEEDED: for r in flow.results.values(): if r.state == StepState.FAILED and r.error is not None: raise RuntimeError( f"close_issue: {r.name} failed: {r.error}" ) from r.error raise RuntimeError("close_issue: close did not succeed") closed = close_state.value cb_state = flow.results.get(post_close_callback_node.name) callback_result = ( cb_state.value if cb_state is not None and cb_state.state == StepState.SUCCEEDED else None ) detached_failures = [(r.name, str(r.error)) for r in flow.detached_failures] return { "issue_url": closed["issue_url"], "comment_url": closed.get("comment_url"), "comment_id": closed.get("comment_id"), "callback_result": callback_result, "detached_failures": detached_failures, }
-
-
tests
-
test_closing_issues.py 5.2 KB
""" Tests for closing-issues.closing_issues.close_issue. Verifies: - happy path (no callback): close + comment, no callback fires - happy path (with callback): close + comment + callback runs detached - validate=must_have_synthesis_text rejects empty/whitespace - close failure raises (main DAG); no callback fires - callback failure does NOT raise; surfaces in detached_failures - missing GH_TOKEN raises before any API call """ from __future__ import annotations import sys from pathlib import Path from unittest.mock import MagicMock THIS_DIR = Path(__file__).resolve().parent SCRIPTS_DIR = THIS_DIR.parent / "scripts" SKILL_ROOT = THIS_DIR.parent SKILLS_PARENT = SKILL_ROOT.parent sys.path.insert(0, str(SKILLS_PARENT / "flowing" / "scripts")) import flowing as _flowing sys.modules.setdefault("flowing", _flowing) import importlib.util spec = importlib.util.spec_from_file_location( "closing_issues_under_test", SCRIPTS_DIR / "closing_issues.py" ) ci = importlib.util.module_from_spec(spec) sys.modules["closing_issues_under_test"] = ci spec.loader.exec_module(ci) def _patch_externals(monkeypatch, *, close_raises=False): if close_raises: monkeypatch.setattr(ci, "_post_close_comment", MagicMock(side_effect=RuntimeError("GH 422"))) else: monkeypatch.setattr(ci, "_post_close_comment", MagicMock(return_value={ "id": 999, "html_url": "https://github.com/o/r/issues/1#issuecomment-999", })) monkeypatch.setattr(ci, "_close_issue", MagicMock(return_value={"state": "closed"})) def _ensure_token(monkeypatch): monkeypatch.setenv("GH_TOKEN", "test-token") def test_happy_path_no_callback(monkeypatch): _ensure_token(monkeypatch) _patch_externals(monkeypatch) result = ci.close_issue( repo="o/r", number=42, synthesis="Pattern X works because of Y. Constraint: Z.", ) assert result["issue_url"] == "https://github.com/o/r/issues/42" assert result["comment_url"].endswith("#issuecomment-999") assert result["callback_result"] is None assert result["detached_failures"] == [] assert ci._post_close_comment.call_count == 1 assert ci._close_issue.call_count == 1 def test_happy_path_with_callback(monkeypatch): _ensure_token(monkeypatch) _patch_externals(monkeypatch) callback = MagicMock(return_value={"stored": True, "id": "mem-1"}) result = ci.close_issue( repo="o/r", number=43, synthesis="Learned about flowing graphs.", post_close_callback=callback, ) assert result["callback_result"] == {"stored": True, "id": "mem-1"} assert callback.call_count == 1 # Callback receives the four kwargs. cb_kwargs = callback.call_args.kwargs assert cb_kwargs["synthesis"] == "Learned about flowing graphs." assert cb_kwargs["issue_url"].endswith("/issues/43") assert cb_kwargs["repo"] == "o/r" assert cb_kwargs["number"] == 43 def test_validate_blocks_empty_synthesis(monkeypatch): _ensure_token(monkeypatch) _patch_externals(monkeypatch) callback = MagicMock() try: ci.close_issue( repo="o/r", number=44, synthesis=" \n\t", post_close_callback=callback, ) except RuntimeError as e: assert "synthesis" in str(e).lower() else: raise AssertionError("expected RuntimeError on empty synthesis") # No GitHub API calls and no callback. assert ci._post_close_comment.call_count == 0 assert ci._close_issue.call_count == 0 assert callback.call_count == 0 def test_close_failure_raises_no_callback(monkeypatch): _ensure_token(monkeypatch) _patch_externals(monkeypatch, close_raises=True) callback = MagicMock() try: ci.close_issue( repo="o/r", number=45, synthesis="real synthesis", post_close_callback=callback, ) except RuntimeError as e: assert "GH 422" in str(e) else: raise AssertionError("expected RuntimeError on close failure") assert callback.call_count == 0 def test_callback_failure_is_detached_no_raise(monkeypatch): _ensure_token(monkeypatch) _patch_externals(monkeypatch) callback = MagicMock(side_effect=RuntimeError("memory store down")) result = ci.close_issue( repo="o/r", number=46, synthesis="real synthesis", post_close_callback=callback, ) # Close still succeeded. assert result["issue_url"].endswith("/issues/46") # Callback failed but didn't propagate. assert result["callback_result"] is None failures = dict(result["detached_failures"]) assert "post_close_callback" in failures assert "memory store down" in failures["post_close_callback"] def test_missing_token_raises_before_api(monkeypatch): monkeypatch.delenv("GH_TOKEN", raising=False) monkeypatch.delenv("GITHUB_TOKEN", raising=False) try: ci._gh_api("GET", "/repos/x/y") except RuntimeError as e: assert "GH_TOKEN" in str(e) else: raise AssertionError("expected RuntimeError on missing token") if __name__ == "__main__": import pytest sys.exit(pytest.main([__file__, "-v"]))
-
-
CHANGELOG.md 278 B
# closing-issues - Changelog All notable changes to the `closing-issues` skill are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.1.0] - 2026-05-08 ### Other - Add opening-prs and closing-issues skills (#624) -
SKILL.md 4.2 KB
--- name: closing-issues description: Close a GitHub issue with a synthesis comment as a flowing graph — validate the synthesis, post the closing comment, close, then run a pluggable callback (e.g. memory store) detached. Use when closing an issue should also capture the LEARNING (not just the diff log) and when the post-close work shouldn't block the close ack. metadata: version: 0.1.0 requires: flowing --- # Closing Issues A `flowing` graph that turns "close GitHub issue + capture what I learned" into a structural DAG. The synthesis text is validated upfront, the close happens against the GitHub API, and an optional post-close callback runs detached so the close ack is unblocked. ```python from closing_issues import close_issue result = close_issue( repo="owner/repo", number=42, synthesis=( "Pattern X works because of Y. Constraint: don't apply to Z. " "Future note: revisit when feature Q lands." ), ) print(result["issue_url"]) # https://github.com/.../issues/42 print(result["comment_url"]) # ...#issuecomment-... ``` ## Why a synthesis, not a "done" comment Closing an issue produces two artifacts: - **The Issue itself** — implementation log. The diff and commit history already show *what* was done. - **The closing comment / synthesis** — what was *learned*. Lasts longer than the diff in mental cache. Good closing comments lead with *why*, not *what*. Failure modes, constraints discovered, alternatives rejected. The synthesis is the seed of an institutional memory. ## Internal shape ``` prepare_synthesis ──▶ close_github_issue [terminal] │ └──▶ post_close_callback [detached, when=callback] ``` - **`validate=must_have_synthesis_text`** runs against the raw input string. Empty or whitespace-only → FAILED with no GitHub API call. This is structural: callers can't accidentally close-with-no-text. - **`close_github_issue`** posts the synthesis as a comment, then PATCHes the issue to `state=closed, state_reason=completed`. Returns the issue URL and comment URL. - **`post_close_callback`** (optional) runs detached. Caller plugs in any extra work — store synthesis in a memory system, ping a tracker, emit a webhook. Failure here lands in `result["detached_failures"]` and does NOT bubble up as a close failure. Skipped via `when=` if the callback isn't provided. ## Pluggable post-close callback ```python def store_in_my_memory(synthesis: str, issue_url: str, repo: str, number: int): # Whatever your memory layer is — Turso, sqlite, a JSON file, etc. db.execute("INSERT INTO learnings (issue, synthesis) VALUES (?, ?)", (issue_url, synthesis)) return {"stored": True} result = close_issue( repo="owner/repo", number=42, synthesis="...", post_close_callback=store_in_my_memory, ) if result["callback_result"] is None and result["detached_failures"]: # The callback failed but the issue is still closed. print("Memory store failed:", result["detached_failures"]) ``` The callback receives keyword arguments: `synthesis`, `issue_url`, `repo`, `number`. Anything it returns goes into `result["callback_result"]`. ## Result shape ```python { "issue_url": "https://github.com/owner/repo/issues/N", "comment_url": "https://github.com/.../issues/N#issuecomment-...", "comment_id": 12345, "callback_result": <whatever the callback returned, or None>, "detached_failures": [], # populated if callback raised } ``` Raises `RuntimeError` only if the GitHub close itself fails. Callback failures are detached. ## Auth Requires `GH_TOKEN` (or `GITHUB_TOKEN`) in the environment. Classic PAT or fine-grained PAT with `repo` scope (specifically `issues:write`). ## When NOT to use - Closing an issue without a synthesis. If you genuinely have nothing to say beyond "done," just `gh issue close N` directly. This skill is for the synthesis use case. - Closing many issues at once (use a script that calls this in a loop — fine, but the flow setup cost per call is small but not zero). ## See also - `flowing` — the DAG runner this skill is built on - `opening-prs` — the symmetric "open and merge" flow
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.