Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(agents): default new conversations to Automatic repository (#6636)
Wolf Mermelstein521b8f90a03a
diff --git a/apps/web/src/features/agents-view/core/repository.test.ts b/apps/web/src/features/agents-view/core/repository.test.tsindex 431929264c..db3cdb235d 100644--- a/apps/web/src/features/agents-view/core/repository.test.ts+++ b/apps/web/src/features/agents-view/core/repository.test.ts@@ -77,7 +77,7 @@ describe('orderRepositories', () => {]);});- it('keeps a recent the listing no longer carries, and dedupes by spelling', () => {+ it('omits a recent the listing no longer carries, and dedupes by spelling', () => {expect(orderRepositories([macro],@@ -86,7 +86,7 @@ describe('orderRepositories', () => {'https://github.com/Macro-Inc/MACRO',])- ).toEqual([{ url: 'https://github.com/macro-inc/gone' }, macro]);+ ).toEqual([macro]);});});diff --git a/apps/web/src/features/agents-view/core/repository.ts b/apps/web/src/features/agents-view/core/repository.tsindex 5818c5236e..8dcb6ff55c 100644--- a/apps/web/src/features/agents-view/core/repository.ts+++ b/apps/web/src/features/agents-view/core/repository.ts@@ -89,10 +89,10 @@ export function sameRepository(left: string, right: string): boolean {}/**- * The repositories to offer: recents first, in their own order, then every- * other reachable repository as the harness sorted it. A recent the listing- * no longer carries stays offered - the service, not this list, decides what- * a session may use, and it says so when it refuses.+ * The repositories to offer: listed recents first, in their own order, then+ * every other reachable repository as the harness sorted it. A recent the+ * listing no longer carries is omitted — the picker only offers repositories+ * the caller can actually hand a session.*/export function orderRepositories(reachable: readonly ReachableRepository[],@@ -107,11 +107,10 @@ export function orderRepositories(ordered.push(repository);};for (const url of recents) {- add(- reachable.find((repository) => sameRepository(repository.url, url)) ?? {- url,- }+ const listed = reachable.find((repository) =>+ sameRepository(repository.url, url));+ if (listed) add(listed);}for (const repository of reachable) add(repository);return ordered;diff --git a/apps/web/src/features/agents-view/primitives/recent-repositories.ts b/apps/web/src/features/agents-view/primitives/recent-repositories.tsindex 41cb943499..06dcae0b80 100644--- a/apps/web/src/features/agents-view/primitives/recent-repositories.ts+++ b/apps/web/src/features/agents-view/primitives/recent-repositories.ts@@ -6,8 +6,8 @@ const RECENT_REPOSITORY_LIMIT = 8;/*** Repositories handed to coders from this composer, newest first and scoped- * to the signed-in user. The picker offers them ahead of the GitHub App's- * full listing, and the newest is where the next session starts.+ * to the signed-in user. The picker offers listed recents ahead of the rest+ * of the GitHub App listing. A new conversation still starts on Automatic.*/export function createRecentRepositories(userId: string | undefined) {const storage = createUserScopedStorage('agents-view-repositories-v1');diff --git a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx b/apps/web/src/features/agents-view/views/NewChatPage.test.tsxindex 5c7a5b986e..5765d7c3f3 100644--- a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx+++ b/apps/web/src/features/agents-view/views/NewChatPage.test.tsx@@ -18,6 +18,7 @@ const mocks = vi.hoisted(() => ({openSettings: vi.fn(),attachments: [] as InputAttachmentData[],recentIds: [] as string[],+ recentUrls: [] as string[],repositories: [] as { url: string; defaultBranch?: string }[],}));vi.mock('@core/util/upload', () => ({ uploadFile: vi.fn() }));@@ -36,7 +37,10 @@ vi.mock('@app/features/block-agent/context/recent-agent-selections', () => ({}),}));vi.mock('../primitives/recent-repositories', () => ({- createRecentRepositories: () => ({ urls: () => [], remember: vi.fn() }),+ createRecentRepositories: () => ({+ urls: () => mocks.recentUrls,+ remember: vi.fn(),+ }),}));vi.mock('../queries/reachable-repositories', () => ({createReachableRepositories: () => ({@@ -164,6 +168,7 @@ describe('agent-led new conversation', () => {beforeEach(() => {mocks.attachments = [];mocks.recentIds = [MACRO_CODER_BOT_ID];+ mocks.recentUrls = [];mocks.repositories = [{ url: 'https://github.com/macro-inc/macro', defaultBranch: 'develop' },];@@ -244,7 +249,24 @@ describe('agent-led new conversation', () => {repoBranch: 'feature/home',});});- it('starts a typed repository on main and a listed one on its default branch', async () => {+ it('starts a new conversation on Choose repository, not the last used one', async () => {+ mocks.recentIds = [CURSOR_BOT_ID];+ mocks.recentUrls = ['https://github.com/macro-inc/macro'];+ const send = page();+ expect(+ screen.getByRole('button', { name: 'Repository' }).textContent+ ).toContain('Choose repository');+ expect(+ screen.getByRole('button', { name: 'Repository' }).textContent+ ).not.toContain('macro-inc/macro');+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));+ expect(send).toHaveBeenLastCalledWith({+ botId: CURSOR_BOT_ID,+ prompt: 'Prompt',+ repoUrl: undefined,+ });+ });+ it('refuses an unlisted repository and starts a listed one on its default branch', async () => {const send = page();await selectAgent(/Cursor/);fireEvent.click(screen.getByRole('button', { name: 'Repository' }));@@ -254,39 +276,29 @@ describe('agent-led new conversation', () => {target: { value: 'macro-inc/other' },});- expect(- screen.queryByRole('option', { name: 'Choose automatically' })- ).toBeNull();- fireEvent.click(- screen.getByRole('option', { name: 'Use macro-inc/other' })+ expect(screen.queryAllByRole('option')).toHaveLength(0);+ expect(screen.getByText(/No repositories match/).textContent).toContain(+ 'macro-inc/other'+ );+ fireEvent.input(+ screen.getByRole('combobox', { name: 'Search repositories' }),+ { target: { value: '' } });+ fireEvent.click(screen.getByRole('option', { name: 'macro-inc/macro' }));expect(screen.getByRole('button', { name: 'Branch' }).textContent- ).toContain('main');+ ).toContain('develop');fireEvent.click(screen.getByRole('button', { name: 'Branch' }));fireEvent.input(screen.getByRole('textbox', { name: 'Starting branch' }), {- target: { value: 'feature/other' },+ target: { value: 'feature/home' },});fireEvent.click(screen.getByRole('button', { name: 'Use branch' }));fireEvent.click(screen.getByRole('button', { name: 'Send' }));- expect(send).toHaveBeenLastCalledWith({- botId: CURSOR_BOT_ID,- prompt: 'Prompt',- repoUrl: 'https://github.com/macro-inc/other',- repoBranch: 'feature/other',- });- // Another repository drops the chosen branch for its own default.- fireEvent.click(screen.getByRole('button', { name: 'Repository' }));- fireEvent.click(screen.getByRole('option', { name: 'macro-inc/macro' }));- expect(- screen.getByRole('button', { name: 'Branch' }).textContent- ).toContain('develop');- fireEvent.click(screen.getByRole('button', { name: 'Send' }));expect(send).toHaveBeenLastCalledWith({botId: CURSOR_BOT_ID,prompt: 'Prompt',repoUrl: 'https://github.com/macro-inc/macro',- repoBranch: 'develop',+ repoBranch: 'feature/home',});});it('uses a saved agent without sending a per-session model override', async () => {diff --git a/apps/web/src/features/agents-view/views/NewChatPage.tsx b/apps/web/src/features/agents-view/views/NewChatPage.tsxindex 3536b69199..5614aeb60e 100644--- a/apps/web/src/features/agents-view/views/NewChatPage.tsx+++ b/apps/web/src/features/agents-view/views/NewChatPage.tsx@@ -49,10 +49,8 @@ export function NewChatPage(props: {const options = () => props.roster;const [agentId, setAgentId] = createSignal<string>();const [modelOverride, setModelOverride] = createSignal<string>();- // The last repository handed to a coder is where the next one starts.- const [repoUrl, setRepoUrl] = createSignal<string | undefined>(- repositories.urls()[0]- );+ // A new conversation starts on Automatic until the caller picks a repository.+ const [repoUrl, setRepoUrl] = createSignal<string | undefined>();const [localDraft, setLocalDraft] = createSignal('');const draft = () => props.draft ?? localDraft();const setDraft = (text: string) =>diff --git a/apps/web/src/features/agents-view/views/RepositoryPicker.test.tsx b/apps/web/src/features/agents-view/views/RepositoryPicker.test.tsxindex 743c400ba9..26385a6a7d 100644--- a/apps/web/src/features/agents-view/views/RepositoryPicker.test.tsx+++ b/apps/web/src/features/agents-view/views/RepositoryPicker.test.tsx@@ -97,19 +97,30 @@ describe('RepositoryPicker', () => {expect(handlers.onSelectRepository).toHaveBeenCalledWith(macro.url);});- it('offers an unlisted GitHub repository typed by hand, canonicalized', () => {+ it('does not offer an unlisted repository typed by hand', () => {const handlers = picker();openRepositories();fireEvent.input(search(), {target: { value: 'https://github.com/macro-inc/other.git' },});- expect(optionNames()).toEqual(['Use macro-inc/other']);- fireEvent.click(- screen.getByRole('option', { name: 'Use macro-inc/other' })- );- expect(handlers.onSelectRepository).toHaveBeenCalledWith(- 'https://github.com/macro-inc/other'+ expect(screen.queryAllByRole('option')).toHaveLength(0);+ expect(screen.getByText(/No repositories match/).textContent).toContain(+ 'macro-inc/other');+ expect(handlers.onSelectRepository).not.toHaveBeenCalled();+ });++ it('does not offer a recent the listing no longer carries', () => {+ picker({+ recentRepositories: ['https://github.com/macro-inc/gone'],+ });+ openRepositories();+ expect(optionNames()).toEqual([+ 'Choose automatically',+ 'macro-inc/macro',+ 'macro-inc/infra',+ ]);+ expect(screen.queryByRole('option', { name: /gone/ })).toBeNull();});it('does not duplicate a listed repository typed in full', () => {diff --git a/apps/web/src/features/agents-view/views/RepositoryPicker.tsx b/apps/web/src/features/agents-view/views/RepositoryPicker.tsxindex a8c6cd6e32..a53b2eae92 100644--- a/apps/web/src/features/agents-view/views/RepositoryPicker.tsx+++ b/apps/web/src/features/agents-view/views/RepositoryPicker.tsx@@ -17,7 +17,6 @@ import { match } from 'ts-pattern';import {filterRepositories,orderRepositories,- parseRepositoryInput,type ReachableRepository,repositoryLabel,sameRepository,@@ -25,17 +24,13 @@ import {} from '../core/repository';/** One row of the repository list. */-type RepositoryChoice =- | { kind: 'automatic' }- | { kind: 'listed'; url: string }- /** Named by hand rather than listed; the service decides whether it may be used. */- | { kind: 'typed'; url: string };+type RepositoryChoice = { kind: 'automatic' } | { kind: 'listed'; url: string };/** Explicit, portaled repository/branch controls shared by Home and Agents. */export function RepositoryPicker(props: {repoUrl?: string;branch: string;- /** Every repository the signed-in user reaches through Macro's GitHub App. */+ /** Repositories the signed-in user can hand a coder through Macro's GitHub App. */repositories: ReachableRepository[];repositoriesLoading: boolean;repositoriesError: boolean;@@ -65,13 +60,6 @@ export function RepositoryPicker(props: {for (const repository of listed) {choices.push({ kind: 'listed', url: repository.url });}- const typed = parseRepositoryInput(text);- if (- typed?.startsWith('https://github.com/') &&- !listed.some((repository) => sameRepository(repository.url, typed))- ) {- choices.push({ kind: 'typed', url: typed });- }return choices;});const choose = (choice: RepositoryChoice) => {@@ -101,7 +89,6 @@ export function RepositoryPicker(props: {match(choice).with({ kind: 'automatic' }, () => 'Choose automatically').with({ kind: 'listed' }, ({ url }) => repositoryLabel(url))- .with({ kind: 'typed' }, ({ url }) => `Use ${repositoryLabel(url)}`).exhaustive();const nothingReachable = () =>!props.repositoriesLoading &&diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.mdindex 67509e4401..db8e6c0cb2 100644--- a/docs/AGENT_GUIDE/ai-chat.md+++ b/docs/AGENT_GUIDE/ai-chat.md@@ -65,13 +65,15 @@(**Choose repository** until one is picked) opens a searchable list:**Choose automatically**, then the repositories the signed-in user reachesthrough Macro's GitHub App (`GET /agent-repositories` on the agent harness),- recently used ones first. Typing filters the list; an unlisted GitHub- `owner/repo` or URL adds a **Use owner/repo** row. Arrow keys move the- highlight and Enter or a click picks it; there is no separate confirm- button. Someone who reaches no repository sees a hint with **Connect- GitHub**, which opens Settings → Connected. The last repository picked is- remembered per user in local storage and preselected next time. Once- selected, **Branch** shows the repository's default branch (`main` when it+ recently used ones first. A new conversation always starts on **Choose+ repository** (Automatic); the last used repository is not preselected.+ Typing filters the list to those reachable repositories. Unlisted GitHub+ URLs and recents the listing no longer carries are not offered. Arrow keys+ move the highlight and Enter or a click picks it; there is no separate+ confirm button. Someone who reaches no repository sees a hint with **Connect+ GitHub**, which opens Settings → Connected. Listed recents are remembered+ per user in local storage and offered first, without changing the Automatic+ default. Once selected, **Branch** shows the repository's default branch (`main` when ithas none) and opens a starting-branch field confirmed with **Use branch**;picking a different repository resets the branch to that repository'sdefault. Omitting the branch on the create-session API likewise starts on