fix(cloud-secrets): round-2 review fixes

Effective names no longer truncate; refused subscription tokens offer Sign in instead inline under
the field; editor errors sit under their field; ready row names only the covered agent; queued
sign-in can be cancelled; paste preview lists lines needing a fix first; Escape from portaled menus
no longer closes the form; model-value rule limited to the agent model names.
This commit is contained in:
Neil
2026-11-09 07:21:03 -08:00
parent a85afd7062
commit 698f7f46d0
11 changed files with 155 additions and 63 deletions
@@ -13,7 +13,13 @@ import {
const NONE: CloudAgentReadiness = { claude: null, codex: null }
const noop = (): void => {}
const actions = { onSave: async () => null, onDone: noop, onSignIn: noop, onLater: noop }
const actions = {
onSave: async () => null,
onDone: noop,
onSignIn: noop,
onCancelSignIn: noop,
onLater: noop
}
const ENTRY: PendingWorktreeCreation = {
creationId: 'fixture',
@@ -58,6 +58,15 @@ export function CloudAgentSetupDialog({
onSaved?: () => void
}): React.JSX.Element {
const t = useTranslate()
const [visit, setVisit] = useState(0)
const [wasOpen, setWasOpen] = useState(open)
// A fresh body per visit (fresh readiness, empty form) that stays mounted through the close animation.
if (open !== wasOpen) {
setWasOpen(open)
if (open) {
setVisit((value) => value + 1)
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-xl">
@@ -70,8 +79,7 @@ export function CloudAgentSetupDialog({
)}
</DialogDescription>
</DialogHeader>
{/* Mounted per open: every visit reads fresh readiness and starts with an empty form. */}
{open ? <DialogBody onClose={() => onOpenChange(false)} onSaved={onSaved} /> : null}
<DialogBody key={visit} onClose={() => onOpenChange(false)} onSaved={onSaved} />
</DialogContent>
</Dialog>
)
@@ -1,6 +1,5 @@
import { ExternalLink } from 'lucide-react'
import { useTranslate } from '@/i18n/use-translate'
import { Button } from '../ui/button'
import { Checkbox } from '../ui/checkbox'
import { Input } from '../ui/input'
import { Label } from '../ui/label'
@@ -34,15 +33,14 @@ const KEY_PAGES = {
function GetKeyLink({ url }: { url: string }): React.JSX.Element {
const t = useTranslate()
return (
<Button
<button
type="button"
variant="link"
size="inline"
className="inline-flex items-center gap-1 text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline [&_svg]:size-3"
onClick={() => void window.api.shell.openUrl(url).catch(() => undefined)}
>
{t('cloudAgentSetup.getKey', 'Get a key')}
<ExternalLink />
</Button>
<ExternalLink aria-hidden />
</button>
)
}
@@ -59,7 +57,7 @@ function Field({
label: string
helpId?: string
help?: string
error?: string | null
error?: React.ReactNode
link?: React.ReactNode
children: React.ReactNode
}): React.JSX.Element {
@@ -94,9 +92,12 @@ export function CloudAgentSetupFields({
failure,
canShare,
share,
onShare
onShare,
onSignInInstead
}: {
option: Exclude<CloudAgentSetupOption, 'sign-in'>
/** Shown inline after a refused subscription token. */
onSignInInstead?: () => void
formId: string
draft: CloudAgentSetupDraft
onDraft: (patch: Partial<CloudAgentSetupDraft>) => void
@@ -106,8 +107,24 @@ export function CloudAgentSetupFields({
onShare: (share: boolean) => void
}): React.JSX.Element {
const t = useTranslate()
const errorFor = (field: string): string | null =>
failure?.field === field ? cloudSecretsErrorCopy(failure.error, t) : null
const errorFor = (field: string): React.ReactNode =>
failure?.field === field ? (
<>
{cloudSecretsErrorCopy(failure.error, t)}
{failure.error === 'subscription_token_refused' && onSignInInstead ? (
<>
{' '}
<button
type="button"
className="inline-flex items-center gap-1 font-medium text-foreground underline underline-offset-2 hover:no-underline"
onClick={onSignInInstead}
>
{t('cloudSecrets.editor.signInInstead', 'Sign in instead')}
</button>
</>
) : null}
</>
) : null
const ids = (field: string): { id: string; helpId: string } => ({
id: `${formId}-${field}`,
helpId: `${formId}-${field}-help`
@@ -122,7 +139,7 @@ export function CloudAgentSetupFields({
value={draft[field]}
onChange={(event) => onDraft({ [field]: event.target.value })}
placeholder={placeholder}
aria-invalid={errorFor(field) !== null || undefined}
aria-invalid={failure?.field === field || undefined}
aria-describedby={ids(field).helpId}
spellCheck={false}
autoComplete="off"
@@ -134,7 +151,7 @@ export function CloudAgentSetupFields({
id={ids('key').id}
value={draft.key}
onChange={(key) => onDraft({ key })}
invalid={errorFor('key') !== null || errorFor('token') !== null}
invalid={failure?.field === 'key' || failure?.field === 'token'}
describedBy={ids('key').helpId}
placeholder={placeholder}
/>
@@ -101,6 +101,8 @@ export type CloudAgentSetupViewProps = {
) => Promise<CloudAgentSetupFailure | null>
onSaved: (saved: CloudAgentSetupSaved) => void
onCancel: () => void
/** Build sheet: the form opens from a button that unmounts, so focus moves into it. */
focusOnOpen?: boolean
/** Build sheet: a refused subscription token points back at in-VM sign-in. */
onSignInInstead?: () => void
/** Fixtures only. */
@@ -117,6 +119,7 @@ export function CloudAgentSetupView({
onSaved,
onCancel,
onSignInInstead,
focusOnOpen = false,
initialOption,
initialFailure = null
}: CloudAgentSetupViewProps): React.JSX.Element {
@@ -194,6 +197,10 @@ export function CloudAgentSetupView({
<form
onSubmit={(event) => void submit(event)}
onKeyDown={(event) => {
// Escape from a portaled Select or menu bubbles here too; let it close only that.
if (!event.currentTarget.contains(event.target as Node)) {
return
}
if (event.key === 'Escape' && !saving) {
event.stopPropagation()
onCancel()
@@ -202,7 +209,12 @@ export function CloudAgentSetupView({
className="space-y-3"
aria-label={t('cloudAgentSetup.title', 'Add an agent')}
>
{summary ? <p className="text-xs leading-5 text-muted-foreground">{summary}</p> : null}
{summary ? (
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
<CircleCheck aria-hidden className="size-3.5 shrink-0" />
{summary}
</p>
) : null}
<Tabs
value={option}
onValueChange={(next) => {
@@ -216,7 +228,7 @@ export function CloudAgentSetupView({
>
<TabsList size="sm">
{options.map((entry) => (
<TabsTrigger key={entry} value={entry}>
<TabsTrigger key={entry} value={entry} autoFocus={focusOnOpen && entry === option}>
{labels[entry].tab}
</TabsTrigger>
))}
@@ -238,20 +250,9 @@ export function CloudAgentSetupView({
canShare={canShare}
share={share}
onShare={setShare}
onSignInInstead={includeSignIn ? () => setOption('sign-in') : onSignInInstead}
/>
)}
{entry === 'api-key' &&
failure?.error === 'subscription_token_refused' &&
(includeSignIn || onSignInInstead) ? (
<Button
type="button"
variant="link"
size="inline"
onClick={() => (includeSignIn ? setOption('sign-in') : onSignInInstead?.())}
>
{t('cloudSecrets.editor.signInInstead', 'Sign in instead')}
</Button>
) : null}
</div>
</TabsContent>
))}
@@ -38,6 +38,7 @@ export type VmBuildCloudAgentStepActions = {
/** The step is done (saved, signing in, or skipped); remember that it ran. */
onDone: () => void
onSignIn: () => void
onCancelSignIn: () => void
onLater: () => void
}
@@ -110,8 +111,21 @@ export function VmBuildCloudAgentStepView({
title={t('cloudAgentSetup.signInPending', 'Agent sign-in')}
detail={t(
'cloudAgentSetup.signInPendingDetail',
'Opens when the VM is ready. Keep this tab open until then.'
'Opens when the VM is ready. Keep Orca open until then.'
)}
actions={
<Button
type="button"
variant="ghost"
size="xs"
onClick={() => {
actions.onCancelSignIn()
setMode(OFFER)
}}
>
{t('cloudSecrets.cancel', 'Cancel')}
</Button>
}
/>
</li>
)
@@ -122,7 +136,13 @@ export function VmBuildCloudAgentStepView({
<li className="py-1.5" data-vm-build-cloud-agent="ready">
<Row
icon={DONE_ICON}
title={t('cloudAgentSetup.readyTitle', 'Agents ready')}
title={
model.readiness.claude && model.readiness.codex
? t('cloudAgentSetup.readyTitle', 'Agents ready')
: t('cloudAgentSetup.readyOne', '{{agent}} ready', {
agent: model.readiness.claude ? 'Claude' : 'Codex'
})
}
detail={cloudAgentReadinessSummary(model.readiness, t)}
actions={
<Button
@@ -191,6 +211,7 @@ export function VmBuildCloudAgentStepView({
readiness={null}
canShare={model.canShare}
includeSignIn={false}
focusOnOpen
onSave={actions.onSave}
onSaved={(saved) => {
actions.onDone()
@@ -300,6 +321,7 @@ export function VmBuildCloudAgentStep({
onSave: save,
onDone: markDone,
onSignIn: () => setSignInRequested(true),
onCancelSignIn: () => setSignInRequested(false),
onLater: () => {
markDone()
setSkipped(true)
@@ -67,6 +67,10 @@ export function CloudSecretEditor({
<form
onSubmit={(event) => void submit(event)}
onKeyDown={(event) => {
// Escape from a portaled Select or menu bubbles here too; let it close only that.
if (!event.currentTarget.contains(event.target as Node)) {
return
}
if (event.key === 'Escape' && !saving) {
event.stopPropagation()
onCancel()
@@ -100,11 +104,16 @@ export function CloudSecretEditor({
}}
placeholder="DATABASE_URL"
aria-invalid={errorIsName || undefined}
aria-describedby={`${formId}-status`}
aria-describedby={errorIsName ? `${formId}-status` : undefined}
spellCheck={false}
autoComplete="off"
className="h-8"
/>
{errorIsName && error ? (
<p id={`${formId}-status`} role="alert" className="text-2xs text-destructive">
{cloudSecretsErrorCopy(error, t)}
</p>
) : null}
</div>
<div className="space-y-1.5">
<Label htmlFor={`${formId}-value`} variant="settings">
@@ -121,7 +130,7 @@ export function CloudSecretEditor({
}}
autoFocus={target.kind === 'replace'}
invalid={error !== null && !errorIsName}
describedBy={`${formId}-status ${formId}-help`}
describedBy={`${formId}-help`}
placeholder={
target.kind === 'replace' && target.hint
? t('cloudSecrets.editor.replacePlaceholder', 'Replaces ••••{{hint}}', {
@@ -130,26 +139,33 @@ export function CloudSecretEditor({
: undefined
}
/>
<p id={`${formId}-help`} className="text-2xs text-muted-foreground">
{t(
'cloudSecrets.editor.help',
'Hidden once saved. New terminals and agents get it within seconds, no rebuild.'
)}
</p>
{error && !errorIsName ? (
<p id={`${formId}-help`} role="alert" className="text-2xs text-destructive">
{cloudSecretsErrorCopy(error, t)}
{error === 'subscription_token_refused' && onSetUpAgent ? (
<>
{' '}
<button
type="button"
className="inline-flex items-center gap-1 font-medium text-foreground underline underline-offset-2 hover:no-underline"
onClick={onSetUpAgent}
>
{t('cloudSecrets.editor.signInInstead', 'Sign in instead')}
</button>
</>
) : null}
</p>
) : (
<p id={`${formId}-help`} className="text-2xs text-muted-foreground">
{t(
'cloudSecrets.editor.help',
'Hidden once saved. New terminals and agents get it within seconds, no rebuild.'
)}
</p>
)}
</div>
</div>
<div className="flex items-start justify-between gap-3">
<p id={`${formId}-status`} role="alert" className="min-h-4 text-xs text-destructive">
{error ? cloudSecretsErrorCopy(error, t) : null}
{error === 'subscription_token_refused' && onSetUpAgent ? (
<>
{' '}
<Button type="button" variant="link" size="inline" onClick={onSetUpAgent}>
{t('cloudSecrets.editor.signInInstead', 'Sign in instead')}
</Button>
</>
) : null}
</p>
<div className="flex items-center justify-end gap-3">
<div className="flex shrink-0 gap-2">
<Button type="button" variant="ghost" size="sm" onClick={onCancel} disabled={saving}>
{t('cloudSecrets.cancel', 'Cancel')}
@@ -119,6 +119,11 @@ export function CloudSecretsEffectiveView({
) : (
<div className="overflow-hidden rounded-md border border-border/60">
<table className="w-full table-fixed text-xs">
<colgroup>
<col />
<col className="w-36" />
<col className="w-44" />
</colgroup>
<thead className="sr-only">
<tr>
<th>{t('cloudSecrets.effective.name', 'Name')}</th>
@@ -140,7 +145,7 @@ export function CloudSecretsEffectiveView({
) : null}
</span>
</td>
<td className="w-40 px-3 py-2">
<td className="px-3 py-2">
<span className="flex items-center gap-2">
<Badge variant="outline">{cloudSecretScopeLabel(secret.scope, t)}</Badge>
<span className="font-mono text-muted-foreground">
@@ -148,7 +153,7 @@ export function CloudSecretsEffectiveView({
</span>
</span>
</td>
<td className="w-56 truncate px-3 py-2 text-muted-foreground">
<td className="truncate px-3 py-2 text-muted-foreground">
{secret.shadowed.length > 0
? t('cloudSecrets.effective.overrides', 'Overrides {{scopes}}', {
scopes: secret.shadowed
@@ -181,6 +181,7 @@ function list(
emptyDetail="Add one or paste a .env file."
initialMode={mode}
initialSaved={options.saved}
onSetUpAgent={noop}
/>
</Frame>
)
@@ -129,6 +129,10 @@ export function CloudSecretsPasteEnv({
<div
className="space-y-3 rounded-lg border border-border bg-background/60 p-3"
onKeyDown={(event) => {
// Escape from a portaled Select or menu bubbles here too; let it close only that.
if (!event.currentTarget.contains(event.target as Node)) {
return
}
// A big paste is not thrown away by a stray Escape; Cancel still discards it.
if (event.key === 'Escape' && !saving && text.trim() === '') {
event.stopPropagation()
@@ -186,14 +190,21 @@ export function CloudSecretsPasteEnv({
aria-label={t('cloudSecrets.paste.preview', 'Preview')}
className="max-h-64 divide-y divide-border/60 overflow-y-auto rounded-md border border-border/60 scrollbar-sleek"
>
{entries.map((entry) => (
<PreviewLine
key={`${entry.line}:${entry.name}`}
entry={entry}
replaces={existing.has(entry.name)}
serverError={serverErrors.get(entry.name) ?? null}
/>
))}
{/* Lines that need a fix first, so they can be checked without scrolling. */}
{[...entries]
.sort(
(a, b) =>
Number(a.issue === null || a.issue === 'overridden') -
Number(b.issue === null || b.issue === 'overridden')
)
.map((entry) => (
<PreviewLine
key={`${entry.line}:${entry.name}`}
entry={entry}
replaces={existing.has(entry.name)}
serverError={serverErrors.get(entry.name) ?? null}
/>
))}
</ul>
) : null}
@@ -44,7 +44,7 @@ export function cloudSecretsErrorCopy(
case 'subscription_token_refused':
return t(
'cloudSecrets.error.subscriptionToken',
'This is a Claude or ChatGPT subscription token, which can’t be stored. Sign the agent in instead.'
'This is a Claude or ChatGPT subscription token, which can’t be stored.'
)
case 'value_too_large':
return t('cloudSecrets.error.valueTooLarge', 'Values can be up to 8 KB.')
@@ -77,6 +77,11 @@ const RESERVED_NAMES: ReadonlySet<string> = new Set([
'GITHUB_TOKEN'
])
const RESERVED_PREFIXES = ['LD_', 'DYLD_', 'ORCA_', 'VERCEL_', 'BASH_FUNC_', 'GIT_CONFIG']
const MODEL_NAMES: ReadonlySet<string> = new Set([
'ANTHROPIC_MODEL',
'ANTHROPIC_SMALL_FAST_MODEL',
'OPENAI_MODEL'
])
const BASE_URL_NAMES: ReadonlySet<string> = new Set(['ANTHROPIC_BASE_URL', 'OPENAI_BASE_URL'])
const JWT_SHAPE = /^[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}$/
@@ -116,7 +121,7 @@ export function cloudSecretValueError(name: string, value: string): CloudSecrets
if (BASE_URL_NAMES.has(name) && (!bare || !isPublicHttpsUrl(value))) {
return 'invalid_base_url'
}
if (name.endsWith('_MODEL') && !bare) {
if (MODEL_NAMES.has(name) && !bare) {
return 'invalid_value'
}
return null