Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions design-system/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ OPENBITFUN_WORKBENCH_MOTION_CONTRACT=1 OPENBITFUN_MOTION_REFERENCE_COMMIT=HEAD O
Use a pre-change reference commit when testing an already committed change.
The native fixture runs outside performance windows. Geometry equivalence does
not establish pixel-identical rasterization or coverage on other WebView engines.

For shared queue pointer/keyboard interaction, cancellation and focus retention:

```bash
pnpm --dir src/web-ui exec vitest run src/flow_chat/components/useQueueReorder.test.tsx
```
9 changes: 9 additions & 0 deletions design-system/packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,12 @@ Checkbox, Select, Combobox, MultiSelect, NumberInput, SearchField and Textarea
consume those references through intervening wrappers. A control's explicit name
or own label takes precedence; descriptions are combined. Give each child in a
composite field its own name. Nested `Field` controls retain their own labels.

`ChatComposerQueue` has no outer border. Each row starts with an inset hairline;
the final row has no bottom hairline and meets the composer without an extra
gap. `ChatComposerQueueItem.leadingControl` accepts an accessible interactive
control; `leadingIcon` remains decorative. `useQueueReorder` supplies pointer
capture, keyboard moves, edge scrolling and cancellation when the authoritative
revision changes. Pass only reorderable IDs and keep the actual order in the
product owner until its mutation succeeds. Disabled or legacy hosts must expose
a clear reason in their product surface.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
gap: var(--openbitfun-space-2);
}

.body:has(> .queue > :global([data-openbitfun-component="chat-composer-queue"])) {
gap: 0;
}

.queue {
/* The wrapper exists when a queue component later renders `null`. Keeping
it out of the box tree makes both that transition and the no-queue path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,13 @@
inline-size: 100%;
flex-direction: column;
gap: var(--openbitfun-space-1);
padding: var(--openbitfun-space-1);
border: var(--openbitfun-border-width-default) solid var(--openbitfun-color-border-subtle);
border-radius: var(--openbitfun-control-composer-surface-radius);
padding: var(--openbitfun-space-1) var(--openbitfun-space-1) 0;
border: 0;
border-radius: 0;
container: composer-queue / inline-size;
color: var(--openbitfun-color-content-primary);
background: var(--openbitfun-color-surface-subtle);
font-family:var(--openbitfun-type-body-md-font-family);
}

/* A composer with a context bar already tints the tray around its input.
The queue joins that tray instead of stacking a second translucent card. */
:global([data-openbitfun-component="chat-composer"][data-has-context="true"]) .root {
margin-block-end: calc(-1 * var(--openbitfun-space-2));
padding-block-end: var(--openbitfun-space-3);
border-block-end: 0;
border-end-start-radius: 0;
border-end-end-radius: 0;
background: transparent;
font-family:var(--openbitfun-type-body-md-font-family);
}

.header {
Expand Down Expand Up @@ -102,6 +91,7 @@
}

.item {
position: relative;
box-sizing: border-box;
display: flex;
flex: 0 0 auto;
Expand All @@ -114,6 +104,29 @@
color: var(--openbitfun-color-content-primary);
}

.item::before {
content: "";
position: absolute;
inset-inline: var(--openbitfun-space-2);
inset-block-start: 0;
border-block-start: var(--openbitfun-border-width-default) solid var(--openbitfun-color-border-subtle);
pointer-events: none;
}

.item[data-queue-dragging] {
z-index: 1;
background: var(--openbitfun-color-surface-panel);
box-shadow: var(--openbitfun-shadow-sm);
}
.item[data-queue-drop="before"] { box-shadow: inset 0 2px var(--openbitfun-color-focus-ring); }
.item[data-queue-drop="after"] { box-shadow: inset 0 -2px var(--openbitfun-color-focus-ring); }
.item [data-queue-handle] {
cursor: grab;
touch-action: none;
user-select: none;
}
.item [data-queue-handle]:active { cursor: grabbing; }

/* The row, not a floating button cluster, is the unit being acted on. */
.item:focus-within {
background: var(--openbitfun-color-surface-subtle);
Expand Down Expand Up @@ -223,6 +236,8 @@
.actions [data-openbitfun-component="button"][data-openbitfun-variant="text"] {
flex: 1 1 0;
min-inline-size: 0;
justify-content: flex-start;
text-align: start;
color: var(--openbitfun-color-content-secondary);
padding-inline: var(--openbitfun-space-2);
}
Expand All @@ -237,6 +252,9 @@
.actions {
--_queue-primary-action-size: var(--_queue-action-size);
}
.actions [data-openbitfun-component="button"][data-openbitfun-variant="text"] {
justify-content: center;
}
.actions [data-openbitfun-component="button"] [data-openbitfun-part="label"] {
display: none;
}
Expand All @@ -252,8 +270,6 @@
}

@media (forced-colors: active) {
.root {
border: var(--openbitfun-border-width-default) solid CanvasText;
}
.item::before { border-color: CanvasText; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface ChatComposerQueueItemProps
extends LiHTMLAttributes<HTMLLIElement> {
state?: ChatComposerQueueItemState;
leadingIcon?: ReactNode;
/** Interactive leading slot; unlike leadingIcon it remains accessible. */
leadingControl?: ReactNode;
}

export interface ChatComposerQueueItemContentProps
Expand Down Expand Up @@ -159,7 +161,7 @@ export const ChatComposerQueueList = forwardRef<
export const ChatComposerQueueItem = forwardRef<
HTMLLIElement,
ChatComposerQueueItemProps
>(function ChatComposerQueueItem({ children, className, leadingIcon, state = "default", ...props }, ref) {
>(function ChatComposerQueueItem({ children, className, leadingIcon, leadingControl, state = "default", ...props }, ref) {
return (
<li
{...props}
Expand All @@ -169,7 +171,8 @@ export const ChatComposerQueueItem = forwardRef<
data-openbitfun-state={state === "default" ? undefined : state}
ref={ref}
>
{leadingIcon && <span className={styles.leadingIcon} data-openbitfun-part="leading-icon" aria-hidden="true">{leadingIcon}</span>}
{leadingControl && <span className={styles.leadingIcon} data-openbitfun-part="leading-control">{leadingControl}</span>}
{!leadingControl && leadingIcon && <span className={styles.leadingIcon} data-openbitfun-part="leading-icon" aria-hidden="true">{leadingIcon}</span>}
{children}
</li>
);
Expand Down
2 changes: 2 additions & 0 deletions design-system/packages/ui/src/flow-chat/composer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export {
type ChatComposerQueueTitleProps,
type ChatComposerQueueToggleProps,
} from "./ChatComposerQueue";

export { useQueueReorder } from './useQueueReorder';
146 changes: 146 additions & 0 deletions design-system/packages/ui/src/flow-chat/composer/useQueueReorder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { useEffect, useRef, useState, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent } from 'react';

type Drag = {
id: string;
startY: number;
pointerY: number;
pointerId: number;
handle: HTMLButtonElement;
order: string[];
revision: string | number;
before: string | null;
scroller: HTMLElement;
scrollTop: number;
moved: boolean;
};

/** Pointer/keyboard presentation only. The caller owns authoritative ordering. */
export function useQueueReorder(ids: string[], enabled: boolean, revision: string | number,
onMove: (id: string, beforeId: string | null) => void) {
const rows = useRef(new Map<string, HTMLLIElement>());
const drag = useRef<Drag | null>(null);
const frame = useRef<number | null>(null);
const focusAfterMove = useRef<string | null>(null);
const [visual, setVisual] = useState<{ id: string; y: number; before: string | null } | null>(null);
const identity = ids.join('\0');
const latest = useRef({ enabled, revision, identity, onMove });
latest.current = { enabled, revision, identity, onMove };

const requestMove = (id: string, before: string | null) => {
focusAfterMove.current = id;
latest.current.onMove(id, before);
};
const stopFrame = () => {
if (frame.current !== null) cancelAnimationFrame(frame.current);
frame.current = null;
};
const finish = (commit: boolean) => {
const current = drag.current;
drag.current = null;
stopFrame();
setVisual(null);
if (!current) return;
if (current.handle.hasPointerCapture?.(current.pointerId)) current.handle.releasePointerCapture(current.pointerId);
const originalBefore = current.order[current.order.indexOf(current.id) + 1] ?? null;
if (commit && current.moved && current.before !== originalBefore && latest.current.enabled
&& latest.current.revision === current.revision && latest.current.identity === current.order.join('\0')) {
requestMove(current.id, current.before);
}
};
useEffect(() => {
finish(false);
if (enabled && focusAfterMove.current) {
const handle = rows.current.get(focusAfterMove.current)?.querySelector<HTMLButtonElement>('[data-queue-handle]');
// Disabling controls during a host mutation can move focus to the body.
// Restore the moved row, but do not interrupt a user who moved elsewhere.
if (handle && !handle.disabled && (document.activeElement === document.body || document.activeElement === handle)) handle.focus();
focusAfterMove.current = null;
}
}, [identity, enabled, revision]);
useEffect(() => {
const cancel = (event: KeyboardEvent) => {
if (event.key === 'Escape' && drag.current) { event.preventDefault(); finish(false); }
};
const blur = () => finish(false);
window.addEventListener('keydown', cancel);
window.addEventListener('blur', blur);
return () => {
window.removeEventListener('keydown', cancel);
window.removeEventListener('blur', blur);
const current = drag.current;
drag.current = null;
stopFrame();
if (current?.handle.hasPointerCapture?.(current.pointerId)) current.handle.releasePointerCapture(current.pointerId);
};
}, []);

const paint = (current: Drag) => {
current.before = current.order.find(id => {
if (id === current.id) return false;
const row = rows.current.get(id);
if (!row) return false;
const rect = row.getBoundingClientRect();
return current.pointerY < rect.top + rect.height / 2;
}) ?? null;
setVisual({ id: current.id, y: current.pointerY - current.startY + current.scroller.scrollTop - current.scrollTop, before: current.before });
};
const scrollFrame = () => {
frame.current = null;
const current = drag.current;
if (!current?.moved) return;
const bounds = current.scroller.getBoundingClientRect();
const speed = current.pointerY < bounds.top + 24 ? -6 : current.pointerY > bounds.bottom - 24 ? 6 : 0;
const previous = current.scroller.scrollTop;
if (speed) current.scroller.scrollTop += speed;
if (previous !== current.scroller.scrollTop) paint(current);
if (speed) frame.current = requestAnimationFrame(scrollFrame);
};
const update = (event: ReactPointerEvent<HTMLButtonElement>) => {
const current = drag.current;
if (!current || current.pointerId !== event.pointerId) return;
current.pointerY = event.clientY;
current.moved ||= Math.abs(event.clientY - current.startY) > 4;
if (!current.moved) return;
paint(current);
if (frame.current === null) frame.current = requestAnimationFrame(scrollFrame);
};
return {
rowProps(id: string) {
return {
ref: (node: HTMLLIElement | null) => { if (node) rows.current.set(id, node); else rows.current.delete(id); },
'data-queue-dragging': visual?.id === id || undefined,
'data-queue-drop': visual && visual.id !== id && (visual.before === id ? 'before'
: visual.before === null && id === ids.filter(value => value !== visual.id).slice(-1)[0] ? 'after' : undefined),
style: visual?.id === id ? { transform: `translateY(${visual.y}px)` } as CSSProperties : undefined,
};
},
handleProps(id: string) {
return {
'data-queue-handle': true,
disabled: !enabled || ids.length < 2 || !ids.includes(id),
onPointerDown(event: ReactPointerEvent<HTMLButtonElement>) {
if (!enabled || ids.length < 2 || !ids.includes(id) || event.button !== 0 || drag.current) return;
const row = rows.current.get(id);
if (!row?.parentElement) return;
event.preventDefault();
event.currentTarget.focus();
event.currentTarget.setPointerCapture(event.pointerId);
drag.current = { id, startY: event.clientY, pointerY: event.clientY, pointerId: event.pointerId,
handle: event.currentTarget, order: [...ids], revision, before: ids[ids.indexOf(id) + 1] ?? null,
scroller: row.parentElement, scrollTop: row.parentElement.scrollTop, moved: false };
},
onPointerMove: update,
onPointerUp: (event: ReactPointerEvent<HTMLButtonElement>) => { if (drag.current?.pointerId === event.pointerId) finish(true); },
onPointerCancel: () => finish(false),
onLostPointerCapture: () => finish(false),
onKeyDown(event: ReactKeyboardEvent<HTMLButtonElement>) {
if (!enabled || drag.current || !['ArrowUp', 'ArrowDown'].includes(event.key)) return;
event.preventDefault();
const index = ids.indexOf(id);
if (event.key === 'ArrowUp' && index > 0) requestMove(id, ids[index - 1]!);
if (event.key === 'ArrowDown' && index >= 0 && index < ids.length - 1) requestMove(id, ids[index + 2] ?? null);
},
};
},
};
}
4 changes: 2 additions & 2 deletions design-system/packages/ui/tests/chat-composer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ test("ChatComposer queue keeps actions visible and message ink primary", async (
assert.ok(actionsRule);
assert.ok(contentRule);
assert.match(actionsRule, /display:\s*inline-flex/);
assert.doesNotMatch(styles, /pointer-events:\s*none|opacity:\s*0(?:;|\s)/);
assert.doesNotMatch(actionsRule, /pointer-events:\s*none|opacity:\s*0(?:;|\s)/);
assert.match(contentRule, /color:\s*var\(--openbitfun-color-content-primary\)/);
assert.match(styles, /@media \(hover: hover\) and \(pointer: fine\)/);
assert.match(styles, /\.item:focus-within\s*\{[^}]*background:/s);
Expand Down Expand Up @@ -249,7 +249,7 @@ test("ChatComposer queue never changes the input surface geometry", async () =>
assert.match(bodyRule, /gap:\s*var\(--openbitfun-space-2\)/);
assert.ok(queueRule);
assert.match(queueRule, /display:\s*contents/);
assert.doesNotMatch(styles, /\.body:has\(/);
assert.match(styles, /\.body:has\([^}]*chat-composer-queue[^}]*gap:\s*0/);
assert.doesNotMatch(styles, /\.queue:empty/);
});

Expand Down
9 changes: 9 additions & 0 deletions src/apps/cli/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,12 @@ Native provider and OS fixture checks belong to
[`services/computer-use`](../../crates/services/computer-use/AGENTS.md). CLI owns
the main-thread run-loop adapter and provider injection, including Shared TUI's
executing host. Dispatch, ACP and the stdio server do not infer a GUI provider.

For `/queue` keyboard mutations, legacy capability gates and compact rendering:

```bash
cargo test --locked -p openbitfun-cli --bin openbitfun ui::message_queue::tests
```

The selector uses the typed runtime port through `CliAgentRuntimeClient`.
Shared TUI reports unsupported until its IPC contract negotiates queue support.
13 changes: 13 additions & 0 deletions src/apps/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ equivalent exists:
| --- | --- |
| `/sessions` | Browse and restore sessions. |
| `/new` or `/clear` | Start a new session. |
| `/queue` | Manage the current session’s pending messages on the embedded runtime. |
| `/timeline` | Navigate persisted user messages without changing the session. |
| `/fork` | Fork the full session or fork immediately before a selected prompt. |
| `/goal <objective>` | Start a persistent goal through the shared runtime; while working, steer the active turn toward it. |
Expand All @@ -117,6 +118,18 @@ selected child Session's active execution subtree.
configure a command that waits until the file is closed; missing commands,
non-zero exits, and empty editor output leave the current draft unchanged.

### Pending messages

`/queue` displays the execution host's pending messages. Use Up/Down to select,
Shift+Up/Down to reorder, Enter to send now, Delete to remove, and `r` to refresh.
The visible list refreshes every two seconds and changes only after the host confirms the operation. Failed requests
retain the visible list and require a refresh before another mutation. Sending
now hands off after the current atomic action; removing a pending message does
not cancel the active turn.

Shared TUI currently reports queue management as unsupported. Queue controls do
not change normal running-turn input or Detached Dispatch behavior.

### Long-running goals

A prompt beginning with `/goal <objective>` activates the goal on the executing
Expand Down
Loading
Loading