diff --git a/mobile/src/cloud/NewCloudWorkspaceScreen.tsx b/mobile/src/cloud/NewCloudWorkspaceScreen.tsx index a24a3b62605..7c7fbb55e9e 100644 --- a/mobile/src/cloud/NewCloudWorkspaceScreen.tsx +++ b/mobile/src/cloud/NewCloudWorkspaceScreen.tsx @@ -41,7 +41,12 @@ import { import { nextCloudWorkspaceTitle } from './cloud-workspace-display' import { roleForCloudError } from './cloud-entitlement-copy' import { createErrorMessage } from './cloud-workspace-copy' -import { ORCA_CLOUD_SANDBOX_SPEC } from '../../../src/shared/hosted-sandbox/hosted-sandbox-wire' +import { + ORCA_CLOUD_IDLE_SLEEP_MINUTES, + ORCA_CLOUD_SANDBOX_SPEC +} from '../../../src/shared/hosted-sandbox/hosted-sandbox-wire' +import { cloudRepoPickerRows } from './cloud-repo-picker-rows' +import { cloudRepoChoices, loadRecentCloudRepos, recordRecentCloudRepo } from './cloud-recent-repos' export function NewCloudWorkspaceScreen() { useMobileColorScheme() @@ -51,6 +56,18 @@ export function NewCloudWorkspaceScreen() { const invalidate = useInvalidateCloudWorkspaces() const existing = useCloudWorkspaces(useCloudEnrollment()).data const [repo, setRepo] = useState('') + const [recents, setRecents] = useState([]) + // "Other repository…": the free-text field, also the only field when there is nothing to pick. + const [typing, setTyping] = useState(false) + useEffect(() => { + void loadRecentCloudRepos().then(setRecents) + }, []) + const choices = cloudRepoChoices( + recents, + (existing ?? []).flatMap((workspace) => (workspace.repo ? [workspace.repo.url] : [])) + ) + // The field stays while what's typed isn't one of the rows, even if the rows load mid-typing. + const showField = typing || choices.length === 0 || (repo !== '' && !choices.includes(repo)) const [branch, setBranch] = useState('') const [agent, setAgent] = useState(ORCA_CLOUD_DEFAULT_AGENT) const [prompt, setPrompt] = useState('') @@ -125,6 +142,9 @@ export function NewCloudWorkspaceScreen() { } // The sandbox exists from here on: nothing below may report "couldn't create" or create again. const { projectRoot } = created + if (repoUrl) { + void recordRecentCloudRepo(repoUrl).catch(() => undefined) + } const workspace = { ...created.workspace, title: nextCloudWorkspaceTitle(created.workspace.title, existing ?? []) @@ -169,12 +189,18 @@ export function NewCloudWorkspaceScreen() { > 0} title={t('cloud.new.repoHeading', 'Repository')} footer={ repoInvalid ? ( {t('cloud.new.repoInvalid', 'Use a GitHub repository, like owner/repo.')} + ) : choices.length > 0 ? ( + t( + 'cloud.new.repoNotePicker', + 'Private repos need the Orca Cloud GitHub app, connected once from Orca on your computer.' + ) ) : ( t( 'cloud.new.repoNote', @@ -183,20 +209,47 @@ export function NewCloudWorkspaceScreen() { ) } > - - - + {cloudRepoPickerRows({ + choices, + repo, + typing, + disabled: creating, + t, + onPick: (next) => { + setTyping(false) + setRepo(next) + }, + onOther: () => { + // Choosing it again keeps what was typed. + if (!typing) { + setTyping(true) + setRepo('') + } + } + })} + {showField ? ( + + { + setRepo(text) + // Typing here is choosing "Other repository…", even if the rows load mid-typing. + if (choices.length > 0) { + setTyping(true) + } + }} + editable={!creating} + autoFocus={typing} + placeholder={t('cloud.new.repoPlaceholder', 'owner/repo')} + placeholderTextColor={colors.textMuted} + autoCapitalize="none" + autoCorrect={false} + keyboardType="url" + accessibilityLabel={t('cloud.new.repoLabel', 'GitHub repository')} + /> + + ) : null} @@ -216,10 +269,22 @@ export function NewCloudWorkspaceScreen() { + + {t('cloud.size.note', 'Every sandbox gets {{vcpus}} vCPU · {{memoryGb}} GB.', { + vcpus: String(ORCA_CLOUD_SANDBOX_SPEC.vcpus), + memoryGb: String(ORCA_CLOUD_SANDBOX_SPEC.memoryGb) + })} + + + {t('cloud.idle.sleeps', 'Sleeps after {{count}} minutes idle.', { + count: ORCA_CLOUD_IDLE_SLEEP_MINUTES, + defaultValue_one: 'Sleeps after {{count}} minute idle.' + })} + + + } > diff --git a/mobile/src/cloud/cloud-recent-repos.test.ts b/mobile/src/cloud/cloud-recent-repos.test.ts new file mode 100644 index 00000000000..594c64595e1 --- /dev/null +++ b/mobile/src/cloud/cloud-recent-repos.test.ts @@ -0,0 +1,40 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +const store = vi.hoisted(() => new Map()) +vi.mock('@react-native-async-storage/async-storage', () => ({ + default: { + getItem: async (key: string) => store.get(key) ?? null, + setItem: async (key: string, value: string) => void store.set(key, value) + } +})) + +import { + cloudRepoChoices, + cloudRepoSlug, + loadRecentCloudRepos, + recordRecentCloudRepo +} from './cloud-recent-repos' + +describe('repository picker choices', () => { + beforeEach(() => store.clear()) + + it('reads owner/repo from GitHub URLs and slugs, nothing else', () => { + expect(cloudRepoSlug('https://github.com/octocat/Hello-World')).toBe('octocat/Hello-World') + expect(cloudRepoSlug('https://github.com/acme/app.git')).toBe('acme/app') + expect(cloudRepoSlug('acme/app')).toBe('acme/app') + expect(cloudRepoSlug('https://gitlab.com/acme/app')).toBeNull() + }) + + it('lists this phone’s recents first, then the team’s projects, each once', async () => { + await recordRecentCloudRepo('https://github.com/acme/app') + await recordRecentCloudRepo('https://github.com/acme/web') + await recordRecentCloudRepo('https://github.com/acme/app') + expect(await loadRecentCloudRepos()).toEqual(['acme/app', 'acme/web']) + expect( + cloudRepoChoices(await loadRecentCloudRepos(), [ + 'https://github.com/acme/web', + 'https://github.com/octocat/Hello-World' + ]) + ).toEqual(['acme/app', 'acme/web', 'octocat/Hello-World']) + }) +}) diff --git a/mobile/src/cloud/cloud-recent-repos.ts b/mobile/src/cloud/cloud-recent-repos.ts new file mode 100644 index 00000000000..4ca8a3cd704 --- /dev/null +++ b/mobile/src/cloud/cloud-recent-repos.ts @@ -0,0 +1,56 @@ +import AsyncStorage from '@react-native-async-storage/async-storage' +import { z } from 'zod' + +// Repositories this phone started cloud workspaces from, newest first, for the new-workspace picker. + +const KEY = 'orca:cloud-recent-repos:v1' +const MAX = 8 + +/** "owner/repo" for a GitHub URL (or an "owner/repo" already), else null. */ +export function cloudRepoSlug(url: string): string | null { + const match = + /^(?:https?:\/\/github\.com\/)?([A-Za-z0-9-]+)\/([A-Za-z0-9._-]+?)(?:\.git)?\/?$/.exec( + url.trim() + ) + return match ? `${match[1]}/${match[2]}` : null +} + +export async function loadRecentCloudRepos(): Promise { + try { + const parsed = z + .array(z.string()) + .safeParse(JSON.parse((await AsyncStorage.getItem(KEY)) ?? '[]')) + return parsed.success ? parsed.data.slice(0, MAX) : [] + } catch { + return [] + } +} + +export async function recordRecentCloudRepo(url: string): Promise { + const slug = cloudRepoSlug(url) + if (!slug) { + return + } + const next = [slug, ...(await loadRecentCloudRepos()).filter((entry) => entry !== slug)].slice( + 0, + MAX + ) + await AsyncStorage.setItem(KEY, JSON.stringify(next)) +} + +/** Recents first, then the team's projects (repos of its cloud workspaces), each once. */ +export function cloudRepoChoices( + recents: readonly string[], + teamRepoUrls: readonly string[] +): string[] { + const seen = new Set() + const choices: string[] = [] + for (const slug of [...recents, ...teamRepoUrls.flatMap((url) => cloudRepoSlug(url) ?? [])]) { + const key = slug.toLowerCase() + if (!seen.has(key)) { + seen.add(key) + choices.push(slug) + } + } + return choices.slice(0, 12) +} diff --git a/mobile/src/cloud/cloud-repo-picker-rows.tsx b/mobile/src/cloud/cloud-repo-picker-rows.tsx new file mode 100644 index 00000000000..77ddadab6a3 --- /dev/null +++ b/mobile/src/cloud/cloud-repo-picker-rows.tsx @@ -0,0 +1,50 @@ +import type { ReactElement } from 'react' +import { ListRow } from '../components/list/ListGroup' +import type { Translate } from '../i18n/mobile-i18n' + +/** + * The repository picker's rows: recents and the team's projects, "No repository (blank project)", + * then "Other repository…" for any other repo (the free-text field). Keyed rows, not a fragment, so + * the group draws its separators. + */ +export function cloudRepoPickerRows(args: { + choices: readonly string[] + repo: string + typing: boolean + disabled: boolean + t: Translate + onPick: (repo: string) => void + onOther: () => void +}): ReactElement[] { + if (args.choices.length === 0) { + return [] + } + return [ + ...args.choices.map((choice) => ( + args.onPick(choice)} + /> + )), + args.onPick('')} + />, + + ] +} diff --git a/mobile/src/home/MobileHomeCloudSection.tsx b/mobile/src/home/MobileHomeCloudSection.tsx index 203ea6d2c06..656110debf9 100644 --- a/mobile/src/home/MobileHomeCloudSection.tsx +++ b/mobile/src/home/MobileHomeCloudSection.tsx @@ -18,6 +18,7 @@ import { useMobileColorScheme } from '../theme/use-mobile-color-scheme' import type { RpcClient } from '../transport/rpc/rpc-client-contract' import { homeListStyles as styles } from './home-list-styles' import { MobileHomeSectionHeading } from './MobileHomeSectionHeading' +import { ORCA_CLOUD_IDLE_SLEEP_MINUTES } from '../../../src/shared/hosted-sandbox/hosted-sandbox-wire' export type CloudEnrollDesktop = { name: string; client: RpcClient } @@ -84,6 +85,12 @@ export function MobileHomeCloudSection(props: { 'Start one here. It keeps running while this phone and your computer sleep.' )} + + {t('cloud.idle.sleeps', 'Sleeps after {{count}} minutes idle.', { + count: ORCA_CLOUD_IDLE_SLEEP_MINUTES, + defaultValue_one: 'Sleeps after {{count}} minute idle.' + })} + ) : ( diff --git a/mobile/src/i18n/en-runtime-required.json b/mobile/src/i18n/en-runtime-required.json index 154fcb60230..efc2a71ff82 100644 --- a/mobile/src/i18n/en-runtime-required.json +++ b/mobile/src/i18n/en-runtime-required.json @@ -141,6 +141,10 @@ } }, "cloud": { + "idle": { + "sleeps_one": "Sleeps after {{count}} minute idle.", + "sleeps_other": "Sleeps after {{count}} minutes idle." + }, "snapshot": { "git": { "files_one": "{{count}} changed file", diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index 4daadc22b31..0f8091a0f3f 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -5088,7 +5088,10 @@ "promptPlaceholder": "Optional. What should the agent start on?", "creating": "Starting your cloud workspace", "createAndStart": "Start workspace and agent", - "create": "Start workspace" + "create": "Start workspace", + "repoOther": "Other repository…", + "repoNotePicker": "Private repos need the Orca Cloud GitHub app, connected once from Orca on your computer.", + "repoNone": "No repository (blank project)" }, "line": { "runningFor": "Up {{elapsed}}. Agents keep working when you close the app.", @@ -5214,6 +5217,10 @@ "asleep": "{{name}} is asleep", "asleepDetail": "Files are kept. Wake it to keep working.", "wake": "Wake" + }, + "idle": { + "sleeps_one": "Sleeps after {{count}} minute idle.", + "sleeps_other": "Sleeps after {{count}} minutes idle." } } }