Files
loki/scripts/test/loki-thread-title.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

63 lines
2.6 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 assert from "node:assert/strict";
import {
buildThreadTitlePrompt,
isAutoTitle,
parseThreadTitle,
THREAD_TITLE_INPUT_CHARS,
THREAD_TITLE_MAX_CHARS,
} from "../../src/lib/loki/thread-title";
// Clean replies pass through, capitalised.
assert.equal(parseThreadTitle("checkout bug on kivvi"), "Checkout bug on kivvi");
assert.equal(parseThreadTitle("Pricing page copy\n"), "Pricing page copy");
// Model habits are stripped: quotes, markdown, a label, filler, punctuation.
assert.equal(parseThreadTitle('"Deploy pipeline review"'), "Deploy pipeline review");
assert.equal(parseThreadTitle("**Zurich move plan**"), "Zurich move plan");
assert.equal(parseThreadTitle("Title: Loki rail states."), "Loki rail states");
assert.equal(parseThreadTitle("Chat about the onboarding flow"), "The onboarding flow");
assert.equal(parseThreadTitle("«Umzug nach Zürich»"), "Umzug nach Zürich");
assert.equal(parseThreadTitle("\n\n Kivvi invoices \nsecond line"), "Kivvi invoices");
// Nothing usable → null, so the caller keeps what the thread had.
assert.equal(parseThreadTitle(""), null);
assert.equal(parseThreadTitle(" \n "), null);
assert.equal(parseThreadTitle("."), null);
assert.equal(
parseThreadTitle("x".repeat(THREAD_TITLE_MAX_CHARS + 1)),
null,
"too long is refused, never cut mid-word",
);
// Only Loki's own titles are Loki's to replace.
const PLACEHOLDER = "New conversation";
assert.ok(isAutoTitle(PLACEHOLDER, null, PLACEHOLDER));
assert.ok(isAutoTitle("", null, PLACEHOLDER));
assert.ok(isAutoTitle("move forward on loki", "move forward on loki", PLACEHOLDER));
assert.ok(!isAutoTitle("Loki deploy fix", "move forward on loki", PLACEHOLDER), "a rename is kept");
assert.ok(!isAutoTitle("Loki deploy fix", null, PLACEHOLDER));
// The prompt names the project first and clips both sides.
const prompt = buildThreadTitlePrompt({
question: "q".repeat(THREAD_TITLE_INPUT_CHARS + 500),
answer: "a",
project: "kivvi",
});
assert.ok(prompt.startsWith("Project: kivvi"));
assert.ok(!prompt.includes("q".repeat(THREAD_TITLE_INPUT_CHARS + 1)));
// The list shows the project beside the title — a title never repeats it.
assert.equal(
parseThreadTitle("Prodtest-bakery: Track multiple projects", "prodtest-bakery"),
"Track multiple projects",
);
assert.equal(parseThreadTitle("prodtest bakery – menu page", "prodtest-bakery"), "Menu page");
assert.equal(
parseThreadTitle("Kivvi checkout bug", "kivvi"),
"Kivvi checkout bug",
"only a prefix with a separator",
);
assert.equal(parseThreadTitle("Bakery: menu", null), "Bakery: menu");
console.log("✓ loki thread title");