@mushi-mushi/ux 0.5.2 → 0.7.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 +14 -0
- package/dist/cli.js +4368 -3989
- package/dist/index.d.ts +20 -3
- package/dist/index.js +158 -45
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -267,6 +267,8 @@ interface SessionOptions {
|
|
|
267
267
|
ignore?: readonly string[];
|
|
268
268
|
/** Write policy (guard.ts). Default read-only; fresh-eyes runs may write to the app's own origins (ADR 0053). */
|
|
269
269
|
policy?: GuardPolicy;
|
|
270
|
+
/** Cookies and storage a clean browser starts with (a sign-in done in another session); ignored with a profile. */
|
|
271
|
+
storageState?: Awaited<ReturnType<BrowserContext['storageState']>>;
|
|
270
272
|
}
|
|
271
273
|
declare function openSession(opts?: SessionOptions): Promise<BrowserSession>;
|
|
272
274
|
/**
|
|
@@ -1272,7 +1274,7 @@ interface FreshEyesStep {
|
|
|
1272
1274
|
capped?: boolean;
|
|
1273
1275
|
}
|
|
1274
1276
|
/** Why a session ended without reaching its goal. Measured causes are page facts; the last two are the model's. */
|
|
1275
|
-
type StallReason = 'signup_wall' | 'captcha' | 'external' | 'dead_end' | 'blocked' | 'error' | 'model_gave_up' | 'model_unavailable' | 'out_of_steps';
|
|
1277
|
+
type StallReason = 'signup_wall' | 'captcha' | 'external' | 'dead_end' | 'blocked' | 'error' | 'model_gave_up' | 'model_unavailable' | 'out_of_steps' | 'unverified';
|
|
1276
1278
|
interface FreshEyesSession {
|
|
1277
1279
|
index: number;
|
|
1278
1280
|
outcome: 'reached' | 'stalled';
|
|
@@ -2251,6 +2253,7 @@ declare function nativeFacts(input: {
|
|
|
2251
2253
|
* <dir>/pages/<screen>/facts.json optional: any of the page facts
|
|
2252
2254
|
* <dir>/pages/<screen>/window.xml optional: `adb exec-out uiautomator dump /dev/tty`
|
|
2253
2255
|
* <dir>/pages/<screen>/hierarchy.json optional: `maestro hierarchy`
|
|
2256
|
+
* <dir>/pages/<screen>/not-checked.txt optional: why the capture did not check it (kept, never scored)
|
|
2254
2257
|
*
|
|
2255
2258
|
* Steps: read and check every screen (a real PNG, at most 8 MB), POST
|
|
2256
2259
|
* /v1/ux/captures (one run, its scoring budget reserved), PUT each PNG to its
|
|
@@ -2263,13 +2266,20 @@ declare const UPLOAD_PLATFORMS: readonly ["ios", "android", "flutter", "react_na
|
|
|
2263
2266
|
type UploadPlatform = (typeof UPLOAD_PLATFORMS)[number];
|
|
2264
2267
|
declare const UPLOAD_SOURCES: readonly ["maestro", "adb", "simctl", "sdk", "playwright", "other"];
|
|
2265
2268
|
type UploadSource = (typeof UPLOAD_SOURCES)[number];
|
|
2266
|
-
/** The server's caps (POST /v1/ux/captures). */
|
|
2269
|
+
/** The server's caps (POST /v1/ux/captures): screens in one request. */
|
|
2267
2270
|
declare const UPLOAD_MAX_PAGES = 60;
|
|
2271
|
+
/**
|
|
2272
|
+
* Screens in one check, sent in requests of UPLOAD_MAX_PAGES (the server's
|
|
2273
|
+
* UX_CAPTURES_MAX_RUN_PAGES; the console sends the same parts, 2026-12-04).
|
|
2274
|
+
*/
|
|
2275
|
+
declare const UPLOAD_MAX_RUN_PAGES = 200;
|
|
2268
2276
|
declare const UPLOAD_MAX_PNG_BYTES: number;
|
|
2269
2277
|
interface CapturedScreen {
|
|
2270
2278
|
folder: string;
|
|
2271
2279
|
facts: UxPageFacts;
|
|
2272
2280
|
shots: Array<'early' | 'settled'>;
|
|
2281
|
+
/** Why this screen was not checked (its folder's not-checked.txt): its picture is kept, it is never scored. */
|
|
2282
|
+
notChecked?: string;
|
|
2273
2283
|
}
|
|
2274
2284
|
/** Read every screen under `<dir>/pages`; throws with a plain message on a screen that cannot be uploaded. */
|
|
2275
2285
|
declare function readScreens(dir: string, opts?: {
|
|
@@ -2293,6 +2303,13 @@ interface UploadOptions {
|
|
|
2293
2303
|
score?: boolean;
|
|
2294
2304
|
/** With score: file the top causes as reports. */
|
|
2295
2305
|
file?: boolean;
|
|
2306
|
+
/**
|
|
2307
|
+
* ADR 0112, a fix's branch capture: for each base/head pair of screens
|
|
2308
|
+
* (keys /__base__<path> and /__head__<path>) whose settled pictures differ,
|
|
2309
|
+
* ask the judge once more on both sides, so a drop never rests on one
|
|
2310
|
+
* judgment. An unchanged picture keeps its cached score and is not asked.
|
|
2311
|
+
*/
|
|
2312
|
+
confirmChanged?: boolean;
|
|
2296
2313
|
/** With file: show what would be filed. */
|
|
2297
2314
|
dryRun?: boolean;
|
|
2298
2315
|
/** Which build the screens show; a field given here wins over `<dir>/build.json`. */
|
|
@@ -2348,5 +2365,5 @@ interface Verdict {
|
|
|
2348
2365
|
}
|
|
2349
2366
|
declare function decide(input: VerdictInput): Verdict;
|
|
2350
2367
|
|
|
2351
|
-
export { AGENTS, CLIP_LIMITS, DEFAULT_CLIP_VIEWPORT, DEFAULT_JUDGE_MODEL, DEFAULT_SCORECARD_MODEL, DEFAULT_SCORECARD_VIEWPORT, DEFAULT_SETUP_COMMAND, FACTS_SCRIPT, POINTER_PROMPT, UPLOAD_MAX_PAGES, UPLOAD_MAX_PNG_BYTES, UPLOAD_PLATFORMS, UPLOAD_SOURCES, UX_DIMENSIONS, UX_RUBRIC, UX_SCORECARD_LIMITS, UX_SCORECARD_PROMPT_VERSION, UX_SCORE_ANCHORS, VIEWPORTS, accessibilityCap, anchoredDimensions, applyFacts, buildPacket, capFlows, captureFolder, capturePage, captureSurface, causeIsFileable, causeRank, causeReportBody, causeSlug, causeTokens, clampCaps, clipSlug, clipUploadBody, countedDimensions, cropTop, cursorCloudAdapter, cursorModel, dHash, decide, discover, effectiveClipCaps, evidenceSeenIn, fetchClipCaps, fileScorecard, findDesignFiles, firstJsonObject, getAgent, groupCauses, groupingPrompt, hammingHex, hasTimeForScreen, httpsRepoUrl, installGuard, isDestructiveLabel, isRequestAllowed, judgeSurface, loadState, localScorer, mergeGrouping, nativeFacts, newRunId, nextRoutePath, nodesToContent, normText, normalizeLink, openSession, overallScore, pageSystemPrompt, pageUserPrompt, parseFlow, parseMaestroHierarchy, parsePageAnswer, parseUiautomator, patternKeyFor, performanceCap, pixelDiff, planFiling, pngSize, probePenalty, quoteArg, rawScores, reactRouterPaths, readCaptures, readScreens, recordClips, rescorePage, routesFromSource, runDir, runFreshEyes, runProbes, runScorecard, runTerminalSetup, safeShotPath, sameCause, saveState, scorecardContext, scorecardMarkdown, scorecardMarker, scorecardPageKey, scorecardRows, scorecardRunId, screenPath, serverScorer, settle, sitemapPaths, startDashboard, startLoop, startSync, surfaceKey, syncConfigFromEnv, syncScorecard, toSnapshot, topCauses, typicalScore, unshuffle, uploadAllShots, uploadCaptures, uploadClips };
|
|
2368
|
+
export { AGENTS, CLIP_LIMITS, DEFAULT_CLIP_VIEWPORT, DEFAULT_JUDGE_MODEL, DEFAULT_SCORECARD_MODEL, DEFAULT_SCORECARD_VIEWPORT, DEFAULT_SETUP_COMMAND, FACTS_SCRIPT, POINTER_PROMPT, UPLOAD_MAX_PAGES, UPLOAD_MAX_PNG_BYTES, UPLOAD_MAX_RUN_PAGES, UPLOAD_PLATFORMS, UPLOAD_SOURCES, UX_DIMENSIONS, UX_RUBRIC, UX_SCORECARD_LIMITS, UX_SCORECARD_PROMPT_VERSION, UX_SCORE_ANCHORS, VIEWPORTS, accessibilityCap, anchoredDimensions, applyFacts, buildPacket, capFlows, captureFolder, capturePage, captureSurface, causeIsFileable, causeRank, causeReportBody, causeSlug, causeTokens, clampCaps, clipSlug, clipUploadBody, countedDimensions, cropTop, cursorCloudAdapter, cursorModel, dHash, decide, discover, effectiveClipCaps, evidenceSeenIn, fetchClipCaps, fileScorecard, findDesignFiles, firstJsonObject, getAgent, groupCauses, groupingPrompt, hammingHex, hasTimeForScreen, httpsRepoUrl, installGuard, isDestructiveLabel, isRequestAllowed, judgeSurface, loadState, localScorer, mergeGrouping, nativeFacts, newRunId, nextRoutePath, nodesToContent, normText, normalizeLink, openSession, overallScore, pageSystemPrompt, pageUserPrompt, parseFlow, parseMaestroHierarchy, parsePageAnswer, parseUiautomator, patternKeyFor, performanceCap, pixelDiff, planFiling, pngSize, probePenalty, quoteArg, rawScores, reactRouterPaths, readCaptures, readScreens, recordClips, rescorePage, routesFromSource, runDir, runFreshEyes, runProbes, runScorecard, runTerminalSetup, safeShotPath, sameCause, saveState, scorecardContext, scorecardMarkdown, scorecardMarker, scorecardPageKey, scorecardRows, scorecardRunId, screenPath, serverScorer, settle, sitemapPaths, startDashboard, startLoop, startSync, surfaceKey, syncConfigFromEnv, syncScorecard, toSnapshot, topCauses, typicalScore, unshuffle, uploadAllShots, uploadCaptures, uploadClips };
|
|
2352
2369
|
export type { AgentAdapter, AgentName, AgentRunOptions, AllowRule, AxeViolation, BrowserSession, Candidate, Capture, CapturedScreen, ClipFlow, ClipResult, ClipSkip, ClipUploadOutcome, CursorCloudDeps, Dashboard, DiscoverOptions, FreshAction, FreshAsk, FreshEyesFinding, FreshEyesOptions, FreshEyesPersona, FreshEyesResult, FreshEyesSession, FreshEyesStep, GuardPolicy, Identity, IterationRecord, JudgeClaim, JudgeOptions, JudgeVerdict, LayoutIssue, LoopEvent, LoopHandle, LoopOptions, NativeNode, Opinion, OpinionCategory, PacketInput, PageCapture, PageFacts, ParsedPageScore, Phase, PhaseName, ProbeResult, RecordClipsOptions, ReplayStep, RequirementKind, RunState, ScoreVia, ScorecardFileOutcome, ScorecardOptions, ScorecardPageResult, ScorecardResult, ScorecardRow, ScoredPage, Scorer, ServerClipCaps, StallReason, StepOutcome, SuccessCheck, Surface, SurfaceKind, SurfaceState, SurfaceStatus, SyncConfig, SyncHandle, TerminalHandoff, TerminalOptions, TerminalResult, UploadOptions, UploadPlatform, UploadResult, UploadSource, UxCause, UxCausePage, UxClaim, UxDimension, UxFilingPlan, UxIssue, UxPageFacts, UxPagePromptContext, UxPageScore, UxSeverity, Verdict, VerdictInput, Viewport, WriteMode };
|
package/dist/index.js
CHANGED
|
@@ -779,7 +779,7 @@ async function openSession(opts = {}) {
|
|
|
779
779
|
};
|
|
780
780
|
} else {
|
|
781
781
|
browser = await chromium.launch({ headless, ...channel });
|
|
782
|
-
context = await browser.newContext({ serviceWorkers: "block" });
|
|
782
|
+
context = await browser.newContext({ serviceWorkers: "block", ...opts.storageState ? { storageState: opts.storageState } : {} });
|
|
783
783
|
closeBrowser = () => browser.close();
|
|
784
784
|
}
|
|
785
785
|
const guard = await installGuard(context, opts.allow ?? [], { blocked: [] }, opts.policy);
|
|
@@ -3415,20 +3415,56 @@ function hasData(body) {
|
|
|
3415
3415
|
}
|
|
3416
3416
|
return true;
|
|
3417
3417
|
}
|
|
3418
|
-
|
|
3419
|
-
if (!hasSuccessCheck(c)) return
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3418
|
+
function goalVerdict(c, now, start2) {
|
|
3419
|
+
if (!hasSuccessCheck(c)) return { verdict: "no" };
|
|
3420
|
+
const proofs = [];
|
|
3421
|
+
const weak = [];
|
|
3422
|
+
let strong = false;
|
|
3423
|
+
if (c.url) {
|
|
3424
|
+
if (!urlMatches(c.url, now.url)) return { verdict: "no" };
|
|
3425
|
+
strong = true;
|
|
3426
|
+
proofs.push(`the address ${pathOf(now.url)} matched ${c.url}`);
|
|
3427
|
+
}
|
|
3428
|
+
if (c.api) {
|
|
3429
|
+
if (!now.apiHasData) return { verdict: "no" };
|
|
3430
|
+
strong = true;
|
|
3431
|
+
proofs.push(`${c.api} answered with data`);
|
|
3424
3432
|
}
|
|
3425
|
-
if (c.
|
|
3433
|
+
if (c.text) {
|
|
3434
|
+
const re = new RegExp(c.text, "i");
|
|
3435
|
+
const hit = re.exec(now.bodyText);
|
|
3436
|
+
if (!hit) return { verdict: "no" };
|
|
3437
|
+
if (re.test(start2.bodyText)) weak.push(`"${hit[0]}" was already on the start page`);
|
|
3438
|
+
else if (!re.test(now.mainText)) weak.push(`"${hit[0]}" showed only outside the page's main content (a menu, header or footer)`);
|
|
3439
|
+
else proofs.push(`"${hit[0]}" appeared in the page's main content`);
|
|
3440
|
+
}
|
|
3441
|
+
if (c.selector) {
|
|
3442
|
+
if (!now.selectorVisible) return { verdict: "no" };
|
|
3443
|
+
if (start2.selectorVisible) weak.push(`${c.selector} was already on the start page`);
|
|
3444
|
+
else proofs.push(`${c.selector} appeared`);
|
|
3445
|
+
}
|
|
3446
|
+
if (weak.length && !strong) return { verdict: "weak", detail: weak.join("; ").slice(0, 240) };
|
|
3447
|
+
return { verdict: "pass", detail: [...proofs, ...weak].join("; ").slice(0, 240) };
|
|
3448
|
+
}
|
|
3449
|
+
async function goalSeen(page, c) {
|
|
3450
|
+
const texts = await page.evaluate(() => {
|
|
3451
|
+
const body = document.body;
|
|
3452
|
+
const main = document.querySelector('main, [role="main"]');
|
|
3453
|
+
let mainText = main?.innerText ?? "";
|
|
3454
|
+
if (!main && body) {
|
|
3455
|
+
const copy = body.cloneNode(true);
|
|
3456
|
+
for (const el of copy.querySelectorAll('header, nav, aside, footer, [role="navigation"], [role="banner"], [role="contentinfo"]')) el.remove();
|
|
3457
|
+
mainText = copy.textContent ?? "";
|
|
3458
|
+
}
|
|
3459
|
+
return { mainText, bodyText: body?.innerText ?? "" };
|
|
3460
|
+
}).catch(() => ({ mainText: "", bodyText: "" }));
|
|
3461
|
+
const selectorVisible = c.selector ? await page.locator(c.selector).first().isVisible({ timeout: 1e3 }).catch(() => false) : void 0;
|
|
3462
|
+
let apiHasData;
|
|
3426
3463
|
if (c.api) {
|
|
3427
3464
|
const res = await page.context().request.get(c.api, { timeout: 15e3 }).catch(() => null);
|
|
3428
|
-
|
|
3429
|
-
if (!hasData(await res.json().catch(() => null))) return false;
|
|
3465
|
+
apiHasData = !!res && res.ok() && hasData(await res.json().catch(() => null));
|
|
3430
3466
|
}
|
|
3431
|
-
return
|
|
3467
|
+
return { url: page.url(), mainText: texts.mainText, bodyText: texts.bodyText, selectorVisible, apiHasData };
|
|
3432
3468
|
}
|
|
3433
3469
|
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
3434
3470
|
function extractSetupValues(text) {
|
|
@@ -3910,6 +3946,23 @@ async function runSession(x) {
|
|
|
3910
3946
|
if (firstSignals.length) landing.signals = firstSignals.map((s) => s.kind);
|
|
3911
3947
|
for (const s of firstSignals) x.addCandidate({ kind: "signal", signal: s, screen: pagePath(new URL(s.url).pathname), steps: [], session: index });
|
|
3912
3948
|
await record(landing);
|
|
3949
|
+
const startSeen = hasSuccessCheck(opts.success) ? await goalSeen(page, opts.success) : { url: "", mainText: "", bodyText: "" };
|
|
3950
|
+
let weakGoal = null;
|
|
3951
|
+
const reachedWith = (detail) => {
|
|
3952
|
+
session.outcome = "reached";
|
|
3953
|
+
const last = session.steps[session.steps.length - 1];
|
|
3954
|
+
if (last) last.note = `${last.note ? `${last.note} \xB7 ` : ""}Goal check passed: ${detail}`.slice(0, 300);
|
|
3955
|
+
};
|
|
3956
|
+
const checkGoal = async () => {
|
|
3957
|
+
if (!hasSuccessCheck(opts.success)) return false;
|
|
3958
|
+
const g = goalVerdict(opts.success, await goalSeen(page, opts.success), startSeen);
|
|
3959
|
+
if (g.verdict === "pass") {
|
|
3960
|
+
reachedWith(g.detail);
|
|
3961
|
+
return true;
|
|
3962
|
+
}
|
|
3963
|
+
if (g.verdict === "weak") weakGoal = g.detail;
|
|
3964
|
+
return false;
|
|
3965
|
+
};
|
|
3913
3966
|
for (let n = 1; n <= x.maxSteps; n++) {
|
|
3914
3967
|
while (page.isClosed() && windows.length) {
|
|
3915
3968
|
page = windows.pop();
|
|
@@ -3924,10 +3977,7 @@ async function runSession(x) {
|
|
|
3924
3977
|
x.addCandidate({ kind: "captcha", screen, detail: "A captcha appeared on this screen.", steps: [...actions], session: index });
|
|
3925
3978
|
break;
|
|
3926
3979
|
}
|
|
3927
|
-
if (await
|
|
3928
|
-
session.outcome = "reached";
|
|
3929
|
-
break;
|
|
3930
|
-
}
|
|
3980
|
+
if (await checkGoal()) break;
|
|
3931
3981
|
const snapshot = redact(await screenForModel(page), identity);
|
|
3932
3982
|
const tAsk = performance.now();
|
|
3933
3983
|
const answer = await x.ask(
|
|
@@ -3971,7 +4021,8 @@ async function runSession(x) {
|
|
|
3971
4021
|
doneClaims++;
|
|
3972
4022
|
say(` step ${n}: the visitor thinks the goal is reached; the goal check says no`);
|
|
3973
4023
|
if (doneClaims >= 2) {
|
|
3974
|
-
stall(n, "
|
|
4024
|
+
if (weakGoal) stall(n, "unverified", `The goal check matched, but proves nothing about this visit: ${weakGoal}.`);
|
|
4025
|
+
else stall(n, "model_gave_up", "The visitor believed the goal was reached, but the goal check did not pass.");
|
|
3975
4026
|
session.opinions.push({ category: "confusing", why: "I thought I was done here.", screen, step: n, mainChars: facts.mainChars });
|
|
3976
4027
|
break;
|
|
3977
4028
|
}
|
|
@@ -4104,8 +4155,9 @@ async function runSession(x) {
|
|
|
4104
4155
|
}
|
|
4105
4156
|
}
|
|
4106
4157
|
if (session.outcome !== "reached" && !session.stall) {
|
|
4107
|
-
|
|
4108
|
-
|
|
4158
|
+
const reached = await checkGoal().catch(() => false);
|
|
4159
|
+
if (!reached && weakGoal) stall(session.steps.length, "unverified", `The goal check matched, but proves nothing about this visit: ${weakGoal}.`);
|
|
4160
|
+
else if (!reached) stall(session.steps.length, "out_of_steps", `The goal was not reached in ${x.maxSteps} steps.`);
|
|
4109
4161
|
}
|
|
4110
4162
|
} finally {
|
|
4111
4163
|
await ctx.close().catch(() => {
|
|
@@ -6982,7 +7034,35 @@ function sizeAndHead(file) {
|
|
|
6982
7034
|
var UPLOAD_PLATFORMS = ["ios", "android", "flutter", "react_native", "capacitor", "web", "other"];
|
|
6983
7035
|
var UPLOAD_SOURCES = ["maestro", "adb", "simctl", "sdk", "playwright", "other"];
|
|
6984
7036
|
var UPLOAD_MAX_PAGES = 60;
|
|
7037
|
+
var UPLOAD_MAX_RUN_PAGES = 200;
|
|
6985
7038
|
var UPLOAD_MAX_PNG_BYTES = 8 * 1024 * 1024;
|
|
7039
|
+
var NOT_CHECKED_FILE = "not-checked.txt";
|
|
7040
|
+
var NOT_CHECKED_NOTE = "Not checked: ";
|
|
7041
|
+
function notCheckedReason(raw) {
|
|
7042
|
+
const line = raw.replace(new RegExp("\\p{Cc}+", "gu"), " ").replace(/\s+/g, " ").trim().slice(0, 300);
|
|
7043
|
+
return line || null;
|
|
7044
|
+
}
|
|
7045
|
+
function changedPairKeys(screens) {
|
|
7046
|
+
const side = (k) => /^\/__(base|head)__(\/.*)?$/.exec(k);
|
|
7047
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
7048
|
+
for (const s of screens) {
|
|
7049
|
+
const m = side(s.key);
|
|
7050
|
+
if (!m) continue;
|
|
7051
|
+
const p = m[2] || "/";
|
|
7052
|
+
const e = byPath.get(p) ?? {};
|
|
7053
|
+
e[m[1]] = s;
|
|
7054
|
+
byPath.set(p, e);
|
|
7055
|
+
}
|
|
7056
|
+
const out = /* @__PURE__ */ new Set();
|
|
7057
|
+
for (const e of byPath.values()) {
|
|
7058
|
+
if (!e.base || !e.head) continue;
|
|
7059
|
+
if (!e.base.hash || !e.head.hash || e.base.hash !== e.head.hash) {
|
|
7060
|
+
out.add(e.base.key);
|
|
7061
|
+
out.add(e.head.key);
|
|
7062
|
+
}
|
|
7063
|
+
}
|
|
7064
|
+
return screens.map((s) => s.key).filter((k) => out.has(k));
|
|
7065
|
+
}
|
|
6986
7066
|
function readScreens(dir, opts = {}) {
|
|
6987
7067
|
const root = join20(dir, "pages");
|
|
6988
7068
|
if (!existsSync12(root)) throw new Error(`No ${root} folder. Put each screen in <dir>/pages/<screen>/settled.png (see docs/templates/ux-native/).`);
|
|
@@ -7015,7 +7095,8 @@ function readScreens(dir, opts = {}) {
|
|
|
7015
7095
|
if (existsSync12(join20(folder, "window.xml"))) nodes = parseUiautomator(readFileSync16(join20(folder, "window.xml"), "utf8"));
|
|
7016
7096
|
else if (existsSync12(join20(folder, "hierarchy.json"))) nodes = parseMaestroHierarchy(readFileSync16(join20(folder, "hierarchy.json"), "utf8"));
|
|
7017
7097
|
const facts = nativeFacts({ folder: name, given, nodes, png: settledSize, scale: opts.scale });
|
|
7018
|
-
|
|
7098
|
+
const notChecked = existsSync12(join20(folder, NOT_CHECKED_FILE)) ? notCheckedReason(readFileSync16(join20(folder, NOT_CHECKED_FILE), "utf8")) : null;
|
|
7099
|
+
out.push({ folder, facts: { ...facts, key: scorecardPageKey(facts.key) }, shots: [...shots], ...notChecked ? { notChecked } : {} });
|
|
7019
7100
|
nameKeys.push(scorecardPageKey(typeof given?.key === "string" && given.key ? given.key : screenPath(name)));
|
|
7020
7101
|
}
|
|
7021
7102
|
const byPath = /* @__PURE__ */ new Map();
|
|
@@ -7024,7 +7105,7 @@ function readScreens(dir, opts = {}) {
|
|
|
7024
7105
|
if ((byPath.get(s.facts.key) ?? 0) > 1) s.facts = { ...s.facts, key: nameKeys[i] };
|
|
7025
7106
|
});
|
|
7026
7107
|
if (!out.length) throw new Error(`No screenshots in ${root}: each screen needs a settled.png (or early.png).`);
|
|
7027
|
-
if (out.length >
|
|
7108
|
+
if (out.length > UPLOAD_MAX_RUN_PAGES) throw new Error(`${out.length} screens; one check takes at most ${UPLOAD_MAX_RUN_PAGES}. Split the folder.`);
|
|
7028
7109
|
const keys = /* @__PURE__ */ new Set();
|
|
7029
7110
|
for (const s of out) {
|
|
7030
7111
|
if (keys.has(s.facts.key)) throw new Error(`Two screens have the key "${s.facts.key}". Give each its own name or facts.json key.`);
|
|
@@ -7050,6 +7131,11 @@ async function pool2(items, n, fn) {
|
|
|
7050
7131
|
};
|
|
7051
7132
|
await Promise.all(Array.from({ length: Math.max(1, Math.min(n, items.length)) }, worker));
|
|
7052
7133
|
}
|
|
7134
|
+
function uploadParts(screens, size = UPLOAD_MAX_PAGES) {
|
|
7135
|
+
const out = [];
|
|
7136
|
+
for (let i = 0; i < screens.length; i += size) out.push(screens.slice(i, i + size));
|
|
7137
|
+
return out;
|
|
7138
|
+
}
|
|
7053
7139
|
async function uploadCaptures(cfg, opts) {
|
|
7054
7140
|
const progress = opts.onProgress ?? (() => {
|
|
7055
7141
|
});
|
|
@@ -7058,28 +7144,38 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7058
7144
|
const build = readBuild(opts.dir, opts.build, opts.ciCommit);
|
|
7059
7145
|
progress(`${screens.length} screen(s) to upload (${opts.platform}${opts.device ? `, ${opts.device}` : ""}${build.appVersion ? `, version ${build.appVersion}` : ", version not recorded"})`);
|
|
7060
7146
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7061
|
-
const
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7147
|
+
const parts = uploadParts(screens);
|
|
7148
|
+
let runId = "";
|
|
7149
|
+
const d = { reservedUsd: null, uploads: [] };
|
|
7150
|
+
for (const [i, part] of parts.entries()) {
|
|
7151
|
+
const sent = await api2(
|
|
7152
|
+
cfg,
|
|
7153
|
+
"/v1/ux/captures",
|
|
7154
|
+
{
|
|
7155
|
+
method: "POST",
|
|
7156
|
+
body: JSON.stringify({
|
|
7157
|
+
...i > 0 ? { runId } : {},
|
|
7158
|
+
platform: opts.platform,
|
|
7159
|
+
...opts.device ? { device: opts.device } : {},
|
|
7160
|
+
...opts.source ? { source: opts.source } : {},
|
|
7161
|
+
...opts.app ? { app: opts.app } : {},
|
|
7162
|
+
...opts.viewport ? { viewport: opts.viewport } : {},
|
|
7163
|
+
...opts.maxCostUsd !== void 0 ? { maxCostUsd: opts.maxCostUsd } : {},
|
|
7164
|
+
...i === 0 && parts.length > 1 ? { totalPages: screens.length } : {},
|
|
7165
|
+
...build,
|
|
7166
|
+
pages: part.map((s) => ({ facts: s.facts, shots: s.shots }))
|
|
7167
|
+
})
|
|
7168
|
+
},
|
|
7169
|
+
doFetch
|
|
7170
|
+
);
|
|
7171
|
+
const where = parts.length > 1 ? ` (part ${i + 1} of ${parts.length}${runId ? `, run ${runId}` : ""})` : "";
|
|
7172
|
+
if (!sent.ok) throw new Error(`The captures were not accepted${where}: ${apiError2(sent)}`);
|
|
7173
|
+
const got = sent.body?.data;
|
|
7174
|
+
if (!got?.runId) throw new Error(`The API returned no run id${where}.`);
|
|
7175
|
+
runId = got.runId;
|
|
7176
|
+
if (i === 0) d.reservedUsd = got.reservedUsd ?? null;
|
|
7177
|
+
d.uploads.push(...got.uploads ?? []);
|
|
7178
|
+
}
|
|
7083
7179
|
const byKey = new Map(screens.map((s) => [s.facts.key, s]));
|
|
7084
7180
|
const shotNames = /* @__PURE__ */ new Map();
|
|
7085
7181
|
let uploaded = 0;
|
|
@@ -7098,8 +7194,10 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7098
7194
|
const result = { runId, pages: screens.length, uploaded, reservedUsd: d.reservedUsd ?? null, scored: 0, mean: null, typical: null, causes: [], errors: [], consoleUrl };
|
|
7099
7195
|
if (!opts.score) return result;
|
|
7100
7196
|
const scores = /* @__PURE__ */ new Map();
|
|
7101
|
-
const
|
|
7102
|
-
|
|
7197
|
+
const toScore = screens.filter((s) => !s.notChecked);
|
|
7198
|
+
if (toScore.length < screens.length) progress(`${screens.length - toScore.length} screen(s) not checked: kept with their picture, not scored`);
|
|
7199
|
+
const labels = toScore.map((s) => s.facts.label);
|
|
7200
|
+
await pool2(toScore, opts.concurrency ?? 3, async (s) => {
|
|
7103
7201
|
const shotHash = settledShotHash(s.folder);
|
|
7104
7202
|
const ask = () => api2(
|
|
7105
7203
|
cfg,
|
|
@@ -7121,6 +7219,19 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7121
7219
|
progress(`could not score ${s.facts.key}: ${apiError2(r)}`);
|
|
7122
7220
|
}
|
|
7123
7221
|
});
|
|
7222
|
+
if (opts.confirmChanged) {
|
|
7223
|
+
const confirm = changedPairKeys(screens.map((s) => ({ key: s.facts.key, hash: settledShotHash(s.folder) })));
|
|
7224
|
+
await pool2(screens.filter((s) => confirm.includes(s.facts.key)), opts.concurrency ?? 3, async (s) => {
|
|
7225
|
+
const r = await api2(
|
|
7226
|
+
cfg,
|
|
7227
|
+
`/v1/admin/projects/${cfg.projectId}/ux-scorecard/${runId}/score`,
|
|
7228
|
+
{ method: "POST", body: JSON.stringify({ facts: s.facts, shots: shotNames.get(s.facts.key) ?? [], app: opts.app ?? "this app", about: opts.about, other_pages: labels.filter((l) => l !== s.facts.label), confirm: true }) },
|
|
7229
|
+
doFetch
|
|
7230
|
+
);
|
|
7231
|
+
if (r.ok) progress(`second look at ${s.facts.key}: ${r.body?.data?.score?.overall ?? "?"}/10`);
|
|
7232
|
+
else result.errors.push(`${s.facts.key} (second look): ${apiError2(r)}`);
|
|
7233
|
+
});
|
|
7234
|
+
}
|
|
7124
7235
|
result.scored = scores.size;
|
|
7125
7236
|
result.mean = scores.size ? Math.round([...scores.values()].reduce((n, x) => n + x.overall, 0) / scores.size * 10) / 10 : null;
|
|
7126
7237
|
result.typical = typicalScore([...scores.values()].map((x) => x.overall));
|
|
@@ -7140,7 +7251,8 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7140
7251
|
started_at: startedAt,
|
|
7141
7252
|
finished_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7142
7253
|
error: null,
|
|
7143
|
-
|
|
7254
|
+
// A check sent in parts closes from the pages the server holds; one part sends them, as before.
|
|
7255
|
+
...parts.length > 1 ? { pages: [], fromSaved: true } : { pages: screens.map((s) => ({ facts: s.facts, score: scores.get(s.facts.key) ?? null, shots: shotNames.get(s.facts.key) ?? [], ...scores.has(s.facts.key) ? {} : { error: s.notChecked ? `${NOT_CHECKED_NOTE}${s.notChecked}` : "Not scored." } })) },
|
|
7144
7256
|
causes: result.causes
|
|
7145
7257
|
})
|
|
7146
7258
|
},
|
|
@@ -7162,6 +7274,7 @@ export {
|
|
|
7162
7274
|
POINTER_PROMPT,
|
|
7163
7275
|
UPLOAD_MAX_PAGES,
|
|
7164
7276
|
UPLOAD_MAX_PNG_BYTES,
|
|
7277
|
+
UPLOAD_MAX_RUN_PAGES,
|
|
7165
7278
|
UPLOAD_PLATFORMS,
|
|
7166
7279
|
UPLOAD_SOURCES,
|
|
7167
7280
|
UX_DIMENSIONS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mushi-mushi/ux",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The bug button for apps built with AI. Local visual UX loop: maps a running app's pages, tabs and dialogs, runs your coding agent on each one against screenshot baselines, and shows before/after diffs, regressions and a pairwise judge.",
|
|
6
6
|
"type": "module",
|