Files
loki/widget/continue-row.ts
T
CatoandClaude Fable 5.1 6c6380efb7 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 (#1107)
* 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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-09 04:12:00 -07:00

66 lines
2.4 KiB
TypeScript

/**
* The row under the composer that leads out of the card and into Loki.
*
* The panel is for saying what you want; developing it — with the project,
* its files and a run to watch — is Loki's chat or terminal. The owner asked
* for exactly this ("switch to Loki so I can develop it there with either
* chat or terminal") and the widget had no answer. Now the thread travels
* with them. Someone without a pass gets one link, because the same trip
* signs them in and finds out whether the site is theirs.
*/
import { h } from "./dom";
import { continueUrl, handoffText } from "./continue";
import type { ThreadItem } from "./thread";
export function createContinueRow(opts: {
apiBase: string;
token: string;
thread: () => readonly ThreadItem[];
owner: () => boolean;
}) {
const el = h("div", "continue");
const label = h("span", "continue-label", "Continue in Loki");
const chat = h("a", "continue-link", "Chat →");
const term = h("a", "continue-link", "Terminal →");
const mine = h("a", "continue-link", "This is my site — continue in Loki →");
for (const a of [chat, term, mine]) {
a.target = "_blank";
a.rel = "noopener";
}
chat.title = "Loki's chat on this project, with this conversation in the message box";
term.title = "The project's terminal in Loki";
mine.title = "Sign in with Loki; this conversation goes with you";
el.append(label, chat, term, mine);
/** Re-aim the links at the thread as it is now, and show the right ones. */
function sync() {
const thread = opts.thread();
const text = handoffText(thread, { title: document.title, url: location.href });
for (const [a, view] of [
[chat, "chat"],
[term, "terminal"],
[mine, "chat"],
] as const) {
a.href = continueUrl({
apiBase: opts.apiBase,
token: opts.token,
view,
text,
here: location.href,
});
}
// The owner always has both doors. A visitor sees the one link once they
// have said something worth taking along — on an empty thread it would
// only be a second sign-in button.
const owner = opts.owner();
const said = thread.some((i) => i.kind === "you");
label.style.display = owner ? "" : "none";
chat.style.display = owner ? "" : "none";
term.style.display = owner ? "" : "none";
mine.style.display = !owner && said ? "" : "none";
el.style.display = owner || said ? "" : "none";
}
return { el, sync };
}