@kinti/a11y-toolkit 5.22.3 → 5.23.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.
- package/a11y_toolkit/a11y.py +2 -0
- package/a11y_toolkit/a11yplan.py +214 -0
- package/a11y_toolkit/server.py +1 -1
- package/package.json +1 -1
package/a11y_toolkit/a11y.py
CHANGED
|
@@ -47,6 +47,7 @@ from . import a11ycrit
|
|
|
47
47
|
from . import a11ydiff
|
|
48
48
|
from . import a11ysarif
|
|
49
49
|
from . import a11ywcagem
|
|
50
|
+
from . import a11yplan
|
|
50
51
|
from . import contrast
|
|
51
52
|
from . import a11ystatement
|
|
52
53
|
from . import a11yjourney
|
|
@@ -70,6 +71,7 @@ SUBCOMMANDS = {
|
|
|
70
71
|
'criterion': (a11ycrit, None),
|
|
71
72
|
'sarif': (a11ysarif, None),
|
|
72
73
|
'wcagem': (a11ywcagem, None),
|
|
74
|
+
'plan': (a11yplan, None),
|
|
73
75
|
'fix': (a11yfix, None),
|
|
74
76
|
'kbd': (a11ydom, 'kbd_main'),
|
|
75
77
|
'scroll': (a11yscroll, None),
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Remediation plan — turn a findings list into an ordered ROUTE.
|
|
3
|
+
|
|
4
|
+
An inventory of 40 findings overwhelms; nobody answers "in what order?".
|
|
5
|
+
Planning matters because fixes change the cost of other fixes: semantic
|
|
6
|
+
infrastructure (headings, landmarks, labels) makes later work cheaper, one
|
|
7
|
+
design-token decision kills many contrast findings at once, and instances
|
|
8
|
+
on a page headed for redesign are wasted minutes. Cross-industry origin:
|
|
9
|
+
planning over evolving state (candidate-generation MDPs, arXiv 2607.02115)
|
|
10
|
+
— translated here into a deterministic, auditable heuristic. No ML, no
|
|
11
|
+
network: batches, declared phases, declared minute assumptions, a root
|
|
12
|
+
seal. The human reorders; the plan is evidence, not an oracle.
|
|
13
|
+
|
|
14
|
+
Phases (in order):
|
|
15
|
+
infrastructure — structural semantics first (they reprice everything else)
|
|
16
|
+
design-system — shared-cause decisions (contrast as a system fix)
|
|
17
|
+
instances — per-instance work, severity high → medium → low
|
|
18
|
+
redesign-zone — one page accumulating many distinct signals: flagged,
|
|
19
|
+
moved last, with an explicit note
|
|
20
|
+
|
|
21
|
+
CLI:
|
|
22
|
+
a11ytoolkit plan --report audit.json [-o plan.json]
|
|
23
|
+
a11ytoolkit plan --report audit.json --from-pack pack.json # pack effort
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
import argparse
|
|
27
|
+
import hashlib
|
|
28
|
+
import json
|
|
29
|
+
import sys
|
|
30
|
+
|
|
31
|
+
# Phase assignment by signal class (declared, not learned).
|
|
32
|
+
INFRA_SIGNALS = {'no_h1', 'heading_order', 'landmark', 'bypass_missing',
|
|
33
|
+
'region_missing', 'field_label', 'button_name', 'link_name',
|
|
34
|
+
'img_no_alt', 'iframe_title', 'html_lang_missing',
|
|
35
|
+
'title_missing', 'viewport_zoom_blocked'}
|
|
36
|
+
DESIGN_SIGNALS = {'contrast_low', 'contrast_image_fail', 'color_alone',
|
|
37
|
+
'focus_visibility', 'text_spacing'}
|
|
38
|
+
MINUTES_BY_SEVERITY = {'high': [12, 20], 'medium': [5, 10], 'low': [2, 4]}
|
|
39
|
+
REDESIGN_SIGNAL_THRESHOLD = 4 # distinct signals on one URL → zone flag
|
|
40
|
+
|
|
41
|
+
# What each assumption means, printed with the plan (honesty by default).
|
|
42
|
+
ASSUMPTIONS_HEURISTIC = {
|
|
43
|
+
'source': 'severity heuristic',
|
|
44
|
+
'minutes': MINUTES_BY_SEVERITY,
|
|
45
|
+
'note': ('per-finding heuristic ranges, NOT measured effort; the pack '
|
|
46
|
+
'effort pricing (a11y_evidence) is the better source when '
|
|
47
|
+
'available'),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _canon(obj):
|
|
52
|
+
return json.dumps(obj, ensure_ascii=False, sort_keys=True,
|
|
53
|
+
separators=(',', ':'))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _minutes_for(findings, effort_by_criterion=None):
|
|
57
|
+
"""Sum of per-finding minute ranges. With pack effort pricing, the
|
|
58
|
+
criterion's MIN/MED/MAX range replaces the severity heuristic."""
|
|
59
|
+
lo = hi = 0
|
|
60
|
+
for f in findings:
|
|
61
|
+
eff = effort_by_criterion.get((f.get('criterion') or '').split(' ')[0])
|
|
62
|
+
if eff and eff.get('minutes'):
|
|
63
|
+
lo += eff['minutes'][0]
|
|
64
|
+
hi += eff['minutes'][1]
|
|
65
|
+
else:
|
|
66
|
+
r = MINUTES_BY_SEVERITY.get(f.get('severity', 'low'), MINUTES_BY_SEVERITY['low'])
|
|
67
|
+
lo += r[0]
|
|
68
|
+
hi += r[1]
|
|
69
|
+
return [lo, hi]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def build_plan(report, pack=None):
|
|
73
|
+
"""Report (dict with findings[]) → sealed fix-plan dict. Deterministic:
|
|
74
|
+
same report, same plan. Malformed findings are skipped, never fatal."""
|
|
75
|
+
findings = [f for f in (report.get('findings') or []) if isinstance(f, dict)
|
|
76
|
+
and f.get('signal')]
|
|
77
|
+
effort_by_criterion = {}
|
|
78
|
+
if pack:
|
|
79
|
+
for c in pack.get('criteria', []):
|
|
80
|
+
if c.get('effort', {}).get('minutes'):
|
|
81
|
+
effort_by_criterion[c['criterion'].split(' ')[0]] = c['effort']
|
|
82
|
+
assumptions = dict(ASSUMPTIONS_HEURISTIC)
|
|
83
|
+
if pack:
|
|
84
|
+
assumptions = {'source': 'pack effort',
|
|
85
|
+
'note': 'minutes from the evidence pack effort pricing'}
|
|
86
|
+
|
|
87
|
+
# redesign zones: one URL accumulating many distinct signals
|
|
88
|
+
by_url = {}
|
|
89
|
+
for f in findings:
|
|
90
|
+
u = f.get('url') or report.get('url') or ''
|
|
91
|
+
by_url.setdefault(u, set()).add(f['signal'])
|
|
92
|
+
zones = {u for u, sigs in by_url.items() if len(sigs) >= REDESIGN_SIGNAL_THRESHOLD}
|
|
93
|
+
|
|
94
|
+
# batch by signal inside each phase (one signal = one kind of fix)
|
|
95
|
+
by_signal = {}
|
|
96
|
+
for f in findings:
|
|
97
|
+
by_signal.setdefault(f['signal'], []).append(f)
|
|
98
|
+
|
|
99
|
+
def phase_of(signal):
|
|
100
|
+
if signal in INFRA_SIGNALS:
|
|
101
|
+
return 'infrastructure'
|
|
102
|
+
if signal in DESIGN_SIGNALS:
|
|
103
|
+
return 'design-system'
|
|
104
|
+
return 'instances'
|
|
105
|
+
|
|
106
|
+
sev_rank = {'high': 0, 'medium': 1, 'low': 2}
|
|
107
|
+
batches = []
|
|
108
|
+
infra_signals = sorted(s for s in by_signal if phase_of(s) == 'infrastructure')
|
|
109
|
+
for signal in sorted(by_signal):
|
|
110
|
+
if signal in infra_signals and signal != (infra_signals or [signal])[0]:
|
|
111
|
+
continue # infrastructure is ONE combined batch (one work session)
|
|
112
|
+
fs = by_signal[signal]
|
|
113
|
+
if signal == (infra_signals or [None])[0] and infra_signals:
|
|
114
|
+
fs = [f for sg in infra_signals for f in by_signal[sg]]
|
|
115
|
+
signal = 'document_structure'
|
|
116
|
+
phase = 'infrastructure' if signal == 'document_structure' else phase_of(signal)
|
|
117
|
+
zone = bool(zones & {f.get('url') or '' for f in fs})
|
|
118
|
+
if phase == 'instances' and zone and len({f.get('url') for f in fs}) == 1 \
|
|
119
|
+
and len(by_url[list(zones & {f.get('url') for f in fs})[0]]) >= REDESIGN_SIGNAL_THRESHOLD:
|
|
120
|
+
phase = 'redesign-zone'
|
|
121
|
+
sev = min((sev_rank.get(f.get('severity', 'low'), 2) for f in fs))
|
|
122
|
+
batch = {
|
|
123
|
+
'title': (f"Fix document structure semantics ({len(fs)} findings)"
|
|
124
|
+
if signal == 'document_structure' else
|
|
125
|
+
f"Fix {signal.replace('_', ' ')} ({len(fs)} finding"
|
|
126
|
+
f"{'s' if len(fs) != 1 else ''})"),
|
|
127
|
+
'phase': phase, 'signal': signal,
|
|
128
|
+
'finding_count': len(fs), 'severity': ('high', 'medium', 'low')[sev],
|
|
129
|
+
'signals': infra_signals if signal == 'document_structure' else [signal],
|
|
130
|
+
'urls': sorted({f.get('url') or '' for f in fs})[:8],
|
|
131
|
+
'criteria': sorted({(f.get('criterion') or '').split(' ')[0] for f in fs}),
|
|
132
|
+
'minutes': _minutes_for(fs, effort_by_criterion),
|
|
133
|
+
'note': ('same kind of fix repeated — fix the pattern once and '
|
|
134
|
+
're-apply; itemized minutes are the upper bound'
|
|
135
|
+
if len(fs) > 1 else ''),
|
|
136
|
+
}
|
|
137
|
+
if phase == 'redesign-zone':
|
|
138
|
+
batch['note'] = ('this URL accumulates %d distinct signals — '
|
|
139
|
+
'consider fixing it in a redesign pass, not '
|
|
140
|
+
'piecemeal' % len(by_url[list(zones & {f.get('url') for f in fs})[0]]))
|
|
141
|
+
batches.append(batch)
|
|
142
|
+
|
|
143
|
+
order = {'infrastructure': 0, 'design-system': 1, 'instances': 2, 'redesign-zone': 3}
|
|
144
|
+
batches.sort(key=lambda b: (order[b['phase']], sev_rank[b['severity']],
|
|
145
|
+
b['signal']))
|
|
146
|
+
|
|
147
|
+
# design-system note when contrast concentrates: one decision, many fixes
|
|
148
|
+
design = [b for b in batches if b['phase'] == 'design-system']
|
|
149
|
+
if design and sum(b['finding_count'] for b in design) >= 3:
|
|
150
|
+
design[0]['note'] = (design[0]['note'] or '') + (
|
|
151
|
+
' — consider a design-token/theme decision: one change here '
|
|
152
|
+
'typically resolves every finding in this batch').strip(' —')
|
|
153
|
+
|
|
154
|
+
cumulative = [0, 0]
|
|
155
|
+
for b in batches:
|
|
156
|
+
cumulative[0] += b['minutes'][0]
|
|
157
|
+
cumulative[1] += b['minutes'][1]
|
|
158
|
+
b['cumulative_minutes'] = list(cumulative)
|
|
159
|
+
|
|
160
|
+
itemized = [cumulative[0], cumulative[1]]
|
|
161
|
+
savings = [max(0, itemized[0] // 6), max(0, itemized[1] // 5)] # declared: 15-20% pattern reuse
|
|
162
|
+
|
|
163
|
+
plan = {
|
|
164
|
+
'format': 'a11y-fix-plan/1',
|
|
165
|
+
'source_report': {'url': report.get('url'), 'score': report.get('score'),
|
|
166
|
+
'mode': report.get('mode'),
|
|
167
|
+
'findings_total': len(findings)},
|
|
168
|
+
'assumptions': assumptions,
|
|
169
|
+
'batches': batches,
|
|
170
|
+
'total_minutes': list(cumulative),
|
|
171
|
+
'grouping_savings_minutes': savings,
|
|
172
|
+
'grouping_note': ('declared estimate of pattern-reuse savings from '
|
|
173
|
+
'fixing by batch instead of item by item — an '
|
|
174
|
+
'optimistic bound, not a promise'),
|
|
175
|
+
'redesign_zones': sorted(zones),
|
|
176
|
+
'note': ('the order is a declared heuristic: infrastructure first '
|
|
177
|
+
'(it reprices everything else), then design decisions, '
|
|
178
|
+
'then instances; the human reorders — re-run the seal '
|
|
179
|
+
'after reordering')
|
|
180
|
+
+ ('' if findings else ' NO FINDINGS in the source report '
|
|
181
|
+
'— nothing to plan (run the audit first).'),
|
|
182
|
+
}
|
|
183
|
+
plan['sha256'] = hashlib.sha256(
|
|
184
|
+
_canon({k: v for k, v in plan.items() if k != 'sha256'}).encode('utf-8')
|
|
185
|
+
).hexdigest()
|
|
186
|
+
return plan
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def verify_plan(plan):
|
|
190
|
+
expected = hashlib.sha256(
|
|
191
|
+
_canon({k: v for k, v in plan.items() if k != 'sha256'}).encode('utf-8')
|
|
192
|
+
).hexdigest()
|
|
193
|
+
return expected == plan.get('sha256'), 'root sha256'
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def main(argv):
|
|
197
|
+
ap = argparse.ArgumentParser(description='Remediation plan: findings → ordered fix route')
|
|
198
|
+
ap.add_argument('--report', required=True, help='audit report JSON (findings[])')
|
|
199
|
+
ap.add_argument('--from-pack', help='evidence pack JSON: use its effort pricing for minutes')
|
|
200
|
+
ap.add_argument('-o', '--out', default='fix-plan.json')
|
|
201
|
+
a = ap.parse_args(argv)
|
|
202
|
+
report = json.load(open(a.report, encoding='utf-8'))
|
|
203
|
+
pack = json.load(open(a.from_pack, encoding='utf-8')) if a.from_pack else None
|
|
204
|
+
plan = build_plan(report, pack=pack)
|
|
205
|
+
with open(a.out, 'w', encoding='utf-8') as f:
|
|
206
|
+
json.dump(plan, f, ensure_ascii=False, indent=1)
|
|
207
|
+
print(json.dumps({'plan': a.out, 'sha256': plan['sha256'],
|
|
208
|
+
'batches': len(plan['batches']),
|
|
209
|
+
'total_minutes': plan['total_minutes']}, ensure_ascii=False))
|
|
210
|
+
return 0
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
if __name__ == '__main__':
|
|
214
|
+
sys.exit(main(sys.argv[1:]))
|
package/a11y_toolkit/server.py
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinti/a11y-toolkit",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.23.0",
|
|
4
4
|
"description": "Zero-dependency WCAG 2.2 accessibility engine (34 MCP tools + CLI): audits, contrast fixing, SHA-256-sealed evidence packs, SARIF, EARL/ACT, CI ratchet. Self-contained: the pure-stdlib Python engine ships inside and runs via python3 \u2014 no downloads, no installs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|