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.

feat(agents): shift-click prompt origin to open in a new split (#9027)

gbirmanf4df8b7b8320
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 757ca43159..3024f461da 100644
--- a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
+++ b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx
@@ -25,8 +25,8 @@ vi.mock('../context/AgentSessionContext', () => ({
// is a marker. The per-part components have their own tests.
const openedOrigins = vi.hoisted(() => [] as unknown[]);
vi.mock('../open-prompt-origin', () => ({
- useOpenPromptOrigin: () => (destination: unknown) => {
- openedOrigins.push(destination);
+ useOpenPromptOrigin: () => (destination: unknown, options: unknown) => {
+ openedOrigins.push({ destination, options });
},
}));
@@ -822,7 +822,19 @@ describe('Message prompt footer', () => {
name: 'via task Fix calendar popover scroll from Julia',
});
line.click();
- expect(openedOrigins).toEqual([{ kind: 'task', taskId: 'task-1' }]);
+ line.dispatchEvent(
+ new MouseEvent('click', { bubbles: true, shiftKey: true })
+ );
+ expect(openedOrigins).toEqual([
+ {
+ destination: { kind: 'task', taskId: 'task-1' },
+ options: { newSplit: false },
+ },
+ {
+ destination: { kind: 'task', taskId: 'task-1' },
+ options: { newSplit: true },
+ },
+ ]);
});
it('shows only when a prompt typed in the session was posted', () => {
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.tsx b/apps/web/src/features/block-agent/component/AgentMessage.tsx
index 91a07faa5b..ce2c747fbc 100644
--- a/apps/web/src/features/block-agent/component/AgentMessage.tsx
+++ b/apps/web/src/features/block-agent/component/AgentMessage.tsx
@@ -316,9 +316,9 @@ function UserMessage(props: { message: FoldedMessage }) {
postedAt={props.message.postedAt ?? undefined}
onOpen={
origin()?.destination
- ? () => {
+ ? (options) => {
const destination = origin()?.destination;
- if (destination) openOrigin(destination);
+ if (destination) openOrigin(destination, options);
}
: undefined
}
diff --git a/apps/web/src/features/block-agent/component/PromptFooter.tsx b/apps/web/src/features/block-agent/component/PromptFooter.tsx
index 144073abc2..080436473b 100644
--- a/apps/web/src/features/block-agent/component/PromptFooter.tsx
+++ b/apps/web/src/features/block-agent/component/PromptFooter.tsx
@@ -1,18 +1,26 @@
import { formatDate } from '@core/util/date';
+import { openInNewSplitForMention } from '@core/util/openInNewSplit';
+import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
import { Show } from 'solid-js';
import type { PromptOrigin } from '../state/prompt-origin';
/**
* A quiet line under a prompt: where it came from, when the harness delivered
* it from elsewhere, and when it was posted - `via @mention in #eng · 2:02 PM`,
- * or just `2:02 PM`. Clicking the origin goes to that place.
+ * or just `2:02 PM`. Clicking the origin goes to that place; Shift-click opens
+ * it in a new split.
*/
export function PromptFooter(props: {
origin: PromptOrigin | undefined;
/** RFC 3339; absent until the log confirms the prompt. */
postedAt: string | undefined;
- onOpen?: () => void;
+ onOpen?: (options: { newSplit: boolean }) => void;
}) {
+ const navHandlers = useSplitNavigationHandler<HTMLButtonElement>((event) =>
+ props.onOpen?.({
+ newSplit: openInNewSplitForMention(event.shiftKey, false),
+ })
+ );
const originText = (origin: PromptOrigin) => (
<>
{origin.lead}
@@ -45,16 +53,14 @@ export function PromptFooter(props: {
</span>
}
>
- {(open) => (
- <button
- type="button"
- title={label(origin())}
- onClick={() => open()()}
- class="min-w-0 truncate rounded px-1 text-left underline decoration-dotted underline-offset-2 not-touch:hover:bg-hover not-touch:hover:text-ink"
- >
- {originText(origin())}
- </button>
- )}
+ <button
+ type="button"
+ title={label(origin())}
+ {...navHandlers}
+ class="min-w-0 truncate rounded px-1 text-left underline decoration-dotted underline-offset-2 not-touch:hover:bg-hover not-touch:hover:text-ink"
+ >
+ {originText(origin())}
+ </button>
</Show>
)}
</Show>
diff --git a/apps/web/src/features/block-agent/open-prompt-origin.ts b/apps/web/src/features/block-agent/open-prompt-origin.ts
index 87caa7327c..c637bf9a55 100644
--- a/apps/web/src/features/block-agent/open-prompt-origin.ts
+++ b/apps/web/src/features/block-agent/open-prompt-origin.ts
@@ -20,14 +20,16 @@ import type { OriginDestination } from './state/prompt-origin';
* feature layers. Called during setup: it reads the split layout from context.
*/
export function useOpenPromptOrigin(): (
- destination: OriginDestination
+ destination: OriginDestination,
+ options?: { newSplit?: boolean }
) => void {
const layout = useSplitLayout();
/** A document's block depends on its file type, which the context omits. */
const openDocumentComment = async (
documentId: string,
- commentId: string | undefined
+ commentId: string | undefined,
+ newSplit: boolean | undefined
) => {
const preview = await ResultAsync.fromPromise(
getItemPreview({ id: documentId, type: 'document' }),
@@ -48,11 +50,13 @@ export function useOpenPromptOrigin(): (
openDocument(
location.blockName,
documentId,
- commentId ? location.params : undefined
+ commentId ? location.params : undefined,
+ newSplit
);
};
- return (destination) =>
+ return (destination, options) => {
+ const newSplit = options?.newSplit;
match(destination)
.with({ kind: 'channel_message' }, (target) => {
const orchestrator = globalSplitManager()?.getOrchestrator();
@@ -62,56 +66,73 @@ export function useOpenPromptOrigin(): (
orchestrator,
target.channelId,
target.messageId,
- target.threadId
+ target.threadId,
+ { preferNewSplit: newSplit }
),
'agent-prompt-origin'
);
return;
}
- layout.openWithSplit({ type: 'channel', id: target.channelId });
+ layout.openWithSplit(
+ { type: 'channel', id: target.channelId },
+ { preferNewSplit: newSplit }
+ );
})
.with({ kind: 'document' }, ({ documentId, commentId }) => {
fireAndForget(
- openDocumentComment(documentId, commentId),
+ openDocumentComment(documentId, commentId, newSplit),
'agent-prompt-origin'
);
})
.with({ kind: 'project' }, ({ projectId, commentId }) =>
- openProject(layout, projectId, { discussionId: commentId })
+ openProject(layout, projectId, { discussionId: commentId, newSplit })
)
.with({ kind: 'crm_company' }, ({ companyId, commentId }) => {
openDocument(
'company',
companyId,
- commentId ? { [COMMENT_LINK_PARAM]: commentId } : undefined
+ commentId ? { [COMMENT_LINK_PARAM]: commentId } : undefined,
+ newSplit
);
})
.with({ kind: 'crm_contact' }, ({ contactId, commentId }) => {
openDocument(
'contact',
contactId,
- commentId ? { [COMMENT_LINK_PARAM]: commentId } : undefined
+ commentId ? { [COMMENT_LINK_PARAM]: commentId } : undefined,
+ newSplit
);
})
.with({ kind: 'call' }, ({ callId }) => {
const content = callsHostedContent({ type: 'call', id: callId });
- if (content) layout.openWithSplit(content);
+ if (content)
+ layout.openWithSplit(content, { preferNewSplit: newSplit });
})
.with({ kind: 'task' }, ({ taskId }) => {
- layout.openWithSplit({ type: 'task', id: taskId });
+ layout.openWithSplit(
+ { type: 'task', id: taskId },
+ { preferNewSplit: newSplit }
+ );
})
.with({ kind: 'routine' }, ({ routineId }) => {
- layout.openWithSplit(routineContent(routineId), { activate: true });
+ layout.openWithSplit(routineContent(routineId), {
+ activate: true,
+ preferNewSplit: newSplit,
+ });
})
.with({ kind: 'email_thread' }, ({ threadId }) => {
- layout.openWithSplit({ type: 'email', id: threadId });
+ layout.openWithSplit(
+ { type: 'email', id: threadId },
+ { preferNewSplit: newSplit }
+ );
})
.with({ kind: 'agent_session' }, ({ sessionId }) => {
layout.openWithSplit(
{ type: 'agent', id: sessionId },
- { activate: true }
+ { activate: true, preferNewSplit: newSplit }
);
})
.with({ kind: 'external' }, ({ url }) => openExternalUrl(url))
.exhaustive();
+ };
}