@mushi-mushi/ux 0.6.0 → 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/dist/cli.js +49 -5
- package/dist/index.d.ts +10 -0
- package/dist/index.js +47 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7121,6 +7121,33 @@ var UPLOAD_SOURCES = ["maestro", "adb", "simctl", "sdk", "playwright", "other"];
|
|
|
7121
7121
|
var UPLOAD_MAX_PAGES = 60;
|
|
7122
7122
|
var UPLOAD_MAX_RUN_PAGES = 200;
|
|
7123
7123
|
var UPLOAD_MAX_PNG_BYTES = 8 * 1024 * 1024;
|
|
7124
|
+
var NOT_CHECKED_FILE = "not-checked.txt";
|
|
7125
|
+
var NOT_CHECKED_NOTE = "Not checked: ";
|
|
7126
|
+
function notCheckedReason(raw) {
|
|
7127
|
+
const line = raw.replace(new RegExp("\\p{Cc}+", "gu"), " ").replace(/\s+/g, " ").trim().slice(0, 300);
|
|
7128
|
+
return line || null;
|
|
7129
|
+
}
|
|
7130
|
+
function changedPairKeys(screens) {
|
|
7131
|
+
const side2 = (k) => /^\/__(base|head)__(\/.*)?$/.exec(k);
|
|
7132
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
7133
|
+
for (const s of screens) {
|
|
7134
|
+
const m = side2(s.key);
|
|
7135
|
+
if (!m) continue;
|
|
7136
|
+
const p = m[2] || "/";
|
|
7137
|
+
const e = byPath.get(p) ?? {};
|
|
7138
|
+
e[m[1]] = s;
|
|
7139
|
+
byPath.set(p, e);
|
|
7140
|
+
}
|
|
7141
|
+
const out = /* @__PURE__ */ new Set();
|
|
7142
|
+
for (const e of byPath.values()) {
|
|
7143
|
+
if (!e.base || !e.head) continue;
|
|
7144
|
+
if (!e.base.hash || !e.head.hash || e.base.hash !== e.head.hash) {
|
|
7145
|
+
out.add(e.base.key);
|
|
7146
|
+
out.add(e.head.key);
|
|
7147
|
+
}
|
|
7148
|
+
}
|
|
7149
|
+
return screens.map((s) => s.key).filter((k) => out.has(k));
|
|
7150
|
+
}
|
|
7124
7151
|
function readScreens(dir, opts = {}) {
|
|
7125
7152
|
const root = join19(dir, "pages");
|
|
7126
7153
|
if (!existsSync10(root)) throw new Error(`No ${root} folder. Put each screen in <dir>/pages/<screen>/settled.png (see docs/templates/ux-native/).`);
|
|
@@ -7153,7 +7180,8 @@ function readScreens(dir, opts = {}) {
|
|
|
7153
7180
|
if (existsSync10(join19(folder, "window.xml"))) nodes = parseUiautomator(readFileSync15(join19(folder, "window.xml"), "utf8"));
|
|
7154
7181
|
else if (existsSync10(join19(folder, "hierarchy.json"))) nodes = parseMaestroHierarchy(readFileSync15(join19(folder, "hierarchy.json"), "utf8"));
|
|
7155
7182
|
const facts = nativeFacts({ folder: name, given, nodes, png: settledSize, scale: opts.scale });
|
|
7156
|
-
|
|
7183
|
+
const notChecked = existsSync10(join19(folder, NOT_CHECKED_FILE)) ? notCheckedReason(readFileSync15(join19(folder, NOT_CHECKED_FILE), "utf8")) : null;
|
|
7184
|
+
out.push({ folder, facts: { ...facts, key: scorecardPageKey(facts.key) }, shots: [...shots], ...notChecked ? { notChecked } : {} });
|
|
7157
7185
|
nameKeys.push(scorecardPageKey(typeof given?.key === "string" && given.key ? given.key : screenPath(name)));
|
|
7158
7186
|
}
|
|
7159
7187
|
const byPath = /* @__PURE__ */ new Map();
|
|
@@ -7251,8 +7279,10 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7251
7279
|
const result = { runId, pages: screens.length, uploaded, reservedUsd: d.reservedUsd ?? null, scored: 0, mean: null, typical: null, causes: [], errors: [], consoleUrl };
|
|
7252
7280
|
if (!opts.score) return result;
|
|
7253
7281
|
const scores = /* @__PURE__ */ new Map();
|
|
7254
|
-
const
|
|
7255
|
-
|
|
7282
|
+
const toScore = screens.filter((s) => !s.notChecked);
|
|
7283
|
+
if (toScore.length < screens.length) progress(`${screens.length - toScore.length} screen(s) not checked: kept with their picture, not scored`);
|
|
7284
|
+
const labels = toScore.map((s) => s.facts.label);
|
|
7285
|
+
await pool2(toScore, opts.concurrency ?? 3, async (s) => {
|
|
7256
7286
|
const shotHash = settledShotHash(s.folder);
|
|
7257
7287
|
const ask = () => api3(
|
|
7258
7288
|
cfg,
|
|
@@ -7274,6 +7304,19 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7274
7304
|
progress(`could not score ${s.facts.key}: ${apiError2(r)}`);
|
|
7275
7305
|
}
|
|
7276
7306
|
});
|
|
7307
|
+
if (opts.confirmChanged) {
|
|
7308
|
+
const confirm = changedPairKeys(screens.map((s) => ({ key: s.facts.key, hash: settledShotHash(s.folder) })));
|
|
7309
|
+
await pool2(screens.filter((s) => confirm.includes(s.facts.key)), opts.concurrency ?? 3, async (s) => {
|
|
7310
|
+
const r = await api3(
|
|
7311
|
+
cfg,
|
|
7312
|
+
`/v1/admin/projects/${cfg.projectId}/ux-scorecard/${runId}/score`,
|
|
7313
|
+
{ 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 }) },
|
|
7314
|
+
doFetch
|
|
7315
|
+
);
|
|
7316
|
+
if (r.ok) progress(`second look at ${s.facts.key}: ${r.body?.data?.score?.overall ?? "?"}/10`);
|
|
7317
|
+
else result.errors.push(`${s.facts.key} (second look): ${apiError2(r)}`);
|
|
7318
|
+
});
|
|
7319
|
+
}
|
|
7277
7320
|
result.scored = scores.size;
|
|
7278
7321
|
result.mean = scores.size ? Math.round([...scores.values()].reduce((n, x) => n + x.overall, 0) / scores.size * 10) / 10 : null;
|
|
7279
7322
|
result.typical = typicalScore([...scores.values()].map((x) => x.overall));
|
|
@@ -7294,7 +7337,7 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7294
7337
|
finished_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7295
7338
|
error: null,
|
|
7296
7339
|
// A check sent in parts closes from the pages the server holds; one part sends them, as before.
|
|
7297
|
-
...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: "Not scored." } })) },
|
|
7340
|
+
...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." } })) },
|
|
7298
7341
|
causes: result.causes
|
|
7299
7342
|
})
|
|
7300
7343
|
},
|
|
@@ -9272,7 +9315,7 @@ ${result.clips.length} clip(s) in ${o.out}`);
|
|
|
9272
9315
|
console.log(`${up.uploaded.length} clip(s) in the release kit: ${consoleBaseUrl()}/releases`);
|
|
9273
9316
|
}
|
|
9274
9317
|
);
|
|
9275
|
-
program.command("upload <dir>").description("Score screenshots any driver made (Maestro, adb, the iOS simulator, an SDK debug build) on the UX scorecard: <dir>/pages/<screen>/settled.png, plus facts.json, window.xml or hierarchy.json (ADR 0073).").addOption(new Option("--platform <name>", "What the screens are from").choices([...UPLOAD_PLATFORMS]).makeOptionMandatory()).option("--device <name>", 'The device or simulator, e.g. "Pixel 8 (API 35)"').addOption(new Option("--source <driver>", "The driver that captured them").choices([...UPLOAD_SOURCES])).option("--app <name>", "What to call the app in the prompts and the run").option("--about <text>", "One line on what the app is and who uses it").option("--scale <n>", "Pixels per point of the device (e.g. 3 for most phones), so the viewport is in points; default 1 (pixels)").option("--viewport <WxH>", "The run viewport (default: the first screen)").option("--max-cost <usd>", "The most this run may spend on server scoring").option("--no-score", "Only upload; score later").option("--file", "File the top root causes as reports (one per cause, at most 5 a run)").option("--dry-run", "With --file: show what would be filed, file nothing").option("--app-version <v>", "The app version the screens show, e.g. 1.4.0 (default: <dir>/build.json)").option("--build <n>", "Its build number or Android versionCode (default: <dir>/build.json)").option("--ota <id>", "The over-the-air update the app ran, if any (default: <dir>/build.json)").option("--commit <sha>", "The commit the build came from (default: <dir>/build.json, else GITHUB_SHA)").action(
|
|
9318
|
+
program.command("upload <dir>").description("Score screenshots any driver made (Maestro, adb, the iOS simulator, an SDK debug build) on the UX scorecard: <dir>/pages/<screen>/settled.png, plus facts.json, window.xml or hierarchy.json (ADR 0073).").addOption(new Option("--platform <name>", "What the screens are from").choices([...UPLOAD_PLATFORMS]).makeOptionMandatory()).option("--device <name>", 'The device or simulator, e.g. "Pixel 8 (API 35)"').addOption(new Option("--source <driver>", "The driver that captured them").choices([...UPLOAD_SOURCES])).option("--app <name>", "What to call the app in the prompts and the run").option("--about <text>", "One line on what the app is and who uses it").option("--scale <n>", "Pixels per point of the device (e.g. 3 for most phones), so the viewport is in points; default 1 (pixels)").option("--viewport <WxH>", "The run viewport (default: the first screen)").option("--max-cost <usd>", "The most this run may spend on server scoring").option("--no-score", "Only upload; score later").option("--confirm-changed", "A fix's branch capture: judge each changed base/head pair twice (ADR 0112)").option("--file", "File the top root causes as reports (one per cause, at most 5 a run)").option("--dry-run", "With --file: show what would be filed, file nothing").option("--app-version <v>", "The app version the screens show, e.g. 1.4.0 (default: <dir>/build.json)").option("--build <n>", "Its build number or Android versionCode (default: <dir>/build.json)").option("--ota <id>", "The over-the-air update the app ran, if any (default: <dir>/build.json)").option("--commit <sha>", "The commit the build came from (default: <dir>/build.json, else GITHUB_SHA)").action(
|
|
9276
9319
|
async (dir, o) => {
|
|
9277
9320
|
const cfg = syncConfigFromEnv();
|
|
9278
9321
|
for (const k of ["MUSHI_API_KEY", "MUSHI_PROJECT_ID", "MUSHI_API_ENDPOINT"]) delete process.env[k];
|
|
@@ -9294,6 +9337,7 @@ program.command("upload <dir>").description("Score screenshots any driver made (
|
|
|
9294
9337
|
viewport: o.viewport,
|
|
9295
9338
|
maxCostUsd: num(o.maxCost, "--max-cost"),
|
|
9296
9339
|
score: o.score,
|
|
9340
|
+
confirmChanged: o.confirmChanged === true,
|
|
9297
9341
|
file: o.file,
|
|
9298
9342
|
dryRun: o.dryRun,
|
|
9299
9343
|
build: { appVersion: o.appVersion, buildNumber: o.build, otaId: o.ota, commitSha: o.commit },
|
package/dist/index.d.ts
CHANGED
|
@@ -2253,6 +2253,7 @@ declare function nativeFacts(input: {
|
|
|
2253
2253
|
* <dir>/pages/<screen>/facts.json optional: any of the page facts
|
|
2254
2254
|
* <dir>/pages/<screen>/window.xml optional: `adb exec-out uiautomator dump /dev/tty`
|
|
2255
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)
|
|
2256
2257
|
*
|
|
2257
2258
|
* Steps: read and check every screen (a real PNG, at most 8 MB), POST
|
|
2258
2259
|
* /v1/ux/captures (one run, its scoring budget reserved), PUT each PNG to its
|
|
@@ -2277,6 +2278,8 @@ interface CapturedScreen {
|
|
|
2277
2278
|
folder: string;
|
|
2278
2279
|
facts: UxPageFacts;
|
|
2279
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;
|
|
2280
2283
|
}
|
|
2281
2284
|
/** Read every screen under `<dir>/pages`; throws with a plain message on a screen that cannot be uploaded. */
|
|
2282
2285
|
declare function readScreens(dir: string, opts?: {
|
|
@@ -2300,6 +2303,13 @@ interface UploadOptions {
|
|
|
2300
2303
|
score?: boolean;
|
|
2301
2304
|
/** With score: file the top causes as reports. */
|
|
2302
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;
|
|
2303
2313
|
/** With file: show what would be filed. */
|
|
2304
2314
|
dryRun?: boolean;
|
|
2305
2315
|
/** Which build the screens show; a field given here wins over `<dir>/build.json`. */
|
package/dist/index.js
CHANGED
|
@@ -7036,6 +7036,33 @@ var UPLOAD_SOURCES = ["maestro", "adb", "simctl", "sdk", "playwright", "other"];
|
|
|
7036
7036
|
var UPLOAD_MAX_PAGES = 60;
|
|
7037
7037
|
var UPLOAD_MAX_RUN_PAGES = 200;
|
|
7038
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
|
+
}
|
|
7039
7066
|
function readScreens(dir, opts = {}) {
|
|
7040
7067
|
const root = join20(dir, "pages");
|
|
7041
7068
|
if (!existsSync12(root)) throw new Error(`No ${root} folder. Put each screen in <dir>/pages/<screen>/settled.png (see docs/templates/ux-native/).`);
|
|
@@ -7068,7 +7095,8 @@ function readScreens(dir, opts = {}) {
|
|
|
7068
7095
|
if (existsSync12(join20(folder, "window.xml"))) nodes = parseUiautomator(readFileSync16(join20(folder, "window.xml"), "utf8"));
|
|
7069
7096
|
else if (existsSync12(join20(folder, "hierarchy.json"))) nodes = parseMaestroHierarchy(readFileSync16(join20(folder, "hierarchy.json"), "utf8"));
|
|
7070
7097
|
const facts = nativeFacts({ folder: name, given, nodes, png: settledSize, scale: opts.scale });
|
|
7071
|
-
|
|
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 } : {} });
|
|
7072
7100
|
nameKeys.push(scorecardPageKey(typeof given?.key === "string" && given.key ? given.key : screenPath(name)));
|
|
7073
7101
|
}
|
|
7074
7102
|
const byPath = /* @__PURE__ */ new Map();
|
|
@@ -7166,8 +7194,10 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7166
7194
|
const result = { runId, pages: screens.length, uploaded, reservedUsd: d.reservedUsd ?? null, scored: 0, mean: null, typical: null, causes: [], errors: [], consoleUrl };
|
|
7167
7195
|
if (!opts.score) return result;
|
|
7168
7196
|
const scores = /* @__PURE__ */ new Map();
|
|
7169
|
-
const
|
|
7170
|
-
|
|
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) => {
|
|
7171
7201
|
const shotHash = settledShotHash(s.folder);
|
|
7172
7202
|
const ask = () => api2(
|
|
7173
7203
|
cfg,
|
|
@@ -7189,6 +7219,19 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7189
7219
|
progress(`could not score ${s.facts.key}: ${apiError2(r)}`);
|
|
7190
7220
|
}
|
|
7191
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
|
+
}
|
|
7192
7235
|
result.scored = scores.size;
|
|
7193
7236
|
result.mean = scores.size ? Math.round([...scores.values()].reduce((n, x) => n + x.overall, 0) / scores.size * 10) / 10 : null;
|
|
7194
7237
|
result.typical = typicalScore([...scores.values()].map((x) => x.overall));
|
|
@@ -7209,7 +7252,7 @@ async function uploadCaptures(cfg, opts) {
|
|
|
7209
7252
|
finished_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7210
7253
|
error: null,
|
|
7211
7254
|
// A check sent in parts closes from the pages the server holds; one part sends them, as before.
|
|
7212
|
-
...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: "Not scored." } })) },
|
|
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." } })) },
|
|
7213
7256
|
causes: result.causes
|
|
7214
7257
|
})
|
|
7215
7258
|
},
|
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",
|