mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:38:43 +01:00
* fix(loki): the assistant composer was deleting your newlines Found by using Loki to develop Loki. 'Brief Loki' on /today prefills the assistant with a multi-line prompt SummaryBar builds - heading, the day's counts, then the question, joined with newlines. The field it lands in was an <input>, and an <input> cannot hold a newline, so the browser stripped every one. Measured live on 2026-09-18: the value was 'Daily brief - Friday, 18 SeptemberWhat should I focus on today?' with a newline count of ZERO. The product generated a structured prompt and its own field destroyed the structure - no error, nothing to notice, and the result still reads as roughly sensible prose, which is why it survived. It is also the composer for the thing this product is FOR. A brief is several sentences by nature; a single-line box that scrolls horizontally shows about forty characters, so you cannot read back what you are about to dispatch. It is now a textarea that grows to a ceiling, with Enter to send and Shift+Enter for a line break - the convention the full-page composer already uses, whose auto-grow this mirrors rather than reinventing. SECOND BUG, same prompt: .filter(Boolean) deleted the paragraph breaks. The array carries two deliberate empty-string separators, and an empty string is falsy, so the filter meant to drop absent counts dropped those too. Even in a textarea the three parts would have run together. The builder moves to lib/today-brief.ts because it could not be tested where it was - an inline array inside an async server component. Six cases now pin it, including the exact 'SeptemberWhat' shape. Proven by mutation: restoring .filter(Boolean) fails two of them. 202/202 unit test files pass; the new test is picked up automatically by scripts/test-unit.ts. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * chore(format): prettier the today-brief test CI's verify runs prettier --check on the whole tree; I had formatted the files I edited but written this one afterwards, so the check caught it and nothing else did. Exactly what that gate is for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
109 lines
4.1 KiB
TypeScript
109 lines
4.1 KiB
TypeScript
/**
|
|
* The "Brief Loki" prompt, pinned.
|
|
*
|
|
* Both bugs this covers were invisible for the same reason: a mangled prompt
|
|
* still reads as roughly sensible prose, so it looks like a wording choice
|
|
* rather than a defect. Neither threw, neither logged. They were found by
|
|
* reading the field's value in a browser on 2026-09-18.
|
|
*
|
|
* Run: npx tsx scripts/test/today-brief.ts
|
|
*/
|
|
import { buildTodayBriefPrompt, TODAY_BRIEF_QUESTION } from "@/lib/today-brief";
|
|
|
|
let failures = 0;
|
|
function check(name: string, fn: () => void) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${name}`);
|
|
} catch (err) {
|
|
failures++;
|
|
console.log(` ✗ ${name}`);
|
|
console.log(` ${err instanceof Error ? err.message : String(err)}`);
|
|
}
|
|
}
|
|
function assert(cond: boolean, msg: string) {
|
|
if (!cond) throw new Error(msg);
|
|
}
|
|
|
|
const NO_COUNTS = {
|
|
activeGoals: 0,
|
|
avgGoalProgress: 0,
|
|
habitsDone: 0,
|
|
habitsTotal: 0,
|
|
goalsDueSoon: 0,
|
|
stuckGoals: 0,
|
|
eventsDueSoon: 0,
|
|
overdueCommitments: 0,
|
|
staleContacts: 0,
|
|
pendingDrafts: 0,
|
|
urgentAlerts: 0,
|
|
};
|
|
const NO_FLEET = { running: 0, waiting: 0, degraded: 0 };
|
|
const HEADING = "Daily brief — Friday, 18 September";
|
|
|
|
console.log("today-brief:");
|
|
|
|
check("the heading never runs into the question", () => {
|
|
// THE BUG, pinned. `.filter(Boolean)` dropped the intentional "" separators
|
|
// because an empty string is falsy, so with the private zone locked (every
|
|
// count zero) the prompt collapsed to heading-then-question with nothing
|
|
// between them. Rendered into an <input>, which strips newlines, it read
|
|
// "…18 SeptemberWhat should I focus on today?".
|
|
const out = buildTodayBriefPrompt(HEADING, NO_COUNTS, NO_FLEET);
|
|
assert(!out.includes("SeptemberWhat"), "heading and question must not concatenate");
|
|
assert(out.includes("\n"), "the prompt is multi-line by construction");
|
|
assert(out.startsWith(HEADING), "heading leads");
|
|
assert(out.endsWith(TODAY_BRIEF_QUESTION), "question closes");
|
|
});
|
|
|
|
check("an empty day still separates its two parts by a blank line", () => {
|
|
const out = buildTodayBriefPrompt(HEADING, NO_COUNTS, NO_FLEET);
|
|
assert(
|
|
out === `${HEADING}\n\n${TODAY_BRIEF_QUESTION}`,
|
|
`unexpected shape: ${JSON.stringify(out)}`,
|
|
);
|
|
});
|
|
|
|
check("no run of blank lines, however many counts are absent", () => {
|
|
// Keeping both separators would open the prompt with a gap when the middle
|
|
// is empty. One collapse rule, rather than a condition per line.
|
|
const out = buildTodayBriefPrompt(HEADING, NO_COUNTS, NO_FLEET);
|
|
assert(!/\n{3,}/.test(out), "three or more consecutive newlines");
|
|
});
|
|
|
|
check("present counts sit between the heading and the question", () => {
|
|
const out = buildTodayBriefPrompt(
|
|
HEADING,
|
|
{ ...NO_COUNTS, activeGoals: 3, avgGoalProgress: 40, habitsTotal: 2, habitsDone: 1 },
|
|
NO_FLEET,
|
|
);
|
|
const lines = out.split("\n");
|
|
assert(lines[0] === HEADING, "heading first");
|
|
assert(lines[1] === "", "blank line after the heading");
|
|
assert(out.includes("Goals: 3 active, 40% average progress"), "goal counts present");
|
|
assert(out.includes("Habits: 1/2 done today"), "habit counts present");
|
|
assert(out.endsWith(TODAY_BRIEF_QUESTION), "question last");
|
|
assert(!/\n{3,}/.test(out), "no gap runs");
|
|
});
|
|
|
|
check("a zero count contributes no line at all", () => {
|
|
// The original `.filter(Boolean)` was right about this half, and the fix must
|
|
// not regress it: absent counts are dropped, not rendered as "Goals: 0".
|
|
const out = buildTodayBriefPrompt(HEADING, NO_COUNTS, NO_FLEET);
|
|
assert(!out.includes("Goals:"), "no goals line when there are none");
|
|
assert(!out.includes("Habits:"), "no habits line when there are none");
|
|
assert(!out.includes("Agent fleet:"), "no fleet line when the fleet is quiet");
|
|
});
|
|
|
|
check("the fleet line names only what is actually happening", () => {
|
|
const out = buildTodayBriefPrompt(HEADING, NO_COUNTS, { running: 2, waiting: 0, degraded: 1 });
|
|
assert(
|
|
out.includes("Agent fleet: 2 running, 1 degraded"),
|
|
"running + degraded, no empty waiting",
|
|
);
|
|
assert(!out.includes("waiting"), "a zero bucket must not be listed");
|
|
});
|
|
|
|
console.log(failures === 0 ? "\nall passed" : `\n${failures} failed`);
|
|
process.exit(failures === 0 ? 0 : 1);
|