From 16135b2b84016399ef7c4850ca224782788e7e60 Mon Sep 17 00:00:00 2001 From: Eric Bukowski Date: Fri, 4 Dec 2026 22:00:56 -0700 Subject: [PATCH] feat(worker): delete an organization's Code Storage mirror when its last link to a repository goes An organization's mirror of a linked GitHub repository held a copy of the code, and its sessions' saved work, for good. It is now deleted as soon as no folder of the organization links the repository: on an unlink from the last folder, a GitHub account disconnect, the App being uninstalled, and the repository being taken out of what the App may access (`installation_repositories` removed, which also unlinks it). The mirror is deleted before the link is taken away, so a failure leaves everything in place to be tried again. Deleting is immediate and drops the saved session work; the app asks before an unlink or disconnect that does. Closes #86 Co-Authored-By: Claude Fable 5.2 --- .changeset/delete-unlinked-mirrors.md | 5 + .../web/src/routes/_app/folders.$folderId.tsx | 42 +- apps/worker/src/api/workspace.ts | 19 +- apps/worker/src/github/accounts.ts | 160 ++++--- apps/worker/src/github/repo-links.test.ts | 448 ++++++++++++++++++ apps/worker/src/github/repo-links.ts | 163 +++++++ apps/worker/src/routes/github.ts | 22 +- docs/sandboxes.md | 6 + packages/git/src/codestorage/client.ts | 12 +- packages/git/src/github/webhooks.test.ts | 22 + packages/git/src/github/webhooks.ts | 32 +- .../features/github/github-access-panel.tsx | 12 +- .../features/workspace/unlink-repo-dialog.tsx | 77 +++ .../src/features/workspace/workspace.test.ts | 60 ++- .../react/src/features/workspace/workspace.ts | 25 +- packages/react/src/index.ts | 2 + 16 files changed, 1026 insertions(+), 81 deletions(-) create mode 100644 .changeset/delete-unlinked-mirrors.md create mode 100644 apps/worker/src/github/repo-links.test.ts create mode 100644 apps/worker/src/github/repo-links.ts create mode 100644 packages/react/src/features/workspace/unlink-repo-dialog.tsx diff --git a/.changeset/delete-unlinked-mirrors.md b/.changeset/delete-unlinked-mirrors.md new file mode 100644 index 0000000..2838ff9 --- /dev/null +++ b/.changeset/delete-unlinked-mirrors.md @@ -0,0 +1,5 @@ +--- +'@swirls/shuttle': minor +--- + +Shuttle's app now deletes an organization's Code Storage copy of a GitHub repository, with the work sessions saved there, as soon as none of its folders links the repository: when it is unlinked from its last folder, when its GitHub account is disconnected, when the GitHub App is uninstalled, and when the repository is taken out of what the App may access. For hosts: `@swirls/shuttle/git` adds `deleteCodeStorageRepo(client, repoName)`, and `normalizeWebhook` reads GitHub's `installation_repositories` `removed` delivery as a new kind, `installation.repos.removed`, with the `fullNames` removed, so a host that switches over `NormalizedWebhook` exhaustively has one more kind to handle. `@swirls/shuttle/react` adds `UnlinkRepoDialog` and `unlinkDeletesSavedWork(tree, folderId, repo)` for asking before an unlink that deletes saved work, and the GitHub access panel's disconnect dialog now says when it does. diff --git a/apps/web/src/routes/_app/folders.$folderId.tsx b/apps/web/src/routes/_app/folders.$folderId.tsx index 7db2836..d0ce0b2 100644 --- a/apps/web/src/routes/_app/folders.$folderId.tsx +++ b/apps/web/src/routes/_app/folders.$folderId.tsx @@ -22,6 +22,8 @@ import { SignInGate, StartAttachments, startWorkspaceSession, + unlinkDeletesSavedWork, + UnlinkRepoDialog, useAgentGate, useDefaultHarness, usePullInbox, @@ -53,6 +55,8 @@ export const Route = createFileRoute('/_app/folders/$folderId')({ const DEMO_GOAL = 'Add a zod schema for greet() and cover it with a small test.' const REPO_PREVIEW = 8 +type LinkedRepo = WorkspaceFolder['repos'][number] + function FolderPage() { const { folderId } = Route.useParams() const workspace = useWorkspace() @@ -125,9 +129,12 @@ function FolderWorkspace({ tree, folder }: { tree: WorkspaceTree; folder: Worksp // The chip goes when the workspace's events say the repository is unlinked. const unlinkRepo = useMutation(api.workspace.repos.unlink.mutationOptions()) + // The repository an unlink is asking about, while its dialog is open. + const [unlinking, setUnlinking] = useState(null) const busy = startSession.isPending - // One line under the composer reports whichever of the two was tried last. - const error = startSession.error ?? unlinkRepo.error + // One line under the composer reports whichever of the two was tried last. An unlink that asked + // first reports in its dialog instead. + const error = startSession.error ?? (unlinking === null ? unlinkRepo.error : null) function start() { const trimmed = goal.trim() @@ -147,9 +154,16 @@ function FolderWorkspace({ tree, folder }: { tree: WorkspaceTree; folder: Worksp } } - function unlink(repoId: string) { + function unlink(repo: LinkedRepo) { startSession.reset() - unlinkRepo.mutate({ folderId: folder.folderId, repoId }) + unlinkRepo.reset() + + // Taking the last link away deletes Shuttle's copy and the work saved there, so it asks first. + if (unlinkDeletesSavedWork(tree, folder.folderId, repo)) { + setUnlinking(repo) + } else { + unlinkRepo.mutate({ folderId: folder.folderId, repoId: repo.id }) + } } return ( @@ -176,7 +190,7 @@ function FolderWorkspace({ tree, folder }: { tree: WorkspaceTree; folder: Worksp unlink(repo.id)} + onRemove={folder.archived ? undefined : () => unlink(repo)} /> ))} {hiddenRepos > 0 ? ( @@ -333,6 +347,24 @@ function FolderWorkspace({ tree, folder }: { tree: WorkspaceTree; folder: Worksp tree={tree} linked={folder.repos} /> + + {unlinking !== null ? ( + { + unlinkRepo.reset() + setUnlinking(null) + }} + onConfirm={() => + unlinkRepo.mutate( + { folderId: folder.folderId, repoId: unlinking.id }, + { onSuccess: () => setUnlinking(null) }, + ) + } + /> + ) : null} ) } diff --git a/apps/worker/src/api/workspace.ts b/apps/worker/src/api/workspace.ts index 25b3f47..f0c53dc 100644 --- a/apps/worker/src/api/workspace.ts +++ b/apps/worker/src/api/workspace.ts @@ -59,6 +59,7 @@ import { DEVICE_ID } from '@shuttle/runner-protocol' import { getAuth } from '../auth/auth' import type { ShuttleEnv } from '../env' +import { deleteMirrors, readFolderLinks, unlinkedMirrors } from '../github/repo-links' import { GITHUB_NOT_CONNECTED, githubTokenOf } from '../github/user-token' import { installationConnected } from '../tenancy/installations' import { api, badRequest, notFound } from './base' @@ -635,15 +636,27 @@ export const workspaceRouter = { return { folderId, repo: linked } }), + /** + * Unlinks a repository from a folder. If that was the organization's last link to it, its + * Code Storage mirror is deleted first, with the work sessions saved there: a mirror that + * cannot be deleted leaves the link in place, to be tried again. + */ unlink: workspace.repos.unlink.handler(async ({ input, context: { env, actor } }) => { const { orgId } = actor const { folderId, repoId } = input await ensureWorkspaceQuietly(env, orgId) - const tree = await readWorkspaceFolders(env, orgId) - const folder = tree.folders[folderId] - const repo = folder?.repos.find((item) => item.id === repoId) + const links = await readFolderLinks(env, orgId) + const link = links.find((item) => item.folderId === folderId && item.repo.id === repoId) + const repo = link?.repo + const fullName = repo === undefined ? null : githubFullName(repo) + + if (fullName !== null) { + const kept = links.filter((item) => item !== link).map((item) => item.repo) + + await deleteMirrors(env, unlinkedMirrors(orgId, [fullName], kept)) + } const stub = loomsStub(env.LOOMS_RUN, workspaceRunId(env, orgId)) await stub.signal([unlinkRepo({ folderId, repoId })]) diff --git a/apps/worker/src/github/accounts.ts b/apps/worker/src/github/accounts.ts index b87c951..22d305c 100644 --- a/apps/worker/src/github/accounts.ts +++ b/apps/worker/src/github/accounts.ts @@ -1,16 +1,15 @@ -import { z } from 'zod' - -import { RepoRefZ } from '@shuttle/api' -import { githubFullName, githubOrigin, readRepoRef } from '@shuttle/core/repo-ref' +import { githubFullName, githubOrigin, type RepoRef } from '@shuttle/core/repo-ref' import { ensureWorkspaceQuietly } from '@shuttle/engine/bootstrap' import { workspaceRunId } from '@shuttle/engine/config' import { loomsStub } from '@shuttle/engine/looms-stub' import { connectGithub, disconnectGithub, unlinkRepo } from '@shuttle/engine/workspace/module' import type { GithubAccount } from '@shuttle/git/github/client' +import type { EventInput } from '@swirls/looms/core' import { syncRepoPolicy } from '../api/workspace' import type { ShuttleEnv } from '../env' import { connectInstallation, disconnectInstallation } from '../tenancy/installations' +import { deleteMirrors, readFolderLinks, unlinkedMirrors } from './repo-links' /** * Connecting a GitHub App installation to an organization, and taking it away again. @@ -41,46 +40,19 @@ export async function connectAccount( ]) } -/** The repositories each folder links, read strictly: a tree that cannot be read is an error. */ -const FoldersProjection = z.object({ - value: z - .object({ - folders: z - .record( - z.string(), - z.object({ - // A `RepoRef`, or the record a link of an earlier release kept. - repos: z.array( - z.union([ - RepoRefZ, - z.object({ - installationId: z.number(), - owner: z.string(), - name: z.string(), - fullName: z.string(), - defaultBranch: z.string(), - private: z.boolean(), - }), - ]), - ), - }), - ) - .optional(), - }) - .nullish(), -}) - /** * Disconnects the installation from the organization, and unlinks its repositories from the - * organization's folders, which could no longer be reached. Returns what was unlinked. + * organization's folders, which could no longer be reached. The organization's Code Storage + * mirror of each goes too (`repo-links.ts`). Returns what was unlinked. * * The App stays installed on GitHub and other organizations keep their connection. Sessions - * already running hold the repositories they started with, and are left alone. + * already running hold the repositories they started with, and are left alone, but the work they + * saved on a deleted mirror is gone. * - * The workspace is changed before the table, and the table row goes last, so a failure part of - * the way leaves the installation connected and the whole thing can be done again. Reading the - * folders must succeed: guessing "none" would disconnect the account and leave its - * repositories linked for good. A repository linked in the instant between the read and the + * The mirrors are deleted first, then the workspace is changed, and the table row goes last, so a + * failure part of the way leaves the installation connected and the whole thing can be done + * again. Reading the folders must succeed: guessing "none" would disconnect the account and leave + * its repositories linked for good. A repository linked in the instant between the read and the * end is the one thing this misses; it stays linked until someone unlinks it. */ export async function disconnectAccount( @@ -91,47 +63,103 @@ export async function disconnectAccount( ): Promise { await ensureWorkspaceQuietly(env, orgId) - const runId = workspaceRunId(env, orgId) - const stub = loomsStub(env.LOOMS_RUN, runId) - - const response = await stub.fetch( - new Request(`https://shuttle.internal/runs/${runId}/projections/workspaceTree`), + const unlinked = await unlinkRepos( + env, + orgId, + (repo) => githubOrigin(repo)?.installationId === installationId, + [disconnectGithub({ installationId })], ) - if (!response.ok) { - throw new Error(`could not read the workspace's folders (${response.status})`) - } + await disconnectInstallation(db, installationId, orgId) + await followUnlinked(env, orgId, installationId, unlinked) - const folders = FoldersProjection.parse(await response.json()).value?.folders ?? {} + return unlinked +} + +/** + * Unlinks the repositories named in `fullNames` (each `owner/name`) from the organization's + * folders, and deletes its mirror of each: GitHub says the App may no longer access them, so they + * could no longer be reached. The account stays connected. Returns what was unlinked. + * + * The mirror of a named repository that no folder links is deleted all the same, so a delivery + * sent again after a failure finishes what the first one started. + */ +export async function removeRepos( + env: ShuttleEnv, + orgId: string, + installationId: number, + fullNames: readonly string[], +): Promise { + await ensureWorkspaceQuietly(env, orgId) - const linked = Object.entries(folders).flatMap(([folderId, folder]) => - folder.repos.flatMap((persisted) => { - const repo = readRepoRef(persisted) + const removed = new Set(fullNames.map((fullName) => fullName.toLowerCase())) - return repo !== null && githubOrigin(repo)?.installationId === installationId - ? [{ folderId, repoId: repo.id, fullName: githubFullName(repo) ?? repo.label }] - : [] - }), + const unlinked = await unlinkRepos( + env, + orgId, + (repo) => removed.has(githubFullName(repo)?.toLowerCase() ?? ''), + [], + fullNames, ) - const unlinked: UnlinkedRepo[] = linked.map(({ folderId, fullName }) => ({ folderId, fullName })) + await followUnlinked(env, orgId, installationId, unlinked) - await stub.signal([ - ...linked.map(({ folderId, repoId }) => unlinkRepo({ folderId, repoId })), - disconnectGithub({ installationId }), - ]) + return unlinked +} - await disconnectInstallation(db, installationId, orgId) +/** + * Takes every link to a repository `gone` picks out of the organization's folders, with `also` + * signalled in the same step. The mirrors that leaves with no link, and those of `named`, are + * deleted first: if one cannot be, this throws with every link still in place. + */ +async function unlinkRepos( + env: ShuttleEnv, + orgId: string, + gone: (repo: RepoRef) => boolean, + also: readonly EventInput[], + named: readonly string[] = [], +): Promise { + const links = await readFolderLinks(env, orgId) + const linked = links.filter(({ repo }) => githubOrigin(repo) !== null && gone(repo)) + const kept = links.filter((link) => !linked.includes(link)).map(({ repo }) => repo) + + const unlinked: UnlinkedRepo[] = linked.map(({ folderId, repo }) => ({ + folderId, + fullName: githubFullName(repo) ?? repo.label, + })) + + await deleteMirrors( + env, + unlinkedMirrors(orgId, [...named, ...unlinked.map((repo) => repo.fullName)], kept), + ) + + const signals = [ + ...linked.map(({ folderId, repo }) => unlinkRepo({ folderId, repoId: repo.id })), + ...also, + ] + + if (signals.length > 0) { + await loomsStub(env.LOOMS_RUN, workspaceRunId(env, orgId)).signal(signals) + } + + return unlinked +} - // With no folder left, the pull request inbox stops following each repository. The account - // is already disconnected, so a failure here is logged and not reported as one. +/** + * With no folder left, the pull request inbox stops following each repository. The links are + * already gone, so a failure here is logged and not reported as one. + */ +async function followUnlinked( + env: ShuttleEnv, + orgId: string, + installationId: number, + unlinked: readonly UnlinkedRepo[], +): Promise { for (const fullName of new Set(unlinked.map((repo) => repo.fullName))) { try { await syncRepoPolicy(env, orgId, fullName, installationId) } catch (error) { - console.error('github disconnect: could not update the pull request inbox', fullName, error) + console.error('github: could not update the pull request inbox', fullName, error) } } - - return unlinked } diff --git a/apps/worker/src/github/repo-links.test.ts b/apps/worker/src/github/repo-links.test.ts new file mode 100644 index 0000000..4287d3d --- /dev/null +++ b/apps/worker/src/github/repo-links.test.ts @@ -0,0 +1,448 @@ +import { afterEach, describe, expect, test } from 'bun:test' + +import { readRepoRef, type RepoRef } from '@shuttle/core/repo-ref' +import type { Actor } from '@shuttle/engine/tenancy/access' +import { workspaceTree } from '@shuttle/engine/workspace/module' +import type { EventInput, JsonValue } from '@swirls/looms/core' + +import { handleApi } from '../api/handler' +import type { ShuttleEnv } from '../env' +import { handleGithubPublicRoutes } from '../routes/github' +import { connectInstallation, installationConnected } from '../tenancy/installations' +import { TEST_AUTH_ENV } from '../testing/auth' +import { migratedD1 } from '../testing/fake-d1' +import { fakeEnv } from '../testing/fake-env' +import { unlinkedMirrors } from './repo-links' + +const admin: Actor = { + userId: 'user1', + orgId: 'org1', + role: 'admin', + name: 'Ada', + email: 'ada@example.com', +} + +const ACME = { login: 'acme', type: 'Organization', avatarUrl: '' } + +/** A repository as a folder links it, with the mirror linking made for `orgId`. */ +function linked(orgId: string, installationId: number, fullName: string): RepoRef { + const [owner = '', name = ''] = fullName.split('/') + + return { + id: `github-${owner}--${name}`, + dir: name, + label: fullName, + defaultBranch: 'main', + private: true, + origin: { kind: 'github', owner, name, repositoryId: null, installationId }, + store: { repoName: `org-${orgId}/${owner}--${name}` }, + hostRef: null, + } +} + +/** A repository linked by a release before `RepoRef`, which recorded no store. */ +const legacy = (installationId: number, fullName: string) => ({ + installationId, + owner: fullName.split('/')[0] ?? '', + name: fullName.split('/')[1] ?? '', + fullName, + defaultBranch: 'main', + private: false, +}) + +/** A signing key like the one Code Storage hands out: ECDSA P-256, PKCS8 PEM. */ +async function testKey(): Promise { + const pair = await crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, [ + 'sign', + 'verify', + ]) + + const der = new Uint8Array(await crypto.subtle.exportKey('pkcs8', pair.privateKey)) + + return `-----BEGIN PRIVATE KEY-----\n${btoa(String.fromCodePoint(...der))}\n-----END PRIVATE KEY-----\n` +} + +const realFetch = globalThis.fetch + +afterEach(() => { + globalThis.fetch = realFetch +}) + +/** + * Code Storage's API holding the repositories in `existing`. A delete of one in `stuck` is + * refused. Records what happened, in order, into `log`. + */ +function fakeCodeStorage( + log: string[], + existing: Set, + stuck: ReadonlySet = new Set(), +): void { + globalThis.fetch = Object.assign( + async (input: RequestInfo | URL, init?: RequestInit) => { + const request = new Request(input, init) + const named = decodeURIComponent(new URL(request.url).pathname.replace(/^\/api\/repos\//, '')) + + if (request.method !== 'DELETE') { + return Response.json({ error: 'unexpected', message: 'unexpected' }, { status: 500 }) + } + + if (stuck.has(named)) { + return Response.json({ error: 'internal', message: 'try later' }, { status: 500 }) + } + + if (!existing.delete(named)) { + return Response.json({ error: 'not found', message: 'not found' }, { status: 404 }) + } + + log.push(`delete ${named}`) + + return Response.json({ repo_name: named, message: 'deleted' }) + }, + { preconnect: realFetch.preconnect }, + ) +} + +interface Folders { + readonly [folderId: string]: { readonly repos: readonly unknown[] } +} + +/** + * Runs that answer each organization's workspace with its folders from `trees`, and record what + * they are signalled into `log`, alongside what Code Storage is asked to delete. + */ +async function fakeWorld( + trees: { readonly [orgId: string]: Folders }, + options: { readonly codeStorage?: boolean; readonly stuck?: readonly string[] } = {}, +) { + const log: string[] = [] + const db = await migratedD1() + + const mirrors = new Set( + Object.entries(trees).flatMap(([orgId, folders]) => + Object.values(folders).flatMap((folder) => + folder.repos.flatMap((repo) => { + const read = readRepoRef(repo) + + return read === null ? [] : [`org-${orgId}/${read.label.replace('/', '--')}`] + }), + ), + ), + ) + + const orgOf = (runId: string) => Object.keys(trees).find((orgId) => runId.includes(orgId)) ?? '' + + const stub = (runId: string) => ({ + fetch: async (request: Request) => + new URL(request.url).pathname.endsWith('/workspaceTree') + ? Response.json({ + value: { + ...workspaceTree.initialState, + installations: { '42': { installationId: 42, account: ACME } }, + folders: trees[orgOf(runId)] ?? {}, + }, + }) + : new Response('not found', { status: 404 }), + getRun: async () => ({ startIdentity: 'started' }), + launch: async () => {}, + signal: async (events: readonly EventInput[]) => { + if (runId.endsWith('workspace')) { + log.push(...events.map((event) => `${orgOf(runId)} ${event.type}`)) + } + + return {} + }, + }) + + const env = fakeEnv({ + ...TEST_AUTH_ENV, + AUTH_DB: db, + GITHUB_WEBHOOK_SECRET: 'hook-secret', + PIERRE_ORG: options.codeStorage === false ? undefined : 'shuttle', + PIERRE_PRIVATE_KEY: options.codeStorage === false ? undefined : await testKey(), + // SAFETY: the routes under test only call `getByName` on the binding, and the fake answers it. + LOOMS_RUN: { getByName: stub } as never, + }) + + fakeCodeStorage(log, mirrors, new Set(options.stuck)) + + for (const orgId of Object.keys(trees)) { + await connectInstallation(db, 42, orgId) + } + + return { env, db, log, mirrors } +} + +function unlink(env: ShuttleEnv, folderId: string, repoId: string) { + return handleApi({ + env, + actor: admin, + request: new Request(`https://worker.example.com/workspace/folders/${folderId}/repos`, { + method: 'DELETE', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ repoId }), + }), + }) +} + +/** A delivery from GitHub, signed as GitHub signs it. */ +async function deliver( + env: ShuttleEnv, + event: string, + payload: JsonValue, +): Promise { + const body = JSON.stringify(payload) + + const key = await crypto.subtle.importKey( + 'raw', + new TextEncoder().encode('hook-secret'), + { name: 'HMAC', hash: 'SHA-256' }, + false, + ['sign'], + ) + + const mac = new Uint8Array(await crypto.subtle.sign('HMAC', key, new TextEncoder().encode(body))) + const hex = Array.from(mac, (byte) => byte.toString(16).padStart(2, '0')).join('') + + return handleGithubPublicRoutes( + new Request('https://worker.example.com/github/webhooks', { + method: 'POST', + headers: { 'x-github-event': event, 'x-hub-signature-256': `sha256=${hex}` }, + body, + }), + env, + ) +} + +describe('which mirrors are left with no link', () => { + const glue = linked('org1', 42, 'acme/glue') + + test('one whose repository no folder links any more', () => { + expect(unlinkedMirrors('org1', ['acme/glue'], [linked('org1', 42, 'acme/tape')])).toEqual([ + 'org-org1/acme--glue', + ]) + }) + + test('not one another folder still links, however the name is spelled or was recorded', () => { + expect(unlinkedMirrors('org1', ['Acme/Glue'], [glue])).toEqual([]) + + const old = readRepoRef(legacy(42, 'acme/glue')) + + expect(old?.store).toBeNull() + expect(unlinkedMirrors('org1', ['acme/glue'], old === null ? [] : [old])).toEqual([]) + }) + + test('each once, and only for a name that is a repository', () => { + expect(unlinkedMirrors('org1', ['acme/glue', 'ACME/glue', 'acme', ''], [])).toEqual([ + 'org-org1/acme--glue', + ]) + }) +}) + +describe('unlinking a repository from a folder', () => { + test("deletes the organization's mirror when it was the last link, before unlinking", async () => { + const { env, log, mirrors } = await fakeWorld({ + org1: { f1: { repos: [linked('org1', 42, 'acme/glue'), linked('org1', 42, 'acme/tape')] } }, + org2: { f1: { repos: [linked('org2', 42, 'acme/glue')] } }, + }) + + expect((await unlink(env, 'f1', 'github-acme--glue'))?.status).toBe(200) + + expect(log).toEqual(['delete org-org1/acme--glue', 'org1 workspace.repo.unlinked']) + // The folder's other repository, and the other organization's copy of this one, are kept. + expect([...mirrors].toSorted()).toEqual(['org-org1/acme--tape', 'org-org2/acme--glue']) + }) + + test('keeps the mirror while another folder links the repository', async () => { + const { env, log } = await fakeWorld({ + org1: { + f1: { repos: [linked('org1', 42, 'acme/glue')] }, + f2: { repos: [legacy(42, 'acme/glue')] }, + }, + }) + + expect((await unlink(env, 'f1', 'github-acme--glue'))?.status).toBe(200) + expect(log).toEqual(['org1 workspace.repo.unlinked']) + }) + + test('deletes the mirror an earlier release made for a link that records no store', async () => { + const { env, log } = await fakeWorld({ org1: { f1: { repos: [legacy(42, 'acme/glue')] } } }) + + expect((await unlink(env, 'f1', 'github-acme--glue'))?.status).toBe(200) + expect(log).toEqual(['delete org-org1/acme--glue', 'org1 workspace.repo.unlinked']) + }) + + test('leaves the link in place when the mirror cannot be deleted, to be tried again', async () => { + const { env, log, mirrors } = await fakeWorld( + { org1: { f1: { repos: [linked('org1', 42, 'acme/glue')] } } }, + { stuck: ['org-org1/acme--glue'] }, + ) + + const response = await unlink(env, 'f1', 'github-acme--glue') + + expect(response?.status).toBe(502) + + expect(await response?.json()).toMatchObject({ + error: + 'Code Storage could not delete its copy of acme/glue, so nothing was changed. Try again.', + }) + + expect(log).toEqual([]) + expect([...mirrors]).toEqual(['org-org1/acme--glue']) + }) + + test('a mirror that is already gone does not stop the unlink', async () => { + const { env, log, mirrors } = await fakeWorld({ + org1: { f1: { repos: [linked('org1', 42, 'acme/glue')] } }, + }) + + mirrors.clear() + + expect((await unlink(env, 'f1', 'github-acme--glue'))?.status).toBe(200) + expect(log).toEqual(['org1 workspace.repo.unlinked']) + }) + + test('without Code Storage there is no mirror to delete', async () => { + const { env, log } = await fakeWorld( + { org1: { f1: { repos: [legacy(42, 'acme/glue')] } } }, + { codeStorage: false }, + ) + + expect((await unlink(env, 'f1', 'github-acme--glue'))?.status).toBe(200) + expect(log).toEqual(['org1 workspace.repo.unlinked']) + }) +}) + +/** Two folders linking acme/glue, one also acme/tape, in each of two organizations. */ +const bothOrgs = () => ({ + org1: { + f1: { repos: [linked('org1', 42, 'acme/glue'), linked('org1', 42, 'acme/tape')] }, + f2: { repos: [linked('org1', 42, 'acme/glue')] }, + }, + org2: { f1: { repos: [linked('org2', 42, 'acme/glue')] } }, +}) + +function disconnect(env: ShuttleEnv) { + return handleApi({ + env, + actor: admin, + request: new Request('https://worker.example.com/github/accounts/42', { method: 'DELETE' }), + }) +} + +describe('disconnecting a GitHub account', () => { + test("deletes the organization's mirror of each repository it unlinks, and no other", async () => { + const { env, db, log, mirrors } = await fakeWorld(bothOrgs()) + + expect((await disconnect(env))?.status).toBe(200) + + expect(log.filter((line) => line.startsWith('delete')).toSorted()).toEqual([ + 'delete org-org1/acme--glue', + 'delete org-org1/acme--tape', + ]) + + // The copies go before anything says the repositories are unlinked. + expect(log.slice(2)).toEqual([ + 'org1 workspace.repo.unlinked', + 'org1 workspace.repo.unlinked', + 'org1 workspace.repo.unlinked', + 'org1 workspace.github.disconnected', + ]) + + expect([...mirrors]).toEqual(['org-org2/acme--glue']) + expect(await installationConnected(db, 42, 'org1')).toBe(false) + }) + + test('changes nothing when a mirror cannot be deleted, so it can be tried again', async () => { + const { env, db, log } = await fakeWorld(bothOrgs(), { stuck: ['org-org1/acme--tape'] }) + + expect((await disconnect(env))?.status).toBe(502) + expect(log).toEqual(['delete org-org1/acme--glue']) + expect(await installationConnected(db, 42, 'org1')).toBe(true) + }) +}) + +describe('the App being uninstalled on GitHub', () => { + test('deletes the mirrors of every organization that used it', async () => { + const { env, mirrors } = await fakeWorld(bothOrgs()) + + const response = await deliver(env, 'installation', { + action: 'deleted', + installation: { id: 42 }, + }) + + expect(response?.status).toBe(200) + expect([...mirrors]).toEqual([]) + }) +}) + +function removed(env: ShuttleEnv, ...fullNames: string[]) { + return deliver(env, 'installation_repositories', { + action: 'removed', + installation: { id: 42 }, + repositories_removed: fullNames.map((fullName) => ({ full_name: fullName })), + }) +} + +describe("repositories taken out of the App's access on GitHub", () => { + test('are unlinked from every folder of every organization, and their mirrors deleted', async () => { + const { env, db, log, mirrors } = await fakeWorld(bothOrgs()) + + expect((await removed(env, 'acme/glue'))?.status).toBe(200) + + expect(log).toEqual([ + 'delete org-org1/acme--glue', + 'org1 workspace.repo.unlinked', + 'org1 workspace.repo.unlinked', + 'delete org-org2/acme--glue', + 'org2 workspace.repo.unlinked', + ]) + + // The account is still connected, and the repository it can still access is still linked. + expect([...mirrors]).toEqual(['org-org1/acme--tape']) + expect(await installationConnected(db, 42, 'org1')).toBe(true) + }) + + test('a delivery sent again after a failure finishes the job', async () => { + const world = await fakeWorld(bothOrgs(), { stuck: ['org-org1/acme--glue'] }) + + expect((await removed(world.env, 'acme/glue'))?.status).toBe(500) + // The organization whose mirror would not go keeps its links; the other is done. + expect(world.log).toEqual(['delete org-org2/acme--glue', 'org2 workspace.repo.unlinked']) + + // Sent again once Code Storage answers. + fakeCodeStorage(world.log, world.mirrors) + + expect((await removed(world.env, 'acme/glue'))?.status).toBe(200) + + expect(world.log.slice(2)).toEqual([ + 'delete org-org1/acme--glue', + 'org1 workspace.repo.unlinked', + 'org1 workspace.repo.unlinked', + // Nothing of the other organization's was left to delete; its links are unlinked again, + // which changes nothing. + 'org2 workspace.repo.unlinked', + ]) + }) + + test('a mirror left behind with no link is deleted all the same', async () => { + const { env, log, mirrors } = await fakeWorld({ org1: { f1: { repos: [] } } }) + + mirrors.add('org-org1/acme--glue') + + expect((await removed(env, 'acme/glue'))?.status).toBe(200) + expect(log).toEqual(['delete org-org1/acme--glue']) + }) + + test('repositories added to it change nothing', async () => { + const { env, log } = await fakeWorld(bothOrgs()) + + const response = await deliver(env, 'installation_repositories', { + action: 'added', + installation: { id: 42 }, + repositories_added: [{ full_name: 'acme/new' }], + }) + + expect(response?.status).toBe(200) + expect(log).toEqual([]) + }) +}) diff --git a/apps/worker/src/github/repo-links.ts b/apps/worker/src/github/repo-links.ts new file mode 100644 index 0000000..3abd8fb --- /dev/null +++ b/apps/worker/src/github/repo-links.ts @@ -0,0 +1,163 @@ +import { ORPCError } from '@orpc/server' +import { z } from 'zod' + +import { RepoRefZ } from '@shuttle/api' +import { githubFullName, readRepoRef, type RepoRef } from '@shuttle/core/repo-ref' +import { workspaceRunId } from '@shuttle/engine/config' +import { loomsStub } from '@shuttle/engine/looms-stub' +import { + codeStorageClient, + codeStorageConfigured, + codeStorageRepoName, + deleteCodeStorageRepo, +} from '@shuttle/git/codestorage/client' + +import type { ShuttleEnv } from '../env' + +/** + * The repositories an organization's folders link, and the Code Storage mirrors that go when the + * last link to a repository does. + * + * Shuttle's app keeps one mirror of a linked GitHub repository per organization + * (`codeStorageRepoName`): a copy of the code, and the work its sessions saved on branches GitHub + * never sees. Linking makes it. It is deleted when no folder of the organization links the + * repository any more, whatever took the last link away: a person unlinking it, the GitHub + * account being disconnected, the App being uninstalled, or the repository being taken out of + * what the App may access. So an organization keeps no copy of code it can no longer reach. + * + * Deleting is immediate and takes the sessions' saved work with it. A session whose sandbox is + * still there keeps the checkout it has, but can no longer save its work or move to another + * sandbox. Nothing waits for sessions to end: a copy that outlived the access would be the thing + * this is here to prevent. + */ + +/** One repository as one folder links it. */ +export interface FolderLink { + readonly folderId: string + readonly repo: RepoRef +} + +/** The repositories each folder links, read strictly: a tree that cannot be read is an error. */ +const FoldersProjection = z.object({ + value: z + .object({ + folders: z + .record( + z.string(), + z.object({ + // A `RepoRef`, or the record a link of an earlier release kept. + repos: z + .array( + z.union([ + RepoRefZ, + z.object({ + installationId: z.number(), + owner: z.string(), + name: z.string(), + fullName: z.string(), + defaultBranch: z.string(), + private: z.boolean(), + }), + ]), + ) + .default([]), + }), + ) + .optional(), + }) + .nullish(), +}) + +/** + * Every repository the organization's folders link. Reading must succeed: answering "none" for a + * tree that could not be read would have its caller take a link away and leave the mirror behind, + * or delete the mirror of a repository that is still linked. + */ +export async function readFolderLinks(env: ShuttleEnv, orgId: string): Promise { + const runId = workspaceRunId(env, orgId) + + const response = await loomsStub(env.LOOMS_RUN, runId).fetch( + new Request(`https://shuttle.internal/runs/${runId}/projections/workspaceTree`), + ) + + if (!response.ok) { + throw new Error(`could not read the workspace's folders (${response.status})`) + } + + const folders = FoldersProjection.parse(await response.json()).value?.folders ?? {} + + return Object.entries(folders).flatMap(([folderId, folder]) => + folder.repos.flatMap((persisted) => { + const repo = readRepoRef(persisted) + + return repo === null ? [] : [{ folderId, repo }] + }), + ) +} + +/** + * The mirrors of `fullNames` (each `owner/name`) that no repository in `kept` uses: the ones to + * delete once the links being taken away are gone. `kept` is every link that stays. + * + * Mirrors are compared by name, which is how a link written before `RepoRef`, with no store + * recorded, and one linked under another spelling of the same name are still counted. + */ +export function unlinkedMirrors( + orgId: string, + fullNames: readonly string[], + kept: readonly RepoRef[], +): string[] { + const inUse = new Set( + kept.flatMap((repo) => { + const fullName = githubFullName(repo) + + return fullName === null ? [] : [codeStorageRepoName(orgId, fullName)] + }), + ) + + return [ + ...new Set( + fullNames + .filter((fullName) => /^[^/]+\/[^/]+$/.test(fullName)) + .map((fullName) => codeStorageRepoName(orgId, fullName)), + ), + ].filter((repoName) => !inUse.has(repoName)) +} + +/** + * Deletes each mirror in `repoNames`. Every one is tried; if any could not be deleted this throws + * (a 502 from a route), so the caller stops before taking the link away and the whole thing can be + * done again. A mirror + * that is already gone is not a failure. Without Code Storage there are no mirrors, and nothing + * is done. + */ +export async function deleteMirrors(env: ShuttleEnv, repoNames: readonly string[]): Promise { + if (repoNames.length === 0 || !codeStorageConfigured(env)) { + return + } + + const client = codeStorageClient(env) + + const settled = await Promise.allSettled( + repoNames.map((repoName) => deleteCodeStorageRepo(client, repoName)), + ) + + const failed: string[] = [] + + for (const [index, result] of settled.entries()) { + if (result.status === 'rejected') { + const repoName = repoNames[index] ?? '' + const cause: unknown = result.reason + + failed.push(repoName) + console.error(`[code-storage] could not delete the mirror ${repoName}`, cause) + } + } + + // Said in words a person can act on: an unlink or a disconnect in the app shows them this. + if (failed.length > 0) { + throw new ORPCError('BAD_GATEWAY', { + message: `Code Storage could not delete its copy of ${failed.map((repoName) => repoName.replace(/^[^/]+\//, '').replace('--', '/')).join(', ')}, so nothing was changed. Try again.`, + }) + } +} diff --git a/apps/worker/src/routes/github.ts b/apps/worker/src/routes/github.ts index 93ae16c..ea93362 100644 --- a/apps/worker/src/routes/github.ts +++ b/apps/worker/src/routes/github.ts @@ -19,7 +19,7 @@ import { import { resolveActor } from '../auth/actor' import { getAuth } from '../auth/auth' import type { ShuttleEnv } from '../env' -import { connectAccount, disconnectAccount } from '../github/accounts' +import { connectAccount, disconnectAccount, removeRepos } from '../github/accounts' import { exchangeGithubCode, githubAuthorizeUrl, @@ -138,6 +138,26 @@ async function handleWebhook(request: Request, env: ShuttleEnv): Promise | ReturnType diff --git a/docs/sandboxes.md b/docs/sandboxes.md index d59d656..78854d7 100644 --- a/docs/sandboxes.md +++ b/docs/sandboxes.md @@ -76,6 +76,12 @@ constant first. - Work is saved to Code Storage every time a session stops working. A session can therefore leave a machine that is closed or offline: the cloud sandbox is rebuilt from the last save. Whatever changed on the machine after that save stays there, and the pill says so. +- In Shuttle's own app the saves of a linked GitHub repository are in the organization's copy of + it in Code Storage. That copy is deleted, saves included, as soon as no folder of the + organization links the repository: when it is unlinked from its last folder, when its GitHub + account is disconnected, when the GitHub App is uninstalled, and when the repository is taken + out of what the App may access. A session still running keeps the files in its sandbox, but + can no longer save them or move. ## Machines and their tokens diff --git a/packages/git/src/codestorage/client.ts b/packages/git/src/codestorage/client.ts index acaa1d5..ca50b1a 100644 --- a/packages/git/src/codestorage/client.ts +++ b/packages/git/src/codestorage/client.ts @@ -96,8 +96,11 @@ export async function ensureScratchRepo(client: Pierre, repoName: string): Promi } } -/** Deletes a session's scratch repository. Does nothing if it never had one. */ -export async function deleteScratchRepo(client: Pierre, repoName: string): Promise { +/** + * Deletes a Code Storage repository and everything in it: for a mirror, the copy of the code it + * holds and every session's saved work on it. Does nothing if there is none. + */ +export async function deleteCodeStorageRepo(client: Pierre, repoName: string): Promise { try { await client.repos.delete({ repo_name: repoName }) } catch (cause) { @@ -107,6 +110,11 @@ export async function deleteScratchRepo(client: Pierre, repoName: string): Promi } } +/** Deletes a session's scratch repository. Does nothing if it never had one. */ +export async function deleteScratchRepo(client: Pierre, repoName: string): Promise { + await deleteCodeStorageRepo(client, repoName) +} + /** The repository's git URL, without credentials. `ephemeral` selects the unmirrored branches. */ export function codeStorageGitUrl( env: CodeStorageEnv, diff --git a/packages/git/src/github/webhooks.test.ts b/packages/git/src/github/webhooks.test.ts index b83c9c2..374a1a6 100644 --- a/packages/git/src/github/webhooks.test.ts +++ b/packages/git/src/github/webhooks.test.ts @@ -106,6 +106,28 @@ describe('github webhooks', () => { ).toBe('ignored') }) + test("repositories taken out of the App's access are named, and ones added are left alone", () => { + expect( + normalizeWebhook('installation_repositories', 'del-6', { + action: 'removed', + installation: { id: 9 }, + repositories_removed: [{ full_name: 'acme/glue' }, { full_name: 'acme/tape' }, {}], + }), + ).toEqual({ + kind: 'installation.repos.removed', + deliveryId: 'del-6', + installationId: 9, + fullNames: ['acme/glue', 'acme/tape'], + }) + + expect( + normalizeWebhook('installation_repositories', 'del-7', { + action: 'added', + installation: { id: 9 }, + }).kind, + ).toBe('ignored') + }) + test('ignores unknown events', () => { const result = normalizeWebhook('issues', 'del-4', { action: 'opened' }) expect(result.kind).toBe('ignored') diff --git a/packages/git/src/github/webhooks.ts b/packages/git/src/github/webhooks.ts index 20f7668..083a771 100644 --- a/packages/git/src/github/webhooks.ts +++ b/packages/git/src/github/webhooks.ts @@ -10,6 +10,14 @@ export type NormalizedWebhook = readonly deliveryId: string readonly installationId: number } + /** Repositories were taken out of what the App may access on an account, which it stays on. */ + | { + readonly kind: 'installation.repos.removed' + readonly deliveryId: string + readonly installationId: number + /** Each as `owner/name`. */ + readonly fullNames: readonly string[] + } | { readonly kind: 'pull.upserted' readonly deliveryId: string @@ -188,6 +196,10 @@ export const WebhookPayloadSchema = z.object({ action: Text, installation: lenientObject({ id: Count }), repository: lenientObject({ full_name: Text }), + repositories_removed: z + .array(lenientObject({ full_name: Text })) + .optional() + .catch(undefined), pull_request: lenientObject({ number: Count, title: Text, @@ -510,7 +522,25 @@ export function normalizeWebhook( return { kind: 'installation.removed', deliveryId, installationId } } - case 'installation_repositories': + case 'installation_repositories': { + const installationId = installationIdFrom(body) + + const fullNames = (body.repositories_removed ?? []).flatMap((repo) => + repo?.full_name === undefined || repo.full_name === '' ? [] : [repo.full_name], + ) + + // Repositories added change nothing here: one is linked by a person, from the app. + if (body.action !== 'removed' || installationId <= 0 || fullNames.length === 0) { + return { + kind: 'ignored', + deliveryId, + reason: `installation_repositories:${body.action ?? ''}`, + } + } + + return { kind: 'installation.repos.removed', deliveryId, installationId, fullNames } + } + case 'ping': return { kind: 'ignored', deliveryId, reason: eventName } diff --git a/packages/react/src/features/github/github-access-panel.tsx b/packages/react/src/features/github/github-access-panel.tsx index 7131a3d..a402614 100644 --- a/packages/react/src/features/github/github-access-panel.tsx +++ b/packages/react/src/features/github/github-access-panel.tsx @@ -264,6 +264,9 @@ function DisconnectDialog({ folder.repos.filter((repo) => githubOrigin(repo)?.installationId === account.installationId), ) + // Shuttle's copy of a repository goes with its last link, and every link to one is this account's. + const copies = linked.some((repo) => repo.store !== null) + const repoCount = new Set(linked.map((repo) => githubFullName(repo) ?? repo.id)).size const folderCount = folders.filter((folder) => @@ -301,7 +304,14 @@ function DisconnectDialog({ will not be able to connect it again yourself. ) : null} -
  • Sessions that are already running keep their access until they end.
  • + {copies ? ( +
  • + Shuttle deletes its copy of each, with the work sessions saved there. A session that + is still running keeps the files in its sandbox, but can no longer save them or move + to another machine. +
  • + ) : null} +
  • Sessions that are already running keep their access to GitHub until they end.
  • {account.settingsUrl !== null ? (
  • The GitHub App stays installed on {account.account.login}. To revoke access diff --git a/packages/react/src/features/workspace/unlink-repo-dialog.tsx b/packages/react/src/features/workspace/unlink-repo-dialog.tsx new file mode 100644 index 0000000..c22f56b --- /dev/null +++ b/packages/react/src/features/workspace/unlink-repo-dialog.tsx @@ -0,0 +1,77 @@ +import { LoaderCircle } from 'lucide-react' + +import type { RepoRef } from '@shuttle/core/repo-ref' + +import { Button } from '../../components/ui/button' +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from '../../components/ui/dialog' + +/** + * Asks before a repository's last link is taken away, which deletes Shuttle's copy of it and the + * work sessions saved there. A host shows it when `unlinkDeletesSavedWork` says so; any other + * unlink loses nothing and needs no asking. + */ +export function UnlinkRepoDialog({ + repo, + pending, + error, + onCancel, + onConfirm, +}: { + repo: Pick + pending: boolean + error: string | null + onCancel: () => void + onConfirm: () => void +}) { + return ( + { + if (!open) { + onCancel() + } + }} + > + + + Unlink {repo.label}? + + No other folder links this repository, so Shuttle deletes its copy of it. + + + +
      +
    • + Work that sessions saved to that copy is deleted with it. Anything already pushed to + GitHub is not affected. +
    • +
    • + A session that is still running keeps the files in its sandbox, but can no longer save + them or move to another machine. +
    • +
    + + {error !== null ? ( +

    {error}

    + ) : null} + + + + + +
    +
    + ) +} diff --git a/packages/react/src/features/workspace/workspace.test.ts b/packages/react/src/features/workspace/workspace.test.ts index d07037d..4de49f4 100644 --- a/packages/react/src/features/workspace/workspace.test.ts +++ b/packages/react/src/features/workspace/workspace.test.ts @@ -1,8 +1,15 @@ import { describe, expect, test } from 'bun:test' +import type { RepoRef } from '@shuttle/core/repo-ref' import type { AnyEventEnvelope, JsonValue } from '@swirls/looms/core' -import { emptySessionTabs, emptyWorkspaceTree, sessionTabs, workspaceTree } from './workspace' +import { + emptySessionTabs, + emptyWorkspaceTree, + sessionTabs, + unlinkDeletesSavedWork, + workspaceTree, +} from './workspace' function event(type: string, payload: JsonValue, idempotencyKey?: string): AnyEventEnvelope { const envelope: AnyEventEnvelope = { @@ -228,3 +235,54 @@ describe('sessionTabs reducer', () => { expect(state.s1?.tabs.events).toBeUndefined() }) }) + +function linkedRepo(fullName: string, store: RepoRef['store']): RepoRef { + return { + id: `github-${fullName.replace('/', '--')}`, + dir: fullName.split('/')[1] ?? '', + label: fullName, + defaultBranch: 'main', + private: true, + origin: { + kind: 'github', + owner: fullName.split('/')[0] ?? '', + name: fullName.split('/')[1] ?? '', + repositoryId: null, + installationId: 1, + }, + store, + hostRef: null, + } +} + +function folderOf(folderId: string, repos: readonly RepoRef[]) { + return { folderId, name: folderId, createdAt: 1, archived: false, repos } +} + +describe('unlinkDeletesSavedWork', () => { + const glue = linkedRepo('acme/glue', { repoName: 'org-o/acme--glue' }) + + test('is true for the last link to a repository Shuttle keeps a copy of', () => { + const tree = { + folders: { f1: folderOf('f1', [glue]), f2: folderOf('f2', [linkedRepo('acme/tape', null)]) }, + } + + expect(unlinkDeletesSavedWork(tree, 'f1', glue)).toBe(true) + }) + + test('is false while another folder links it, however the name is spelled', () => { + const tree = { + folders: { f1: folderOf('f1', [glue]), f2: folderOf('f2', [linkedRepo('Acme/Glue', null)]) }, + } + + expect(unlinkDeletesSavedWork(tree, 'f1', glue)).toBe(false) + }) + + test('is false for a repository with no copy to delete', () => { + const plain = linkedRepo('acme/glue', null) + + expect(unlinkDeletesSavedWork({ folders: { f1: folderOf('f1', [plain]) } }, 'f1', plain)).toBe( + false, + ) + }) +}) diff --git a/packages/react/src/features/workspace/workspace.ts b/packages/react/src/features/workspace/workspace.ts index da5ef56..6592f70 100644 --- a/packages/react/src/features/workspace/workspace.ts +++ b/packages/react/src/features/workspace/workspace.ts @@ -5,7 +5,7 @@ import type { WorkspaceSession, WorkspaceTree, } from '@shuttle/api' -import { githubOrigin, type RepoRef } from '@shuttle/core/repo-ref' +import { githubFullName, githubOrigin, type RepoRef } from '@shuttle/core/repo-ref' import { readRepoRef, unlinkNames, withLinked } from '@shuttle/core/workspace' import { defineProjection } from '@swirls/looms/core' @@ -675,6 +675,29 @@ export function sessionStatusLabel(status: string): string { return SESSION_STATUS_LABELS.get(status) ?? status } +/** + * Whether unlinking `repo` from `folderId` deletes Shuttle's copy of it, and with that the work + * sessions saved there: it has such a copy (a `store`), and no other folder links the repository. + * It is what an unlink asks about first. + */ +export function unlinkDeletesSavedWork( + tree: Pick, + folderId: string, + repo: RepoRef, +): boolean { + const fullName = githubFullName(repo)?.toLowerCase() ?? null + + if (fullName === null || repo.store === null) { + return false + } + + return !Object.values(tree.folders).some( + (folder) => + folder.folderId !== folderId && + folder.repos.some((other) => githubFullName(other)?.toLowerCase() === fullName), + ) +} + export function repoCountLabel(count: number): string { return count === 1 ? '1 linked repo' : `${count} linked repos` } diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index f2e384e..89f7bae 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -48,6 +48,7 @@ export { AppSidebarShell, useSidebarCollapsed } from './features/workspace/app-s export { LinkRepoDialog } from './features/workspace/link-repo-dialog' export { RepoChip } from './features/workspace/repo-chip' export { StartAttachments, useStartAttachments } from './features/workspace/start-attachments' +export { UnlinkRepoDialog } from './features/workspace/unlink-repo-dialog' export { createWorkspaceFolder, orderedFolders, @@ -56,6 +57,7 @@ export { repoCountLabel, sessionsForFolder, startWorkspaceSession, + unlinkDeletesSavedWork, type WorkspaceFolder, type WorkspaceTree, } from './features/workspace/workspace'