Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Loose ends: open the bot chat a case came from
Lin (kwant bot)bfd45d122784
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 3ff4b9f2..1f9b8b3a 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -2440,7 +2440,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({onBack={isPhone ? () => { setShowAway(false); setPhoneView('list'); } : undefined}/>);- const loose = <LooseEndsPage onBack={isPhone ? () => { setShowLoose(false); setPhoneView('list'); } : undefined} />;+ const loose = <LooseEndsPage onBack={isPhone ? () => { setShowLoose(false); setPhoneView('list'); } : undefined} onOpenChat={openThread} />;const chat = (<ChatViewtitle={chatTitle}diff --git a/frontend/src/components/LooseEndsView.tsx b/frontend/src/components/LooseEndsView.tsxindex 9ce0a1bb..51900280 100644--- a/frontend/src/components/LooseEndsView.tsx+++ b/frontend/src/components/LooseEndsView.tsx@@ -36,6 +36,7 @@ import {actionDoneText,actionsFor,ageText,+ caseChat,deadlineText,draftCopyText,draftOpen,@@ -85,13 +86,15 @@ export interface LooseCaseCardProps {busy: boolean;now?: number;onAction: (c: LooseCase, action: CaseAction, body?: unknown) => void;+ /** Opens a bot thread in the app; without it a case shows no chat link. */+ onOpenChat?: (kwantId: string, threadId: string) => void;/** Tests open a choice. */initialChoice?: 'snooze' | 'dismiss' | null;}/** One loose end: who, why it stalled, the evidence, the draft and what to do with it. Generic* over the source, so a letter or a bank statement can use the same card. */-export const LooseCaseCard: React.FC<LooseCaseCardProps> = ({ c, busy, now = Date.now(), onAction, initialChoice = null }) => {+export const LooseCaseCard: React.FC<LooseCaseCardProps> = ({ c, busy, now = Date.now(), onAction, onOpenChat, initialChoice = null }) => {const id = useId();const [choice, setChoice] = useState<'snooze' | 'dismiss' | null>(initialChoice);const [copied, setCopied] = useState<'ok' | 'failed' | null>(null);@@ -99,6 +102,7 @@ export const LooseCaseCard: React.FC<LooseCaseCardProps> = ({ c, busy, now = Datconst who = c.counterpart_name || c.counterpart;const due = c.deadline ? deadlineText(c.deadline, now) : null;const link = safeHref(c.link);+ const chat = onOpenChat ? caseChat(c) : null;const open = c.draft ? draftOpen(c.draft) : null;const copy = async () => {@@ -185,6 +189,16 @@ export const LooseCaseCard: React.FC<LooseCaseCardProps> = ({ c, busy, now = Dat</div>)}+ {chat && (+ <button+ type="button"+ onClick={() => onOpenChat?.(chat.kwantId, chat.threadId)}+ className="inline-flex min-h-[32px] items-center gap-1 text-[11px] text-sky-300 hover:text-sky-200 underline-offset-2 hover:underline"+ >+ <MessageSquare size={12} aria-hidden="true" /> Open chat+ </button>+ )}+{c.draft && (c.status === 'open' || c.status === 'waiting_reply') && (<div className="rounded-lg border border-sky-500/20 bg-sky-500/5 p-3 space-y-2"><div className="flex flex-wrap items-baseline justify-between gap-2">@@ -599,6 +613,7 @@ export interface LooseEndsViewProps {onRefresh: () => void;onScan: () => void;onAction: (c: LooseCase, action: CaseAction, body?: unknown) => void;+ onOpenChat?: (kwantId: string, threadId: string) => void;onBack?: () => void;}@@ -619,6 +634,7 @@ export const LooseEndsView: React.FC<LooseEndsViewProps> = ({onRefresh,onScan,onAction,+ onOpenChat,onBack,}) => {const counts = CASE_TABS.reduce((acc, t) => ({ ...acc, [t.key]: (cases ?? []).filter((c) => tabOf(c.status) === t.key).length }), {} as Record<CaseTab, number>);@@ -720,7 +736,7 @@ export const LooseEndsView: React.FC<LooseEndsViewProps> = ({) : (<ul className="space-y-3">{shown.map((c) => (- <LooseCaseCard key={c.id} c={c} busy={busy === c.id} now={now} onAction={onAction} />+ <LooseCaseCard key={c.id} c={c} busy={busy === c.id} now={now} onAction={onAction} onOpenChat={onOpenChat} />))}</ul>)}@@ -736,7 +752,7 @@ export const LooseEndsView: React.FC<LooseEndsViewProps> = ({};/** Loads cases and sources, runs the card actions and scans. */-export const LooseEndsPage: React.FC<{ onBack?: () => void }> = ({ onBack }) => {+export const LooseEndsPage: React.FC<{ onBack?: () => void; onOpenChat?: (kwantId: string, threadId: string) => void }> = ({ onBack, onOpenChat }) => {const [cases, setCases] = useState<LooseCase[] | null>(null);const [running, setRunning] = useState(false);const [loading, setLoading] = useState(true);@@ -852,6 +868,7 @@ export const LooseEndsPage: React.FC<{ onBack?: () => void }> = ({ onBack }) =>onRefresh={load}onScan={scan}onAction={act}+ onOpenChat={onOpenChat}onBack={onBack}sources={<LooseSources sources={sources} error={sourcesError} onChanged={() => (loadSources(), load())} />}/>diff --git a/frontend/src/looseEnds.ts b/frontend/src/looseEnds.tsindex 25728e19..c3475ca3 100644--- a/frontend/src/looseEnds.ts+++ b/frontend/src/looseEnds.ts@@ -55,6 +55,8 @@ export interface LooseCase {deadline: string | null;resolution: string | null;dismiss_reason: string | null;+ /** The bot whose chat a `kwant_*` case is in; `null` for other sources and older cases. */+ kwant_id?: string | null;}export interface LooseSource {@@ -168,6 +170,14 @@ export function deadlineText(deadline: string, now = Date.now()): { text: stringexport const safeHref = (url: string | null | undefined, scheme: 'https' | 'mailto' = 'https'): string | null =>url && url.toLowerCase().startsWith(`${scheme}:`) ? url : null;+/** The bot chat a case came from, to open in the app. Needs both the bot (`kwant_id`, missing on+ * cases found before it was added) and the thread (`kwant://thread/<id>` in `link`). */+export function caseChat(c: Pick<LooseCase, 'kwant_id' | 'link' | 'draft'>): { kwantId: string; threadId: string } | null {+ const fromLink = c.link?.startsWith('kwant://thread/') ? c.link.slice('kwant://thread/'.length) : null;+ const threadId = fromLink || c.draft?.kwant_thread_id || null;+ return c.kwant_id && threadId ? { kwantId: c.kwant_id, threadId } : null;+}+/** The text "Copy draft" puts on the clipboard. */export const draftCopyText = (d: CaseDraft): string => (d.subject ? `Subject: ${d.subject}\n\n${d.body}` : d.body);diff --git a/frontend/tests/looseEnds.test.mjs b/frontend/tests/looseEnds.test.mjsindex 98343406..e48fdf07 100644--- a/frontend/tests/looseEnds.test.mjs+++ b/frontend/tests/looseEnds.test.mjs@@ -82,6 +82,28 @@ test('links only open https or mailto, never a script or a kwant:// address', ()assert.equal(m.draftOpen({ channel: 'email', body: 'x', mailto: 'javascript:x', open_url: null }), null);});+test('a bot-chat case opens its chat in the app when it names the bot, and shows no chat link without it', () => {+ const chatCase = (over = {}) => mailCase({+ source: 'kwant', conv_kind: 'kwant_thread', kind: 'unanswered_question', counterpart: null, counterpart_name: 'Ada',+ link: 'kwant://thread/t-9', kwant_id: 'k-ada', draft: null, ...over,+ });+ assert.deepEqual(m.caseChat(chatCase()), { kwantId: 'k-ada', threadId: 't-9' });+ assert.deepEqual(m.caseChat(chatCase({ link: null, draft: { ...mailCase().draft, channel: 'kwant', kwant_thread_id: 't-3' } })), { kwantId: 'k-ada', threadId: 't-3' });+ // Cases found before kwant_id existed, and mail cases, have no chat to open.+ assert.equal(m.caseChat(chatCase({ kwant_id: null })), null);+ assert.equal(m.caseChat(chatCase({ link: null })), null);+ assert.equal(m.caseChat(mailCase()), null);++ const opened = [];+ const withChat = ui.card({ c: chatCase(), busy: false, onAction: noop, onOpenChat: (k, t) => opened.push([k, t]) });+ assert.match(withChat, /Open chat/);+ assert.doesNotMatch(withChat, /kwant:\/\//, 'the kwant:// address is never rendered as a link');+ assert.doesNotMatch(ui.card({ c: chatCase({ kwant_id: null }), busy: false, onAction: noop, onOpenChat: noop }), /Open chat/);+ assert.doesNotMatch(ui.card({ c: chatCase(), busy: false, onAction: noop }), /Open chat/, 'no handler, no link');+ assert.doesNotMatch(ui.card({ c: mailCase(), busy: false, onAction: noop, onOpenChat: noop }), /Open chat/);+ assert.match(ui.view(viewProps({ cases: [chatCase()], onOpenChat: noop })), /Open chat/);+});+test('no cases shows the empty state, other tabs say what goes there, and a scan in progress is shown', () => {const empty = ui.view(viewProps({ cases: [] }));assert.match(empty, /No loose ends/);