Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(agents): agent composer auto focus (#6161)

Wolf Mermelstein9b351d7bc001
diff --git a/apps/web/src/features/block-agent/component/AgentComposer.tsx b/apps/web/src/features/block-agent/component/AgentComposer.tsx
index 990705e129..f63edbcf7e 100644
--- a/apps/web/src/features/block-agent/component/AgentComposer.tsx
+++ b/apps/web/src/features/block-agent/component/AgentComposer.tsx
@@ -16,7 +16,13 @@ import {
QueuedPrompts,
} from '../ui';
-export function AgentComposer() {
+export function AgentComposer(props: {
+ /**
+ * Whether the composer opens focused. The block adapter decides, from the
+ * split layout and j/k navigation — same contract as Chat and Channel.
+ */
+ autofocus?: boolean;
+}) {
const {
composer,
loadFailed,
@@ -49,11 +55,6 @@ export function AgentComposer() {
};
});
- // A session still being created was created by this user, one action ago,
- // and has an empty transcript: the only thing to do with it is type. The
- // wait for the sandbox is exactly when that matters most.
- const autofocus = pending();
-
return (
<>
<Show when={queuedItems().length > 0}>
@@ -74,7 +75,7 @@ export function AgentComposer() {
</Show>
<AgentInput
placeholder="Message the agent, @mention anything"
- autofocus={autofocus}
+ autofocus={props.autofocus}
busy={composer.busy()}
hasQueuedMessages={queuedItems().length > 0}
// Prompts go straight to the service, so sending needs a session to
diff --git a/apps/web/src/features/block-agent/component/Block.tsx b/apps/web/src/features/block-agent/component/Block.tsx
index a1b5c02311..02bbc35946 100644
--- a/apps/web/src/features/block-agent/component/Block.tsx
+++ b/apps/web/src/features/block-agent/component/Block.tsx
@@ -1,6 +1,8 @@
import { FloatRegionOrInline } from '@components/app/mobile/float-regions/FloatRegion';
import { SidePanel } from '@components/app/side-panel';
import { SplitPanelContext } from '@components/app/split-layout/context';
+import { useCanAutofocusSplitContent } from '@components/app/split-layout/layoutUtils';
+import { useNavigatedFromJK } from '@components/app/useNavigatedFromJK';
import { useBlockId } from '@core/block';
import { LoadErrorPanel } from '@core/component/EntityLoadGate';
import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
@@ -25,6 +27,8 @@ import { Transcript } from './Transcript';
function AgentBlockContent() {
const { session, metadata, loadFailed, loadRetryable, pending, retryLoad } =
useAgentSession();
+ const canAutofocusSplitContent = useCanAutofocusSplitContent();
+ const { navigatedFromJK } = useNavigatedFromJK();
// Nothing loaded and no way forward: the load failed outright, or the
// device is offline and the pending load cannot complete until
@@ -67,7 +71,9 @@ function AgentBlockContent() {
contribution — the float host is pointer-transparent. */}
<div class="flex w-full justify-center shrink-0 px-4 pb-4 pointer-events-auto touch:px-(--mobile-chrome-gutter) touch:pb-0">
<div class="macro-message-width mx-auto">
- <AgentComposer />
+ <AgentComposer
+ autofocus={canAutofocusSplitContent && !navigatedFromJK()}
+ />
</div>
</div>
</FloatRegionOrInline>
diff --git a/apps/web/src/features/block-agent/context/create-agent-session-feed.test.ts b/apps/web/src/features/block-agent/context/create-agent-session-feed.test.ts
index f61e9958ca..8ea8761480 100644
--- a/apps/web/src/features/block-agent/context/create-agent-session-feed.test.ts
+++ b/apps/web/src/features/block-agent/context/create-agent-session-feed.test.ts
@@ -11,7 +11,13 @@ import type {
FoldedStreamEvent,
} from '@service-agent-fold/generated/types';
import type { AgentSessionResponse } from '@service-agent-harness/generated/schemas';
-import { createComputed, createMemo, createRoot, mapArray } from 'solid-js';
+import {
+ createComputed,
+ createMemo,
+ createRoot,
+ createSignal,
+ mapArray,
+} from 'solid-js';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const worker = vi.hoisted(() => ({
@@ -480,4 +486,47 @@ describe('createAgentSessionFeed live updates', () => {
});
expect(feed.working()).toBe(false);
});
+
+ it('does not suspend session() while the first fetch runs after a pending open', async () => {
+ let release!: () => void;
+ const gate = new Promise<void>((resolve) => {
+ release = resolve;
+ });
+ worker.getSession = async () => {
+ await gate;
+ return {
+ isErr: () => false,
+ value: {
+ id: 'session',
+ name: 'Agent Session',
+ modifiedAt: '2026-08-24T12:00:00Z',
+ harness: 'claude-code',
+ },
+ };
+ };
+
+ const { createAgentSessionFeed } = await import(
+ './create-agent-session-feed'
+ );
+
+ let dispose!: () => void;
+ let setSessionId!: (id: string | undefined) => void;
+ const feed = createRoot((cleanup) => {
+ dispose = cleanup;
+ const [sessionId, setId] = createSignal<string | undefined>(undefined);
+ setSessionId = setId;
+ return createAgentSessionFeed(sessionId);
+ });
+
+ expect(feed.session()).toBeUndefined();
+ setSessionId('session');
+ // The fetch is in flight. Reading session() must not throw a promise
+ // (the unguarded `resource.latest` path suspends until first resolve).
+ expect(feed.session()).toBeUndefined();
+ release();
+ await flush();
+ await flush();
+ expect(feed.session()?.id).toBe('session');
+ dispose();
+ });
});
diff --git a/apps/web/src/features/block-agent/context/create-agent-session-feed.ts b/apps/web/src/features/block-agent/context/create-agent-session-feed.ts
index ef3257b7d9..e872af1ea7 100644
--- a/apps/web/src/features/block-agent/context/create-agent-session-feed.ts
+++ b/apps/web/src/features/block-agent/context/create-agent-session-feed.ts
@@ -76,6 +76,20 @@ function sameMessage(a: FoldedMessage, b: FoldedMessage): boolean {
export function createAgentSessionFeed(
sessionId: Accessor<string | undefined>
): AgentSessionFeed {
+ // Whether this block went on screen before it had a session to load.
+ //
+ // `resource.latest` falls back to a *suspending* read until the resource has
+ // resolved once, and suspending hands the block's
+ // `<Suspense fallback={<LoadingBlock />}>` a promise: Solid swaps in the
+ // fallback, which detaches the whole block subtree and re-attaches it when
+ // the fetch lands. A cold open has nothing on screen to lose and wants that
+ // skeleton. This block does: it opened on a placeholder minutes before the
+ // create resolved, the user has been typing into its composer the whole
+ // time, and the detach blanks the transcript and drops the caret to
+ // `<body>`. Absent is a state it already renders — that is the whole point
+ // of the placeholder — so report that for the first fetch instead.
+ const openedPending = sessionId() === undefined;
+
const [list, setList] = createStore<FoldedMessage[]>([]);
const [bot, setBot] = createSignal<SessionBot>();
const [metadata, setMetadata] = createSignal<SessionMetadata>();
@@ -212,8 +226,12 @@ export function createAgentSessionFeed(
mutate(session);
};
+ // A first fetch would suspend; see `openedPending`.
+ const session = () =>
+ openedPending && resource.state === 'pending' ? undefined : resource.latest;
+
return {
- session: () => resource.latest,
+ session,
bot,
metadata,
messages,
diff --git a/apps/web/src/features/block-agent/ui/AgentInput.tsx b/apps/web/src/features/block-agent/ui/AgentInput.tsx
index 5df6ddc3c2..546644e631 100644
--- a/apps/web/src/features/block-agent/ui/AgentInput.tsx
+++ b/apps/web/src/features/block-agent/ui/AgentInput.tsx
@@ -18,6 +18,12 @@ import EnterIcon from '@phosphor-icons/core/regular/arrow-bend-down-left.svg?com
import { Button, SendButton, Surface } from '@ui';
import { createSignal, type JSX, onCleanup, onMount, Show } from 'solid-js';
+/**
+ * Id of the agent input's text-area wrapper. Exposed so callers (e.g. the
+ * mobile Create menu) can arm focus on the contenteditable before it mounts.
+ */
+export const AGENT_INPUT_TEXT_AREA_ID = 'agent-input-text-area';
+
/** Quote text into the composer as a referenced paste chip. */
export type QuoteInsert = (text: string) => void;
@@ -174,6 +180,7 @@ export function AgentInput(props: AgentInputProps) {
paragraphs carry my-1.5, so the row's py-1.5 is the whole frame —
the same 44px single-line height as ChatInput. */}
<div
+ id={AGENT_INPUT_TEXT_AREA_ID}
ref={bodyRef}
class="min-w-0 flex-1 pl-1 text-sm text-ink touch:pl-0 touch:text-base"
classList={{
@@ -191,7 +198,7 @@ export function AgentInput(props: AgentInputProps) {
placeholder={
props.placeholder ?? 'Message the agent, @mention anything'
}
- autofocus={props.autofocus}
+ autofocus={!isMobile() && !isTouchDevice() && props.autofocus}
/>
</div>
diff --git a/apps/web/src/features/block-agent/ui/index.ts b/apps/web/src/features/block-agent/ui/index.ts
index e9eb8d4150..bdc2a239a6 100644
--- a/apps/web/src/features/block-agent/ui/index.ts
+++ b/apps/web/src/features/block-agent/ui/index.ts
@@ -8,6 +8,7 @@
export { ActionLine, type ActionLineProps } from './ActionLine';
export {
+ AGENT_INPUT_TEXT_AREA_ID,
AgentInput,
type AgentInputProps,
type QuoteInsert,
diff --git a/apps/web/src/features/command/Launcher.tsx b/apps/web/src/features/command/Launcher.tsx
index 27b2a054d2..c6218bab91 100644
--- a/apps/web/src/features/command/Launcher.tsx
+++ b/apps/web/src/features/command/Launcher.tsx
@@ -1,4 +1,5 @@
import { startPendingSession } from '@app/features/block-agent/context/pending-session';
+import { AGENT_INPUT_TEXT_AREA_ID } from '@app/features/block-agent/ui/AgentInput';
import { openStandaloneReminderComposer } from '@app/features/reminders/reminder-composer';
import { useFeatureFlag } from '@app/lib/analytics/posthog';
import { setAutomationComposerOpen } from '@block-automation/component';
@@ -422,6 +423,16 @@ export function runCreateAction(
case 'agent': {
const { openWithSplit } = useSplitLayout();
setCreateMenuOpen(false, false);
+ // On mobile the agent input doesn't autofocus on mount, so arm focus
+ // within this gesture (iOS only raises the keyboard for a synchronous
+ // focus). The block mounts asynchronously, so this waits for the input.
+ if (isMobile()) {
+ triggerFocusInput(() =>
+ document
+ .getElementById(AGENT_INPUT_TEXT_AREA_ID)
+ ?.querySelector<HTMLElement>('[contenteditable="true"]')
+ );
+ }
openWithSplit(
{ type: 'agent', id: startPendingSession() },
{ referredFrom: 'launcher', preferNewSplit: shouldInsert }
@@ -451,7 +462,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
},
{
// The pre-agent-session chat, kept on `a` for anyone the new agent flag
- // has not reached. Mutually exclusive with the Coding Agent entry below:
+ // has not reached. Mutually exclusive with the Agent entry below:
// both bind `a`, and exactly one is ever enabled.
label: 'Agent',
icon: WideStar,
@@ -488,10 +499,10 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [
},
},
{
- label: 'Coding Agent',
+ label: 'Agent',
icon: Robot,
description: 'Create agent session',
- launcherHint: 'Sandboxed coding session',
+ launcherHint: 'Dedicated Agent Session',
keywords: ['new', 'make', 'add', 'agent', 'code', 'coder', 'session'],
blockName: 'agent',
hotkeyToken: TOKENS.create.agent,
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index ee6311d254..ad319fe6a3 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -11,7 +11,8 @@
Almost every list surface (Home, Agents, Files, Tasks, Customers, Email) has a bottom
composer with placeholder **`Ask AI, @mention anything`**. Click it, `type_text` the message,
press Enter — the app creates a chat and navigates to `/app/chat/<uuid>`. Alternatively
-`Create` → `Coding Agent A`, or keyboard `c` then `a`.
+`Create` → `Agent A`, or keyboard `c` then `a`. That create path focuses the
+agent composer so you can type immediately.
## Start a doc-scoped chat
@@ -48,7 +49,9 @@ transcript at `/app/agent/<uuid>` whose replies also stream back into the thread
## Agent sessions
An agent session is `/app/agent/<uuid>`. The composer placeholder is
-**`Message the agent, @mention anything`**. Type `@` to insert the same mention chips
+**`Message the agent, @mention anything`**. Creating one (`c` then `a`, or
+`Create` → `Agent`) leaves that composer focused — on mobile that is the same
+Create-menu `triggerFocusInput` as chat, so the keyboard opens. Type `@` to insert the same mention chips
used in chat and channels; they serialize as `<m-document-mention>` tags in the prompt
the agent sees. Agent replies that emit those tags render as clickable chips in the
transcript (and in the originating channel thread).
diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.md
index 6610531fd7..79ec68006c 100644
--- a/docs/AGENT_GUIDE/navigation.md
+++ b/docs/AGENT_GUIDE/navigation.md
@@ -53,7 +53,7 @@ changes roll back rather than becoming committed local favorites.
## Create menu
-`Create` button (top-left) opens a menu of: Email E, Automation U, Coding Agent A, Skill K,
+`Create` button (top-left) opens a menu of: Email E, Automation U, Agent A, Skill K,
Document D, Task T, Reminder R, Snippet S, Message M, Channel G, Canvas N, Folder F, Code O.
Document navigates straight into a new doc; Task and Channel open dialogs.