rtl-analyzer 0.1.0 → 0.3.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 +88 -35
- 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 +113 -0
- package/dist/contextual-preview.js +74 -0
- package/dist/controlled-apply.js +222 -0
- package/dist/css-directional.js +60 -0
- package/dist/css-icons.js +51 -0
- package/dist/css-spacing.js +64 -0
- package/dist/dashboard-client.js +57 -40
- package/dist/dashboard-contextual-preview.js +119 -0
- package/dist/dashboard-data.js +1 -1
- package/dist/dashboard-embedded-preview.js +200 -0
- package/dist/dashboard-html.js +11 -10
- package/dist/dashboard-review-details.js +175 -0
- package/dist/dashboard-review-workflow.js +151 -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 +68 -0
- package/dist/output-path.js +65 -0
- package/dist/policy-validation.js +1 -1
- package/dist/preview-cli.js +22 -0
- package/dist/preview-companion.js +621 -0
- package/dist/preview-configuration.js +144 -0
- package/dist/preview-runtime.js +98 -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 +199 -54
- package/dist/review-store.js +175 -0
- package/dist/review-workflow.js +554 -0
- package/dist/rules.js +14 -13
- 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/serialization.js +1 -0
- package/dist/source-context.js +93 -0
- package/dist/source-snippets.js +3 -3
- package/dist/standalone-cli.js +91 -9
- package/dist/tailwind.js +3 -1
- package/dist/transformations.js +20 -0
- package/dist/validation.js +71 -0
- package/dist/workflow-validation.js +46 -0
- package/package.json +20 -7
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import { configuredWorkflowChecks, workflowValidationPresentation, workflowValidationEvidenceIssue } from './workflow-validation.js';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { mkdir, readFile, readdir, rename, realpath, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { execFile } from 'node:child_process';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { chromium } from '@playwright/test';
|
|
8
|
+
import { loadProjectConfiguration, PROJECT_CONFIGURATION } from './project-configuration.js';
|
|
9
|
+
import { previewConfigurationDigest, loadPreviewConfiguration, configuredMapping, routeUrl } from './preview-configuration.js';
|
|
10
|
+
import { scan } from './scan.js';
|
|
11
|
+
import { verifiedSourceTransition } from './source-context.js';
|
|
12
|
+
import { proposeTransformation } from './transformations.js';
|
|
13
|
+
import { approvedPreviewForSource } from './preview-manifest.js';
|
|
14
|
+
import { createReviewSession, startCandidateRuntime, stopCandidateRuntime, validateProjectSourcePath, REVIEW_SOURCE } from './review-session.js';
|
|
15
|
+
const run = promisify(execFile);
|
|
16
|
+
const sha = (text) => createHash('sha256').update(text).digest('hex');
|
|
17
|
+
/** Patches always address immutable originals. Recomposition avoids drift and removes only the rejected edit. */
|
|
18
|
+
export function composeWorkflowFile(before, patches) {
|
|
19
|
+
const sorted = [...patches].sort((a, b) => b.startOffset - a.startOffset);
|
|
20
|
+
let boundary = before.length;
|
|
21
|
+
let result = before;
|
|
22
|
+
for (const p of sorted) {
|
|
23
|
+
if (!Number.isInteger(p.startOffset) || !Number.isInteger(p.endOffset) || p.startOffset < 0 || p.endOffset <= p.startOffset || p.endOffset > boundary)
|
|
24
|
+
throw new Error('OVERLAPPING_OR_INVALID_PATCH');
|
|
25
|
+
if (sha(before.slice(p.startOffset, p.endOffset)) !== p.expectedSha256)
|
|
26
|
+
throw new Error('STALE_PATCH_RANGE');
|
|
27
|
+
result = result.slice(0, p.startOffset) + p.replacement + result.slice(p.endOffset);
|
|
28
|
+
boundary = p.startOffset;
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
const included = (e) => !!e.patch && e.applied && !['Rejected', 'Deferred', 'Flagged'].includes(e.decision);
|
|
33
|
+
const signature = (w) => sha(JSON.stringify(w.entries.filter(e => e.decision === 'Accepted' && included(e)).map(e => e.patch)));
|
|
34
|
+
export class ReviewWorkflowStore {
|
|
35
|
+
root;
|
|
36
|
+
path;
|
|
37
|
+
applyService;
|
|
38
|
+
originalOrigin;
|
|
39
|
+
workflows = [];
|
|
40
|
+
queue = Promise.resolve();
|
|
41
|
+
constructor(root, path, applyService, originalOrigin = 'http://127.0.0.1:4200') {
|
|
42
|
+
this.root = root;
|
|
43
|
+
this.path = path;
|
|
44
|
+
this.applyService = applyService;
|
|
45
|
+
this.originalOrigin = originalOrigin;
|
|
46
|
+
}
|
|
47
|
+
async load() {
|
|
48
|
+
try {
|
|
49
|
+
const data = JSON.parse(await readFile(this.path, 'utf8'));
|
|
50
|
+
if (data.version !== 1 || !Array.isArray(data.workflows))
|
|
51
|
+
throw new Error('WORKFLOW_STORE_INVALID');
|
|
52
|
+
this.workflows = data.workflows.filter(w => w.root === this.root);
|
|
53
|
+
for (const w of this.workflows) {
|
|
54
|
+
if (w.session)
|
|
55
|
+
w.session.runtime = undefined;
|
|
56
|
+
if (w.state === 'Applying')
|
|
57
|
+
w.receipts = await this.applyService.recoverAcceptedFileReceipts(w.id);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error.code !== 'ENOENT')
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async persist() {
|
|
66
|
+
await mkdir(dirname(this.path), { recursive: true, mode: 0o700 });
|
|
67
|
+
const tmp = `${this.path}.${randomUUID()}.tmp`;
|
|
68
|
+
await writeFile(tmp, JSON.stringify({ version: 1, workflows: this.workflows }, null, 2), { flag: 'wx', mode: 0o600 });
|
|
69
|
+
await rename(tmp, this.path);
|
|
70
|
+
}
|
|
71
|
+
exclusive(operation) {
|
|
72
|
+
const result = this.queue.then(operation);
|
|
73
|
+
this.queue = result.catch(() => undefined);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
list() { return [...this.workflows].reverse(); }
|
|
77
|
+
get(id) { const w = this.workflows.find(w => w.id === id); if (!w)
|
|
78
|
+
throw new Error('WORKFLOW_NOT_FOUND'); return w; }
|
|
79
|
+
find(inputDigest, policyDigest, mode) { return [...this.workflows].reverse().find(w => w.inputDigest === inputDigest && w.policyDigest === policyDigest && w.mode === mode); }
|
|
80
|
+
async begin(input, resuming) {
|
|
81
|
+
if (!['one-by-one', 'apply-first'].includes(input.mode))
|
|
82
|
+
throw new Error('INVALID_WORKFLOW_MODE');
|
|
83
|
+
const scope = input.scope ?? [];
|
|
84
|
+
if (!Array.isArray(scope) || scope.some(p => typeof p !== 'string'))
|
|
85
|
+
throw new Error('INVALID_WORKFLOW_SCOPE');
|
|
86
|
+
const prior = this.find(input.inputDigest, input.policyDigest, input.mode);
|
|
87
|
+
const restartable = prior && ['Rolled Back', 'Reviewing'].includes(prior.state);
|
|
88
|
+
if (prior && !resuming && !(input.restart === true && restartable)) {
|
|
89
|
+
if (JSON.stringify(prior.scope) !== JSON.stringify(scope))
|
|
90
|
+
throw new Error('WORKFLOW_SCOPE_MISMATCH');
|
|
91
|
+
return prior;
|
|
92
|
+
}
|
|
93
|
+
const report = await scan(this.root);
|
|
94
|
+
if (report.inputDigest !== input.inputDigest || report.policyDigest !== input.policyDigest)
|
|
95
|
+
throw new Error('DASHBOARD_SOURCE_IDENTITY_MISMATCH');
|
|
96
|
+
if (scope.some(path => !report.files.includes(path)))
|
|
97
|
+
throw new Error('INVALID_WORKFLOW_SCOPE');
|
|
98
|
+
const previewConfigDigest = await previewConfigurationDigest(this.root);
|
|
99
|
+
let configuredFiles = [];
|
|
100
|
+
try {
|
|
101
|
+
configuredFiles = Object.values((await loadPreviewConfiguration(this.root)).applications).flatMap(a => [a.viteConfig, a.entry]);
|
|
102
|
+
}
|
|
103
|
+
catch { /* Invalid preview configuration cannot disable code-only proposals. */ }
|
|
104
|
+
const baseline = {}, sourcePaths = {};
|
|
105
|
+
// Whole scanned source/config identity protects unchanged files too.
|
|
106
|
+
const rootConfigs = (await readdir(this.root)).filter(p => /^(tsconfig.*\.json|(?:vite|vitest|playwright|eslint)(?:\.[\w-]+)*\.config\.[cm]?[jt]s|package-lock\.json|rtl-preview\.config\.json)$/.test(p));
|
|
107
|
+
const project = await loadProjectConfiguration(this.root);
|
|
108
|
+
const projectConfigs = [];
|
|
109
|
+
if (!project) {
|
|
110
|
+
for (const group of ['apps', 'libs'])
|
|
111
|
+
for (const project of await readdir(join(this.root, group))) {
|
|
112
|
+
const directory = join(group, project);
|
|
113
|
+
for (const name of await readdir(join(this.root, directory)))
|
|
114
|
+
if (/^(project\.json|tsconfig.*\.json|vite\.config\.[cm]?[jt]s)$/.test(name))
|
|
115
|
+
projectConfigs.push(join(directory, name));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const optionalConfigs = await Promise.all(['nx.json', 'rtl-scanner.config.json', PROJECT_CONFIGURATION].map(async (path) => await readFile(join(this.root, path)).then(() => path).catch(error => { if (error.code === 'ENOENT')
|
|
119
|
+
return ''; throw error; })));
|
|
120
|
+
for (const path of [...new Set([...report.files, 'package.json', ...optionalConfigs.filter(Boolean), ...rootConfigs, ...projectConfigs, ...configuredFiles])]) {
|
|
121
|
+
sourcePaths[path] = await validateProjectSourcePath(this.root, path);
|
|
122
|
+
baseline[path] = await readFile(sourcePaths[path], 'utf8');
|
|
123
|
+
}
|
|
124
|
+
const entries = report.findings.filter(f => !scope.length || scope.includes(f.path)).map(finding => {
|
|
125
|
+
const entry = { finding, reason: '', applied: false, decision: 'Pending', notes: '', history: [] };
|
|
126
|
+
try {
|
|
127
|
+
if (!report.complete)
|
|
128
|
+
throw new Error('INCOMPLETE_SCAN_REQUIRES_MANUAL_RESOLUTION');
|
|
129
|
+
if (finding.exceptionReason)
|
|
130
|
+
throw new Error('POLICY_EXCEPTION_REQUIRES_REVIEW');
|
|
131
|
+
const proposal = proposeTransformation(finding, baseline[finding.path]);
|
|
132
|
+
entry.patch = proposal.patch;
|
|
133
|
+
entry.reason = proposal.transformationId + ': ' + proposal.reason;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
entry.reason = `${error instanceof Error ? error.message : 'UNSUPPORTED'}: inspect code and resolve manually; no automatic change.`;
|
|
137
|
+
}
|
|
138
|
+
return entry;
|
|
139
|
+
});
|
|
140
|
+
const conflicting = entries.filter(e => e.patch && entries.some(other => other !== e && other.patch && other.patch.path === e.patch.path && other.patch.startOffset < e.patch.endOffset && e.patch.startOffset < other.patch.endOffset));
|
|
141
|
+
for (const e of conflicting) {
|
|
142
|
+
e.reason = 'CONFLICTING_PATCH: overlapping transformations need manual resolution.';
|
|
143
|
+
e.patch = undefined;
|
|
144
|
+
}
|
|
145
|
+
const w = { id: randomUUID(), root: this.root, ...(resuming ? { resumedFrom: resuming.id } : {}), previewConfigDigest, inputDigest: report.inputDigest, policyDigest: report.policyDigest, mode: input.mode, scope, entries, baseline, sourcePaths, state: 'Reviewing', createdAt: new Date().toISOString() };
|
|
146
|
+
if (input.restart && prior && restartable && !resuming) {
|
|
147
|
+
if (prior.session)
|
|
148
|
+
prior.session = await stopCandidateRuntime(prior.session);
|
|
149
|
+
prior.supersededBy = w.id;
|
|
150
|
+
}
|
|
151
|
+
this.workflows.push(w);
|
|
152
|
+
if (!resuming && w.mode === 'apply-first' && entries.some(e => e.patch)) {
|
|
153
|
+
for (const e of entries)
|
|
154
|
+
e.applied = !!e.patch;
|
|
155
|
+
await this.rebuild(w);
|
|
156
|
+
}
|
|
157
|
+
await this.persist();
|
|
158
|
+
return w;
|
|
159
|
+
}
|
|
160
|
+
/** Resume analysis only. Historical decisions, candidates and validation never enter the new review. */
|
|
161
|
+
async resumeAfterRollback(id) {
|
|
162
|
+
const historical = this.get(id);
|
|
163
|
+
if (historical.state !== 'Rolled Back')
|
|
164
|
+
throw Error('SUCCESSFUL_ROLLBACK_REQUIRED');
|
|
165
|
+
const report = await verifiedSourceTransition(this.root, historical);
|
|
166
|
+
const prior = this.workflows.find(w => w.resumedFrom === id);
|
|
167
|
+
if (prior) {
|
|
168
|
+
await this.fresh(prior);
|
|
169
|
+
return prior;
|
|
170
|
+
}
|
|
171
|
+
return this.begin({ inputDigest: report.inputDigest, policyDigest: report.policyDigest, mode: historical.mode, scope: historical.scope }, historical);
|
|
172
|
+
}
|
|
173
|
+
async fresh(w) {
|
|
174
|
+
if (await previewConfigurationDigest(this.root) !== (w.previewConfigDigest ?? sha('')))
|
|
175
|
+
throw Error('PREVIEW_CONFIGURATION_CHANGED');
|
|
176
|
+
if (await realpath(w.root) !== w.root || w.root !== this.root)
|
|
177
|
+
throw new Error('PROJECT_ROOT_IDENTITY_MISMATCH');
|
|
178
|
+
for (const [path, before] of Object.entries(w.baseline)) {
|
|
179
|
+
const target = await validateProjectSourcePath(this.root, path);
|
|
180
|
+
if (target !== w.sourcePaths[path] || sha(await readFile(target, 'utf8')) !== sha(before))
|
|
181
|
+
throw new Error('STALE_ORIGINAL_SOURCE');
|
|
182
|
+
}
|
|
183
|
+
const report = await scan(this.root);
|
|
184
|
+
if (report.inputDigest !== w.inputDigest || report.policyDigest !== w.policyDigest)
|
|
185
|
+
throw new Error('STALE_PROJECT_IDENTITY');
|
|
186
|
+
}
|
|
187
|
+
async candidateFresh(w) {
|
|
188
|
+
if (!w.session)
|
|
189
|
+
throw new Error('CANDIDATE_REQUIRED');
|
|
190
|
+
for (const [path, before] of Object.entries(w.baseline)) {
|
|
191
|
+
const expected = composeWorkflowFile(before, w.entries.filter(e => included(e) && e.patch.path === path).map(e => e.patch));
|
|
192
|
+
const actual = await readFile(await validateProjectSourcePath(w.session.candidateRoot, path), 'utf8');
|
|
193
|
+
if (actual !== expected)
|
|
194
|
+
throw new Error('STALE_CANDIDATE_SOURCE');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
ensureReviewing(w) { if (w.supersededBy)
|
|
198
|
+
throw new Error('HISTORICAL_REVIEW_LOCKED'); if (w.state !== 'Reviewing')
|
|
199
|
+
throw new Error('WORKFLOW_LOCKED_' + w.state); }
|
|
200
|
+
async rebuild(w) {
|
|
201
|
+
await this.fresh(w);
|
|
202
|
+
if (w.session)
|
|
203
|
+
await this.candidateFresh(w);
|
|
204
|
+
if (!w.session)
|
|
205
|
+
w.session = await createReviewSession(this.root, Object.hasOwn(w.baseline, REVIEW_SOURCE) ? REVIEW_SOURCE : w.entries.find(e => e.patch)?.finding.path);
|
|
206
|
+
if (w.session.runtime)
|
|
207
|
+
w.session = await stopCandidateRuntime(w.session);
|
|
208
|
+
for (const path of new Set(w.entries.filter(e => e.patch).map(e => e.finding.path))) {
|
|
209
|
+
const after = composeWorkflowFile(w.baseline[path], w.entries.filter(e => included(e) && e.patch.path === path).map(e => e.patch));
|
|
210
|
+
await writeFile(await validateProjectSourcePath(w.session.candidateRoot, path), after, 'utf8');
|
|
211
|
+
}
|
|
212
|
+
w.session.candidateSha256 = sha(await readFile(join(w.session.candidateRoot, w.session.sourcePath), 'utf8'));
|
|
213
|
+
w.validation = undefined;
|
|
214
|
+
}
|
|
215
|
+
async change(id, findingId, input) {
|
|
216
|
+
const w = this.get(id);
|
|
217
|
+
this.ensureReviewing(w);
|
|
218
|
+
await this.fresh(w);
|
|
219
|
+
const e = w.entries.find(e => e.finding.id === findingId);
|
|
220
|
+
if (!e)
|
|
221
|
+
throw new Error('FINDING_NOT_IN_SCOPE');
|
|
222
|
+
if (!['apply', 'notes', 'Accepted', 'Rejected', 'Deferred', 'Flagged'].includes(input.action))
|
|
223
|
+
throw new Error('INVALID_REVIEW_ACTION');
|
|
224
|
+
if (input.notes !== undefined && (typeof input.notes !== 'string' || input.notes.length > 4000))
|
|
225
|
+
throw new Error('INVALID_REVIEW_NOTES');
|
|
226
|
+
if (input.action === 'notes') {
|
|
227
|
+
e.notes = input.notes ?? '';
|
|
228
|
+
e.history.push({ decision: e.decision, notes: e.notes, at: new Date().toISOString() });
|
|
229
|
+
await this.persist();
|
|
230
|
+
return w;
|
|
231
|
+
}
|
|
232
|
+
if (input.action === 'apply' && !e.patch)
|
|
233
|
+
throw new Error('UNSUPPORTED_TRANSFORMATION');
|
|
234
|
+
if (input.action === 'Accepted' && (!e.patch || !e.applied || ['Rejected', 'Deferred', 'Flagged'].includes(e.decision)))
|
|
235
|
+
throw new Error('APPLY_CANDIDATE_BEFORE_ACCEPTANCE');
|
|
236
|
+
// Check the previous composition before changing membership.
|
|
237
|
+
if (w.session)
|
|
238
|
+
await this.candidateFresh(w);
|
|
239
|
+
const previous = { ...e };
|
|
240
|
+
if (input.action === 'apply') {
|
|
241
|
+
e.applied = true;
|
|
242
|
+
if (['Rejected', 'Deferred', 'Flagged'].includes(e.decision))
|
|
243
|
+
e.decision = 'Pending';
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
e.decision = input.action;
|
|
247
|
+
e.notes = input.notes ?? '';
|
|
248
|
+
if (e.decision !== 'Accepted')
|
|
249
|
+
e.applied = false;
|
|
250
|
+
e.history.push({ decision: e.decision, notes: e.notes, at: new Date().toISOString() });
|
|
251
|
+
}
|
|
252
|
+
// Rebuild from original coordinates, not from the previously patched content.
|
|
253
|
+
try {
|
|
254
|
+
await this.writeComposition(w);
|
|
255
|
+
await this.persist();
|
|
256
|
+
return w;
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
Object.assign(e, previous);
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async writeComposition(w) {
|
|
264
|
+
if (!w.session && !w.entries.some(included)) {
|
|
265
|
+
w.validation = undefined;
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (!w.session)
|
|
269
|
+
w.session = await createReviewSession(this.root, Object.hasOwn(w.baseline, REVIEW_SOURCE) ? REVIEW_SOURCE : w.entries.find(e => e.patch)?.finding.path);
|
|
270
|
+
if (w.session.runtime)
|
|
271
|
+
w.session = await stopCandidateRuntime(w.session);
|
|
272
|
+
for (const path of new Set(w.entries.filter(e => e.patch).map(e => e.finding.path)))
|
|
273
|
+
await writeFile(await validateProjectSourcePath(w.session.candidateRoot, path), composeWorkflowFile(w.baseline[path], w.entries.filter(e => included(e) && e.patch.path === path).map(e => e.patch)), 'utf8');
|
|
274
|
+
w.session.candidateSha256 = sha(await readFile(join(w.session.candidateRoot, w.session.sourcePath), 'utf8'));
|
|
275
|
+
w.validation = undefined;
|
|
276
|
+
}
|
|
277
|
+
async runtime(id, application) {
|
|
278
|
+
const w = this.get(id);
|
|
279
|
+
await this.fresh(w);
|
|
280
|
+
await this.candidateFresh(w);
|
|
281
|
+
w.session = await startCandidateRuntime(w.session, application);
|
|
282
|
+
await this.persist();
|
|
283
|
+
return w;
|
|
284
|
+
}
|
|
285
|
+
/** Called only after the client verifies the original target. Serialized by Companion.
|
|
286
|
+
* Reuses the current composition/runtime; never changes a decision or applies to source. */
|
|
287
|
+
async preparePreview(id, input) {
|
|
288
|
+
const w = this.get(id);
|
|
289
|
+
this.ensureReviewing(w);
|
|
290
|
+
await this.fresh(w);
|
|
291
|
+
if (input.inputDigest !== w.inputDigest || input.policyDigest !== w.policyDigest)
|
|
292
|
+
throw Error('PREVIEW_SOURCE_IDENTITY_MISMATCH');
|
|
293
|
+
const entry = w.entries.find(e => e.finding.id === input.findingId);
|
|
294
|
+
if (!entry?.patch)
|
|
295
|
+
throw Error(entry?.reason || 'PREVIEW_FIX_UNSUPPORTED');
|
|
296
|
+
if (['Rejected', 'Deferred', 'Flagged'].includes(entry.decision))
|
|
297
|
+
throw Error('PREVIEW_DECISION_' + entry.decision.toUpperCase());
|
|
298
|
+
const mapping = configuredMapping(entry.finding, await loadPreviewConfiguration(this.root));
|
|
299
|
+
if (!mapping.routes.some(r => r.id === input.routeId && r.application === input.application))
|
|
300
|
+
throw Error('PREVIEW_MAPPING_UNAVAILABLE');
|
|
301
|
+
if (w.session)
|
|
302
|
+
await this.candidateFresh(w);
|
|
303
|
+
if (!entry.applied)
|
|
304
|
+
await this.change(id, entry.finding.id, { action: 'apply' });
|
|
305
|
+
const prepared = await this.runtime(id, input.application);
|
|
306
|
+
if (prepared.session?.runtime?.status !== 'healthy')
|
|
307
|
+
throw Error(prepared.session?.runtime?.error || 'CANDIDATE_RUNTIME_UNAVAILABLE');
|
|
308
|
+
return prepared;
|
|
309
|
+
}
|
|
310
|
+
async preview(id, findingId, mode) {
|
|
311
|
+
const w = this.get(id);
|
|
312
|
+
const e = w.entries.find(e => e.finding.id === findingId);
|
|
313
|
+
const mapping = e && approvedPreviewForSource(e.finding.path);
|
|
314
|
+
if (!mapping || !e?.patch || !['ltr', 'rtl'].includes(mode))
|
|
315
|
+
throw new Error('LIVE_PREVIEW_MAPPING_UNAVAILABLE');
|
|
316
|
+
await this.fresh(w);
|
|
317
|
+
if (w.session)
|
|
318
|
+
await this.candidateFresh(w);
|
|
319
|
+
let originalAvailable = false;
|
|
320
|
+
try {
|
|
321
|
+
const identity = await fetch(this.originalOrigin + '/__rtl_preview_identity', { signal: AbortSignal.timeout(1200) }).then(r => r.json());
|
|
322
|
+
originalAvailable = identity.projectRoot === this.root && identity.role === 'original' && identity.sourceSha256 === sha(w.baseline[REVIEW_SOURCE]);
|
|
323
|
+
}
|
|
324
|
+
catch { /* show unavailable */ }
|
|
325
|
+
const route = mapping.routes[mode];
|
|
326
|
+
const candidateOrigin = w.session?.runtime?.status === 'healthy' ? w.session.runtime.origin : null;
|
|
327
|
+
return { originalAvailable, originalUrl: this.originalOrigin + route, originalSourceSha256: sha(w.baseline[REVIEW_SOURCE]), candidateSessionId: w.session?.id ?? null, candidateSourceSha256: w.session?.candidateSha256 ?? null, candidateOrigin, url: (candidateOrigin ?? this.originalOrigin) + route, findingId };
|
|
328
|
+
}
|
|
329
|
+
async validate(id) {
|
|
330
|
+
const w = this.get(id);
|
|
331
|
+
this.ensureReviewing(w);
|
|
332
|
+
await this.fresh(w);
|
|
333
|
+
if (!w.entries.some(e => e.decision === 'Accepted' && included(e)))
|
|
334
|
+
throw new Error('ACCEPTED_CHANGES_REQUIRED');
|
|
335
|
+
if (w.session)
|
|
336
|
+
await this.candidateFresh(w);
|
|
337
|
+
// The final candidate contains only explicit acceptances. Pending batch edits remain pending in the inventory.
|
|
338
|
+
for (const e of w.entries)
|
|
339
|
+
if (e.decision !== 'Accepted')
|
|
340
|
+
e.applied = false;
|
|
341
|
+
await this.writeComposition(w);
|
|
342
|
+
await this.persist();
|
|
343
|
+
const checks = [];
|
|
344
|
+
const hashes = {};
|
|
345
|
+
const pkg = JSON.parse(w.baseline['package.json']);
|
|
346
|
+
const project = await loadProjectConfiguration(this.root);
|
|
347
|
+
for (const name of ['typecheck', 'build', 'test']) {
|
|
348
|
+
const args = project ? project.validation[name] : pkg.scripts?.[name] ? ['run', name] : undefined;
|
|
349
|
+
const configured = configuredWorkflowChecks(w).find(c => c.name === name);
|
|
350
|
+
if (!args) {
|
|
351
|
+
checks.push(configured);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const result = await run(project?.packageManager ?? 'npm', args, { cwd: w.session.candidateRoot, env: { ...process.env, NX_DAEMON: 'false', NX_ISOLATE_PLUGINS: 'false' }, timeout: 180_000, maxBuffer: 2_000_000 });
|
|
356
|
+
checks.push({ ...configured, name, state: 'Passed', detail: (result.stdout + result.stderr).slice(-8000) });
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
const failure = error;
|
|
360
|
+
checks.push({ ...configured, name, state: typeof failure.code === 'number' || failure.signal ? 'Failed' : 'Error', detail: ((failure.stdout ?? '') + (failure.stderr ?? '') + failure.message).slice(-8000) });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
const before = await scan(this.root), after = await scan(w.session.candidateRoot);
|
|
365
|
+
const unresolved = w.entries.filter(e => e.decision === 'Accepted' && after.findings.filter(f => f.ruleId === e.finding.ruleId && f.path === e.finding.path).length !== before.findings.filter(f => f.ruleId === e.finding.ruleId && f.path === e.finding.path).length - w.entries.filter(a => a.decision === 'Accepted' && a.finding.ruleId === e.finding.ruleId && a.finding.path === e.finding.path).length);
|
|
366
|
+
checks.push({ name: 'scanner', state: after.complete && !unresolved.length ? 'Passed' : 'Failed', detail: JSON.stringify({ before: before.inputDigest, after: after.inputDigest, beforeFindings: before.findings.length, afterFindings: after.findings.length, unresolved: unresolved.map(e => e.finding.id), complete: after.complete }) });
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
checks.push({ name: 'scanner', state: 'Failed', detail: String(error) });
|
|
370
|
+
}
|
|
371
|
+
const configuration = await loadPreviewConfiguration(this.root);
|
|
372
|
+
if (project || (!Object.hasOwn(w.baseline, REVIEW_SOURCE) && Object.keys(configuration.applications).length)) {
|
|
373
|
+
const accepted = w.entries.filter(e => e.decision === 'Accepted' && included(e));
|
|
374
|
+
const routes = new Map();
|
|
375
|
+
for (const entry of accepted) {
|
|
376
|
+
const mapping = configuredMapping(entry.finding, configuration);
|
|
377
|
+
if (!mapping.configured || !mapping.routes.length) {
|
|
378
|
+
checks.push({ name: 'runtime:' + entry.finding.id, state: 'Unavailable', detail: 'Accepted change has no explicit configured source-to-target route.' });
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
for (const route of mapping.routes) {
|
|
382
|
+
const prior = routes.get(route.id);
|
|
383
|
+
if (prior)
|
|
384
|
+
prior.entries.push(entry);
|
|
385
|
+
else
|
|
386
|
+
routes.set(route.id, { application: route.application, route, entries: [entry] });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
for (const { application, route, entries } of routes.values())
|
|
390
|
+
try {
|
|
391
|
+
await this.runtime(id, application);
|
|
392
|
+
if (w.session?.runtime?.status !== 'healthy')
|
|
393
|
+
throw Error('CANDIDATE_RUNTIME_UNAVAILABLE');
|
|
394
|
+
const browser = await chromium.launch({ headless: true });
|
|
395
|
+
try {
|
|
396
|
+
for (const mode of ['ltr', 'rtl']) {
|
|
397
|
+
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } }), errors = [];
|
|
398
|
+
page.on('pageerror', e => errors.push(e.message));
|
|
399
|
+
await page.goto(routeUrl(route, mode, w.session.runtime.origin), { waitUntil: 'domcontentloaded', timeout: 20000 });
|
|
400
|
+
await page.locator(configuration.applications[application].readySelector).first().waitFor();
|
|
401
|
+
await page.waitForFunction(mode => document.documentElement.dir === mode, mode, { timeout: 10000 });
|
|
402
|
+
const targets = [];
|
|
403
|
+
for (const entry of entries) {
|
|
404
|
+
const mapping = configuredMapping(entry.finding, configuration);
|
|
405
|
+
await page.locator(mapping.selector).first().waitFor({ state: 'visible', timeout: 10000 });
|
|
406
|
+
const evidence = await page.evaluate(({ selector, sourceSelector, path, bidi }) => {
|
|
407
|
+
const nodes = [...document.querySelectorAll(selector)], styles = [...document.querySelectorAll('style[data-vite-dev-id]')].filter(n => n.getAttribute('data-vite-dev-id')?.replaceAll('\\', '/').endsWith('/' + path));
|
|
408
|
+
const rules = [];
|
|
409
|
+
function walk(items) { for (const rule of items) {
|
|
410
|
+
if ('selectorText' in rule)
|
|
411
|
+
rules.push(rule);
|
|
412
|
+
else if ('cssRules' in rule)
|
|
413
|
+
walk(rule.cssRules);
|
|
414
|
+
} }
|
|
415
|
+
for (const style of styles)
|
|
416
|
+
if (style.sheet)
|
|
417
|
+
walk(style.sheet.cssRules);
|
|
418
|
+
const matched = !sourceSelector || rules.some(r => r.selectorText.split(',').map(s => s.trim()).includes(sourceSelector) && nodes.some(n => n.matches(r.selectorText)));
|
|
419
|
+
return { path, selector, sourceRuleMatched: matched, count: nodes.length, bdi: !bidi || nodes.some(n => n.matches('bdi[dir="auto"]') || n.querySelector('bdi[dir="auto"]')), computed: nodes.slice(0, 5).map(n => ({ direction: getComputedStyle(n).direction, textAlign: getComputedStyle(n).textAlign, insetInlineStart: getComputedStyle(n).insetInlineStart, insetInlineEnd: getComputedStyle(n).insetInlineEnd })) };
|
|
420
|
+
}, { selector: mapping.selector, sourceSelector: mapping.sourceSelector, path: entry.finding.path, bidi: entry.finding.ruleId === 'RTL.BIDI.ISOLATION' });
|
|
421
|
+
if (!evidence.sourceRuleMatched || !evidence.bdi)
|
|
422
|
+
throw Error('CONFIGURED_SOURCE_TARGET_NOT_VERIFIED:' + entry.finding.path);
|
|
423
|
+
targets.push(evidence);
|
|
424
|
+
}
|
|
425
|
+
if (errors.length)
|
|
426
|
+
throw Error('RUNTIME_DOM_FAILED:' + errors.join(';'));
|
|
427
|
+
checks.push({ name: 'runtime-' + route.id + '-' + mode, state: 'Passed', detail: JSON.stringify({ route: page.url(), direction: mode, viewport: { width: 1280, height: 800 }, targets, errors }) });
|
|
428
|
+
await page.close();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
finally {
|
|
432
|
+
await browser.close();
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
checks.push({ name: 'runtime-' + route.id, state: 'Unavailable', detail: String(error) });
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
try {
|
|
441
|
+
await this.runtime(id);
|
|
442
|
+
if (w.session?.runtime?.status !== 'healthy')
|
|
443
|
+
throw new Error('CANDIDATE_RUNTIME_UNAVAILABLE');
|
|
444
|
+
const browser = await chromium.launch({ headless: true });
|
|
445
|
+
try {
|
|
446
|
+
for (const mode of ['ltr', 'rtl']) {
|
|
447
|
+
const page = await browser.newPage();
|
|
448
|
+
const errors = [];
|
|
449
|
+
page.on('pageerror', e => errors.push(e.message));
|
|
450
|
+
await page.goto(w.session.runtime.origin + (mode === 'ltr' ? '/invoices' : '/invoices?demo=unmigrated-rtl&lang=ar'), { waitUntil: 'domcontentloaded', timeout: 20_000 });
|
|
451
|
+
await page.locator('.invoice-link').first().waitFor();
|
|
452
|
+
if (await page.locator('html').getAttribute('dir') !== mode || errors.length)
|
|
453
|
+
throw new Error('RUNTIME_DOM_FAILED:' + errors.join(';'));
|
|
454
|
+
if (w.entries.some(e => e.finding.ruleId === 'RTL.BIDI.ISOLATION' && e.finding.path === REVIEW_SOURCE && e.decision === 'Accepted') && await page.locator('.invoice-link bdi[dir="auto"]').count() === 0)
|
|
455
|
+
throw new Error('PATCHED_DOM_MISSING');
|
|
456
|
+
checks.push({ name: 'runtime-' + mode, state: 'Passed', detail: 'Real /invoices route rendered; direction and supported patched DOM verified.' });
|
|
457
|
+
await page.close();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
finally {
|
|
461
|
+
await browser.close();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
checks.push({ name: 'runtime', state: 'Unavailable', detail: String(error) });
|
|
466
|
+
}
|
|
467
|
+
for (const e of w.entries.filter(e => e.decision === 'Accepted'))
|
|
468
|
+
if (!approvedPreviewForSource(e.finding.path))
|
|
469
|
+
checks.push({ name: 'live-preview:' + e.finding.path, state: 'Unavailable', detail: 'No approved owning-route mapping. Code review remains available.' });
|
|
470
|
+
}
|
|
471
|
+
await this.candidateFresh(w);
|
|
472
|
+
await this.fresh(w);
|
|
473
|
+
for (const path of Object.keys(w.baseline))
|
|
474
|
+
hashes[path] = sha(await readFile(await validateProjectSourcePath(w.session.candidateRoot, path), 'utf8'));
|
|
475
|
+
const required = checks.filter(c => !c.name.startsWith('live-preview:') && !(['Not configured', 'Not applicable'].includes(c.state) && ['typecheck', 'build', 'test'].includes(c.name)));
|
|
476
|
+
w.validation = { state: required.some(c => c.state === 'Failed') ? 'Failed' : required.some(c => ['Unavailable', 'Error', 'Not run'].includes(c.state)) ? 'Unavailable' : 'Passed', signature: signature(w), checks, hashes, at: new Date().toISOString() };
|
|
477
|
+
await this.persist();
|
|
478
|
+
return w;
|
|
479
|
+
}
|
|
480
|
+
async apply(id, confirmation) {
|
|
481
|
+
const w = this.get(id);
|
|
482
|
+
if (w.supersededBy)
|
|
483
|
+
throw Error('HISTORICAL_REVIEW_LOCKED');
|
|
484
|
+
if (w.state === 'Applied')
|
|
485
|
+
return w;
|
|
486
|
+
if (!w.validation || w.validation.state !== 'Passed' || w.validation.signature !== signature(w))
|
|
487
|
+
throw new Error('VALIDATED_ACCEPTED_CANDIDATE_REQUIRED');
|
|
488
|
+
const evidenceIssue = workflowValidationEvidenceIssue(w);
|
|
489
|
+
if (evidenceIssue)
|
|
490
|
+
throw Error('VALIDATION_EVIDENCE_MISSING: ' + evidenceIssue);
|
|
491
|
+
if (w.state === 'Reviewing')
|
|
492
|
+
await this.fresh(w);
|
|
493
|
+
if (!['Reviewing', 'Applying'].includes(w.state))
|
|
494
|
+
throw new Error('WORKFLOW_LOCKED_' + w.state);
|
|
495
|
+
if (w.state === 'Applying') {
|
|
496
|
+
for (const [path, before] of Object.entries(w.baseline)) {
|
|
497
|
+
const target = await validateProjectSourcePath(this.root, path);
|
|
498
|
+
const after = composeWorkflowFile(before, w.entries.filter(e => e.decision === 'Accepted' && included(e) && e.finding.path === path).map(e => e.patch));
|
|
499
|
+
const current = sha(await readFile(target, 'utf8'));
|
|
500
|
+
if (target !== w.sourcePaths[path] || (current !== sha(before) && current !== sha(after)))
|
|
501
|
+
throw new Error('STALE_APPLY_SOURCE');
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
await this.candidateFresh(w);
|
|
505
|
+
for (const [path, hash] of Object.entries(w.validation.hashes))
|
|
506
|
+
if (sha(await readFile(await validateProjectSourcePath(w.session.candidateRoot, path), 'utf8')) !== hash)
|
|
507
|
+
throw new Error('STALE_VALIDATED_CANDIDATE');
|
|
508
|
+
if (confirmation !== 'APPLY_CONFIRMED')
|
|
509
|
+
throw new Error('APPLY_CONFIRMATION_REQUIRED');
|
|
510
|
+
w.state = 'Applying';
|
|
511
|
+
await this.persist();
|
|
512
|
+
const files = [...new Set(w.entries.filter(e => e.decision === 'Accepted' && included(e)).map(e => e.finding.path))].map(path => ({ path, before: w.baseline[path], after: composeWorkflowFile(w.baseline[path], w.entries.filter(e => e.decision === 'Accepted' && included(e) && e.finding.path === path).map(e => e.patch)) }));
|
|
513
|
+
try {
|
|
514
|
+
w.receipts = await this.applyService.applyAcceptedFiles(w.id, files, confirmation);
|
|
515
|
+
w.state = 'Applied';
|
|
516
|
+
await this.persist();
|
|
517
|
+
return w;
|
|
518
|
+
}
|
|
519
|
+
catch (error) {
|
|
520
|
+
w.receipts = await this.applyService.recoverAcceptedFileReceipts(w.id);
|
|
521
|
+
await this.persist();
|
|
522
|
+
throw error;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
async rollback(id, confirmation) {
|
|
526
|
+
const w = this.get(id);
|
|
527
|
+
if (confirmation !== 'ROLLBACK_CONFIRMED')
|
|
528
|
+
throw new Error('ROLLBACK_CONFIRMATION_REQUIRED');
|
|
529
|
+
if (w.state === 'Rolled Back')
|
|
530
|
+
return w;
|
|
531
|
+
if (!w.receipts?.length)
|
|
532
|
+
throw new Error('APPLY_RECEIPTS_REQUIRED');
|
|
533
|
+
await this.applyService.rollbackAcceptedFiles(w.receipts);
|
|
534
|
+
w.state = 'Rolled Back';
|
|
535
|
+
w.rolledBackAt = new Date().toISOString();
|
|
536
|
+
await this.persist();
|
|
537
|
+
return w;
|
|
538
|
+
}
|
|
539
|
+
async shutdown() { for (const w of this.workflows)
|
|
540
|
+
if (w.session)
|
|
541
|
+
w.session = await stopCandidateRuntime(w.session); await this.persist(); }
|
|
542
|
+
view(w) {
|
|
543
|
+
const { baseline, sourcePaths: _paths, ...rest } = w;
|
|
544
|
+
const files = [...new Set(w.entries.map(e => e.finding.path))].map(path => {
|
|
545
|
+
const before = baseline[path], after = composeWorkflowFile(before, w.entries.filter(e => included(e) && e.finding.path === path).map(e => e.patch));
|
|
546
|
+
return { path, originalSha256: sha(before), candidateSha256: sha(after), before, after, diff: before === after ? 'No candidate changes.' : `--- ${path}\n+++ ${path}\n- ${before.split('\n').join('\n- ')}\n+ ${after.split('\n').join('\n+ ')}` };
|
|
547
|
+
});
|
|
548
|
+
const fresh = !!w.validation && w.validation.signature === signature(w);
|
|
549
|
+
const evidenceIssue = w.validation ? workflowValidationEvidenceIssue(w) : undefined;
|
|
550
|
+
const eligible = !evidenceIssue && !w.supersededBy && fresh && w.validation?.state === 'Passed' && ['Reviewing', 'Applying'].includes(w.state) && w.entries.some(e => e.decision === 'Accepted' && included(e));
|
|
551
|
+
const reason = w.supersededBy ? 'Historical review was superseded; start from the current review.' : eligible ? 'Snapshot eligible under existing Apply policy: missing or explicitly excluded project commands are not required; scanner/runtime checks and source/candidate identity guards still apply.' : w.state !== 'Reviewing' && w.state !== 'Applying' ? 'Historical review cannot apply changes.' : !w.entries.some(e => e.decision === 'Accepted' && included(e)) ? 'Approve at least one prepared change.' : !fresh ? 'Validate the current accepted candidate before Apply.' : evidenceIssue ? evidenceIssue : 'Resolve required checks: ' + (w.validation?.checks.filter(c => ['Failed', 'Unavailable', 'Error', 'Not run'].includes(c.state) && !c.name.startsWith('live-preview:')).map(c => c.name + ': ' + c.state + ' · ' + c.detail.slice(0, 180)).join('; ') || w.validation?.state);
|
|
552
|
+
return { ...rest, schemaVersion: 2, files, validationPresentation: workflowValidationPresentation(w, fresh), applyEligibility: { eligible, reason } };
|
|
553
|
+
}
|
|
554
|
+
}
|
package/dist/rules.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
import { hasIsolation } from './codemod.js';
|
|
3
|
+
import { cssIconAnchors } from './css-icons.js';
|
|
2
4
|
import { analyzeRuntimeDirection } from './runtime-direction.js';
|
|
3
5
|
import valueParser from 'postcss-value-parser';
|
|
4
6
|
import { hash, range } from './model.js';
|
|
@@ -19,6 +21,10 @@ export function detect(evidence, sources, policy, diagnostics) {
|
|
|
19
21
|
return findings.at(-1);
|
|
20
22
|
}
|
|
21
23
|
for (const e of evidence) {
|
|
24
|
+
if (['tailwind-utility', 'bootstrap-utility'].includes(e.semantics)) {
|
|
25
|
+
add('RTL.UTILITY.PHYSICAL', 'Physical utility class requires compiler-aware review', e, 'MANUAL_REVIEW', 'Static class syntax does not establish the installed compiler, version or semantic intent.', 'Check utility framework/version/config and variants; review reading-edge intent. No utility patch is prepared.', 'utility-compiler', [e], 'Medium');
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
22
28
|
if (cssKey(e.property) === 'position' && plain(e.value) === 'fixed') {
|
|
23
29
|
const peers = evidence.filter(x => x.path === e.path && x.context === e.context);
|
|
24
30
|
const width = peers.find(x => cssKey(x.property) === 'width');
|
|
@@ -38,7 +44,7 @@ export function detect(evidence, sources, policy, diagnostics) {
|
|
|
38
44
|
const dynamic = diagnostics.some(d => d.path === e.path && d.blocking && d.range.start.offset >= e.range.start.offset && d.range.end.offset <= e.range.end.offset);
|
|
39
45
|
if (/^(left|right)$/.test(p))
|
|
40
46
|
add('RTL.GEOMETRY.EDGE', 'Physical positioned edge', e, 'MANUAL_REVIEW', 'Physical edge is coupled to placement, containing block and clearance; logical replacement alone does not select the correct side.', 'Review anchor, companion gutter, breakpoints and collision clearance as one layout contract.', owner, [e, ...(position ? [position] : [])], 'High');
|
|
41
|
-
else if (/^(margin|padding|border)-(left|right)(-|$)/.test(p) || /^(border-top-left-radius|border-top-right-radius|border-bottom-left-radius|border-bottom-right-radius)$/.test(p) || (/^(text-align|float|clear)$/.test(p) && /^(left|right)$/.test(v))) {
|
|
47
|
+
else if (/^(margin|padding|border)-(left|right)(-|$)/.test(p) || /^(border-top-left-radius|border-top-right-radius|border-bottom-left-radius|border-bottom-right-radius)$/.test(p) || (/^(text-align|float|clear)$/.test(p) && /^(left|right)$/.test(valueParser(v).nodes.filter(n => n.type !== 'space' && n.type !== 'comment').map(n => valueParser.stringify(n)).join(' ')))) {
|
|
42
48
|
const approval = policy.approvals.find(a => a.path === e.path && a.context === e.context && a.property === e.property && a.value === e.value && a.owner === owner && a.sourceDigest === hash(sources.get(e.path) ?? ''));
|
|
43
49
|
const expectedLogical = p.replace(/^(margin|padding|border)-(left|right)(.*)$/, (_, group, side, suffix) => `${group}-inline-${side === 'left' ? 'start' : 'end'}${suffix}`);
|
|
44
50
|
const safe = approval && cssKey(approval.logicalProperty) === expectedLogical && !evidence.some(x => cssKey(x.property) === 'writing-mode' && plain(x.value) !== 'horizontal-tb') && e.mechanism !== 'mui-sx' && !/^(inherit|initial|unset|revert|revert-layer)$/.test(v) && !/\b(var|env)\(/.test(v) && !dynamic && ['custom-css', 'custom-inline', 'custom-emotion-logical'].includes(owner) && /^(margin|padding|border)-(left|right)(-|$)/.test(p) && !diagnostics.some(d => d.blocking) && !peers.some(x => x !== e && cssKey(x.property) === p) && !position && !peers.some(x => /writing-mode|direction/.test(cssKey(x.property)));
|
|
@@ -55,6 +61,10 @@ export function detect(evidence, sources, policy, diagnostics) {
|
|
|
55
61
|
else if ((p === 'transform' && /translateX\((?!0\))/i.test(v)) || (/^(transform-origin|background-position|box-shadow)$/.test(p) && /left|right|\d/.test(v)) || p === 'order' || p === 'flex-direction' && v === 'row-reverse' || /^grid-(column|row|area)/.test(p) && !/^auto$/.test(v) && !/^1\s*\/\s*-1$/.test(v))
|
|
56
62
|
add('RTL.GEOMETRY.ORDER', 'Directional geometry or explicit order', e, 'MANUAL_REVIEW', 'Transform/axis/order semantics require geometric and reading-order decisions.', 'Review spatial intent, focus order and companion positioning; no numeric sign reversal.', owner, [e], 'Medium');
|
|
57
63
|
}
|
|
64
|
+
for (const [path, text] of sources)
|
|
65
|
+
if (path.endsWith('.css'))
|
|
66
|
+
for (const a of cssIconAnchors(path, text))
|
|
67
|
+
add('RTL.ICON.PROGRESSION', 'Explicit progression icon needs direction-aware rendering', a, 'MANUAL_REVIEW', 'Author supplied rtl-icon: progression-right semantic metadata; rendered ownership and icon-only targeting still require review.', 'Review icon-only targeting, LTR baseline, inherited direction and existing transforms before mirroring.', policy.ownership.css ?? 'unknown', [], 'High');
|
|
58
68
|
// Generic syntax evidence: imports and JSX/data flow are inspected, never executed.
|
|
59
69
|
const themes = [], rtl = evidence.filter(e => e.mechanism === 'html-root' && e.property === 'dir' && e.value === 'rtl'), providers = [], caches = [], cacheChecks = new Map();
|
|
60
70
|
const entries = [...sources.entries()].filter(([p]) => /\.[jt]sx?$/.test(p));
|
|
@@ -82,17 +92,6 @@ export function detect(evidence, sources, policy, diagnostics) {
|
|
|
82
92
|
return 'JsxText:' + n.getText(sf).trim(); if (ts.isIdentifier(n) || ts.isStringLiteral(n) || ts.isNumericLiteral(n))
|
|
83
93
|
return ts.SyntaxKind[n.kind] + ':' + n.text; const parts = []; ts.forEachChild(n, x => { parts.push(identity(x)); }); return ts.SyntaxKind[n.kind] + '(' + parts.join('|') + ')'; }
|
|
84
94
|
function anchor(n, context = ctx(n)) { const a = { path, range: range(text, n.getStart(sf), n.end), original: n.getText(sf), context, id: hash(path + '|' + context + '|' + ts.SyntaxKind[n.kind] + '|' + identity(n)) }; return a; }
|
|
85
|
-
function isolated(n) { let p = n.parent; while (p && !ts.isFunctionDeclaration(p) && !ts.isVariableDeclaration(p)) {
|
|
86
|
-
if (ts.isJsxElement(p)) {
|
|
87
|
-
const o = p.openingElement;
|
|
88
|
-
if (o.tagName.getText(sf) === 'bdi' || o.attributes.properties.some(x => ts.isJsxAttribute(x) && x.name.getText(sf) === 'dir' && x.initializer && ts.isStringLiteral(x.initializer) && ['ltr', 'auto'].includes(x.initializer.text)))
|
|
89
|
-
return true;
|
|
90
|
-
const style = o.attributes.properties.find(x => ts.isJsxAttribute(x) && x.name.getText(sf) === 'style');
|
|
91
|
-
if (style && ts.isJsxAttribute(style) && style.initializer && ts.isJsxExpression(style.initializer) && style.initializer.expression && ts.isObjectLiteralExpression(style.initializer.expression) && style.initializer.expression.properties.some(x => ts.isPropertyAssignment(x) && x.name.getText(sf) === 'unicodeBidi' && ts.isStringLiteral(x.initializer) && x.initializer.text === 'isolate'))
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
p = p.parent;
|
|
95
|
-
} return false; }
|
|
96
95
|
function visit(n) {
|
|
97
96
|
for (const proof of runtimeProofs.filter(p => p.node === n)) {
|
|
98
97
|
const cacheAnchor = anchor(n, ctx(n) + (ts.isJsxOpeningElement(n) || ts.isJsxSelfClosingElement(n) ? '/' + n.tagName.getText(sf) : ''));
|
|
@@ -161,6 +160,8 @@ export function detect(evidence, sources, policy, diagnostics) {
|
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
162
|
const classAttr = n.attributes.properties.find(p => ts.isJsxAttribute(p) && p.name.getText(sf) === 'className');
|
|
163
|
+
if (classAttr && !evidence.some(e => e.path === path && ['tailwind-utility', 'bootstrap-utility'].includes(e.semantics) && e.range.start.offset >= classAttr.getStart(sf) && e.range.end.offset <= classAttr.end) && ts.isJsxAttribute(classAttr) && classAttr.initializer && ts.isStringLiteral(classAttr.initializer) && classAttr.initializer.text.split(/\s+/).some(c => /^(?:(?:sm|md|lg|xl|hover|focus|rtl|ltr):)*(?:-?(?:ml|mr|pl|pr|left|right)-[\w.[\]%-]+|text-(?:left|right)|border-(?:l|r)(?:-[\w-]+)?|rounded-(?:tl|tr|bl|br)(?:-[\w-]+)?)$/.test(c)))
|
|
164
|
+
add('RTL.UTILITY.PHYSICAL', 'Physical utility class requires compiler-aware review', anchor(classAttr), 'MANUAL_REVIEW', 'Static className contains recognized physical utility tokens; class names do not establish the installed compiler, version or semantic intent.', 'Check utility framework/version/config and variants; review reading-edge intent, then use compiler-supported logical utilities. No utility patch is prepared.', 'utility-compiler', [], 'Medium');
|
|
164
165
|
if (classAttr && ts.isJsxAttribute(classAttr) && classAttr.initializer && ts.isStringLiteral(classAttr.initializer)) {
|
|
165
166
|
const role = policy.roles.find(r => r.kind === 'brand' && r.path === path && classAttr.initializer && ts.isStringLiteral(classAttr.initializer) && classAttr.initializer.text.split(/\s+/).includes(r.className));
|
|
166
167
|
if (role && !n.attributes.properties.some(p => ts.isJsxAttribute(p) && p.name.getText(sf) === 'dir')) {
|
|
@@ -176,7 +177,7 @@ export function detect(evidence, sources, policy, diagnostics) {
|
|
|
176
177
|
p = p.parent;
|
|
177
178
|
} return false; })()))
|
|
178
179
|
add('RTL.ICON.LITERAL', 'Literal directional arrow in rendered-copy call', anchor(n), 'MANUAL_REVIEW', 'A literal arrow occurs in a copy/function call; its progression meaning and translated rendering need review.', 'Review copy and navigation semantics rather than replacing every arrow.', 'custom-copy', [], 'Medium');
|
|
179
|
-
if (ts.isJsxExpression(n) && n.expression && !
|
|
180
|
+
if (ts.isJsxExpression(n) && n.expression && !hasIsolation(n, true)) {
|
|
180
181
|
let candidate = false;
|
|
181
182
|
function token(x) { if (ts.isPropertyAccessExpression(x) && ['name', 'address', 'email', 'id'].includes(x.name.text))
|
|
182
183
|
candidate = true; if (ts.isCallExpression(x) && ts.isIdentifier(x.expression) && imports.get(x.expression.text)?.endsWith(':money'))
|