diff --git a/ui/src/api/instanceSettings.ts b/ui/src/api/instanceSettings.ts index 8ae0b80a4de..8bf1454b0a2 100644 --- a/ui/src/api/instanceSettings.ts +++ b/ui/src/api/instanceSettings.ts @@ -1,5 +1,5 @@ import type { - InstanceExperimentalSettings, + InstanceExperimentalSettingsWithManaged, InstanceGeneralSettings, InstanceSettings, IssueGraphLivenessAutoRecoveryPreview, @@ -19,9 +19,9 @@ export const instanceSettingsApi = { updateGeneral: (patch: PatchInstanceGeneralSettings) => api.patch("/instance/settings/general", patch), getExperimental: () => - api.get("/instance/settings/experimental"), + api.get("/instance/settings/experimental"), updateExperimental: (patch: PatchInstanceExperimentalSettings) => - api.patch("/instance/settings/experimental", patch), + api.patch("/instance/settings/experimental", patch), previewIssueGraphLivenessAutoRecovery: (input: { lookbackHours?: number }) => api.post( "/instance/settings/experimental/issue-graph-liveness-auto-recovery/preview", diff --git a/ui/src/pages/InstanceExperimentalSettings.test.tsx b/ui/src/pages/InstanceExperimentalSettings.test.tsx index 007afd3e61e..8000faa0fc7 100644 --- a/ui/src/pages/InstanceExperimentalSettings.test.tsx +++ b/ui/src/pages/InstanceExperimentalSettings.test.tsx @@ -5,10 +5,12 @@ import { createRoot, type Root } from "react-dom/client"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import type { InstanceExperimentalSettings as InstanceExperimentalSettingsPayload, + InstanceExperimentalSettingsWithManaged, IssueGraphLivenessAutoRecoveryPreview, } from "@paperclipai/shared"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { InstanceExperimentalSettings } from "./InstanceExperimentalSettings"; +import { queryKeys } from "../lib/queryKeys"; const mockInstanceSettingsApi = vi.hoisted(() => ({ getExperimental: vi.fn(), @@ -567,3 +569,139 @@ describe("InstanceExperimentalSettings — Conference Room Chat card (PAP-11233) expect(enabledToggle?.getAttribute("aria-checked")).toBe("true"); }); }); + +describe("InstanceExperimentalSettings — cloud-managed keys", () => { + const MANAGED_BADGE_TEXT = "Managed by Paperclip Cloud"; + + let container: HTMLDivElement; + let root: Root | null = null; + let queryClient: QueryClient; + + async function renderPage(settings: InstanceExperimentalSettingsWithManaged) { + mockInstanceSettingsApi.getExperimental.mockResolvedValue({ ...settings }); + root = createRoot(container); + queryClient = new QueryClient({ + defaultOptions: { queries: { retry: false } }, + }); + flushSync(() => { + root!.render( + + + , + ); + }); + await flushReact(); + } + + beforeEach(() => { + container = document.createElement("div"); + document.body.appendChild(container); + mockInstanceSettingsApi.updateExperimental.mockImplementation(async (patch) => ({ + ...defaultExperimentalSettings(), + ...patch, + })); + }); + + afterEach(() => { + flushSync(() => { + root?.unmount(); + }); + root = null; + container.remove(); + vi.clearAllMocks(); + }); + + it("renders a managed key locked with the badge while unmanaged keys stay editable", async () => { + await renderPage({ + ...defaultExperimentalSettings(), + enableApps: true, + managedKeys: { + enableApps: { managed: true, managedBy: "paperclip-cloud" }, + }, + }); + + expect(container.textContent).toContain(MANAGED_BADGE_TEXT); + + const appsToggle = container.querySelector(APPS_TOGGLE_SELECTOR); + expect(appsToggle?.getAttribute("aria-checked")).toBe("true"); + expect(appsToggle?.disabled).toBe(true); + + await act(() => appsToggle?.click()); + await flushReact(); + expect(mockInstanceSettingsApi.updateExperimental).not.toHaveBeenCalled(); + + const summariesToggle = container.querySelector(SUMMARIES_TOGGLE_SELECTOR); + expect(summariesToggle?.disabled).toBe(false); + + await act(() => summariesToggle?.click()); + await flushReact(); + expect(mockInstanceSettingsApi.updateExperimental).toHaveBeenCalledWith({ + enableSummaries: true, + }); + }); + + it("locks the managed auto-recovery toggle without opening the preview dialog", async () => { + await renderPage({ + ...defaultExperimentalSettings(), + managedKeys: { + enableIssueGraphLivenessAutoRecovery: { managed: true, managedBy: "paperclip-cloud" }, + }, + }); + + const toggle = container.querySelector(AUTO_RECOVERY_TOGGLE_SELECTOR); + expect(toggle?.disabled).toBe(true); + + await act(() => toggle?.click()); + await flushReact(); + + expect(mockInstanceSettingsApi.previewIssueGraphLivenessAutoRecovery).not.toHaveBeenCalled(); + expect(mockInstanceSettingsApi.updateExperimental).not.toHaveBeenCalled(); + expect(document.body.textContent).not.toContain("Confirm auto-recovery"); + }); + + it("closes an open recovery preview when a refresh marks auto-recovery as managed", async () => { + mockInstanceSettingsApi.previewIssueGraphLivenessAutoRecovery.mockResolvedValue( + emptyRecoveryPreview(), + ); + const settings = defaultExperimentalSettings(); + await renderPage(settings); + + const toggle = container.querySelector(AUTO_RECOVERY_TOGGLE_SELECTOR); + await act(() => toggle?.click()); + await flushReact(); + expect(document.body.textContent).toContain("Confirm auto-recovery"); + + const managedSettings: InstanceExperimentalSettingsWithManaged = { + ...settings, + enableIssueGraphLivenessAutoRecovery: true, + managedKeys: { + enableIssueGraphLivenessAutoRecovery: { managed: true, managedBy: "paperclip-cloud" }, + }, + }; + await act(() => { + queryClient.setQueryData(queryKeys.instance.experimentalSettings, managedSettings); + }); + await flushReact(); + + expect(document.body.textContent).not.toContain("Confirm auto-recovery"); + expect(document.body.querySelector('[data-slot="dialog-overlay"]')).toBeNull(); + expect(mockInstanceSettingsApi.updateExperimental).not.toHaveBeenCalled(); + expect(mockInstanceSettingsApi.runIssueGraphLivenessAutoRecovery).not.toHaveBeenCalled(); + + const lockedToggle = container.querySelector(AUTO_RECOVERY_TOGGLE_SELECTOR); + expect(lockedToggle?.disabled).toBe(true); + }); + + it("renders no managed badge and keeps toggles editable without managedKeys (self-hosted)", async () => { + await renderPage(defaultExperimentalSettings()); + + expect(container.textContent).not.toContain(MANAGED_BADGE_TEXT); + + const appsToggle = container.querySelector(APPS_TOGGLE_SELECTOR); + expect(appsToggle?.disabled).toBe(false); + + await act(() => appsToggle?.click()); + await flushReact(); + expect(mockInstanceSettingsApi.updateExperimental).toHaveBeenCalledWith({ enableApps: true }); + }); +}); diff --git a/ui/src/pages/InstanceExperimentalSettings.tsx b/ui/src/pages/InstanceExperimentalSettings.tsx index 695a5d70f89..b6c4201c473 100644 --- a/ui/src/pages/InstanceExperimentalSettings.tsx +++ b/ui/src/pages/InstanceExperimentalSettings.tsx @@ -1,9 +1,11 @@ import { useEffect, useState } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { AlertTriangle, Clock, FlaskConical, Play, Search } from "lucide-react"; +import { AlertTriangle, Clock, FlaskConical, Lock, Play, Search } from "lucide-react"; import type { InstanceExperimentalSettings, + InstanceExperimentalSettingsWithManaged, IssueGraphLivenessAutoRecoveryPreview, + ManagedSettingMetadata, PatchInstanceExperimentalSettings, } from "@paperclipai/shared"; import { instanceSettingsApi } from "@/api/instanceSettings"; @@ -74,6 +76,63 @@ function formatActivationTimestamp(iso: string): string { // PAP-11233: keep Conference Room code intact, but hide the user-facing opt-in for now. const SHOW_CONFERENCE_ROOM_EXPERIMENTAL_SETTING = false; +function ManagedByCloudBadge() { + return ( + + + ); +} + +function ExperimentalToggleCard({ + title, + experimental = false, + description, + footnote, + checked, + onCheckedChange, + disabled, + managed, + ariaLabel, +}: { + title: string; + experimental?: boolean; + description: string; + footnote?: string; + checked: boolean; + onCheckedChange: (checked: boolean) => void; + disabled: boolean; + managed?: ManagedSettingMetadata; + ariaLabel: string; +}) { + const isManaged = managed?.managed === true; + return ( + +
+
+
+

{title}

+ {experimental ? Experimental : null} + {isManaged ? : null} +
+

{description}

+ {footnote ?

{footnote}

: null} +
+ { + if (isManaged) return; + onCheckedChange(next); + }} + disabled={disabled || isManaged} + aria-label={ariaLabel} + /> +
+
+ ); +} + function RecoveryPreviewDialog({ preview, open, @@ -189,20 +248,20 @@ export function InstanceExperimentalSettings() { }); const toggleMutation = useMutation< - InstanceExperimentalSettings, + InstanceExperimentalSettingsWithManaged, Error, PatchInstanceExperimentalSettings, - { previousSettings?: InstanceExperimentalSettings } + { previousSettings?: InstanceExperimentalSettingsWithManaged } >({ mutationFn: async (patch: PatchInstanceExperimentalSettings) => instanceSettingsApi.updateExperimental(patch), onMutate: async (patch) => { await queryClient.cancelQueries({ queryKey: queryKeys.instance.experimentalSettings }); - const previousSettings = queryClient.getQueryData( + const previousSettings = queryClient.getQueryData( queryKeys.instance.experimentalSettings, ); if (previousSettings) { - queryClient.setQueryData( + queryClient.setQueryData( queryKeys.instance.experimentalSettings, { ...previousSettings, ...patch }, ); @@ -262,6 +321,17 @@ export function InstanceExperimentalSettings() { } }, [experimentalQuery.data?.issueGraphLivenessAutoRecoveryLookbackHours]); + const autoRecoveryManaged = + experimentalQuery.data?.managedKeys?.enableIssueGraphLivenessAutoRecovery?.managed === true; + + // If refreshed settings mark auto-recovery as managed while the preview + // dialog is open, close it so its confirmation actions cannot emit a PATCH. + useEffect(() => { + if (autoRecoveryManaged) { + closeRecoveryPreview(); + } + }, [autoRecoveryManaged]); + if (experimentalQuery.isLoading) { return
Loading experimental settings...
; } @@ -277,7 +347,12 @@ export function InstanceExperimentalSettings() { } const inWorktree = isWorktreeRuntime(); + // Present only on cloud-managed instances: keys the managed overlay controls + // render locked with the "Managed by Paperclip Cloud" badge. Self-hosted + // responses carry no `managedKeys`, so every card stays editable. + const managedKeys = experimentalQuery.data?.managedKeys ?? {}; const enableWorktreeRunExecution = experimentalQuery.data?.enableWorktreeRunExecution === true; + const worktreeRunExecutionManaged = managedKeys.enableWorktreeRunExecution?.managed === true; const worktreeRunExecutionState = resolveWorktreeRunExecutionDisplayState( experimentalQuery.data, getWorktreeInstanceId(), @@ -314,6 +389,7 @@ export function InstanceExperimentalSettings() { toggleMutation.isPending || previewMutation.isPending || runRecoveryMutation.isPending; function previewForEnable() { + if (autoRecoveryManaged) return; if (!lookbackHoursIsValid) { setActionError("Lookback hours must be a whole number from 1 to 720."); return; @@ -323,6 +399,7 @@ export function InstanceExperimentalSettings() { } function enableOnly() { + if (autoRecoveryManaged) return; if (!lookbackHoursIsValid) return; closeRecoveryPreview(); toggleMutation.mutate({ @@ -332,6 +409,7 @@ export function InstanceExperimentalSettings() { } function enableAndRun() { + if (autoRecoveryManaged) return; if (!lookbackHoursIsValid) return; closeRecoveryPreview(); toggleMutation.mutate({ @@ -381,7 +459,10 @@ export function InstanceExperimentalSettings() {
-

Run tasks in this worktree

+
+

Run tasks in this worktree

+ {worktreeRunExecutionManaged ? : null} +

This is an isolated git-worktree preview instance. Turn this on to let the scheduler execute runs here. Only tasks created after enabling will run automatically — copied/pre-existing tasks stay @@ -390,10 +471,11 @@ export function InstanceExperimentalSettings() {

- toggleMutation.mutate({ enableWorktreeRunExecution: checked }) - } - disabled={toggleMutation.isPending} + onCheckedChange={(checked) => { + if (worktreeRunExecutionManaged) return; + toggleMutation.mutate({ enableWorktreeRunExecution: checked }); + }} + disabled={toggleMutation.isPending || worktreeRunExecutionManaged} aria-label="Toggle worktree run execution setting" />
@@ -429,346 +511,189 @@ export function InstanceExperimentalSettings() { ) : null} - -
-
-
-

Apps

- Experimental -
-

- Show the Apps navigation and allow access to app connections, gateways, and advanced app tooling. -

-
- toggleMutation.mutate({ enableApps: !enableApps })} - disabled={toggleMutation.isPending} - aria-label="Toggle apps experimental setting" - /> -
-
+ toggleMutation.mutate({ enableApps: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableApps} + ariaLabel="Toggle apps experimental setting" + /> - -
-
-
-

Cases

- Experimental -
-

- Durable work products (blog posts, tweet storms…) that tasks create and iterate on. Adds the - Cases tab and the agent case API. -

-

- Turning Cases off hides the tab and blocks the case API; existing case data is kept. -

-
- toggleMutation.mutate({ enableCases: !enableCases })} - disabled={toggleMutation.isPending} - aria-label="Toggle cases experimental setting" - /> -
-
+ toggleMutation.mutate({ enableCases: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableCases} + ariaLabel="Toggle cases experimental setting" + /> - -
-
-

Enable Environments

-

- Show environment management in company settings and allow project and agent environment assignment - controls. -

-
- toggleMutation.mutate({ enableEnvironments: !enableEnvironments })} - disabled={toggleMutation.isPending} - aria-label="Toggle environments experimental setting" - /> -
-
+ toggleMutation.mutate({ enableEnvironments: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableEnvironments} + ariaLabel="Toggle environments experimental setting" + /> - -
-
-

Built-in Agents

-

- Show Paperclip-managed built-in agent surfaces, including built-in roster badges, the Built-in agents - tab, and built-in agent setup controls. -

-
- toggleMutation.mutate({ enableBuiltInAgents: !enableBuiltInAgents })} - disabled={toggleMutation.isPending} - aria-label="Toggle built-in agents experimental setting" - /> -
-
+ toggleMutation.mutate({ enableBuiltInAgents: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableBuiltInAgents} + ariaLabel="Toggle built-in agents experimental setting" + /> - -
-
-

Summaries

-

- Show Summarizer-generated status slots on project and workspace pages, with on-demand refresh and - revision history. Existing summary data is kept when this is disabled. -

-
- toggleMutation.mutate({ enableSummaries: !enableSummaries })} - disabled={toggleMutation.isPending} - aria-label="Toggle summaries experimental setting" - /> -
-
+ toggleMutation.mutate({ enableSummaries: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableSummaries} + ariaLabel="Toggle summaries experimental setting" + /> - -
-
-

Experimental File Viewer

-

- Show task detail controls for browsing and previewing workspace files relative to a task. -

-
- - toggleMutation.mutate({ - enableExperimentalFileViewer: !enableExperimentalFileViewer, - }) - } - disabled={toggleMutation.isPending} - aria-label="Toggle experimental file viewer setting" - /> -
-
+ toggleMutation.mutate({ enableExperimentalFileViewer: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableExperimentalFileViewer} + ariaLabel="Toggle experimental file viewer setting" + /> - -
-
-

Enable External Objects

-

- Detect external URLs in issues and show resolved status for pull requests, tickets, and other referenced - work objects. -

-
- toggleMutation.mutate({ enableExternalObjects: !enableExternalObjects })} - disabled={toggleMutation.isPending} - aria-label="Toggle external objects experimental setting" - /> -
-
+ toggleMutation.mutate({ enableExternalObjects: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableExternalObjects} + ariaLabel="Toggle external objects experimental setting" + /> - -
-
-

Decisions

-

- Show the Decisions item in the main sidebar — the attention home that surfaces the tasks awaiting your - input — while the surface is still being evaluated. -

-
- toggleMutation.mutate({ enableDecisions: !enableDecisions })} - disabled={toggleMutation.isPending} - aria-label="Toggle decisions experimental setting" - /> -
-
+ toggleMutation.mutate({ enableDecisions: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableDecisions} + ariaLabel="Toggle decisions experimental setting" + /> - -
-
-

Goals Sidebar Link

-

- Restore the Goals item in the main sidebar while the goals surface is being evaluated. -

-
- toggleMutation.mutate({ enableGoalsSidebarLink: !enableGoalsSidebarLink })} - disabled={toggleMutation.isPending} - aria-label="Toggle goals sidebar link experimental setting" - /> -
-
+ toggleMutation.mutate({ enableGoalsSidebarLink: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableGoalsSidebarLink} + ariaLabel="Toggle goals sidebar link experimental setting" + /> - -
-
-

Enable Isolated Workspaces

-

- Show execution workspace controls in project configuration and allow isolated workspace behavior for new - and existing task runs. -

-
- toggleMutation.mutate({ enableIsolatedWorkspaces: !enableIsolatedWorkspaces })} - disabled={toggleMutation.isPending} - aria-label="Toggle isolated workspaces experimental setting" - /> -
-
+ toggleMutation.mutate({ enableIsolatedWorkspaces: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableIsolatedWorkspaces} + ariaLabel="Toggle isolated workspaces experimental setting" + /> {SHOW_CONFERENCE_ROOM_EXPERIMENTAL_SETTING ? ( - -
-
-

Conference Room Chat

-

- Adds a Conference Room — one chat where you and your whole team work together — plus the live activity - feed and the redesigned onboarding. Also restyles task threads as chat bubbles. Turn off anytime to - restore the classic UI. -

-
- - toggleMutation.mutate({ - enableConferenceRoomChat: !enableConferenceRoomChat, - }) - } - disabled={toggleMutation.isPending} - aria-label="Toggle conference room chat experimental setting" - /> -
-
+ toggleMutation.mutate({ enableConferenceRoomChat: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableConferenceRoomChat} + ariaLabel="Toggle conference room chat experimental setting" + /> ) : null} - -
-
-

Task Plan Decomposition Panel

-

- Show accepted-plan decomposition history on task detail pages. Intended for debugging and validating - subtask creation behavior while the presentation is still being refined. -

-
- - toggleMutation.mutate({ - enableIssuePlanDecompositions: !enableIssuePlanDecompositions, - }) - } - disabled={toggleMutation.isPending} - aria-label="Toggle task plan decomposition panel experimental setting" - /> -
-
+ toggleMutation.mutate({ enableIssuePlanDecompositions: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableIssuePlanDecompositions} + ariaLabel="Toggle task plan decomposition panel experimental setting" + /> - -
-
-

Task Watchdogs

-

- Show task detail controls for configuring watchdog agents that verify stopped task subtrees and restore - live paths when work should continue. -

-
- - toggleMutation.mutate({ - enableTaskWatchdogs: checked, - }) - } - disabled={toggleMutation.isPending} - aria-label="Toggle task watchdogs experimental setting" - /> -
-
+ toggleMutation.mutate({ enableTaskWatchdogs: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableTaskWatchdogs} + ariaLabel="Toggle task watchdogs experimental setting" + /> - -
-
-

Cloud Sync

-

- Show local Paperclip Cloud upstream connection, preview, push, retry, and activation review surfaces. - Saved connections and run history are preserved when this is disabled. -

-
- toggleMutation.mutate({ enableCloudSync: !enableCloudSync })} - disabled={toggleMutation.isPending} - aria-label="Toggle cloud sync experimental setting" - /> -
-
+ toggleMutation.mutate({ enableCloudSync: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableCloudSync} + ariaLabel="Toggle cloud sync experimental setting" + /> - -
-
-

Server Info Debug View

-

- Show a "Server" section in the account drawer with the current server restart time and running commit. -

-
- - toggleMutation.mutate({ - enableServerInfoDebugView: !enableServerInfoDebugView, - }) - } - disabled={toggleMutation.isPending} - aria-label="Toggle server info debug view experimental setting" - /> -
-
+ toggleMutation.mutate({ enableServerInfoDebugView: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableServerInfoDebugView} + ariaLabel="Toggle server info debug view experimental setting" + /> - -
-
-

Smoke Lab

-

- Add a "Smoke Lab" tab under Apps → Developer and an "Integration smoke" card on the - dashboard for exercising every integration path against deterministic local fixtures - (fake OAuth provider + loopback MCP servers). Private (non-public) deployments only. -

-
- toggleMutation.mutate({ enableSmokeLab: !enableSmokeLab })} - disabled={toggleMutation.isPending} - aria-label="Toggle smoke lab experimental setting" - /> -
-
+ toggleMutation.mutate({ enableSmokeLab: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.enableSmokeLab} + ariaLabel="Toggle smoke lab experimental setting" + /> - -
-
-

Auto-Restart Dev Server When Idle

-

- In `pnpm dev:once`, wait for all queued and running local agent runs to finish, then restart the server - automatically when backend changes or migrations make the current boot stale. -

-
- toggleMutation.mutate({ autoRestartDevServerWhenIdle: !autoRestartDevServerWhenIdle })} - disabled={toggleMutation.isPending} - aria-label="Toggle guarded dev-server auto-restart" - /> -
-
+ toggleMutation.mutate({ autoRestartDevServerWhenIdle: checked })} + disabled={toggleMutation.isPending} + managed={managedKeys.autoRestartDevServerWhenIdle} + ariaLabel="Toggle guarded dev-server auto-restart" + />
-

Auto-Create Recovery Tasks

+
+

Auto-Create Recovery Tasks

+ {autoRecoveryManaged ? : null} +

Let the heartbeat scheduler create recovery tasks for task dependency chains found inside the configured lookback window. @@ -777,13 +702,14 @@ export function InstanceExperimentalSettings() { { + if (autoRecoveryManaged) return; if (enableIssueGraphLivenessAutoRecovery) { toggleMutation.mutate({ enableIssueGraphLivenessAutoRecovery: false }); return; } previewForEnable(); }} - disabled={recoveryActionPending} + disabled={recoveryActionPending || autoRecoveryManaged} aria-label="Toggle task graph liveness auto-recovery" />

@@ -850,7 +776,7 @@ export function InstanceExperimentalSettings() {
- {previewDialogOpen ? ( + {previewDialogOpen && !autoRecoveryManaged ? ( {