mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-05 03:47:53 +01:00
* feat(widget): Ask Loki for a second opinion; hiding is visible and reversible Tested the embed in a real browser and found three install/hide defects: - a `type="module"` tag rendered nothing (document.currentScript is null); - two copies of the tag rendered two launchers; - hiding lived only behind a long-press/right-click and was one-way: after a reload nothing, not even the host's own Loki.report(), brought it back. Fixes: find the tag by its attribute when currentScript is null; a boot-in- flight guard keeps one widget per page; "Hide this button on this site" sits at the foot of the panel with an Undo toast, and #loki, Loki.show(), report() and ask() all restore it. New Ask Loki mode (on by default next to "Request a change"): the person the site was built for asks whether an element, the page or the whole site should change and why it is the way it is. The widget builds a text outline in the visitor's browser (a few same-origin pages for "Whole site") and POSTs it to /api/widget/advise — same token, origin allowlist, rate limits and owner AI budget as widget chat. The answer may say "leave it"; each recommended change has "Request this", which prefills Report so advice becomes ordinary Implement work. data-fc-modes="report" opts a site out. Tests: scripts/test/widget-embed-browser.ts (real Chromium; fails on the old bundle) and scripts/test/widget-advise.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EsT2PtLuBKwgaaBU5pheG8 * refactor(widget): move panel pieces out of main.ts to meet the function-length ratchet CI lint failed: the main IIFE grew to 597 lines (max-lines-per-function 510). The success views, scope chips, mode tabs and hide toast move to widget/panel-views.ts; the counter/Send sync is one helper. No behaviour change — widget-embed-browser (31) and widget-host-avoid-browser (17) pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EsT2PtLuBKwgaaBU5pheG8 --------- Co-authored-by: Claude <noreply@anthropic.com>
27 lines
1.4 KiB
TypeScript
27 lines
1.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import {
|
|
defaultWidgetSurfaceMode,
|
|
initialWidgetSurfaceMode,
|
|
parseWidgetSurfaceModes,
|
|
WIDGET_SURFACE_MODE_META,
|
|
} from "../../widget/surface-modes";
|
|
|
|
assert.equal(defaultWidgetSurfaceMode(), "report");
|
|
// No attribute: request a change, or ask Loki first. Explicit lists are kept as written.
|
|
assert.deepEqual(parseWidgetSurfaceModes(null), ["report", "ask"]);
|
|
assert.deepEqual(parseWidgetSurfaceModes("report"), ["report"]);
|
|
assert.deepEqual(parseWidgetSurfaceModes("ask,report"), ["ask", "report"]);
|
|
assert.deepEqual(parseWidgetSurfaceModes("report,chat,watch"), ["report", "chat", "watch"]);
|
|
// The embed's order is kept: the first listed mode is the one the panel opens in.
|
|
assert.deepEqual(parseWidgetSurfaceModes("chat, report, chat, nonsense"), ["chat", "report"]);
|
|
assert.deepEqual(parseWidgetSurfaceModes("nonsense"), ["report", "ask"]);
|
|
assert.equal(initialWidgetSurfaceMode(["chat", "report"]), "chat");
|
|
assert.equal(initialWidgetSurfaceMode(["report", "chat"]), "report");
|
|
// An unshipped mode listed first is skipped rather than opening a dead tab.
|
|
assert.equal(initialWidgetSurfaceMode(["watch", "chat"]), "chat");
|
|
assert.equal(WIDGET_SURFACE_MODE_META.report.shipped, true);
|
|
assert.equal(WIDGET_SURFACE_MODE_META.chat.shipped, true);
|
|
assert.equal(WIDGET_SURFACE_MODE_META.ask.shipped, true);
|
|
assert.equal(WIDGET_SURFACE_MODE_META.watch.shipped, false);
|
|
console.log("widget-surface-modes: ok");
|