mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 09:20:03 +01:00
"Ask Loki" from a project, the terminal and Control all link to /loki?project=X. Each landed on an empty start screen, so the next message minted another thread — which is how fifteen "move forward on loki" threads came to exist, and why the rail had to collapse them into one row with a count. Now such a link opens X's most recent thread when it was active in the last 14 days, with New chat one tap away for a new topic. ?c= still wins, and a link carrying ?q= (a prefilled ask, a site hand-off) still starts fresh: it is a beginning by construction. The rule is initialThreadId in lib/loki/conversation-param.ts, pure, pinned by scripts/test/loki-home-thread.ts, and reads the list the page already prefetches — no extra request. Claude-Session: https://claude.ai/code/session_01CG9dupSVqoXCCqKfBCfd9B Co-authored-by: Claude <noreply@anthropic.com>
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
/**
|
|
* A link into the chat that names a project opens that project's recent
|
|
* thread, instead of an empty start screen whose next message mints another.
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import { HOME_THREAD_MAX_AGE_MS, initialThreadId } from "../../src/lib/loki/conversation-param";
|
|
|
|
const NOW = Date.parse("2026-10-12T12:00:00Z");
|
|
const ago = (days: number) => new Date(NOW - days * 24 * 60 * 60 * 1000).toISOString();
|
|
const A = "aaaaaaaa-1111-4222-8333-444455556666";
|
|
const B = "bbbbbbbb-1111-4222-8333-444455556666";
|
|
const C = "cccccccc-1111-4222-8333-444455556666";
|
|
const list = [
|
|
{ id: A, projectKeys: ["loki"], updatedAt: ago(1) },
|
|
{ id: B, projectKeys: ["Loki", "kivvi"], updatedAt: ago(0.1) },
|
|
{ id: C, projectKeys: ["datacat"], updatedAt: ago(30) },
|
|
];
|
|
const at = (over: Partial<Parameters<typeof initialThreadId>[0]>) =>
|
|
initialThreadId({ c: null, project: null, q: null, conversations: list, now: NOW, ...over });
|
|
|
|
// ?c= always wins.
|
|
assert.equal(at({ c: C, project: "loki" }), C);
|
|
// A project link opens its newest thread, case-insensitively.
|
|
assert.equal(at({ project: "loki" }), B);
|
|
assert.equal(at({ project: "KIVVI" }), B);
|
|
// Past two weeks it is history: start fresh.
|
|
assert.equal(at({ project: "datacat" }), null);
|
|
assert.equal(
|
|
initialThreadId({
|
|
c: null,
|
|
project: "datacat",
|
|
q: null,
|
|
conversations: [
|
|
{
|
|
id: C,
|
|
projectKeys: ["datacat"],
|
|
updatedAt: new Date(NOW - HOME_THREAD_MAX_AGE_MS + 1000).toISOString(),
|
|
},
|
|
],
|
|
now: NOW,
|
|
}),
|
|
C,
|
|
);
|
|
// A prefilled ask is a beginning: leave it on the start screen.
|
|
assert.equal(at({ project: "loki", q: "add a pricing page" }), null);
|
|
// No project, an unknown project, or no list yet: nothing to open.
|
|
assert.equal(at({}), null);
|
|
assert.equal(at({ project: "nope" }), null);
|
|
assert.equal(at({ project: "loki", conversations: undefined }), null);
|
|
|
|
console.log("✓ loki home thread");
|