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.

30o point-overlay-fixes: hover tag never covers the Point bar; Point turns off after Send (#891)

Oleksandr Ivanchenkof9c025088646
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index 8c6818b9..eb5074b6 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -1389,7 +1389,10 @@ export const ChatView: React.FC<ChatViewProps> = ({
};
// G3 Point at it: a pick from the browser pane is a composer upload with a `point`
+ // 30o: counts the sent messages that carried a pick; the pane turns Point off when it goes up.
+ const [sentPicks, setSentPicks] = useState(0);
const pointSink: PointSink = {
+ sentPicks,
picks: pointPicks(uploads),
filesLeft: uploadSlotsLeft(uploads),
start: (label, n, { fromMouse }) => {
@@ -1483,7 +1486,9 @@ export const ChatView: React.FC<ChatViewProps> = ({
playSfx('click');
stickRef.current = true;
const replying = replyTo;
- const sent = onSendMessage(inputVal.trim(), readyAttachments(uploads), replying ? { replyTo: replying } : undefined);
+ const refs = readyAttachments(uploads);
+ const sent = onSendMessage(inputVal.trim(), refs, replying ? { replyTo: replying } : undefined);
+ if (refs.some((r) => r.point)) setSentPicks((n) => n + 1);
setReplyTo(null);
// A send that fails keeps the reply, unless the person has moved on to another one.
if (replying && sent && typeof (sent as Promise<unknown>).then === 'function')
diff --git a/frontend/src/components/PointLayer.tsx b/frontend/src/components/PointLayer.tsx
index b7907137..bc61c269 100644
--- a/frontend/src/components/PointLayer.tsx
+++ b/frontend/src/components/PointLayer.tsx
@@ -22,6 +22,7 @@ import {
pickedCountText,
spokenText,
tagPlacement,
+ tagTop,
tagText,
toPage,
toView,
@@ -39,6 +40,8 @@ export interface PointSink {
done(key: string, pick: PointPick): void;
/** The capture failed: the chip goes away. */
fail(key: string): void;
+ /** Goes up each time a message carrying at least one pick is sent: Point turns off then (30o). */
+ sentPicks?: number;
}
export interface PointLayerProps {
@@ -365,7 +368,7 @@ export const PointLayer: React.FC<PointLayerProps> = ({ request, page, frameId,
onKeyDown={onKeyDown}
className="absolute inset-0 z-10 cursor-crosshair rounded-xl ring-2 ring-inset ring-sky-500/70 focus:outline-none focus-visible:ring-[3px] focus-visible:ring-sky-300"
>
- <div className="absolute top-0 inset-x-0 h-7 px-2.5 flex items-center justify-between gap-2 bg-[rgb(14_10_33/0.88)] text-[11.5px] text-zinc-100 pointer-events-none rounded-t-xl">
+ <div className="absolute top-0 inset-x-0 z-[1] h-7 px-2.5 flex items-center justify-between gap-2 bg-[rgb(14_10_33/0.88)] text-[11.5px] text-zinc-100 pointer-events-none rounded-t-xl">
<span className="truncate font-semibold">{bar?.kind === 'waiting' ? bar.text : topText}</span>
{!phone && <span className="shrink-0 text-zinc-400">{POINT_COPY.keys}</span>}
</div>
@@ -387,7 +390,7 @@ export const PointLayer: React.FC<PointLayerProps> = ({ request, page, frameId,
}`}
style={{
left: Math.max(4, Math.min(outline.x, size.width - 4 - tagW)),
- top: place === 'above' ? outline.y - 20 : place === 'below' ? outline.y + outline.height + 2 : outline.y + 2,
+ top: tagTop(outline, place, size.height),
}}
>
{tagLabel}
diff --git a/frontend/src/components/VirtualMachinePane.tsx b/frontend/src/components/VirtualMachinePane.tsx
index e2929c99..c81fe07d 100644
--- a/frontend/src/components/VirtualMachinePane.tsx
+++ b/frontend/src/components/VirtualMachinePane.tsx
@@ -556,6 +556,14 @@ export const VirtualMachinePane: React.FC<VirtualMachinePaneProps> = ({
setPointing(false);
pointButton.current?.focus();
}, []);
+ // 30o: a message with picks went out, so Point turns off; focus stays in the composer (not stopPointing)
+ const sentPicks = point?.sentPicks ?? 0;
+ const lastSentPicks = useRef(sentPicks);
+ useEffect(() => {
+ if (sentPicks === lastSentPicks.current) return;
+ lastSentPicks.current = sentPicks;
+ setPointing(false);
+ }, [sentPicks]);
// 0.9.8 D: a panel the bot opened stays open while the person controls it or has picks to send
const pointPending = (point?.picks ?? 0) > 0;
diff --git a/frontend/src/point.ts b/frontend/src/point.ts
index 95fe8f45..85cf1362 100644
--- a/frontend/src/point.ts
+++ b/frontend/src/point.ts
@@ -302,13 +302,23 @@ export function toView(fit: Fit, page: { width: number; height: number }, box: P
};
}
-/** The tag goes above the outline, or below it when there's no room above (inside it as a last resort). */
-export function tagPlacement(outline: PointBox, viewHeight: number, tagHeight = 18): 'above' | 'below' | 'inside' {
- if (outline.y >= tagHeight + 2) return 'above';
+/** The Point bar across the top of the view (PointLayer's `h-7`): the tag never goes on it. */
+export const POINT_BAR_H = 28;
+
+/** The tag goes above the outline when it clears the Point bar, else below it, else inside it (bottom left). */
+export function tagPlacement(outline: PointBox, viewHeight: number, barHeight = POINT_BAR_H, tagHeight = 18): 'above' | 'below' | 'inside' {
+ if (outline.y >= barHeight + tagHeight + 2) return 'above';
if (outline.y + outline.height + tagHeight + 2 <= viewHeight) return 'below';
return 'inside';
}
+/** The tag's top for a placement: 2 px off the outline, or 22 px up from the outline's (visible) bottom when inside. */
+export function tagTop(outline: PointBox, place: 'above' | 'below' | 'inside', viewHeight: number, tagHeight = 18): number {
+ if (place === 'above') return outline.y - tagHeight - 2;
+ if (place === 'below') return outline.y + outline.height + 2;
+ return Math.min(outline.y + outline.height, viewHeight) - tagHeight - 4;
+}
+
/** The arrow keys' directions. */
export const ARROW_DIRS: Record<string, 'parent' | 'child' | 'prev' | 'next'> = {
ArrowUp: 'parent',
diff --git a/frontend/tests/point.test.mjs b/frontend/tests/point.test.mjs
index 8b6dcbb9..8bbd4943 100644
--- a/frontend/tests/point.test.mjs
+++ b/frontend/tests/point.test.mjs
@@ -86,6 +86,17 @@ test('geometry: object-contain letterbox, view to page and back, clipped outline
assert.deepEqual(m.toView(fit, { width: 1280, height: 800 }, { x: -20, y: 790, width: 100, height: 40 }), { x: 0, y: 445, width: 40, height: 5 });
assert.equal(m.tagPlacement({ x: 0, y: 4, width: 10, height: 10 }, 400), 'below');
assert.equal(m.tagPlacement({ x: 0, y: 4, width: 10, height: 395 }, 400), 'inside');
+ // 30o: the tag never covers the 28 px Point bar
+ const full = { x: 0, y: 0, width: 1265, height: 900 };
+ const low = { x: 0, y: 30, width: 200, height: 40 };
+ assert.equal(m.tagPlacement(low, 900), 'below', 'y 30 has no room above the bar any more');
+ assert.equal(m.tagPlacement(full, 900), 'inside', 'a full-view element keeps its tag inside');
+ assert.equal(m.tagTop(full, 'inside', 900), 878, 'bottom left inside the outline, not on the bar');
+ assert.equal(m.tagTop(low, 'below', 900), 72);
+ assert.equal(m.tagPlacement({ x: 0, y: 48, width: 10, height: 10 }, 900), 'above', 'above from y 48 (bar 28 + tag 18 + 2)');
+ assert.equal(m.tagTop({ x: 0, y: 48, width: 10, height: 10 }, 'above', 900), 28, 'an above tag starts right under the bar');
+ assert.equal(m.tagTop({ x: 0, y: 100, width: 10, height: 2000 }, 'inside', 900), 878, 'inside measures from the visible bottom');
+ assert.equal(m.POINT_BAR_H, 28);
});
test('composer: n/of by the picks\' order, other files not counted; the bubble parses it back', () => {
diff --git a/frontend/tests/pointOffAfterSend.test.mjs b/frontend/tests/pointOffAfterSend.test.mjs
new file mode 100644
index 00000000..e5987df8
--- /dev/null
+++ b/frontend/tests/pointOffAfterSend.test.mjs
@@ -0,0 +1,149 @@
+// 30o point-overlay-fixes (autonomy/point-overlay-fixes/design.md, Fix B): once the person sends a message that
+// carries a pick, Point turns off (layer, bar and "Pointing · n picked" go, the button is off) and focus stays in
+// the composer. A send without picks leaves Point on. Real ChatView with its browser pane; the pane's socket is faked
+// the way the server answers the point actions. Fails on main 43c2aa89, where Point stays on after the send.
+// Element checks are booleans: a failing assert must never try to print a jsdom node.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/s/spc_default', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'HTMLButtonElement', 'HTMLInputElement', 'HTMLTextAreaElement', 'HTMLImageElement', 'Element', 'Node', 'Event', 'FocusEvent', 'MouseEvent', 'KeyboardEvent', 'MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'CSS', 'DOMException']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+const store = new Map();
+const ls = { getItem: (k) => (store.has(k) ? store.get(k) : null), setItem: (k, v) => void store.set(k, String(v)), removeItem: (k) => void store.delete(k) };
+Object.defineProperty(g, 'localStorage', { value: ls, configurable: true, writable: true });
+Object.defineProperty(dom.window, 'localStorage', { value: ls, configurable: true });
+Object.defineProperty(g, 'sessionStorage', { value: ls, configurable: true, writable: true });
+g.window.matchMedia = (q) => ({ matches: false, media: q, addEventListener() {}, removeEventListener() {}, addListener() {}, removeListener() {} });
+g.matchMedia = g.window.matchMedia;
+g.ResizeObserver = g.window.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} };
+g.IntersectionObserver = g.window.IntersectionObserver = class { observe() {} unobserve() {} disconnect() {} };
+dom.window.HTMLElement.prototype.scrollIntoView ??= function () {};
+dom.window.HTMLElement.prototype.scrollTo ??= function () {};
+g.fetch = g.window.fetch = async () => ({ ok: false, status: 404, json: async () => ({}), text: async () => '' });
+
+const box = { x: 15, y: 303, width: 328, height: 36 };
+const sockets = [];
+class FakeWebSocket {
+ static OPEN = 1;
+ constructor(url) { this.url = url; this.readyState = 1; this.sent = []; this.bufferedAmount = 0; sockets.push(this); }
+ send(text) {
+ const p = JSON.parse(text);
+ this.sent.push(p);
+ if (typeof p.id !== 'number') return;
+ const el = { handle: 'k3f9.12', label: 'button.pay', box, viewport: { width: 1280, height: 800 }, text: 'Pay' };
+ if (p.action === 'point_neighbour' || p.action === 'point_at') setTimeout(() => this.receive({ type: 'ack', id: p.id, el }), 0);
+ if (p.action === 'point_pick') {
+ setTimeout(() => this.receive({ type: 'ack', id: p.id, pick: { attachment_id: '6b0c1d2e-3f40-4a5b-8c6d-7e8f90a1b2c3', picture: true, url: 'https://shop.example.com/', host: 'shop.example.com', path: '/', label: 'button.pay', box, viewport: { width: 1280, height: 800 }, captured_at: '2026-11-15T05:00:00Z' } }), 0);
+ }
+ }
+ close() { this.readyState = 3; }
+ receive(message) { this.onmessage?.({ data: JSON.stringify(message) }); }
+}
+g.WebSocket = g.window.WebSocket = FakeWebSocket;
+
+const ui = await loadBundled(`
+ import React from 'react';
+ import { flushSync } from 'react-dom';
+ import { createRoot } from 'react-dom/client';
+ import { ChatView } from './src/components/ChatView';
+ export const mount = (p) => {
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ const root = createRoot(host);
+ flushSync(() => root.render(React.createElement(ChatView, p)));
+ return { host, unmount: () => { root.unmount(); host.remove(); } };
+ };
+`);
+const settle = async () => {
+ for (let i = 0; i < 20; i++) {
+ await new Promise((r) => setImmediate(r));
+ await new Promise((r) => setTimeout(r, 0));
+ }
+};
+const key = (target, k) => target.dispatchEvent(new window.KeyboardEvent('keydown', { key: k, bubbles: true }));
+const type = (ta, text) => {
+ Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value').set.call(ta, text);
+ ta.dispatchEvent(new window.Event('input', { bubbles: true }));
+};
+const textarea = (host) => host.querySelector('form textarea');
+const send = async (host) => {
+ host.querySelector('form').dispatchEvent(new window.Event('submit', { bubbles: true, cancelable: true }));
+ await settle();
+};
+
+async function pointingInChat() {
+ const sends = [];
+ const { host, unmount } = ui.mount({
+ title: 'Ben', subtitle: 'Browser', messages: [], streamingText: '', streamingThinking: '', isStreaming: false,
+ pendingApprovals: [], onSendMessage: (text, atts) => { sends.push({ text, atts }); }, onResolveApproval: () => {}, onCancelDiscussion: () => {},
+ kwants: [], teams: [], teamId: 'k1', teamName: 'Ben', isVmPaneOpen: true, onToggleVmPane: () => {},
+ home: { kind: 'bot', bot: { id: 'k1', name: 'Ben', title: 'Browser', avatar_sprite: 'Frontend' } },
+ });
+ try {
+ await settle();
+ const ws = sockets.at(-1);
+ assert.ok(ws, 'the browser pane opened its socket');
+ ws.onopen?.();
+ ws.receive({ type: 'location', url: 'https://shop.example.com/', title: 'Shop' });
+ ws.receive({ type: 'frame', id: 1, image: 'AAAA', width: 1280, height: 800 });
+ await settle();
+ const button = host.querySelector('[data-point-button]');
+ assert.ok(button, 'Point at it shows once a page is on screen');
+ button.dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
+ await settle();
+ assert.ok(host.querySelector('[data-point-layer]'), 'Point is on');
+ return { host, unmount, ws, sends };
+ } catch (e) {
+ unmount();
+ throw e;
+ }
+}
+
+test('a send that carries a pick turns Point off; focus stays in the composer', async () => {
+ const { host, unmount, ws, sends } = await pointingInChat();
+ try {
+ const view = host.querySelector('[data-point-layer]');
+ key(view, 'ArrowUp');
+ await settle();
+ key(view, 'Enter');
+ await settle();
+ assert.ok(ws.sent.some((s) => s.action === 'point_pick'), 'the pick went to the browser');
+ assert.ok(host.querySelector('[data-point-layer]'), 'a click keeps Point on, to pick more');
+ const ta = textarea(host);
+ type(ta, 'Why is this button grey?');
+ ta.focus();
+ await settle();
+ await send(host);
+ assert.equal(sends.length, 1, 'the message went out');
+ assert.equal(sends[0].atts.filter((a) => a.point).length, 1, 'with the pick');
+ assert.ok(!host.querySelector('[data-point-layer]'), 'Point turned off: no ring, bar or outline');
+ assert.ok(!host.querySelector('[data-point-footer]'), 'no "Pointing · 0 picked" footer');
+ const button = host.querySelector('[data-point-button]');
+ assert.ok(button, 'the Point button stays');
+ assert.equal(button.getAttribute('aria-pressed'), 'false', 'the Point button is off');
+ assert.ok(document.activeElement === textarea(host), 'focus stays in the composer (not moved to the Point button)');
+ } finally {
+ unmount();
+ }
+});
+
+test('a send without picks leaves Point on', async () => {
+ const { host, unmount, sends } = await pointingInChat();
+ try {
+ type(textarea(host), 'Keep going');
+ await settle();
+ await send(host);
+ assert.equal(sends.length, 1, 'the message went out');
+ assert.equal(sends[0].atts.length, 0, 'no attachments');
+ assert.ok(host.querySelector('[data-point-layer]'), 'Point stays on');
+ assert.ok(host.querySelector('[data-point-footer]'), 'the footer still says Pointing');
+ } finally {
+ unmount();
+ }
+});