@bbcsoftwarefactory/skills 0.1.1 → 1.1.3
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.
- package/dist/index.json +2 -3
- package/dist/skills/code-quality-gate/SKILL.md +4 -5
- package/dist/skills/code-quality-gate/references/gate-bigo.md +1 -1
- package/dist/skills/delivery-coordinator/SKILL.md +7 -8
- package/dist/skills/delivery-coordinator/references/hud-output.md +1 -1
- package/dist/skills/delivery-coordinator/references/issue-claim.md +5 -5
- package/dist/skills/delivery-coordinator/references/issue-dedup.md +1 -1
- package/dist/skills/delivery-coordinator/references/worktree-isolation.md +2 -2
- package/dist/skills/greptile-review-loop/SKILL.md +3 -4
- package/dist/skills/greptile-review-loop/references/review-protocol.md +1 -1
- package/dist/skills/issue-reviewer/SKILL.md +10 -13
- package/dist/skills/issue-reviewer/references/review-format.md +1 -1
- package/dist/skills/issue-reviewer/references/triage.md +6 -6
- package/dist/skills/question-gate/SKILL.md +6 -8
- package/dist/skills/question-gate/references/client-hooks.md +10 -10
- package/dist/skills/question-gate/references/diagram-routing.md +3 -3
- package/dist/skills/skill-clean-architecture/SKILL.md +2 -3
- package/dist/skills/skill-clean-architecture/references/source-headers.md +2 -3
- package/dist/skills/tool-depot/references/readonly-access.md +1 -1
- package/dist/skills/tool-depot/references/tool-catalog.json +2 -2
- package/dist/skills/watcher-observability/SKILL.md +3 -4
- package/dist/skills/watcher-observability/references/batch-protocol.md +6 -6
- package/dist/skills/watcher-observability/references/configuration.md +1 -1
- package/dist/skills/watcher-observability/references/error-scan.md +1 -1
- package/dist/skills/watcher-observability/references/live-protocol.md +8 -8
- package/dist/skills/watcher-observability/references/server-account.md +8 -8
- package/dist/skills/watcher-observability/server/watcher-gate.sh +1 -1
- package/dist/skills/watcher-observability/tests/watcher-gate.test.sh +10 -7
- package/dist/skills/workflow-auditor/SKILL.md +3 -5
- package/dist/skills/workflow-auditor/references/audit-protocol.md +3 -3
- package/dist/skills/workflow-auditor/references/ledger.md +1 -1
- package/package.json +26 -27
- package/dist/skills/code-quality-gate/scripts/extract-diff-scope.py +0 -225
- package/dist/skills/code-quality-gate/tests/extract-diff-scope.test.sh +0 -200
- package/dist/skills/delivery-coordinator/scripts/check-issue-claim.py +0 -363
- package/dist/skills/delivery-coordinator/scripts/check-worktree-guard.py +0 -220
- package/dist/skills/delivery-coordinator/scripts/classify-change-lane.py +0 -263
- package/dist/skills/delivery-coordinator/tests/check-issue-claim.test.sh +0 -221
- package/dist/skills/delivery-coordinator/tests/check-worktree-guard.test.sh +0 -123
- package/dist/skills/delivery-coordinator/tests/classify-change-lane.test.sh +0 -124
- package/dist/skills/greptile-review-loop/scripts/review-loop.py +0 -435
- package/dist/skills/greptile-review-loop/tests/review-loop.test.sh +0 -331
- package/dist/skills/issue-reviewer/scripts/fetch-issue-attachments.py +0 -239
- package/dist/skills/issue-reviewer/scripts/plan-issue-triage.py +0 -311
- package/dist/skills/issue-reviewer/tests/fetch-issue-attachments.test.sh +0 -90
- package/dist/skills/issue-reviewer/tests/plan-issue-triage.test.sh +0 -168
- package/dist/skills/question-gate/scripts/triage-question.py +0 -713
- package/dist/skills/question-gate/tests/question-corpus.test.sh +0 -32
- package/dist/skills/question-gate/tests/triage-question.test.sh +0 -441
- package/dist/skills/skill-clean-architecture/scripts/measure-bigo.py +0 -427
- package/dist/skills/skill-clean-architecture/tests/measure-bigo.test.sh +0 -222
- package/dist/skills/watcher-observability/scripts/error-scan.py +0 -318
- package/dist/skills/watcher-observability/scripts/resolve-containers.py +0 -155
- package/dist/skills/watcher-observability/scripts/save-counts.py +0 -381
- package/dist/skills/watcher-observability/scripts/summarize-logs.py +0 -113
- package/dist/skills/watcher-observability/scripts/watch-live.py +0 -606
- package/dist/skills/watcher-observability/tests/error-scan.test.sh +0 -257
- package/dist/skills/watcher-observability/tests/live-windows.test.sh +0 -177
- package/dist/skills/watcher-observability/tests/resolve-containers.test.sh +0 -87
- package/dist/skills/watcher-observability/tests/save-counts.test.sh +0 -338
- package/dist/skills/watcher-observability/tests/sleuth.test.sh +0 -176
- package/dist/skills/watcher-observability/tests/summarize-logs.test.sh +0 -105
- package/dist/skills/watcher-observability/tests/watcher-config.test.sh +0 -70
- package/dist/skills/workflow-auditor/scripts/audit-ledger.py +0 -624
- package/dist/skills/workflow-auditor/scripts/list-zed-commands.py +0 -183
- package/dist/skills/workflow-auditor/scripts/render-workflow.py +0 -201
- package/dist/skills/workflow-auditor/scripts/validate-skills.py +0 -444
- package/dist/skills/workflow-auditor/tests/audit-ledger.test.sh +0 -660
- package/dist/skills/workflow-auditor/tests/list-zed-commands.test.sh +0 -93
- package/dist/skills/workflow-auditor/tests/render-workflow.test.sh +0 -135
- package/dist/skills/workflow-auditor/tests/validate-skills.test.sh +0 -190
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""check-worktree-guard.py: enforce linked feat/<task> worktree isolation before edits.
|
|
3
|
-
|
|
4
|
-
Read-only: checks whether a target path or working directory lives inside a linked Git
|
|
5
|
-
worktree on a feat/<task> branch. Supports standalone CLI and client hook modes.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import json
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
import subprocess
|
|
11
|
-
import sys
|
|
12
|
-
|
|
13
|
-
PROTECTED_BRANCHES = {'main', 'master', 'HEAD'}
|
|
14
|
-
|
|
15
|
-
HELP = (
|
|
16
|
-
'Usage: python3 -I -B scripts/check-worktree-guard.py '
|
|
17
|
-
'[--path <dir>] [--target-path <file>] [--stdin --format json|claude-hook|cursor-hook|codex-hook]\n'
|
|
18
|
-
'Exit 0: allowed linked feat/<task> worktree; 1: blocked (primary/non-feat); 2: unusable.\n'
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def _write_out(text):
|
|
23
|
-
sys.stdout.buffer.write((text + '\n').encode('utf-8', 'surrogateescape'))
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def _existing_dir(path_str):
|
|
27
|
-
candidate = Path(path_str).expanduser()
|
|
28
|
-
try:
|
|
29
|
-
resolved = candidate.resolve()
|
|
30
|
-
except OSError:
|
|
31
|
-
resolved = candidate
|
|
32
|
-
cur = resolved
|
|
33
|
-
while not cur.exists() and cur != cur.parent:
|
|
34
|
-
cur = cur.parent
|
|
35
|
-
if not cur.exists():
|
|
36
|
-
return None
|
|
37
|
-
return cur if cur.is_dir() else cur.parent
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def _git_info(directory):
|
|
41
|
-
try:
|
|
42
|
-
res = subprocess.run(
|
|
43
|
-
['git', '-C', str(directory), 'rev-parse', '--git-dir', '--git-common-dir',
|
|
44
|
-
'--abbrev-ref', 'HEAD', '--show-toplevel'],
|
|
45
|
-
stdout=subprocess.PIPE,
|
|
46
|
-
stderr=subprocess.PIPE,
|
|
47
|
-
timeout=10,
|
|
48
|
-
)
|
|
49
|
-
except (OSError, subprocess.SubprocessError):
|
|
50
|
-
return None
|
|
51
|
-
if res.returncode != 0:
|
|
52
|
-
return None
|
|
53
|
-
lines = res.stdout.decode('utf-8', 'surrogateescape').splitlines()
|
|
54
|
-
if len(lines) < 4:
|
|
55
|
-
return None
|
|
56
|
-
git_dir_raw, common_dir_raw, branch, toplevel = lines[0], lines[1], lines[2].strip(), lines[3]
|
|
57
|
-
git_dir = Path(git_dir_raw)
|
|
58
|
-
common_dir = Path(common_dir_raw)
|
|
59
|
-
if not git_dir.is_absolute():
|
|
60
|
-
git_dir = (directory / git_dir).resolve()
|
|
61
|
-
else:
|
|
62
|
-
git_dir = git_dir.resolve()
|
|
63
|
-
if not common_dir.is_absolute():
|
|
64
|
-
common_dir = (directory / common_dir).resolve()
|
|
65
|
-
else:
|
|
66
|
-
common_dir = common_dir.resolve()
|
|
67
|
-
return {
|
|
68
|
-
'is_linked_worktree': git_dir != common_dir,
|
|
69
|
-
'branch': branch,
|
|
70
|
-
'toplevel': toplevel,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def evaluate_path(path_str):
|
|
75
|
-
directory = _existing_dir(path_str)
|
|
76
|
-
if directory is None:
|
|
77
|
-
return {'decision': 'unusable', 'reason': f'Path does not exist: {path_str}'}, 2
|
|
78
|
-
info = _git_info(directory)
|
|
79
|
-
if info is None:
|
|
80
|
-
return {'decision': 'unusable', 'reason': 'Target directory is not inside a Git worktree.'}, 2
|
|
81
|
-
|
|
82
|
-
branch = info['branch']
|
|
83
|
-
is_linked = info['is_linked_worktree']
|
|
84
|
-
is_feat = branch.startswith('feat/') and len(branch) > len('feat/')
|
|
85
|
-
|
|
86
|
-
if not is_linked:
|
|
87
|
-
return {
|
|
88
|
-
'decision': 'block',
|
|
89
|
-
'is_linked_worktree': False,
|
|
90
|
-
'branch': branch,
|
|
91
|
-
'toplevel': info['toplevel'],
|
|
92
|
-
'reason': (
|
|
93
|
-
f'Blocked write in primary checkout (branch {branch!r}). '
|
|
94
|
-
'Prepare a linked Git worktree on feat/<task> first.'
|
|
95
|
-
),
|
|
96
|
-
}, 1
|
|
97
|
-
|
|
98
|
-
if branch in PROTECTED_BRANCHES or not is_feat:
|
|
99
|
-
return {
|
|
100
|
-
'decision': 'block',
|
|
101
|
-
'is_linked_worktree': True,
|
|
102
|
-
'branch': branch,
|
|
103
|
-
'toplevel': info['toplevel'],
|
|
104
|
-
'reason': (
|
|
105
|
-
f'Blocked write on non-feature branch {branch!r}. '
|
|
106
|
-
'Worktrees must use a unique feat/<task> branch.'
|
|
107
|
-
),
|
|
108
|
-
}, 1
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
'decision': 'allow',
|
|
112
|
-
'is_linked_worktree': True,
|
|
113
|
-
'branch': branch,
|
|
114
|
-
'toplevel': info['toplevel'],
|
|
115
|
-
'reason': f'Verified linked worktree on {branch}.',
|
|
116
|
-
}, 0
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def _extract_payload_path(payload):
|
|
120
|
-
if not isinstance(payload, dict):
|
|
121
|
-
return None
|
|
122
|
-
tool_input = payload.get('tool_input')
|
|
123
|
-
if isinstance(tool_input, dict):
|
|
124
|
-
for key in ('file_path', 'path', 'target_file', 'working_directory'):
|
|
125
|
-
val = tool_input.get(key)
|
|
126
|
-
if isinstance(val, str) and val.strip():
|
|
127
|
-
return val.strip()
|
|
128
|
-
for key in ('file_path', 'path', 'cwd', 'working_directory'):
|
|
129
|
-
val = payload.get(key)
|
|
130
|
-
if isinstance(val, str) and val.strip():
|
|
131
|
-
return val.strip()
|
|
132
|
-
return None
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def _format_hook(report, status, fmt):
|
|
136
|
-
if status == 0 or status == 2:
|
|
137
|
-
return {}
|
|
138
|
-
reason = report['reason']
|
|
139
|
-
if fmt == 'cursor-hook':
|
|
140
|
-
return {
|
|
141
|
-
'permission': 'deny',
|
|
142
|
-
'user_message': reason,
|
|
143
|
-
'agent_message': reason,
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
'decision': 'block',
|
|
147
|
-
'reason': reason,
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def parse_args(argv):
|
|
152
|
-
path_arg = None
|
|
153
|
-
target_path = None
|
|
154
|
-
use_stdin = False
|
|
155
|
-
fmt = 'json'
|
|
156
|
-
i = 0
|
|
157
|
-
while i < len(argv):
|
|
158
|
-
arg = argv[i]
|
|
159
|
-
if arg in ('-h', '--help'):
|
|
160
|
-
return 'help'
|
|
161
|
-
if arg == '--stdin':
|
|
162
|
-
use_stdin = True
|
|
163
|
-
elif arg in ('--path', '--target-path', '--format'):
|
|
164
|
-
if i + 1 >= len(argv) or not argv[i + 1]:
|
|
165
|
-
sys.stderr.write(f'error: {arg} requires a value\n')
|
|
166
|
-
return None
|
|
167
|
-
val = argv[i + 1]
|
|
168
|
-
if arg == '--path':
|
|
169
|
-
path_arg = val
|
|
170
|
-
elif arg == '--target-path':
|
|
171
|
-
target_path = val
|
|
172
|
-
else:
|
|
173
|
-
if val not in ('json', 'claude-hook', 'cursor-hook', 'codex-hook'):
|
|
174
|
-
sys.stderr.write(f'error: invalid --format: {val}\n')
|
|
175
|
-
return None
|
|
176
|
-
fmt = val
|
|
177
|
-
i += 1
|
|
178
|
-
else:
|
|
179
|
-
sys.stderr.write(f'error: unknown option: {arg}\n')
|
|
180
|
-
return None
|
|
181
|
-
i += 1
|
|
182
|
-
return path_arg, target_path, use_stdin, fmt
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
def main(argv):
|
|
186
|
-
parsed = parse_args(argv)
|
|
187
|
-
if parsed == 'help':
|
|
188
|
-
_write_out(HELP.rstrip('\n'))
|
|
189
|
-
return 0
|
|
190
|
-
if parsed is None:
|
|
191
|
-
return 1
|
|
192
|
-
path_arg, target_path, use_stdin, fmt = parsed
|
|
193
|
-
|
|
194
|
-
resolved_target = target_path or path_arg
|
|
195
|
-
if use_stdin:
|
|
196
|
-
raw_stdin = sys.stdin.read().strip()
|
|
197
|
-
if raw_stdin:
|
|
198
|
-
try:
|
|
199
|
-
payload = json.loads(raw_stdin)
|
|
200
|
-
except ValueError:
|
|
201
|
-
_write_out(json.dumps({'decision': 'unusable', 'reason': 'Invalid JSON on stdin.'}))
|
|
202
|
-
return 2
|
|
203
|
-
extracted = _extract_payload_path(payload)
|
|
204
|
-
if extracted and not target_path:
|
|
205
|
-
resolved_target = extracted
|
|
206
|
-
|
|
207
|
-
if not resolved_target:
|
|
208
|
-
resolved_target = '.'
|
|
209
|
-
|
|
210
|
-
report, status = evaluate_path(resolved_target)
|
|
211
|
-
if fmt == 'json':
|
|
212
|
-
_write_out(json.dumps(report, indent=2))
|
|
213
|
-
return status
|
|
214
|
-
|
|
215
|
-
_write_out(json.dumps(_format_hook(report, status, fmt)))
|
|
216
|
-
return 0
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if __name__ == '__main__':
|
|
220
|
-
sys.exit(main(sys.argv[1:]))
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""classify-change-lane.py: classify a diff or file list into trivial, standard, or high-risk.
|
|
3
|
-
|
|
4
|
-
Read-only: inspects git diff or explicit paths using Python 3.8+ standard library only.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import json
|
|
8
|
-
import os
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
import re
|
|
11
|
-
import subprocess
|
|
12
|
-
import sys
|
|
13
|
-
|
|
14
|
-
LARGE_LINES_THRESHOLD = 300
|
|
15
|
-
LARGE_FILES_THRESHOLD = 10
|
|
16
|
-
|
|
17
|
-
TRIVIAL_EXTS = {
|
|
18
|
-
'.md', '.mdx', '.txt', '.svg', '.excalidraw',
|
|
19
|
-
'.png', '.jpg', '.jpeg', '.webp', '.gif',
|
|
20
|
-
}
|
|
21
|
-
TRIVIAL_NAMES = {
|
|
22
|
-
'CHANGELOG.md', 'README.md', 'AGENTS.md', 'INSTALLATION.md',
|
|
23
|
-
'CONTRIBUTING.md', 'SUPPORT.md', 'SECURITY.md', 'LICENSE', 'NOTICE',
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
HIGH_RISK_PATTERNS = (
|
|
27
|
-
re.compile(r'(^|/)skills/watcher-observability/', re.I),
|
|
28
|
-
re.compile(r'(^|/)skills/tool-depot/', re.I),
|
|
29
|
-
re.compile(r'(^|/)skills/workflow-auditor/scripts/audit-ledger\.py$', re.I),
|
|
30
|
-
re.compile(r'(^|/)skills/question-gate/scripts/triage-question\.py$', re.I),
|
|
31
|
-
re.compile(r'(^|/)skills/delivery-coordinator/scripts/check-worktree-guard\.py$', re.I),
|
|
32
|
-
re.compile(r'(^|/)tools/export-public\.py$', re.I),
|
|
33
|
-
re.compile(r'(^|/)\.github/workflows/', re.I),
|
|
34
|
-
re.compile(
|
|
35
|
-
r'(^|/)(?:auth|oauth|jwt|session|token|crypto|secret|permission|rbac|'
|
|
36
|
-
r'security|migration|migrations|prisma|schema|deploy|infra)(?:/|[._-]|$)',
|
|
37
|
-
re.I,
|
|
38
|
-
),
|
|
39
|
-
re.compile(r'\.sql$', re.I),
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
LANE_PLANS = {
|
|
43
|
-
'trivial': {
|
|
44
|
-
'test_mode': 'proportional',
|
|
45
|
-
'required_stages': ['specify', 'implement', 'quality', 'docs', 'commit_pr', 'review'],
|
|
46
|
-
'skipped_stages': ['requirements-spec-full-prd', 'risk-scout', 'reproduce-runtime-red', 'verify-runtime-green'],
|
|
47
|
-
'extra_checks': ['documentation-steward', 'validate-skills.py'],
|
|
48
|
-
},
|
|
49
|
-
'standard': {
|
|
50
|
-
'test_mode': 'tdd',
|
|
51
|
-
'required_stages': ['specify', 'reproduce', 'implement', 'verify', 'quality', 'commit_pr', 'review'],
|
|
52
|
-
'skipped_stages': ['risk-scout'],
|
|
53
|
-
'extra_checks': ['code-quality-gate'],
|
|
54
|
-
},
|
|
55
|
-
'high-risk': {
|
|
56
|
-
'test_mode': 'tdd',
|
|
57
|
-
'required_stages': [
|
|
58
|
-
'specify', 'risk-scout', 'reproduce', 'implement',
|
|
59
|
-
'verify', 'quality', 'commit_pr', 'review', 'residual_risk',
|
|
60
|
-
],
|
|
61
|
-
'skipped_stages': [],
|
|
62
|
-
'extra_checks': ['risk-scout', 'code-quality-gate', 'human-security-review'],
|
|
63
|
-
},
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
HELP = (
|
|
67
|
-
'Usage: python3 -I -B scripts/classify-change-lane.py '
|
|
68
|
-
'[--working|--staged|--range A..B|--head N|--files <p1>...] [--format json|hud]\n'
|
|
69
|
-
'Classifies a change into trivial, standard, or high-risk.\n'
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def _write_out(text):
|
|
74
|
-
sys.stdout.buffer.write((text + '\n').encode('utf-8', 'surrogateescape'))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def _git(args):
|
|
78
|
-
try:
|
|
79
|
-
res = subprocess.run(
|
|
80
|
-
['git', *args],
|
|
81
|
-
stdout=subprocess.PIPE,
|
|
82
|
-
stderr=subprocess.PIPE,
|
|
83
|
-
timeout=10,
|
|
84
|
-
)
|
|
85
|
-
return res.stdout.decode('utf-8', 'surrogateescape'), res.returncode
|
|
86
|
-
except (OSError, subprocess.SubprocessError):
|
|
87
|
-
return '', 1
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def _is_high_risk_path(path):
|
|
91
|
-
norm = path.replace('\\', '/')
|
|
92
|
-
return any(pattern.search(norm) for pattern in HIGH_RISK_PATTERNS)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def _is_trivial_path(path):
|
|
96
|
-
norm = path.replace('\\', '/')
|
|
97
|
-
if _is_high_risk_path(norm):
|
|
98
|
-
return False
|
|
99
|
-
p = Path(norm)
|
|
100
|
-
return p.name in TRIVIAL_NAMES or p.suffix.lower() in TRIVIAL_EXTS
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def _collect_git_diff(mode, value):
|
|
104
|
-
has_head = _git(['rev-parse', '--verify', 'HEAD'])[1] == 0
|
|
105
|
-
if mode == 'working':
|
|
106
|
-
diff_args = ['HEAD'] if has_head else ['--staged']
|
|
107
|
-
elif mode == 'staged':
|
|
108
|
-
diff_args = ['--staged']
|
|
109
|
-
elif mode == 'range':
|
|
110
|
-
diff_args = [value]
|
|
111
|
-
else:
|
|
112
|
-
diff_args = [f'HEAD~{value}..HEAD']
|
|
113
|
-
|
|
114
|
-
names_raw, rc = _git(['-c', 'core.quotePath=false', 'diff', *diff_args, '--name-only', '-z'])
|
|
115
|
-
if rc != 0:
|
|
116
|
-
return None
|
|
117
|
-
files = [p for p in names_raw.split('\0') if p]
|
|
118
|
-
untracked = []
|
|
119
|
-
if mode == 'working':
|
|
120
|
-
others_raw, rc_other = _git(
|
|
121
|
-
['-c', 'core.quotePath=false', 'ls-files', '--others', '--exclude-standard', '-z']
|
|
122
|
-
)
|
|
123
|
-
if rc_other == 0:
|
|
124
|
-
untracked = [p for p in others_raw.split('\0') if p and os.path.isfile(p)]
|
|
125
|
-
|
|
126
|
-
all_files = sorted(set(files + untracked))
|
|
127
|
-
added = removed = 0
|
|
128
|
-
if files:
|
|
129
|
-
stat_raw, _ = _git(['-c', 'core.quotePath=false', 'diff', *diff_args, '--numstat', '--', *files])
|
|
130
|
-
for row in stat_raw.splitlines():
|
|
131
|
-
cols = row.split('\t')
|
|
132
|
-
if len(cols) >= 2:
|
|
133
|
-
if cols[0].isdigit():
|
|
134
|
-
added += int(cols[0])
|
|
135
|
-
if cols[1].isdigit():
|
|
136
|
-
removed += int(cols[1])
|
|
137
|
-
for path in untracked:
|
|
138
|
-
try:
|
|
139
|
-
with open(path, 'rb') as handle:
|
|
140
|
-
added += handle.read().count(b'\n')
|
|
141
|
-
except OSError:
|
|
142
|
-
pass
|
|
143
|
-
return all_files, added, removed
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def classify(files, lines_added=0, lines_removed=0):
|
|
147
|
-
lines_changed = lines_added + lines_removed
|
|
148
|
-
reasons = []
|
|
149
|
-
high_risk_hits = [f for f in files if _is_high_risk_path(f)]
|
|
150
|
-
|
|
151
|
-
if not files:
|
|
152
|
-
lane = 'trivial'
|
|
153
|
-
reasons.append('No changed files detected.')
|
|
154
|
-
elif high_risk_hits or lines_changed > LARGE_LINES_THRESHOLD or len(files) > LARGE_FILES_THRESHOLD:
|
|
155
|
-
lane = 'high-risk'
|
|
156
|
-
if high_risk_hits:
|
|
157
|
-
reasons.append('Touched high-risk path(s): ' + ', '.join(high_risk_hits[:5]))
|
|
158
|
-
if lines_changed > LARGE_LINES_THRESHOLD:
|
|
159
|
-
reasons.append(f'Large diff ({lines_changed} lines > {LARGE_LINES_THRESHOLD}).')
|
|
160
|
-
if len(files) > LARGE_FILES_THRESHOLD:
|
|
161
|
-
reasons.append(f'Broad change ({len(files)} files > {LARGE_FILES_THRESHOLD}).')
|
|
162
|
-
elif all(_is_trivial_path(f) for f in files):
|
|
163
|
-
lane = 'trivial'
|
|
164
|
-
reasons.append('Only documentation, markdown, or visual assets changed.')
|
|
165
|
-
else:
|
|
166
|
-
lane = 'standard'
|
|
167
|
-
reasons.append('Scoped code or skill change without high-risk paths or oversized diff.')
|
|
168
|
-
|
|
169
|
-
plan = LANE_PLANS[lane]
|
|
170
|
-
return {
|
|
171
|
-
'lane': lane,
|
|
172
|
-
'reasons': reasons,
|
|
173
|
-
'files_changed': len(files),
|
|
174
|
-
'lines_added': lines_added,
|
|
175
|
-
'lines_removed': lines_removed,
|
|
176
|
-
'lines_changed': lines_changed,
|
|
177
|
-
'files': files,
|
|
178
|
-
'test_mode': plan['test_mode'],
|
|
179
|
-
'required_stages': plan['required_stages'],
|
|
180
|
-
'skipped_stages': plan['skipped_stages'],
|
|
181
|
-
'extra_checks': plan['extra_checks'],
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
def parse_args(argv):
|
|
186
|
-
mode, value, fmt, files = 'working', '', 'json', None
|
|
187
|
-
i = 0
|
|
188
|
-
while i < len(argv):
|
|
189
|
-
arg = argv[i]
|
|
190
|
-
if arg in ('-h', '--help'):
|
|
191
|
-
return 'help'
|
|
192
|
-
if arg in ('--working', '--staged'):
|
|
193
|
-
mode = arg[2:]
|
|
194
|
-
elif arg in ('--range', '--head'):
|
|
195
|
-
if i + 1 >= len(argv) or not argv[i + 1]:
|
|
196
|
-
sys.stderr.write(f'error: {arg} requires an argument\n')
|
|
197
|
-
return None
|
|
198
|
-
mode, value = arg[2:], argv[i + 1]
|
|
199
|
-
i += 1
|
|
200
|
-
elif arg == '--files':
|
|
201
|
-
mode, files = 'files', []
|
|
202
|
-
i += 1
|
|
203
|
-
while i < len(argv) and not argv[i].startswith('--'):
|
|
204
|
-
files.append(argv[i])
|
|
205
|
-
i += 1
|
|
206
|
-
continue
|
|
207
|
-
elif arg == '--format':
|
|
208
|
-
if i + 1 >= len(argv) or argv[i + 1] not in ('json', 'hud'):
|
|
209
|
-
sys.stderr.write('error: --format must be json or hud\n')
|
|
210
|
-
return None
|
|
211
|
-
fmt = argv[i + 1]
|
|
212
|
-
i += 1
|
|
213
|
-
else:
|
|
214
|
-
sys.stderr.write(f'error: unknown option: {arg}\n')
|
|
215
|
-
return None
|
|
216
|
-
i += 1
|
|
217
|
-
|
|
218
|
-
if mode == 'head' and not re.fullmatch(r'[1-9][0-9]*', value):
|
|
219
|
-
sys.stderr.write(f'error: --head requires a positive integer: {value}\n')
|
|
220
|
-
return None
|
|
221
|
-
if mode == 'files' and not files:
|
|
222
|
-
sys.stderr.write('error: --files requires at least one path\n')
|
|
223
|
-
return None
|
|
224
|
-
return mode, value, fmt, files
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
def format_hud(report):
|
|
228
|
-
badge = {'trivial': '🟢', 'standard': '🟡', 'high-risk': '🔴'}[report['lane']]
|
|
229
|
-
reason = report['reasons'][0] if report['reasons'] else ''
|
|
230
|
-
return (
|
|
231
|
-
f"🛣️ Lane: {badge} {report['lane']} "
|
|
232
|
-
f"({report['files_changed']} files, {report['lines_changed']} lines) — {reason}"
|
|
233
|
-
)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
def main(argv):
|
|
237
|
-
parsed = parse_args(argv)
|
|
238
|
-
if parsed == 'help':
|
|
239
|
-
_write_out(HELP.rstrip('\n'))
|
|
240
|
-
return 0
|
|
241
|
-
if parsed is None:
|
|
242
|
-
return 1
|
|
243
|
-
mode, value, fmt, explicit_files = parsed
|
|
244
|
-
|
|
245
|
-
if mode == 'files':
|
|
246
|
-
report = classify(explicit_files)
|
|
247
|
-
else:
|
|
248
|
-
collected = _collect_git_diff(mode, value)
|
|
249
|
-
if collected is None:
|
|
250
|
-
sys.stderr.write('error: failed to inspect git diff\n')
|
|
251
|
-
return 2
|
|
252
|
-
files, added, removed = collected
|
|
253
|
-
report = classify(files, added, removed)
|
|
254
|
-
|
|
255
|
-
if fmt == 'hud':
|
|
256
|
-
_write_out(format_hud(report))
|
|
257
|
-
else:
|
|
258
|
-
_write_out(json.dumps(report, indent=2))
|
|
259
|
-
return 0
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if __name__ == '__main__':
|
|
263
|
-
sys.exit(main(sys.argv[1:]))
|