mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 17:27:43 +01:00
* fix(feedback): the reporter page was the counter-example to its own top report /my-feedback rendered a report asking for a three-line clamp at full eight lines, under a chip reading "Being implemented". The clamp WAS implemented — FeedbackReportText, #783, written in answer to that very report — but only in FeedbackItemRow, the operator's inbox. The reporter page kept its own row markup, so the fix never reached the person who asked for it. The missing import is the symptom. The defect is that a third feedback surface existed with its own renderer and nobody knew, so this fixes the page and closes the gap that let it drift. The page now: - renders bodies through the shared FeedbackReportText, so one dictated report stops owning the list; - derives status instead of dictionary-mapping the DB word. `dispatched` meant queued, running, crashed days ago, or shipped-but-unconfirmed, and all four read "Being implemented"; work-phase.ts opens by saying DB status cannot answer that question, and this page was the last one still asking it; - gives the reporter a next action — "Check the live page" once a fix is actually deployed, never while its pull request is open; - colours the chip. Every state used .ui-badge, the same neutral pill as a duplicate count, so the one thing a reporter comes here to learn carried the weight of a footnote; - formats dates in the READER's locale and time zone. toLocaleString() ran in a server component, so a Swiss reporter was shown a US date on the box's clock. The operator row never had this; it is already a client component; - labels the project name, which sat unlabelled exactly where a person's name would and read as one. What a reporter may see is decided in one place. reporter-view.ts writes every reporter-facing sentence rather than forwarding FeedbackWorkView's, because that view is written for whoever owns the machine: `detail` carries builder asks, `diagnostic` the agent's raw error, `stepSummary` run-hop narration, plus run and command ids. A pass-through would have been shorter and would have put an engineer's note on a stranger's screen. attachReporterView is likewise a narrow read, never attachFeedbackWork — that one refreshes GitHub ledgers, sends the owner's notifications and scopes to the owner, none of which belongs on a reporter's page load. Reporter run lookup is deliberately not owner-scoped, and authorization comes from the report instead: the caller has proved reporter_user_id, and passes only the dispatched_run_id values off those rows. Guards, so the next clamp-class fix cannot land on one surface only: - feedback-reporter-view.ts pins that the page renders through the shared clamp, formats no date server-side, maps every phase, and leaks no operator-only string for any phase; - CLAUDE.md names /my-feedback in Views — it listed /feedback and ControlInbox and not this one; - /feedback and /my-feedback join audit:responsive, which would have caught an eight-line row at 390px. Dropped the subtitle's "Tracking a report never grants permission to edit its project." It answered a question no reporter asked and spent the line that now says what the page is for; the boundary it described is enforced in code and pinned by tests, not by that sentence. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FuaeWPc8gT5sbS7G8BjnrK * fix(feedback): read the reader's clock without setState in an effect `react-hooks/set-state-in-effect` rejected the first cut, and correctly: a useEffect that immediately setStates is a cascading render, and the rule does not care that the second render is the point. The constraint that produced it is real, though. Only the browser knows the reader's time zone, so the localized string cannot exist during SSR — and server and client must still emit identical markup or React throws the tree away. useSyncExternalStore with a server snapshot answers both, and is the shape this repo already reaches for: BrandVersion says "client-only, with a null server snapshot so SSR/hydration match (no setState-in-effect)" in as many words, and NotificationsPill uses the same mounted gate after a React #418 on every authenticated page. Also drops the now-redundant `title`: after hydration the visible text IS the full localized string, and `dateTime` carries the exact instant for machines at every stage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FuaeWPc8gT5sbS7G8BjnrK --------- Co-authored-by: Claude <noreply@anthropic.com>
240 lines
7.7 KiB
JavaScript
240 lines
7.7 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { chromium } from "playwright";
|
|
|
|
const root = process.cwd();
|
|
const outDir = path.join(root, ".tmp", "responsive-audit");
|
|
fs.mkdirSync(outDir, { recursive: true });
|
|
|
|
function readLocalEnv() {
|
|
const envPath = path.join(root, ".env.local");
|
|
if (!fs.existsSync(envPath)) return;
|
|
const lines = fs.readFileSync(envPath, "utf8").split(/\r?\n/);
|
|
for (const line of lines) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
const idx = trimmed.indexOf("=");
|
|
if (idx === -1) continue;
|
|
const key = trimmed.slice(0, idx);
|
|
const value = trimmed.slice(idx + 1).replace(/^"|"$/g, "");
|
|
if (!process.env[key]) process.env[key] = value;
|
|
}
|
|
}
|
|
|
|
readLocalEnv();
|
|
|
|
const base = process.env.BASE ?? "http://localhost:3002";
|
|
const ownerPassword = process.env.LOCAL_AUTH_PASSWORD;
|
|
const dogfoodEmail = process.env.DOGFOOD_EMAIL;
|
|
const dogfoodPassword = process.env.DOGFOOD_PASSWORD;
|
|
const isLocal = base.includes("localhost") || base.includes("127.0.0.1");
|
|
const routes = [
|
|
"/today",
|
|
"/control",
|
|
"/loki",
|
|
"/terminal?source=server&tab=loki",
|
|
"/projects",
|
|
"/prompts",
|
|
// Both feedback surfaces. The reporter page shipped an unclamped report body
|
|
// that swallowed the list at phone width for two days; neither page was ever
|
|
// driven through a viewport here.
|
|
"/feedback",
|
|
"/my-feedback",
|
|
"/activity",
|
|
"/history",
|
|
"/decisions",
|
|
"/system",
|
|
"/settings",
|
|
"/people",
|
|
"/crew",
|
|
"/goals",
|
|
"/habits",
|
|
"/events",
|
|
"/money",
|
|
"/thoughts",
|
|
];
|
|
|
|
const viewports = [
|
|
{ name: "mobile", width: 390, height: 844, isMobile: true },
|
|
{ name: "desktop", width: 1440, height: 1000, isMobile: false },
|
|
];
|
|
|
|
function slug(route) {
|
|
return route.replace(/^\//, "").replace(/\//g, "-") || "home";
|
|
}
|
|
|
|
async function login(page) {
|
|
await page.goto(`${base}/sign-in?callbackUrl=/today`, { waitUntil: "domcontentloaded" });
|
|
if (isLocal) {
|
|
const ownerTab = page.getByRole("button", { name: /owner key/i });
|
|
if (await ownerTab.count()) await ownerTab.click();
|
|
if (!ownerPassword) throw new Error("LOCAL_AUTH_PASSWORD is not configured");
|
|
await page.locator('input[type="password"]').first().fill(ownerPassword);
|
|
} else {
|
|
if (!dogfoodEmail || !dogfoodPassword)
|
|
throw new Error("DOGFOOD_EMAIL/DOGFOOD_PASSWORD required for production audit");
|
|
await page.locator('input[type="email"]').first().fill(dogfoodEmail);
|
|
await page.locator('input[type="password"]').first().fill(dogfoodPassword);
|
|
}
|
|
await page
|
|
.getByRole("button", { name: /sign in|continue|unlock/i })
|
|
.last()
|
|
.click();
|
|
await page.waitForURL((url) => !url.pathname.startsWith("/sign-in"), { timeout: 15000 });
|
|
}
|
|
|
|
async function analyze(page, viewportName) {
|
|
return page.evaluate((vpName) => {
|
|
const vw = document.documentElement.clientWidth;
|
|
const vh = window.innerHeight;
|
|
const body = document.body;
|
|
const doc = document.documentElement;
|
|
const all = [...document.querySelectorAll("*")];
|
|
|
|
const textNodes = all
|
|
.map((el) => {
|
|
const rect = el.getBoundingClientRect();
|
|
const style = window.getComputedStyle(el);
|
|
const text = (el.textContent || "").trim().replace(/\s+/g, " ");
|
|
return {
|
|
tag: el.tagName.toLowerCase(),
|
|
text: text.slice(0, 80),
|
|
size: parseFloat(style.fontSize),
|
|
visible:
|
|
rect.width > 0 &&
|
|
rect.height > 0 &&
|
|
style.visibility !== "hidden" &&
|
|
style.display !== "none",
|
|
};
|
|
})
|
|
.filter((x) => x.visible && x.text && x.size > 0 && x.size < (vpName === "mobile" ? 12 : 11))
|
|
.slice(0, 30);
|
|
|
|
const overflow = all
|
|
.map((el) => {
|
|
const rect = el.getBoundingClientRect();
|
|
const style = window.getComputedStyle(el);
|
|
const text = (el.textContent || "").trim().replace(/\s+/g, " ");
|
|
return {
|
|
tag: el.tagName.toLowerCase(),
|
|
cls: typeof el.className === "string" ? el.className.slice(0, 120) : "",
|
|
text: text.slice(0, 80),
|
|
right: Math.round(rect.right),
|
|
left: Math.round(rect.left),
|
|
width: Math.round(rect.width),
|
|
visible:
|
|
rect.width > 0 &&
|
|
rect.height > 0 &&
|
|
style.visibility !== "hidden" &&
|
|
style.display !== "none",
|
|
};
|
|
})
|
|
.filter((x) => x.visible && (x.right > vw + 2 || x.left < -2))
|
|
.slice(0, 30);
|
|
|
|
const targets = all
|
|
.filter((el) => el.matches("button,a,input,select,textarea,[role='button']"))
|
|
.map((el) => {
|
|
const rect = el.getBoundingClientRect();
|
|
const style = window.getComputedStyle(el);
|
|
const text = (
|
|
el.getAttribute("aria-label") ||
|
|
el.textContent ||
|
|
el.getAttribute("title") ||
|
|
""
|
|
)
|
|
.trim()
|
|
.replace(/\s+/g, " ");
|
|
return {
|
|
tag: el.tagName.toLowerCase(),
|
|
text: text.slice(0, 80),
|
|
width: Math.round(rect.width),
|
|
height: Math.round(rect.height),
|
|
visible:
|
|
rect.width > 0 &&
|
|
rect.height > 0 &&
|
|
style.visibility !== "hidden" &&
|
|
style.display !== "none",
|
|
};
|
|
})
|
|
.filter((x) => x.visible && vpName === "mobile" && (x.width < 36 || x.height < 36))
|
|
.slice(0, 40);
|
|
|
|
return {
|
|
viewport: vpName,
|
|
title: document.title,
|
|
url: location.pathname,
|
|
scrollHeight: Math.round(doc.scrollHeight),
|
|
viewportHeight: vh,
|
|
scrollScreens: Number((doc.scrollHeight / vh).toFixed(2)),
|
|
clientWidth: vw,
|
|
scrollWidth: Math.max(body.scrollWidth, doc.scrollWidth),
|
|
overflow,
|
|
tinyText: textNodes,
|
|
smallTargets: targets,
|
|
};
|
|
}, viewportName);
|
|
}
|
|
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath: process.env.CHROME_PATH || "/usr/bin/google-chrome",
|
|
});
|
|
|
|
const results = [];
|
|
try {
|
|
const context = await browser.newContext({
|
|
viewport: { width: 390, height: 844 },
|
|
deviceScaleFactor: 1,
|
|
});
|
|
const page = await context.newPage();
|
|
await login(page);
|
|
await context.storageState({ path: path.join(outDir, "storage.json") });
|
|
await context.close();
|
|
|
|
for (const vp of viewports) {
|
|
const ctx = await browser.newContext({
|
|
storageState: path.join(outDir, "storage.json"),
|
|
viewport: { width: vp.width, height: vp.height },
|
|
isMobile: vp.isMobile,
|
|
deviceScaleFactor: 1,
|
|
});
|
|
const p = await ctx.newPage();
|
|
for (const route of routes) {
|
|
try {
|
|
await p.goto(`${base}${route}`, { waitUntil: "load", timeout: 20000 });
|
|
} catch (err) {
|
|
console.error(`nav failed ${route}: ${err.message?.split("\n")[0]}`);
|
|
continue;
|
|
}
|
|
// Let client-side fetches and first paint settle without waiting for SSE to go idle.
|
|
await p.waitForTimeout(1200);
|
|
await p.screenshot({
|
|
path: path.join(outDir, `${vp.name}-${slug(route)}.png`),
|
|
fullPage: true,
|
|
});
|
|
results.push(await analyze(p, vp.name));
|
|
}
|
|
await ctx.close();
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
|
|
fs.writeFileSync(path.join(outDir, "report.json"), JSON.stringify(results, null, 2));
|
|
for (const result of results) {
|
|
const problems = [
|
|
result.scrollWidth > result.clientWidth
|
|
? `overflow ${result.scrollWidth}/${result.clientWidth}`
|
|
: null,
|
|
result.tinyText.length ? `tinyText ${result.tinyText.length}` : null,
|
|
result.smallTargets.length ? `smallTargets ${result.smallTargets.length}` : null,
|
|
]
|
|
.filter(Boolean)
|
|
.join(", ");
|
|
console.log(
|
|
`${result.viewport.padEnd(7)} ${result.url.padEnd(12)} screens=${result.scrollScreens}${problems ? ` ${problems}` : ""}`,
|
|
);
|
|
}
|
|
console.log(`report ${path.join(outDir, "report.json")}`);
|