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): open sidebar PR link as the GitHub entity (#6641)

Wolf Mermelstein516c2db3b1ae
diff --git a/apps/web/src/features/agents-view/components/AgentsSidebar.test.tsx b/apps/web/src/features/agents-view/components/AgentsSidebar.test.tsx
index 22619732d5..581ca6065d 100644
--- a/apps/web/src/features/agents-view/components/AgentsSidebar.test.tsx
+++ b/apps/web/src/features/agents-view/components/AgentsSidebar.test.tsx
@@ -30,6 +30,19 @@ vi.mock('@queries/agents/agents', () => ({
}));
vi.mock('@app/features/block-agent/component/AgentPullRequestChip', () => ({
AgentPullRequestIcon: () => <svg data-pr-icon />,
+ AgentPullRequestLink: (props: { url: string }) => {
+ const number = props.url.match(/\/pull\/(\d+)/)?.[1];
+ return (
+ <a
+ href={props.url}
+ target="_blank"
+ rel="noreferrer"
+ onClick={(event) => event.stopPropagation()}
+ >
+ View PR #{number} in GitHub
+ </a>
+ );
+ },
}));
vi.mock('@entity', () => ({
Entity: { Title: () => 'Recent chat', Timestamp: () => 'now' },
diff --git a/apps/web/src/features/agents-view/views/AgentSessionListItem.tsx b/apps/web/src/features/agents-view/views/AgentSessionListItem.tsx
index 3438b718fc..6ec5231704 100644
--- a/apps/web/src/features/agents-view/views/AgentSessionListItem.tsx
+++ b/apps/web/src/features/agents-view/views/AgentSessionListItem.tsx
@@ -1,5 +1,8 @@
import { ViewSidebar } from '@app/components/view-shell';
-import { AgentPullRequestIcon } from '@app/features/block-agent/component/AgentPullRequestChip';
+import {
+ AgentPullRequestIcon,
+ AgentPullRequestLink,
+} from '@app/features/block-agent/component/AgentPullRequestChip';
import { parseGithubPrUrl, prHtmlUrl } from '@app/features/block-pr/util/prKey';
import type { AgentSessionEntity } from '@entity';
import ChatIcon from '@phosphor/chat-circle.svg';
@@ -108,17 +111,13 @@ function SessionListItem(props: Props) {
/>
</Show>
</span>
- <Show when={pullRequest()}>
- {(pr) => (
- <a
- href={prHtmlUrl(pr())}
- target="_blank"
- rel="noreferrer"
- class="pointer-events-auto block truncate text-xs leading-4 text-ink-extra-muted hover:text-ink hover:underline focus-visible:outline-2 focus-visible:outline-accent"
- onClick={(event) => event.stopPropagation()}
- >
- View PR #{pr().number} in GitHub
- </a>
+ <Show when={pullRequestUrl()}>
+ {(url) => (
+ <ErrorBoundary fallback={null}>
+ <Suspense>
+ <AgentPullRequestLink url={url()} />
+ </Suspense>
+ </ErrorBoundary>
)}
</Show>
</span>
diff --git a/apps/web/src/features/block-agent/component/AgentPullRequestChip.test.tsx b/apps/web/src/features/block-agent/component/AgentPullRequestChip.test.tsx
index c566fb644c..add69b2464 100644
--- a/apps/web/src/features/block-agent/component/AgentPullRequestChip.test.tsx
+++ b/apps/web/src/features/block-agent/component/AgentPullRequestChip.test.tsx
@@ -14,7 +14,10 @@ import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
import { err } from 'neverthrow';
import { Suspense } from 'solid-js';
import { afterEach, expect, it, vi } from 'vitest';
-import { AgentPullRequestChip } from './AgentPullRequestChip';
+import {
+ AgentPullRequestChip,
+ AgentPullRequestLink,
+} from './AgentPullRequestChip';
const { openWithSplit } = vi.hoisted(() => {
class FakeWebSocket {
@@ -159,3 +162,39 @@ it('opens the PR entity once synced and follows later status changes', async ()
rendered.unmount();
client.clear();
});
+
+it('opens the sidebar PR as the synced entity instead of GitHub', async () => {
+ vi.useFakeTimers();
+ const lookup = vi.mocked(storageServiceClient.getForeignEntityBySource);
+ type Lookup = ReturnType<
+ typeof storageServiceClient.getForeignEntityBySource
+ >;
+ lookup.mockResolvedValue(
+ err([{ code: 'NOT_FOUND', message: 'Not synced' }]) as Awaited<Lookup>
+ );
+ const client = queryClient;
+ const rendered = render(() => (
+ <QueryClientProvider client={client}>
+ <AgentPullRequestLink url={url} />
+ </QueryClientProvider>
+ ));
+ await vi.advanceTimersByTimeAsync(1);
+ const fallback = screen.getByRole('link', {
+ name: 'View PR #6303 in GitHub',
+ });
+ expect(fallback.getAttribute('href')).toBe(url);
+ expect(fallback.getAttribute('target')).toBe('_blank');
+ await handlePullRequestUpdated(entity('open'));
+ await vi.advanceTimersByTimeAsync(1);
+ const control = screen.getByRole('button', {
+ name: 'View PR #6303 in GitHub',
+ });
+ expect(screen.queryByRole('link')).toBeNull();
+ fireEvent.click(control);
+ expect(openWithSplit).toHaveBeenCalledWith(
+ { type: 'pr', id: entity('open').id },
+ { preferNewSplit: true }
+ );
+ rendered.unmount();
+ client.clear();
+});
diff --git a/apps/web/src/features/block-agent/component/AgentPullRequestChip.tsx b/apps/web/src/features/block-agent/component/AgentPullRequestChip.tsx
index 258954d1da..2592dc74e9 100644
--- a/apps/web/src/features/block-agent/component/AgentPullRequestChip.tsx
+++ b/apps/web/src/features/block-agent/component/AgentPullRequestChip.tsx
@@ -129,14 +129,9 @@ function EntityChip(props: {
const { openWithSplit } = useSplitLayout();
const status = () => pullRequestStatus(props.entity);
const title = () => pullRequestTitle(props.entity);
- const open = (event: MouseEvent | KeyboardEvent) => {
- event.stopPropagation();
- openWithSplit(
- { type: 'pr', id: props.entity.id },
- { preferNewSplit: openInNewSplitForMention(event.shiftKey, true) }
- );
- };
- const navHandlers = useSplitNavigationHandler<HTMLButtonElement>(open);
+ const navHandlers = useSplitNavigationHandler<HTMLButtonElement>((event) =>
+ openPullRequestEntity(openWithSplit, props.entity.id, event)
+ );
return (
<HoverCard
@@ -176,6 +171,44 @@ function useLinkedPullRequest(url: Accessor<string>) {
return { reference, entity };
}
+function openPullRequestEntity(
+ openWithSplit: ReturnType<typeof useSplitLayout>['openWithSplit'],
+ entityId: string,
+ event: MouseEvent | KeyboardEvent
+) {
+ event.stopPropagation();
+ openWithSplit(
+ { type: 'pr', id: entityId },
+ { preferNewSplit: openInNewSplitForMention(event.shiftKey, true) }
+ );
+}
+
+function viewPullRequestLabel(number?: number): string {
+ return number != null ? `View PR #${number} in GitHub` : 'View PR in GitHub';
+}
+
+function EntityTextLink(props: {
+ entity: ForeignEntity;
+ number?: number;
+}): JSX.Element {
+ const { openWithSplit } = useSplitLayout();
+ const navHandlers = useSplitNavigationHandler<HTMLButtonElement>((event) =>
+ openPullRequestEntity(openWithSplit, props.entity.id, event)
+ );
+
+ return (
+ <button
+ type="button"
+ class="pointer-events-auto relative block truncate text-xs leading-4 text-ink-extra-muted hover:text-ink hover:underline focus-visible:outline-2 focus-visible:outline-accent"
+ data-agent-pull-request={props.entity.id}
+ data-pr-entity-link={props.entity.id}
+ {...navHandlers}
+ >
+ {viewPullRequestLabel(props.number)}
+ </button>
+ );
+}
+
/** Leading list icon, with the same PR status as the chip. */
export function AgentPullRequestIcon(props: { url: string }): JSX.Element {
const { entity } = useLinkedPullRequest(() => props.url);
@@ -187,6 +220,36 @@ export function AgentPullRequestIcon(props: { url: string }): JSX.Element {
);
}
+/**
+ * Sidebar / Home row control for the session's linked PR. Same destination
+ * as the header chip: the synced GitHub foreign entity, or GitHub until then.
+ */
+export function AgentPullRequestLink(props: { url: string }): JSX.Element {
+ const { reference, entity } = useLinkedPullRequest(() => props.url);
+
+ return (
+ <Show
+ when={entity()}
+ fallback={
+ <a
+ href={props.url}
+ target="_blank"
+ rel="noreferrer"
+ class="pointer-events-auto block truncate text-xs leading-4 text-ink-extra-muted hover:text-ink hover:underline focus-visible:outline-2 focus-visible:outline-accent"
+ data-agent-pull-request={props.url}
+ onClick={(event) => event.stopPropagation()}
+ >
+ {viewPullRequestLabel(reference()?.number)}
+ </a>
+ }
+ >
+ {(synced) => (
+ <EntityTextLink entity={synced()} number={reference()?.number} />
+ )}
+ </Show>
+ );
+}
+
export function AgentPullRequestChip(props: { url: string }): JSX.Element {
const { reference, entity } = useLinkedPullRequest(() => props.url);
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index 4db8dd07e9..67509e4401 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -16,8 +16,10 @@
Chat rows use a chat icon; coding rows use `</>` (the PR status icon when a
pull request is linked). Home and the Agents sidebar share these agent rows.
Rows have no agent or runtime-status subtext. Sessions with a linked PR show
- **View PR #<number> in GitHub** beneath the title; clicking it opens GitHub in
- a new tab without opening the session. The leading icon reflects the PR status. Changing the composer mode does not filter the sidebar.
+ **View PR #<number> in GitHub** beneath the title; clicking it opens the synced
+ GitHub PR entity in a split (the same destination as the session header chip
+ and Magic Chip). Until GitHub has synced the entity it opens GitHub in a new
+ tab. Either click leaves the session unopened. The leading icon reflects the PR status. Changing the composer mode does not filter the sidebar.
Selecting a row opens its own mode; Shift-click opens it in a new split.
- The starting page has a compact composer that starts at one line and grows
with longer prompts or Shift+Enter. Lists, quotes, headings, and other