rtl-analyzer 0.2.0 → 0.4.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/README.md +90 -56
- package/dist/cli.js +18 -1
- package/dist/codemod.js +50 -12
- package/dist/companion-security.js +2 -0
- package/dist/contextual-preview-bridge.js +118 -0
- package/dist/contextual-preview.js +74 -0
- package/dist/controlled-apply.js +222 -0
- package/dist/css-configured-proposal.js +98 -0
- package/dist/css-directional.js +60 -0
- package/dist/css-icons.js +51 -0
- package/dist/css-spacing.js +65 -0
- package/dist/dashboard-batch-review.js +37 -0
- package/dist/dashboard-client.js +73 -50
- package/dist/dashboard-contextual-preview.js +127 -0
- package/dist/dashboard-data.js +4 -4
- package/dist/dashboard-embedded-preview.js +202 -0
- package/dist/dashboard-html.js +13 -10
- package/dist/dashboard-operation-flow.js +47 -0
- package/dist/dashboard-review-details.js +175 -0
- package/dist/dashboard-review-navigation.js +19 -0
- package/dist/dashboard-review-workflow.js +219 -0
- package/dist/dashboard-themes.js +34 -0
- package/dist/directional-properties.js +53 -0
- package/dist/discovery.js +1 -2
- package/dist/eligibility.js +8 -8
- package/dist/evidence-store.js +110 -0
- package/dist/example-preview-mappings.js +98 -0
- package/dist/manual-change-store.js +27 -0
- package/dist/migration-lifecycle.js +19 -0
- package/dist/original-preview-runtime.js +78 -0
- package/dist/output-path.js +65 -0
- package/dist/page-navigation.js +17 -0
- package/dist/policy-validation.js +7 -4
- package/dist/preview-cli.js +22 -0
- package/dist/preview-companion.js +649 -0
- package/dist/preview-configuration.js +171 -0
- package/dist/preview-runtime.js +102 -0
- package/dist/project-configuration.js +48 -0
- package/dist/project-root.js +12 -0
- package/dist/react-inline.js +65 -0
- package/dist/report-publisher.js +4 -7
- package/dist/review-approval.js +9 -0
- package/dist/review-session.js +211 -56
- package/dist/review-store.js +175 -0
- package/dist/review-workflow.js +820 -0
- package/dist/rules.js +27 -17
- package/dist/runtime-process.js +35 -0
- package/dist/scan-history.js +35 -0
- package/dist/scan-manifest-store.js +26 -0
- package/dist/scan.js +55 -4
- package/dist/scoped-direction-evidence.js +117 -0
- package/dist/serialization.js +1 -0
- package/dist/source-context.js +93 -0
- package/dist/source-snippets.js +3 -3
- package/dist/standalone-cli.js +14 -1
- package/dist/tailwind.js +3 -1
- package/dist/transformations.js +34 -0
- package/dist/validation.js +75 -0
- package/dist/workflow-validation.js +46 -0
- package/package.json +17 -8
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { access, lstat, mkdir, open, readFile, rename, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { join, dirname } from 'node:path';
|
|
5
|
+
import { homedir, tmpdir } from 'node:os';
|
|
6
|
+
import { validateEvidenceSnapshot } from './evidence-store.js';
|
|
7
|
+
import { validateReviewIdentity, validateReviewPath, validatePatch, validateProjectSourcePath, REVIEW_SOURCE } from './review-session.js';
|
|
8
|
+
export const APPLY_CONFIRMATION = 'APPLY_CONFIRMED';
|
|
9
|
+
const active = new Set();
|
|
10
|
+
const sha = (text) => createHash('sha256').update(text).digest('hex');
|
|
11
|
+
const readNoFollow = async (path) => { const handle = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0)); try {
|
|
12
|
+
return await handle.readFile('utf8');
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
await handle.close();
|
|
16
|
+
} };
|
|
17
|
+
const atomicWrite = async (path, content) => { const temporary = `${path}.rtl-apply.${process.pid}.${randomUUID()}.tmp`; try {
|
|
18
|
+
await writeFile(temporary, content, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
|
|
19
|
+
await rename(temporary, path);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
try {
|
|
23
|
+
await access(temporary, constants.F_OK);
|
|
24
|
+
await rename(temporary, `${temporary}.failed`);
|
|
25
|
+
}
|
|
26
|
+
catch { /* preserve original error */ }
|
|
27
|
+
throw error;
|
|
28
|
+
} };
|
|
29
|
+
export class ApplyAuditStore {
|
|
30
|
+
path;
|
|
31
|
+
constructor(path) {
|
|
32
|
+
this.path = path;
|
|
33
|
+
}
|
|
34
|
+
async list() { try {
|
|
35
|
+
return JSON.parse(await readFile(this.path, 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error.code === 'ENOENT')
|
|
39
|
+
return [];
|
|
40
|
+
throw new Error('APPLY_AUDIT_UNREADABLE');
|
|
41
|
+
} }
|
|
42
|
+
async append(event) { const parent = dirname(this.path); await mkdir(parent, { recursive: true, mode: 0o700 }); const events = await this.list(); events.push(event); await atomicWrite(this.path, `${JSON.stringify(events, null, 2)}\n`); }
|
|
43
|
+
}
|
|
44
|
+
export class ControlledApplyService {
|
|
45
|
+
repositoryRoot;
|
|
46
|
+
audit;
|
|
47
|
+
backupRoot;
|
|
48
|
+
constructor(repositoryRoot, audit = new ApplyAuditStore(process.env.RTL_AUDIT_STORE_PATH || join(homedir(), '.rtl-migration-analyzer', 'apply-audit-v1.json')), backupRoot = process.env.RTL_APPLY_BACKUP_ROOT || join(tmpdir(), 'rtl-migration-analyzer-apply-backups')) {
|
|
49
|
+
this.repositoryRoot = repositoryRoot;
|
|
50
|
+
this.audit = audit;
|
|
51
|
+
this.backupRoot = backupRoot;
|
|
52
|
+
}
|
|
53
|
+
async recoverAcceptedFileReceipts(operationId) {
|
|
54
|
+
const events = await this.audit.list();
|
|
55
|
+
const receipts = [];
|
|
56
|
+
for (const e of events.filter(e => e.type === 'APPLY_PREPARED' && e.auditId === `${operationId}:${e.path}`)) {
|
|
57
|
+
if (!e.backupPath || !e.resultingSha256 || sha(await readFile(e.backupPath, 'utf8')) !== e.sourceSha256)
|
|
58
|
+
throw new Error('APPLY_BACKUP_MISMATCH');
|
|
59
|
+
const current = sha(await readNoFollow(await validateProjectSourcePath(this.repositoryRoot, e.path)));
|
|
60
|
+
// Prepared but unwritten files are not tool-owned rollback changes.
|
|
61
|
+
if (current === e.resultingSha256 || events.some(done => done.auditId === e.auditId && done.type === 'APPLIED'))
|
|
62
|
+
receipts.push({ auditId: e.auditId, path: e.path, originalSha256: e.sourceSha256, appliedSha256: e.resultingSha256, backupPath: e.backupPath, appliedAt: e.timestamp });
|
|
63
|
+
}
|
|
64
|
+
return receipts;
|
|
65
|
+
}
|
|
66
|
+
/** Internal workflow boundary: callers must supply the accepted, validated file set. Journal precedes writes. */
|
|
67
|
+
async applyAcceptedFiles(operationId, files, confirmation) {
|
|
68
|
+
if (confirmation !== APPLY_CONFIRMATION)
|
|
69
|
+
throw new Error('APPLY_CONFIRMATION_REQUIRED');
|
|
70
|
+
const events = await this.audit.list();
|
|
71
|
+
const prepared = [];
|
|
72
|
+
for (const file of files) {
|
|
73
|
+
const path = await validateProjectSourcePath(this.repositoryRoot, file.path);
|
|
74
|
+
if (!(await lstat(path)).isFile())
|
|
75
|
+
throw new Error('APPLY_SOURCE_NOT_REGULAR_FILE');
|
|
76
|
+
const auditId = `${operationId}:${file.path}`;
|
|
77
|
+
const old = events.find(e => e.auditId === auditId && e.type === 'APPLY_PREPARED');
|
|
78
|
+
const current = sha(await readNoFollow(path));
|
|
79
|
+
if (current !== sha(file.before) && !(old && current === sha(file.after)))
|
|
80
|
+
throw new Error('STALE_APPLY_SOURCE');
|
|
81
|
+
if (old && (old.sourceSha256 !== sha(file.before) || old.resultingSha256 !== sha(file.after)))
|
|
82
|
+
throw new Error('APPLY_OPERATION_MISMATCH');
|
|
83
|
+
if (!old) {
|
|
84
|
+
await mkdir(this.backupRoot, { recursive: true, mode: 0o700 });
|
|
85
|
+
const backupPath = join(this.backupRoot, `${randomUUID()}.bak`);
|
|
86
|
+
await writeFile(backupPath, file.before, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
|
|
87
|
+
const timestamp = new Date().toISOString();
|
|
88
|
+
await this.audit.append({ auditId, type: 'APPLY_PREPARED', path: file.path, sourceSha256: sha(file.before), resultingSha256: sha(file.after), backupPath, timestamp });
|
|
89
|
+
prepared.push({ auditId, path: file.path, originalSha256: sha(file.before), appliedSha256: sha(file.after), backupPath, appliedAt: timestamp });
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
prepared.push({ auditId, path: file.path, originalSha256: old.sourceSha256, appliedSha256: old.resultingSha256, backupPath: old.backupPath, appliedAt: old.timestamp });
|
|
93
|
+
}
|
|
94
|
+
for (const [index, receipt] of prepared.entries()) {
|
|
95
|
+
const path = await validateProjectSourcePath(this.repositoryRoot, receipt.path);
|
|
96
|
+
const current = sha(await readNoFollow(path));
|
|
97
|
+
if (sha(await readFile(receipt.backupPath, 'utf8')) !== receipt.originalSha256)
|
|
98
|
+
throw new Error('APPLY_BACKUP_MISMATCH');
|
|
99
|
+
if (current === receipt.appliedSha256)
|
|
100
|
+
continue;
|
|
101
|
+
if (current !== receipt.originalSha256)
|
|
102
|
+
throw new Error('STALE_APPLY_SOURCE');
|
|
103
|
+
await atomicWrite(path, files[index].after);
|
|
104
|
+
await this.audit.append({ auditId: receipt.auditId, type: 'APPLIED', path: receipt.path, sourceSha256: receipt.originalSha256, resultingSha256: receipt.appliedSha256, backupPath: receipt.backupPath, timestamp: new Date().toISOString() });
|
|
105
|
+
}
|
|
106
|
+
return prepared;
|
|
107
|
+
}
|
|
108
|
+
async rollbackAcceptedFiles(receipts) {
|
|
109
|
+
const events = await this.audit.list();
|
|
110
|
+
// Preflight the entire scope: a later user edit blocks every write in this rollback.
|
|
111
|
+
for (const r of receipts) {
|
|
112
|
+
const event = events.find(e => e.auditId === r.auditId && e.type === 'APPLY_PREPARED' && e.path === r.path && e.backupPath === r.backupPath && e.sourceSha256 === r.originalSha256 && e.resultingSha256 === r.appliedSha256);
|
|
113
|
+
if (!event)
|
|
114
|
+
throw new Error('ROLLBACK_RECEIPT_UNTRUSTED');
|
|
115
|
+
const current = sha(await readNoFollow(await validateProjectSourcePath(this.repositoryRoot, r.path)));
|
|
116
|
+
if (current !== r.appliedSha256 && current !== r.originalSha256)
|
|
117
|
+
throw new Error('ROLLBACK_CONFLICT');
|
|
118
|
+
if (sha(await readFile(r.backupPath, 'utf8')) !== r.originalSha256)
|
|
119
|
+
throw new Error('ROLLBACK_BACKUP_MISMATCH');
|
|
120
|
+
}
|
|
121
|
+
for (const r of receipts) {
|
|
122
|
+
const path = await validateProjectSourcePath(this.repositoryRoot, r.path);
|
|
123
|
+
const current = sha(await readNoFollow(path));
|
|
124
|
+
if (current === r.originalSha256)
|
|
125
|
+
continue;
|
|
126
|
+
if (current !== r.appliedSha256)
|
|
127
|
+
throw new Error('ROLLBACK_CONFLICT');
|
|
128
|
+
await atomicWrite(path, await readFile(r.backupPath, 'utf8'));
|
|
129
|
+
await this.audit.append({ auditId: r.auditId, type: 'ROLLED_BACK', path: r.path, sourceSha256: r.appliedSha256, resultingSha256: r.originalSha256, backupPath: r.backupPath, timestamp: new Date().toISOString() });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async recoverRollbackReceipt(pathValue, originalSha256, appliedSha256) {
|
|
133
|
+
const path = validateReviewPath(this.repositoryRoot, pathValue);
|
|
134
|
+
const events = await this.audit.list();
|
|
135
|
+
const applied = [...events].reverse().find(event => event.type === 'APPLIED' && event.path === pathValue && event.sourceSha256 === originalSha256 && event.resultingSha256 === appliedSha256 && event.backupPath);
|
|
136
|
+
if (!applied?.backupPath || events.some(event => event.auditId === applied.auditId && event.type === 'ROLLED_BACK'))
|
|
137
|
+
return null;
|
|
138
|
+
const current = await readNoFollow(path);
|
|
139
|
+
if (sha(current) !== appliedSha256)
|
|
140
|
+
return null;
|
|
141
|
+
const backup = await readFile(applied.backupPath, 'utf8');
|
|
142
|
+
if (sha(backup) !== originalSha256)
|
|
143
|
+
return null;
|
|
144
|
+
return { auditId: applied.auditId, path: pathValue, originalSha256, appliedSha256, backupPath: applied.backupPath, appliedAt: applied.timestamp };
|
|
145
|
+
}
|
|
146
|
+
async apply(auth) {
|
|
147
|
+
validateReviewIdentity(auth.identity);
|
|
148
|
+
if (auth.confirmation !== APPLY_CONFIRMATION)
|
|
149
|
+
throw new Error('APPLY_CONFIRMATION_REQUIRED');
|
|
150
|
+
if (auth.reviewRecord.status !== 'Approved' || auth.reviewRecord.findingId !== auth.identity.findingId || auth.reviewRecord.inputDigest !== auth.identity.inputDigest || auth.reviewRecord.policyDigest !== auth.identity.policyDigest)
|
|
151
|
+
throw new Error('APPROVED_REVIEW_REQUIRED');
|
|
152
|
+
if (auth.patch.path !== REVIEW_SOURCE || auth.patch.findingId !== auth.identity.findingId)
|
|
153
|
+
throw new Error('APPLY_PATCH_IDENTITY_MISMATCH');
|
|
154
|
+
const evidence = auth.evidence.find(x => { try {
|
|
155
|
+
validateEvidenceSnapshot(x);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return false;
|
|
159
|
+
} return x.findingId === auth.identity.findingId && x.sourcePath === auth.identity.sourcePath && x.inputDigest === auth.identity.inputDigest && x.policyDigest === auth.identity.policyDigest && (x.decision === 'Approved' || x.decision === 'Ready for Review') && x.candidatePatchIdentity.expectedSha256 === auth.patch.expectedSha256 && x.candidatePatchIdentity.replacementSha256 === sha(auth.patch.replacement) && !x.scannerAfter.findingPresent && x.browserDomValidation.length > 0; });
|
|
160
|
+
if (!evidence)
|
|
161
|
+
throw new Error('VALIDATION_EVIDENCE_REQUIRED');
|
|
162
|
+
const path = validateReviewPath(this.repositoryRoot, auth.patch.path);
|
|
163
|
+
const key = path;
|
|
164
|
+
if (active.has(key))
|
|
165
|
+
throw new Error('APPLY_IN_PROGRESS');
|
|
166
|
+
active.add(key);
|
|
167
|
+
try {
|
|
168
|
+
const stat = await lstat(path);
|
|
169
|
+
if (!stat.isFile())
|
|
170
|
+
throw new Error('APPLY_SOURCE_NOT_REGULAR_FILE');
|
|
171
|
+
const original = await readNoFollow(path);
|
|
172
|
+
const originalSha256 = sha(original);
|
|
173
|
+
if (originalSha256 !== evidence.originalSourceSha256)
|
|
174
|
+
throw new Error('STALE_APPLY_SOURCE');
|
|
175
|
+
validatePatch(original, auth.patch);
|
|
176
|
+
const next = original.slice(0, auth.patch.startOffset) + auth.patch.replacement + original.slice(auth.patch.endOffset);
|
|
177
|
+
const appliedSha256 = sha(next);
|
|
178
|
+
if (appliedSha256 !== evidence.candidateSourceSha256)
|
|
179
|
+
throw new Error('APPLY_RESULT_MISMATCH');
|
|
180
|
+
await mkdir(this.backupRoot, { recursive: true, mode: 0o700 });
|
|
181
|
+
const backupPath = join(this.backupRoot, `${randomUUID()}.bak`);
|
|
182
|
+
await writeFile(backupPath, original, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
183
|
+
if (sha(await readFile(backupPath, 'utf8')) !== originalSha256)
|
|
184
|
+
throw new Error('APPLY_BACKUP_MISMATCH');
|
|
185
|
+
const auditId = randomUUID();
|
|
186
|
+
try {
|
|
187
|
+
await atomicWrite(path, next);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
await this.audit.append({ auditId, type: 'APPLY_FAILED', path: auth.patch.path, sourceSha256: originalSha256, timestamp: new Date().toISOString(), reason: 'ATOMIC_WRITE_FAILED' });
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
await this.audit.append({ auditId, type: 'APPLIED', path: auth.patch.path, sourceSha256: originalSha256, resultingSha256: appliedSha256, backupPath, timestamp: new Date().toISOString() });
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
await atomicWrite(path, original);
|
|
198
|
+
throw new Error('APPLY_AUDIT_FAILED');
|
|
199
|
+
}
|
|
200
|
+
return { auditId, path: auth.patch.path, originalSha256, appliedSha256, backupPath, appliedAt: new Date().toISOString() };
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
active.delete(key);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async rollback(receipt) { const path = validateReviewPath(this.repositoryRoot, receipt.path); const key = path; if (active.has(key))
|
|
207
|
+
throw new Error('APPLY_IN_PROGRESS'); active.add(key); try {
|
|
208
|
+
const current = await readNoFollow(path);
|
|
209
|
+
if (sha(current) !== receipt.appliedSha256) {
|
|
210
|
+
await this.audit.append({ auditId: receipt.auditId, type: 'ROLLBACK_FAILED', path: receipt.path, sourceSha256: receipt.originalSha256, resultingSha256: sha(current), timestamp: new Date().toISOString(), reason: 'CURRENT_SOURCE_CHANGED' });
|
|
211
|
+
throw new Error('ROLLBACK_CONFLICT');
|
|
212
|
+
}
|
|
213
|
+
const backup = await readFile(receipt.backupPath, 'utf8');
|
|
214
|
+
if (sha(backup) !== receipt.originalSha256)
|
|
215
|
+
throw new Error('ROLLBACK_BACKUP_MISMATCH');
|
|
216
|
+
await atomicWrite(path, backup);
|
|
217
|
+
await this.audit.append({ auditId: receipt.auditId, type: 'ROLLED_BACK', path: receipt.path, sourceSha256: receipt.appliedSha256, resultingSha256: receipt.originalSha256, backupPath: receipt.backupPath, timestamp: new Date().toISOString() });
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
active.delete(key);
|
|
221
|
+
} }
|
|
222
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import postcss from 'postcss';
|
|
2
|
+
import { directionalProperty, propertyConflict } from './directional-properties.js';
|
|
3
|
+
import { hash } from './model.js';
|
|
4
|
+
export const CSS_CONFIGURED_TRANSFORMATION_ID = 'css-configured-intent';
|
|
5
|
+
const offsetVariable = (context, property) => '--rtl-offset-' + hash(context + '\0' + property).slice(0, 16);
|
|
6
|
+
function parseOffset(property, value) {
|
|
7
|
+
if (property === 'transform')
|
|
8
|
+
return /^translateX\((-?\d+(?:\.\d+)?)(%|px)\)$/.exec(value);
|
|
9
|
+
if (property === 'box-shadow')
|
|
10
|
+
return /^(-?\d+(?:\.\d+)?)(px)\s+0(?:px)?\s+\d+(?:\.\d+)?px\s+#[\da-f]{3,8}$/i.exec(value);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
/** Suppress the physical-offset finding only when both literal directional branches are present. */
|
|
14
|
+
export function hasMirroredCssOffset(declaration, evidence) {
|
|
15
|
+
if (declaration.mechanism !== 'css' || !['transform', 'box-shadow'].includes(declaration.property))
|
|
16
|
+
return false;
|
|
17
|
+
const variable = offsetVariable(declaration.context, declaration.property);
|
|
18
|
+
const use = new RegExp(`var\\(${variable}, (-?\\d+(?:\\.\\d+)?(?:%|px))\\)`).exec(declaration.value);
|
|
19
|
+
if (!use)
|
|
20
|
+
return false;
|
|
21
|
+
const offset = parseOffset(declaration.property, declaration.value.replace(use[0], use[1]));
|
|
22
|
+
if (!offset || Number(offset[1]) === 0)
|
|
23
|
+
return false;
|
|
24
|
+
const definitions = evidence.filter(e => e.path === declaration.path && e.mechanism === 'css' && e.property === variable);
|
|
25
|
+
return definitions.length === 2 && definitions.some(e => e.context === declaration.context && e.value === use[1])
|
|
26
|
+
&& definitions.some(e => e.context === declaration.context + '/&:dir(rtl)' && e.value === String(-Number(offset[1])) + offset[2]);
|
|
27
|
+
}
|
|
28
|
+
function replacementFor(declaration, finding) {
|
|
29
|
+
const rule = declaration.parent;
|
|
30
|
+
const intent = finding.cssProposal;
|
|
31
|
+
const { prop, value } = declaration;
|
|
32
|
+
if (rule?.type !== 'rule')
|
|
33
|
+
throw Error('CSS_INTENT_EXPECTED_RULE');
|
|
34
|
+
const peers = rule.nodes.filter((node) => node.type === 'decl' && node !== declaration);
|
|
35
|
+
const base = declaration.clone();
|
|
36
|
+
const serialize = (declarations) => declarations.map(d => d.toString()).join('; ') + (finding.original.endsWith(';') ? ';' : '');
|
|
37
|
+
if (peers.some(d => d.prop === prop || /^(all|direction|writing-mode)$/.test(d.prop)))
|
|
38
|
+
throw Error('CSS_INTENT_CONFLICTING_DECLARATIONS');
|
|
39
|
+
if (intent.kind === 'inline-edge') {
|
|
40
|
+
const spec = directionalProperty(prop, value);
|
|
41
|
+
if (!spec || !['borders', 'positioning'].includes(spec.family))
|
|
42
|
+
throw Error('CSS_INTENT_UNSUPPORTED_EDGE');
|
|
43
|
+
if (peers.some(d => propertyConflict(prop, d.prop, spec.family)))
|
|
44
|
+
throw Error('CSS_INTENT_CONFLICTING_EDGE');
|
|
45
|
+
if (spec.family === 'positioning' && !peers.some(d => d.prop === 'position' && /^(absolute|fixed)$/.test(d.value)))
|
|
46
|
+
throw Error('CSS_INTENT_EXPLICIT_POSITION_REQUIRED');
|
|
47
|
+
base.prop = spec.logical;
|
|
48
|
+
return serialize([base]);
|
|
49
|
+
}
|
|
50
|
+
if (intent.kind === 'dom-order') {
|
|
51
|
+
if (prop !== 'flex-direction' || value !== 'row-reverse' || !peers.some(d => d.prop === 'display' && /^(inline-)?flex$/.test(d.value)) || peers.some(d => d.prop === 'flex-flow'))
|
|
52
|
+
throw Error('CSS_INTENT_EXPLICIT_FLEX_ROW_REQUIRED');
|
|
53
|
+
base.value = 'row';
|
|
54
|
+
return serialize([base]);
|
|
55
|
+
}
|
|
56
|
+
if (intent.kind === 'logical-corners') {
|
|
57
|
+
const radii = value.split(/\s+/);
|
|
58
|
+
if (prop !== 'border-radius' || radii.length !== 4 || !radii.every(v => /^(0|\d+(?:\.\d+)?(?:px|rem|em|%))$/.test(v)) || peers.some(d => /^border-.*radius$/.test(d.prop)))
|
|
59
|
+
throw Error('CSS_INTENT_FOUR_LITERAL_CORNERS_REQUIRED');
|
|
60
|
+
return serialize(['start-start', 'start-end', 'end-end', 'end-start'].map((corner, i) => declaration.clone({ prop: `border-${corner}-radius`, value: radii[i] })));
|
|
61
|
+
}
|
|
62
|
+
if (intent.kind !== 'mirror-offset')
|
|
63
|
+
throw Error('CSS_INTENT_UNKNOWN');
|
|
64
|
+
const offset = parseOffset(prop, value);
|
|
65
|
+
if (!offset || Number(offset[1]) === 0)
|
|
66
|
+
throw Error('CSS_INTENT_LITERAL_HORIZONTAL_OFFSET_REQUIRED');
|
|
67
|
+
const variable = offsetVariable(finding.context, prop);
|
|
68
|
+
const literal = offset[1] + offset[2];
|
|
69
|
+
base.value = value.replace(literal, `var(${variable}, ${literal})`);
|
|
70
|
+
// Nest a direction-specific variable on the same target. Keep the original property and specificity.
|
|
71
|
+
return `${base.toString()}; ${variable}: ${literal}; &:dir(rtl) { ${variable}: ${-Number(offset[1])}${offset[2]}; }`;
|
|
72
|
+
}
|
|
73
|
+
export function proposeConfiguredCss(finding, source) {
|
|
74
|
+
const intent = finding.cssProposal;
|
|
75
|
+
if (!intent || intent.sourceDigest !== hash(source))
|
|
76
|
+
throw Error('CSS_INTENT_STALE_SOURCE');
|
|
77
|
+
if (finding.exceptionReason || finding.ownership !== 'custom-css' || finding.sourceMechanism !== 'css' || !finding.path.endsWith('.css'))
|
|
78
|
+
throw Error('CSS_INTENT_LOCAL_STYLESHEET_REQUIRED');
|
|
79
|
+
const { start, end } = finding.range;
|
|
80
|
+
const root = postcss.parse(source);
|
|
81
|
+
let declaration;
|
|
82
|
+
root.walkDecls(node => {
|
|
83
|
+
if (node.source?.start?.offset === start.offset && node.source?.end?.offset === end.offset)
|
|
84
|
+
declaration = node;
|
|
85
|
+
});
|
|
86
|
+
if (!declaration || source.slice(start.offset, end.offset) !== finding.original)
|
|
87
|
+
throw Error('CSS_INTENT_STALE_RANGE');
|
|
88
|
+
const d = declaration;
|
|
89
|
+
const rule = d.parent;
|
|
90
|
+
if (rule?.type !== 'rule' || rule.parent?.type !== 'root' || !/^\.[a-zA-Z_][\w-]*(?: \.[a-zA-Z_][\w-]*)*$/.test(rule.selector) || finding.context !== 'stylesheet/' + rule.selector)
|
|
91
|
+
throw Error('CSS_INTENT_UNSUPPORTED_SELECTOR');
|
|
92
|
+
if (rule.nodes.some(node => node.type !== 'decl' && node.type !== 'comment') || rule.nodes.some(node => node.type === 'comment' && /rtl-physical\s*:|rtl-icon\s*:/i.test(node.text)))
|
|
93
|
+
throw Error('CSS_INTENT_UNSUPPORTED_RULE_CONTENT');
|
|
94
|
+
const replacement = replacementFor(d, finding);
|
|
95
|
+
postcss.parse(source.slice(0, start.offset) + replacement + source.slice(end.offset));
|
|
96
|
+
return { transformationId: CSS_CONFIGURED_TRANSFORMATION_ID, reason: 'Project declares direction intent for this exact source. Verify the rendered result in each direction before approval.',
|
|
97
|
+
patch: { findingId: finding.id, path: finding.path, startOffset: start.offset, endOffset: end.offset, expectedSha256: hash(finding.original), replacement } };
|
|
98
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import valueParser from 'postcss-value-parser';
|
|
2
|
+
import postcss from 'postcss';
|
|
3
|
+
import { hash } from './model.js';
|
|
4
|
+
import { directionalProperty, propertyConflict, readingEdgeReason } from './directional-properties.js';
|
|
5
|
+
export const CSS_DIRECTIONAL_TRANSFORMATION_ID = 'css-directional-logical';
|
|
6
|
+
export function proposeCssDirectional(finding, source) {
|
|
7
|
+
const reject = (s) => { throw Error('CSS_DIRECTIONAL_' + s); };
|
|
8
|
+
if (!['RTL.CSS.PHYSICAL', 'RTL.GEOMETRY.EDGE'].includes(finding.ruleId) || finding.sourceMechanism !== 'css' || !finding.path.endsWith('.css'))
|
|
9
|
+
reject('STYLESHEET_ONLY');
|
|
10
|
+
if (!new RegExp('^' + finding.ruleId.replaceAll('.', '\\.') + ':[a-f0-9]{24,64}$').test(finding.id))
|
|
11
|
+
reject('FINDING_IDENTITY');
|
|
12
|
+
if (finding.exceptionReason || ['INTENTIONAL_LTR', 'INFORMATIONAL'].includes(finding.category))
|
|
13
|
+
reject('INTENTIONAL_PHYSICAL');
|
|
14
|
+
if (finding.ownership !== 'custom-css')
|
|
15
|
+
reject('OWNER_REQUIRES_REVIEW');
|
|
16
|
+
const root = postcss.parse(source, { from: undefined });
|
|
17
|
+
let target;
|
|
18
|
+
root.walkDecls(d => { if (d.source?.start?.offset === finding.range.start.offset)
|
|
19
|
+
target = d; });
|
|
20
|
+
if (!target || target.source?.end?.offset !== finding.range.end.offset || source.slice(finding.range.start.offset, finding.range.end.offset) !== finding.original)
|
|
21
|
+
reject('STALE_RANGE');
|
|
22
|
+
const d = target;
|
|
23
|
+
if (d.parent?.type !== 'rule' || d.parent.parent?.type !== 'root')
|
|
24
|
+
reject('NESTED_OR_CONDITIONAL_RULE');
|
|
25
|
+
const rule = d.parent;
|
|
26
|
+
if (!/^\.[a-zA-Z_][\w-]*$/.test(rule.selector))
|
|
27
|
+
reject('SIMPLE_CLASS_SELECTOR_REQUIRED');
|
|
28
|
+
if (rule.nodes.some(n => n.type !== 'decl' && n.type !== 'comment'))
|
|
29
|
+
reject('UNSUPPORTED_RULE_CONTENT');
|
|
30
|
+
if (rule.nodes.some(n => n.type === 'comment' && /rtl-physical\s*:|rtl-icon\s*:/i.test(n.text)))
|
|
31
|
+
reject('INTENTIONAL_OR_ICON_REVIEW');
|
|
32
|
+
let direction = false, collision = false;
|
|
33
|
+
root.walkDecls(n => { if (n.prop.toLowerCase() === 'direction' || n.prop.toLowerCase() === 'writing-mode' && n.value !== 'horizontal-tb')
|
|
34
|
+
direction = true; });
|
|
35
|
+
if (direction)
|
|
36
|
+
reject('DIRECTION_OR_WRITING_MODE_REVIEW');
|
|
37
|
+
root.walkRules(r => { if (r !== rule && (r.selector.includes(rule.selector) || r.selector.includes('*')))
|
|
38
|
+
collision = true; });
|
|
39
|
+
if (collision)
|
|
40
|
+
reject('CASCADE_SELECTOR_CONFLICT');
|
|
41
|
+
const spec = directionalProperty(d.prop, d.value);
|
|
42
|
+
if (!spec)
|
|
43
|
+
reject('UNSUPPORTED_PROPERTY_OR_VALUE');
|
|
44
|
+
const peers = rule.nodes.filter((n) => n.type === 'decl' && n !== d);
|
|
45
|
+
if (peers.some(n => propertyConflict(d.prop, n.prop.toLowerCase(), spec.family)))
|
|
46
|
+
reject('CASCADE_DECLARATION_CONFLICT');
|
|
47
|
+
if (spec.family === 'positioning' && !peers.some(n => n.prop === 'position' && /^(absolute|fixed)$/.test(n.value)))
|
|
48
|
+
reject('EXPLICIT_POSITION_REQUIRED');
|
|
49
|
+
const offset = d.prop.length + (d.raws.between ?? ':').length;
|
|
50
|
+
if (source.slice(finding.range.start.offset, finding.range.start.offset + d.prop.length) !== d.prop)
|
|
51
|
+
reject('PROPERTY_SPELLING');
|
|
52
|
+
let replacement = spec.logical + finding.original.slice(d.prop.length);
|
|
53
|
+
if (spec.family === 'alignment') {
|
|
54
|
+
if (finding.original.slice(offset, offset + d.value.length) !== d.value)
|
|
55
|
+
reject('VALUE_RANGE');
|
|
56
|
+
const token = valueParser(d.value).nodes.find(n => n.type === 'word');
|
|
57
|
+
replacement = finding.original.slice(0, offset + token.sourceIndex) + spec.value + finding.original.slice(offset + token.sourceEndIndex);
|
|
58
|
+
}
|
|
59
|
+
return { transformationId: CSS_DIRECTIONAL_TRANSFORMATION_ID, reason: readingEdgeReason, patch: { findingId: finding.id, path: finding.path, startOffset: finding.range.start.offset, endOffset: finding.range.end.offset, expectedSha256: hash(finding.original), replacement } };
|
|
60
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import postcss from 'postcss';
|
|
2
|
+
import { hash, range } from './model.js';
|
|
3
|
+
export const CSS_ICON_TRANSFORMATION_ID = 'css-icon-progression-mirror';
|
|
4
|
+
const marked = (r) => r.nodes.some(n => n.type === 'comment' && /^rtl-icon:\s*progression-right\s*$/.test(n.text.trim()));
|
|
5
|
+
const mirrored = (r, selector) => r.selector === selector + ':dir(rtl)' && r.nodes.length === 1 && r.nodes[0].type === 'decl' && r.nodes[0].prop === 'scale' && r.nodes[0].value === '-1 1' && !r.nodes[0].important;
|
|
6
|
+
/** Explicit semantic opt-in only: property names and generic icon names do not prove intent. */
|
|
7
|
+
export function cssIconAnchors(path, source) {
|
|
8
|
+
const result = [];
|
|
9
|
+
let root;
|
|
10
|
+
try {
|
|
11
|
+
root = postcss.parse(source, { from: undefined });
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
root.walkRules(r => { if (marked(r) && !root.nodes.some(n => n.type === 'rule' && mirrored(n, r.selector))) {
|
|
17
|
+
const start = r.source.start.offset, end = r.source.end.offset;
|
|
18
|
+
const original = source.slice(start, end), context = 'stylesheet/' + r.selector;
|
|
19
|
+
result.push({ path, range: range(source, start, end), original, context, id: hash(path + '|' + context + '|' + original), mechanism: 'css' });
|
|
20
|
+
} });
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
export function proposeCssIcon(finding, source) {
|
|
24
|
+
const reject = (s) => { throw Error('CSS_ICON_' + s); };
|
|
25
|
+
if (finding.ruleId !== 'RTL.ICON.PROGRESSION' || finding.sourceMechanism !== 'css' || !finding.path.endsWith('.css') || !/^RTL\.ICON\.PROGRESSION:[a-f0-9]{24,64}$/.test(finding.id))
|
|
26
|
+
reject('EXPLICIT_SEMANTIC_MARKER_REQUIRED');
|
|
27
|
+
if (finding.exceptionReason || ['INTENTIONAL_LTR', 'INFORMATIONAL'].includes(finding.category) || finding.ownership !== 'custom-css')
|
|
28
|
+
reject('OWNER_OR_INTENT_REVIEW');
|
|
29
|
+
const root = postcss.parse(source, { from: undefined });
|
|
30
|
+
let rule;
|
|
31
|
+
root.walkRules(r => { if (r.source?.start?.offset === finding.range.start.offset && r.source?.end?.offset === finding.range.end.offset)
|
|
32
|
+
rule = r; });
|
|
33
|
+
if (!rule || source.slice(finding.range.start.offset, finding.range.end.offset) !== finding.original)
|
|
34
|
+
reject('STALE_RANGE');
|
|
35
|
+
const r = rule;
|
|
36
|
+
if (!marked(r) || r.parent?.type !== 'root' || !/^\.[a-zA-Z_][\w-]*$/.test(r.selector))
|
|
37
|
+
reject('FLAT_MARKED_CLASS_REQUIRED');
|
|
38
|
+
if (r.nodes.some(n => n.type !== 'decl' && n.type !== 'comment') || r.nodes.some(n => n.type === 'comment' && /rtl-physical\s*:/i.test(n.text)))
|
|
39
|
+
reject('INTENT_OR_RULE_CONTENT_REVIEW');
|
|
40
|
+
if (!r.nodes.some(n => n.type === 'decl' && n.prop === 'display' && /^(inline-block|block)$/.test(n.value)))
|
|
41
|
+
reject('DISPLAY_BOX_REQUIRED');
|
|
42
|
+
let conflict = false;
|
|
43
|
+
root.walkDecls(d => { if (/^(?:transform(?:-|$)|scale$|rotate$|translate$|animation(?:-|$)|transition(?:-|$)|direction$|writing-mode$|all$)/.test(d.prop.toLowerCase()))
|
|
44
|
+
conflict = true; });
|
|
45
|
+
root.walkRules(n => { if (n !== r && (n.selector.includes(r.selector) || n.selector.includes('*')))
|
|
46
|
+
conflict = true; });
|
|
47
|
+
if (conflict)
|
|
48
|
+
reject('CASCADE_OR_TRANSFORM_REVIEW');
|
|
49
|
+
const newline = source.includes('\r\n') ? '\r\n' : '\n';
|
|
50
|
+
return { transformationId: CSS_ICON_TRANSFORMATION_ID, reason: 'Requires semantic review: author marked an LTR right-facing progression icon. Confirm this class targets only the graphic, with no text, brand, trend or framework-owned mirroring; horizontal-tb and inherited CSS direction are required. Preserve LTR; mirror only :dir(rtl). Inspect nested transforms and external styles.', patch: { findingId: finding.id, path: finding.path, startOffset: finding.range.start.offset, endOffset: finding.range.end.offset, expectedSha256: hash(finding.original), replacement: finding.original + newline + r.selector + ':dir(rtl) { scale: -1 1; }' } };
|
|
51
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import postcss from 'postcss';
|
|
2
|
+
import valueParser from 'postcss-value-parser';
|
|
3
|
+
import { hash } from './model.js';
|
|
4
|
+
export const CSS_SPACING_TRANSFORMATION_ID = 'css-spacing-logical';
|
|
5
|
+
/** Syntactic proposal only. Accepting it declares horizontal-tb, LTR-authored reading-edge intent. */
|
|
6
|
+
export function proposeCssSpacing(finding, source) {
|
|
7
|
+
const reject = (code) => { throw Error(code); };
|
|
8
|
+
if (finding.ruleId !== 'RTL.CSS.PHYSICAL' || finding.sourceMechanism !== 'css' || !finding.path.endsWith('.css'))
|
|
9
|
+
reject('CSS_SPACING_STYLESHEET_ONLY');
|
|
10
|
+
if (!/^RTL\.CSS\.PHYSICAL:[a-f0-9]{24,64}$/.test(finding.id))
|
|
11
|
+
reject('CSS_SPACING_FINDING_IDENTITY');
|
|
12
|
+
if (finding.exceptionReason || finding.category === 'INTENTIONAL_LTR' || finding.category === 'INFORMATIONAL')
|
|
13
|
+
reject('CSS_SPACING_INTENTIONAL_PHYSICAL');
|
|
14
|
+
if (finding.ownership !== 'custom-css')
|
|
15
|
+
reject('CSS_SPACING_OWNER_REQUIRES_REVIEW');
|
|
16
|
+
let root;
|
|
17
|
+
try {
|
|
18
|
+
root = postcss.parse(source, { from: undefined });
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
reject('CSS_SPACING_PARSE_FAILED');
|
|
22
|
+
}
|
|
23
|
+
let target;
|
|
24
|
+
root.walkDecls(d => { if (d.source?.start?.offset === finding.range.start.offset)
|
|
25
|
+
target = d; });
|
|
26
|
+
if (!target || target.source?.end?.offset !== finding.range.end.offset || source.slice(finding.range.start.offset, finding.range.end.offset) !== finding.original)
|
|
27
|
+
reject('CSS_SPACING_STALE_RANGE');
|
|
28
|
+
const d = target, match = /^(margin|padding)-(left|right)$/.exec(d.prop);
|
|
29
|
+
if (!match)
|
|
30
|
+
reject('CSS_SPACING_UNSUPPORTED_PROPERTY');
|
|
31
|
+
if (d.parent?.type !== 'rule' || d.parent.parent?.type !== 'root')
|
|
32
|
+
reject('CSS_SPACING_NESTED_OR_CONDITIONAL_RULE');
|
|
33
|
+
const rule = d.parent;
|
|
34
|
+
if (!/^\.[a-zA-Z_][\w-]*$/.test(rule.selector))
|
|
35
|
+
reject('CSS_SPACING_SIMPLE_CLASS_SELECTOR_REQUIRED');
|
|
36
|
+
if (rule.nodes.some(n => n.type !== 'decl' && n.type !== 'comment'))
|
|
37
|
+
reject('CSS_SPACING_UNSUPPORTED_RULE_CONTENT');
|
|
38
|
+
if (rule.nodes.some(n => n.type === 'comment' && /rtl-physical\s*:/i.test(n.text)))
|
|
39
|
+
reject('CSS_SPACING_INTENTIONAL_PHYSICAL');
|
|
40
|
+
// A stylesheet selector alone cannot establish ancestry or co-matching classes.
|
|
41
|
+
// Proposal generation is syntactic; scoped browser evidence evaluates the actual
|
|
42
|
+
// cascade (including inheritance and active conditions) before validation/Apply.
|
|
43
|
+
// A directly declared non-horizontal mode is already conclusively unsupported.
|
|
44
|
+
if (rule.nodes.some(n => n.type === 'decl' && n.prop.toLowerCase() === 'writing-mode' && n.value.trim() !== 'horizontal-tb'))
|
|
45
|
+
reject('CSS_SPACING_DIRECTION_OR_WRITING_MODE_REVIEW');
|
|
46
|
+
const family = match[1];
|
|
47
|
+
const conflicts = (prop) => prop === 'all' || prop === family || prop.startsWith(family + '-inline') || prop.startsWith(family + '-block') || prop.startsWith(family + '-left') || prop.startsWith(family + '-right');
|
|
48
|
+
let collision = false;
|
|
49
|
+
root.walkRules(r => { if (r !== rule && (r.selector.includes(rule.selector) || r.selector.includes('*')) && r.nodes.some(n => n.type === 'decl' && conflicts(n.prop.toLowerCase())))
|
|
50
|
+
collision = true; });
|
|
51
|
+
if (collision)
|
|
52
|
+
reject('CSS_SPACING_CASCADE_SELECTOR_CONFLICT');
|
|
53
|
+
if (rule.nodes.some(n => n !== d && n.type === 'decl' && (conflicts(n.prop.toLowerCase()) || n.prop.toLowerCase() === 'position')))
|
|
54
|
+
reject('CSS_SPACING_CASCADE_DECLARATION_CONFLICT');
|
|
55
|
+
const tokens = valueParser(d.value).nodes.filter(n => n.type !== 'space' && n.type !== 'comment');
|
|
56
|
+
if (tokens.length !== 1 || tokens[0].type !== 'word' || !/^(-?(?:\d*\.)?\d+(?:px|em|rem|%|vw|vh|ch|ex)?|auto)$/.test(tokens[0].value) || family === 'padding' && tokens[0].type === 'word' && (/^-/.test(tokens[0].value) || tokens[0].value === 'auto'))
|
|
57
|
+
reject('CSS_SPACING_UNSUPPORTED_VALUE');
|
|
58
|
+
if (tokens[0].type === 'word' && /^-?(?:\d*\.)?\d+$/.test(tokens[0].value) && Number(tokens[0].value) !== 0)
|
|
59
|
+
reject('CSS_SPACING_UNITLESS_LENGTH');
|
|
60
|
+
const logical = family + '-inline-' + (match[2] === 'left' ? 'start' : 'end');
|
|
61
|
+
const start = finding.range.start.offset, end = finding.range.end.offset;
|
|
62
|
+
if (source.slice(start, start + d.prop.length) !== d.prop)
|
|
63
|
+
reject('CSS_SPACING_UNSUPPORTED_PROPERTY_SPELLING');
|
|
64
|
+
return { transformationId: CSS_SPACING_TRANSFORMATION_ID, reason: 'Requires semantic review: horizontal-tb, LTR-authored reading-start/end spacing. RTL intentionally moves the side; physical coordinates are not preserved. Cross-stylesheet cascade and inherited writing mode must be reviewed. Value, formatting and !important are preserved.', patch: { findingId: finding.id, path: finding.path, startOffset: start, endOffset: end, expectedSha256: hash(finding.original), replacement: logical + finding.original.slice(d.prop.length) } };
|
|
65
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Batch overview reuses persisted entries and existing detail/operation flows. */
|
|
2
|
+
export const batchReviewClientSource = String.raw `
|
|
3
|
+
let batchOpen=false,batchSelection=new Set(),batchScroll=0,batchOwner=null;
|
|
4
|
+
const batchStyle=el('style');batchStyle.textContent='.workspace[hidden]{display:none!important}.batch-review{margin:10px 12px;padding:18px;border-radius:12px;border:1px solid var(--theme-line);min-width:0}.batch-review p{margin:6px 0}.batch-review h2{margin:4px 0 8px;font-size:20px}.batch-review h1{font-size:32px;margin:0 0 6px;letter-spacing:-.02em}.batch-stage{color:var(--theme-muted);margin-bottom:14px!important;font-weight:650}.batch-stats{display:flex;flex-wrap:wrap;gap:10px;margin:12px 0}.batch-stat,.batch-panel{border:1px solid var(--theme-line);border-radius:8px;padding:11px;flex:1;min-width:150px}.batch-stat strong{display:block;font-size:23px}.batch-table-wrap{overflow:auto;max-height:320px}.batch-review table{border-collapse:collapse;width:100%;text-align:left}.batch-review th,.batch-review td{padding:9px 10px;border-bottom:1px solid color-mix(in srgb,var(--theme-line) 68%,transparent)}.batch-review th{font-size:12px;letter-spacing:.03em}.batch-review td code{overflow-wrap:anywhere;color:var(--theme-muted)}.batch-review tbody tr:hover{background:var(--theme-raised)}.batch-review button{padding:8px 12px;border:1px solid var(--theme-line);border-radius:7px;background:var(--theme-raised);color:var(--theme-text)}.batch-review button:disabled{opacity:.5}.batch-review input[type=checkbox]{width:19px;height:19px;accent-color:var(--theme-accent)}.batch-manual{margin:10px 0;border:1px solid var(--theme-warn);border-radius:8px;padding:12px}.batch-manual li{margin:7px 0}.batch-footer{position:sticky;bottom:0;display:flex;gap:10px;align-items:center;flex-wrap:wrap;padding:11px 0;background:var(--theme-surface);border-top:1px solid var(--theme-line);z-index:2}.batch-live{color:var(--theme-muted)}.batch-footer .batch-primary{margin-left:auto}.batch-back{margin-left:8px}@media(max-width:600px){.batch-review{margin:8px;padding:12px}.batch-review h1{font-size:28px}.batch-review th,.batch-review td{padding:8px 5px}.batch-footer .batch-primary{margin-left:0}}';document.head.append(batchStyle);
|
|
5
|
+
function batchFindingLabel(f){const prop=(f.original||'').split(':')[0];return f.ruleId==='RTL.CSS.PHYSICAL'?'Review physical '+(prop.startsWith('padding')?'padding':prop.startsWith('margin')?'margin':prop.startsWith('border')?'border':'alignment'):f.ruleId==='RTL.BIDI.ISOLATION'?'Review '+(f.original?.includes('email')?'email':'name')+' direction':by.get(f.id)?.title||f.message||f.ruleId;}
|
|
6
|
+
const reviewableBatchEntries=()=>workflow?.entries.filter(e=>all.some(f=>f.id===e.finding.id))||[];
|
|
7
|
+
const batchEligible=e=>e.batch?.state==='ready'&&!!e.patch&&e.decision==='Pending';
|
|
8
|
+
function openBatch(focus=true){if(!workflow||sourceContextError||workflow.mode!=='apply-first')return;batchOpen=true;renderBatch();const list=document.querySelector('.batch-table-wrap');if(list)list.scrollTop=batchListScroll;scrollTo(0,batchScroll);if(focus)requestAnimationFrame(()=>document.querySelector('.batch-review h1')?.focus({preventScroll:true}));requestAnimationFrame(()=>{scrollTo(0,batchScroll);const list=document.querySelector('.batch-table-wrap');if(list)list.scrollTop=batchListScroll});}
|
|
9
|
+
let batchListScroll=0;
|
|
10
|
+
function openBatchDetail(f){batchScroll=scrollY;batchListScroll=document.querySelector('.batch-table-wrap')?.scrollTop||0;batchOpen=false;document.querySelector('.batch-review')?.remove();document.querySelector('.workspace').hidden=false;selectReviewFinding(f);renderBatch();requestAnimationFrame(()=>scrollTo(0,Math.max(0,document.querySelector('.workspace').offsetTop-16)));}
|
|
11
|
+
async function prepareBatchOverview(){
|
|
12
|
+
if(!workflow||workflow.mode!=='apply-first'||workflow.state!=='Reviewing')return;
|
|
13
|
+
operationWindow('Preparing batch','Preparing supported fixes in an isolated candidate…',true);
|
|
14
|
+
const result=await api(endpoint+'/'+workflow.id+'/prepare-batch',{});workflow=result.workflow;dismissOperation();batchSelection.clear();batchOwner=workflow.id;batchScroll=0;batchListScroll=0;batchOpen=true;
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
function renderBatch(){
|
|
18
|
+
const workspace=document.querySelector('.workspace');if(!workspace)return;
|
|
19
|
+
let back=document.querySelector('.batch-back');if(workflow?.mode==='apply-first'&&workflow.state==='Reviewing'&&!batchOpen){if(!back){back=el('button','Back to batch','panel-toggle-btn batch-back');back.onclick=()=>openBatch();document.querySelector('.panel-controls')?.append(back)}}else back?.remove();
|
|
20
|
+
if(!batchOpen||!workflow||workflow.mode!=='apply-first'||workflow.state!=='Reviewing'||!workflow.batchPreparedAt||sourceContextError){document.querySelector('.batch-review')?.remove();workspace.hidden=false;return}
|
|
21
|
+
workspace.hidden=true;if(batchOwner!==workflow.id){batchOwner=workflow.id;batchSelection.clear();batchListScroll=0;batchScroll=0}
|
|
22
|
+
const entries=reviewableBatchEntries(),ready=entries.filter(e=>e.batch?.state==='ready'&&e.patch),pending=ready.filter(batchEligible),approved=entries.filter(e=>e.decision==='Accepted'),manual=entries.filter(e=>e.batch?.state!=='ready'||!e.patch||['Deferred','Flagged'].includes(e.decision));
|
|
23
|
+
const ids=new Set(pending.map(e=>e.finding.id));for(const id of batchSelection)if(!ids.has(id))batchSelection.delete(id);
|
|
24
|
+
const old=document.querySelector('.batch-review'),listTop=old?.querySelector('.batch-table-wrap')?.scrollTop||0,focusId=old?.contains(document.activeElement)?document.activeElement.dataset.batchId:null,focusLabel=old?.contains(document.activeElement)&&document.activeElement.tagName==='BUTTON'?document.activeElement.textContent:null;
|
|
25
|
+
const screen=el('section','','batch-review');screen.setAttribute('aria-label','Batch review');const title=el('h1','Batch review');title.tabIndex=-1;screen.append(title,el('p','Review the fixes prepared in an isolated candidate. Original source files are unchanged.'),el('p',workflow.applyEligibility?.eligible?'Prepare ✓ → Review → Validate ✓ → Apply (awaiting confirmation)':'Prepare ✓ → Review (current step) → Validate → Apply','batch-stage'));
|
|
26
|
+
const stats=el('div','','batch-stats');for(const [count,label] of [[ready.length,'fixes prepared'],[pending.length,'pending approval'],[manual.length,'need manual review'],[approved.length,'approved']]){const stat=el('div','','batch-stat');stat.append(el('strong',count),el('span',label));stats.append(stat)}screen.append(stats);
|
|
27
|
+
if(!ready.length)screen.append(el('p','No fixes are ready for batch approval. Review the reasons below, open a finding for code review, or use Defer / Needs review. Original source has not changed.','batch-empty'));
|
|
28
|
+
const panel=el('div','','batch-panel');panel.append(el('h2','Prepared fixes'),el('p','Showing all '+ready.length+' prepared fixes across the selected review scope. Select all prepared includes all eligible pending rows; Explorer and search do not limit this batch.'));
|
|
29
|
+
const wrap=el('div','','batch-table-wrap'),table=el('table'),head=el('thead'),header=el('tr');for(const name of ['Select','Finding','File','Status','Action'])header.append(el('th',name));head.append(header);table.append(head);const body=el('tbody');
|
|
30
|
+
for(const e of ready){const row=el('tr'),cell=el('td'),checkbox=document.createElement('input');checkbox.type='checkbox';checkbox.setAttribute('aria-label','Select '+e.finding.path+' '+e.finding.original);checkbox.dataset.batchId=e.finding.id;checkbox.checked=batchSelection.has(e.finding.id);checkbox.disabled=busy||!!uncertainOperation||!batchEligible(e);checkbox.onchange=()=>{checkbox.checked?batchSelection.add(e.finding.id):batchSelection.delete(e.finding.id);renderBatch()};cell.append(checkbox);const finding=el('td',batchFindingLabel(e.finding)),file=el('td');file.append(el('code',e.finding.path));const status=el('td',e.decision==='Accepted'?'Approved':e.decision==='Flagged'?'Needs review':e.decision),actionCell=el('td'),diff=el('button','View diff');diff.onclick=()=>openBatchDetail(e.finding);actionCell.append(diff);row.append(cell,finding,file,status,actionCell);body.append(row)}table.append(body);wrap.append(table);panel.append(wrap);screen.append(panel);
|
|
31
|
+
if(manual.length){const block=el('section','','batch-manual');block.append(el('h2','Needs manual review'));const list=el('ul');for(const e of manual){const item=el('li',e.finding.path+' · '+e.finding.original+' · '+(['Deferred','Flagged'].includes(e.decision)?(e.decision==='Flagged'?'Needs review':'Deferred')+' · Unresolved; excluded from approved Apply.':e.batch?.reason||e.reason||'No supported automatic fix.')),view=el('button','Review code');view.onclick=()=>openBatchDetail(e.finding);item.append(view);list.append(item)}block.append(list);screen.append(block)}
|
|
32
|
+
const footer=el('div','','batch-footer'),selectAll=el('button','Select all prepared');selectAll.disabled=busy||!!uncertainOperation||!pending.length;selectAll.onclick=()=>{for(const e of pending)batchSelection.add(e.finding.id);renderBatch()};const clear=el('button','Clear selection');clear.disabled=busy||!batchSelection.size;clear.onclick=()=>{batchSelection.clear();renderBatch()};const count=el('span',batchSelection.size+' selected','batch-selection-count');count.setAttribute('role','status');const approve=el('button','Approve selected','batch-primary');approve.disabled=busy||!!uncertainOperation||!batchSelection.size;approve.onclick=async()=>{const ids=[...batchSelection];const result=await operate(()=>api(endpoint+'/'+workflow.id+'/approve-batch',{findingIds:ids}),'Approving selected fixes');if(result?.workflow){batchSelection.clear();render();document.querySelector('.batch-selection-count')?.focus()}};footer.append(selectAll,clear,count,approve);screen.append(footer);
|
|
33
|
+
const stateCopy=workflow.applyEligibility?.eligible?'Validation passed for this exact approved set. The current validation candidate contains only '+approved.length+' approved changes; other prepared proposals are excluded. Apply requires explicit source confirmation.':workflow.validationInvalidation||(!approved.length?'Approve eligible prepared fixes to enable Validate.':workflow.validation?.state==='Failed'?'Validation failed: '+workflow.applyEligibility?.reason:'Validate '+approved.length+' approved changes. Original source has not changed.');const live=el('p',stateCopy,'batch-live');live.setAttribute('role','status');screen.append(live);
|
|
34
|
+
const validate=el('button',workflow.applyEligibility?.eligible?'Apply '+approved.length+' changes to source':'Validate '+approved.length+' approved changes','batch-primary');validate.disabled=busy||!!uncertainOperation||!approved.length;validate.onclick=()=>workflow.applyEligibility?.eligible?applyConfirmation():runDashboardOperation('validate');screen.append(validate);if(error)screen.append(el('p',error,'batch-error'));
|
|
35
|
+
if(old)old.replaceWith(screen);else workspace.before(screen);wrap.scrollTop=listTop;if(focusId)screen.querySelector('input[data-batch-id="'+CSS.escape(focusId)+'"]')?.focus({preventScroll:true});else if(focusLabel)[...screen.querySelectorAll('button')].find(b=>b.textContent===focusLabel&&!b.disabled)?.focus({preventScroll:true});
|
|
36
|
+
}
|
|
37
|
+
`;
|