mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 20:48:18 +01:00
Loki did more work than any other surface in the app and showed the least
of it. A turn is up to three model rounds with real retrieval in between —
it searches your people, reads your projects, queries the knowledge graph —
and all of it happened behind one static "Loki is thinking" line for as long
as it took. `runLokiTurn` has always returned `toolsUsed`, carrying the
comment "surfaced so the UI can show work". Nothing ever surfaced it.
## The turn streams, for real
Not a typewriter over a finished string. `agent/llm.ts` gained a genuine
`stream: true` path against the providers' OpenAI-compatible endpoint, with
`stream_options.include_usage` so a streamed turn is still BILLED — without
it the final chunk carries no usage and the day's ration would drain for
free on exactly the turns someone is watching.
Two rules keep the preview honest:
- **Prose is released a whole line at a time.** A weak model narrates its
tool calls as `TOOL:` / `ARGS:` lines, and the buffered path strips them
before anyone sees them. A chunk ending in `TOO` could still become
`TOOL:`, so nothing is shown until a newline proves the line finished.
Extracted as `createProseGate` and covered by `test:loki-prose-gate`,
including that it agrees with `stripToolCallLines` on the same text.
- **`delta` is a preview; `message` is the record.** The loop REPLACES its
answer every round (`text = turn.text`), and the grounding repair pass can
delete unsupported claims from a finished one. So round boundaries and
dead links emit `reset`, and the persisted turn replaces the preview when
it lands. Appending instead would leave a fabrication on screen that the
database does not contain.
The fallback path streams too. It is tempting to treat it as degraded and
therefore allowed to be silent — but it runs precisely when the free tiers
are drained and the tool loop cannot start, which is to say on the slowest
days. Leaving it unstreamed meant no visible streaming exactly when progress
most needed showing. One shared SSE frame reader, not two.
## What else changed
- **A stop button.** There was none: a running turn could not be cancelled.
It takes the same slot as send, and the abort reaches the provider call.
- **The work trail** — each tool as it runs, with the records it actually
returned. A failed tool reads as "unavailable", never as "nothing found".
- **One rail instead of four navigations.** The global sidebar, a
Chat/Control/Terminal strip, a pinned history rail AND a "Chats / New"
toolbar all led to the same two actions. The rail owns them now.
- **A model picker** that says what it does: a choice sets where the CHAIN
starts, and the fallback below it survives — a hard pin on a free tier is
a scheduled outage. Vendors without a key are listed, disabled, with the
reason; never hidden, never fake-enabled.
- Copy and try-again on an answer. Autoscroll that follows only while you
are at the bottom, plus a way back down.
## Bugs found on the way
- `bg-accent-primary` + `text-white` is invisible in dark mode, where
`--accent-primary` is near-WHITE. The send arrow did not exist on a dark
screen. Same bug in `.ui-assist-send`; both now `text-text-inverted`.
- The composer was keyed on `activeId`, so creating the thread REMOUNTED it
mid-send — silently resetting the model choice and dropping staged files.
- That same transition looked like a thread SWITCH, so the transcript
cleared, showed "Loading conversation" over the streaming turn, and
refetched a thread the server had not finished writing. The question
vanished and the answer arrived alone.
- `.ui-loki-thread` was missing `flex flex-col`, making its `mt-auto` inert:
a short conversation pinned to the top with dead space above the composer.
- The rail's project filter could hide the thread you were reading, because
scope follows the answer. A filter may narrow what else is offered; it may
not hide where you are.
## Refactor
Three components deleted. The composer finally uses `useAttachments` — the
hook that was extracted FROM it and adopted by the Control and Terminal
composers, leaving the one surface it came from as the only one with a
private copy. Dispatch/approval/project-picker footers moved out verbatim,
because rewriting honest-status logic to move it is how the regressions its
comments warn about get reintroduced.
`check-loki-classes.mjs` (wired into `check:design`) asserts every
`ui-loki-*` class is both defined and used. A renamed class is invisible to
tsc, eslint and the build — it still renders, as unstyled markup. It found
six orphaned rules on its first run, and fails under mutation.
Verified live: page renders at 1440/390/320 with no horizontal overflow, a
real turn streams against real models and the local DB, and the stop button
cancels one.
Claude-Session: https://claude.ai/code/session_01PMLf9PxnoryRqRxzVLu7WM
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
/**
|
|
* Every `ui-loki-*` class used in a component must exist in globals.css, and
|
|
* every one defined there must still be used.
|
|
*
|
|
* This exists because a CSS mistake is invisible to every other check in this
|
|
* repo: a component referencing a class that was renamed or deleted still
|
|
* typechecks, still lints, still builds, and still renders — as unstyled
|
|
* markup. The rebuild of this surface deleted three components and a dozen
|
|
* rules; without a check, the leftovers are found by a human noticing something
|
|
* looks wrong.
|
|
*
|
|
* Run: node scripts/check-loki-classes.mjs
|
|
*/
|
|
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
const CLASS_RE = /ui-loki-[a-z0-9-]+/g;
|
|
|
|
function walk(dir, out = []) {
|
|
for (const name of readdirSync(dir)) {
|
|
const full = join(dir, name);
|
|
if (statSync(full).isDirectory()) walk(full, out);
|
|
else if (/\.(tsx|ts)$/.test(full)) out.push(full);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
const css = readFileSync("src/app/globals.css", "utf8");
|
|
// Only a selector defines a class. A bare mention inside a comment does not.
|
|
const defined = new Set([...css.matchAll(/\.(ui-loki-[a-z0-9-]+)/g)].map((m) => m[1]));
|
|
|
|
const used = new Set();
|
|
for (const file of walk("src")) {
|
|
for (const match of readFileSync(file, "utf8").matchAll(CLASS_RE)) used.add(match[0]);
|
|
}
|
|
|
|
const missing = [...used].filter((c) => !defined.has(c)).sort();
|
|
const orphaned = [...defined].filter((c) => !used.has(c)).sort();
|
|
|
|
if (missing.length) {
|
|
console.error(`✗ used in a component but not defined in globals.css:\n ${missing.join("\n ")}`);
|
|
}
|
|
if (orphaned.length) {
|
|
console.error(`✗ defined in globals.css but used nowhere:\n ${orphaned.join("\n ")}`);
|
|
}
|
|
if (missing.length || orphaned.length) process.exit(1);
|
|
|
|
console.log(`✓ ${defined.size} ui-loki-* classes: all defined, all used`);
|