From be58dc0f022b007edc444fc44e93298a612df35a Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 12 Nov 2026 23:04:00 -0800 Subject: [PATCH] feat(cloud): SECRETS-EFFECTIVE-SHARED in the agent host panel, missing-secrets ask and secret request card (no Personal in shared workspaces) --- .../cloud-sections/CloudPanelSections.tsx | 19 +-- .../cloud-panel-sections-model.test.ts | 10 +- .../use-cloud-panel-sections.ts | 33 +++-- .../agent-pane/SecretRequestCard.fixture.tsx | 7 +- .../agent-pane/SecretRequestCard.test.tsx | 3 +- .../agent-pane/SecretRequestCard.tsx | 31 ++++- .../agent-pane/SecretRequestCardParts.tsx | 2 +- .../use-secret-request-card.test.tsx | 32 ++++- .../agent-pane/use-secret-request-card.ts | 32 ++++- .../cloud-secrets-ask/CloudSecretsAskForm.tsx | 28 ++-- .../CloudSecretsMissingNotice.tsx | 8 +- .../cloud-secrets-ask-model.test.ts | 8 ++ .../cloud-secrets-ask-model.ts | 25 +++- .../use-cloud-secrets-ask-form.ts | 12 +- .../use-cloud-secrets-ask.ts | 23 +++- .../VmBuildSheet.fixture.tsx | 16 +++ .../vm-build-secrets-fixture-data.tsx | 1 + src/renderer/src/i18n/locales/en.json | 11 +- .../cloud-workspace-secrets-mode.test.tsx | 124 ++++++++++++++++++ .../cloud-workspace-secrets-mode.ts | 24 ++++ 20 files changed, 383 insertions(+), 66 deletions(-) create mode 100644 src/renderer/src/lib/orca-cloud/cloud-workspace-secrets-mode.test.tsx create mode 100644 src/renderer/src/lib/orca-cloud/cloud-workspace-secrets-mode.ts diff --git a/src/renderer/src/components/agent-host-panel/cloud-sections/CloudPanelSections.tsx b/src/renderer/src/components/agent-host-panel/cloud-sections/CloudPanelSections.tsx index 10fd8c637ef..fbeecb8813b 100644 --- a/src/renderer/src/components/agent-host-panel/cloud-sections/CloudPanelSections.tsx +++ b/src/renderer/src/components/agent-host-panel/cloud-sections/CloudPanelSections.tsx @@ -22,7 +22,6 @@ import { type ShadowedKey } from './cloud-panel-sections-model' import { - isGuestInSharedWorkspace, type CloudPanelAddSecret, type CloudPanelSectionsLoad } from './use-cloud-panel-sections' @@ -253,19 +252,11 @@ export function CloudEnvironmentPanelSection({ number={number} title={t('agentHostPanel.section.env', 'Environment')} help={ - data && isGuestInSharedWorkspace(data) - ? `${t('agentHostPanel.help.cloudEnv', 'From Cloud secrets: Repository, then Personal, then Shared.')} ${ - data.sharing?.ownerName - ? t( - 'agentHostPanel.env.guestOwner', - 'In a shared workspace, Personal values come from its owner, {{owner}}, not from you.', - { owner: data.sharing.ownerName } - ) - : t( - 'agentHostPanel.env.guest', - 'In a shared workspace, Personal values come from its owner, not from you.' - ) - }` + data?.withoutPersonal + ? `${t('agentHostPanel.help.cloudEnv', 'From Cloud secrets: Repository, then Personal, then Shared.')} ${t( + 'agentHostPanel.env.sharedNoPersonal', + 'A shared workspace gets nobody’s Personal values, not even its owner’s, so only Repository and Shared apply.' + )}` : t( 'agentHostPanel.help.cloudEnv', 'From Cloud secrets: Repository, then Personal, then Shared.' diff --git a/src/renderer/src/components/agent-host-panel/cloud-sections/cloud-panel-sections-model.test.ts b/src/renderer/src/components/agent-host-panel/cloud-sections/cloud-panel-sections-model.test.ts index b32c87666c4..c45c8ee56db 100644 --- a/src/renderer/src/components/agent-host-panel/cloud-sections/cloud-panel-sections-model.test.ts +++ b/src/renderer/src/components/agent-host-panel/cloud-sections/cloud-panel-sections-model.test.ts @@ -97,7 +97,7 @@ describe('shared workspaces (D13)', () => { ]) }) - it('applies only to a teammate who is not the owner', () => { + it('applies in every shared workspace, the owner’s too (SEC-5), and never in an unshared one', () => { const declared = ['NPM_TOKEN', 'SENTRY_DSN', 'DATABASE_URL'] const base = { effective: values, envVarNames: declared, repoKey: null, asleep: false } expect( @@ -106,8 +106,14 @@ describe('shared workspaces (D13)', () => { sharing: { shared: true, ownerName: 'Ada', isOwner: false } }).missing ).toEqual(['NPM_TOKEN']) + const owner = cloudPanelSectionsData({ + ...base, + sharing: { shared: true, ownerName: null, isOwner: true } + }) + expect(owner.withoutPersonal).toBe(true) + expect(owner.missing).toEqual(['NPM_TOKEN']) expect( - cloudPanelSectionsData({ ...base, sharing: { shared: true, ownerName: null, isOwner: true } }) + cloudPanelSectionsData({ ...base, sharing: { shared: false, ownerName: null, isOwner: true } }) .missing ).toEqual([]) }) diff --git a/src/renderer/src/components/agent-host-panel/cloud-sections/use-cloud-panel-sections.ts b/src/renderer/src/components/agent-host-panel/cloud-sections/use-cloud-panel-sections.ts index 7badd914942..fea009a3f1f 100644 --- a/src/renderer/src/components/agent-host-panel/cloud-sections/use-cloud-panel-sections.ts +++ b/src/renderer/src/components/agent-host-panel/cloud-sections/use-cloud-panel-sections.ts @@ -24,17 +24,12 @@ export type CloudPanelSectionsData = { /** Shared with teammates (D13), and whose workspace it is; null when unknown. */ sharing: CloudWorkspaceSharing | null /** - * The caller's Personal values are left out: a teammate in a shared workspace, or a workspace whose - * sharing couldn't be read (D13 fails closed: it may be someone else's shared workspace). + * Personal values are left out: a shared workspace gets nobody's Personal secrets, not even its + * owner's (SEC-5), and one whose sharing couldn't be read fails closed the same way (D13). */ withoutPersonal: boolean } -/** A teammate's view of someone else's shared workspace: only their non-Personal values apply. */ -export function isGuestInSharedWorkspace(data: Pick): boolean { - return data.sharing !== null && data.sharing.shared && !data.sharing.isOwner -} - export function cloudPanelSectionsData(args: { effective: CloudSecretsEffective envVarNames: readonly string[] | null @@ -44,7 +39,7 @@ export function cloudPanelSectionsData(args: { /** The workspace's sharing read failed; treat it as possibly someone else's shared workspace. */ sharingUnknown?: boolean }): CloudPanelSectionsData { - const withoutPersonal = args.sharingUnknown === true || isGuestInSharedWorkspace(args) + const withoutPersonal = args.sharingUnknown === true || args.sharing?.shared === true const effective = withoutPersonal ? withoutCallerPersonal(args.effective) : args.effective return { withoutPersonal, @@ -88,12 +83,22 @@ export function useCloudPanelSections(args: { } let cancelled = false void (async () => { - const [effective, list, sharing] = await Promise.all([ - secrets.effective(repoKey ? { repo: repoKey } : {}).catch(() => null), - window.api.orcaCloudEnvironments?.list().catch(() => null) ?? Promise.resolve(null), - runtimeEnvironmentId - ? secrets.workspaceSharing({ runtimeEnvironmentId }).catch(() => null) - : Promise.resolve(null) + const listing = + window.api.orcaCloudEnvironments?.list().catch(() => null) ?? Promise.resolve(null) + const sharing = runtimeEnvironmentId + ? await secrets.workspaceSharing({ runtimeEnvironmentId }).catch(() => null) + : null + // SEC-5: a shared workspace (or one whose sharing can't be read) gets no Personal values, so ask + // the control plane for exactly what such a workspace receives. + const shared = runtimeEnvironmentId !== null && !(sharing?.ok && !sharing.value.shared) + const [effective, list] = await Promise.all([ + secrets + .effective({ + ...(repoKey ? { repo: repoKey } : {}), + ...(shared ? { workspace: 'shared' as const } : {}) + }) + .catch(() => null), + listing ]) if (cancelled) { return diff --git a/src/renderer/src/components/agent-pane/SecretRequestCard.fixture.tsx b/src/renderer/src/components/agent-pane/SecretRequestCard.fixture.tsx index e3791d85846..2f0515a629f 100644 --- a/src/renderer/src/components/agent-pane/SecretRequestCard.fixture.tsx +++ b/src/renderer/src/components/agent-pane/SecretRequestCard.fixture.tsx @@ -32,7 +32,8 @@ const BASE: SecretRequestCardModel = { fieldError: null, more: 0, canRestart: true, - collapsed: false + collapsed: false, + sharedWorkspace: false } /** A terminal pane behind the card, as it sits over a Claude session. */ @@ -58,6 +59,10 @@ export const open = frame({ value: 'npm_9f2cA81bX7' }) export const openWithMore = frame({ more: 2 }) export const repoHint = frame({ suggestedRepo: true }) export const personalOnly = frame({ scopes: ['personal'] }) +/** SEC-5: a shared workspace, and the person can write the repository: Repository only. */ +export const sharedRepoOnly = frame({ sharedWorkspace: true, scopes: ['repo'], scope: 'repo' }) +/** SEC-5: a shared workspace, and nothing this person can write reaches it. */ +export const sharedNoScope = frame({ sharedWorkspace: true, scopes: [], scope: 'personal' }) export const unknownAgent = frame({ agent: null, canRestart: false }) export const longReason = frame({ reason: diff --git a/src/renderer/src/components/agent-pane/SecretRequestCard.test.tsx b/src/renderer/src/components/agent-pane/SecretRequestCard.test.tsx index f3fd61efd03..db043990275 100644 --- a/src/renderer/src/components/agent-pane/SecretRequestCard.test.tsx +++ b/src/renderer/src/components/agent-pane/SecretRequestCard.test.tsx @@ -31,7 +31,8 @@ const BASE: SecretRequestCardModel = { fieldError: null, more: 0, canRestart: false, - collapsed: false + collapsed: false, + sharedWorkspace: false } afterEach(cleanup) diff --git a/src/renderer/src/components/agent-pane/SecretRequestCard.tsx b/src/renderer/src/components/agent-pane/SecretRequestCard.tsx index 69f9cbb36ac..27923d79580 100644 --- a/src/renderer/src/components/agent-pane/SecretRequestCard.tsx +++ b/src/renderer/src/components/agent-pane/SecretRequestCard.tsx @@ -34,8 +34,13 @@ export type SecretRequestCardModel = { reason: string | null /** The agent suggested Repository. A hint only: it never preselects (D2). */ suggestedRepo: boolean - /** Personal always; Repository only when the person can write it. Never Shared (D6). */ + /** + * Personal, plus Repository when the person can write it. Never Shared (D6). In a shared workspace + * Personal is left out (SEC-5), so this can be empty: then the card says who can add it instead. + */ scopes: readonly SecretRequestScope[] + /** The workspace is shared with teammates, so it gets no Personal secrets (SEC-5). */ + sharedWorkspace: boolean scope: SecretRequestScope value: string phase: SecretRequestCardPhase @@ -91,7 +96,7 @@ export function SecretRequestCard({ const agentName = model.agent ?? t('secretRequest.anAgent', 'an agent') const done = model.phase === 'saved' || model.phase === 'savedAfterExpiry' const saving = model.phase === 'saving' - const canSave = model.value.length > 0 && !saving + const canSave = model.value.length > 0 && !saving && model.scopes.length > 0 const ownRef = React.useRef(null) const focusedWithin = React.useRef(false) @@ -230,6 +235,21 @@ export function SecretRequestCard({ /> ) : ( <> + {model.scopes.length === 0 ? ( + + ) : (
+ )} {model.phase === 'failed' ? ( - {cloudSecretScopeLabel('personal', t)} + {cloudSecretScopeLabel(scopes[0] ?? 'personal', t)} ) } diff --git a/src/renderer/src/components/agent-pane/use-secret-request-card.test.tsx b/src/renderer/src/components/agent-pane/use-secret-request-card.test.tsx index 8c5f65e586a..136d4543f70 100644 --- a/src/renderer/src/components/agent-pane/use-secret-request-card.test.tsx +++ b/src/renderer/src/components/agent-pane/use-secret-request-card.test.tsx @@ -22,6 +22,7 @@ const NOW = 1_700_000_000_000 const put = vi.fn() const refreshEnv = vi.fn() const effective = vi.fn() +const workspaceSharing = vi.fn() function event(patch: Partial = {}): SecretRequestedEvent { return { @@ -68,12 +69,18 @@ describe('S4-b secret request card', () => { put.mockResolvedValue({ ok: true, value: {} }) refreshEnv.mockResolvedValue({ ok: true, value: true }) effective.mockResolvedValue({ ok: false, error: 'unavailable' }) + workspaceSharing.mockResolvedValue({ + ok: true, + value: { shared: false, ownerName: null, isOwner: true } + }) rpc.mockImplementation(async (_target, method: string) => method === 'secrets.touchRequest' ? { expiresAt: Date.now() + 15 * 60_000 } : { outcome: 'provided' } ) - Object.assign(window, { api: { cloudSecrets: { put, refreshEnv, effective } } }) + Object.assign(window, { + api: { cloudSecrets: { put, refreshEnv, effective, workspaceSharing } } + }) applySecretRequested('env-1', event()) }) afterEach(() => { @@ -93,6 +100,29 @@ describe('S4-b secret request card', () => { expect(screen.getByText(/Commands in this workspace can read it as \$NPM_TOKEN/)).toBeTruthy() }) + it('in a shared workspace never offers Personal (SEC-5): says who can add it instead', async () => { + workspaceSharing.mockResolvedValue({ + ok: true, + value: { shared: true, ownerName: 'Ada', isOwner: false } + }) + render() + await act(async () => {}) + expect(workspaceSharing).toHaveBeenCalledWith({ runtimeEnvironmentId: 'env-1' }) + expect(screen.getByText('This workspace is shared, so it doesn’t get personal secrets.')).toBeTruthy() + expect(screen.queryByLabelText('Value for NPM_TOKEN')).toBeNull() + expect(screen.getByRole('button', { name: 'Add secret' }).getAttribute('aria-disabled')).toBe( + 'true' + ) + expect(put).not.toHaveBeenCalled() + }) + + it('fails closed when the workspace sharing can’t be read', async () => { + workspaceSharing.mockRejectedValue(new Error('down')) + render() + await act(async () => {}) + expect(screen.queryByLabelText('Value for NPM_TOKEN')).toBeNull() + }) + it('saves through Cloud secrets, then tells orcad the outcome without the value', async () => { render() fireEvent.change(valueInput(), { target: { value: 'npm_secret_1' } }) diff --git a/src/renderer/src/components/agent-pane/use-secret-request-card.ts b/src/renderer/src/components/agent-pane/use-secret-request-card.ts index bdd3f3f331e..9c944273351 100644 --- a/src/renderer/src/components/agent-pane/use-secret-request-card.ts +++ b/src/renderer/src/components/agent-pane/use-secret-request-card.ts @@ -27,6 +27,7 @@ import { type SecretsResolveRequestResult, type SecretsTouchRequestResult } from '../../../../shared/secret-request-contract' +import { cloudWorkspaceSecretsMode } from '@/lib/orca-cloud/cloud-workspace-secrets-mode' import type { CloudSecretsErrorCode } from '../../../../shared/cloud-secrets/cloud-secrets-wire' import type { SecretRequestCardActions, @@ -121,6 +122,9 @@ export function useSecretRequestCard(args: { const [fieldError, setFieldError] = useState(null) const [focused, setFocused] = useState(false) const [repoWritable, setRepoWritable] = useState(false) + // SEC-5: a shared workspace gets no Personal secrets, so a Personal save would never reach it. + // Unknown until read: Personal stays offered meanwhile, as before this check existed. + const [sharedWorkspace, setSharedWorkspace] = useState(false) const [collapsed, setCollapsed] = useState(false) const repoKey = useWorkspaceRepoKey(event.worktreeId ?? worktreeId) const openPanel = useAgentHostPanelOpener() @@ -140,6 +144,18 @@ export function useSecretRequestCard(args: { } }, [repoKey]) + useEffect(() => { + let cancelled = false + void cloudWorkspaceSecretsMode(environmentId).then((mode) => { + if (!cancelled) { + setSharedWorkspace(mode === 'shared') + } + }) + return () => { + cancelled = true + } + }, [environmentId]) + // The card's own clock: an open request past its expiry shows as expired and drops what was typed. useEffect(() => { if (local !== null) { @@ -196,12 +212,19 @@ export function useSecretRequestCard(args: { } }, [holding, environmentId, requestId]) - const scopes: SecretRequestScope[] = repoKey && repoWritable ? ['personal', 'repo'] : ['personal'] - const effectiveScope: SecretRequestScope = scopes.includes(scope) ? scope : 'personal' + const repoScope = repoKey !== null && repoWritable + const scopes: SecretRequestScope[] = sharedWorkspace + ? repoScope + ? ['repo'] + : [] + : repoScope + ? ['personal', 'repo'] + : ['personal'] + const effectiveScope: SecretRequestScope = scopes.includes(scope) ? scope : (scopes[0] ?? 'personal') const add = useCallback(async () => { const api = window.api.cloudSecrets - if (!value || local !== null) { + if (!value || local !== null || scopes.length === 0) { return } setFailed(false) @@ -236,7 +259,7 @@ export function useSecretRequestCard(args: { requestId, outcome === 'provided' ? 'saved' : 'savedAfterExpiry' ) - }, [value, local, environmentId, requestId, effectiveScope, repoKey, event.name, t]) + }, [value, local, scopes.length, environmentId, requestId, effectiveScope, repoKey, event.name, t]) const phase: SecretRequestCardPhase = local === 'saving' @@ -258,6 +281,7 @@ export function useSecretRequestCard(args: { suggestedRepo: event.scope === 'repo', scopes, scope: effectiveScope, + sharedWorkspace, // An expired request shows no field, and what was typed doesn't come back. value: local === 'expired' ? '' : value, phase, diff --git a/src/renderer/src/components/cloud-secrets-ask/CloudSecretsAskForm.tsx b/src/renderer/src/components/cloud-secrets-ask/CloudSecretsAskForm.tsx index 9cfb8d665c5..c753ccfaf7e 100644 --- a/src/renderer/src/components/cloud-secrets-ask/CloudSecretsAskForm.tsx +++ b/src/renderer/src/components/cloud-secrets-ask/CloudSecretsAskForm.tsx @@ -25,7 +25,7 @@ import type { import { isTeamAdmin, parseScope, - writableScopes, + askScopes, type CloudSecretsAskData } from './cloud-secrets-ask-model' @@ -130,10 +130,11 @@ export function CloudSecretsAskForm({ const id = React.useId() const headingId = `${id}-heading` const admin = isTeamAdmin(data.caller) - const scopes = writableScopes(data.caller, { repo: data.repoKey !== null, shared: true }) + const scopes = askScopes(data) + const fallbackScope = scopes[0] ?? 'personal' const filled = data.missing.filter((name) => (state.values[name] ?? '').length > 0) const saving = state.phase === 'saving' - const canSave = filled.length > 0 && !saving + const canSave = filled.length > 0 && !saving && scopes.length > 0 if (state.phase === 'skipped') { return ( @@ -275,13 +276,13 @@ export function CloudSecretsAskForm({ onChange={(value) => actions.onValueChange(name, value)} placeholder={t('cloudSecretsAsk.valuePlaceholder', 'Value')} invalid={Boolean(refusal)} - disabled={saving} + disabled={saving || scopes.length === 0} describedBy={refusal ? errorId : undefined} /> - {scopes.length > 1 ? ( + {scopes.length === 0 ? null : scopes.length > 1 ? ( ) : ( - {cloudSecretScopeLabel('personal', t)} + {cloudSecretScopeLabel(fallbackScope, t)} )} {refusal ? ( @@ -337,10 +338,15 @@ export function CloudSecretsAskForm({

{admin ? t('cloudSecrets.editor.help', 'Write-only. You won’t see it again after saving.') - : t( - 'cloudSecretsAsk.memberFooter', - 'Saved to your personal Cloud secrets, so only your workspaces get them. To set them for the whole team, ask an owner or admin.' - )} + : data.shared + ? t( + 'cloudSecretsAsk.sharedMemberFooter', + 'This workspace is shared, so it doesn’t get personal secrets. Ask an owner or admin to add the missing values to this repository or the team.' + ) + : t( + 'cloudSecretsAsk.memberFooter', + 'Saved to your personal Cloud secrets, so only your workspaces get them. To set them for the whole team, ask an owner or admin.' + )}