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.

fix(agents): hide internal context in prompt bubbles (#8994)

Wolf Mermelstein697430b51cee
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
index e2ae08dd16..ad915dd3ae 100644
--- a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
+++ b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
@@ -729,6 +729,24 @@ describe('Message thought shimmer', () => {
});
});
+describe('Message prompt context', () => {
+ it.each([true, false])(
+ 'hides internal context when pending is %s',
+ (pending) => {
+ const raw =
+ '<m-agent-context>{"version":1,"text":"Private instructions"}</m-agent-context>\n\nOnly user text.';
+ const prompt: FoldedMessage = {
+ ...message([text(raw)]),
+ author: { kind: 'user', userId: null },
+ pending,
+ };
+ const view = render(() => <Message message={prompt} inFlight={false} />);
+ expect(view.getByTestId('bubble').textContent).toBe('Only user text.');
+ expect(prompt.parts).toEqual([text(raw)]);
+ }
+ );
+});
+
describe('Message prompt attribution', () => {
const prompt = (userId: string | null): FoldedMessage => ({
...message([text('Do the thing.')]),
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.tsx b/apps/web/src/features/block-agent/component/AgentMessage.tsx
index adef565c8b..9c207ed651 100644
--- a/apps/web/src/features/block-agent/component/AgentMessage.tsx
+++ b/apps/web/src/features/block-agent/component/AgentMessage.tsx
@@ -13,6 +13,7 @@ import { useUserId } from '@core/context/user';
import { idToDisplayName } from '@core/user/util';
import { messageSendMotion } from '@core/util/message-send-motion';
import { openExternalUrl } from '@core/util/url';
+import { stripAgentContext } from '@macro-inc/lexical-core/utils/parsers';
import type {
FoldedMessage,
MessagePart,
@@ -79,7 +80,11 @@ function AgentMessagePart(props: {
<Match when={props.part.kind === 'text' && props.part}>
{(part) => (
<TextPart
- text={part().text}
+ text={
+ props.message.author.kind === 'user'
+ ? stripAgentContext(part().text)
+ : part().text
+ }
inFlight={props.inFlight}
hideIncompleteXml={props.message.author.kind === 'agent'}
observeRender={
diff --git a/apps/web/src/features/block-agent/debug/Gallery.tsx b/apps/web/src/features/block-agent/debug/Gallery.tsx
index d4dc9c5095..ed50895792 100644
--- a/apps/web/src/features/block-agent/debug/Gallery.tsx
+++ b/apps/web/src/features/block-agent/debug/Gallery.tsx
@@ -205,7 +205,8 @@ function QueuedInFlightDemo() {
{
actionId: 'older',
kind: 'prompt',
- prompt: 'Summarize the queue design',
+ prompt:
+ '<m-agent-context>{"version":1,"text":"Private instructions"}</m-agent-context>\n\nSummarize the queue design',
},
{
actionId: 'newer',
@@ -224,7 +225,10 @@ function QueuedInFlightDemo() {
);
return (
- <div class="flex max-w-xl flex-col gap-2">
+ <div
+ class="flex max-w-xl flex-col gap-2"
+ data-testid="queued-context-proof"
+ >
<p class="text-xs text-ink-muted">{note()}</p>
<QueuedPrompts
items={items()}
@@ -906,9 +910,12 @@ function PromptAuthorDemo() {
parts: [{ kind: 'text', text }],
});
return (
- <div class="flex flex-col gap-3">
+ <div class="flex flex-col gap-3" data-testid="prompt-context-proof">
<Message
- message={prompt(userId() ?? null, 'Tighten up the fold, please.')}
+ message={prompt(
+ userId() ?? null,
+ '<m-agent-context>{"version":1,"text":"Private instructions"}</m-agent-context>\n\nTighten up the fold, please.'
+ )}
inFlight={false}
/>
<Message
diff --git a/apps/web/src/features/block-agent/ui/QueuedPrompts.test.tsx b/apps/web/src/features/block-agent/ui/QueuedPrompts.test.tsx
index a0eb6395ad..900d40a391 100644
--- a/apps/web/src/features/block-agent/ui/QueuedPrompts.test.tsx
+++ b/apps/web/src/features/block-agent/ui/QueuedPrompts.test.tsx
@@ -276,3 +276,33 @@ describe('queued prompt access', () => {
expect(onSteer).not.toHaveBeenCalled();
});
});
+
+it('hides private context in the queue and preserves it when editing', () => {
+ const prefix =
+ '<m-agent-context>{"version":1,"text":"Private instructions"}</m-agent-context>\n\n';
+ const onEdit = vi.fn();
+ const view = render(() => (
+ <QueuedPrompts
+ items={[
+ {
+ actionId: 'queued-context',
+ kind: 'prompt',
+ prompt: prefix + 'Queued request',
+ },
+ ]}
+ onEdit={onEdit}
+ onRemove={() => {}}
+ />
+ ));
+ expect(view.getByRole('button', { name: 'Queued request' })).toBeTruthy();
+ expect(view.getByRole('textbox', { hidden: true }).textContent).toBe(
+ 'Queued request'
+ );
+ editor.markdown = 'Updated request';
+ editor.change?.('Updated request');
+ fireEvent.focusOut(view.getByRole('textbox', { hidden: true }));
+ expect(onEdit).toHaveBeenCalledWith(
+ 'queued-context',
+ prefix + 'Updated request'
+ );
+});
diff --git a/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx b/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx
index 0e527cbcc0..ad7b617cef 100644
--- a/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx
+++ b/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx
@@ -20,6 +20,7 @@ import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownCon
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
import CaretUpIcon from '@icon/system/regular/caret-up.svg?component-solid';
import XIcon from '@icon/system/regular/x.svg?component-solid';
+import { stripAgentContext } from '@macro-inc/lexical-core/utils/parsers';
import { Button, Surface } from '@ui';
import {
createEffect,
@@ -173,7 +174,8 @@ function QueuedRow(props: QueuedRowProps) {
let focusBody: (() => void) | undefined;
const preview = () =>
props.item.kind === 'prompt'
- ? (draft() ?? props.item.prompt ?? '').trim() || 'Attached files'
+ ? (draft() ?? stripAgentContext(props.item.prompt ?? '')).trim() ||
+ 'Attached files'
: 'Compact the conversation';
const open = () => {
props.onExpandedChange(true);
@@ -306,7 +308,7 @@ function PromptBody(
// The last text this row and the server agree on: what was mounted,
// applied from a server snapshot, or handed to `onEdit`. Both the autosave
// and the anti-clobber check compare against it.
- let synced = props.item.prompt ?? '';
+ let synced = stripAgentContext(props.item.prompt ?? '');
let saveTimer: ReturnType<typeof setTimeout> | undefined;
const flush = () => {
@@ -320,7 +322,10 @@ function PromptBody(
// prompts and "delete the text" has the remove affordance for it.
if (text === synced || text.trim().length === 0) return;
synced = text;
- props.onEdit(text);
+ // Keep the private prefix on the wire when saving the visible text.
+ const raw = props.item.prompt ?? '';
+ const visible = stripAgentContext(raw);
+ props.onEdit(raw.slice(0, raw.length - visible.length) + text);
};
const scheduleSave = (markdown: string) => {
@@ -365,7 +370,7 @@ function PromptBody(
// untouched — never over a focused editor or unsaved local changes, which
// are about to become the server's text anyway.
createEffect(() => {
- const server = props.item.prompt ?? '';
+ const server = stripAgentContext(props.item.prompt ?? '');
if (server === synced) return;
const root = editor.lexical.getRootElement();
const focused = root?.contains(document.activeElement) ?? false;
@@ -381,7 +386,7 @@ function PromptBody(
<div class="text-sm text-ink" onFocusOut={flush}>
<MarkdownShell
config={editor}
- initialValue={props.item.prompt}
+ initialValue={stripAgentContext(props.item.prompt ?? '')}
disabled={props.disabled}
/>
{/* Attached files ride the prompt as-is: an edit rewrites the text and
diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.md
index e10d8644cc..08c58a0924 100644
--- a/docs/agent-guide/ai-chat.md
+++ b/docs/agent-guide/ai-chat.md
@@ -12,6 +12,12 @@ User-sent messages in chat and agent transcripts use an ink-colored bubble with
lighter bubble with the normal text palette. Preview Markdown and controls at
`/app/debug/ui?ui=invert-util` under **User-sent AI message**.
+Prompt bubbles show only user text: the private `<m-agent-context>` prefix
+stays in the agent payload but is stripped before Markdown rendering, for both
+the optimistic echo and stored prompts after reload. Queued previews and editors
+also hide it; editing a queued prompt preserves its private prefix on save.
+Verify with a context-bearing prompt before confirmation and after reload.
+
A prompt shows a quiet line under its bubble (`data-testid="prompt-footer"`):
when it was posted, and, for a prompt delivered from elsewhere (a mention, a
follow-up in a discussion, an assigned task, a handoff, a routine run), where