mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 02:57:00 +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>
79 lines
3.1 KiB
TypeScript
79 lines
3.1 KiB
TypeScript
/**
|
|
* "Continue in Loki": carrying the panel's conversation into Loki itself.
|
|
*
|
|
* The panel is where a site's owner first says what they want — on their
|
|
* phone, on the live page, in a 372px card. It is the wrong place to develop
|
|
* the idea: no project context, no files, no run to watch. On 2026-10-09 the
|
|
* owner wrote "Read the conversation and switch to Loki so I can develop it
|
|
* there with either chat or terminal interface" and the widget answered with
|
|
* the same advice a third time, because nothing in it knew what Loki was.
|
|
*
|
|
* Two pure pieces: the thread as one message Loki's chat can start from, and
|
|
* the link that takes the person there. The link goes through Loki's server
|
|
* (src/app/api/widget/continue/route.ts), which signs them in if needed,
|
|
* checks they may work on this widget's project, resolves the project, and
|
|
* lands them in /loki with this text in the composer — or in /terminal on the
|
|
* project. The widget never learns the project's name; it only holds a token.
|
|
*/
|
|
import type { ThreadItem } from "./thread";
|
|
|
|
/** The composer in /loki takes 4000; the address bar should stay well under it. */
|
|
export const HANDOFF_MAX = 1800;
|
|
const LOKI_TURN_MAX = 280;
|
|
|
|
export type ContinueView = "chat" | "terminal";
|
|
|
|
function line(item: ThreadItem): string {
|
|
const clip = (t: string) => (t.length > LOKI_TURN_MAX ? `${t.slice(0, LOKI_TURN_MAX - 1)}…` : t);
|
|
switch (item.kind) {
|
|
case "you":
|
|
return `Me: ${item.text}`;
|
|
case "loki":
|
|
return `Loki: ${clip(item.text)}`;
|
|
case "noticed":
|
|
return `Loki noticed: ${clip(item.text)}`;
|
|
default:
|
|
return `Sent to the builder: ${item.text}`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The thread as one message, newest turns kept when it has to be cut: the
|
|
* person's own words in full, Loki's answers clipped, receipts as one line.
|
|
* The page it happened on leads, so the chat knows which site this is about
|
|
* before reading a word of it.
|
|
*/
|
|
export function handoffText(
|
|
thread: readonly ThreadItem[],
|
|
page: { title: string; url: string },
|
|
max = HANDOFF_MAX,
|
|
): string {
|
|
const head = `From Loki on “${page.title.trim() || page.url}” (${page.url}):`;
|
|
const lines = thread.map(line);
|
|
// Drop the oldest first: what they said last is what they want to go on with.
|
|
while (lines.length && [head, "", ...lines].join("\n").length > max) lines.shift();
|
|
if (!lines.length) return head.slice(0, max);
|
|
return [head, "", ...lines].join("\n");
|
|
}
|
|
|
|
/**
|
|
* The link into Loki. A top-level navigation (Loki's session cookie is
|
|
* first-party there), never a fetch. `here` is where the person was, so that
|
|
* someone who turns out not to own the site can be sent back to it with a
|
|
* word rather than left on an error page.
|
|
*/
|
|
export function continueUrl(opts: {
|
|
apiBase: string;
|
|
token: string;
|
|
view: ContinueView;
|
|
text: string;
|
|
here: string;
|
|
}): string {
|
|
const u = new URL("/api/widget/continue", opts.apiBase);
|
|
u.searchParams.set("token", opts.token);
|
|
u.searchParams.set("view", opts.view);
|
|
if (opts.text.trim()) u.searchParams.set("q", opts.text.slice(0, HANDOFF_MAX));
|
|
u.searchParams.set("return", opts.here.split("#")[0]);
|
|
return u.href;
|
|
}
|