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.

Smart Results follow-up: Ask about this twice, long Evidence at 390 px (#233)

Oleksandr Ivanchenko985614a1e147
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index 94bf10f3..c00a6e8b 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -47,7 +47,7 @@ import { approvalScrollAction, fullyVisible, isNearBottom, nextFollowing } from
import { DecidingLine, DecisionChips, WorkAheadBody } from './Proactive';
import { RouteChoiceMeta, parseRouteChoiceMeta, questionsOfReplies } from '../routeChoice';
import { SmartActionsSlot } from './results/SmartActions';
-import { COMPOSE_PREFILL_EVENT } from './results/SmartResult';
+import { COMPOSE_PREFILL_EVENT, withPrefill } from './results/SmartResult';
import { FilesPreviewOnly } from './results/Files';
/** A swipeable chip row whose right fade edge (phones only, see .kw-scroll-row) goes away once
@@ -914,7 +914,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
const prefill = (e: Event) => {
const text = (e as CustomEvent<{ text?: unknown }>).detail?.text;
if (typeof text !== 'string' || !text) return;
- setInputVal((prev) => (prev.trim() ? `${prev.trimEnd()}\n${text}` : text));
+ setInputVal((prev) => withPrefill(prev, text));
requestAnimationFrame(() => {
const el = textareaRef.current;
if (!el) return;
diff --git a/frontend/src/components/results/SmartResult.tsx b/frontend/src/components/results/SmartResult.tsx
index ba1f80f0..c12b4cb7 100644
--- a/frontend/src/components/results/SmartResult.tsx
+++ b/frontend/src/components/results/SmartResult.tsx
@@ -9,6 +9,12 @@ import { SmartActions, actionClass } from './SmartActions';
/** "Ask about this": ChatView puts `text` in the composer and focuses it. Nothing is sent. */
export const COMPOSE_PREFILL_EVENT = 'kwnt:compose-prefill';
+/** The composer's text after "Ask about this": the line goes on a new line, and asking again for the same line changes nothing. */
+export const withPrefill = (prev: string, text: string): string => {
+ if (!prev.trim()) return text;
+ const last = prev.trimEnd().split('\n').pop() ?? '';
+ return last.trim() === text.trim() ? prev : `${prev.trimEnd()}\n${text}`;
+};
export const askAbout = (text: string) => window.dispatchEvent(new CustomEvent(COMPOSE_PREFILL_EVENT, { detail: { text } }));
const textKey = (messageId: string) => `kwnt:smart-text:${messageId}`;
@@ -190,7 +196,7 @@ const CopyData: React.FC<{ block: SmartBlock; messageId: string }> = ({ block, m
/** The footer every block shares, in the message's action row: Evidence, Show as text, Copy data. */
const Footer: React.FC<{ block: SmartBlock; messageId: string; asText: boolean; onToggle: () => void }> = ({ block, messageId, asText, onToggle }) => (
<SmartActions messageId={messageId}>
- <span className="min-w-0 px-1 text-[11px] text-zinc-500" data-evidence>
+ <span className="min-w-0 max-w-full truncate px-1 text-[11px] text-zinc-500" data-evidence title={evidenceText(block)}>
{evidenceText(block)}
</span>
<button type="button" aria-pressed={asText} onClick={onToggle} className={`${actionClass} ${asText ? 'bg-zinc-900 text-zinc-300' : ''}`}>
diff --git a/frontend/tests/smartResults.test.mjs b/frontend/tests/smartResults.test.mjs
index 46ec80f1..446ce2a2 100644
--- a/frontend/tests/smartResults.test.mjs
+++ b/frontend/tests/smartResults.test.mjs
@@ -30,7 +30,7 @@ const m = await loadBundled(`
export { REGISTRY, resolveBlock } from './src/components/results/registry';
export { FIXTURES } from './src/components/results/fixtures';
export { blockCsv, blockMarkdown, blockRows } from './src/components/results/exporters';
- export { COMPOSE_PREFILL_EVENT, evidenceText } from './src/components/results/SmartResult';
+ export { COMPOSE_PREFILL_EVENT, evidenceText, withPrefill } from './src/components/results/SmartResult';
export { shortList } from './src/components/results/Comparison';
`);
const { React, createRoot } = m;
@@ -620,3 +620,15 @@ test('a reply’s HTML is shown as text, in plain markdown and next to a block',
assert.match(v.host.textContent, /<b>bold<\/b>/);
assert.equal(window.__pwned, undefined);
});
+
+test('Ask about this: asking again for the same line leaves the composer as it is (SR-U-18)', () => {
+ const line = 'About Basic in your Plan table: ';
+ assert.equal(m.withPrefill('', line), line);
+ assert.equal(m.withPrefill('Hi', line), `Hi\n${line}`);
+ assert.equal(m.withPrefill(`Hi\n${line}`, line), `Hi\n${line}`);
+ assert.equal(m.withPrefill(line, line), line);
+ // another row still goes on its own line
+ assert.equal(m.withPrefill(line, 'About Pro in your Plan table: '), `${line.trimEnd()}\nAbout Pro in your Plan table: `);
+ // the person typed after the line: the line comes back below it
+ assert.equal(m.withPrefill(`${line}and why?`, line), `${line}and why?\n${line}`);
+});