@bbcsoftwarefactory/commands 0.0.0-stage โ†’ 0.1.1

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,181 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ cd -- "${BASH_SOURCE[0]%/*}/.."
4
+
5
+ SCRIPT="$PWD/scripts/sweep.py"
6
+ PYTHON_BIN=$(command -v python3 || command -v python)
7
+ "$PYTHON_BIN" -I -B - "$SCRIPT" <<'PY'
8
+ from datetime import datetime, timedelta, timezone
9
+ import json
10
+ import os
11
+ from pathlib import Path
12
+ import subprocess
13
+ import sys
14
+ import tempfile
15
+
16
+ script = Path(sys.argv[1]).resolve()
17
+ if not script.is_file():
18
+ sys.exit('FAIL: missing script ' + str(script))
19
+ scratch = Path(tempfile.mkdtemp())
20
+ checks = 0
21
+ failures = []
22
+ REPO = 'example/repo'
23
+
24
+
25
+ def check(label, condition, detail=''):
26
+ global checks
27
+ checks += 1
28
+ if not condition:
29
+ failures.append(label + ' ' + str(detail)[:600])
30
+
31
+
32
+ # A fake gh: answers the login, the optional policy file, and the GraphQL page; logs every write.
33
+ fake_gh = scratch / 'fake_gh.py'
34
+ fake_gh.write_text(r'''
35
+ import json, os, sys
36
+ args = sys.argv[1:]
37
+ state = os.environ['FAKE_DIR']
38
+ if args[:2] == ['api', 'user']:
39
+ print('pm-login'); sys.exit(0)
40
+ if any(a.endswith('contents/.github/issue-sweeper.json') for a in args):
41
+ path = os.path.join(state, 'config.json')
42
+ if not os.path.exists(path):
43
+ sys.stderr.write('gh: Not Found (HTTP 404)'); sys.exit(1)
44
+ print(open(path, encoding='utf-8').read()); sys.exit(0)
45
+ if args[:2] == ['api', 'graphql']:
46
+ print(open(os.path.join(state, 'page.json'), encoding='utf-8').read()); sys.exit(0)
47
+ with open(os.path.join(state, 'writes.log'), 'a', encoding='utf-8') as handle:
48
+ handle.write(json.dumps(args[:4]) + '\n')
49
+ print('{}')
50
+ ''', encoding='utf-8')
51
+
52
+
53
+ def page(issues):
54
+ return {'data': {'repository': {'nameWithOwner': REPO, 'labels': {'nodes': [{'name': 'bug'}]},
55
+ 'issues': {'pageInfo': {'hasNextPage': False, 'endCursor': None}, 'nodes': issues}}}}
56
+
57
+
58
+ def merged(number, closes=True):
59
+ return {'number': number, 'title': 'T', 'url': 'https://github.com/example/repo/issues/' + str(number),
60
+ 'createdAt': '2026-10-01T10:00:00Z', 'body': '', 'author': {'login': 'carla'}, 'labels': {'nodes': []},
61
+ 'assignees': {'nodes': []}, 'recent': {'nodes': []},
62
+ 'refs': {'pageInfo': {'hasNextPage': False}, 'nodes': [
63
+ {'__typename': 'CrossReferencedEvent', 'createdAt': '2026-11-19T10:00:00Z', 'willCloseTarget': False,
64
+ 'source': {'number': 100 + number, 'url': 'https://github.com/example/repo/pull/' + str(100 + number),
65
+ 'state': 'MERGED', 'mergedAt': '2026-11-20T10:00:00Z', 'title': 'Fix',
66
+ 'body': ('Closes #' if closes else 'Refs #') + str(number),
67
+ 'repository': {'nameWithOwner': REPO}, 'mergeCommit': {'oid': 'abcdef1234567'}}}]}}
68
+
69
+
70
+ def setup(name, config=None, issues=None):
71
+ fake_dir = scratch / name
72
+ fake_dir.mkdir()
73
+ if config is not None:
74
+ (fake_dir / 'config.json').write_text(config if isinstance(config, str) else json.dumps(config), encoding='utf-8')
75
+ issues = [merged(12), merged(15)] if issues is None else issues
76
+ (fake_dir / 'page.json').write_text(json.dumps(page(issues)), encoding='utf-8')
77
+ return fake_dir
78
+
79
+
80
+ def sweep(fake_dir, *args, cwd=None):
81
+ environ = dict(os.environ, FAKE_DIR=str(fake_dir), SWEEP_HOME=str(fake_dir / 'home'),
82
+ SWEEP_GH=json.dumps([sys.executable, str(fake_gh)]))
83
+ result = subprocess.run([sys.executable, '-I', '-B', str(script), *args], capture_output=True, text=True,
84
+ encoding='utf-8', env=environ, cwd=cwd or str(fake_dir))
85
+ try:
86
+ return result.returncode, json.loads(result.stdout)
87
+ except ValueError:
88
+ return result.returncode, {'raw': result.stdout + result.stderr}
89
+
90
+
91
+ def writes(fake_dir):
92
+ path = fake_dir / 'writes.log'
93
+ return [json.loads(line) for line in path.read_text(encoding='utf-8').splitlines()] if path.exists() else []
94
+
95
+
96
+ def runs(fake_dir):
97
+ path = fake_dir / 'home' / 'example__repo' / 'runs.log'
98
+ return [json.loads(line) for line in path.read_text(encoding='utf-8').splitlines()] if path.exists() else []
99
+
100
+
101
+ # plan: reads, decides, writes nothing to GitHub
102
+ fake = setup('plan')
103
+ code, out = sweep(fake, 'plan', '--repo', REPO)
104
+ check('plan succeeds without a policy file (defaults)', code == 0 and out.get('verdict') == 'planned'
105
+ and out.get('config') == 'defaults', out)
106
+ check('plan writes nothing to GitHub', writes(fake) == [], writes(fake))
107
+ check('plan lists the actions for the gate', [(a['issue'], a['rule']) for a in out.get('actions', [])]
108
+ == [(12, 'SW1'), (15, 'SW1')] and all(a.get('url') and a.get('steps') for a in out['actions']), out)
109
+ plan_path = Path(out.get('plan', 'missing'))
110
+ check('the plan file is kept for traceability', plan_path.is_file() and plan_path.parent.name == 'plans', out)
111
+ check('plan includes metrics and the report', out.get('metrics', {}).get('open') == 2
112
+ and 'issue-sweeper:report' in out.get('report_markdown', ''), out)
113
+ check('plan is logged', [r.get('step') for r in runs(fake)] == ['plan'], runs(fake))
114
+
115
+ # apply: exactly the approved plan
116
+ code, out = sweep(fake, 'apply', '--repo', REPO, '--plan', str(plan_path), '--dry-run')
117
+ check('--dry-run writes nothing', code == 0 and writes(fake) == [] and len(out.get('writes', [])) == 5, out)
118
+ code, out = sweep(fake, 'apply', '--repo', REPO, '--plan', str(plan_path), '--only', '15')
119
+ check('--only applies only the approved issues, then the report', code == 0 and writes(fake) == [
120
+ ['api', '-X', 'POST', 'repos/example/repo/issues/15/comments'],
121
+ ['api', '-X', 'PATCH', 'repos/example/repo/issues/15'], ['api', '-X', 'POST', 'repos/example/repo/issues']],
122
+ writes(fake))
123
+ log = runs(fake)
124
+ check('apply is logged with what it did', log[-1].get('step') == 'apply' and log[-1].get('applied') == 3
125
+ and log[-1].get('only') == [15] and log[-1].get('errors') == [], log)
126
+ code, out = sweep(fake, 'apply', '--repo', REPO, '--plan', str(plan_path), '--only', '99')
127
+ check('an issue outside the plan is refused', code == 2 and len(writes(fake)) == 3, out)
128
+
129
+ # apply: guards
130
+ stale = json.loads(plan_path.read_text(encoding='utf-8'))
131
+ stale['generated_at'] = (datetime.now(timezone.utc) - timedelta(hours=2)).strftime('%Y-%m-%dT%H:%M:%SZ')
132
+ old_path = scratch / 'old-plan.json'
133
+ old_path.write_text(json.dumps(stale), encoding='utf-8')
134
+ code, out = sweep(fake, 'apply', '--repo', REPO, '--plan', str(old_path))
135
+ check('a plan older than 60 minutes must be planned again', code == 2 and 'plan' in out.get('reason', '')
136
+ and len(writes(fake)) == 3, out)
137
+ code, out = sweep(fake, 'apply', '--repo', 'other/repo', '--plan', str(plan_path))
138
+ check('a plan for another repository is refused', code == 2 and len(writes(fake)) == 3, out)
139
+ code, out = sweep(fake, 'apply', '--repo', REPO)
140
+ check('apply needs the exact plan file', code == 2, out)
141
+
142
+ # repository detection from the current checkout
143
+ for label, url in (('https remote', 'https://github.com/example/repo.git'), ('ssh remote', 'git@github.com:example/repo.git')):
144
+ fake = setup('detect-' + label.split()[0])
145
+ checkout = fake / 'checkout'
146
+ checkout.mkdir()
147
+ subprocess.run(['git', 'init', '-q', str(checkout)], check=True)
148
+ subprocess.run(['git', '-C', str(checkout), 'remote', 'add', 'origin', url], check=True)
149
+ code, out = sweep(fake, 'plan', cwd=str(checkout))
150
+ check('the repository comes from origin (' + label + ')', code == 0 and out.get('repo') == REPO, out)
151
+ fake = setup('no-git')
152
+ code, out = sweep(fake, 'plan', cwd=str(fake))
153
+ check('outside a GitHub checkout --repo is required', code == 2, out)
154
+
155
+ # optional policy file on the default branch
156
+ fake = setup('english', {'language': 'en'})
157
+ code, out = sweep(fake, 'plan', '--repo', REPO)
158
+ body = json.loads(Path(out['plan']).read_text(encoding='utf-8'))['actions'][0]['steps'][0]['body'] if code == 0 else ''
159
+ check('the repository policy file tunes the plan', code == 0 and out.get('config') == '.github/issue-sweeper.json'
160
+ and 'Closing' in body, out)
161
+ fake = setup('broken-config', '{not json')
162
+ code, out = sweep(fake, 'plan', '--repo', REPO)
163
+ check('a broken policy file stops the plan', code == 2 and writes(fake) == [], out)
164
+ fake = setup('keep')
165
+ for _ in range(3):
166
+ sweep(fake, 'plan', '--repo', REPO, '--keep', '2')
167
+ check('old plans are pruned', len(list((fake / 'home' / 'example__repo' / 'plans').glob('*.json'))) == 2, '')
168
+
169
+ for label, args in (('bad repo', ('plan', '--repo', 'nope')), ('unknown command', ('install', '--repo', REPO)),
170
+ ('bad keep', ('plan', '--repo', REPO, '--keep', '0'))):
171
+ code, out = sweep(setup('args-' + label.replace(' ', '-')), *args)
172
+ check(label + ' is unusable', code == 2, out)
173
+ result = subprocess.run([sys.executable, '-I', '-B', str(script), '--help'], capture_output=True, text=True)
174
+ check('--help', result.returncode == 0 and 'Usage' in result.stdout, result.stdout)
175
+
176
+ if failures:
177
+ for item in failures:
178
+ print('FAIL:', item, file=sys.stderr)
179
+ sys.exit(1)
180
+ print(f'PASS {checks} checks')
181
+ PY
@@ -0,0 +1,90 @@
1
+ ---
2
+ name: recap
3
+ description: "Trigger: /recap, recap, resumen del dia, progreso del dia, cuanto avance, que efectivo fui, daily progress summary. Daily progress summary across Git, GitHub REST, and Project v2 boards: issues created/closed, PRs opened/merged, contribution, work in progress, effectiveness ratios, and optional board sync."
4
+ disable-model-invocation: true
5
+ license: Apache-2.0
6
+ compatibility: Requires Python 3.8+, Git, and an authenticated gh CLI for GitHub metrics in scripts/recap.py.
7
+ metadata:
8
+ author: bbc-skill-internals
9
+ version: "1.1"
10
+ pre_hook: "tool-depot (github-read: read-approved-issue-or-pr, read-pr-review-and-checks)"
11
+ post_hook: "Quest-Tree HUD"
12
+ post_install: "npx --full-depth; copy adapters/gemini.toml + /commands reload (Gemini); server restart (Zed ACP)"
13
+ scripts: "scripts/recap.py"
14
+ adapters: "adapters/command.md, adapters/gemini.toml"
15
+ ---
16
+
17
+ ## Activation Contract
18
+
19
+ Run only when a person explicitly invokes `/recap` (or asks for a daily progress recap). By default it produces a **read-only** summary across local Git, GitHub REST, and an optional GitHub Project v2 board; it never mutates branches, files, issues, PRs, or boards unless the user explicitly asks to organize/sync the board (`--sync-board`).
20
+
21
+ Optional arguments:
22
+ - `--since <YYYY-MM-DD | <N>h | <N>d>`: Start of the summary window (default: local midnight today).
23
+ - `--all-repos`: Aggregate GitHub activity across all repositories for the user instead of only the current `origin` repository.
24
+ - `--repo <owner/repo>`: Override the target GitHub repository.
25
+ - `--user <login>`: Override the GitHub login (default: authenticated `gh` user).
26
+ - `--team`: Collect summary across all members of the target organization.
27
+ - `--users <u1,u2,...>`: Comma-separated GitHub logins for team summary.
28
+ - `--project <url | owner/number>`: Inspect a GitHub Project v2 board (column counts, assignee breakdown, and sync diff).
29
+ - `--sync-board`: With `--project`, add missing items and move closed/merged cards to `Done`.
30
+ - `--fix-colors`: With `--sync-board`, normalize `Status`/single-select colors (preserving option IDs) and show Labels/Priority/PRs on board view cards.
31
+ - `--apply-labels`: With `--sync-board`, apply matching existing repo labels (`bug`, `enhancement`, `documentation`) to unlabeled added items.
32
+ - `--dry-run`: With `--sync-board`, preview planned board changes without writing.
33
+ - `--no-github`: Collect local Git metrics only without calling `gh`.
34
+ - `--json`: Return structured JSON instead of the Quest-Tree HUD.
35
+
36
+ Granted authority upon explicit `/recap` invocation:
37
+ - `A1` (Read-only repo, GitHub & Project v2): local read-only `git log` / `git status` / `git rev-list`, GitHub REST reads (`gh api`) under [Tool Depot](../../skills/tool-depot/SKILL.md) `github-read` (`read-approved-issue-or-pr`, `read-pr-review-and-checks`), and read-only Project v2 GraphQL queries when `--project` is passed. Keep issue/PR/CI reads on REST (`scripts/recap.py`).
38
+ - `A2` (Board sync, only when explicitly requested): `--sync-board` mutates only the named `--project` board (and existing repo labels when `--apply-labels` is passed), never closing issues, merging PRs, or modifying local Git files. Preview with `--dry-run` first when the user has not explicitly approved the write target.
39
+
40
+ ## Hard Rules
41
+
42
+ - **Read-only by default.** Never write files, switch branches, push commits, or mutate issues, PRs, or boards unless `--sync-board` is explicitly authorized for that target project.
43
+ - **Preserve option IDs on color updates.** When `--fix-colors` updates a single-select field, always keep every option `id` so existing card assignments are never cleared.
44
+ - **No invented numbers.** Every count and ratio comes from `scripts/recap.py` against real Git/GitHub output. When GitHub or local Git is unavailable, report `๐ŸŸก GAP` and `N/A` rather than guessing `0` or `100%`.
45
+ - **Objective effectiveness.** Report ratios (`merged/opened`, `CI passing`, `closed/created`) with traffic lights (`๐ŸŸข` / `๐ŸŸก` / `๐Ÿ”ด` / `โšช N/A`), never a fabricated score.
46
+ - Match the final HUD language to the user (`--lang es` or `--lang en`).
47
+
48
+ ## Decision Gates
49
+
50
+ | Situation | Action |
51
+ |---|---|
52
+ | Default invocation (`/recap`) | Run `scripts/recap.py` for the current repo (`origin`) from local midnight today |
53
+ | `--all-repos` passed | Include all GitHub repositories for the user while keeping local Git metrics from the current working tree if present |
54
+ | `--project <url\|owner/n>` passed | Query Project v2 board columns, assignee breakdown, and sync diff (`missing_from_board`, `status_mismatches`) read-only |
55
+ | `--team` or `--users` passed | Collect per-member metrics across org members (or listed logins) and include them in the board cross-check |
56
+ | User asks to organize/sync the board | Run `--sync-board --dry-run` to preview, then apply `--sync-board` (with `--fix-colors` / `--apply-labels` as requested) once the target project is confirmed |
57
+ | `gh` missing or unauthenticated | Still run with local Git fallback and surface the explicit `๐ŸŸก GAP` in the HUD |
58
+ | Zero denominator in a ratio (e.g. `0` PRs opened) | Show `N/A` (or `<N> merged (0 opened)` when merges occurred from earlier days) |
59
+
60
+ ## Execution Steps
61
+
62
+ 1. Resolve `scripts/recap.py` from the installed `recap` skill/command directory (for example `.cursor/skills/recap/scripts/recap.py`, `~/.cursor/skills/recap/scripts/recap.py`, or `commands/recap/scripts/recap.py`).
63
+ 2. Run the script with `--lang` matching the user's language (`es` or `en`) and any user-supplied flags (`--since`, `--all-repos`, `--repo`, `--user`, `--team`, `--users`, `--project`, `--sync-board`, `--fix-colors`, `--apply-labels`, `--dry-run`, `--no-github`, `--json`):
64
+ ```bash
65
+ python3 -I -B <recap-root>/scripts/recap.py --lang es
66
+ ```
67
+ On Windows:
68
+ ```powershell
69
+ python -I -X utf8 -B <recap-root>\scripts\recap.py --lang es
70
+ ```
71
+ 3. Render the script's Quest-Tree HUD directly in chat. If the user asks for item links (`"detalle"`), rerun with `--json` (or include the `items` list from the JSON output) without inventing details.
72
+
73
+ ## Output Contract
74
+
75
+ Render the compact **Quest-Tree HUD** (`๐Ÿ“Š RECAP โ”€ <repo> (@<user> ยท desde <since>)`) covering all 7 core items (plus `๐Ÿ‘ฅ Equipo`, `๐Ÿ“‹ Tablero`, and `๐Ÿ”„ Tablero organizado` when `--team`, `--project`, or `--sync-board` are used):
76
+ 1. `Issues creados`
77
+ 2. `Issues cerrados`
78
+ 3. `PRs enviados`
79
+ 4. `Aporte` (commits, files changed, `+ins/-del`, peer PRs reviewed/commented)
80
+ 5. `Solucionado` (PRs merged + issues closed)
81
+ 6. `Avance en curso` (active open PRs ready/draft, unpushed commits, local working changes)
82
+ 7. `Efectividad` (PR merge ratio, CI pass rate, issue close ratio)
83
+
84
+ Close with `๐Ÿ STAGE CLEAR` when all sources succeeded, or list explicit `๐ŸŸก Gaps` when a source was unavailable or capped.
85
+
86
+ ## References
87
+
88
+ - [Install guide for Cursor, Zed, Claude Code, Claude, and Gemini](../../INSTALLATION.md)
89
+ - [Tool Depot catalog](../../skills/tool-depot/references/tool-catalog.json)
90
+ - [Commands reference](../../docs/commands.md)
@@ -0,0 +1,17 @@
1
+ ---
2
+ description: Read-only daily progress summary: issues created/closed, PRs opened/merged, commit/review contribution, work in progress, and effectiveness ratios (/recap)
3
+ ---
4
+
5
+ # /recap
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/recap/SKILL.md`
10
+ 2. `.claude/skills/recap/SKILL.md`
11
+ 3. `.agents/skills/recap/SKILL.md`
12
+ 4. `~/.cursor/skills/recap/SKILL.md`
13
+ 5. `~/.claude/skills/recap/SKILL.md`
14
+ 6. `~/.agents/skills/recap/SKILL.md`
15
+ 7. `commands/recap/SKILL.md`
16
+
17
+ Optional arguments: `--since <YYYY-MM-DD|Nh|Nd>`, `--all-repos`, `--repo <owner/repo>`, `--user <login>`, `--team`, `--users <u1,u2>`, `--project <url|owner/number>`, `--sync-board`, `--fix-colors`, `--apply-labels`, `--dry-run`, `--no-github`, `--json`.
@@ -0,0 +1,17 @@
1
+ description = "Read-only daily progress summary: issues created/closed, PRs opened/merged, commits/reviews contribution, work in progress, and effectiveness ratios (/recap)."
2
+
3
+ prompt = """
4
+ Execute the `/recap` 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/recap/SKILL.md`
8
+ 2. `.agents/skills/recap/SKILL.md`
9
+ 3. `~/.gemini/skills/recap/SKILL.md`
10
+ 4. `~/.agents/skills/recap/SKILL.md`
11
+ 5. `commands/recap/SKILL.md`
12
+
13
+ If none of those files exists, stop and ask the user to install `commands/recap` into `.gemini/skills/recap/` (or `~/.gemini/skills/recap/`) following `INSTALLATION.md`.
14
+
15
+ Otherwise, follow `SKILL.md` exactly without skipping steps.
16
+ Optional arguments passed by the user: {{args}}
17
+ """