diff --git a/src/renderer/src/components/agent-pane/SecretRequestCard.fixture.tsx b/src/renderer/src/components/agent-pane/SecretRequestCard.fixture.tsx
index 35921fa5d0c..4b188d7cc56 100644
--- a/src/renderer/src/components/agent-pane/SecretRequestCard.fixture.tsx
+++ b/src/renderer/src/components/agent-pane/SecretRequestCard.fixture.tsx
@@ -14,7 +14,9 @@ const ACTIONS: SecretRequestCardActions = {
onNotNow: noop,
onRetry: noop,
onRestart: noop,
- onDismiss: noop
+ onDismiss: noop,
+ onToggleCollapsed: noop,
+ onDetails: noop
}
const BASE: SecretRequestCardModel = {
@@ -28,7 +30,8 @@ const BASE: SecretRequestCardModel = {
phase: 'open',
fieldError: null,
more: 0,
- canRestart: true
+ canRestart: true,
+ collapsed: false
}
/** A terminal pane behind the card, as it sits over a Claude session. */
@@ -69,3 +72,5 @@ export const saved = frame({ phase: 'saved' })
export const savedRepo = frame({ phase: 'saved', scope: 'repo' })
export const savedAfterExpiry = frame({ phase: 'savedAfterExpiry' })
export const expired = frame({ phase: 'expired' })
+export const collapsed = frame({ collapsed: true, more: 1 })
+export const notOnAskingPane = frame({ phase: 'saved', canRestart: false })
diff --git a/src/renderer/src/components/agent-pane/SecretRequestCard.tsx b/src/renderer/src/components/agent-pane/SecretRequestCard.tsx
index 625fc1bc97f..c796da92242 100644
--- a/src/renderer/src/components/agent-pane/SecretRequestCard.tsx
+++ b/src/renderer/src/components/agent-pane/SecretRequestCard.tsx
@@ -1,20 +1,20 @@
import React from 'react'
-import { CircleCheck, KeyRound, Loader2, RotateCw } from 'lucide-react'
-import { useTranslate, type Translate } from '@/i18n/use-translate'
+import { ChevronDown, ChevronUp, KeyRound, Loader2 } from 'lucide-react'
+import { useTranslate } from '@/i18n/use-translate'
import { Button } from '@/components/ui/button'
import { InlineError } from '@/components/ui/inline-error'
import { Label } from '@/components/ui/label'
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue
-} from '@/components/ui/select'
import { SecretValueInput } from '@/components/settings/cloud-secrets/SecretValueInput'
-import { cloudSecretScopeLabel } from '@/components/settings/cloud-secrets/cloud-secrets-copy'
import { cn } from '@/lib/utils'
import type { SecretRequestScope } from '../../../../shared/secret-request-contract'
+import {
+ SecretRequestDone,
+ SecretRequestScopeControl,
+ SecretRequestTitle,
+ UntrustedReason
+} from './SecretRequestCardParts'
+
+export { secretRequestTitle } from './SecretRequestCardParts'
export type SecretRequestCardPhase =
| 'open'
@@ -22,6 +22,7 @@ export type SecretRequestCardPhase =
/** The save didn't reach Orca Cloud; nothing changed. */
| 'failed'
| 'saved'
+ /** Saved, but the agent wasn't told: the request expired first, or orcad didn't answer (D3). */
| 'savedAfterExpiry'
| 'expired'
@@ -42,8 +43,10 @@ export type SecretRequestCardModel = {
fieldError: string | null
/** Other requests waiting on this pane. */
more: number
- /** Restart is offered where Orca can restart that agent in the pane. */
+ /** Restart is offered only on the asking agent's own pane. */
canRestart: boolean
+ /** Folded to one line so the output under it can be read, without declining. */
+ collapsed: boolean
}
export type SecretRequestCardActions = {
@@ -54,85 +57,27 @@ export type SecretRequestCardActions = {
onRetry: () => void
onRestart: () => void
onDismiss: () => void
+ onToggleCollapsed: () => void
+ /** Opens the Agent accounts & secrets panel on this name; absent until the panel exists. */
+ onDetails?: () => void
/** Focus entered or left the card (the desktop keeps the request alive while it has focus). */
onFocusChange?: (focused: boolean) => void
}
-const NAME_SLOT = '\u0000'
-
-/** The translated title with the variable name set in monospace. */
-function titleFor(agent: string | null, name: string, t: Translate): React.ReactNode {
- const text = agent
- ? t('secretRequest.title', '{{agent}} asked for {{name}}', { agent, name: NAME_SLOT })
- : t('secretRequest.titleUnknown', 'An agent asked for {{name}}', { name: NAME_SLOT })
- return text.split(NAME_SLOT).map((part, index) => (
-
- {index > 0 ? {name} : null}
- {part}
-
- ))
-}
-
-/** Title text for aria-label and announcements. */
-export function secretRequestTitle(agent: string | null, name: string, t: Translate): string {
- return agent
- ? t('secretRequest.title', '{{agent}} asked for {{name}}', { agent, name })
- : t('secretRequest.titleUnknown', 'An agent asked for {{name}}', { name })
-}
-
-/** Plain text clamped to two lines, with Show more when it overflows. Never linkified. */
-function UntrustedReason({ reason, from }: { reason: string; from: string }): React.JSX.Element {
- const t = useTranslate()
- const ref = React.useRef
(null)
- const [expanded, setExpanded] = React.useState(false)
- const [overflows, setOverflows] = React.useState(false)
- React.useLayoutEffect(() => {
- const element = ref.current
- if (element && !expanded) {
- setOverflows(element.scrollHeight > element.clientHeight + 1)
- }
- }, [reason, expanded])
- return (
-
-
-
- {`“${reason}”`}
-
-
-
- {from}
- {overflows || expanded ? (
-
- ) : null}
-
-
- )
-}
-
/**
* S4-b: an agent in an Orca Cloud workspace asked for a secret. The value goes from this card to
* Orca Cloud only; the agent is told it's ready and never gets it from Orca. Non-modal: it never takes
- * focus from the terminal.
+ * focus from the terminal (F6 moves focus in and back out).
*/
export function SecretRequestCard({
model,
actions,
- inputRef,
+ rootRef,
className
}: {
model: SecretRequestCardModel
actions: SecretRequestCardActions
- /** Lets F6 move focus into the card. */
- inputRef?: React.Ref
+ rootRef?: React.Ref
className?: string
}): React.JSX.Element {
const t = useTranslate()
@@ -144,107 +89,125 @@ export function SecretRequestCard({
const done = model.phase === 'saved' || model.phase === 'savedAfterExpiry'
const saving = model.phase === 'saving'
const canSave = model.value.length > 0 && !saving
+ const ownRef = React.useRef(null)
+ const focusedWithin = React.useRef(false)
- const onKeyDown = (event: React.KeyboardEvent): void => {
- if (event.key === 'Escape' && !done && model.phase !== 'expired') {
- event.stopPropagation()
- actions.onNotNow()
+ // When the form gives way to the result, focus that was in it lands on the result's first action
+ // instead of falling to the page.
+ React.useLayoutEffect(() => {
+ const root = ownRef.current
+ if (done && focusedWithin.current && root && !root.contains(document.activeElement)) {
+ root.querySelector('button')?.focus()
+ }
+ }, [done])
+
+ const setRefs = (node: HTMLDivElement | null): void => {
+ ownRef.current = node
+ if (typeof rootRef === 'function') {
+ rootRef(node)
+ } else if (rootRef) {
+ rootRef.current = node
}
}
+ const header = (
+
+
+
+
+
+
+ {model.more > 0 ? (
+
+ {t('secretRequest.more', '{{count}} more requests', {
+ count: model.more,
+ defaultValue_one: '{{count}} more request'
+ })}
+
+ ) : null}
+
+
+
+ )
+
return (
actions.onFocusChange?.(true)}
- onBlur={(event) => {
- if (!event.currentTarget.contains(event.relatedTarget)) {
- actions.onFocusChange?.(false)
+ onKeyDown={(event) => {
+ if (event.key === 'Escape' && !done && !saving && model.phase !== 'expired') {
+ event.stopPropagation()
+ actions.onNotNow()
}
}}
+ onFocus={() => {
+ focusedWithin.current = true
+ actions.onFocusChange?.(true)
+ }}
+ onBlur={(event) => {
+ const root = event.currentTarget
+ if (root.contains(event.relatedTarget)) {
+ return
+ }
+ // A control that unmounts (Add → result) blurs with nowhere to go; that isn't leaving.
+ window.setTimeout(() => {
+ if (!root.isConnected || root.contains(document.activeElement)) {
+ return
+ }
+ if (document.activeElement === document.body) {
+ return
+ }
+ focusedWithin.current = false
+ actions.onFocusChange?.(false)
+ }, 0)
+ }}
className={cn(
- 'flex w-full flex-col gap-3 rounded-lg border border-border bg-popover p-4 font-sans text-sm text-popover-foreground shadow-lg motion-safe:animate-in motion-safe:fade-in-0',
+ 'flex w-full flex-col gap-3 rounded-lg border border-border bg-popover font-sans text-sm text-popover-foreground shadow-lg motion-safe:animate-in motion-safe:fade-in-0',
+ model.collapsed ? 'px-3 py-2' : 'p-4',
className
)}
>
{done ? (
-
-
-
-
- {model.phase === 'savedAfterExpiry'
- ? t(
- 'secretRequest.savedAfterExpiry',
- 'Saved. {{agent}} stopped waiting, so tell it the secret is ready.',
- { agent: model.agent ?? t('secretRequest.theAgent', 'The agent') }
- )
- : model.scope === 'repo'
- ? t('secretRequest.doneRepo', '{{name}} added to this repository’s secrets.', {
- name: model.name
- })
- : t('secretRequest.done', '{{name}} added to your personal secrets.', {
- name: model.name
- })}
-
-
- {model.phase === 'saved'
- ? t(
- 'secretRequest.doneDetail',
- 'New shells get it now. {{agent}} was told it’s ready, and it never gets the value from Orca.',
- { agent: model.agent ?? t('secretRequest.theAgent', 'The agent') }
- )
- : t('secretRequest.doneDetailExpired', 'New shells get it now.')}{' '}
- {model.canRestart
- ? t(
- 'secretRequest.restartDetail',
- 'Restart {{agent}} to give its own shell the new value.',
- { agent: agentName }
- )
- : null}
-
-
-
- {model.canRestart ? (
-
- ) : null}
-
-
-
+
+ ) : model.collapsed ? (
+ header
) : (
<>
-
-
-
-
-
- {titleFor(model.agent, model.name, t)}
-
- {model.more > 0 ? (
-
- {t('secretRequest.more', '{{count}} more requests', {
- count: model.more,
- defaultValue_one: '{{count}} more request'
- })}
-
- ) : null}
-
- {model.reason ? (
-
- ) : null}
+ {header}
+ {model.reason ? (
+
+
-
-
+ ) : null}
{model.phase === 'expired' ? (
) : (
<>
-
+
@@ -284,36 +247,13 @@ export function SecretRequestCard({
describedBy={model.fieldError ? `${errorId} ${helpId}` : helpId}
/>
- {model.scopes.length > 1 ? (
-
- ) : (
-
- {cloudSecretScopeLabel('personal', t)}
-
- )}
+
{model.fieldError ? (
@@ -344,8 +284,20 @@ export function SecretRequestCard({
density="compact"
/>
) : null}
-
-