mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-03 21:57:04 +01:00
* fix(prompts): one card per saved prompt, schedules in words, dialogs that say why
What the owner found on /prompts from an Android phone, item by item:
1. Saved prompts: saving the same name + words again no longer inserts a
row — POST /api/prompts answers with the prompt already saved
(existing: true); the form opens it, the default's save button says
"Already in your prompts". A card that stands for identical copies says
how many and offers "Remove N extra copies" — one explicit tap, the
caller's own rows only, the same soft delete as Delete
(DELETE /api/prompts/<id>/copies). Same name with different words says
"2 versions with this name, worded differently".
2. Filters: the scope filter is a <Segmented> (All / Any project / One
project) sitting with the category row on the list they both filter,
under "Loki's prompts". Category counts follow the scope. Filter chip
rows on a phone get a wider fade, snap to a chip's start and leave room
after the last chip, so the edge reads as "more" rather than a cut word.
3. New prompt: Create stays disabled until there is a name and a prompt,
and says what is missing beside it. Opening or closing the form never
saved anything; the copy glyph on every default card did, in one tap
with no label on a phone — it is now a labelled "save a copy" button.
4. Schedule: pick Every day / Weekdays / Every week / Every month, a day
and a time; Loki writes the cron (lib/cron-words), with "Write it as a
cron line instead" for experts. The schedule reads back in words with
the time zone it runs in ("Every Monday at 10:00, Zurich time
(Europe/Zurich)") and a link to change it; the zone is sent with the
job. The API refuses a cron line the scheduler cannot read, in words.
Create is the primary button and says why when it cannot be pressed.
5. Run: a prompt that names {{project_name}} asks for a project whatever
its scope (a saved copy is global), defaulting to the project in use;
the prompt is shown only once complete. Each action says in one line
who does the work; Send to terminal works for any of your projects
(tab-inject starts or queues the session) and says why when it cannot.
Project pickers list projectTitle(), not folder keys.
6. Category chips are neutral (ui-tag-neutral); the ui-cat-* rainbow and
the featured star's amber are gone. "control" was a second id for the
fleet prompts — one category now, "Fleet control".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(voice): spoken sentences start with a capital and name a repeated project once
The briefing read "one run is waiting for a builder: loki ... three runs
failed: loki, loki and loki". Sentences now open with a capital, and the
runs' projects are said once each: "Three runs failed on loki.", "Four runs
failed: loki three times and heidi once." The same for runs waiting for a
builder, agents working, and the announcements between turns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(voice): say why the studio voice is off, with the link that fixes it
POST /api/voice/speak answered 502 with Groq's reason only in the server
console, and the phone fell back to its own voice in silence, so every voice
in the picker sounded the same. Groq's refusal is now classified
(lib/voice/tts-failure: terms gate, bad key, limit, model gone, vendor down,
no key) into one plain sentence and, where one exists, the link that fixes
it — for the Orpheus terms gate, Groq's voice page and "press Accept". The
route returns it in the 502/503 body and records it in debug_logs (once per
reason per half hour) so System shows it. The speaker reports the fallback
to the page; useStudioVoiceStatus keeps it for the tab's session and
StudioVoiceNotice shows it. The phone-voice fallback stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* feat(voice): change Loki's voice by saying so, and answer questions about voice mode truthfully
"I don't like your voice, can I change your voice" was answered like a
generic chatbot ("in most voice-enabled AI chat apps... look in settings").
Now "use Troy", "change your voice to Diana", "other voice" and
"switch voice" are a spoken command (config/no-screen.ts, lib/voice/commands)
that the phone answers itself; with no name it lists the voices. A question
that does reach Loki carries voiceModeContext (lib/voice/self.ts), built from
the SSOT: the voices by name, how to change one, the three switches with the
same one-line notes the screen shows (NO_SCREEN_OPTIONS), every command, the
current settings and why studio voices are off, if they are.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(voice): a music bed a phone can actually play, and keep its sound awake
The bed sat at about -38 dBFS RMS alone and -50 under the voice, every note
98-370 Hz behind a 900 Hz low-pass: below what a phone speaker or many
earbuds reproduce, so "music bed on" was silence. It is now an octave
higher (196-740 Hz), about 12 dB louder, ducks by 10 dB instead of 11 more on
top, and earcons sit above it. The AudioContext is resumed inside the Start
tap, on every tap on the circle or headphone button, on return to the page,
and when the phone suspends it mid-session.
useSoundscape also returned a new object every render, so effects keyed on
it re-ran ~20 times a second while listening: the gain was re-ramped every
frame and the 20-second fleet poll was cleared before it could fire. It is
memoized now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(voice): one h1 per screen, End clear of the feedback launcher, voices as an even grid
- Speaking screen: an h1 below md, where the app top bar steps aside; the
start screen's big "Voice" is no longer a second h1 beside the top bar's.
- The speaking screen sets data-fc-place="tab", so the feedback launcher
and its Watching pill become the slim edge handle instead of sitting on
End; End is larger, with room below it, and the stage scrolls rather than
pushing End off a short screen.
- The voice picker is a <Segmented> grid of four columns (seven voices as
4 + 3, the last two cells wide) instead of a chip row cut off at the edge;
the setting groups have real headings.
- The unclear note under the switches is one short line under each switch,
shared with what Loki is told about itself.
- The page wires the studio-voice notice (under the picker and under the
circle, said aloud once), the spoken voice change, the page's state sent
with each question, and the sound resume on every tap.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(widget): one card per finding, settled page checks, honest fix status, a count that means what needs you
Watching on Loki's own /voice from an Android phone showed six problems in
one panel. Each is fixed where it starts:
- Notices no longer stack. A page's checks own ONE card (checksSlot), which
each new reading replaces in place and a clean reading takes back
(thread.ts pushNoticed / dropNoticed); a remark whose words are already on
screen is not said again; a finding's signature ignores its count and its
placeholder example (findingKind), and the card names its page.
- The heading miscount: the check counted headings inside aria-hidden and
inert subtrees, and measured the page once, mid-swap — /voice's setup
screen (top bar h1 + page h1) leaving for its speaking screen (immersive
mode hides the top bar: no h1). Checks now count only rendered elements and
run once the page has held still, twice, keeping only what both readings
agree on (settledPageChecks / stableChecks). The Voice page itself now has
one h1 on each screen.
- A fix Watch started that failed no longer promises it "goes live by
itself": it says the fix did not finish, and "Open it in Loki to see why"
is a real link to that run's Watch page (owner-view ownerTap; watch-fix
now resolves a failed run's Watch page even without a live page).
- Self-watch: "I couldn't check on your changes just now" replaces the old
sentence; a request that lived through the page being put away (a phone
locking) is never a failure; background reads count only after three
failures in a row; the changes route always answers with CORS headers and
logs what failed.
- The header's one number is what waits on the owner's decision (failed
attempts, saved notes, notes not started, changes said but not saved),
counted by the server over ALL of the owner's rows, not inside the newest
twelve; the open list shows every one of them first. Nothing waiting:
just "Watching".
- The save receipt never quotes a cut sentence: several changes are listed
one per line under it, clamped to whole lines with "Show all".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* docs(changelog): voice, Watching and Prompts fixes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
---------
Co-authored-by: Claude <noreply@anthropic.com>
280 lines
9.4 KiB
TypeScript
280 lines
9.4 KiB
TypeScript
// The widget's one conversation, as data (widget/thread.ts): who answers on
|
|
// which embed, a stored thread restored only as far as it validates (anything
|
|
// on the host page can write sessionStorage), and the thread said back to the
|
|
// model as history — receipts included, so "and the footer too" has context.
|
|
// Run: npx tsx scripts/test/widget-thread.ts
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
assistantFor,
|
|
dropNoticed,
|
|
historyFor,
|
|
isPageReadKey,
|
|
noticeSlot,
|
|
pushItem,
|
|
pushNoticed,
|
|
pushPageRead,
|
|
restoreThread,
|
|
THREAD_MAX,
|
|
THREAD_MAX_AGE_MS,
|
|
type ThreadItem,
|
|
} from "../../widget/thread";
|
|
import { CHAT_MAX_HISTORY, CHAT_MAX_MESSAGE } from "../../widget/loki-api";
|
|
import { parseWidgetSurfaceModes } from "../../widget/surface-modes";
|
|
import { readFileSync } from "node:fs";
|
|
|
|
// Read, not imported: the route module opens the database on import.
|
|
const chatRoute = readFileSync("src/app/api/widget/chat/route.ts", "utf8");
|
|
const routeCap = (name: string) =>
|
|
Number(new RegExp(`export const ${name} = (\\d+)`).exec(chatRoute)?.[1]);
|
|
const WIDGET_CHAT_MAX_MESSAGE = routeCap("WIDGET_CHAT_MAX_MESSAGE");
|
|
const WIDGET_CHAT_MAX_HISTORY = routeCap("WIDGET_CHAT_MAX_HISTORY");
|
|
|
|
// ---- who answers ----
|
|
assert.equal(
|
|
assistantFor(parseWidgetSurfaceModes(null), false),
|
|
"advisor",
|
|
"default: the site advisor",
|
|
);
|
|
assert.equal(assistantFor(parseWidgetSurfaceModes("chat,report"), false), "concierge");
|
|
assert.equal(
|
|
assistantFor(parseWidgetSurfaceModes("report"), false),
|
|
"none",
|
|
"report-only opts out of AI",
|
|
);
|
|
assert.equal(
|
|
assistantFor(parseWidgetSurfaceModes("report"), true),
|
|
"advisor",
|
|
"the owner always gets advice",
|
|
);
|
|
assert.equal(
|
|
assistantFor(parseWidgetSurfaceModes("chat"), true),
|
|
"advisor",
|
|
"even on a front desk",
|
|
);
|
|
assert.deepEqual(parseWidgetSurfaceModes("chat, report, chat, nonsense"), ["chat", "report"]);
|
|
assert.deepEqual(parseWidgetSurfaceModes("nonsense"), ["report", "ask"]);
|
|
|
|
// ---- restoring a stored thread ----
|
|
{
|
|
const now = 50_000_000;
|
|
const restored = restoreThread(
|
|
[
|
|
{ kind: "you", at: now - 1000, text: "Is the menu ok?" },
|
|
{
|
|
kind: "loki",
|
|
at: now - 900,
|
|
text: "Mostly.",
|
|
speaker: "cat",
|
|
changes: ["Shorten it", 7, "x".repeat(900)],
|
|
links: [
|
|
{ label: "OK", url: "https://example.org/a" },
|
|
{ label: "evil", url: "javascript:alert(1)" },
|
|
],
|
|
},
|
|
{
|
|
kind: "sent",
|
|
at: now - 800,
|
|
text: "Shorten it",
|
|
owner: true,
|
|
building: true,
|
|
claimUrl: "data:x",
|
|
},
|
|
{
|
|
kind: "sent",
|
|
at: now - 790,
|
|
text: "The panel covers the keyboard",
|
|
owner: false,
|
|
toLoki: true,
|
|
},
|
|
{ kind: "you", at: now - THREAD_MAX_AGE_MS - 1, text: "from an earlier visit" },
|
|
{ kind: "you", at: now + 60_000, text: "from the future" },
|
|
{ kind: "you", at: now - 10, text: " " },
|
|
{ kind: "admin", at: now - 10, text: "forged" },
|
|
null,
|
|
"nonsense",
|
|
],
|
|
now,
|
|
);
|
|
assert.equal(restored.length, 4, `only valid, fresh items survive (${JSON.stringify(restored)})`);
|
|
const loki = restored[1] as Extract<ThreadItem, { kind: "loki" }>;
|
|
assert.equal(loki.speaker, "cat");
|
|
assert.equal(loki.changes?.length, 2, "non-string changes dropped");
|
|
assert.equal(loki.changes?.[1].length, 300, "a long change is capped");
|
|
assert.deepEqual(
|
|
loki.links,
|
|
[{ label: "OK", url: "https://example.org/a" }],
|
|
"only http(s) links",
|
|
);
|
|
const sent = restored[2] as Extract<ThreadItem, { kind: "sent" }>;
|
|
assert.equal(sent.claimUrl, undefined, "a non-http claim link is dropped");
|
|
assert.equal(sent.building, true);
|
|
const toLoki = restored[3] as Extract<ThreadItem, { kind: "sent" }>;
|
|
assert.equal(toLoki.toLoki, true, "a note about Loki itself is remembered as such");
|
|
assert.deepEqual(restoreThread("not an array", now), []);
|
|
}
|
|
|
|
// ---- Loki's remarks survive a reload, and need their fix to be a remark ----
|
|
{
|
|
const now = 50_000_000;
|
|
const r = restoreThread(
|
|
[
|
|
{
|
|
kind: "noticed",
|
|
at: now - 5,
|
|
text: "It found nothing there (404).",
|
|
fix: "Fix /hours",
|
|
filed: true,
|
|
},
|
|
{ kind: "noticed", at: now - 4, text: "No fix to send" },
|
|
{
|
|
kind: "noticed",
|
|
at: now - 3,
|
|
text: "The page has no main heading.",
|
|
fix: "Add one",
|
|
key: "/p|checks|The page has no main heading (h#)",
|
|
again: true,
|
|
},
|
|
],
|
|
now,
|
|
);
|
|
assert.deepEqual(r, [
|
|
{
|
|
kind: "noticed",
|
|
at: now - 5,
|
|
text: "It found nothing there (404).",
|
|
fix: "Fix /hours",
|
|
filed: true,
|
|
},
|
|
{
|
|
kind: "noticed",
|
|
at: now - 3,
|
|
text: "The page has no main heading.",
|
|
fix: "Add one",
|
|
key: "/p|checks|The page has no main heading (h#)",
|
|
again: true,
|
|
},
|
|
]);
|
|
assert.match(historyFor(r, 4, 200)[0].content, /^\(Noticed while watching: /);
|
|
}
|
|
|
|
// ---- bounded ----
|
|
{
|
|
let t: ThreadItem[] = [];
|
|
for (let i = 0; i < THREAD_MAX + 7; i++) t = pushItem(t, { kind: "you", at: i, text: `m${i}` });
|
|
assert.equal(t.length, THREAD_MAX);
|
|
assert.equal((t[0] as { text: string }).text, "m7", "the oldest go first");
|
|
}
|
|
|
|
// ---- Loki's unasked page reads: only the newest stays ----
|
|
{
|
|
// 2026-10-15: one read per page browsed, four stacked above the owner's own
|
|
// words. A new read replaces the last; every other item is untouched.
|
|
const read = (at: number, key: string): ThreadItem => ({
|
|
kind: "noticed",
|
|
at,
|
|
text: `read ${at}`,
|
|
fix: "f",
|
|
key,
|
|
});
|
|
let t: ThreadItem[] = [];
|
|
t = pushPageRead(t, read(1, "/a|read"));
|
|
t = pushItem(t, { kind: "noticed", at: 2, text: "slow", fix: "f", key: "/a|notice|slow" });
|
|
t = pushItem(t, { kind: "you", at: 3, text: "hello" });
|
|
t = pushPageRead(t, read(4, "/b|read"));
|
|
assert.deepEqual(
|
|
t.map((i) => i.at),
|
|
[2, 3, 4],
|
|
"the earlier read goes; a measured notice and your words stay",
|
|
);
|
|
assert.ok(
|
|
isPageReadKey("/b|read") && !isPageReadKey("/a|notice|slow") && !isPageReadKey(undefined),
|
|
);
|
|
}
|
|
|
|
// ---- one card per finding: a new reading updates it, never stacks ----
|
|
{
|
|
// 2026-10-20, operator's phone on /voice: "no main title" three times in
|
|
// one panel, "1 form field has no label" beside "2 form fields have no
|
|
// label". A page's checks own ONE card; each reading replaces it in place.
|
|
const checks = (
|
|
at: number,
|
|
kinds: string,
|
|
text: string,
|
|
): Extract<ThreadItem, { kind: "noticed" }> => ({
|
|
kind: "noticed",
|
|
at,
|
|
text,
|
|
fix: "f",
|
|
key: `/voice|checks|${kinds}`,
|
|
});
|
|
let t: ThreadItem[] = [];
|
|
t = pushNoticed(t, checks(1, "The page's main heading (h1)", "no main title"));
|
|
t = pushItem(t, { kind: "you", at: 2, text: "hello" });
|
|
t = pushNoticed(
|
|
t,
|
|
checks(3, "The page's main heading (h1)|# form field(s) have no label", "two things"),
|
|
);
|
|
t = pushNoticed(t, checks(4, "# form field(s) have no label", "one field"));
|
|
assert.deepEqual(
|
|
t.map((i) => `${i.at}:${i.kind}`),
|
|
["4:noticed", "2:you"],
|
|
"the card keeps its place and shows only the newest reading",
|
|
);
|
|
// The same words again (a reload): nothing changes.
|
|
assert.equal(pushNoticed(t, checks(4, "# form field(s) have no label", "one field")), t);
|
|
// Another page's checks are another card.
|
|
t = pushNoticed(t, {
|
|
kind: "noticed",
|
|
at: 5,
|
|
text: "other page",
|
|
fix: "f",
|
|
key: "/loki|checks|x",
|
|
});
|
|
assert.equal(t.filter((i) => i.kind === "noticed").length, 2);
|
|
// A remark whose words are already on screen is not said twice.
|
|
const slow = { kind: "noticed" as const, at: 6, text: "It took 4s", fix: "f", key: "/a|slow|x" };
|
|
t = pushNoticed(t, slow);
|
|
assert.equal(pushNoticed(t, { ...slow, at: 7, key: "/b|slow|y" }).length, t.length);
|
|
// A clean reading takes the page's card back.
|
|
assert.equal(noticeSlot("/voice|checks|# form field(s) have no label"), "/voice|checks");
|
|
assert.equal(noticeSlot("/voice|fail|request:x"), "/voice|fail|request:x");
|
|
const dropped = dropNoticed(t, "/voice|checks");
|
|
assert.deepEqual(
|
|
dropped.map((i) => i.at),
|
|
[2, 5, 6],
|
|
"only that page's card goes",
|
|
);
|
|
assert.equal(dropNoticed(dropped, "/voice|checks"), dropped, "nothing to drop: same thread");
|
|
// Reads keep their own rule: one read at a time.
|
|
t = pushNoticed(t, { kind: "noticed", at: 8, text: "read a", fix: "f", key: "/a|read" });
|
|
t = pushNoticed(t, { kind: "noticed", at: 9, text: "read b", fix: "f", key: "/b|read" });
|
|
assert.equal(t.filter((i) => i.kind === "noticed" && isPageReadKey(i.key)).length, 1);
|
|
}
|
|
|
|
// ---- the thread as model history ----
|
|
{
|
|
const t: ThreadItem[] = [
|
|
{ kind: "you", at: 1, text: "Change the title" },
|
|
{ kind: "loki", at: 2, text: "Try “Your pharmacy”." },
|
|
{ kind: "sent", at: 3, text: "Use “Your pharmacy” as the title", owner: true },
|
|
{ kind: "you", at: 4, text: "and the footer too" },
|
|
];
|
|
const h = historyFor(t, 3, 20);
|
|
assert.deepEqual(
|
|
h.map((x) => x.role),
|
|
["assistant", "assistant", "user"],
|
|
"the last N turns",
|
|
);
|
|
assert.ok(h[1].content.startsWith("(Sent to the bu"), "a receipt is said back as Loki's");
|
|
assert.ok(
|
|
h.every((x) => x.content.length <= 20),
|
|
"each turn is capped",
|
|
);
|
|
}
|
|
|
|
// ---- the widget clamps to what the chat route accepts ----
|
|
assert.equal(CHAT_MAX_MESSAGE, WIDGET_CHAT_MAX_MESSAGE, "chat message cap mirrors the route");
|
|
assert.equal(CHAT_MAX_HISTORY, WIDGET_CHAT_MAX_HISTORY, "chat history cap mirrors the route");
|
|
|
|
console.log("widget-thread: ok");
|