Files
loki/scripts/test/answer-citations.ts
CatoandClaude ddea79f5cc fix(loki): what talking to the live chat turned up (#1213)
Found by using loki.orangecat.ch as a new, non-technical account:

- "Yes, create it" under Loki's own suggestion was sent to the only
  project as a build task. A bare yes is now a reply: it runs the one
  ready-to-send line the previous answer ended with, or stays in chat.
- A newcomer's private zone (approvals, commitments, people) was locked
  behind the founder's env PIN, which every PIN-less account inherited —
  a dead end for them, and the founder's PIN opened all of them. The env
  PIN now gates the owner account only.
- Loki did not know the date: "dentist on Monday" came back as "the date
  for Monday is not in your data". Every turn now carries the time in
  the person's own zone, and drafts lead with what was drafted.
- "What did I ask you today?" got "no record of any request". Recent
  threads are now a source Loki reads when asked about them.
- A refused dispatch left its run WAITING forever (six phantom runs);
  it is now closed as undelivered, quietly, since the reply says so.
- The fleet fact said "OFFLINE — nothing can run" to an account that
  can never use the cloud builder, so Loki told it to restart a runner.
  It now says which is true and the way forward; the prompt asks for
  plain words and no "restart Loki's services" advice.
- A system-prompt example leaked the owner's project into strangers'
  answers ("sink: bring runner online…").
- Citations were eight 44px "Source" buttons inline; now one per
  paragraph, at its end.
- Thread titles were cut by reasoning tokens ("Bring") and repeated the
  project shown right beside them.


Claude-Session: https://claude.ai/code/session_01CG9dupSVqoXCCqKfBCfd9B

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-15 05:29:23 -07:00

54 lines
2.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React, { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { MarkdownText } from "../../src/components/ui/markdown-text";
Object.assign(globalThis, { React });
/**
* Citations in a Loki answer: out of the sentence, one Sources button per
* paragraph. Case from the live site (2026-10-15): eight inline "Source"
* buttons, each 44px tall, made one answer unreadable.
*/
let passed = 0;
function check(label: string, cond: boolean): void {
if (!cond) throw new Error(`✗ ${label}`);
passed++;
console.log(` ✓ ${label}`);
}
const citations = {
F1: { label: "Runner", detail: "offline" },
F2: { label: "Runs", detail: "5 waiting" },
F5: { label: "Goals", detail: "none" },
F7: { label: "Commitments", detail: "none" },
};
const html = (text: string) =>
renderToStaticMarkup(createElement(MarkdownText, { text, citations }));
const count = (s: string, needle: string) => s.split(needle).length - 1;
const one = html(
"The runner is offline [F1] and five runs wait [F2]. No goals or commitments [F5]–[F7], so nothing else blocks.",
);
check("no raw handle left in the prose", !/\[[FD]\d/.test(one));
check("one sources button for the paragraph", count(one, "ui-loki-cite") === 1);
check("it opens all four records", one.includes("View 4 sources"));
check("punctuation closes up where a handle was", one.includes("offline and five runs wait."));
check("a range leaves no stray dash", one.includes("commitments, so"));
const two = html("First claim [F1].\n\nSecond claim [F2].\n\nNo claim here.");
check("each citing paragraph gets its own button", count(two, "ui-loki-cite") === 2);
const unknown = html("A claim [F9].");
check(
"an unknown handle shows nothing",
!unknown.includes("ui-loki-cite") && unknown.includes("A claim."),
);
const bare = renderToStaticMarkup(createElement(MarkdownText, { text: "No resolver [F1]." }));
check(
"without a resolver the handle is dropped",
bare.includes("No resolver.") && !bare.includes("ui-loki-cite"),
);
const list = html("- one [F1]\n- two");
check("a list item carries its own button", count(list, "ui-loki-cite") === 1);
console.log(`\nanswer-citations: ${passed} passed`);