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): hide agent session Changes controls until a pull request is linked (#7074)

Wolf Mermelstein7980ec9a93a5
diff --git a/apps/web/src/features/agent-changes/README.md b/apps/web/src/features/agent-changes/README.md
index 2c0e73cdf0..6c724278bc 100644
--- a/apps/web/src/features/agent-changes/README.md
+++ b/apps/web/src/features/agent-changes/README.md
@@ -10,9 +10,10 @@ and mounts `AgentChangesControllerProvider` around `ChangesPane` or
`pr:<foreign-entity-id>`) to isolate its locally persisted collapse state and notes.
The optional `agent` capability enables inline note creation and sending; omit it
for a read-only PR viewer. The optional `canHaveChanges` accessor hides every
-control and the pane while false; the session host reports it from the harness so
-a chat-only (in-memory) session shows no GitHub chrome. Clipboard, external
-navigation, and notifications are host callbacks.
+control and the pane while false; the session host reports it from the harness and
+the linked pull request, so a chat-only (in-memory) session or a coding session
+without a pull request yet shows no GitHub chrome. Clipboard, external navigation,
+and notifications are host callbacks.
The source owns fetching, cache identity, and conversion into the feature's core
changeset types. A PR entity adapter should resolve its GitHub owner/repository/PR
diff --git a/apps/web/src/features/agent-changes/agent-changes.test.tsx b/apps/web/src/features/agent-changes/agent-changes.test.tsx
new file mode 100644
index 0000000000..54e4b2caa7
--- /dev/null
+++ b/apps/web/src/features/agent-changes/agent-changes.test.tsx
@@ -0,0 +1,108 @@
+import type { AgentSessionResponse } from '@service-agent-harness/generated/schemas';
+import { render, screen } from '@solidjs/testing-library';
+import { createSignal } from 'solid-js';
+import { describe, expect, it, vi } from 'vitest';
+import {
+ AgentChangesProvider,
+ ChangesHandoff,
+ ChangesToggle,
+} from './agent-changes';
+import {
+ createMockAgentChangesContext,
+ mockChangeset,
+} from './tests/mock-context';
+
+const [session, setSession] = createSignal<AgentSessionResponse>();
+/** Every session id the changes source was asked to read, in order. */
+const sourceSessionIds: Array<string | undefined> = [];
+
+vi.mock('../block-agent/context/AgentSessionContext', () => ({
+ useAgentSession: () => ({
+ userId: () => 'user-1',
+ sessionId: () => 'session-1',
+ session,
+ loadFailed: () => false,
+ issue: async () => undefined,
+ }),
+}));
+
+vi.mock('./queries/session-changes', () => ({
+ createSessionChangesSource: (sessionId: () => string | undefined) => {
+ const context = createMockAgentChangesContext({
+ summary: { capturing: false, changeset: mockChangeset() },
+ });
+ return {
+ ...context.source,
+ summary: () => {
+ sourceSessionIds.push(sessionId());
+ return sessionId() ? context.source.summary() : undefined;
+ },
+ };
+ },
+}));
+
+vi.mock('./queries/pull-request-stats', () => ({
+ createPullRequestStatsSource: () => () => undefined,
+}));
+
+vi.mock('./url-diff-state', () => ({
+ createUrlDiffState: () => {
+ const [layout, setLayout] = createSignal('agent-only');
+ const [diffStyle, setDiffStyle] = createSignal('unified');
+ return { layout, setLayout, diffStyle, setDiffStyle };
+ },
+}));
+
+vi.mock('@core/component/Toast/Toast', () => ({
+ toast: { success() {}, failure() {} },
+}));
+vi.mock('@core/util/url', () => ({ openExternalUrl() {} }));
+
+function sessionWith(fields: {
+ harness: string;
+ pullRequestUrl: string | null;
+}): AgentSessionResponse {
+ return fields as unknown as AgentSessionResponse;
+}
+
+describe('AgentChangesProvider', () => {
+ it('hides the Changes controls until the coding session links a pull request', () => {
+ setSession(sessionWith({ harness: 'cursor', pullRequestUrl: null }));
+ sourceSessionIds.length = 0;
+ render(() => (
+ <AgentChangesProvider>
+ <ChangesToggle />
+ <ChangesHandoff />
+ </AgentChangesProvider>
+ ));
+ expect(screen.queryByRole('button', { name: /Changes/ })).toBeNull();
+ expect(screen.queryByText('Changes ready to review')).toBeNull();
+ // Nothing is fetched while there is no pull request to capture from.
+ expect(sourceSessionIds.every((id) => id === undefined)).toBe(true);
+
+ setSession(
+ sessionWith({
+ harness: 'cursor',
+ pullRequestUrl: 'https://github.com/macro-inc/macro/pull/42',
+ })
+ );
+ expect(screen.getByRole('button', { name: /Changes/ })).toBeTruthy();
+ expect(screen.getByText('Changes ready to review')).toBeTruthy();
+ expect(sourceSessionIds.at(-1)).toBe('session-1');
+ });
+
+ it('keeps the controls hidden for a chat-only harness even with a pull request', () => {
+ setSession(
+ sessionWith({
+ harness: 'in-memory',
+ pullRequestUrl: 'https://github.com/macro-inc/macro/pull/42',
+ })
+ );
+ render(() => (
+ <AgentChangesProvider>
+ <ChangesToggle />
+ </AgentChangesProvider>
+ ));
+ expect(screen.queryByRole('button', { name: /Changes/ })).toBeNull();
+ });
+});
diff --git a/apps/web/src/features/agent-changes/agent-changes.tsx b/apps/web/src/features/agent-changes/agent-changes.tsx
index efa8641532..5a57376961 100644
--- a/apps/web/src/features/agent-changes/agent-changes.tsx
+++ b/apps/web/src/features/agent-changes/agent-changes.tsx
@@ -38,11 +38,15 @@ async function copyText(text: string): Promise<boolean> {
export function AgentChangesProvider(props: ParentProps) {
const session = useAgentSession();
+ const pullRequestUrl = () => session.session()?.pullRequestUrl ?? undefined;
// Only a coding harness has a repository to diff; a chat-only session
// (in-memory) never fetches changes and shows none of the GitHub chrome.
const coding = () => isCoderHarness(session.session()?.harness);
+ // The harness captures a session's changeset from its linked pull
+ // request, so until one is linked there is nothing to fetch or show.
+ const canHaveChanges = () => coding() && pullRequestUrl() !== undefined;
const source = createSessionChangesSource(() =>
- coding() ? session.sessionId() : undefined
+ canHaveChanges() ? session.sessionId() : undefined
);
const sendPrompt = async (markdown: string) => {
try {
@@ -55,10 +59,7 @@ export function AgentChangesProvider(props: ParentProps) {
}
};
const pullRequestChangeCounts = createPullRequestStatsSource(
- () =>
- coding() && session.userId()
- ? (session.session()?.pullRequestUrl ?? undefined)
- : undefined,
+ () => (coding() && session.userId() ? pullRequestUrl() : undefined),
() => source.summary()?.changeset?.id
);
const host: ChangesHost = {
@@ -71,8 +72,8 @@ export function AgentChangesProvider(props: ParentProps) {
!session.loadFailed() &&
(session.session()?.canEdit ?? true),
},
- canHaveChanges: coding,
- pullRequestUrl: () => session.session()?.pullRequestUrl ?? undefined,
+ canHaveChanges,
+ pullRequestUrl,
openExternal: openExternalUrl,
copyText,
notify: (message, tone) => {
diff --git a/apps/web/src/features/agent-changes/context/agent-changes-context.ts b/apps/web/src/features/agent-changes/context/agent-changes-context.ts
index 6ac782faf1..6d113068eb 100644
--- a/apps/web/src/features/agent-changes/context/agent-changes-context.ts
+++ b/apps/web/src/features/agent-changes/context/agent-changes-context.ts
@@ -52,8 +52,8 @@ export type ChangesHost = {
/**
* Whether the source can ever hold changes. Omit for hosts that always
* can (a PR entity); a session host reports false for a chat-only
- * harness, which hides every Changes control instead of showing an
- * empty pane.
+ * harness or a session with no linked pull request, which hides every
+ * Changes control instead of showing an empty pane.
*/
canHaveChanges?: Accessor<boolean>;
/** GitHub API totals; undefined while unavailable, with no estimated fallback. */