@bbcsoftwarefactory/commands 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ ---
2
+ name: daily
3
+ description: "Trigger: /daily, daily, refresh, qué tenemos para hoy, dónde quedamos, revisar issues y PRs, seguimiento de backlog. Daily refresh: fetch origin, see where we left off, triage open GitHub issues, and audit open PRs for CI checks and merge conflicts."
4
+ disable-model-invocation: true
5
+ license: Apache-2.0
6
+ metadata:
7
+ author: bbc-skill-internals
8
+ version: "1.4"
9
+ pre_hook: "gh auth status && git fetch origin --prune; tool-depot (github-read / github-write)"
10
+ post_hook: "question-gate (triage-question.py) + Quest-Tree HUD"
11
+ post_install: "npx --full-depth; copy adapters/gemini.toml + /commands reload (Gemini); server restart (Zed ACP)"
12
+ adapters: "adapters/command.md, adapters/gemini.toml"
13
+ ---
14
+
15
+ ## Activation Contract
16
+
17
+ Run only when a person explicitly invokes `/daily` (or asks to run `daily` as a refresh/standup check). It audits issues and PRs, **drafts** follow-up comments, and posts only the comments the person approves at the closing `🟡 BOSS GATE`.
18
+
19
+ Optional arguments:
20
+ - `--dry-run`: Audit and render the daily HUD report without drafting or posting any GitHub comments.
21
+ - `#<number>` (or `<number>`): Prioritize or filter the issue/PR triage to that specific number.
22
+
23
+ Granted authority upon explicit `/daily` invocation:
24
+ - `A1` (Read-only repo & GitHub): `git remote`, `git fetch`, read-only code search, and GitHub reads through `gh api` (REST) under Tool Depot `github-read` (`read-approved-issue-or-pr`, `read-pr-review-and-checks`). Use REST, not `gh issue` / `gh pr`: those subcommands use GraphQL, which some hosts (for example Claude Code cloud sessions) refuse. Never edit files or switch branches in the main checkout.
25
+ - `A2` (Issue follow-up comments): Draft at most 1 useful comment per open issue, with an anti-duplicate guard when the latest comment is already a recent `daily` check with no new human or PR activity. Invoking `/daily` does **not** authorize posting: the Tool Depot catalog requires authorization for the exact target. List every draft (issue number + text) in the `🟡 BOSS GATE` and post only the approved ones, each as `github-write` / `comment-approved-issue` recorded in the delivery ledger when one exists, and each following the [visual reference rule](../../skills/delivery-coordinator/references/visual-reference.md) (an image, or a `🟡 GAP visual` line).
26
+
27
+ ## Hard Rules
28
+
29
+ - Never close or edit issues (`gh issue close`, `gh issue edit`), never push or merge PRs, and never modify files in the main checkout without explicit human approval at the closing `🟡 BOSS GATE`.
30
+ - If `tool-depot`, `issue-reviewer`, `question-gate`, or `delivery-coordinator` are present in the active project or user skills directory, follow their contracts; never assume unverified companions or hardcode user-specific machine paths.
31
+ - Check `gh auth status` first. If `gh` is missing or unauthenticated, stop and report the blocker.
32
+ - Match each issue comment to the issue's language (`es` / `en` / `pt`), and match the final chat HUD to the user's language.
33
+ - Never guess the contents of unreadable attachments or claim an issue is resolved without verified evidence (merged PR + commit on `origin/<default-branch>` + code verification).
34
+
35
+ ## Decision Gates
36
+
37
+ | Situation | Action |
38
+ |---|---|
39
+ | `--dry-run` passed | Run all read-only checks and render HUD; draft and post no comments |
40
+ | Issue has image/file attachments and `issue-reviewer/scripts/fetch-issue-attachments.py` is installed | Download and visually inspect attachments before classifying the issue |
41
+ | Issue is already fixed (merged PR + commit on `origin/<default-branch>` + verified in code) | Draft a comment with PR link, merge commit, and verified code location (unless `--dry-run`); queue it and the close candidate in `🟡 BOSS GATE` |
42
+ | Issue is open and latest comment is already an unchanged `daily` (or legacy `allio`) follow-up | Skip commenting (`⚪ Sin cambios` / `unchanged`) to avoid duplicate noise |
43
+ | Issue is open and unresolved (pending / in-progress PR / blocked) | Draft 1 concrete follow-up comment (unless `--dry-run`) stating observed state, what was checked, and next recommended step; queue it in `🟡 BOSS GATE` |
44
+ | Claim status `duplicate-work` (`CL11`: several open PRs for one issue) | `🔴 Duplicate work`: list the PRs and their authors; queue in `🟡 BOSS GATE` for the Tech Lead to keep one. Never close a PR. |
45
+ | Claim status `stale-claim` (`CL12`) or `orphan-claim` (`CL6`) | `🟡 Stale claim`: draft 1 comment asking the holder whether the work continues (unless `--dry-run`); queue it and a release proposal in `🟡 BOSS GATE`. Never unassign anyone. |
46
+ | PR `mergeable` is `null` (GitHub still computing) | Wait 2–3 seconds and re-query `gh api repos/<owner>/<repo>/pulls/<pr>` once |
47
+ | PR has conflicts (`CONFLICTING` / `DIRTY`) | Diagnose exact conflicting files without touching main checkout (`git merge-tree --write-tree` or temporary detached worktree), report files, and offer resolution in `🟡 BOSS GATE` |
48
+
49
+ ## Execution Steps
50
+
51
+ 1. **Identify repo and fetch origin**
52
+ - Run `git rev-parse --show-toplevel`, `git remote -v`, and `git ls-remote --symref origin HEAD` to detect `<owner>/<repo>` and `<default-branch>`.
53
+ - Verify `gh auth status`, then run `git fetch origin --prune`.
54
+
55
+ 2. **Audit open issues**
56
+ - Run `gh api "repos/<owner>/<repo>/issues?state=open&per_page=50" --jq '[.[] | select(.pull_request == null)]'` (the endpoint also returns PRs; the filter drops them). Filter by `#<n>` if provided. If empty, record `🟢 0 open issues` and continue to step 3.
57
+ - For each open issue:
58
+ - Read body and comments via `gh api -H "Accept: application/vnd.github.full+json" repos/<owner>/<repo>/issues/<n>` and `gh api repos/<owner>/<repo>/issues/<n>/comments`.
59
+ - If attachments exist and `issue-reviewer` is available, run `python3 -I -B <issue-reviewer>/scripts/fetch-issue-attachments.py --repo <owner/repo> --issue <n>` and inspect them before judging status.
60
+ - Cross-check related PRs (`gh api -X GET search/issues -f q='repo:<owner>/<repo> is:pr <terms>'`), commits on `origin/<default-branch>` (`git log origin/<default-branch> --oneline -n 50 --grep="..."`), and current code (`rg` / file read).
61
+ - Classify as resolved (Case A) or pending/in-progress/blocked (Case B) and apply the Decision Gates above.
62
+ - Check who holds it with the [claim rules](../../skills/delivery-coordinator/references/issue-claim.md), when `delivery-coordinator` is installed: save the issue (`gh api repos/<owner>/<repo>/issues/<n>`), and once per run the open PRs (`gh api --paginate --slurp "repos/<owner>/<repo>/pulls?state=open&per_page=100"`) and claim branches (`git ls-remote --heads origin "feat/*"`), then run `python3 -I -B <delivery-coordinator>/scripts/check-issue-claim.py --phase status --issue-json <issue> --pulls-json <pulls> --branches <branches> --repo <owner>/<repo>`. Report `claimed` with the holder, and apply the claim rows above for `duplicate-work`, `stale-claim`, or `orphan-claim`.
63
+
64
+ 3. **Audit open PRs (CI checks & conflicts)**
65
+ - Run `gh api "repos/<owner>/<repo>/pulls?state=open&per_page=50"`.
66
+ - For each open PR, run `gh api repos/<owner>/<repo>/pulls/<pr>` (`mergeable`, `mergeable_state`, `draft`, `head.sha`, `base.ref`), `gh api "repos/<owner>/<repo>/commits/<head.sha>/check-runs?per_page=100"` (`name`, `status`, `conclusion`), and `gh api repos/<owner>/<repo>/pulls/<pr>/reviews` for the review state.
67
+ - Classify each PR:
68
+ - `🟢 Green`: `mergeable: true` / `mergeable_state: clean`, every check run `conclusion: success` (or `skipped`/`neutral`), not draft (note if a review is still required or if duplicate/stacked PRs exist).
69
+ - `🟡 Pending / Draft`: a check run with `status` other than `completed`, or `draft: true`.
70
+ - `🔴 Failing CI`: list failed check names and observable causes/links.
71
+ - `🔴 Conflicts` (`mergeable: false` / `mergeable_state: dirty`): fetch `pull/<pr>/head:refs/remotes/origin/pr/<pr>` and run `git merge-tree --write-tree origin/<base.ref> refs/remotes/origin/pr/<pr>` (or use a temporary detached worktree to run `git merge --no-commit --no-ff`, list `git diff --name-only --diff-filter=U`, abort, and remove the temporary worktree).
72
+
73
+ 4. **Gate & report**
74
+ - If `question-gate` (`triage-question.py`) is installed and any human decision remains (comment drafts to post, conflicted PRs, resolved issues ready to close, or green PRs ready to merge), validate the closing prompt before replying.
75
+ - List each comment draft in the `🟡 BOSS GATE` as `#<n>: <first line of the draft>`, so the person approves exact targets (all, some by number, or none).
76
+
77
+ 5. **Post approved comments** (only after the person answers the gate)
78
+ - For each approved issue, request `github-write` / `comment-approved-issue` from Tool Depot for that exact issue, then post with `gh api -X POST repos/<owner>/<repo>/issues/<n>/comments -F body=@<draft-file>`. Record the request and the use, with its `visual`, in the delivery ledger when one exists.
79
+ - Never post a draft that was not approved, and never widen an approval to issues that were not listed.
80
+
81
+ ## Output Contract
82
+
83
+ Render a compact **Quest-Tree HUD** matching the user's language (`es` / `en` / `pt`):
84
+
85
+ ```text
86
+ 🎮 DAILY ─ <owner>/<repo> (base: <default-branch> · <short-sha>)
87
+ │ 🔄 Fetch: 🟢 origin updated
88
+ │
89
+ ├── 📋 Open issues (<total>)
90
+ │ ├── #<n> <title> ············ 🟢 Resolved → PR #<pr> (comment drafted)
91
+ │ ├── #<m> <title> ············ 🟡 Pending → Follow-up drafted
92
+ │ ├── #<c> <title> ············ 🔴 Duplicate work → PR #<a> @<x> · PR #<b> @<y>
93
+ │ ├── #<s> <title> ············ 🟡 Stale claim → @<holder>, 9 days idle
94
+ │ └── #<k> <title> ············ ⚪ Unchanged (duplicate skipped)
95
+ │
96
+ └── 🔀 Open PRs (<total>)
97
+ ├── #<p> <title> ············ 🟢 Green (checks OK · ready/review)
98
+ ├── #<q> <title> ············ 🔴 Failing checks (<check name>)
99
+ └── #<r> <title> ············ 🔴 Conflict vs <base> (<files>)
100
+ ```
101
+
102
+ If any action requires human approval (posting comment drafts, resolving conflicts + pushing, closing verified resolved issues, or merging green PRs), close with a single `🟡 BOSS GATE` offering `[A]` / `[B]`; otherwise close with `🏁 STAGE CLEAR`. After approved comments are posted, report them as `commented` in a short follow-up.
103
+
104
+ When several open issues already have a merged PR, or `needs-info` without an answer, point to [`/issue-clean-and-close`](../issue-clean-and-close/SKILL.md) for the bulk cleanup instead of drafting one comment each. Do not draft a comment that repeats an `<!-- issue-sweeper:… -->` comment newer than the issue's last activity.
105
+
106
+ ## References
107
+
108
+ - [Issue cleanup (`/issue-clean-and-close`)](../issue-clean-and-close/SKILL.md)
109
+ - [Install guide for Cursor, Zed, Claude Code, Claude, and Gemini](../../INSTALLATION.md)
110
+ - [Question Gate](../../skills/question-gate/SKILL.md)
111
+ - [Issue Reviewer](../../skills/issue-reviewer/SKILL.md)
112
+ - [Tool Depot catalog](../../skills/tool-depot/references/tool-catalog.json)
@@ -0,0 +1,17 @@
1
+ ---
2
+ description: Daily refresh: fetch origin, see where we left off, triage open GitHub issues, and audit open PRs for CI checks and conflicts (/daily)
3
+ ---
4
+
5
+ # /daily
6
+
7
+ Read and execute `SKILL.md` from the first existing path (single source of truth; do not duplicate or summarize its steps here):
8
+
9
+ 1. `.cursor/skills/daily/SKILL.md`
10
+ 2. `.claude/skills/daily/SKILL.md`
11
+ 3. `.agents/skills/daily/SKILL.md`
12
+ 4. `~/.cursor/skills/daily/SKILL.md`
13
+ 5. `~/.claude/skills/daily/SKILL.md`
14
+ 6. `~/.agents/skills/daily/SKILL.md`
15
+ 7. `commands/daily/SKILL.md`
16
+
17
+ Optional argument: `--dry-run` (read-only audit without posting GitHub comments) or an issue/PR number (`/daily #51`).
@@ -0,0 +1,17 @@
1
+ description = "Daily refresh: fetch origin, triage open GitHub issues, and audit open PRs for CI checks and conflicts (/daily)."
2
+
3
+ prompt = """
4
+ Execute the `/daily` command workflow from its single source of truth `SKILL.md`.
5
+
6
+ First, locate and read `SKILL.md` from the first existing path:
7
+ 1. `.gemini/skills/daily/SKILL.md`
8
+ 2. `.agents/skills/daily/SKILL.md`
9
+ 3. `~/.gemini/skills/daily/SKILL.md`
10
+ 4. `~/.agents/skills/daily/SKILL.md`
11
+ 5. `commands/daily/SKILL.md`
12
+
13
+ If none of those files exists, stop and ask the user to install `commands/daily` into `.gemini/skills/daily/` (or `~/.gemini/skills/daily/`) following `INSTALLATION.md`.
14
+
15
+ Otherwise, follow `SKILL.md` exactly without skipping steps.
16
+ Optional arguments passed by the user: {{args}}
17
+ """
@@ -0,0 +1,86 @@
1
+ ---
2
+ name: issue-clean-and-close
3
+ description: "Trigger: /issue-clean-and-close, limpiar issues, cerrar issues resueltas, issues abiertas con PR fusionado, backlog sin trazabilidad. Review every open issue of the current repository, propose closing only what a merged PR or an unanswered needs-info settles, label and ping the rest, and apply only the plan the person approves."
4
+ disable-model-invocation: true
5
+ license: Apache-2.0
6
+ compatibility: Requires Python 3.8+, git, and an authenticated gh CLI with GraphQL access for scripts/sweep.py and scripts/sweep-github.py; scripts/sweep-issues.py runs offline.
7
+ metadata:
8
+ author: bbc-skill-internals
9
+ version: "1.0"
10
+ pre_hook: "gh auth status; tool-depot (github-read / github-write)"
11
+ post_hook: "question-gate (triage-question.py) + Quest-Tree HUD"
12
+ post_install: "npx --full-depth; copy adapters/gemini.toml + /commands reload (Gemini); server restart (Zed ACP)"
13
+ scripts: "scripts/sweep-github.py, scripts/sweep-issues.py, scripts/sweep.py"
14
+ adapters: "adapters/command.md, adapters/gemini.toml"
15
+ ---
16
+
17
+ ## Activation Contract
18
+
19
+ Run only when a person explicitly invokes `/issue-clean-and-close` in a repository checkout. It reviews every open issue of that repository (the `origin` remote on github.com), shows a plan, and writes to GitHub only what the person approves at the closing `🟡 BOSS GATE`.
20
+
21
+ Optional arguments:
22
+ - `--dry-run`: plan and render the HUD; write nothing.
23
+ - `--repo <owner/repo>`: review another repository instead of the current checkout's `origin`.
24
+
25
+ Granted authority upon explicit invocation:
26
+ - `A1` (read): `sweep.py plan` under Tool Depot `github-read` / `read-issues-for-cleanup`: the authenticated login, the optional `.github/issue-sweeper.json` on the default branch, and the open issues with one paginated GraphQL query.
27
+ - `A2` (write, only after the gate): `sweep.py apply` of the exact plan file under `github-write` / `clean-approved-issues`. Invoking the command is **not** approval to write.
28
+
29
+ ## Hard Rules
30
+
31
+ - Close only what the [policy](references/policy.md) settles: a merged PR that declares closing the issue (`SW1`), or `needs-info` unanswered by its author for 14 days (`SW3`). Everything else is a label or a ping, never a close. Never close because an issue is old.
32
+ - Apply only the plan file shown at the gate, all of it or the issue numbers the person lists (`--only`). A plan older than 60 minutes is refused: plan again and show the new one.
33
+ - Never touch exempt issues (`security`, `frozen`, `pinned`, `P0`, `P1`), never unassign, never create labels, never edit an issue title or body other than the command's own report issue.
34
+ - Never copy issue or PR text into comments; the scripts write fixed text with numbers, links, dates, and logins.
35
+ - Check `gh auth status` first. If `gh` is missing or unauthenticated, stop and report the blocker.
36
+ - Match the HUD to the user's language; the comments use the policy's `language` (`es` by default).
37
+
38
+ ## Execution Steps
39
+
40
+ 1. **Plan** (read-only)
41
+ - Run `python3 -I -B <issue-clean-and-close>/scripts/sweep.py plan` from the repository root (add `--repo <owner/repo>` if given).
42
+ - On `unusable`, report its `reason` and stop. A missing `.github/issue-sweeper.json` is not an error: the defaults apply (`config: defaults`).
43
+
44
+ 2. **Render the plan** as the HUD below, from the `plan` output: every action with its issue link, rule, and steps; the issues deferred by the per-run cap; report-only issues (`SW4` duplicate work, `SW8` exempt); gaps (missing labels, incomplete timelines); and the metrics.
45
+ - If `actions` is empty, close with `🏁 STAGE CLEAR` (nothing to apply).
46
+ - With `--dry-run`, stop after the HUD.
47
+
48
+ 3. **Gate**: validate the closing prompt with `question-gate` (`triage-question.py`) when installed, then ask one `🟡 BOSS GATE ─ Code Owner / Issue cleanup`:
49
+ - `[A]` apply the whole plan (each issue's comment, close, or label, plus the report issue);
50
+ - `[B]` apply only the issue numbers the person lists;
51
+ - `[C]` apply nothing.
52
+
53
+ 4. **Apply** (only after `[A]` or `[B]`)
54
+ - Run `python3 -I -B <issue-clean-and-close>/scripts/sweep.py apply --plan <plan> [--only <n,m>]` with the `plan` path from step 1. Record the request and the use in the delivery ledger when one exists.
55
+ - If it reports a stale plan, go back to step 1 and show the new plan at a new gate; never widen an approval to a plan the person has not seen.
56
+ - Report what was applied and any `errors` (a failed comment means that issue was not closed).
57
+
58
+ ## Output Contract
59
+
60
+ ```text
61
+ 🧹 ISSUE CLEAN ─ <owner>/<repo> (open: <n> · with PR: <p> · merged but open: <m>)
62
+ │
63
+ ├── ✅ Close (<k>)
64
+ │ ├── #<n> <url> ··· SW1 → comment + close (completed) · PR #<pr>
65
+ │ └── #<n> <url> ··· SW3 → comment + close (not planned) · needs-info <d> days
66
+ ├── 🏷️ Label / ping (<k>)
67
+ │ ├── #<n> ··· SW2 → needs-close-review + ping @<assignees>
68
+ │ ├── #<n> ··· SW5 → ping @<holder> (stale claim)
69
+ │ └── #<n> ··· SW6 → stale (+ comment) · SW7 → remove stale
70
+ ├── ⏸️ Deferred by the cap: #<n>, #<m>
71
+ ├── 👀 Report only: #<n> SW4 duplicate work · #<m> SW8 exempt
72
+ └── ⚠️ Gaps: missing label `stale` · incomplete #<n>
73
+ ```
74
+
75
+ Then the `🟡 BOSS GATE` with `[A]` / `[B]` / `[C]`, or `🏁 STAGE CLEAR`. After applying, report each issue as `closed`, `labeled`, or `commented`, and the report issue link.
76
+
77
+ ## Evidence
78
+
79
+ Every `plan` and `apply` keeps its evidence in `~/.issue-clean-and-close/<owner>__<repo>/`: the policy file used, the snapshot, each plan in `plans/` (last 30), `report.md`, and one JSON line per step in `runs.log`. Every comment carries `<!-- issue-sweeper:<rule> -->`, so a later run does not repeat it.
80
+
81
+ ## References
82
+
83
+ - [Policy and rules SW1–SW8](references/policy.md)
84
+ - [Daily refresh](../daily/SKILL.md)
85
+ - [Question Gate](../../skills/question-gate/SKILL.md)
86
+ - [Tool Depot catalog](../../skills/tool-depot/references/tool-catalog.json)
@@ -0,0 +1,17 @@
1
+ ---
2
+ description: Review every open issue of this repository, close only what a merged PR or an unanswered needs-info settles, label and ping the rest, after your approval (/issue-clean-and-close)
3
+ ---
4
+
5
+ # /issue-clean-and-close
6
+
7
+ Read and execute `SKILL.md` from the first existing path (single source of truth; do not duplicate or summarize its steps here):
8
+
9
+ 1. `.cursor/skills/issue-clean-and-close/SKILL.md`
10
+ 2. `.claude/skills/issue-clean-and-close/SKILL.md`
11
+ 3. `.agents/skills/issue-clean-and-close/SKILL.md`
12
+ 4. `~/.cursor/skills/issue-clean-and-close/SKILL.md`
13
+ 5. `~/.claude/skills/issue-clean-and-close/SKILL.md`
14
+ 6. `~/.agents/skills/issue-clean-and-close/SKILL.md`
15
+ 7. `commands/issue-clean-and-close/SKILL.md`
16
+
17
+ Optional arguments: `--dry-run` (plan only, write nothing) or `--repo <owner/repo>`.
@@ -0,0 +1,17 @@
1
+ description = "Review every open issue of this repository, close only what the evidence settles, label and ping the rest, after your approval (/issue-clean-and-close)."
2
+
3
+ prompt = """
4
+ Execute the `/issue-clean-and-close` command workflow from its single source of truth `SKILL.md`.
5
+
6
+ First, locate and read `SKILL.md` from the first existing path:
7
+ 1. `.gemini/skills/issue-clean-and-close/SKILL.md`
8
+ 2. `.agents/skills/issue-clean-and-close/SKILL.md`
9
+ 3. `~/.gemini/skills/issue-clean-and-close/SKILL.md`
10
+ 4. `~/.agents/skills/issue-clean-and-close/SKILL.md`
11
+ 5. `commands/issue-clean-and-close/SKILL.md`
12
+
13
+ If none of those files exists, stop and ask the user to install `commands/issue-clean-and-close` into `.gemini/skills/issue-clean-and-close/` (or `~/.gemini/skills/issue-clean-and-close/`) following `INSTALLATION.md`.
14
+
15
+ Otherwise, follow `SKILL.md` exactly without skipping steps.
16
+ Optional arguments passed by the user: {{args}}
17
+ """
@@ -0,0 +1,87 @@
1
+ # Issue cleanup policy
2
+
3
+ `/issue-clean-and-close` reviews every open issue of the repository it runs in, closes only what the evidence settles, and labels and pings the rest, so nothing is left open without a reason and nothing is closed because it is old. It runs when a person invokes it; nothing is scheduled or installed. The person approves the exact plan at the Boss Gate, and that approval is the authorization for Tool Depot `github-write` / `clean-approved-issues`.
4
+
5
+ ## Pipeline
6
+
7
+ ```text
8
+ sweep.py plan -> login, optional .github/issue-sweeper.json from the default branch
9
+ sweep-github.py fetch -> snapshot.json (one GraphQL query per 30 open issues)
10
+ sweep-issues.py -> plans/<UTC>.json (offline: rules SW1-SW8, metrics, report)
11
+ 🟡 Boss Gate -> the person approves all, some issue numbers, or nothing
12
+ sweep.py apply --plan -> sweep-github.py apply: only what the approved plan lists, plus the report issue
13
+ ```
14
+
15
+ `sweep-issues.py` decides everything and never calls GitHub; `sweep-github.py` only reads and writes what the plan says; `sweep.py` chains them, finds the repository from the checkout's `origin`, and keeps the evidence. An LLM reading this file applies the same rules and must reach the same plan; when they differ, the script stands and the difference is reported.
16
+
17
+ ## Configuration (optional `.github/issue-sweeper.json`)
18
+
19
+ Without the file, the defaults apply. With it, its keys override them; it is read from the default branch, so changing it takes a reviewed pull request.
20
+
21
+ | Key | Default | Meaning |
22
+ |---|---|---|
23
+ | `language` | `es` | Language of comments and report (`es`, `en`). |
24
+ | `max_writes_per_run` | `20` | Issues acted on per plan; the rest are listed as `deferred` for the next run. |
25
+ | `needs_info_days` | `14` | Days after `needs-info` without an answer from the author before closing. |
26
+ | `claim_stale_days` | `7` | Days a claimed issue may go without activity or an open PR. |
27
+ | `inactive_days` | `30` | Days without activity before an unclaimed issue with no PR is marked `stale`. |
28
+ | `labels` | `stale`, `needs-info`, `needs-close-review`, `status:in-progress` | Label names. The command never creates labels; a missing one is a gap and the action proceeds without it. |
29
+ | `exempt_labels` | `security`, `frozen`, `lifecycle/frozen`, `pinned` | Issues the command never touches. |
30
+ | `exempt_priorities` | `P0`, `P1` | Priority levels it never touches (`priority:*`, `prioridad:*`, `P0`–`P3`). |
31
+ | `report_title` | `Estado de issues` | Title of the report issue. |
32
+
33
+ The account that applies the plan is the `gh` login of whoever runs the command (`run_by` in the plan). Its sweep comments (by marker) and the `stale` and `needs-close-review` labels it sets are the command's own writes; anything else that person does is activity.
34
+
35
+ ## Rules decided by `sweep-issues.py`
36
+
37
+ Rules are checked in this order; an issue gets at most one action per plan.
38
+
39
+ | Rule | Condition | Action |
40
+ |---|---|---|
41
+ | `SW8` | The issue has an exempt label or priority. | Report only. |
42
+ | `SW1` | A merged pull request **declares** closing the issue (manual link, GitHub's `willCloseTarget`, or a closing keyword `close/fix/resolve` + `#n` in its title or body), the issue was not reopened after that merge, and no open pull request also declares closing it. | Comment with the PR and merge commit, then close as `completed`. |
43
+ | `SW2` | A merged pull request references the issue without declaring it closed, or `SW1` was blocked by a reopen or another open PR. | Add `needs-close-review` and comment to the assignees (or the author). |
44
+ | `SW3` | `needs-info` is set, was added at least `needs_info_days` ago, and the author has not commented since. | Comment, then close as `not_planned`. |
45
+ | `SW4` | More than one open pull request references the issue. | Report only (`duplicate-work`). |
46
+ | `SW5` | The claim label is set, someone is assigned, no open pull request references it, and no activity for `claim_stale_days`. | Comment to the assignees. Never unassign. |
47
+ | `SW7` | `stale` is set and there was activity after it was added, within the last `inactive_days`. | Remove `stale`. |
48
+ | `SW6` | `stale` is not set, no open or merged pull request references it, it is not claimed, and no activity for `inactive_days`. | Add `stale` and comment. Never close. |
49
+
50
+ An issue with an incomplete pull request timeline gets no action at all, only a gap in the report.
51
+
52
+ **Activity** is the latest of: the issue's creation, a comment without a sweep marker, a label change other than the runner setting `stale` or `needs-close-review`, and a pull request referencing the issue. The command's own writes never reset or extend a timer.
53
+
54
+ **Idempotency:** every comment ends with `<!-- issue-sweeper:<rule> -->`. A rule that comments (`SW2`, `SW5`, `SW6`) does not comment again while its marker is newer than the last activity, whoever ran it.
55
+
56
+ **Safety:**
57
+
58
+ - The person sees every write before it happens, and `apply` performs only the plan file shown (all of it, or `--only` the approved issue numbers; a number outside the plan is refused). A plan older than 60 minutes or for another repository is refused.
59
+ - An issue with more pull request references than one page holds (25) gets no action (`incomplete`). Only the latest 25 comments and label events are read; an older `needs-info` label without its event in that window is never closed by `SW3`.
60
+ - `willCloseTarget` is not reliable once an issue is closed or reopened, so the closing keywords in the pull request's title and body are checked too. The fetcher keeps only the body lines that reference an issue, so a keyword at the end of a long body is not lost.
61
+ - Comments contain only numbers, links, dates, logins, and fixed text, never text copied from issues or pull requests. Each comment carries a `🟡 GAP visual` line: the evidence is the linked pull request or the timeline.
62
+ - Only an issue opened by the runner's login and carrying the report marker is its report issue, so copying the marker into another issue cannot get that issue's body overwritten.
63
+ - A failed write skips the remaining steps for that issue (a comment that fails is never followed by a close).
64
+
65
+ ## Report
66
+
67
+ The plan carries a report, shown at the gate and kept as `report.md`. When a plan is applied, the runner's report issue (titled `report_title`, marked `<!-- issue-sweeper:report -->`) is created or rewritten with it:
68
+
69
+ - Open issues, with a pull request, assigned, age (median and 90th percentile, in days).
70
+ - Merged but still open (`SW1` + `SW2`), stale claims (`SW5`), duplicate work (`SW4`), waiting for information, inactive (`SW6`), exempt (`SW8`).
71
+ - The actions, the issues deferred by the cap, and the report-only issues, each with its rule.
72
+ - Gaps: missing labels, incomplete issues.
73
+
74
+ ## Operation
75
+
76
+ ```bash
77
+ python3 -I -B commands/issue-clean-and-close/scripts/sweep.py plan [--repo <owner>/<repo>]
78
+ python3 -I -B commands/issue-clean-and-close/scripts/sweep.py apply --plan <plan> [--only 12,15] [--dry-run]
79
+ ```
80
+
81
+ Every step keeps its evidence in `~/.issue-clean-and-close/<owner>__<repo>/` (`SWEEP_HOME` overrides it): the policy file used (`config.json`), `snapshot.json`, the last 30 plans in `plans/` (`--keep`), `report.md`, and one JSON line per step in `runs.log` (plan: actions, deferred, gaps; apply: the plan, `only`, writes, errors).
82
+
83
+ | Exit | `sweep.py` | `sweep-issues.py` | `sweep-github.py` |
84
+ |---|---|---|---|
85
+ | 0 | Done | Plan ready | Done |
86
+ | 1 | Some writes failed (listed) | — | Some writes failed (listed) |
87
+ | 2 | Unusable input, stale or foreign plan, broken policy file | `unusable` input or config | Unusable input |