Files
loki/scripts/test/read-website.ts
CatoandClaude Opus 5.5 95383b92db Improve a live site as a private preview; consultation reads the whole site and talks (#1234)
* feat(change): improve a live site as a private preview, with a site tour and a consultation that talks

"Improve this site" created a GitHub repository per click and a kickoff that
told the agent to "treat the repository as possibly empty" — for a site that
already exists. Two clicks made two repos (center-com, center-com-2), and the
owner had nothing to show their client but a run log.

- /change builds a PREVIEW (lib/previews/from-website): folder + local git,
  <name>.orangecat.ch behind the access code, widget on it. No repository until
  the client says yes; servers without previews fall back to the repo path.
  Repeat submits resume the same preview. An access code is created when the
  operator has none.
- The brief starts from the live site and asks for improvements.html, a tour
  of what changed (live page vs new page), so the client SEES the improvement.
  "Watch it work" shows the link, code, tour and a copy-ready client message.
- The consultation reads the homepage AND the pages it links to
  (site-consult/crawl, bounded, same SSRF-guarded fetch), with site-wide checks:
  broken links, duplicate titles, thin pages.
- It is a conversation now: what Loki read, its advice on what to fix first,
  what already works, then two one-tap questions whose answers become brief
  lines from config.
- Loki chat's read_website reads up to five linked pages and returns the
  consultation as advice.

Fixes from the owner's screenshots:
- Owner launcher on phones drops the "Loki · watching" label and fades while
  scrolling — it was covering "It worked" and card buttons.
- Tapped labels no longer glue count badges on ("Feedback to triage11").
- The widget no longer files Loki's own app polls (/api/feedback/summary) or
  navigation-cut requests as its failures ("never answered after 0.3s").
- Live-check evidence speaks as Loki, not "The provided page text…".
- Watch: "Waiting to start · started just now / Queued" → "Next in line ·
  asked just now / Waiting for a builder to pick it up."
- Session box: an agent's "request access to the widget storage and dump
  submissions" suggestion is replaced by the Attach-feedback action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zCRuBPv8KpyTPkh6JsSYt

* fix(feedback): keep evidence wording pure so the inbox client bundle builds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zCRuBPv8KpyTPkh6JsSYt

* test(widget): read the owner launcher's words, not its pixels

On phones the owner label is now hidden so it stops covering the page; the
accessible name still says Loki is watching.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zCRuBPv8KpyTPkh6JsSYt

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-16 17:29:03 +00:00

45 lines
1.4 KiB
TypeScript

import assert from "node:assert/strict";
import { readWebsite } from "@/lib/agent/tools/read-website";
import type { PageFetch } from "@/lib/site-consult/fetch-page";
async function main() {
const seen: string[] = [];
const fake = async (url: string): Promise<PageFetch> => {
seen.push(url);
return {
ok: true,
requestedUrl: url,
finalUrl: url,
html: '<a href="/about">About</a><a href="https://other.test">Elsewhere</a><a href="/care">Care</a><a href="/more">More</a>',
headers: { robots: "" },
ms: 1,
bytes: 100,
truncated: false,
};
};
const pages = await readWebsite("https://petvity.test/", fake);
assert.equal(pages.length, 4);
assert.deepEqual(seen, [
"https://petvity.test/",
"https://petvity.test/about",
"https://petvity.test/care",
"https://petvity.test/more",
]);
assert.deepEqual(pages.siteMap, [
"https://petvity.test/about",
"https://petvity.test/care",
"https://petvity.test/more",
]);
const failure = await readWebsite("https://unavailable.test", async (url) => ({
ok: false,
requestedUrl: url,
reason: "HTTP 503",
}));
assert.equal(failure.length, 1);
assert.equal(failure[0].ok, false);
console.log("✓ fresh site reading follows up to five same-origin pages and preserves failures");
}
main().catch((e) => {
console.error(e);
process.exitCode = 1;
});