Skip to content

armgit / kwant

Public Imported from GitHub
0

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.

Answer in chat: close the board when the chat is already selected

pixel-bot5b596884e657
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b1d2c4c..21e37e75 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## Unreleased
+### Fixed
+- **"Answer in chat" works when that chat is already open.** On the Mission board, "Answer in chat" and
+ "Open the chat it came from" now close the board and show the chat even when it's the one already
+ selected underneath; before, nothing visible happened.
+- **An expired card on the Away page is a plain notice.** Answering a card the bot stopped waiting for
+ shows the server's "This card expired: … Ask the bot again." as a neutral notice instead of an error.
+
## [Mac 0.3.0] - 2026-10-29
### Added
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 03e506c6..a67bb892 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -33,6 +33,7 @@ import { AwayPage } from './components/AwayView';
import { LooseEndsPage } from './components/LooseEndsView';
import { MissionBoardPage } from './components/MissionBoardView';
import { MISSION_BOARD_SETTING_EVENT, emitMission, parseMissionBoardSetting, sourceChat } from './missions';
+import { type ChatTarget, planOpenTarget } from './chatTarget';
import { ParallelPage } from './components/ParallelUniverseView';
import { ConnectionsPage } from './components/ConnectionsView';
import { AlertTriangle, Bot, Check, HelpCircle, Inbox, KeyRound, ListChecks, Loader2, MessageSquare, Settings } from 'lucide-react';
@@ -339,7 +340,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
const openQuestionRef = useRef<(kwantId: string) => boolean>(() => false);
// Opens the chat of a bot's newest open browser step; false when it has none.
const openHumanStepRef = useRef<(kwantId: string) => boolean>(() => false);
- const openTargetRef = useRef<(t: { channel_id: string | null; kwant_id: string | null }) => boolean>(() => false);
+ const openTargetRef = useRef<(t: ChatTarget) => boolean>(() => false);
const showNotification = (n: NotifyEvent) => {
// Another space's news is the shell's to show, with a way to switch there.
if (n.space_id && n.space_id !== space.id) return;
@@ -1465,17 +1466,28 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
playSfx('click');
};
+ /** Closes the page on top of the chat (board, Loose ends, Away…) and shows the chat pane. */
+ const revealChat = () => {
+ setShowAway(false);
+ setShowLoose(false);
+ setShowConnections(false);
+ setShowParallel(false);
+ setShowMissions(false);
+ setPhoneView('chat');
+ };
+
/** Opens a channel, or the direct chat with a bot when there's no channel. False if it's gone. */
- const openTarget = (t: { channel_id: string | null; kwant_id: string | null }): boolean => {
- if (t.channel_id) {
- const channel = channels.find((c) => c.id === t.channel_id);
- if (!channel) return false;
- if (selectedIdRef.current !== channel.id) handleSelectChannel(channel);
- return true;
- }
- const kwant = kwants.find((k) => k.id === t.kwant_id);
- if (!kwant) return false;
- if (selectedIdRef.current !== kwant.id || openThreadId) handleSelectKwant(kwant);
+ const openTarget = (t: ChatTarget): boolean => {
+ const plan = planOpenTarget(
+ t,
+ { selectedId: selectedIdRef.current, isChannel: isChannelRef.current, openThreadId },
+ { channel: (id) => channels.some((c) => c.id === id), kwant: (id) => kwants.some((k) => k.id === id) },
+ );
+ if (plan === 'gone') return false;
+ // Already the selected chat: the board or Loose ends may still cover it.
+ if (plan === 'reveal') revealChat();
+ else if (t.channel_id) handleSelectChannel(channels.find((c) => c.id === t.channel_id)!);
+ else handleSelectKwant(kwants.find((k) => k.id === t.kwant_id)!);
return true;
};
openTargetRef.current = openTarget;
diff --git a/frontend/src/away.ts b/frontend/src/away.ts
index 4791e3e1..ae099ac0 100644
--- a/frontend/src/away.ts
+++ b/frontend/src/away.ts
@@ -137,6 +137,22 @@ export function withoutItem(r: AwayResponse, section: AwaySection, id: string):
export const actionErrorText = (status: number, fallback: string): string =>
status === 409 || status === 404 ? 'This request expired' : fallback;
+/** Outcome of a one-tap action; `info` is neither a success nor a failure (a card that expired). */
+export interface AwayNotice {
+ text: string;
+ error: boolean;
+ info?: boolean;
+}
+
+/**
+ * The notice for a failed one-tap action. A card that expired before it was answered is not an error:
+ * the server's own sentence ("This card expired: … Ask the bot again.") is shown as a plain notice.
+ */
+export function actionFailureNotice(status: number, serverMessage: string, title: string): AwayNotice {
+ if (status === 409 && /^This card expired\b/.test(serverMessage)) return { text: `${serverMessage} (“${title}”)`, error: false, info: true };
+ return { text: `${actionErrorText(status, `Couldn't send it: ${serverMessage}`)}: “${title}”`, error: true };
+}
+
export class AwayError extends Error {
constructor(public status: number, message: string) {
super(message);
diff --git a/frontend/src/chatTarget.ts b/frontend/src/chatTarget.ts
new file mode 100644
index 00000000..2cab6a2a
--- /dev/null
+++ b/frontend/src/chatTarget.ts
@@ -0,0 +1,31 @@
+/** Where "Answer in chat", a search hit or a notification wants to go: a channel, or a bot's direct chat. */
+export interface ChatTarget {
+ channel_id: string | null;
+ kwant_id: string | null;
+}
+
+/** What the chat pane shows right now. */
+export interface ShownChat {
+ selectedId: string | null;
+ isChannel: boolean;
+ openThreadId: string | null;
+}
+
+/**
+ * How to open a target: `gone` when it no longer exists, `select` to switch the chat pane to it,
+ * `reveal` when it's already the selected chat and only the page on top (board, Loose ends…) has to close.
+ */
+export type OpenTargetPlan = 'gone' | 'select' | 'reveal';
+
+export function planOpenTarget(
+ t: ChatTarget,
+ shown: ShownChat,
+ exists: { channel: (id: string) => boolean; kwant: (id: string) => boolean },
+): OpenTargetPlan {
+ if (t.channel_id) {
+ if (!exists.channel(t.channel_id)) return 'gone';
+ return shown.isChannel && shown.selectedId === t.channel_id ? 'reveal' : 'select';
+ }
+ if (!t.kwant_id || !exists.kwant(t.kwant_id)) return 'gone';
+ return !shown.isChannel && shown.selectedId === t.kwant_id && !shown.openThreadId ? 'reveal' : 'select';
+}
diff --git a/frontend/src/components/AwayView.tsx b/frontend/src/components/AwayView.tsx
index 4193fa71..1ee6ed68 100644
--- a/frontend/src/components/AwayView.tsx
+++ b/frontend/src/components/AwayView.tsx
@@ -9,9 +9,10 @@ import {
AwayError,
AwayItem,
AwayResponse,
+ AwayNotice,
AwaySection,
Tone,
- actionErrorText,
+ actionFailureNotice,
awayApi,
isAwayEmpty,
itemLabel,
@@ -39,7 +40,7 @@ export interface AwayViewProps {
loading: boolean;
error: string | null;
/** Outcome of the last one-tap action (e.g. "This request expired"); the item may be gone by now. */
- notice?: { text: string; error: boolean } | null;
+ notice?: AwayNotice | null;
/** Item id being acted on. */
busy?: string | null;
now?: number;
@@ -165,7 +166,11 @@ export const AwayView: React.FC<AwayViewProps> = ({ data, loading, error, notice
{notice && (
<p
className={`px-3 py-2 rounded-lg border text-xs ${
- notice.error ? 'border-amber-500/30 bg-amber-500/10 text-amber-200' : 'border-emerald-500/30 bg-emerald-500/10 text-emerald-200'
+ notice.error
+ ? 'border-amber-500/30 bg-amber-500/10 text-amber-200'
+ : notice.info
+ ? 'border-slate-500/30 bg-slate-500/10 text-slate-200'
+ : 'border-emerald-500/30 bg-emerald-500/10 text-emerald-200'
}`}
>
{notice.text}
@@ -227,7 +232,7 @@ export const AwayPage: React.FC<AwayPageProps> = ({ since = null, onSince, onOpe
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState<string | null>(null);
- const [notice, setNotice] = useState<{ text: string; error: boolean } | null>(null);
+ const [notice, setNotice] = useState<AwayNotice | null>(null);
// Refreshes keep the first load's window, so marking it seen doesn't empty the page.
const sinceRef = useRef<string | null>(since);
const onCountsRef = useRef(onCounts);
@@ -281,8 +286,7 @@ export const AwayPage: React.FC<AwayPageProps> = ({ since = null, onSince, onOpe
setNotice({ text: `${done} “${item.title}”`, error: false });
} catch (err) {
const status = err instanceof AwayError ? err.status : 0;
- const text = actionErrorText(status, `Couldn't send it: ${err instanceof Error ? err.message : 'Something went wrong.'}`);
- setNotice({ text: `${text}: “${item.title}”`, error: true });
+ setNotice(actionFailureNotice(status, err instanceof Error ? err.message : 'Something went wrong.', item.title));
} finally {
setBusy(null);
}
diff --git a/frontend/tests/away.test.mjs b/frontend/tests/away.test.mjs
index 406465e6..9d7a5742 100644
--- a/frontend/tests/away.test.mjs
+++ b/frontend/tests/away.test.mjs
@@ -94,6 +94,18 @@ test('a lapsed request reads "This request expired"', () => {
assert.equal(a.actionErrorText(500, 'Couldn’t send it'), 'Couldn’t send it');
});
+test("an expired card's 409 shows the server's sentence as a plain notice, not an error", () => {
+ const msg = 'This card expired: the bot is no longer waiting for it. Ask the bot again.';
+ assert.deepEqual(a.actionFailureNotice(409, msg, 'Use send (mail)'), { text: `${msg} (“Use send (mail)”)`, error: false, info: true });
+ // Other failures stay errors, with the old wording.
+ assert.deepEqual(a.actionFailureNotice(409, 'Already answered', 'X'), { text: 'This request expired: “X”', error: true });
+ assert.deepEqual(a.actionFailureNotice(500, 'Boom', 'X'), { text: "Couldn't send it: Boom: “X”", error: true });
+ const html = ui.render({ data: resp(), loading: false, error: null, busy: null, notice: a.actionFailureNotice(409, msg, 'X'), onRefresh() {}, onOpen() {}, onAnswer() {}, onResolve() {} });
+ assert.match(html, /This card expired/);
+ assert.match(html, /bg-slate-500\/10/);
+ assert.doesNotMatch(html, /bg-amber-500\/10 text-amber-200[^>]*>This card expired/);
+});
+
const noop = () => {};
const view = (over = {}) => ui.render({ data: resp(), loading: false, error: null, now: NOW, onRefresh: noop, onOpen: noop, onAnswer: noop, onResolve: noop, ...over });
diff --git a/frontend/tests/chatTarget.test.mjs b/frontend/tests/chatTarget.test.mjs
new file mode 100644
index 00000000..8c295c14
--- /dev/null
+++ b/frontend/tests/chatTarget.test.mjs
@@ -0,0 +1,44 @@
+// "Answer in chat" / "Open the chat it came from" on the Mission board: the chat it points at may
+// already be the selected one, under the board. It must still close the board and show that chat.
+import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
+import test from 'node:test';
+import { loadBundled } from './bundle.mjs';
+
+const { planOpenTarget } = await loadBundled(`export * from './src/chatTarget';`);
+
+const exists = { channel: (id) => id === 'c1' || id === 'c2', kwant: (id) => id === 'shelly' || id === 'lead' };
+const shown = (over = {}) => ({ selectedId: 'shelly', isChannel: false, openThreadId: null, ...over });
+
+test("the owner's direct chat is already selected: reveal it instead of doing nothing", () => {
+ assert.equal(planOpenTarget({ channel_id: null, kwant_id: 'shelly' }, shown(), exists), 'reveal');
+});
+
+test('a channel that is already selected is revealed too', () => {
+ assert.equal(planOpenTarget({ channel_id: 'c1', kwant_id: null }, shown({ selectedId: 'c1', isChannel: true }), exists), 'reveal');
+});
+
+test('another chat, or a thread of the same bot, switches the chat pane', () => {
+ assert.equal(planOpenTarget({ channel_id: null, kwant_id: 'lead' }, shown(), exists), 'select');
+ assert.equal(planOpenTarget({ channel_id: 'c2', kwant_id: null }, shown({ selectedId: 'c1', isChannel: true }), exists), 'select');
+ assert.equal(planOpenTarget({ channel_id: null, kwant_id: 'shelly' }, shown({ openThreadId: 't1' }), exists), 'select');
+ assert.equal(planOpenTarget({ channel_id: 'c1', kwant_id: null }, shown(), exists), 'select');
+});
+
+test('a chat that no longer exists is gone', () => {
+ assert.equal(planOpenTarget({ channel_id: 'nope', kwant_id: null }, shown(), exists), 'gone');
+ assert.equal(planOpenTarget({ channel_id: null, kwant_id: 'nope' }, shown(), exists), 'gone');
+ assert.equal(planOpenTarget({ channel_id: null, kwant_id: null }, shown(), exists), 'gone');
+});
+
+test("App's openTarget closes the board and Loose ends when the chat is already selected", () => {
+ const app = readFileSync(new URL('../src/App.tsx', import.meta.url), 'utf8');
+ const reveal = app.match(/const revealChat = \(\) => \{([\s\S]*?)\n \};/);
+ assert.ok(reveal, 'revealChat exists');
+ for (const call of ['setShowMissions(false)', 'setShowLoose(false)', 'setShowAway(false)', "setPhoneView('chat')"]) {
+ assert.ok(reveal[1].includes(call), `revealChat calls ${call}`);
+ }
+ const open = app.match(/const openTarget = \(t: ChatTarget\): boolean => \{([\s\S]*?)\n \};/);
+ assert.ok(open, 'openTarget exists');
+ assert.match(open[1], /if \(plan === 'reveal'\) revealChat\(\);/);
+});