@bbcsoftwarefactory/skills 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.
Files changed (100) hide show
  1. package/dist/index.json +42 -0
  2. package/dist/skills/code-quality-gate/SKILL.md +59 -0
  3. package/dist/skills/code-quality-gate/references/gate-bigo.md +31 -0
  4. package/dist/skills/code-quality-gate/references/gate-earlyreturn.md +73 -0
  5. package/dist/skills/code-quality-gate/references/gate-typesafe.md +32 -0
  6. package/dist/skills/code-quality-gate/references/output-schema.yml +40 -0
  7. package/dist/skills/code-quality-gate/scripts/extract-diff-scope.py +225 -0
  8. package/dist/skills/code-quality-gate/tests/extract-diff-scope.test.sh +200 -0
  9. package/dist/skills/delivery-coordinator/SKILL.md +81 -0
  10. package/dist/skills/delivery-coordinator/references/hud-output.md +55 -0
  11. package/dist/skills/delivery-coordinator/references/intake.md +86 -0
  12. package/dist/skills/delivery-coordinator/references/issue-claim.md +143 -0
  13. package/dist/skills/delivery-coordinator/references/issue-dedup.md +38 -0
  14. package/dist/skills/delivery-coordinator/references/sleuth-regression-exercise.md +60 -0
  15. package/dist/skills/delivery-coordinator/references/visual-reference.md +45 -0
  16. package/dist/skills/delivery-coordinator/references/worktree-isolation.md +19 -0
  17. package/dist/skills/delivery-coordinator/scripts/check-issue-claim.py +363 -0
  18. package/dist/skills/delivery-coordinator/scripts/check-worktree-guard.py +220 -0
  19. package/dist/skills/delivery-coordinator/scripts/classify-change-lane.py +263 -0
  20. package/dist/skills/delivery-coordinator/tests/check-issue-claim.test.sh +221 -0
  21. package/dist/skills/delivery-coordinator/tests/check-worktree-guard.test.sh +123 -0
  22. package/dist/skills/delivery-coordinator/tests/classify-change-lane.test.sh +124 -0
  23. package/dist/skills/documentation-steward/SKILL.md +43 -0
  24. package/dist/skills/documentation-steward/references/discovery.md +17 -0
  25. package/dist/skills/documentation-steward/references/handoff.md +15 -0
  26. package/dist/skills/greptile-review-loop/SKILL.md +57 -0
  27. package/dist/skills/greptile-review-loop/references/review-protocol.md +37 -0
  28. package/dist/skills/greptile-review-loop/scripts/review-loop.py +435 -0
  29. package/dist/skills/greptile-review-loop/tests/review-loop.test.sh +331 -0
  30. package/dist/skills/issue-reviewer/SKILL.md +87 -0
  31. package/dist/skills/issue-reviewer/references/review-format.md +100 -0
  32. package/dist/skills/issue-reviewer/references/triage.md +105 -0
  33. package/dist/skills/issue-reviewer/scripts/fetch-issue-attachments.py +239 -0
  34. package/dist/skills/issue-reviewer/scripts/plan-issue-triage.py +311 -0
  35. package/dist/skills/issue-reviewer/tests/fetch-issue-attachments.test.sh +90 -0
  36. package/dist/skills/issue-reviewer/tests/plan-issue-triage.test.sh +168 -0
  37. package/dist/skills/question-gate/SKILL.md +66 -0
  38. package/dist/skills/question-gate/references/client-hooks.md +111 -0
  39. package/dist/skills/question-gate/references/diagram-routing.md +58 -0
  40. package/dist/skills/question-gate/scripts/triage-question.py +713 -0
  41. package/dist/skills/question-gate/tests/fixtures/question-corpus.json +481 -0
  42. package/dist/skills/question-gate/tests/question-corpus.test.sh +32 -0
  43. package/dist/skills/question-gate/tests/triage-question.test.sh +441 -0
  44. package/dist/skills/regression-testing/SKILL.md +49 -0
  45. package/dist/skills/regression-testing/references/evidence-record.md +35 -0
  46. package/dist/skills/requirements-spec/SKILL.md +59 -0
  47. package/dist/skills/risk-scout/SKILL.md +53 -0
  48. package/dist/skills/risk-scout/references/risk-matrix.md +49 -0
  49. package/dist/skills/skill-clean-architecture/SKILL.md +54 -0
  50. package/dist/skills/skill-clean-architecture/references/layer-rules.md +22 -0
  51. package/dist/skills/skill-clean-architecture/references/source-headers.md +31 -0
  52. package/dist/skills/skill-clean-architecture/scripts/measure-bigo.py +427 -0
  53. package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/bad-utf8.js +1 -0
  54. package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/edge-crlf.ts +6 -0
  55. package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/edge-mixed.ts +15 -0
  56. package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/empty.js +0 -0
  57. package/dist/skills/skill-clean-architecture/tests/fixtures/bigo/no-newline.js +1 -0
  58. package/dist/skills/skill-clean-architecture/tests/fixtures/bigo.expected.yml +95 -0
  59. package/dist/skills/skill-clean-architecture/tests/measure-bigo.test.sh +222 -0
  60. package/dist/skills/tool-depot/SKILL.md +47 -0
  61. package/dist/skills/tool-depot/references/checkout.md +29 -0
  62. package/dist/skills/tool-depot/references/loki-read.md +41 -0
  63. package/dist/skills/tool-depot/references/readonly-access.md +84 -0
  64. package/dist/skills/tool-depot/references/tool-catalog.json +47 -0
  65. package/dist/skills/tool-depot/scripts/loki-runtime-logs.py +305 -0
  66. package/dist/skills/tool-depot/tests/loki-runtime-logs.test.sh +101 -0
  67. package/dist/skills/watcher-observability/SKILL.md +73 -0
  68. package/dist/skills/watcher-observability/references/batch-protocol.md +44 -0
  69. package/dist/skills/watcher-observability/references/configuration.md +31 -0
  70. package/dist/skills/watcher-observability/references/error-scan.md +102 -0
  71. package/dist/skills/watcher-observability/references/live-protocol.md +49 -0
  72. package/dist/skills/watcher-observability/references/server-account.md +72 -0
  73. package/dist/skills/watcher-observability/scripts/error-scan.py +318 -0
  74. package/dist/skills/watcher-observability/scripts/resolve-containers.py +155 -0
  75. package/dist/skills/watcher-observability/scripts/save-counts.py +381 -0
  76. package/dist/skills/watcher-observability/scripts/summarize-logs.py +113 -0
  77. package/dist/skills/watcher-observability/scripts/watch-live.py +606 -0
  78. package/dist/skills/watcher-observability/server/watcher-gate.sh +51 -0
  79. package/dist/skills/watcher-observability/tests/error-scan.test.sh +257 -0
  80. package/dist/skills/watcher-observability/tests/live-windows.test.sh +177 -0
  81. package/dist/skills/watcher-observability/tests/resolve-containers.test.sh +87 -0
  82. package/dist/skills/watcher-observability/tests/save-counts.test.sh +338 -0
  83. package/dist/skills/watcher-observability/tests/sleuth.test.sh +176 -0
  84. package/dist/skills/watcher-observability/tests/summarize-logs.test.sh +105 -0
  85. package/dist/skills/watcher-observability/tests/watcher-config.test.sh +70 -0
  86. package/dist/skills/watcher-observability/tests/watcher-gate.test.sh +110 -0
  87. package/dist/skills/watcher-observability/watcher.json +1 -0
  88. package/dist/skills/workflow-auditor/SKILL.md +55 -0
  89. package/dist/skills/workflow-auditor/references/audit-protocol.md +49 -0
  90. package/dist/skills/workflow-auditor/references/ledger.md +122 -0
  91. package/dist/skills/workflow-auditor/scripts/audit-ledger.py +624 -0
  92. package/dist/skills/workflow-auditor/scripts/list-zed-commands.py +183 -0
  93. package/dist/skills/workflow-auditor/scripts/render-workflow.py +201 -0
  94. package/dist/skills/workflow-auditor/scripts/validate-skills.py +444 -0
  95. package/dist/skills/workflow-auditor/tests/audit-ledger.test.sh +660 -0
  96. package/dist/skills/workflow-auditor/tests/list-zed-commands.test.sh +93 -0
  97. package/dist/skills/workflow-auditor/tests/render-workflow.test.sh +135 -0
  98. package/dist/skills/workflow-auditor/tests/validate-skills.test.sh +190 -0
  99. package/package.json +27 -6
  100. package/README.md +0 -3
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env bash
2
+ set -eu
3
+ cd -- "${BASH_SOURCE[0]%/*}/.."
4
+ PYTHON_BIN=$(command -v python3 || command -v python)
5
+ "$PYTHON_BIN" -I -B - <<'PY'
6
+ import importlib.util
7
+ from pathlib import Path
8
+ import tempfile
9
+
10
+ spec = importlib.util.spec_from_file_location(
11
+ 'fetch_issue_attachments', Path('scripts/fetch-issue-attachments.py')
12
+ )
13
+ mod = importlib.util.module_from_spec(spec)
14
+ spec.loader.exec_module(mod)
15
+
16
+ checks = 0
17
+
18
+ # 1. HTML unescaping and deduplication between <a> and <img>
19
+ html_sample = (
20
+ '<a href="https://private-user-images.githubusercontent.com/1/2.png?a=1&amp;b=2">'
21
+ '<img src="https://private-user-images.githubusercontent.com/1/2.png?a=1&amp;b=2" /></a>'
22
+ '<a href="https://github.com/user-attachments/files/99/trace.txt">trace.txt</a>'
23
+ )
24
+ urls = mod.extract_urls_from_html(html_sample, '')
25
+ assert len(urls) == 2, urls
26
+ assert urls[0]['url'] == 'https://private-user-images.githubusercontent.com/1/2.png?a=1&b=2'
27
+ assert urls[1]['url'] == 'https://github.com/user-attachments/files/99/trace.txt'
28
+ checks += 1
29
+
30
+ # 2. Ignores plain non-attachment web links while keeping user-attachments
31
+ html_links = (
32
+ '<a href="https://example.com/docs">docs</a>'
33
+ '<img src="https://private-user-images.githubusercontent.com/1/shot.jpeg?jwt=abc" />'
34
+ )
35
+ urls2 = mod.extract_urls_from_html(html_links, '')
36
+ assert len(urls2) == 1 and urls2[0]['url'].endswith('jwt=abc'), urls2
37
+ checks += 1
38
+
39
+ # 3. process_issue_payload handles body + comments without duplicating URLs
40
+ with tempfile.TemporaryDirectory() as tmp:
41
+ def fake_downloader(url, dest_dir, index):
42
+ p = Path(dest_dir) / f'attachment-{index}.jpg'
43
+ p.write_bytes(b'fake-jpg')
44
+ return {
45
+ 'url': url,
46
+ 'local_path': str(p),
47
+ 'content_type': 'image/jpeg',
48
+ 'bytes': 8,
49
+ 'status': 'downloaded',
50
+ }
51
+
52
+ report = mod.process_issue_payload(
53
+ {
54
+ 'number': 743,
55
+ 'title': 'ui ux problema edit',
56
+ 'html_url': 'https://github.com/example-org/example-app/issues/743',
57
+ 'body_html': '<img src="https://private-user-images.githubusercontent.com/1/a.jpg?jwt=1" />',
58
+ 'body': '![image](https://github.com/user-attachments/assets/uuid-1)',
59
+ },
60
+ [
61
+ {
62
+ 'id': 10,
63
+ 'body_html': (
64
+ '<img src="https://private-user-images.githubusercontent.com/1/a.jpg?jwt=1" />'
65
+ '<img src="https://private-user-images.githubusercontent.com/1/b.png?jwt=2" />'
66
+ ),
67
+ }
68
+ ],
69
+ tmp,
70
+ downloader=fake_downloader,
71
+ )
72
+ assert report['issue'] == 743
73
+ assert len(report['attachments']) == 2
74
+ assert report['attachments'][0]['source'] == 'body'
75
+ assert report['attachments'][1]['source'] == 'comment:10'
76
+ checks += 1
77
+
78
+ # 4. SSRF / untrusted host rejection and invalid --repo validation
79
+ with tempfile.TemporaryDirectory() as tmp:
80
+ ssrf_res = mod.download_attachment('http://127.0.0.1:8080/secret.png', tmp, 1)
81
+ assert ssrf_res['status'] == 'error', ssrf_res
82
+ meta_res = mod.download_attachment('https://169.254.169.254/latest/meta-data/', tmp, 2)
83
+ assert meta_res['status'] == 'error', meta_res
84
+ evil_res = mod.download_attachment('https://evil.example.com/shot.png', tmp, 3)
85
+ assert evil_res['status'] == 'error', evil_res
86
+ assert mod.main(['--repo', 'owner/repo/extra', '--issue', '1']) == 2
87
+ checks += 1
88
+
89
+ print(f'PASS {checks} checks')
90
+ PY
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ cd -- "${BASH_SOURCE[0]%/*}/.."
4
+
5
+ SCRIPT="$PWD/scripts/plan-issue-triage.py"
6
+ PYTHON_BIN=$(command -v python3 || command -v python)
7
+ "$PYTHON_BIN" -I -B - "$SCRIPT" <<'PY'
8
+ import json
9
+ from pathlib import Path
10
+ import subprocess
11
+ import sys
12
+ import tempfile
13
+
14
+ script = Path(sys.argv[1]).resolve()
15
+ if not script.is_file():
16
+ sys.exit('FAIL: missing script ' + str(script))
17
+
18
+ scratch = Path(tempfile.mkdtemp())
19
+ checks = 0
20
+ failures = []
21
+ REPO_LABELS = ['bug', 'enhancement', 'documentation', 'needs-info', 'area:flows', 'Area: Inbox',
22
+ 'priority:critical', 'priority:high', 'priority:medium', 'priority:low', 'status:in-progress']
23
+
24
+
25
+ def issue(author='carla', kind='User', assignees=(), labels=(), number=12):
26
+ return {'number': number, 'state': 'open', 'user': {'login': author, 'type': kind},
27
+ 'assignees': [{'login': a} for a in assignees], 'labels': [{'name': n} for n in labels]}
28
+
29
+
30
+ def proposal(priority='P1', add=('bug', 'priority:high'), remove=(), rationale='Flows editor fails for every bot.'):
31
+ return {'priority': priority, 'add': list(add), 'remove': list(remove), 'rationale': rationale}
32
+
33
+
34
+ def write(name, value):
35
+ path = scratch / name
36
+ path.write_text(value if isinstance(value, str) else json.dumps(value), encoding='utf-8')
37
+ return str(path)
38
+
39
+
40
+ def run(issue_data=None, plan=None, labels=REPO_LABELS, assignable='yes', extra=()):
41
+ issue_data = issue() if issue_data is None else issue_data
42
+ plan = proposal() if plan is None else plan
43
+ pages = labels if isinstance(labels, str) else [[{'name': n} for n in labels]]
44
+ args = ['--repo', 'example/repo', '--issue-json', write('issue.json', issue_data),
45
+ '--labels-json', write('labels.json', pages), '--proposal-json', write('proposal.json', plan),
46
+ '--author-assignable', assignable]
47
+ result = subprocess.run([sys.executable, '-I', '-B', str(script), *args, *extra],
48
+ capture_output=True, text=True, encoding='utf-8')
49
+ try:
50
+ report = json.loads(result.stdout)
51
+ except ValueError:
52
+ report = {'verdict': None, 'raw': result.stdout + result.stderr}
53
+ return result.returncode, report
54
+
55
+
56
+ def expect(label, observed, status, verdict, rules=(), **fields):
57
+ global checks
58
+ checks += 1
59
+ code, report = observed
60
+ got = (code, report.get('verdict'), sorted({f['rule'] for f in report.get('findings', [])}))
61
+ want = (status, verdict, sorted(rules))
62
+ wrong = {key: report.get(key) for key, value in fields.items() if report.get(key) != value}
63
+ if got != want or wrong:
64
+ failures.append(label + ': expected ' + repr((want, fields)) + ', observed ' + repr(got) + ' '
65
+ + json.dumps(report))
66
+
67
+
68
+ # assignment: the issue author, never anyone else
69
+ expect('author assigned and labels added', run(), 0, 'ready', assign='carla',
70
+ labels_add=['bug', 'priority:high'], labels_remove=[], priority='P1', priority_label='priority:high')
71
+ expect('author already assigned is a no-op', run(issue(assignees=['carla'])), 0, 'ready', assign=None,
72
+ already_assigned=True)
73
+ expect('other assignees are kept, the author is added', run(issue(assignees=['bob'])), 0, 'ready', assign='carla')
74
+ expect('a bot author is not assigned (TR2)', run(issue(author='dependabot[bot]', kind='Bot')),
75
+ 0, 'ready-with-gaps', ['TR2'], assign=None)
76
+ expect('a [bot] login without type is a bot (TR2)', run(issue(author='renovate[bot]', kind='User')),
77
+ 0, 'ready-with-gaps', ['TR2'], assign=None)
78
+ expect('an author without access is not assigned (TR3)', run(assignable='no'),
79
+ 0, 'ready-with-gaps', ['TR3'], assign=None)
80
+ expect('unverified assignability is not assigned (TR3)', run(assignable='unknown'),
81
+ 0, 'ready-with-gaps', ['TR3'], assign=None)
82
+
83
+ # labels: only labels that already exist, matched case-insensitively to their real name
84
+ expect('a label missing in the repository is dropped (TR4)', run(plan=proposal(add=('bug', 'area:billing', 'priority:high'))),
85
+ 0, 'ready-with-gaps', ['TR4'], labels_add=['bug', 'priority:high'], missing_labels=['area:billing'])
86
+ expect('case-insensitive match uses the repository name', run(plan=proposal(add=('BUG', 'area: inbox', 'priority:high'))),
87
+ 0, 'ready', labels_add=['bug', 'Area: Inbox', 'priority:high'])
88
+ expect('a label already on the issue is not re-added', run(issue(labels=['bug'])), 0, 'ready',
89
+ labels_add=['priority:high'])
90
+ expect('a wrong type label is removed', run(issue(labels=['enhancement']), proposal(remove=('enhancement',))),
91
+ 0, 'ready', labels_remove=['enhancement'])
92
+ expect('removing a label the issue does not have is ignored', run(plan=proposal(remove=('enhancement',))),
93
+ 0, 'ready', labels_remove=[])
94
+ expect('the claim label is protected (TR5)', run(plan=proposal(add=('bug', 'priority:high', 'status:in-progress'))),
95
+ 1, 'invalid-proposal', ['TR5'])
96
+ expect('removing a status label is protected (TR5)',
97
+ run(issue(labels=['status:in-progress']), proposal(remove=('status:in-progress',))),
98
+ 1, 'invalid-proposal', ['TR5'])
99
+ expect('a custom claim label is protected (TR5)',
100
+ run(plan=proposal(add=('bug', 'priority:high', 'wip')), labels=REPO_LABELS + ['wip'], extra=['--claim-label', 'wip']),
101
+ 1, 'invalid-proposal', ['TR5'])
102
+ expect('add and remove the same label (TR1)', run(plan=proposal(remove=('bug',))), 2, 'unusable', ['TR1'])
103
+
104
+ # priority: one level, one label, matching each other
105
+ expect('re-prioritizing replaces the old priority label', run(issue(labels=['priority:low'])),
106
+ 0, 'ready', labels_add=['bug', 'priority:high'], labels_remove=['priority:low'])
107
+ expect('two priority labels (TR6)', run(plan=proposal(add=('bug', 'priority:high', 'priority:low'))),
108
+ 1, 'invalid-proposal', ['TR6'])
109
+ expect('a label of another level (TR7)', run(plan=proposal(priority='P0', add=('bug', 'priority:low'))),
110
+ 1, 'invalid-proposal', ['TR7'])
111
+ expect('P0 maps to critical', run(plan=proposal(priority='P0', add=('bug', 'priority:critical'))),
112
+ 0, 'ready', priority_label='priority:critical')
113
+ expect('P-number labels are understood', run(plan=proposal(priority='P2', add=('bug', 'P2'))
114
+ , labels=['bug', 'P0', 'P1', 'P2', 'P3']), 0, 'ready', priority_label='P2')
115
+ expect('the priority label is derived from the level', run(plan=proposal(add=('bug',))),
116
+ 0, 'ready', labels_add=['bug', 'priority:high'], priority_label='priority:high')
117
+ expect('Spanish priority labels are understood', run(plan=proposal(priority='P3', add=('bug',)),
118
+ labels=['bug', 'prioridad: alta', 'prioridad: baja']), 0, 'ready', priority_label='prioridad: baja')
119
+ expect('two repository labels for one level must be chosen explicitly (TR7)',
120
+ run(plan=proposal(add=('bug',)), labels=REPO_LABELS + ['P1']), 1, 'invalid-proposal', ['TR7'])
121
+ expect('no repository label for the level (TR8)', run(plan=proposal(priority='P0', add=('bug',)),
122
+ labels=['bug', 'priority:high', 'priority:low']), 0, 'ready-with-gaps', ['TR8'], priority_label=None)
123
+ expect('area labels are not priority labels', run(plan=proposal(add=('bug', 'area:flows'))),
124
+ 0, 'ready', labels_add=['bug', 'area:flows', 'priority:high'])
125
+ expect('without priority labels the priority goes in the comment (TR8)',
126
+ run(plan=proposal(add=('bug',)), labels=['bug', 'enhancement']), 0, 'ready-with-gaps', ['TR8'],
127
+ priority='P1', priority_label=None)
128
+ expect('the priority label already on the issue is kept', run(issue(labels=['priority:high'])),
129
+ 0, 'ready', labels_add=['bug'], labels_remove=[], priority_label='priority:high')
130
+
131
+ # commands: exactly what the plan writes, nothing else
132
+ code, report = run(issue(labels=['priority:low']))
133
+ checks += 1
134
+ commands = report.get('commands', [])
135
+ want = ['gh api -X POST repos/example/repo/issues/12/assignees -f "assignees[]=carla"',
136
+ 'gh api -X POST repos/example/repo/issues/12/labels -f "labels[]=bug" -f "labels[]=priority:high"',
137
+ 'gh api -X DELETE repos/example/repo/issues/12/labels/priority%3Alow']
138
+ if commands != want:
139
+ failures.append('commands: expected ' + repr(want) + ', observed ' + repr(commands))
140
+ checks += 1
141
+ _, spaced = run(plan=proposal(add=('Area: Inbox', 'priority:high')), extra=[])
142
+ if 'gh api -X POST repos/example/repo/issues/12/labels -f "labels[]=Area: Inbox" -f "labels[]=priority:high"' \
143
+ not in spaced.get('commands', []):
144
+ failures.append('label names with spaces must stay quoted: ' + json.dumps(spaced))
145
+ checks += 1
146
+ _, noop = run(issue(assignees=['carla'], labels=['bug', 'priority:high']))
147
+ if noop.get('commands') != []:
148
+ failures.append('nothing to change must yield no commands: ' + json.dumps(noop))
149
+
150
+ # unusable input
151
+ expect('priority must be P0-P3 (TR1)', run(plan=proposal(priority='urgent')), 2, 'unusable', ['TR1'])
152
+ expect('a rationale is required (TR1)', run(plan=proposal(rationale=' ')), 2, 'unusable', ['TR1'])
153
+ expect('issue JSON must be valid (TR1)', run('{'), 2, 'unusable', ['TR1'])
154
+ expect('labels JSON must be an array (TR1)', run(labels='{"name": "bug"}'), 2, 'unusable', ['TR1'])
155
+ expect('assignability must be yes, no or unknown (TR1)', run(assignable='maybe'), 2, 'unusable', ['TR1'])
156
+ expect('closed issues are not triaged (TR1)', run({**issue(), 'state': 'closed'}), 2, 'unusable', ['TR1'])
157
+
158
+ checks += 1
159
+ result = subprocess.run([sys.executable, '-I', '-B', str(script), '--help'], capture_output=True, text=True)
160
+ if result.returncode != 0 or 'Usage' not in result.stdout:
161
+ failures.append('--help must print usage and exit 0')
162
+
163
+ if failures:
164
+ for item in failures:
165
+ print('FAIL:', item, file=sys.stderr)
166
+ sys.exit(1)
167
+ print(f'PASS {checks} checks')
168
+ PY
@@ -0,0 +1,66 @@
1
+ ---
2
+ name: question-gate
3
+ description: "Trigger: before stopping, before asking the user, Question Gate, should I ask, next step question. Run before finishing a turn or asking the user a question: route delegable questions to the owning diagram skill and surface only genuine human approval gates."
4
+ license: Apache-2.0
5
+ compatibility: Requires Python 3.8+ for the bundled triage command.
6
+ metadata:
7
+ author: bbc-skill-internals
8
+ version: "1.1"
9
+ pre_hook: "AGENTS.md -> python3 -I -B scripts/triage-question.py --question"
10
+ post_hook: "stop / AfterAgent / experimental.idle -> python3 -I -B scripts/triage-question.py --stdin --format <client>"
11
+ post_install: "configure client stop hook JSON per references/client-hooks.md"
12
+ scripts: "scripts/triage-question.py"
13
+ ---
14
+
15
+ ## Activation Contract
16
+
17
+ Run before finishing a turn with a question or pausing to ask the user what to do next, across Cursor, Claude, Claude Code, Codex, Gemini CLI, OpenCode, and Pi. Answers one question: *"Do I really need to ask the user this, or can a skill in the workflow diagram resolve it (or is it already authorized)?"*
18
+
19
+ **Company role:** Workflow Gatekeeper. It routes delegable work back to the skill that owns it in the diagram; it never grants approvals on a person's behalf.
20
+
21
+ ## Hard Rules
22
+
23
+ - **Never offload agent work to the user.** Questions like *"ΒΏprefieres probarlo primero en local?"*, *"should I run the tests?"*, *"does this affect docs?"*, *"is there a duplicate issue?"*, or *"what should we do next?"* belong to skills in the diagram (`regression-testing`, `code-quality-gate`, `documentation-steward`, `risk-scout`, `greptile-review-loop`, `workflow-auditor`, `tool-depot`, `delivery-coordinator`), never to the user.
24
+ - **Never bundle a delegable task with a human approval.** Split compound questions first: resolve every delegable clause through its owning skill, verify prerequisites, and check whether any human decision actually remains.
25
+ - **Check existing authorizations before asking.** Read `bbc-delivery-ledger.json` (when present) and the session instructions. If a person already authorized `implement` or `commit_pr`, do not ask again. Never invent an authorization (`A2`).
26
+ - **Escalate only genuine human gates.** Only people decide `Product Manager` open product trade-offs, `Tech Lead` change authorization, `Commit & PR` / `publish-approved-issue` when not yet authorized, `Code Owner` merge, `Release Owner` deployment, and `Tool Depot` `needs-approval` targets. Keep each remaining human question to one focused decision with a clear recommendation and why.
27
+
28
+ ## Decision Gates
29
+
30
+ | Verdict from `triage-question.py` | Action |
31
+ |---|---|
32
+ | `no_question` | Safe to finish the turn. |
33
+ | `allow_question` | Genuine human gate only (`human_approval_required`). Present the single focused decision with your recommendation and wait for the person. |
34
+ | `block_question` (`do_not_ask`) | Do **not** ask the blocked clause. Execute the named `resolved_by` diagram skill(s) (or proceed directly if `already_authorized`), then rerun the gate if a separate human approval still remains. |
35
+ | `block_question` with a `needs_classification` clause | No skill or human rule recognised the clause. Route it to its owning skill, or, if a person must decide, declare the owner with a `🟑 BOSS GATE ─ <Role>` header (`PM`, `Tech Lead`, `Commit & PR`, `Code Owner`, `Release Owner`) and rerun the gate: a valid declared role turns it into `allow_question` for that role. An invented role stays blocked. |
36
+ | `block_format` | Reformat the human decision or choice prompt using the Quest-Tree HUD + `🟑 BOSS GATE` (`❓`, `πŸ‘‰ Recomendado: [A]`, `⚑ Opciones` with `[A]`/`[B]`) before stopping. |
37
+ | `unusable` | Fix invalid CLI arguments or malformed ledger JSON before proceeding. |
38
+
39
+ ## Execution Steps
40
+
41
+ 1. Before sending any final message that asks the user a question (or pauses for next steps), run:
42
+ ```bash
43
+ python3 -I -B <skill-root>/scripts/triage-question.py --question "<draft question>"
44
+ ```
45
+ (From a delivery worktree, it automatically reads `bbc-delivery-ledger.json` unless `--ledger` or `--no-ledger` is passed.)
46
+ 2. Inspect `verdict`, `clauses`, `resolved_by`, and `rewrite_suggestion` in the JSON output.
47
+ 3. For every clause marked `delegate_to_skill`, invoke that diagram skill (or run the verification/check using the repository's tools) instead of asking the user.
48
+ 4. For any clause marked `already_authorized`, proceed directly with that authorized stage (`Commit & PR`, etc.).
49
+ 5. Only if a `human_approval_required` clause remains after prerequisites pass, ask the user that isolated decision using the [diagram routing table](references/diagram-routing.md).
50
+
51
+ ## Companion Handoffs
52
+
53
+ Route each blocked clause to the skill named by `resolved_by`: `regression-testing`, `code-quality-gate`, `skill-clean-architecture`, `documentation-steward`, `risk-scout`, `greptile-review-loop`, `workflow-auditor`, `watcher-observability`, `tool-depot`, `requirements-spec`, or `delivery-coordinator`.
54
+
55
+ Check the active skill catalog for the named companion before relying on it; if a companion is missing, perform the equivalent check with the host repository's tools when authorized rather than pushing the work onto the user.
56
+
57
+ ## Output Contract
58
+
59
+ - **Machine / hook mode (`triage-question.py`):** return `verdict`, `resolved_by`, `human_gates`, and `rewrite_suggestion` (if any) without leaking secrets, tokens, or raw logs.
60
+ - **Human-facing chat mode (`allow_question`):** format the single isolated `human_approval_required` gate as a compact **Quest-Tree Boss Gate** (`🟑 BOSS GATE ─ <Role>`, `❓` 1-line question, `πŸ‘‰ Recomendado: [A]`, `⚑ Opciones: [A] / [B]`), matching the user's language for fast decisions. See [diagram-routing.md](references/diagram-routing.md#agile-decision-card).
61
+
62
+ ## References
63
+
64
+ - [Diagram routing table and examples](references/diagram-routing.md)
65
+ - [Pre-exit hook setup for Cursor, Claude Code, Codex, and CLI clients](references/client-hooks.md)
66
+ - [Question triage CLI](scripts/triage-question.py)
@@ -0,0 +1,111 @@
1
+ # Client integration for Question Gate
2
+
3
+ Run `triage-question.py` both **preventively** (via `AGENTS.md` / rules before drafting a question) and **deterministically** (via each client's native turn-end / stop hook).
4
+
5
+ ## Universal command (every client)
6
+
7
+ ```bash
8
+ python3 -I -B <path-to-question-gate>/scripts/triage-question.py --question "<draft question>"
9
+ ```
10
+
11
+ - Exit `0`: `no_question` or `allow_question` (genuine human approval gate only).
12
+ - Exit `1`: `block_question` β€” at least one clause can be resolved by a skill in the diagram (`delegate_to_skill`) or is `already_authorized` in the delivery ledger β€” or `block_format` when `--require-hud` is set and a human gate / choice offer lacks the `🟑 BOSS GATE` format.
13
+ - Exit `2`: `unusable` input or malformed ledger.
14
+
15
+ In client hook modes (`--format cursor-hook`, `claude-hook`, `codex-hook`, `gemini-hook`), `triage-question.py` enforces the `🟑 BOSS GATE` format automatically for any genuine human decision or numbered choice offer (`Si quieres: 1. ... 2. ...`) unless `--no-hud` is passed.
16
+
17
+ ## Cursor (`.cursor/hooks.json` or `~/.cursor/hooks.json`)
18
+
19
+ Cursor's `stop` hook receives `status`, `loop_count`, and `transcript_path` (`.jsonl`), and returns `{"followup_message": "..."}` to continue the turn automatically. When `status != "completed"` or `loop_count >= 2`, `triage-question.py` returns `{}` so user aborts or loop limits never spin.
20
+
21
+ Project-level `.cursor/hooks.json`:
22
+
23
+ ```json
24
+ {
25
+ "version": 1,
26
+ "hooks": {
27
+ "stop": [
28
+ {
29
+ "command": "python3 -I -B .cursor/skills/question-gate/scripts/triage-question.py --stdin --format cursor-hook",
30
+ "loop_limit": 2
31
+ }
32
+ ]
33
+ }
34
+ }
35
+ ```
36
+
37
+ (Cursor also reads Claude Code `.claude/settings.json` `Stop` hooks automatically when Third-Party Imports is enabled.)
38
+
39
+ ## Claude Code (`.claude/settings.json` or `~/.claude/settings.json`)
40
+
41
+ Claude Code's `Stop` hook receives `last_assistant_message` and `stop_hook_active`, and returns `{"decision": "block", "reason": "..."}`. When `stop_hook_active` is `true`, `triage-question.py` returns `{}` to prevent infinite loops.
42
+
43
+ ```json
44
+ {
45
+ "hooks": {
46
+ "Stop": [
47
+ {
48
+ "hooks": [
49
+ {
50
+ "type": "command",
51
+ "command": "python3 -I -B .claude/skills/question-gate/scripts/triage-question.py --stdin --format claude-hook"
52
+ }
53
+ ]
54
+ }
55
+ ]
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## OpenAI Codex CLI (`.codex/hooks.json` or `~/.codex/hooks.json`)
61
+
62
+ Codex CLI supports `Stop` hooks with `last_assistant_message` and `stop_hook_active`, returning `{"decision": "block", "reason": "..."}`. Review and trust non-managed hooks with `/hooks` in the CLI.
63
+
64
+ ```json
65
+ {
66
+ "hooks": {
67
+ "Stop": [
68
+ {
69
+ "hooks": [
70
+ {
71
+ "type": "command",
72
+ "command": "python3 -I -B \"$(git rev-parse --show-toplevel)/.codex/skills/question-gate/scripts/triage-question.py\" --stdin --format codex-hook",
73
+ "timeout": 10
74
+ }
75
+ ]
76
+ }
77
+ ]
78
+ }
79
+ }
80
+ ```
81
+
82
+ Also place the preventive rule in `~/.codex/AGENTS.md` (user-wide) or the repository's `AGENTS.md`.
83
+
84
+ ## Gemini CLI (`.gemini/settings.json` or `~/.gemini/settings.json`)
85
+
86
+ Gemini CLI uses the `AfterAgent` hook, which passes `prompt_response` and `stop_hook_active` and retries when the hook returns `{"decision": "deny", "reason": "..."}` with exit code `0` (`continue: false` would halt the session, so `--format gemini-hook` uses `decision: "deny"`).
87
+
88
+ ```json
89
+ {
90
+ "hooks": {
91
+ "AfterAgent": [
92
+ {
93
+ "matcher": "*",
94
+ "hooks": [
95
+ {
96
+ "name": "question-gate",
97
+ "type": "command",
98
+ "command": "python3 -I -B .gemini/skills/question-gate/scripts/triage-question.py --stdin --format gemini-hook"
99
+ }
100
+ ]
101
+ }
102
+ ]
103
+ }
104
+ }
105
+ ```
106
+
107
+ ## OpenCode v2, Pi, and Claude (desktop/web)
108
+
109
+ - **OpenCode v2**: loads `~/.config/opencode/AGENTS.md` and workspace `AGENTS.md` automatically; plugin authors can also wire `triage-question.py` into the `experimental.idle` session hook before the session goes idle.
110
+ - **Pi**: loads `AGENTS.md` + `.agents/skills/question-gate/`.
111
+ - **Claude (desktop/web)**: upload `question-gate` as a Skill `.zip`; in web/sandboxed environments without shell hooks, apply [diagram-routing.md](diagram-routing.md) before emitting any question.
@@ -0,0 +1,58 @@
1
+ # Diagram routing for questions before stopping
2
+
3
+ Every box in the BuilderBot workflow diagram owns a class of decisions or checks. Before asking the user a question, map each clause to the diagram owner.
4
+
5
+ ## Canonical example
6
+
7
+ Draft question:
8
+
9
+ > "ΒΏQuieres que haga el commit, cree la issue y abra el PR en el repositorio o prefieres probarlo primero en local?"
10
+
11
+ Split into clauses:
12
+
13
+ 1. `"prefieres probarlo primero en local"`
14
+ - **Diagram owner:** `regression-testing` (QA Engineer) + `code-quality-gate` (Software Engineer self-check).
15
+ - **Disposition:** `delegate_to_skill` (**do not ask**). Run focused tests, typecheck, lint, quality gate, or local smoke checks yourself and report the evidence. Never ask the user to act as QA.
16
+ 2. `"Quieres que haga el commit, cree la issue y abra el PR"`
17
+ - **Diagram owner:** `delivery-coordinator` checks `authorizations` -> `πŸ‘€ Authorization to commit and publish`.
18
+ - **Disposition:**
19
+ - If `verify` or `quality` is still missing in the delivery ledger -> `delegate_to_skill` (finish verification and quality gate first).
20
+ - If `commit_pr` is already covered by a `person` authorization in the ledger (or explicitly requested in the session) -> `already_authorized` (proceed to Commit & PR, then `greptile-review-loop` and `workflow-auditor`).
21
+ - Otherwise -> `human_approval_required`: ask **only** the isolated publication decision with a recommendation, with zero QA fallback attached.
22
+
23
+ ## Routing table
24
+
25
+ | Question / pause intent | Diagram owner | Disposition | Action |
26
+ |---|---|---|---|
27
+ | Test locally, run tests, reproduce bug, verify fix | `regression-testing` | `delegate_to_skill` | Run or rerun the focused test suite and report RED/GREEN evidence. |
28
+ | Check types, lint, BigO, early return, code quality | `code-quality-gate` | `delegate_to_skill` | Run `extract-diff-scope.py` + typechecker and fix any `block`. |
29
+ | Check layer boundaries, DDD placement, file headers | `skill-clean-architecture` | `delegate_to_skill` | Inspect touched layers and run `measure-bigo.py`. |
30
+ | Audit or update local docs / README | `documentation-steward` | `delegate_to_skill` | Audit the exact diff in `audit` mode; update only if authorized. |
31
+ | Assess failure modes, rollout or operational risk | `risk-scout` | `delegate_to_skill` | Build the 5 scenarios and risk matrix before asking. |
32
+ | Check Greptile score, review threads, or 5/5 loop | `greptile-review-loop` | `delegate_to_skill` | Run the bounded review loop on the current PR head. |
33
+ | Verify workflow order, ledger, or Tool Depot usage | `workflow-auditor` | `delegate_to_skill` | Run `audit-ledger.py` and the semantic pass. |
34
+ | Inspect container logs or incident timeline | `watcher-observability` | `delegate_to_skill` | Check existing `report.json` or request bounded Watcher read via `tool-depot`. |
35
+ | Search duplicate issues, read PR, or check public docs | `tool-depot` (`github-read` / `public-web`) | `delegate_to_skill` | Submit a Tool Depot checkout request and execute if `eligible`. |
36
+ | Decide next workflow step or which skill runs next | `delivery-coordinator` | `delegate_to_skill` | Follow the earliest unmet stage in the handoff contracts. |
37
+ | Commit, push, publish issue, or open PR | `delivery-coordinator` + `πŸ‘€ Person` | `already_authorized` or `human_approval_required` | Execute if `commit_pr` is already authorized and prerequisites are GREEN; otherwise ask only for that authorization. |
38
+ | Ambiguous product behavior or UX trade-off | `requirements-spec` -> `πŸ‘€ Product Manager` | `human_approval_required` | Check existing issue/PRD first; if open, ask using `Open Decision Question Format`. |
39
+ | Merge PR / approve Code Owner review | `πŸ‘€ Code Owner` | `human_approval_required` | Hand off PR, criteria, verification, Greptile score, and `workflow-auditor` verdict. |
40
+ | Deploy / release to production | `πŸ‘€ Release Owner` | `human_approval_required` | Hand off readiness conditions and residual risks. |
41
+ | Approve SSH target or unauthorized `github-write` | `tool-depot` -> `πŸ‘€ Person` | `human_approval_required` | Ask for the exact missing authorization (`needs-approval`). |
42
+
43
+ ## Agile Decision Card
44
+
45
+ When `verdict` is `allow_question`, present the remaining `human_approval_required` gate as a compact **Quest-Tree Boss Gate** so the person can decide fast:
46
+
47
+ ```text
48
+ 🟑 BOSS GATE ─ <Role>
49
+ β”‚
50
+ β”œβ”€β”€ ❓ <1-line question?>
51
+ β”‚
52
+ β”œβ”€β”€ πŸ‘‰ Recomendado: [A]
53
+ β”‚ └── <1-line reason>
54
+ β”‚
55
+ └── ⚑ Opciones
56
+ β”œβ”€β”€ [A] <action>
57
+ └── [B] <action>
58
+ ```