mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:17:01 +01:00
* fix(prompts): one card per saved prompt, schedules in words, dialogs that say why
What the owner found on /prompts from an Android phone, item by item:
1. Saved prompts: saving the same name + words again no longer inserts a
row — POST /api/prompts answers with the prompt already saved
(existing: true); the form opens it, the default's save button says
"Already in your prompts". A card that stands for identical copies says
how many and offers "Remove N extra copies" — one explicit tap, the
caller's own rows only, the same soft delete as Delete
(DELETE /api/prompts/<id>/copies). Same name with different words says
"2 versions with this name, worded differently".
2. Filters: the scope filter is a <Segmented> (All / Any project / One
project) sitting with the category row on the list they both filter,
under "Loki's prompts". Category counts follow the scope. Filter chip
rows on a phone get a wider fade, snap to a chip's start and leave room
after the last chip, so the edge reads as "more" rather than a cut word.
3. New prompt: Create stays disabled until there is a name and a prompt,
and says what is missing beside it. Opening or closing the form never
saved anything; the copy glyph on every default card did, in one tap
with no label on a phone — it is now a labelled "save a copy" button.
4. Schedule: pick Every day / Weekdays / Every week / Every month, a day
and a time; Loki writes the cron (lib/cron-words), with "Write it as a
cron line instead" for experts. The schedule reads back in words with
the time zone it runs in ("Every Monday at 10:00, Zurich time
(Europe/Zurich)") and a link to change it; the zone is sent with the
job. The API refuses a cron line the scheduler cannot read, in words.
Create is the primary button and says why when it cannot be pressed.
5. Run: a prompt that names {{project_name}} asks for a project whatever
its scope (a saved copy is global), defaulting to the project in use;
the prompt is shown only once complete. Each action says in one line
who does the work; Send to terminal works for any of your projects
(tab-inject starts or queues the session) and says why when it cannot.
Project pickers list projectTitle(), not folder keys.
6. Category chips are neutral (ui-tag-neutral); the ui-cat-* rainbow and
the featured star's amber are gone. "control" was a second id for the
fleet prompts — one category now, "Fleet control".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(voice): spoken sentences start with a capital and name a repeated project once
The briefing read "one run is waiting for a builder: loki ... three runs
failed: loki, loki and loki". Sentences now open with a capital, and the
runs' projects are said once each: "Three runs failed on loki.", "Four runs
failed: loki three times and heidi once." The same for runs waiting for a
builder, agents working, and the announcements between turns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(voice): say why the studio voice is off, with the link that fixes it
POST /api/voice/speak answered 502 with Groq's reason only in the server
console, and the phone fell back to its own voice in silence, so every voice
in the picker sounded the same. Groq's refusal is now classified
(lib/voice/tts-failure: terms gate, bad key, limit, model gone, vendor down,
no key) into one plain sentence and, where one exists, the link that fixes
it — for the Orpheus terms gate, Groq's voice page and "press Accept". The
route returns it in the 502/503 body and records it in debug_logs (once per
reason per half hour) so System shows it. The speaker reports the fallback
to the page; useStudioVoiceStatus keeps it for the tab's session and
StudioVoiceNotice shows it. The phone-voice fallback stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* feat(voice): change Loki's voice by saying so, and answer questions about voice mode truthfully
"I don't like your voice, can I change your voice" was answered like a
generic chatbot ("in most voice-enabled AI chat apps... look in settings").
Now "use Troy", "change your voice to Diana", "other voice" and
"switch voice" are a spoken command (config/no-screen.ts, lib/voice/commands)
that the phone answers itself; with no name it lists the voices. A question
that does reach Loki carries voiceModeContext (lib/voice/self.ts), built from
the SSOT: the voices by name, how to change one, the three switches with the
same one-line notes the screen shows (NO_SCREEN_OPTIONS), every command, the
current settings and why studio voices are off, if they are.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(voice): a music bed a phone can actually play, and keep its sound awake
The bed sat at about -38 dBFS RMS alone and -50 under the voice, every note
98-370 Hz behind a 900 Hz low-pass: below what a phone speaker or many
earbuds reproduce, so "music bed on" was silence. It is now an octave
higher (196-740 Hz), about 12 dB louder, ducks by 10 dB instead of 11 more on
top, and earcons sit above it. The AudioContext is resumed inside the Start
tap, on every tap on the circle or headphone button, on return to the page,
and when the phone suspends it mid-session.
useSoundscape also returned a new object every render, so effects keyed on
it re-ran ~20 times a second while listening: the gain was re-ramped every
frame and the 20-second fleet poll was cleared before it could fire. It is
memoized now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(voice): one h1 per screen, End clear of the feedback launcher, voices as an even grid
- Speaking screen: an h1 below md, where the app top bar steps aside; the
start screen's big "Voice" is no longer a second h1 beside the top bar's.
- The speaking screen sets data-fc-place="tab", so the feedback launcher
and its Watching pill become the slim edge handle instead of sitting on
End; End is larger, with room below it, and the stage scrolls rather than
pushing End off a short screen.
- The voice picker is a <Segmented> grid of four columns (seven voices as
4 + 3, the last two cells wide) instead of a chip row cut off at the edge;
the setting groups have real headings.
- The unclear note under the switches is one short line under each switch,
shared with what Loki is told about itself.
- The page wires the studio-voice notice (under the picker and under the
circle, said aloud once), the spoken voice change, the page's state sent
with each question, and the sound resume on every tap.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(widget): one card per finding, settled page checks, honest fix status, a count that means what needs you
Watching on Loki's own /voice from an Android phone showed six problems in
one panel. Each is fixed where it starts:
- Notices no longer stack. A page's checks own ONE card (checksSlot), which
each new reading replaces in place and a clean reading takes back
(thread.ts pushNoticed / dropNoticed); a remark whose words are already on
screen is not said again; a finding's signature ignores its count and its
placeholder example (findingKind), and the card names its page.
- The heading miscount: the check counted headings inside aria-hidden and
inert subtrees, and measured the page once, mid-swap — /voice's setup
screen (top bar h1 + page h1) leaving for its speaking screen (immersive
mode hides the top bar: no h1). Checks now count only rendered elements and
run once the page has held still, twice, keeping only what both readings
agree on (settledPageChecks / stableChecks). The Voice page itself now has
one h1 on each screen.
- A fix Watch started that failed no longer promises it "goes live by
itself": it says the fix did not finish, and "Open it in Loki to see why"
is a real link to that run's Watch page (owner-view ownerTap; watch-fix
now resolves a failed run's Watch page even without a live page).
- Self-watch: "I couldn't check on your changes just now" replaces the old
sentence; a request that lived through the page being put away (a phone
locking) is never a failure; background reads count only after three
failures in a row; the changes route always answers with CORS headers and
logs what failed.
- The header's one number is what waits on the owner's decision (failed
attempts, saved notes, notes not started, changes said but not saved),
counted by the server over ALL of the owner's rows, not inside the newest
twelve; the open list shows every one of them first. Nothing waiting:
just "Watching".
- The save receipt never quotes a cut sentence: several changes are listed
one per line under it, clamped to whole lines with "Show all".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* docs(changelog): voice, Watching and Prompts fixes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
---------
Co-authored-by: Claude <noreply@anthropic.com>
734 lines
33 KiB
TypeScript
734 lines
33 KiB
TypeScript
// Watch mode in a real browser: the owner sees "Loki is watching" the whole
|
|
// time; a request the site makes that fails with a 500 files ONE report with
|
|
// the trail (the tap that led there included, the typed value excluded);
|
|
// Pause stops it, and paused, a failure files nothing. A visitor without the
|
|
// owner pass gets no pill and no recording at all.
|
|
// Run: npx tsx scripts/test/widget-watch-browser.ts
|
|
import { build } from "esbuild";
|
|
import { chromium, type Browser, type Page } from "playwright";
|
|
import { PALETTE } from "../../src/lib/palette";
|
|
import { failureSignature, noticeSignature } from "../../widget/watch-trail";
|
|
|
|
let pass = 0;
|
|
let fail = 0;
|
|
function ok(cond: boolean, label: string) {
|
|
if (cond) pass++;
|
|
else {
|
|
fail++;
|
|
console.error(`✗ ${label}`);
|
|
}
|
|
}
|
|
|
|
const ORIGIN = "http://host.fixture";
|
|
const SITE = `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Shop</title>
|
|
<meta name="viewport" content="width=device-width,initial-scale=1"></head><body>
|
|
<main><h1>Shop</h1><input id="email" placeholder="Your email">
|
|
<button id="buy">Buy now</button><button id="dead">Save</button><button id="ok">Refresh</button>
|
|
<button id="find">Find a size</button><button id="icon"><svg width="10" height="10"></svg></button>
|
|
<img src="/shop/hero.png" width="40" height="40"><button id="jank">Load more</button>
|
|
<nav><a href="/roomy" style="display:inline-block;height:20px;margin:24px">Roomy nav link</a></nav>
|
|
<div><a href="/p1" style="display:inline-block;width:16px;height:16px">1</a><a href="/p2" style="display:inline-block;width:16px;height:16px">2</a></div></main>
|
|
<footer style="content-visibility:auto;margin-top:4000px"><a href="/about">About the shop</a></footer>
|
|
<script>document.getElementById("buy").onclick = () => fetch("/shop/checkout?token=secret", { method: "POST" });
|
|
document.getElementById("ok").onclick = () => fetch("/shop/ok");
|
|
document.getElementById("find").onclick = () => fetch("/shop/sizes?user=secret");
|
|
// A janky "Load more": freezes the main thread, then pushes everything down.
|
|
document.getElementById("jank").onclick = () => {
|
|
const until = performance.now() + 450; while (performance.now() < until) {}
|
|
setTimeout(() => { const b = document.createElement("div"); b.style.height = "320px";
|
|
b.textContent = "Banner"; document.querySelector("main").prepend(b); }, 900);
|
|
};</script>
|
|
<script src="${ORIGIN}/widget.js" data-fc-project="fcw_fixture" async></script></body></html>`;
|
|
|
|
type Report = { suggestion: string; ownerPass?: string };
|
|
type Advice = { question: string; scope: string; session?: string; read?: boolean };
|
|
|
|
async function open(browser: Browser, js: string, hash: string, known: unknown[] = []) {
|
|
const ctx = await browser.newContext({ viewport: { width: 390, height: 800 } });
|
|
const p = await ctx.newPage();
|
|
const errors: string[] = [];
|
|
const reports: Report[] = [];
|
|
const advice: Advice[] = [];
|
|
p.on("pageerror", (e) => errors.push(e.message));
|
|
await p.route(`${ORIGIN}/**`, async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (body: unknown, status = 200) =>
|
|
route.fulfill({ status, body: JSON.stringify(body), contentType: "application/json" });
|
|
if (url.pathname === "/widget.js")
|
|
return route.fulfill({ body: js, contentType: "text/javascript" });
|
|
if (url.pathname === "/api/widget-boot") {
|
|
return json({
|
|
active: true,
|
|
placement: { corner: "bottom-right", offsetX: 16, offsetY: 16, autoAvoid: true },
|
|
theme: PALETTE.widget,
|
|
});
|
|
}
|
|
if (url.pathname === "/api/feedback") {
|
|
reports.push(JSON.parse(route.request().postData() ?? "{}") as Report);
|
|
return json({ ok: true, owner: true, building: true });
|
|
}
|
|
if (url.pathname === "/shop/checkout") return json({ error: "boom" }, 500);
|
|
// The owner's fixes, as Loki remembers them (known-fixes.ts).
|
|
if (url.pathname === "/api/widget/owner/changes") {
|
|
return json({
|
|
ok: true,
|
|
owner: true,
|
|
changes: [],
|
|
known,
|
|
inbox: "https://loki.example/feedback",
|
|
visitors: 0,
|
|
});
|
|
}
|
|
if (url.pathname === "/api/widget/advise") {
|
|
advice.push(JSON.parse(route.request().postData() ?? "{}") as Advice);
|
|
return json({
|
|
ok: true,
|
|
reply: "You were looking for a size. **Errors:** the size lookup 404s.",
|
|
changes: ["Make “Find a size” show the size chart instead of failing"],
|
|
});
|
|
}
|
|
if (url.pathname === "/shop/ok") return json({ ok: true });
|
|
if (url.pathname === "/shop/sizes") return json({ error: "not found" }, 404);
|
|
if (url.pathname === "/shop/hero.png") return route.fulfill({ status: 404, body: "" });
|
|
return route.fulfill({ body: SITE, contentType: "text/html" });
|
|
});
|
|
await p.goto(`${ORIGIN}/${hash}`);
|
|
await p.waitForTimeout(1000);
|
|
return { p, errors, reports, advice, close: () => ctx.close() };
|
|
}
|
|
|
|
/** The recorded trail, as the tab keeps it across page loads. */
|
|
const trailText = (p: Page) =>
|
|
p.evaluate(() => sessionStorage.getItem("loki-watch-trail:fcw_fixture") ?? "");
|
|
|
|
/** Click a pill button by its label — the pill's buttons are Review, Report, Pause. */
|
|
const clickPill = (p: Page, label: string) =>
|
|
p.evaluate((label) => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const btn = Array.from(r.querySelectorAll(".watch-pill .wbtn")).find(
|
|
(b) => (b as HTMLElement).innerText.trim() === label,
|
|
) as HTMLElement | undefined;
|
|
if (!btn) throw new Error(`no pill button "${label}"`);
|
|
btn.click();
|
|
}, label);
|
|
|
|
const pillText = (p: Page) =>
|
|
p.evaluate(() => {
|
|
const el = document
|
|
.getElementById("loki-feedback-host")
|
|
?.shadowRoot?.querySelector(".watch-pill .wtext") as HTMLElement | null;
|
|
return el?.innerText ?? null;
|
|
});
|
|
/** The pill's last button is Pause / Resume (Report sits before it). */
|
|
const clickPillButton = (p: Page) =>
|
|
p.evaluate(() => {
|
|
const all = document
|
|
.getElementById("loki-feedback-host")!
|
|
.shadowRoot!.querySelectorAll(".watch-pill .wbtn");
|
|
(all[all.length - 1] as HTMLElement).click();
|
|
});
|
|
|
|
async function main() {
|
|
let browser: Browser;
|
|
try {
|
|
browser = await chromium.launch(
|
|
process.env.PW_CHROMIUM ? { executablePath: process.env.PW_CHROMIUM } : {},
|
|
);
|
|
} catch (err) {
|
|
const why = err instanceof Error ? err.message.split("\n")[0] : String(err);
|
|
if (process.env.CI) {
|
|
console.error(`✗ Chromium is required under CI and could not launch: ${why}`);
|
|
process.exit(1);
|
|
}
|
|
console.log(`↷ skipped: no Chromium on this machine (${why}). CI runs it.`);
|
|
process.exit(0);
|
|
}
|
|
const out = await build({
|
|
entryPoints: ["widget/main.ts"],
|
|
bundle: true,
|
|
format: "iife",
|
|
write: false,
|
|
logLevel: "silent",
|
|
});
|
|
const js = out.outputFiles[0].text;
|
|
|
|
// ---- the owner: watched, visibly, and a failure files one report ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
// The owner link opens the note panel; close it to use the page.
|
|
await s.p.keyboard.press("Escape");
|
|
ok(
|
|
(await pillText(s.p))?.startsWith("Loki is watching") === true,
|
|
"owner sees the watching pill",
|
|
);
|
|
await s.p.fill("#email", "me@example.com");
|
|
await s.p.click("#email");
|
|
await s.p.click("#buy");
|
|
await s.p.waitForTimeout(600);
|
|
await s.p.click("#buy");
|
|
await s.p.waitForTimeout(600);
|
|
ok(s.reports.length === 1, `one report for one cause (got ${s.reports.length})`);
|
|
const r = s.reports[0]?.suggestion ?? "";
|
|
ok(r.includes("POST /shop/checkout → 500"), "the report names the failed request");
|
|
ok(r.includes("button “Buy now”"), "the report carries the tap that led there");
|
|
ok(!r.includes("me@example.com"), "what was typed never leaves the page");
|
|
ok(!r.includes("token=secret"), "query strings never leave the page");
|
|
ok(s.reports[0]?.ownerPass === "pass123", "the report is the owner's, so it starts a fix");
|
|
ok(
|
|
(await pillText(s.p))?.includes("Loki is fixing") === true,
|
|
"the pill says it is being fixed",
|
|
);
|
|
ok(s.errors.length === 0, `no page errors (${s.errors.join("; ")})`);
|
|
await s.close();
|
|
}
|
|
|
|
// ---- the launcher IS the status; the top bar only when it cannot be seen ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
await s.p.keyboard.press("Escape");
|
|
const state = () =>
|
|
s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const fab = r.querySelector(".fab") as HTMLElement;
|
|
const bar = r.querySelector(".watch-pill") as HTMLElement;
|
|
const bubble = r.querySelector(".fab-bubble") as HTMLElement;
|
|
return {
|
|
// The words, not the pixels: on a phone the owner's label is hidden
|
|
// (it covered the page) and the accessible name carries it.
|
|
label: (fab.querySelector(".fab-label")?.textContent ?? "").replace(/\s+/g, " ").trim(),
|
|
name: fab.getAttribute("aria-label") ?? "",
|
|
watching: fab.classList.contains("watching"),
|
|
badge: (r.querySelector(".fab-badge") as HTMLElement).innerText,
|
|
bar: getComputedStyle(bar).display !== "none",
|
|
bubble:
|
|
getComputedStyle(bubble).display !== "none"
|
|
? (bubble.querySelector(".fab-bubble-text")?.textContent ?? "")
|
|
: "",
|
|
latest: (bar.querySelector(".wtext") as HTMLElement).innerText.replace(
|
|
/^Loki noticed: /,
|
|
"",
|
|
),
|
|
requestNoted: JSON.parse(sessionStorage.getItem("loki-thread:fcw_fixture") ?? "[]").some(
|
|
(item: { kind: string; text?: string }) =>
|
|
item.kind === "noticed" &&
|
|
item.text?.includes("/shop/sizes") &&
|
|
item.text.includes("404"),
|
|
),
|
|
};
|
|
});
|
|
let st = await state();
|
|
ok(
|
|
st.label === "Watching" && st.watching && st.name.includes("watching"),
|
|
`the owner's launcher says so (${st.label})`,
|
|
);
|
|
ok(!st.bar, "with the launcher showing it, the top bar stays off the site");
|
|
await s.p.click("#find");
|
|
await s.p.waitForTimeout(600);
|
|
st = await state();
|
|
ok(
|
|
st.badge === "1" || st.badge === "2",
|
|
`what Loki said while closed is counted (${st.badge})`,
|
|
);
|
|
// Performance observations can legitimately arrive after the request.
|
|
// Keep the specific error and preview the latest notice, whichever arrived last.
|
|
ok(st.requestNoted, "the failed request stays in the conversation");
|
|
ok(
|
|
!!st.bubble && st.bubble === st.latest,
|
|
`the latest notice is shown beside the launcher (${st.bubble}; latest: ${st.latest})`,
|
|
);
|
|
await s.p.evaluate(() =>
|
|
(
|
|
document
|
|
.getElementById("loki-feedback-host")!
|
|
.shadowRoot!.querySelector(".fab") as HTMLElement
|
|
).click(),
|
|
);
|
|
await s.p.keyboard.press("Escape");
|
|
st = await state();
|
|
ok(st.badge === "", "opening Loki clears the count");
|
|
// A site that hides the launcher must not hide that Loki is watching.
|
|
await s.p.evaluate(() => document.documentElement.setAttribute("data-fc-place", "hidden"));
|
|
await s.p.waitForTimeout(2600);
|
|
st = await state();
|
|
ok(st.bar, "launcher hidden by the site → the top bar says Loki is watching");
|
|
ok(s.errors.length === 0, `no page errors (${s.errors.join("; ")})`);
|
|
await s.close();
|
|
}
|
|
|
|
// ---- a button that does nothing, and one that works ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
await s.p.keyboard.press("Escape");
|
|
for (let i = 0; i < 3; i++) await s.p.click("#ok");
|
|
await s.p.waitForTimeout(400);
|
|
ok(s.reports.length === 0, "a working button tapped three times is not reported");
|
|
for (let i = 0; i < 3; i++) await s.p.click("#dead");
|
|
await s.p.waitForTimeout(400);
|
|
ok(s.reports.length === 1, `a dead button files one report (got ${s.reports.length})`);
|
|
ok(
|
|
(s.reports[0]?.suggestion ?? "").includes(
|
|
"pressed button “Save” three times and nothing happened",
|
|
),
|
|
"the report says which button did nothing",
|
|
);
|
|
// Loki said so in the conversation; Show on the bar opens it there.
|
|
await clickPill(s.p, "Show");
|
|
await s.p.waitForTimeout(300);
|
|
const said = await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const m = Array.from(r.querySelectorAll(".msg.noticed")).find((x) =>
|
|
(x as HTMLElement).innerText.includes("three times"),
|
|
) as HTMLElement | undefined;
|
|
return {
|
|
open: !!r.querySelector(".panel"),
|
|
text: m?.innerText ?? "",
|
|
fix: !!m?.querySelector(".change-send"),
|
|
};
|
|
});
|
|
ok(said.open, "Show opens the conversation");
|
|
ok(
|
|
said.text.includes("three times and nothing happened") && said.text.includes("started a fix"),
|
|
`Loki says what broke and that a fix is under way (${said.text})`,
|
|
);
|
|
ok(!said.fix, "an already-started fix offers no second Fix button");
|
|
await s.close();
|
|
}
|
|
|
|
// ---- Loki remembers what it noticed: a fix in flight is not said again ----
|
|
{
|
|
const key = noticeSignature("/", { kind: "4xx", text: "GET /shop/sizes → 404", after: null });
|
|
const inFlight = {
|
|
key,
|
|
id: "f-sizes",
|
|
at: "2026-10-10T10:00:00Z",
|
|
label: "Building",
|
|
tone: "accent",
|
|
detail: "An agent is working on it right now.",
|
|
live: false,
|
|
settled: false,
|
|
href: "https://loki.example/feedback",
|
|
};
|
|
const s = await open(browser, js, "#loki-owner=pass123", [inFlight]);
|
|
await s.p.keyboard.press("Escape");
|
|
await s.p.click("#find");
|
|
await s.p.waitForTimeout(600);
|
|
ok(
|
|
(await pillText(s.p))?.includes("/shop/sizes") !== true,
|
|
`a finding whose fix is building is not noticed again (${await pillText(s.p)})`,
|
|
);
|
|
const trail = await trailText(s.p);
|
|
ok(trail.includes("already with Loki"), "the notes say why Loki kept quiet");
|
|
await clickPill(s.p, "Show");
|
|
await s.p.waitForTimeout(200);
|
|
const cards = await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
return Array.from(r.querySelectorAll(".msg.noticed")).filter((x) =>
|
|
(x as HTMLElement).innerText.includes("/shop/sizes"),
|
|
).length;
|
|
});
|
|
ok(cards === 0, `no second card for a fix in flight (${cards})`);
|
|
await s.close();
|
|
}
|
|
|
|
// ---- …a fix that is live and back is said as such, with Fix again ----
|
|
{
|
|
const key = noticeSignature("/", { kind: "4xx", text: "GET /shop/sizes → 404", after: null });
|
|
const live = {
|
|
key,
|
|
id: "f-sizes",
|
|
at: "2026-10-03T10:00:00Z",
|
|
label: "Live",
|
|
tone: "positive",
|
|
detail: "It is on the site now. Have a look.",
|
|
live: true,
|
|
settled: true,
|
|
href: "https://host.fixture/shop",
|
|
};
|
|
const s = await open(browser, js, "#loki-owner=pass123", [live]);
|
|
await s.p.keyboard.press("Escape");
|
|
await s.p.click("#find");
|
|
await s.p.waitForTimeout(600);
|
|
await clickPill(s.p, "Show");
|
|
await s.p.waitForTimeout(200);
|
|
const card = await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const m = Array.from(r.querySelectorAll(".msg.noticed")).find((x) =>
|
|
(x as HTMLElement).innerText.includes("/shop/sizes"),
|
|
) as HTMLElement | undefined;
|
|
return {
|
|
text: m?.innerText ?? "",
|
|
status: (m?.querySelector(".noticed-status") as HTMLElement | null)?.innerText ?? "",
|
|
button: (m?.querySelector(".change-send") as HTMLElement | null)?.innerText ?? "",
|
|
};
|
|
});
|
|
ok(card.text.includes("It is back"), `a fixed finding that recurs says so (${card.text})`);
|
|
ok(card.status.startsWith("Fixed 3 Oct"), `the card says when it was fixed (${card.status})`);
|
|
ok(card.button === "Fix again →", `and offers to fix it again (${card.button})`);
|
|
// Fix again files the finding's key with the note, so it lands on the same row.
|
|
await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
(r.querySelector(".msg.noticed .change-send") as HTMLElement).click();
|
|
});
|
|
await s.p.waitForTimeout(300);
|
|
const filed = s.reports.find((r) => r.suggestion.includes("/shop/sizes")) as
|
|
(Report & { noticeKey?: string }) | undefined;
|
|
ok(filed?.noticeKey === key, `Fix again carries the key (${filed?.noticeKey})`);
|
|
await s.close();
|
|
}
|
|
|
|
// ---- a fix Watch started and that failed: said as it stands, with a link ----
|
|
{
|
|
// 2026-10-20: "I've started a fix — it goes live by itself." over "Needs
|
|
// you — The attempt did not finish. Open it in Loki…" with nothing to tap.
|
|
const known: unknown[] = [];
|
|
const s = await open(browser, js, "#loki-owner=pass123", known);
|
|
await s.p.keyboard.press("Escape");
|
|
await s.p.click("#buy");
|
|
await s.p.waitForTimeout(600);
|
|
known.push({
|
|
key: `/|fail|${failureSignature({ kind: "request", text: "POST /shop/checkout → 500" })}`,
|
|
id: "f-checkout",
|
|
at: "2026-10-20T10:00:00Z",
|
|
label: "Needs you",
|
|
tone: "warning",
|
|
detail: "The attempt did not finish.",
|
|
live: false,
|
|
settled: false,
|
|
href: "https://loki.example/feedback/f-checkout/watch-fix",
|
|
action: "Open it in Loki to see why",
|
|
});
|
|
// Opening the panel asks Loki where the owner's fixes are.
|
|
await clickPill(s.p, "Show");
|
|
await s.p.waitForTimeout(500);
|
|
const card = await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const m = Array.from(r.querySelectorAll(".msg.noticed")).find((x) =>
|
|
(x as HTMLElement).innerText.includes("/shop/checkout"),
|
|
) as HTMLElement | undefined;
|
|
const go = m?.querySelector(".noticed-status a") as HTMLAnchorElement | null;
|
|
return { text: m?.innerText ?? "", link: go?.innerText ?? "", href: go?.href ?? "" };
|
|
});
|
|
ok(
|
|
card.text.includes("The fix I started did not finish.") &&
|
|
!card.text.includes("goes live by itself"),
|
|
`a failed fix is never still promised (${card.text})`,
|
|
);
|
|
ok(
|
|
card.link.startsWith("Open it in Loki to see why") &&
|
|
card.href === "https://loki.example/feedback/f-checkout/watch-fix",
|
|
`"Open it in Loki" is a real link to that run (${card.link} → ${card.href})`,
|
|
);
|
|
await s.close();
|
|
}
|
|
|
|
// ---- Review: Loki judges what the owner did, from evidence ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
await s.p.keyboard.press("Escape");
|
|
await s.p.fill("#email", "me@example.com");
|
|
// Tap the FILLED field: a tap on a field is recorded, its value never is.
|
|
// (fill() alone types without a tap, which once made this check vacuous.)
|
|
await s.p.click("#email");
|
|
await s.p.click("#find");
|
|
await s.p.waitForTimeout(500);
|
|
// The scheduled page check/read can finish while Playwright performs the
|
|
// clicks, legitimately replacing the latest status. The specific request
|
|
// remark is asserted in the conversation below; model calls from the
|
|
// scheduled page read are counted separately later in this same fixture.
|
|
ok(
|
|
(await pillText(s.p))?.startsWith("Loki noticed:") === true,
|
|
`the bar says what Loki noticed, in words (${await pillText(s.p)})`,
|
|
);
|
|
ok(s.reports.length === 0, "a 404 is a remark, not an automatic fix");
|
|
ok(s.advice.filter((a) => a.read !== true).length === 0, "speaking up costs no model call");
|
|
await clickPill(s.p, "Show");
|
|
await s.p.waitForTimeout(200);
|
|
const remark = await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const m = Array.from(r.querySelectorAll(".msg.noticed")).find((x) =>
|
|
(x as HTMLElement).innerText.includes("/shop/sizes"),
|
|
) as HTMLElement | undefined;
|
|
(m?.querySelector(".change-send") as HTMLElement | null)?.click();
|
|
return m?.innerText ?? "";
|
|
});
|
|
ok(
|
|
remark.includes("After you pressed button “Find a size”") &&
|
|
remark.includes("found nothing there (404)"),
|
|
`Loki says it in the conversation, naming the control pressed (${remark})`,
|
|
);
|
|
// The owner's word is the decision: Fix this starts the build, no card.
|
|
await s.p.waitForTimeout(300);
|
|
ok(
|
|
s.reports.some((r) => r.suggestion.includes("Fix the request to /shop/sizes")),
|
|
"Fix this starts the fix, written out",
|
|
);
|
|
const reportsBeforeReload = s.reports.length;
|
|
await s.p.keyboard.press("Escape");
|
|
|
|
// A trail survives a full page load: a multi-page site is one visit —
|
|
// and what Loki already said, it does not say again.
|
|
const pendingRead = s.advice.some((item) => item.read === true)
|
|
? null
|
|
: s.p.waitForResponse(
|
|
(response) =>
|
|
response.url().endsWith("/api/widget/advise") &&
|
|
response.request().postDataJSON()?.read === true,
|
|
{ timeout: 15000 },
|
|
);
|
|
await s.p.reload();
|
|
await s.p.waitForTimeout(3500);
|
|
if (pendingRead) await pendingRead;
|
|
const repeats = await s.p.evaluate(
|
|
() =>
|
|
JSON.parse(sessionStorage.getItem("loki-thread:fcw_fixture") ?? "[]").filter(
|
|
(i: { kind: string; text: string }) =>
|
|
i.kind === "noticed" && i.text.includes("/shop/sizes"),
|
|
).length,
|
|
);
|
|
ok(repeats === 1, `a reload does not repeat a remark (${repeats})`);
|
|
await clickPill(s.p, "Show");
|
|
await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
// Review is the conversation's first suggestion — no longer a header pill.
|
|
(r.querySelector(".starter.primary") as HTMLElement).click();
|
|
});
|
|
await s.p.waitForTimeout(800);
|
|
// Watch READS each page by itself (loki-api READ_QUESTION, once per path
|
|
// per visit): the two page loads before the reload are one path, so one
|
|
// read — and the reload did not repeat it either.
|
|
const reads = s.advice.filter((x) => x.read === true);
|
|
ok(reads.length === 1, `Watch reads the page once per visit (got ${reads.length})`);
|
|
ok(/^Read this page/.test(reads[0]?.question ?? ""), "the read is the read question");
|
|
ok(!reads[0]?.session, "a read carries no session — it judges the page, not the taps");
|
|
const reviews = s.advice.filter((x) => x.read !== true);
|
|
const a = reviews[0];
|
|
ok(reviews.length === 1, `Review asks Loki once (got ${reviews.length})`);
|
|
const session = a?.session ?? "";
|
|
ok(/^Review what I just did/.test(a?.question ?? ""), "Review asks for a review");
|
|
ok(session.includes("tap button “Find a size”"), "the session carries the tap");
|
|
ok(session.includes("GET /shop/sizes → 404"), "and what the page answered");
|
|
ok(/page \/[\s\S]*page \//.test(session), "and both page loads — the trail survived reload");
|
|
ok(
|
|
session.includes("1 button(s)/link(s) have no name a screen reader can read"),
|
|
`page checks: the unnamed icon button — and ONLY it, not the labelled footer link the browser skipped painting (${/\d+ button\(s\)[^\n]*/.exec(session)?.[0]})`,
|
|
);
|
|
const crowded = /(\d+) tap target\(s\) are under 24px and crowded[^\n]*/.exec(session);
|
|
ok(!!crowded, "page checks: the two cramped 16px links are a finding");
|
|
ok(
|
|
!!crowded && !crowded[0].includes("Roomy"),
|
|
`…a roomy 20px link is not — WCAG's spacing exception (${crowded?.[0]})`,
|
|
);
|
|
ok(session.includes("no alt text"), "page checks: the image without alt");
|
|
ok(session.includes("failed to load"), "page checks: the broken image");
|
|
ok(!session.includes("me@example.com"), "what was typed never leaves the page");
|
|
ok(!session.includes("user=secret"), "query strings never leave the page");
|
|
const shown = await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
return {
|
|
reply: (
|
|
Array.from(r.querySelectorAll(".convo .msg.from-loki")).pop() as HTMLElement | undefined
|
|
)?.innerText,
|
|
change: (r.querySelector(".convo .changes .change-text") as HTMLElement | null)?.innerText,
|
|
};
|
|
});
|
|
ok(
|
|
shown.reply?.includes("looking for a size") === true,
|
|
"the review is shown in the conversation",
|
|
);
|
|
ok(shown.change?.includes("size chart") === true, "with its change one tap away");
|
|
|
|
// Building that change carries the session's steps to the builder — and
|
|
// for the owner it starts at once: one change, no confirmation card.
|
|
await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
(r.querySelector(".convo .changes .change-send") as HTMLElement).click();
|
|
});
|
|
await s.p.waitForTimeout(400);
|
|
const built = s.reports.slice(reportsBeforeReload).map((r) => r.suggestion);
|
|
ok(built.length === 1, `one change, one build (got ${built.length})`);
|
|
ok(built[0]?.includes("size chart") === true, "the change is what gets built");
|
|
ok(/step 1/.test(built[0] ?? ""), "with the watched steps attached");
|
|
// Loki's own panel opening is not the site's layout shift, and Loki's own
|
|
// boot and page reading are not the site freezing.
|
|
const after = await trailText(s.p);
|
|
ok(!after.includes("jumped around"), `Loki's panel is not blamed for a shift (${after})`);
|
|
ok(!after.includes("froze"), "nor Loki's own work for a freeze");
|
|
ok(s.errors.length === 0, `no page errors (${s.errors.join("; ")})`);
|
|
await s.close();
|
|
}
|
|
|
|
// ---- what a tap DID: answered, or nothing visibly happened ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
await s.p.keyboard.press("Escape");
|
|
await s.p.click("#ok");
|
|
await s.p.waitForTimeout(300);
|
|
await s.p.click("#dead");
|
|
await s.p.waitForTimeout(2000);
|
|
const t = await trailText(s.p);
|
|
ok(t.includes("it asked the server"), `a tap that sent a request is answered (${t})`);
|
|
ok(t.includes("button “Save” did nothing visible"), "a tap that did nothing is noted, once");
|
|
const said = await s.p.evaluate(() =>
|
|
JSON.parse(sessionStorage.getItem("loki-thread:fcw_fixture") ?? "[]").some(
|
|
(i: { kind: string; text: string }) =>
|
|
i.kind === "noticed" && i.text.includes("“Save” and nothing visibly happened"),
|
|
),
|
|
);
|
|
ok(said, "and Loki says so after ONE tap, not three");
|
|
ok(s.reports.length === 0, "a do-nothing tap is a remark, not an automatic fix");
|
|
await s.close();
|
|
}
|
|
|
|
// ---- the site's own jank IS noticed (a detector that never fires reads as clean) ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
await s.p.keyboard.press("Escape");
|
|
await s.p.click("#jank");
|
|
await s.p.waitForTimeout(1600);
|
|
const t = await trailText(s.p);
|
|
ok(/after button “Load more” the page froze for \d+ms/.test(t), `a felt freeze (${t})`);
|
|
ok(t.includes("content jumped around on this page"), "and the content pushed down");
|
|
ok(s.reports.length === 0, "jank is a remark for Review, not an automatic fix");
|
|
await s.close();
|
|
}
|
|
|
|
// ---- paused: says so, and records nothing ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
await s.p.keyboard.press("Escape");
|
|
await clickPillButton(s.p);
|
|
ok((await pillText(s.p))?.startsWith("Loki stopped watching") === true, "stopping is visible");
|
|
await s.p.click("#buy");
|
|
await s.p.waitForTimeout(600);
|
|
ok(s.reports.length === 0, "stopped, a failure files nothing");
|
|
await clickPillButton(s.p); // leave it resumed for the next context
|
|
await s.close();
|
|
}
|
|
|
|
// ---- Pause from the panel's notes row: nothing recorded, nothing said ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
const header = (label: string) =>
|
|
s.p.evaluate((label) => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const b = r.querySelector(".thoughts-toggle") as HTMLElement | null;
|
|
if (!b || b.innerText !== label) return false;
|
|
b.click();
|
|
return true;
|
|
}, label);
|
|
ok(await header("Pause"), "the notes row offers Pause while Loki watches");
|
|
await s.p.keyboard.press("Escape");
|
|
await s.p.click("#find");
|
|
await s.p.waitForTimeout(3200);
|
|
const after = await s.p.evaluate(() => ({
|
|
thread: sessionStorage.getItem("loki-thread:fcw_fixture") ?? "",
|
|
trail: sessionStorage.getItem("loki-watch-trail:fcw_fixture") ?? "",
|
|
}));
|
|
ok(!after.thread.includes("noticed"), "stopped, Loki says nothing");
|
|
ok(!after.trail.includes("Find a size"), "stopped, nothing is recorded");
|
|
await clickPill(s.p, "Show");
|
|
ok(await header("Resume"), "and the notes row offers Resume");
|
|
ok((await pillText(s.p))?.startsWith("Loki is watching") === true, "which starts it again");
|
|
await s.close();
|
|
}
|
|
|
|
// ---- one Loki on the owner's site: ONE launcher that says its state and
|
|
// opens Loki; pointing is in the panel, and "This screen" marks what is
|
|
// on screen ----
|
|
{
|
|
const s = await open(browser, js, "#loki-owner=pass123");
|
|
await s.p.keyboard.press("Escape");
|
|
const state = () =>
|
|
s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const fab = r.querySelector(".fab") as HTMLElement;
|
|
const bar = r.querySelector(".watch-pill") as HTMLElement;
|
|
return {
|
|
fab: getComputedStyle(fab).visibility !== "hidden" && fab.style.display !== "none",
|
|
label: (r.querySelector(".fab-label") as HTMLElement).innerText.trim(),
|
|
halves: r.querySelectorAll(".fab-point").length,
|
|
bar: getComputedStyle(bar).display !== "none",
|
|
};
|
|
});
|
|
let st = await state();
|
|
ok(st.fab && st.halves === 0 && st.label === "Watching", "one launcher, and it says Watching");
|
|
// Paused (the status line's Pause): still one launcher, and it says so.
|
|
await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
(r.querySelector(".fab") as HTMLElement).click();
|
|
});
|
|
await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
(r.querySelector(".thoughts-toggle") as HTMLElement | null)?.click();
|
|
});
|
|
await s.p.keyboard.press("Escape");
|
|
st = await state();
|
|
ok(st.fab && st.label === "Paused", `paused, the same launcher says Paused (${st.label})`);
|
|
// A page that blocks every corner: both launchers become an edge handle
|
|
// (host-avoid test); the owner's stays reachable, with no second bar.
|
|
await s.p.evaluate(() => {
|
|
const wall = document.createElement("div");
|
|
wall.id = "wall";
|
|
wall.style.cssText =
|
|
"position:fixed;inset:0;display:flex;flex-wrap:wrap;overflow:hidden;z-index:5";
|
|
wall.innerHTML = Array.from(
|
|
{ length: 400 },
|
|
(_, i) => `<button style="width:48px;height:48px;margin:0">${i}</button>`,
|
|
).join("");
|
|
document.body.append(wall);
|
|
});
|
|
await s.p.waitForTimeout(2800);
|
|
st = await state();
|
|
ok(st.fab && !st.bar, "every corner busy → the owner's launcher stays, no bar appears");
|
|
await s.p.evaluate(() => document.getElementById("wall")?.remove());
|
|
// Point to area → This screen: the blocks on screen are marked and the
|
|
// conversation has them attached.
|
|
await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
(r.querySelector(".fab") as HTMLElement).click();
|
|
});
|
|
await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
(r.querySelector(".pointbtn") as HTMLElement).click();
|
|
});
|
|
await s.p.waitForTimeout(300);
|
|
const picked = await s.p.evaluate(() => {
|
|
const r = document.getElementById("loki-feedback-host")!.shadowRoot!;
|
|
const btn = Array.from(r.querySelectorAll(".pickbar button")).find(
|
|
(b) => (b as HTMLElement).innerText.trim() === "This screen",
|
|
) as HTMLElement | undefined;
|
|
btn?.click();
|
|
return {
|
|
offered: !!btn,
|
|
marked: document.querySelectorAll(".fcw-selected").length,
|
|
panel: !!r.querySelector(".panel"),
|
|
chip: (r.querySelector(".scopebtn") as HTMLElement | null)?.innerText ?? "",
|
|
};
|
|
});
|
|
ok(picked.offered, "Point to area offers This screen beside tapping an element");
|
|
ok(picked.marked >= 1, `This screen marks what is on screen (${picked.marked})`);
|
|
ok(
|
|
picked.panel && /area/.test(picked.chip),
|
|
`…and the conversation opens with it attached (${picked.chip})`,
|
|
);
|
|
ok(s.errors.length === 0, `no page errors (${s.errors.join("; ")})`);
|
|
await s.close();
|
|
}
|
|
|
|
// ---- a visitor: no pill, no recording ----
|
|
{
|
|
const s = await open(browser, js, "");
|
|
ok((await pillText(s.p)) === null, "a visitor gets no pill");
|
|
await s.p.click("#buy");
|
|
await s.p.waitForTimeout(600);
|
|
ok(s.reports.length === 0, "a visitor's failures are not reported automatically");
|
|
await s.close();
|
|
}
|
|
|
|
await browser.close();
|
|
console.log(`widget-watch-browser: ${pass} passed, ${fail} failed`);
|
|
if (fail) process.exit(1);
|
|
}
|
|
|
|
void main();
|