Skip to content

An open-source, faster Devin alternative

TypeScript

fix(web): harden Flue repository state

Igor Zalutskie458d3c0be00
diff --git a/docs/agent-sessions/runtime-tools.mdx b/docs/agent-sessions/runtime-tools.mdx
index d0715cd0..8f97ec6f 100644
--- a/docs/agent-sessions/runtime-tools.mdx
+++ b/docs/agent-sessions/runtime-tools.mdx
@@ -55,13 +55,17 @@ commits as usual; calling the tool hands the requested outcome to the platform,
commits the agent's edits to an `oc/<session>/<source>-<id>` branch and opens the PR with a
just-in-time, write-scoped token — outside the agent sandbox. It returns the PR URL.
-| Argument | Required | What it is |
-| -------- | -------- | ------------------------------------------------------------------------------- |
-| `source` | yes | The checked-out source's local name (its directory under `/workspace/sources`). |
-| `title` | yes | PR title. |
-| `body` | no | PR description. |
-| `base` | no | PR base branch. Defaults to the source's checked-out ref. |
-| `draft` | no | Open the PR as a draft. |
+| Argument | Required | What it is |
+| -------- | ------------------------ | --------------------------------------------------------------------------------------------------------------- |
+| `source` | yes | The checked-out source's local name (its directory under `/workspace/sources`). |
+| `title` | yes | PR title. |
+| `body` | no | PR description. |
+| `base` | built-in: no · Flue: yes | PR base branch. Built-in runtimes default to the checked-out ref; hosted Flue requires the exact target branch. |
+| `draft` | no | Open the PR as a draft. |
+
+Hosted Flue uses an object input:
+`github_publish_pull_request({ source, title, body?, base, draft? })`. `base` is
+required. Built-in runtimes keep their existing tool input and may omit `base`.
<Note>
`github_publish_pull_request` requires a **configured GitHub App** (the
@@ -74,13 +78,16 @@ just-in-time, write-scoped token — outside the agent sandbox. It returns the P
App; they never fall back to a bring-your-own App.
</Note>
-`add_source(repo, ref, name?)` checks out an **additional** repo into
-`/workspace/sources/<name>` mid-session. `repo` is `"owner/repo"` (or a `repo_…` id), `ref` a
-branch or `refs/pull/N/head`, `name` defaults to the repo name. Same zero-credential model as
-the initial checkout — a Git operations sandbox mints a just-in-time, read-only token; the
-agent never sees it. **Connected-App (`oc_app`) repos only.**
+`add_source` checks out an **additional** repo into
+`/workspace/sources/<name>` mid-session. Built-in runtimes use
+`add_source(repo, ref, name?)`. Hosted Flue uses the object input
+`add_source({ repository, ref, name? })`. `repo`/`repository` is exact
+`"owner/repo"` coordinates (or a `repo_…` id), `ref` is a branch, tag, commit,
+or `refs/pull/N/head`, and `name` defaults to the repo name. The Git operations
+sandbox mints a just-in-time read token; the agent never sees it.
+**Connected-App (`oc_app`) repos only.**
-For Flue, `repo` must be within the agent's current
+For Flue, `repository` must be within the agent's current
[repository access policy](/agent-sessions/repos#choose-working-repositories-for-a-flue-agent).
Checkout is lazy and uses the session's shared hands sandbox. Publishing always
creates an `oc/…` branch and pull request; it never pushes directly to the
diff --git a/web/package-lock.json b/web/package-lock.json
index b5ed8759..3a5f5d0e 100644
--- a/web/package-lock.json
+++ b/web/package-lock.json
@@ -40,6 +40,7 @@
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.3",
"globals": "^17.7.0",
+ "happy-dom": "^20.11.0",
"prettier": "^3.8.5",
"prettier-plugin-tailwindcss": "^0.8.0",
"shadcn": "^4.12.0",
@@ -3964,6 +3965,16 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/node": {
+ "version": "26.1.1",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-26.1.1.tgz",
+ "integrity": "sha512-nxAkRSVkN1Y0JC1W8ky/fTfkGsMmcrRsbx+3XoZE+rMOX71kLYTV7fLXpqud1GpbpP5TuffXFqfX7fH2GgZREw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~8.3.0"
+ }
+ },
"node_modules/@types/react": {
"version": "19.2.17",
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.17.tgz",
@@ -3998,6 +4009,23 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/whatwg-mimetype": {
+ "version": "3.0.2",
+ "resolved": "https://registry.npmjs.org/@types/whatwg-mimetype/-/whatwg-mimetype-3.0.2.tgz",
+ "integrity": "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/@types/ws": {
+ "version": "8.18.1",
+ "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
+ "integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.62.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.62.0.tgz",
@@ -4851,6 +4879,19 @@
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
}
},
+ "node_modules/buffer-image-size": {
+ "version": "0.6.4",
+ "resolved": "https://registry.npmjs.org/buffer-image-size/-/buffer-image-size-0.6.4.tgz",
+ "integrity": "sha512-nEh+kZOPY1w+gcCMobZ6ETUp9WfibndnosbpwB1iJk/8Gt5ZF2bhS6+B6bPYz424KtwsR6Rflc3tCz1/ghX2dQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/node": "*"
+ },
+ "engines": {
+ "node": ">=4.0"
+ }
+ },
"node_modules/bundle-name": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-4.1.0.tgz",
@@ -5657,6 +5698,19 @@
"node": ">=8.6"
}
},
+ "node_modules/entities": {
+ "version": "7.0.1",
+ "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
+ "integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==",
+ "dev": true,
+ "license": "BSD-2-Clause",
+ "engines": {
+ "node": ">=0.12"
+ },
+ "funding": {
+ "url": "https://github.com/fb55/entities?sponsor=1"
+ }
+ },
"node_modules/env-paths": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz",
@@ -7010,6 +7064,25 @@
"dev": true,
"license": "ISC"
},
+ "node_modules/happy-dom": {
+ "version": "20.11.0",
+ "resolved": "https://registry.npmjs.org/happy-dom/-/happy-dom-20.11.0.tgz",
+ "integrity": "sha512-XogN4asPd1a56di9prVG6bZxteNcXsZxxKmAvcEfc5Px5Ca2hMyMgk8wvqK2K1V8zXg40j9VANXsDaJYh9DeNA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/node": ">=20.0.0",
+ "@types/whatwg-mimetype": "^3.0.2",
+ "@types/ws": "^8.18.1",
+ "buffer-image-size": "^0.6.4",
+ "entities": "^7.0.1",
+ "whatwg-mimetype": "^3.0.0",
+ "ws": "^8.21.0"
+ },
+ "engines": {
+ "node": ">=20.0.0"
+ }
+ },
"node_modules/has-bigints": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.1.0.tgz",
@@ -10878,6 +10951,13 @@
"node": ">=20.18.1"
}
},
+ "node_modules/undici-types": {
+ "version": "8.3.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz",
+ "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/unicorn-magic": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.3.0.tgz",
@@ -11196,6 +11276,16 @@
"integrity": "sha512-q6LWsLatGYZp5VGBIOvbTj6JBV2nOmC8KvWztXBmwJcfFAzhwKwbOxhUH306XY3CcaZDUlSmSuNPBsCn0bFu+g==",
"license": "Apache-2.0"
},
+ "node_modules/whatwg-mimetype": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz",
+ "integrity": "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12"
+ }
+ },
"node_modules/which": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz",
@@ -11335,6 +11425,28 @@
"dev": true,
"license": "ISC"
},
+ "node_modules/ws": {
+ "version": "8.21.1",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.1.tgz",
+ "integrity": "sha512-+0NTnW77fFN/DjQi6k/Sq/Yvk4Sgajw7urW8V+asjXnRgDs9gyGkdb7EzgfhA4goXsRIZKE28fzIXBHEzhuiWw==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=10.0.0"
+ },
+ "peerDependencies": {
+ "bufferutil": "^4.0.1",
+ "utf-8-validate": ">=5.0.2"
+ },
+ "peerDependenciesMeta": {
+ "bufferutil": {
+ "optional": true
+ },
+ "utf-8-validate": {
+ "optional": true
+ }
+ }
+ },
"node_modules/wsl-utils": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/wsl-utils/-/wsl-utils-0.3.1.tgz",
diff --git a/web/package.json b/web/package.json
index 1c1d55da..5f4d4fce 100644
--- a/web/package.json
+++ b/web/package.json
@@ -50,6 +50,7 @@
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.3",
"globals": "^17.7.0",
+ "happy-dom": "^20.11.0",
"prettier": "^3.8.5",
"prettier-plugin-tailwindcss": "^0.8.0",
"shadcn": "^4.12.0",
diff --git a/web/src/api/mock.ts b/web/src/api/mock.ts
index 86d027d6..0410dd83 100644
--- a/web/src/api/mock.ts
+++ b/web/src/api/mock.ts
@@ -978,7 +978,7 @@ const sessionSources = [
repo_id: 'repo_01k0acmeagents000000000',
full_name: 'acme/agents',
requested_ref: 'main',
- status: 'ready',
+ status: 'resolved',
path: '/workspace/sources/app',
sha: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0',
resolved_sha: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0',
diff --git a/web/src/api/repository-access-client.test.ts b/web/src/api/repository-access-client.test.ts
index 927ddff5..cabe916b 100644
--- a/web/src/api/repository-access-client.test.ts
+++ b/web/src/api/repository-access-client.test.ts
@@ -69,7 +69,7 @@ describe('repository access client', () => {
repo_id: 'repo_1',
full_name: 'acme/app',
requested_ref: 'main',
- status: 'ready',
+ status: 'resolved',
path: '/workspace/sources/app',
sha: 'a'.repeat(40),
resolved_sha: 'b'.repeat(40),
diff --git a/web/src/api/repository-access-schemas.test.ts b/web/src/api/repository-access-schemas.test.ts
index 72e4c3d1..0051c90e 100644
--- a/web/src/api/repository-access-schemas.test.ts
+++ b/web/src/api/repository-access-schemas.test.ts
@@ -44,7 +44,7 @@ describe('repository access schemas', () => {
SessionSourceListSchema.parse([
{
name: 'app',
- status: 'ready',
+ status: 'pending',
path: '/workspace/sources/app',
sha: 'a'.repeat(40),
},
diff --git a/web/src/api/schemas.ts b/web/src/api/schemas.ts
index 4c29ea94..d24d3c7f 100644
--- a/web/src/api/schemas.ts
+++ b/web/src/api/schemas.ts
@@ -931,7 +931,14 @@ export const SessionListSchema = z.object({
export const SessionSourceSchema = z.object({
name: z.string(),
- status: z.string(),
+ status: z.enum([
+ 'pending',
+ 'materializing',
+ 'resolved',
+ 'failed',
+ 'unavailable',
+ 'auth_required',
+ ]),
path: z.string(),
sha: z.string(),
resolved_sha: z.string().optional(),
diff --git a/web/src/components/repository-access-agent-switch.test.tsx b/web/src/components/repository-access-agent-switch.test.tsx
new file mode 100644
index 00000000..ddfc4c2c
--- /dev/null
+++ b/web/src/components/repository-access-agent-switch.test.tsx
@@ -0,0 +1,140 @@
+// @vitest-environment happy-dom
+
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import type { RepositoryAccess } from '@/api/client'
+import { repositoryAccessQueryKey } from '@/lib/repository-access'
+import { RepositoryAccessPanel } from './repository-access'
+
+const agentA = 'agt_aaaaaaaaaaaaaaaaaaaaaaaa'
+const agentB = 'agt_bbbbbbbbbbbbbbbbbbbbbbbb'
+
+const repository = {
+ id: 'repo_1',
+ full_name: 'acme/support-agent',
+ default_branch: 'main',
+ private: true,
+}
+
+function access(policy: RepositoryAccess['policy']): RepositoryAccess {
+ return {
+ policy,
+ grant: {
+ status: 'active',
+ account: 'acme',
+ repository_selection: 'all',
+ install_url: 'https://github.test/install',
+ configure_url: 'https://github.test/configure',
+ truncated: false,
+ },
+ effective_repositories: policy.mode === 'all' ? [repository] : [],
+ unavailable_selected_repositories: [],
+ }
+}
+
+function button(container: ParentNode, label: string): HTMLButtonElement {
+ const match = [...container.querySelectorAll('button')].find((element) =>
+ element.textContent?.includes(label),
+ )
+ if (!(match instanceof HTMLButtonElement))
+ throw new Error(`Button not found: ${label}`)
+ return match
+}
+
+function radio(container: ParentNode, label: string): HTMLInputElement {
+ const match = [
+ ...container.querySelectorAll<HTMLInputElement>('input[type="radio"]'),
+ ].find((element) => element.closest('label')?.textContent?.includes(label))
+ if (!match) throw new Error(`Radio not found: ${label}`)
+ return match
+}
+
+describe('RepositoryAccessPanel agent scoping', () => {
+ let container: HTMLDivElement
+ let root: Root
+ let client: QueryClient
+
+ beforeEach(() => {
+ ;(
+ globalThis as typeof globalThis & {
+ IS_REACT_ACT_ENVIRONMENT: boolean
+ }
+ ).IS_REACT_ACT_ENVIRONMENT = true
+ container = document.createElement('div')
+ document.body.append(container)
+ root = createRoot(container)
+ client = new QueryClient({
+ defaultOptions: { queries: { retry: false, staleTime: Infinity } },
+ })
+ client.setQueryData(
+ repositoryAccessQueryKey(agentA),
+ access({ mode: 'all' }),
+ )
+ client.setQueryData(
+ repositoryAccessQueryKey(agentB),
+ access({ mode: 'selected', repository_ids: [] }),
+ )
+ client.setQueryData(['deploy-app'], {
+ installed: true,
+ install_url: 'https://github.test/install',
+ configure_url: 'https://github.test/configure',
+ account: 'acme',
+ repository_selection: 'all',
+ repositories: [repository],
+ })
+ })
+
+ afterEach(() => {
+ act(() => root.unmount())
+ client.clear()
+ container.remove()
+ document.body.replaceChildren()
+ })
+
+ function renderAgent(agentId: string) {
+ act(() => {
+ root.render(
+ <QueryClientProvider client={client}>
+ <RepositoryAccessPanel agentId={agentId} />
+ </QueryClientProvider>,
+ )
+ })
+ }
+
+ it('discards Agent A draft, search, and confirmation when rerendered for Agent B', () => {
+ renderAgent(agentA)
+
+ const allPolicy = radio(container, 'All granted repositories')
+ const selectedPolicyA = radio(container, 'Only selected repositories')
+ expect(allPolicy.name).toBe(selectedPolicyA.name)
+ expect(allPolicy.checked).toBe(true)
+ act(() => selectedPolicyA.click())
+ expect(selectedPolicyA.checked).toBe(true)
+ const search = container.querySelector<HTMLInputElement>(
+ 'input[aria-label="Find a repository"]',
+ )
+ expect(search).not.toBeNull()
+ act(() => {
+ search!.value = 'support'
+ search!.dispatchEvent(new Event('input', { bubbles: true }))
+ })
+ expect(search!.value).toBe('support')
+
+ act(() => button(container, 'Save access').click())
+ expect(document.body.textContent).toContain('Narrow repository access?')
+
+ renderAgent(agentB)
+
+ const selectedPolicy = radio(container, 'Only selected repositories')
+ expect(selectedPolicy.checked).toBe(true)
+ expect(button(container, 'Save access').disabled).toBe(true)
+ expect(
+ container.querySelector<HTMLInputElement>(
+ 'input[aria-label="Find a repository"]',
+ )?.value,
+ ).toBe('')
+ expect(document.body.textContent).not.toContain('Narrow repository access?')
+ })
+})
diff --git a/web/src/components/repository-access.test.tsx b/web/src/components/repository-access.test.tsx
index ab80e1d8..10ea1e7d 100644
--- a/web/src/components/repository-access.test.tsx
+++ b/web/src/components/repository-access.test.tsx
@@ -95,11 +95,23 @@ describe('repository access UI', () => {
],
})
expect(html).toContain('partial repository list')
- expect(html).toContain('Hidden selections are preserved')
+ expect(html).toContain('Hidden existing selections are preserved')
expect(html).toContain('acme/removed')
expect(html).toContain('Unavailable')
})
+ it('explains that switching from a truncated all grant is intentionally narrowing', () => {
+ const html = renderAccess({
+ ...selected,
+ grant: { ...selected.grant, truncated: true },
+ policy: { mode: 'all' },
+ })
+ expect(html).toContain(
+ 'Switching to selected access limits the agent to repositories you choose from this partial list.',
+ )
+ expect(html).not.toContain('Hidden existing selections are preserved')
+ })
+
it('distinguishes an unavailable grant from a valid empty grant', () => {
const html = renderAccess({
...selected,
diff --git a/web/src/components/repository-access.tsx b/web/src/components/repository-access.tsx
index 788da4e9..570a60c8 100644
--- a/web/src/components/repository-access.tsx
+++ b/web/src/components/repository-access.tsx
@@ -103,13 +103,28 @@ function AccessUnavailable({ access }: { access: RepositoryAccess }) {
)
}
+interface RepositoryAccessPanelProps {
+ agentId: string
+ context?: 'setup' | 'settings'
+}
+
export function RepositoryAccessPanel({
agentId,
context = 'settings',
-}: {
- agentId: string
- context?: 'setup' | 'settings'
-}) {
+}: RepositoryAccessPanelProps) {
+ return (
+ <RepositoryAccessPanelForAgent
+ key={agentId}
+ agentId={agentId}
+ context={context}
+ />
+ )
+}
+
+function RepositoryAccessPanelForAgent({
+ agentId,
+ context = 'settings',
+}: RepositoryAccessPanelProps) {
const queryClient = useQueryClient()
const accessQuery = useRepositoryAccess(agentId)
const deployAppQuery = useQuery({
@@ -248,22 +263,24 @@ export function RepositoryAccessPanel({
<AccessUnavailable access={access} />
) : access && draft ? (
<div className="space-y-4">
- <div
- className="grid gap-2 sm:grid-cols-2"
- role="radiogroup"
- aria-label="Repository policy"
- >
- <button
- type="button"
- role="radio"
- aria-checked={draft.mode === 'all'}
- onClick={() => setDraft({ mode: 'all' })}
+ <fieldset className="grid gap-2 sm:grid-cols-2">
+ <legend className="sr-only">Repository policy</legend>
+ <label
className={cn(
- 'hover:border-foreground/20 flex min-h-16 min-w-0 items-start gap-3 rounded-lg border p-3 text-left transition-colors',
+ 'hover:border-foreground/20 focus-within:ring-foreground/20 flex min-h-16 min-w-0 cursor-pointer items-start gap-3 rounded-lg border p-3 text-left transition-colors focus-within:ring-2 focus-within:ring-offset-2',
draft.mode === 'all' && 'border-foreground/30 bg-muted/50',
)}
>
+ <input
+ type="radio"
+ name={`repository-policy-${agentId}`}
+ value="all"
+ checked={draft.mode === 'all'}
+ onChange={() => setDraft({ mode: 'all' })}
+ className="sr-only"
+ />
<span
+ aria-hidden
className={cn(
'mt-0.5 grid size-4 place-items-center rounded-full border',
draft.mode === 'all' &&
@@ -280,29 +297,34 @@ export function RepositoryAccessPanel({
Includes repositories added to the installation later.
</span>
</span>
- </button>
- <button
- type="button"
- role="radio"
- aria-checked={draft.mode === 'selected'}
- onClick={() =>
- setDraft({
- mode: 'selected',
- repository_ids:
- access.policy.mode === 'selected'
- ? selectedRepositoryIds(access.policy)
- : (access.effective_repositories ?? []).map(
- (repo) => repo.id,
- ),
- })
- }
+ </label>
+ <label
className={cn(
- 'hover:border-foreground/20 flex min-h-16 min-w-0 items-start gap-3 rounded-lg border p-3 text-left transition-colors',
+ 'hover:border-foreground/20 focus-within:ring-foreground/20 flex min-h-16 min-w-0 cursor-pointer items-start gap-3 rounded-lg border p-3 text-left transition-colors focus-within:ring-2 focus-within:ring-offset-2',
draft.mode === 'selected' &&
'border-foreground/30 bg-muted/50',
)}
>
+ <input
+ type="radio"
+ name={`repository-policy-${agentId}`}
+ value="selected"
+ checked={draft.mode === 'selected'}
+ onChange={() =>
+ setDraft({
+ mode: 'selected',
+ repository_ids:
+ access.policy.mode === 'selected'
+ ? selectedRepositoryIds(access.policy)
+ : (access.effective_repositories ?? []).map(
+ (repo) => repo.id,
+ ),
+ })
+ }
+ className="sr-only"
+ />
<span
+ aria-hidden
className={cn(
'mt-0.5 grid size-4 place-items-center rounded-full border',
draft.mode === 'selected' &&
@@ -321,8 +343,8 @@ export function RepositoryAccessPanel({
An empty selection disables repository work.
</span>
</span>
- </button>
- </div>
+ </label>
+ </fieldset>
{access.grant.truncated ? (
<div className="border-border bg-muted/40 rounded-md border px-3 py-2 text-xs">
@@ -330,8 +352,10 @@ export function RepositoryAccessPanel({
GitHub returned a partial repository list
</p>
<p className="text-muted-foreground mt-0.5">
- Hidden selections are preserved when you save. Configure the
- GitHub app to see the full grant.
+ {access.policy.mode === 'selected'
+ ? 'Hidden existing selections are preserved when you save.'
+ : 'Switching to selected access limits the agent to repositories you choose from this partial list.'}{' '}
+ Configure the GitHub app to see the full grant.
</p>
</div>
) : null}
diff --git a/web/src/components/status-badge.tsx b/web/src/components/status-badge.tsx
index 090d7323..554779d5 100644
--- a/web/src/components/status-badge.tsx
+++ b/web/src/components/status-badge.tsx
@@ -28,6 +28,7 @@ const STATUS: Record<string, Meta> = {
ready: { tone: 'running', label: 'Ready', icon: CircleCheck },
active: { tone: 'running', label: 'Active', icon: CircleCheck },
success: { tone: 'running', label: 'Success', icon: CircleCheck },
+ resolved: { tone: 'running', label: 'Resolved', icon: CircleCheck },
stopped: { tone: 'stopped', label: 'Stopped', icon: CircleSlash },
not_deployed: {
tone: 'stopped',
@@ -45,6 +46,12 @@ const STATUS: Record<string, Meta> = {
queued: { tone: 'pending', label: 'Queued', icon: Clock },
accepted: { tone: 'pending', label: 'Queued', icon: Clock },
fetching: { tone: 'pending', label: 'Fetching', icon: Loader2, spin: true },
+ materializing: {
+ tone: 'pending',
+ label: 'Materializing',
+ icon: Loader2,
+ spin: true,
+ },
validating: {
tone: 'pending',
label: 'Validating',
@@ -93,6 +100,8 @@ const STATUS: Record<string, Meta> = {
deleting: { tone: 'pending', label: 'Deleting', icon: Loader2, spin: true },
error: { tone: 'error', label: 'Error', icon: CircleAlert },
failed: { tone: 'error', label: 'Failed', icon: CircleAlert },
+ unavailable: { tone: 'error', label: 'Unavailable', icon: CircleAlert },
+ auth_required: { tone: 'error', label: 'Auth required', icon: CircleAlert },
unverified: { tone: 'error', label: 'Unverified', icon: CircleAlert },
verified: { tone: 'running', label: 'Verified', icon: CircleCheck },
superseded: { tone: 'stopped', label: 'Superseded', icon: CircleSlash },
diff --git a/web/src/components/working-repo-field-state.test.tsx b/web/src/components/working-repo-field-state.test.tsx
new file mode 100644
index 00000000..4330550a
--- /dev/null
+++ b/web/src/components/working-repo-field-state.test.tsx
@@ -0,0 +1,134 @@
+// @vitest-environment happy-dom
+
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import type { RepositoryAccess } from '@/api/client'
+import { repositoryAccessQueryKey } from '@/lib/repository-access'
+import { WorkingRepoField, type WorkingRepo } from './working-repo-field'
+
+const agentA = 'agt_aaaaaaaaaaaaaaaaaaaaaaaa'
+const agentB = 'agt_bbbbbbbbbbbbbbbbbbbbbbbb'
+const value: WorkingRepo = {
+ repo: 'repo_1',
+ fullName: 'acme/app',
+ ref: 'main',
+}
+
+function access(
+ repositories: RepositoryAccess['effective_repositories'],
+ truncated = false,
+): RepositoryAccess {
+ return {
+ policy: { mode: 'all' },
+ grant: {
+ status: repositories === null ? 'unavailable' : 'active',
+ account: 'acme',
+ repository_selection: 'all',
+ install_url: 'https://github.test/install',
+ configure_url: 'https://github.test/configure',
+ truncated,
+ },
+ effective_repositories: repositories,
+ unavailable_selected_repositories: [],
+ }
+}
+
+const repository = {
+ id: 'repo_1',
+ full_name: 'acme/app',
+ default_branch: 'main',
+ private: true,
+}
+
+describe('WorkingRepoField selection validity', () => {
+ let container: HTMLDivElement
+ let root: Root
+ let client: QueryClient
+
+ beforeEach(() => {
+ ;(
+ globalThis as typeof globalThis & {
+ IS_REACT_ACT_ENVIRONMENT: boolean
+ }
+ ).IS_REACT_ACT_ENVIRONMENT = true
+ container = document.createElement('div')
+ document.body.append(container)
+ root = createRoot(container)
+ client = new QueryClient({
+ defaultOptions: { queries: { retry: false, staleTime: Infinity } },
+ })
+ client.setQueryData(repositoryAccessQueryKey(agentA), access([repository]))
+ client.setQueryData(repositoryAccessQueryKey(agentB), access([repository]))
+ })
+
+ afterEach(() => {
+ act(() => root.unmount())
+ client.clear()
+ container.remove()
+ })
+
+ function renderField(
+ agentId: string,
+ onChange: (next: WorkingRepo | null) => void,
+ ) {
+ act(() => {
+ root.render(
+ <QueryClientProvider client={client}>
+ <WorkingRepoField
+ agentId={agentId}
+ runtime="flue"
+ value={value}
+ onChange={onChange}
+ />
+ </QueryClientProvider>,
+ )
+ })
+ }
+
+ it('clears a selection immediately when the agent scope changes', () => {
+ const onChange = vi.fn()
+ renderField(agentA, onChange)
+ expect(onChange).not.toHaveBeenCalled()
+
+ renderField(agentB, onChange)
+ expect(onChange).toHaveBeenCalledWith(null)
+ })
+
+ it('clears a selection removed from the loaded effective policy', () => {
+ const onChange = vi.fn()
+ renderField(agentA, onChange)
+
+ act(() => {
+ client.setQueryData(repositoryAccessQueryKey(agentA), access([]))
+ })
+ renderField(agentA, onChange)
+
+ expect(onChange).toHaveBeenCalledWith(null)
+ })
+
+ it('keeps the selection when an unavailable grant makes the set unknown', () => {
+ const onChange = vi.fn()
+ renderField(agentA, onChange)
+
+ act(() => {
+ client.setQueryData(repositoryAccessQueryKey(agentA), access(null))
+ })
+ renderField(agentA, onChange)
+
+ expect(onChange).not.toHaveBeenCalled()
+ })
+
+ it('keeps the selection when a truncated grant makes absence ambiguous', () => {
+ const onChange = vi.fn()
+ renderField(agentA, onChange)
+
+ act(() => {
+ client.setQueryData(repositoryAccessQueryKey(agentA), access([], true))
+ })
+ renderField(agentA, onChange)
+
+ expect(onChange).not.toHaveBeenCalled()
+ })
+})
diff --git a/web/src/components/working-repo-field.tsx b/web/src/components/working-repo-field.tsx
index 41bc6702..2209406d 100644
--- a/web/src/components/working-repo-field.tsx
+++ b/web/src/components/working-repo-field.tsx
@@ -1,4 +1,4 @@
-import { useMemo } from 'react'
+import { useEffect, useMemo, useRef } from 'react'
import { useQuery } from '@tanstack/react-query'
import { Select as SelectPrimitive } from 'radix-ui'
import { Check, ChevronDown, GitBranch, X } from 'lucide-react'
@@ -53,6 +53,7 @@ export function WorkingRepoField({
data: app,
isLoading: appLoading,
isError: appError,
+ isSuccess: appSuccess,
refetch: refetchApp,
} = useQuery({
queryKey: ['deploy-app'],
@@ -64,6 +65,7 @@ export function WorkingRepoField({
data: access,
isLoading: accessLoading,
isError: accessError,
+ isSuccess: accessSuccess,
refetch: refetchAccess,
} = useQuery({
queryKey: repositoryAccessQueryKey(agentId ?? ''),
@@ -93,6 +95,27 @@ export function WorkingRepoField({
access?.policy.mode === 'selected' &&
access.policy.repository_ids.length === 0
const disabled = !installed || repoOptions.length === 0
+ const scope = `${runtime ?? ''}:${agentId ?? ''}`
+ const previousScope = useRef(scope)
+
+ useEffect(() => {
+ if (previousScope.current === scope) return
+ previousScope.current = scope
+ if (value) onChange(null)
+ }, [onChange, scope, value])
+
+ const optionsAreAuthoritative = useFluePolicy
+ ? accessSuccess &&
+ access?.effective_repositories !== null &&
+ !access?.grant.truncated
+ : appSuccess
+ useEffect(() => {
+ if (!value || !optionsAreAuthoritative) return
+ const stillAvailable = repoOptions.some(
+ (repo) => workingRepoValue(repo, useFluePolicy) === value.repo,
+ )
+ if (!stillAvailable) onChange(null)
+ }, [onChange, optionsAreAuthoritative, repoOptions, useFluePolicy, value])
const pickRepo = (repoValue: string) => {
const r = repoOptions.find((x) =>
diff --git a/web/src/lib/session-source-polling.ts b/web/src/lib/session-source-polling.ts
new file mode 100644
index 00000000..0ef08eac
--- /dev/null
+++ b/web/src/lib/session-source-polling.ts
@@ -0,0 +1,17 @@
+import type { SessionSource } from '@/api/client'
+
+const ACTIVE_SOURCE_STATUSES = new Set(['pending', 'materializing'])
+
+/**
+ * Empty sessions keep a slow watch for the first lazy Flue checkout. Active
+ * materialization polls quickly. Terminal sources return to the slow watch so
+ * a later turn adding another source still appears. React Query pauses these
+ * intervals while the page is backgrounded.
+ */
+export function sessionSourcesRefetchInterval(
+ sources: SessionSource[] | undefined,
+): number {
+ if (sources?.some((source) => ACTIVE_SOURCE_STATUSES.has(source.status)))
+ return 1_500
+ return 5_000
+}
diff --git a/web/src/pages/SessionDetail.tsx b/web/src/pages/SessionDetail.tsx
index 6a431929..e85ce38e 100644
--- a/web/src/pages/SessionDetail.tsx
+++ b/web/src/pages/SessionDetail.tsx
@@ -52,6 +52,7 @@ import {
isOutOfCredits,
isTurnInput,
} from '@/lib/session-turns'
+import { sessionSourcesRefetchInterval } from '@/lib/session-source-polling'
function toolSummary(ev: SessionEvent): string {
const b = (ev.body ?? {}) as Record<string, unknown>
@@ -251,6 +252,8 @@ for await (const event of session.events()) {
queryKey: ['session-sources', sessionId],
queryFn: () => getSessionSources(sessionId),
staleTime: 15_000,
+ refetchInterval: (query) => sessionSourcesRefetchInterval(query.state.data),
+ refetchIntervalInBackground: false,
refetchOnWindowFocus: 'always',
})
diff --git a/web/src/pages/session-sources.test.tsx b/web/src/pages/session-sources.test.tsx
index 9210911c..d3b8253d 100644
--- a/web/src/pages/session-sources.test.tsx
+++ b/web/src/pages/session-sources.test.tsx
@@ -1,5 +1,6 @@
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it } from 'vitest'
+import { sessionSourcesRefetchInterval } from '@/lib/session-source-polling'
import { SessionSourcesPanel } from './SessionDetail'
describe('session working sources', () => {
@@ -12,11 +13,44 @@ describe('session working sources', () => {
repo_id: 'repo_1',
full_name: 'acme/app',
requested_ref: 'main',
- status: 'ready',
+ status: 'resolved',
path: '/workspace/sources/app',
sha: 'a'.repeat(40),
resolved_sha: 'b'.repeat(40),
},
+ {
+ name: 'docs',
+ repo_id: 'repo_2',
+ full_name: 'acme/docs',
+ requested_ref: 'main',
+ status: 'materializing',
+ path: '/workspace/sources/docs',
+ sha: 'c'.repeat(40),
+ },
+ {
+ name: 'pending',
+ status: 'pending',
+ path: '/workspace/sources/pending',
+ sha: 'd'.repeat(40),
+ },
+ {
+ name: 'failed',
+ status: 'failed',
+ path: '/workspace/sources/failed',
+ sha: 'e'.repeat(40),
+ },
+ {
+ name: 'unavailable',
+ status: 'unavailable',
+ path: '/workspace/sources/unavailable',
+ sha: 'f'.repeat(40),
+ },
+ {
+ name: 'auth',
+ status: 'auth_required',
+ path: '/workspace/sources/auth',
+ sha: '0'.repeat(40),
+ },
]}
loading={false}
error={false}
@@ -27,7 +61,12 @@ describe('session working sources', () => {
expect(html).toContain('main · aaaaaaaa')
expect(html).toContain('observed bbbbbbbb')
expect(html).toContain(`title="Pinned commit ${'a'.repeat(40)}"`)
- expect(html).toContain('Ready')
+ expect(html).toContain('Resolved')
+ expect(html).toContain('Materializing')
+ expect(html).toContain('Pending')
+ expect(html).toContain('Failed')
+ expect(html).toContain('Unavailable')
+ expect(html).toContain('Auth required')
expect(html).toContain('/workspace/sources/app')
})
@@ -43,4 +82,39 @@ describe('session working sources', () => {
),
).toBe('')
})
+
+ it('watches for new sources and accelerates while materialization is active', () => {
+ expect(sessionSourcesRefetchInterval([])).toBe(5_000)
+ expect(
+ sessionSourcesRefetchInterval([
+ {
+ name: 'app',
+ status: 'pending',
+ path: '/workspace/sources/app',
+ sha: 'a'.repeat(40),
+ },
+ ]),
+ ).toBe(1_500)
+ expect(
+ sessionSourcesRefetchInterval([
+ {
+ name: 'app',
+ status: 'materializing',
+ path: '/workspace/sources/app',
+ sha: 'a'.repeat(40),
+ },
+ ]),
+ ).toBe(1_500)
+ expect(
+ sessionSourcesRefetchInterval([
+ {
+ name: 'app',
+ status: 'resolved',
+ path: '/workspace/sources/app',
+ sha: 'a'.repeat(40),
+ resolved_sha: 'a'.repeat(40),
+ },
+ ]),
+ ).toBe(5_000)
+ })
})