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(agent): keep magic chip replies inside the channel column (#6231)

Wolf Mermelstein197e81598735
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
index 91066ce46e..edddbbbbe9 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
@@ -546,7 +546,7 @@ const MagicChip: TypedRenderableEntity<MagicChipNode> = {
guard: (node: LexicalNode): node is MagicChipNode =>
node.__type === 'magic-chip',
render: (props) => (
- <div class="max-w-full">
+ <div class="min-w-0 max-w-full overflow-x-hidden">
<MagicChipDecorator
{...props.node.exportComponentProps()}
key={props.node.getKey()}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView.test.tsx
new file mode 100644
index 0000000000..fa809667bf
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView.test.tsx
@@ -0,0 +1,70 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { render, screen } from '@solidjs/testing-library';
+import { describe, expect, it, vi } from 'vitest';
+
+vi.mock(
+ '@core/component/LexicalMarkdown/component/core/StaticMarkdown',
+ () => ({
+ StaticMarkdownContext: (props: { children: unknown }) => props.children,
+ StaticMarkdown: (props: { markdown: string }) => <p>{props.markdown}</p>,
+ })
+);
+
+import { MagicChipView } from './MagicChipView';
+
+const LONG_PATH =
+ '/home/ubuntu/.cursor/projects/workspace/terminals/261831.txt'.repeat(8);
+
+describe('MagicChipView', () => {
+ it('keeps a streaming thought inside the message column', () => {
+ const { container } = render(() => (
+ <div style={{ width: '320px' }}>
+ <MagicChipView
+ agentSessionId="session-1"
+ presentation={{
+ kind: 'working',
+ activity: {
+ label: 'Thinking',
+ detail: LONG_PATH,
+ busy: true,
+ },
+ }}
+ />
+ </div>
+ ));
+
+ const chip = container.querySelector('[data-magic-chip="session-1"]');
+ expect(chip?.className).toContain('min-w-0');
+ expect(chip?.className).toContain('max-w-full');
+ expect(chip?.className).toContain('overflow-x-hidden');
+ expect(screen.getByText('Thinking')).toBeTruthy();
+ expect(screen.getByText(LONG_PATH).className).toContain('truncate');
+ });
+
+ it('keeps a streaming answer inside the message column', () => {
+ const { container } = render(() => (
+ <div style={{ width: '320px' }}>
+ <MagicChipView
+ agentSessionId="session-2"
+ presentation={{
+ kind: 'answering',
+ markdown: `Inspecting \`${LONG_PATH}\``,
+ activity: {
+ label: 'Reading files',
+ detail: LONG_PATH,
+ busy: true,
+ },
+ }}
+ />
+ </div>
+ ));
+
+ const chip = container.querySelector('[data-magic-chip="session-2"]');
+ expect(chip?.className).toContain('grid-cols-[minmax(0,1fr)]');
+ expect(chip?.className).toContain('overflow-x-hidden');
+ expect(screen.getByText('Reading files')).toBeTruthy();
+ });
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView.tsx
index 8da1a288c7..fc6f36612e 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView.tsx
@@ -6,6 +6,15 @@ import { channelTheme } from '@core/component/LexicalMarkdown/theme';
import { type Component, Match, Show, Switch } from 'solid-js';
import type { MagicChipActivity, MagicChipPresentation } from './presentation';
+/**
+ * Keep the chip inside the message column. A default grid track sizes to
+ * min-content, so a streaming thought, path, or unbreakable token can grow
+ * the chip past the chat edge — the reply is still in the DOM, just off
+ * screen, which looks like the agent never answered.
+ */
+const CHIP_BOUNDS = 'w-full min-w-0 max-w-full overflow-x-hidden';
+const CHIP_STACK = `grid ${CHIP_BOUNDS} grid-cols-[minmax(0,1fr)] gap-1`;
+
function working(presentation: MagicChipPresentation) {
return presentation.kind === 'working' ? presentation : undefined;
}
@@ -26,7 +35,7 @@ const ActivityLine: Component<{
}> = (props) => (
<button
type="button"
- class="flex h-6 w-full min-w-0 items-center gap-2 text-left"
+ class={`flex h-6 ${CHIP_BOUNDS} items-center gap-2 text-left`}
data-magic-chip={props.agentSessionId}
data-message-reply-preview={`${props.activity.label}${
props.activity.detail ? ` ${props.activity.detail}` : ''
@@ -47,7 +56,7 @@ const ActivityLine: Component<{
</span>
<Show when={props.activity.detail}>
{(detail) => (
- <span class="min-w-0 truncate text-xs text-ink-extra-muted">
+ <span class="min-w-0 flex-1 truncate text-xs text-ink-extra-muted">
{detail()}
</span>
)}
@@ -58,7 +67,7 @@ const ActivityLine: Component<{
/** The response, quoted as if the agent had answered inline. */
const AnswerBody: Component<{ markdown: string }> = (props) => (
<div
- class="w-full border-l-2 border-accent pl-3 text-left text-sm leading-6"
+ class={`${CHIP_BOUNDS} wrap-break-word border-l-2 border-accent pl-3 text-left text-sm leading-6`}
data-message-reply-preview
>
<StaticMarkdownContext theme={channelTheme}>
@@ -80,12 +89,9 @@ const StreamingAnswer: Component<{
activity: MagicChipActivity;
onOpen?: () => void;
}> = (props) => (
- <div
- class="grid w-full min-w-0 justify-items-start gap-1"
- data-magic-chip={props.agentSessionId}
- >
+ <div class={CHIP_STACK} data-magic-chip={props.agentSessionId}>
<AnswerBody markdown={props.markdown} />
- <div class="w-full pl-3">
+ <div class={`${CHIP_BOUNDS} pl-3`}>
<ActivityLine
agentSessionId={props.agentSessionId}
activity={props.activity}
@@ -101,10 +107,7 @@ const SettledAnswer: Component<{
markdown: string;
onOpen?: () => void;
}> = (props) => (
- <div
- class="grid w-full min-w-0 justify-items-start gap-1"
- data-magic-chip={props.agentSessionId}
- >
+ <div class={CHIP_STACK} data-magic-chip={props.agentSessionId}>
<AnswerBody markdown={props.markdown} />
<button
type="button"
diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.md
index 47f1c7ef8d..7d8e39e024 100644
--- a/docs/AGENT_GUIDE/channels.md
+++ b/docs/AGENT_GUIDE/channels.md
@@ -45,6 +45,9 @@ an agent session; follow-up
`@` mentions of that bot in the same thread route to it.
Agent replies may contain mention chips (`<m-document-mention>`) that render like any
other channel mention.
+The Magic Chip that streams the agent's reply stays inside the message column: long
+thoughts, file paths, and unbreakable tokens wrap or truncate instead of expanding the
+thread past the chat's right edge.
## Message scrolling and navigation