Repository navigation
feat(shared-browser): choose which new agents get the browser tool #637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
omercnet
merged 4 commits into
omercnet:main
from
keithpk:feat/shared-browser-agent-filter
Nov 17, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bfd3226
feat(shared-browser): choose which new agents get the browser tool
keithpk 03d1e01
fix(shared-browser): bound and harden the agent access decision
keithpk b04a807
fix(shared-browser): keep the filesystem root canonical and scope fie…
keithpk 97ec65f
fix(shared-browser): put the deadline on the settings read, tighten p…
keithpk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import { type PluginSurfaceProps, useSettings } from "@getpaseo/plugin/client"; | ||
| import { | ||
| SettingsAction, | ||
| SettingsCard, | ||
| SettingsInput, | ||
| type SettingsInputHandle, | ||
| SettingsSection, | ||
| SettingsSelect, | ||
| } from "@getpaseo/plugin/client/ui"; | ||
| import { useRef, useState } from "react"; | ||
| import { Text } from "react-native"; | ||
| import { type AgentAccessMode, agentAccessSettings, parseEntries } from "../shared/agent-access"; | ||
|
|
||
| const MODE_OPTIONS: readonly { label: string; value: AgentAccessMode }[] = [ | ||
| { label: "Every new agent", value: "all" }, | ||
| { label: "Only the agents listed below", value: "listed" }, | ||
| ]; | ||
|
|
||
| type ListName = "providers" | "workspaces" | "projects"; | ||
| const NO_ERRORS: Record<ListName, string | null> = { | ||
| providers: null, | ||
| workspaces: null, | ||
| projects: null, | ||
| }; | ||
|
|
||
| /** Settings screen: which new agents get the browser tool. */ | ||
| export function AgentAccessSettings({ theme }: PluginSurfaceProps) { | ||
| const settings = useSettings(agentAccessSettings); | ||
| const providers = useRef<SettingsInputHandle>(null); | ||
| const workspaces = useRef<SettingsInputHandle>(null); | ||
| const projects = useRef<SettingsInputHandle>(null); | ||
| // Errors belong to the revision they were found on; a newer revision (another client saved) clears them. | ||
| const [found, setFound] = useState<{ | ||
| revision: string | null; | ||
| errors: Record<ListName, string | null>; | ||
| }>({ revision: null, errors: NO_ERRORS }); | ||
| const muted = { color: theme.colors.foregroundMuted, fontSize: 13, lineHeight: 19 }; | ||
|
|
||
| if (settings.status === "loading") { | ||
| return ( | ||
| <SettingsSection title="Shared Browser: agent access"> | ||
| <Text style={muted}>Loading</Text> | ||
| </SettingsSection> | ||
| ); | ||
| } | ||
| if (settings.status !== "ready") { | ||
| return ( | ||
| <SettingsSection title="Shared Browser: agent access"> | ||
| <Text style={muted}>{settings.error}</Text> | ||
| <SettingsCard> | ||
| <SettingsAction label="Try again" actionLabel="Reload" onPress={settings.reload} /> | ||
| {settings.status === "invalid" ? ( | ||
| <SettingsAction | ||
| label="Back to the default" | ||
| actionLabel="Reset" | ||
| onPress={settings.reset} | ||
| /> | ||
| ) : null} | ||
| </SettingsCard> | ||
| </SettingsSection> | ||
| ); | ||
| } | ||
|
|
||
| const { values } = settings; | ||
| const listErrors = found.revision === settings.revision ? found.errors : NO_ERRORS; | ||
| const save = (next: typeof values) => void settings.save(next, settings.revision); | ||
| // The lists as typed, parsed the same way for Save and for a mode change, so unsaved text is never | ||
| // lost to the revision remount. A list that does not parse shows its error and nothing is saved. | ||
| const typedLists = () => { | ||
| const parsed = { | ||
| providers: parseEntries(providers.current?.getText() ?? ""), | ||
| workspaces: parseEntries(workspaces.current?.getText() ?? ""), | ||
| projects: parseEntries(projects.current?.getText() ?? ""), | ||
| }; | ||
| const errors = { | ||
| providers: parsed.providers.error, | ||
| workspaces: parsed.workspaces.error, | ||
| projects: parsed.projects.error, | ||
| }; | ||
| setFound({ revision: settings.revision, errors }); | ||
| if (errors.providers || errors.workspaces || errors.projects) return null; | ||
| return { | ||
| providers: parsed.providers.entries, | ||
| workspaces: parsed.workspaces.entries, | ||
| projects: parsed.projects.entries, | ||
| }; | ||
| }; | ||
| return ( | ||
| <SettingsSection title="Shared Browser: agent access"> | ||
| {/* Keyed on the revision, so the text inputs start over from the saved lists when another client changes them. */} | ||
| <SettingsCard key={settings.revision}> | ||
| <SettingsSelect | ||
| label="Browser tool for" | ||
| hint="Applies to agents created from now on. With the lists empty, no agent gets the tool." | ||
| error={settings.saveError} | ||
| value={values.mode} | ||
| options={MODE_OPTIONS} | ||
| disabled={settings.saving} | ||
| onValueChange={(mode) => { | ||
| const lists = typedLists(); | ||
| if (lists) save({ ...values, ...lists, mode }); | ||
| }} | ||
| /> | ||
|
keithpk marked this conversation as resolved.
Resolved
|
||
| <SettingsInput | ||
| ref={providers} | ||
| label="Provider ids" | ||
| hint="Separated by commas or new lines. An agent whose provider is listed gets the tool." | ||
| initialValue={values.providers.join(", ")} | ||
| error={listErrors.providers} | ||
| onChangeText={() => {}} | ||
| disabled={settings.saving} | ||
| /> | ||
| <SettingsInput | ||
| ref={workspaces} | ||
| label="Workspace ids" | ||
| hint="Every new agent in a listed workspace gets the tool." | ||
| initialValue={values.workspaces.join(", ")} | ||
| error={listErrors.workspaces} | ||
| onChangeText={() => {}} | ||
| disabled={settings.saving} | ||
| /> | ||
| <SettingsInput | ||
| ref={projects} | ||
| label="Project ids" | ||
| hint="Every new agent in a workspace of a listed project gets the tool." | ||
| initialValue={values.projects.join(", ")} | ||
| error={listErrors.projects} | ||
| onChangeText={() => {}} | ||
| disabled={settings.saving} | ||
| /> | ||
| <SettingsAction | ||
| label="Save the lists" | ||
| actionLabel="Save" | ||
| disabled={settings.saving} | ||
| onPress={() => { | ||
| const lists = typedLists(); | ||
| if (lists) save({ ...values, ...lists }); | ||
| }} | ||
| /> | ||
| </SettingsCard> | ||
| </SettingsSection> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { WorkspaceRef } from "../shared/agent-access"; | ||
|
|
||
| export const WORKSPACE_PAGE_SIZE = 200; | ||
| export const WORKSPACE_PAGE_LIMIT = 20; | ||
|
|
||
| interface WorkspacePage { | ||
| entries: readonly WorkspaceRef[]; | ||
| pageInfo: { nextCursor?: string | null; hasMore: boolean }; | ||
| } | ||
|
|
||
| export interface WorkspaceLister { | ||
| workspaces: { | ||
| list(options: { | ||
| filter: { includeBackground: true }; | ||
| page: { limit: number; cursor?: string }; | ||
| }): Promise<WorkspacePage>; | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Every workspace the daemon knows, background ones included. An access decision made from a partial | ||
| * list could match a shallower workspace than the agent is really in, so a list that is still | ||
| * incomplete after the page limit is an error, and the caller counts it as a failed lookup. | ||
| */ | ||
| export async function listAllWorkspaces( | ||
| paseo: WorkspaceLister, | ||
| pageLimit: number = WORKSPACE_PAGE_LIMIT, | ||
| ): Promise<WorkspaceRef[]> { | ||
| const workspaces: WorkspaceRef[] = []; | ||
| let cursor: string | undefined; | ||
| for (let page = 0; page < pageLimit; page += 1) { | ||
| const result = await paseo.workspaces.list({ | ||
| filter: { includeBackground: true }, | ||
| page: { limit: WORKSPACE_PAGE_SIZE, ...(cursor ? { cursor } : {}) }, | ||
| }); | ||
| workspaces.push(...result.entries); | ||
| if (!result.pageInfo.hasMore) return workspaces; | ||
| cursor = result.pageInfo.nextCursor ?? undefined; | ||
| if (!cursor) throw new Error("Workspace list reports more pages but gave no cursor"); | ||
| } | ||
| throw new Error(`Workspace list is longer than ${pageLimit} pages`); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.