mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 11:48:24 +01:00
* feat(widget): the owner's way into Loki — Continue in Loki, an advisor that knows whose site it is, a header that fits a phone On 2026-10-09 the owner of heidi.orangecat.ch opened the widget on their phone and asked for one new page. The widget treated them as a stranger: it told them which heading to insert and to "keep the structure in a data file (JSON/YAML)", wrote five invented sentences in the site's own language, and answered "switch to Loki so I can develop it there with either chat or terminal" with the same advice a third time. The owner's sign-in lived only behind "Watch". Once signed in, Review + Stop watching pushed ✕ off the right edge of the screen. - widget/continue.ts + src/lib/widget/continue.ts: the thread as one message (newest kept, ≤1800 chars) and where it lands in Loki. - GET /api/widget/continue: signs the person in if needed, checks getProjectAccess on the widget's project, resolves the project key and redirects into /loki?project=&q= or /terminal?project=&view=terminal; a stranger goes back to the site with #loki-owner-denied. - widget/conversation.ts: "Continue in Loki · Chat → · Terminal →" under the composer for the owner; one sign-in link for anyone else after their first message; "This is my site — sign in with Loki →" under Loki's greeting, on the first screen. The owner pass travels with each question. - /api/widget/advise + advisor.ts: the pass is verified as ingest verifies it; with it the advisor knows the person OWNS the site and Build this builds. For everyone, four hands-off rules: never explain how to edit the site, never write its content, a build request becomes the one change to tap, and "take this into Loki" is answered with where that control is. - widget/theme.ts: the header's text column shrinks before the actions do; Stop watching stays on one line; the continue row wraps on a phone. - widget/main.ts: the owner is not offered to hide their own tool. - scripts/test/widget-continue.ts (new), widget-advise.ts: pinned. - docs/architecture/feedback-widget.md: the row and the route. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * feat(widget): the loop closes on the site — Your changes, a live announcement, an honest Follow link "On it — Loki tells you when" was the end of the widget's story, and on the site Loki never told anyone: the telling went to push and Telegram, the page the owner came back to said nothing, and "Follow the build" toured the unchanged page with "let me show you what changed". - widget/changes.ts: "Your changes" above the thread for the owner — the project's recent changes with one word each (Building · On its way · Live · Needs you …), See it → once live, Open in Loki → when something needs them, asked for on arrival and every 30 s while something moves. A change this browser saw building that is now live is announced once: in the thread when the panel is open, beside the launcher (bubble + unread) when it is not. - POST /api/widget/owner/changes: the one read with the owner pass. Same attachFeedbackWork the inbox uses, then src/lib/feedback/owner-view.ts writes the owner's words; the work view never leaves the server. No valid pass → no rows. - /feedback/<id>/watch-fix lands on the inbox row while the change is still being built; the walkthrough only once it is live. - The owner's repeated note keeps its follow link. - widget/continue-row.ts, widget/greeting.ts: split out of createConversation (the lint rule caps it at 510 lines; CI caught it at 543). - scripts/test/widget-changes.ts (new); widget-continue.ts updated. - docs/architecture/feedback-widget.md. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * fix(widget): the owner's door is not an .act — the embed test counts those widget-embed-browser asserts exactly one "as written" link (.act) under the visitor's last message; the sign-in door under the greeting shared the class and made it two. Its own class, same look. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * feat(public): three ways in — build it yourself, with a partner, or let the studio — and every stranger's door ends at /build The ways to get something built were scattered: the landing page offered only "Start a project", hiring the studio was a word in the nav, the partner directory was reachable from OrangeCat's careers page and nowhere here, and a stranger who watched a fix land on someone else's site was sent to a bare homepage. "Start a project" at the bottom of six marketing pages went to sign-IN, and so did a stranger arriving with a brief. - src/config/build-paths.ts: the one list — yourself (sign-up), with a partner (bitbaum.orangecat.ch/partners/), the studio (the commission config's hire address) — plus buildPageHref/fromHost. - /build (public, allowlisted): the invitation, naming the site the person came from (validated host only) and the three doors (BuildPaths cards). - Landing: the "Three ways in" section after "Who it is for"; the closing line and FinalCta name the other two ways; FinalCta → sign-up. - /change and /take send a signed-out person to sign-up with the brief kept. - Widget: "Made with Loki — build something of your own →" as the last line for anyone who is not the owner (/build?from=<host>); the tour's "Get this for your site" lands on /build naming the site; the concierge gets the same door (appended last — the test addresses the others by index). - scripts/test/build-paths.ts pins all of it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * fix(widget): /api/widget/continue is public — it signs the person in itself Live, the merged route answered a bare 401: the session middleware caught it before the route could send the person to sign-in. Same list entry as /api/widget/owner, pinned by widget-continue.ts. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * test(audit): /build is measured by the responsive audit A new page has to be a decision — measured, or excluded with a reason. Measured: it is a public page a stranger lands on from a phone. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * fix(widget): yours means yours, a review that picks three, the composer above the keyboard From the owner's phone on 2026-10-09: - "Your changes" listed a stranger's "so nice picture!" as the owner's own request. The strip now shows what the owner asked for and what Loki filed itself; visitors' notes are counted ("3 notes from visitors, in Loki →"). - Review answered with five nits (alt text, a renamed button, a table) and five identical buttons. The rubric now asks for at most three changes a visitor would notice or that fix something broken, and says none is fine. - With the keyboard open the box being typed into sat half behind it; it scrolls into view once the keyboard has settled. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * feat: the first day is the whole product — your website in onboarding, Loki on it, help doors when a build stalls, the terminal hand-off with its text, a launcher that stays in the corner From the owner's phone on 2026-10-09, and the three follow-ups named then: - Onboarding asks for the website (optional). A project created with one (`liveUrl` on POST /api/user-projects) gets its widget token at once, so the token's origin is the site's; the new step "Put Loki on your site" shows the one line to paste, lets an agent add it when there is a repo, and opens the site with the owner pass (`openSiteUrl` on the token route). Finishing lands on the project, not Control. A refused project no longer advances the step in silence. - A stalled build and a failed kickoff offer the other two ways to get it built — find a partner, hire the studio — from the same list as the landing page (GetHelpLine), the studio with the brief. - "Continue in Loki → Terminal" carries the thread: /terminal?q= prefills the rail's composer as an unsent draft, and opens the rail sheet on a phone (the same path ?explain=1 takes). - The launcher stays in the corner: a near slot over plain text beats a free slot mid-page (heidi.orangecat.ch: the site's own bar took one corner and the launcher floated beside a heading). A near sheet still sends it climbing. - Page checks: a small-caps label by design is not a defect, 11.84px is not under 12, and one kind of finding is one card (the signature drops counts and examples; "30 pieces" then "6 pieces" were two cards). Tests: onboarding-site-step.ts (new), widget-placement.ts, widget-watch.ts, widget-continue.ts, build-paths.ts; all widget browser suites pass locally. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * refactor(widget): keepInViewOnFocus lives in dom.ts — createConversation back under the 510-line cap after the merge Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z * fix(widget): import keepInViewOnFocus — the panel threw at mount and boot swallowed it An unimported identifier compiles fine with esbuild and fails at run time; boot's catch hid it, so the launcher rendered and the panel never opened. Caught by widget-embed-browser. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1Yw4cCwXWRP2S5Hj62u2Z --------- Co-authored-by: Claude <noreply@anthropic.com>
246 lines
9.7 KiB
TypeScript
246 lines
9.7 KiB
TypeScript
// Watch mode's trail and reports: privacy by construction (labels, never
|
|
// values; paths, never query strings), one report per distinct failure, and a
|
|
// report that names what broke before what led there.
|
|
// Run: npx tsx scripts/test/widget-watch.ts
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
describeControl,
|
|
describeRequest,
|
|
failureSignature,
|
|
freshTrail,
|
|
isFailedRequest,
|
|
isNoiseError,
|
|
isNoticeableRequest,
|
|
nextTapStreak,
|
|
noticeCount,
|
|
pushTrail,
|
|
REVIEW_SESSION_MAX,
|
|
sessionForReview,
|
|
SLOW_REQUEST_MS,
|
|
TRAIL_MAX,
|
|
TRAIL_MAX_AGE_MS,
|
|
watchReport,
|
|
explainChecks,
|
|
checksSignature,
|
|
explainNotice,
|
|
noticeSignature,
|
|
type TrailEntry,
|
|
} from "../../widget/watch-trail";
|
|
import { buildSuggestion } from "../../widget/report-payload";
|
|
|
|
let n = 0;
|
|
const check = (fn: () => void) => {
|
|
fn();
|
|
n++;
|
|
};
|
|
|
|
check(() => {
|
|
assert.equal(
|
|
describeControl({ tag: "BUTTON", text: " Save\n project " }),
|
|
"button “Save project”",
|
|
);
|
|
assert.equal(describeControl({ tag: "a", label: "Open profile" }), "link “Open profile”");
|
|
// An input is named by its placeholder — what was typed never appears.
|
|
assert.equal(
|
|
describeControl({ tag: "input", type: "email", placeholder: "Your email" }),
|
|
"email field “Your email”",
|
|
);
|
|
assert.equal(describeControl({ tag: "div", role: "button" }), "button");
|
|
});
|
|
check(() => {
|
|
assert.equal(
|
|
describeRequest("post", "https://orangecat.ch/api/projects?token=secret", 500),
|
|
"POST /api/projects → 500",
|
|
);
|
|
assert.equal(describeRequest("get", "/shop/x", null), "GET /shop/x → no response");
|
|
assert.equal(isFailedRequest(500), true);
|
|
assert.equal(isFailedRequest(null), true);
|
|
assert.equal(isFailedRequest(404), false);
|
|
});
|
|
check(() => {
|
|
let t: TrailEntry[] = [];
|
|
for (let i = 0; i < TRAIL_MAX + 5; i++) t = pushTrail(t, { at: i, kind: "tap", text: `b${i}` });
|
|
assert.equal(t.length, TRAIL_MAX);
|
|
const before = t.length;
|
|
t = pushTrail(t, { at: 99, kind: "tap", text: `b${TRAIL_MAX + 4}` });
|
|
assert.equal(t.length, before, "a repeat of the last entry is one fact");
|
|
});
|
|
check(() => {
|
|
assert.equal(isNoiseError("ResizeObserver loop limit exceeded"), true);
|
|
assert.equal(isNoiseError("Script error."), true);
|
|
assert.equal(isNoiseError("TypeError: cannot read properties of undefined"), false);
|
|
assert.equal(
|
|
failureSignature({ kind: "request", text: "GET /api/projects/123 → 500" }),
|
|
failureSignature({ kind: "request", text: "GET /api/projects/456 → 500" }),
|
|
);
|
|
});
|
|
check(() => {
|
|
const trail: TrailEntry[] = [
|
|
{ at: 1000, kind: "page", text: "/projects" },
|
|
{ at: 3000, kind: "tap", text: "button “Create”" },
|
|
];
|
|
const r = watchReport({ kind: "request", text: "POST /api/projects → 500" }, trail, 5000);
|
|
assert.match(r.message, /request failed: POST \/api\/projects → 500/);
|
|
assert.equal(r.diagnostics["step 2"], "tap button “Create” (2s ago)");
|
|
const s = buildSuggestion(r.message, r.diagnostics, 2000);
|
|
assert.ok(s.length <= 2000 && s.includes("failure: POST /api/projects → 500"));
|
|
});
|
|
|
|
check(() => {
|
|
// Three taps on one button inside the window: dead. A field, a gap, or a
|
|
// different button in between: not.
|
|
let r = nextTapStreak(null, "button “Pay”", 0);
|
|
r = nextTapStreak(r.streak, "button “Pay”", 1000);
|
|
assert.equal(r.dead, false);
|
|
r = nextTapStreak(r.streak, "button “Pay”", 2000);
|
|
assert.equal(r.dead, true);
|
|
let f = nextTapStreak(null, "email field “Your email”", 0);
|
|
f = nextTapStreak(f.streak, "email field “Your email”", 100);
|
|
f = nextTapStreak(f.streak, "email field “Your email”", 200);
|
|
assert.equal(f.dead, false, "fields are tapped to focus");
|
|
let g = nextTapStreak(null, "button “Pay”", 0);
|
|
g = nextTapStreak(g.streak, "button “Pay”", 1000);
|
|
g = nextTapStreak(g.streak, "button “Pay”", 9000);
|
|
assert.equal(g.dead, false, "outside the window it starts again");
|
|
const rep = watchReport({ kind: "dead-tap", text: "button “Pay”" }, [], 0);
|
|
assert.match(rep.message, /tapped button “Pay” three times and nothing happened/);
|
|
});
|
|
|
|
// ---- Review: what a reviewer remarks on that is not a failure ----
|
|
check(() => {
|
|
assert.equal(describeRequest("get", "/a?x=1", 200, 4230), "GET /a → 200 in 4.2s");
|
|
assert.equal(isNoticeableRequest(404, 50), true, "a 404 is worth a remark");
|
|
assert.equal(isNoticeableRequest(200, SLOW_REQUEST_MS), true, "so is a slow answer");
|
|
assert.equal(isNoticeableRequest(200, 120), false);
|
|
// 5xx and no-answer are failures (they file a fix) — never also a remark.
|
|
assert.equal(isNoticeableRequest(500, 9000), false);
|
|
assert.equal(isNoticeableRequest(null, 9000), false);
|
|
});
|
|
|
|
check(() => {
|
|
const now = 10_000_000;
|
|
const kept = freshTrail(
|
|
[
|
|
{ at: now - TRAIL_MAX_AGE_MS - 1, kind: "tap", text: "yesterday" },
|
|
{ at: now - 1000, kind: "tap", text: "button “Go”" },
|
|
{ at: now - 500, kind: "bogus", text: "x" },
|
|
{ at: "soon", kind: "tap", text: "x" },
|
|
{ at: now + 60_000, kind: "tap", text: "from the future" },
|
|
null,
|
|
],
|
|
now,
|
|
);
|
|
assert.deepEqual(kept, [{ at: now - 1000, kind: "tap", text: "button “Go”" }]);
|
|
assert.deepEqual(freshTrail("not json array", now), [], "stored garbage is an empty trail");
|
|
});
|
|
|
|
check(() => {
|
|
const t: TrailEntry[] = [
|
|
{ at: 0, kind: "page", text: "/shop" },
|
|
{ at: 1_000, kind: "tap", text: "button “Buy”" },
|
|
{ at: 1_200, kind: "notice", text: "POST /cart → 404 in 0.2s" },
|
|
{ at: 45_000, kind: "tap", text: "link “Help”" },
|
|
];
|
|
assert.equal(noticeCount(t), 1);
|
|
const s = sessionForReview(t, ["2 image(s) have no alt text"], 90_000);
|
|
assert.match(s, /page \/shop\ntap button “Buy”\nnotice POST \/cart → 404/);
|
|
assert.match(s, /\(paused 44s\)\ntap link “Help”/, "a long stop before a step is written out");
|
|
assert.match(s, /nothing for 45s, then asked for this review/);
|
|
assert.match(s, /Checks on the page they are on now:\n- 2 image\(s\) have no alt text/);
|
|
});
|
|
|
|
check(() => {
|
|
// Too long: the OLDEST steps go, the checks and the newest steps stay.
|
|
const t: TrailEntry[] = Array.from({ length: TRAIL_MAX }, (_, i) => ({
|
|
at: i,
|
|
kind: "tap" as const,
|
|
text: `button “${String(i).padStart(3, "0")} ${"x".repeat(140)}”`,
|
|
}));
|
|
const s = sessionForReview(t, ["check A"], TRAIL_MAX);
|
|
assert.ok(s.length <= REVIEW_SESSION_MAX, `capped (${s.length})`);
|
|
assert.ok(s.includes(`button “${String(TRAIL_MAX - 1).padStart(3, "0")}`), "newest kept");
|
|
assert.ok(!s.includes("button “000"), "oldest dropped");
|
|
assert.ok(s.endsWith("- check A"), "checks survive the cut");
|
|
});
|
|
|
|
// ---- Loki speaks up: each remark in plain words, with the fix it would send ----
|
|
check(() => {
|
|
const nf = explainNotice({
|
|
kind: "4xx",
|
|
text: "GET /hours → 404",
|
|
after: "button “Opening hours”",
|
|
});
|
|
assert.equal(
|
|
nf.say,
|
|
"After you tapped button “Opening hours”, the page asked for /hours and it found nothing there (404).",
|
|
);
|
|
assert.match(
|
|
nf.fix,
|
|
/^Fix the request to \/hours after tapping button “Opening hours”: it answers 404\.$/,
|
|
);
|
|
// No tap to blame: the sentence still stands on its own.
|
|
assert.match(
|
|
explainNotice({ kind: "4xx", text: "POST /cart → 403" }).say,
|
|
/^the page asked for \/cart and it was refused — not allowed\.$/,
|
|
);
|
|
assert.match(
|
|
explainNotice({ kind: "4xx", text: "GET /x → 418" }).say,
|
|
/was rejected \(418\)/,
|
|
"an unlisted status still reads",
|
|
);
|
|
assert.match(
|
|
explainNotice({ kind: "slow", text: "GET /api/menu → 200 in 4.2s" }).say,
|
|
/waited 4\.2s for \/api\/menu/,
|
|
);
|
|
assert.match(
|
|
explainNotice({ kind: "console", text: "console error: x is undefined" }).say,
|
|
/“x is undefined”/,
|
|
);
|
|
assert.match(
|
|
explainNotice({ kind: "load", text: "this page took 4.1s to load" }).say,
|
|
/it took 4\.1s to load/,
|
|
);
|
|
const freeze = explainNotice({
|
|
kind: "longtask",
|
|
text: "after button “Load more” the page froze for 450ms (taps go unanswered meanwhile)",
|
|
});
|
|
assert.match(freeze.say, /^After button “Load more” the page froze for 450ms/);
|
|
assert.equal(freeze.fix, "Stop the page freezing after button “Load more”.");
|
|
assert.match(explainNotice({ kind: "cls", text: "content jumped around" }).fix, /jumping around/);
|
|
});
|
|
|
|
check(() => {
|
|
assert.equal(explainChecks([]), null, "a clean page gets no remark — silence is right");
|
|
// One finding, two counts, two examples: one signature.
|
|
assert.equal(
|
|
checksSignature("/p", ["30 piece(s) of text are under 12px (e.g. “Partners” at 11.84px)"]),
|
|
checksSignature("/p", [
|
|
"6 piece(s) of text are under 12px (e.g. “AI-native studio” at 11.5px)",
|
|
]),
|
|
"the same kind of finding is said once, whatever the count or example",
|
|
);
|
|
assert.notEqual(
|
|
checksSignature("/p", ["2 image(s) have no alt text"]),
|
|
checksSignature("/p", ["The page has no main heading (h1)"]),
|
|
"a different finding is a different signature",
|
|
);
|
|
assert.notEqual(checksSignature("/p", ["x"]), checksSignature("/q", ["x"]), "per path");
|
|
const c = explainChecks(["2 image(s) have no alt text", "The page has no main heading (h1)"])!;
|
|
assert.match(
|
|
c.say,
|
|
/2 things stand out:\n• 2 image\(s\) have no alt text\n• The page has no main heading/,
|
|
);
|
|
assert.match(c.fix, /^Fix these on this page:\n• 2 image/);
|
|
assert.equal(
|
|
c.short,
|
|
"2 things on this page could be better",
|
|
"the bar's one line never ends on a colon",
|
|
);
|
|
// One remark per cause per page: numbers do not make it new, another page does.
|
|
const a = noticeSignature("/shop", { kind: "slow", text: "GET /a → 200 in 4.2s" });
|
|
assert.equal(a, noticeSignature("/shop", { kind: "slow", text: "GET /a → 200 in 5.9s" }));
|
|
assert.notEqual(a, noticeSignature("/cart", { kind: "slow", text: "GET /a → 200 in 4.2s" }));
|
|
});
|
|
|
|
console.log(`${n} widget-watch cases passed`);
|