Files
ARCADIA-Studio/harness/experiments/text-diagnostics-20260913/native-preparation/native-recorder.js
T
sorokin.oleg.edu 9fd76aef3a Add current-draft diagnostic underlines and passive hover
Preserve raw include diagnostic provenance and derive bands from the existing shaped editor. Retain deferred tooltip paragraphs through rendering. Include source, regression, failure and native-trial evidence; corrected native acceptance remains pending.
2026-09-13 01:43:22 -07:00

32 lines
1.8 KiB
JavaScript

// Native diagnostic trial: archive the current observation, then one input and immediate refresh.
globalThis.recordDiagnosticTrial = async function(label) {
if (!/^[a-z0-9-]+$/.test(label)) throw Error('Invalid evidence label');
const s = diagnosticState;
if (!s) throw Error('No current native observation');
const n = String(++diagnosticSequence).padStart(3, '0');
const meta = {atUtc:new Date().toISOString(), label, window:s.window, accessibility:s.accessibility, screenshots:[]};
for (let i = 0; i < s.screenshots.length; i++) {
const {url, ...info} = s.screenshots[i];
const filename = n + '-' + label + '-' + i + '.jpg';
await diagnosticFs.writeFile(diagnosticEvidence + '/' + filename, Buffer.from(url.split(',')[1], 'base64'), {flag:'wx'});
meta.screenshots.push({...info, file:filename});
}
await diagnosticFs.writeFile(diagnosticEvidence + '/' + n + '-' + label + '.json', JSON.stringify(meta, null, 2) + '\n', {flag:'wx'});
};
globalThis.diagnosticAct = async function(kind, args, label, screenshotIndex = 0) {
const allowed = ['click', 'scroll', 'press_key', 'type_text', 'drag'];
if (!allowed.includes(kind)) throw Error('Unsupported trial action');
const s = diagnosticState;
if (!s) throw Error('Reobserve before acting');
const input = {...args, window:s.window};
if (['click', 'scroll', 'drag'].includes(kind)) {
if (!s.screenshots[screenshotIndex]) throw Error('Missing observed screenshot');
input.screenshotId = s.screenshots[screenshotIndex].id;
}
diagnosticState = null;
await sky[kind](input);
diagnosticState = await sky.get_window_state({window:s.window, include_screenshot:true, include_text:true});
if (label) await recordDiagnosticTrial(label);
nodeRepl.write(String(diagnosticState.accessibility?.tree || diagnosticState.accessibility?.document_text || ''));
};