mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-18 15:39:47 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - An instance can turn on the `enableManagedSandboxOnly` feature, which hides the local environment and runs every agent in the platform-managed environment > - That feature already gated the environment pickers, the onboarding wizard, and the server-side run selection, but many other screens still showed absolute paths on the execution host and still let the user pick an execution engine > - On such an instance those controls name a filesystem the user cannot reach; a path written there is stored and then ignored, which reads as a broken control > - This pull request hides the remaining host-path and execution-engine surfaces behind the same feature, adds a server rule that refuses a project-workspace path write while the feature is on, and closes a related route gap in the isolated-workspace pages > - The benefit is that a managed instance shows no host path and no folder picker anywhere, and a write that carries a path now fails with a clear message instead of being silently discarded ## Linked Issues or Issue Description No public issue exists. The description below follows `.github/ISSUE_TEMPLATE/enhancement.yml`. **What existing behavior does this improve?** The `enableManagedSandboxOnly` instance feature, and the UI surfaces that show a host filesystem path: project properties, the new-project dialog, the project workspace and execution workspace detail pages, the workspace and task cards, plugin local folders, and the agent configuration form with its per-adapter fields. It also improves route gating for `enableIsolatedWorkspaces`. **Subsystem affected** Cross-cutting (`ui/` and `server/`). **Current behavior** When `enableManagedSandboxOnly` is on, the local environment disappears from the environment pickers and the server refuses to run an agent on the local host. Everything else stays visible. A user still sees: - the project "Local folder" row, its absolute path, and the Set/Change/Clear buttons - the "Local folder" field and its "Choose" folder picker in the new-project dialog - the "Local path" field and fact row on a project workspace - the "Paths" and "Lifecycle commands" groups on an execution workspace - the working directory on workspace cards, task properties, and runtime service rows - the plugin "Local folders" section - "Working directory (deprecated)", "Command", "Execution engine", "ACP server command", "ACP state directory", and "Agent instructions file" in the agent configuration form A path typed into any of these names a filesystem no agent on the instance uses. The project workspace API also accepts a `cwd` write and stores it. Separately, `/workspaces`, `/execution-workspaces/*`, and `/projects/:projectId/workspaces/:workspaceId` render for anyone who types or bookmarks the URL, even with `enableIsolatedWorkspaces` off. Only the sidebar entry reads that flag. **Proposed behavior** With `enableManagedSandboxOnly` on, none of those surfaces render. A project whose codebase came from a managed checkout keeps its one-line "Paperclip-managed folder." label and shows no path. The non-path controls stay: repo URL, branch, service URL, port, command output, ACP session mode, ACP non-interactive permissions, Codex fast mode, and the sandbox toggles. The project-workspace create and patch routes, and the nested workspace on project create, answer `422` with "This instance runs agents only in the platform-managed environment; local folders are not configurable." when the payload carries a non-null `cwd`. A `cwd: null` write still passes, so an instance that just turned the feature on can clear a stale path. With `enableIsolatedWorkspaces` off, the three workspace route groups redirect to the dashboard. **Reason and benefit** A control that cannot do anything is worse than a missing control: the user fills it in, saves, and gets no error and no effect. The server rule turns that silent no-op into a clear refusal. The route gate stops a feature that an instance has turned off from staying reachable by URL, which is the same standard the Cases, Pipelines, and hidden-settings pages already meet. **Breaking changes** None for a default instance: both flags are off by default for self-hosted and managed instances, so nothing changes unless an operator turns them on. Stored `adapterConfig` values are never cleared, so turning the feature off restores every previous value. ## What Changed - Add `ui/src/hooks/useManagedSandboxOnly.ts`, modelled on `useAppsEnabled`, for components that do not already read the experimental settings. It exposes `hideHostPaths`, which fails closed while the settings query is in flight, so a cold cache never flashes a host path before the policy resolves. Components that keep their own settings read compute the same gate from `isFetched`. - Add `managedSandboxOnly` to `AdapterConfigFieldsProps` and populate it where `AgentConfigForm` builds the adapter field props. Resolve the effective instructions-file gate once as `hideInstructionsFile || hideHostPaths`, so every adapter hides that path field with no per-adapter edit. - Hide under the flag: the project "Local folder" block and its absolute-path edit panel (a managed checkout keeps its label, without the path); the new-project "Local folder" field; the project-workspace "Local path" field and fact row; the execution-workspace "Paths" and "Lifecycle commands" groups; the working directory on the workspace summary card, the task workspace card, the task properties "Folder" row, and the runtime service rows; the plugin "Local folders" section; "Working directory (deprecated)" and "Command" in the agent form; and the per-adapter "Execution engine", "ACP server command", and "ACP state directory" for `claude_local`, `codex_local`, and `gemini_local`. - Drop two working-directory fallbacks that had no gate to read: the close-workspace dialog now falls back to "No additional details", and the reuse-existing workspace label and picker subtitle fall back to a neutral phrase. - Refuse a non-null `cwd` with `422` on `POST /projects/:id/workspaces`, `PATCH /projects/:id/workspaces/:workspaceId`, and the nested workspace on `POST /companies/:companyId/projects`, following the `assertNoAgentHostWorkspaceCommandMutation` precedent on those routes. - Add `IsolatedWorkspacesRouteGate` and wrap the `/workspaces`, `/execution-workspaces/*`, and `/projects/:projectId/workspaces/:workspaceId` routes with it. - Leave the SSH "Remote workspace path" and the workspace file browser alone, with a comment explaining why. ## Verification Automated: - `pnpm --filter @paperclipai/ui exec vitest run` — 479 of 480 files pass (4455 of 4456 tests). The one failure is `OnboardingWizard.test.tsx > renders instead of throwing when the browser denies storage access`, which also fails on `origin/master` and is unrelated to this change. - `pnpm --filter @paperclipai/server exec vitest run project workspace instance-settings` — 45 of 50 files pass. Four files fail on macOS for reasons unrelated to this change: `workspace-instance-cleanup`, `workspace-runtime`, `execution-workspace-runtime-control-conflict`, and `workspace-runtime-exposure` compare `/var/...` against the resolved `/private/var/...` or bind real ports. The same files fail on a clean `master` checkout on the same machine. - `pnpm --filter @paperclipai/ui typecheck` - `tsc --noEmit` in `server/` (after `pnpm --filter @paperclipai/plugin-sdk ensure-build-deps`). The package `typecheck` script also builds the Rust runner, which needs `cargo`; it is not installed on the machine that ran this. New and extended tests: - `ui/src/adapters/managed-sandbox-only-config-fields.test.tsx` — the three adapters drop the execution engine, the ACP paths, the instructions-file path, and every "Choose" button when the flag is on, and keep the non-path controls. - `ui/src/components/AgentConfigForm.render.test.tsx` — flag-on and flag-off renders for the working directory, the command, the engine, the ACP paths, and the resolved adapter field props. - `ui/src/components/ProjectProperties.managed-sandbox.test.tsx`, `ui/src/components/NewProjectDialog.managed-sandbox.test.tsx`, `ui/src/pages/ProjectWorkspaceDetail.test.tsx`, `ui/src/components/ProjectWorkspaceSummaryCard.test.tsx`, `ui/src/components/WorkspaceRuntimeControls.test.tsx`. - `ui/src/components/IsolatedWorkspacesRouteGate.test.tsx` — redirect when off, render when on, and render nothing while the flag query is in flight. - "Still loading" cases for the project properties, the new-project dialog, the workspace summary card, the runtime service rows, and the agent configuration form, each asserting that no host path renders before the policy resolves. - `server/src/__tests__/project-workspace-managed-sandbox-routes.test.ts` — the `422` on all three write paths, the `cwd: null` pass-through, and the flag-off pass-through. Manual check to reproduce: turn on Managed Environment Only in instance experimental settings, then open a project, the new-project dialog, an agent's configuration, and a workspace page. No path, folder icon, or "Choose" button appears. Turn the setting off and each control returns with its stored value. No documentation change was needed. The operator-facing text for both settings lives in the feature catalog entry, which already states the contract this pull request now enforces across the UI. ## Risks - Low. Both flags default to off, so a default instance is unchanged. - The hidden fields are presentation only. No stored `adapterConfig` value is cleared, because an import carries adapter configuration written on another instance and clearing it would break that flow. Turning the setting off shows every previous value again. - The `422` is the one behavior change for an API caller, and only while the setting is on. `cwd: null` still passes so a stale path can be cleared. - The route gate renders nothing until the flag query settles, so an instance with isolated workspaces on never flashes a redirect. An instance with the feature off now redirects a bookmarked workspace URL to the dashboard. - Every host-path guard fails closed while the settings query is in flight, so a default instance shows those controls a moment later than before on a cold load. That is the safe direction: the alternative flashes a path a managed instance must never show. - Two path surfaces stay on purpose, each with a comment: the SSH "Remote workspace path" is a path on the user's own remote host, and the workspace file browser shows workspace-relative paths. The instance Adapters page also keeps its "Local path" install option, since that page is an instance-admin surface the hosting operator can already hide through the hidden-settings mechanism. ## Model Used Claude (Anthropic), Claude Opus, 1M context window, extended thinking, agentic tool use through Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
554 lines
21 KiB
TypeScript
554 lines
21 KiB
TypeScript
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
import { Link } from "@/lib/router";
|
|
import type { Issue, ExecutionWorkspace } from "@paperclipai/shared";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { executionWorkspacesApi } from "../api/execution-workspaces";
|
|
import { environmentsApi } from "../api/environments";
|
|
import { instanceSettingsApi } from "../api/instanceSettings";
|
|
import { useCompany } from "../context/CompanyContext";
|
|
import { queryKeys } from "../lib/queryKeys";
|
|
import { copyTextToClipboard } from "../lib/clipboard";
|
|
import {
|
|
defaultExecutionWorkspaceModeForProject,
|
|
issueExecutionWorkspaceModeForExistingWorkspace,
|
|
} from "../lib/project-workspace-defaults";
|
|
import { orderReusableExecutionWorkspaces } from "../lib/reusable-execution-workspaces";
|
|
import { cn, projectWorkspaceUrl } from "../lib/utils";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Check, Copy, FileSearch, FolderOpen, FolderSearch, GitBranch, Pencil, X } from "lucide-react";
|
|
import { ReusableExecutionWorkspaceSelect } from "./ReusableExecutionWorkspaceSelect";
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* Utility helpers (mirrored from IssueProperties for self-containment) */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
const EXECUTION_WORKSPACE_OPTIONS = [
|
|
{ value: "shared_workspace", label: "Project default" },
|
|
{ value: "isolated_workspace", label: "New isolated workspace" },
|
|
{ value: "reuse_existing", label: "Reuse existing workspace" },
|
|
] as const;
|
|
|
|
function shouldPresentExistingWorkspaceSelection(
|
|
issue: Pick<
|
|
Issue,
|
|
"executionWorkspaceId" | "executionWorkspacePreference" | "executionWorkspaceSettings" | "currentExecutionWorkspace"
|
|
>,
|
|
) {
|
|
const persistedMode =
|
|
issue.currentExecutionWorkspace?.mode
|
|
?? issue.executionWorkspaceSettings?.mode
|
|
?? issue.executionWorkspacePreference;
|
|
return Boolean(
|
|
issue.executionWorkspaceId &&
|
|
(persistedMode === "isolated_workspace" || persistedMode === "operator_branch"),
|
|
);
|
|
}
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* Sub-components */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
function BreakablePath({ text }: { text: string }) {
|
|
const parts: React.ReactNode[] = [];
|
|
const segments = text.split(/(?<=[\/-])/);
|
|
for (let i = 0; i < segments.length; i++) {
|
|
if (i > 0) parts.push(<wbr key={i} />);
|
|
parts.push(segments[i]);
|
|
}
|
|
return <>{parts}</>;
|
|
}
|
|
|
|
function CopyableInline({ value, label, mono }: { value: string; label?: string; mono?: boolean }) {
|
|
const [copied, setCopied] = useState(false);
|
|
const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
|
|
useEffect(() => () => clearTimeout(timerRef.current), []);
|
|
|
|
const handleCopy = useCallback(async () => {
|
|
try {
|
|
await copyTextToClipboard(value);
|
|
setCopied(true);
|
|
clearTimeout(timerRef.current);
|
|
timerRef.current = setTimeout(() => setCopied(false), 1500);
|
|
} catch { /* noop */ }
|
|
}, [value]);
|
|
|
|
return (
|
|
<span className="inline-flex items-center gap-1 group/copy">
|
|
{label && <span className="text-muted-foreground">{label}</span>}
|
|
<span className={cn("min-w-0", mono && "font-mono")} style={{ overflowWrap: "anywhere" }}>
|
|
<BreakablePath text={value} />
|
|
</span>
|
|
<button
|
|
type="button"
|
|
className="shrink-0 p-0.5 rounded hover:bg-accent/50 transition-colors text-muted-foreground hover:text-foreground opacity-0 group-hover/copy:opacity-100 focus:opacity-100"
|
|
onClick={handleCopy}
|
|
title={copied ? "Copied!" : "Copy"}
|
|
aria-label={copied ? "Copied to clipboard" : `Copy ${label ?? "value"}`}
|
|
>
|
|
{copied ? <Check className="h-3 w-3 text-green-500" /> : <Copy className="h-3 w-3" />}
|
|
</button>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
function workspaceModeLabel(mode: string | null | undefined) {
|
|
switch (mode) {
|
|
case "isolated_workspace": return "Isolated workspace";
|
|
case "operator_branch": return "Operator branch";
|
|
case "cloud_sandbox": return "Cloud environment";
|
|
case "adapter_managed": return "Adapter managed";
|
|
default: return "Workspace";
|
|
}
|
|
}
|
|
|
|
function configuredWorkspaceLabel(
|
|
selection: string | null | undefined,
|
|
reusableWorkspace: ExecutionWorkspace | null,
|
|
) {
|
|
switch (selection) {
|
|
case "isolated_workspace":
|
|
return "New isolated workspace";
|
|
case "reuse_existing":
|
|
return reusableWorkspace?.mode === "isolated_workspace"
|
|
? "Existing isolated workspace"
|
|
: "Reuse existing workspace";
|
|
default:
|
|
return "Project default";
|
|
}
|
|
}
|
|
|
|
function projectWorkspaceDetailLink(input: {
|
|
projectId: string | null | undefined;
|
|
projectWorkspaceId: string | null | undefined;
|
|
}) {
|
|
if (!input.projectId || !input.projectWorkspaceId) return null;
|
|
return projectWorkspaceUrl({ id: input.projectId, urlKey: input.projectId }, input.projectWorkspaceId);
|
|
}
|
|
|
|
function workspaceDetailLink(input: {
|
|
projectId: string | null | undefined;
|
|
issueProjectWorkspaceId: string | null | undefined;
|
|
workspace: ExecutionWorkspace | null | undefined;
|
|
}) {
|
|
const linkedProjectWorkspaceId = input.workspace?.projectWorkspaceId ?? input.issueProjectWorkspaceId ?? null;
|
|
if (input.workspace?.mode === "shared_workspace") {
|
|
return projectWorkspaceDetailLink({
|
|
projectId: input.projectId,
|
|
projectWorkspaceId: linkedProjectWorkspaceId,
|
|
});
|
|
}
|
|
return input.workspace ? `/execution-workspaces/${input.workspace.id}` : null;
|
|
}
|
|
|
|
function statusBadge(status: string) {
|
|
const colors: Record<string, string> = {
|
|
active: "bg-green-500/15 text-green-700 dark:text-green-400",
|
|
idle: "bg-muted text-muted-foreground",
|
|
in_review: "bg-blue-500/15 text-blue-700 dark:text-blue-400",
|
|
archived: "bg-muted text-muted-foreground",
|
|
};
|
|
return (
|
|
<Badge variant="ghost" className={cn("text-(length:--text-nano) px-1.5", colors[status] ?? colors.idle)}>
|
|
{status.replace(/_/g, " ")}
|
|
</Badge>
|
|
);
|
|
}
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* Main component */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
interface IssueWorkspaceCardProps {
|
|
issue: Omit<
|
|
Pick<
|
|
Issue,
|
|
| "companyId"
|
|
| "projectId"
|
|
| "projectWorkspaceId"
|
|
| "executionWorkspaceId"
|
|
| "executionWorkspacePreference"
|
|
| "executionWorkspaceSettings"
|
|
>,
|
|
"companyId"
|
|
> & {
|
|
companyId: string | null;
|
|
currentExecutionWorkspace?: ExecutionWorkspace | null;
|
|
};
|
|
project: {
|
|
id: string;
|
|
executionWorkspacePolicy?: {
|
|
enabled?: boolean;
|
|
defaultMode?: string | null;
|
|
defaultProjectWorkspaceId?: string | null;
|
|
environmentId?: string | null;
|
|
} | null;
|
|
workspaces?: Array<{ id: string; isPrimary: boolean }>;
|
|
} | null;
|
|
onUpdate: (data: Record<string, unknown>) => void;
|
|
initialEditing?: boolean;
|
|
livePreview?: boolean;
|
|
onDraftChange?: (data: Record<string, unknown>, meta: { canSave: boolean; workspaceBranchName?: string | null }) => void;
|
|
/** Opens the workspace file browser sheet. When omitted, the browse row is hidden. */
|
|
onBrowseFiles?: () => void;
|
|
/** Opens the same browser sheet focused for path entry. */
|
|
onOpenFileByPath?: () => void;
|
|
}
|
|
|
|
export function IssueWorkspaceCard({
|
|
issue,
|
|
project,
|
|
onUpdate,
|
|
initialEditing = false,
|
|
livePreview = false,
|
|
onDraftChange,
|
|
onBrowseFiles,
|
|
onOpenFileByPath,
|
|
}: IssueWorkspaceCardProps) {
|
|
const { selectedCompanyId } = useCompany();
|
|
const companyId = issue.companyId ?? selectedCompanyId;
|
|
const [editing, setEditing] = useState(initialEditing);
|
|
|
|
const { data: experimentalSettings } = useQuery({
|
|
queryKey: queryKeys.instance.experimentalSettings,
|
|
queryFn: () => instanceSettingsApi.getExperimental(),
|
|
});
|
|
|
|
const environmentsEnabled = experimentalSettings?.enableEnvironments === true;
|
|
// Managed-sandbox-only policy: the workspace path is a host filesystem path,
|
|
// so the card omits it and keeps branch, repo, and environment. The gate fails
|
|
// closed whenever the policy is unknown — in flight and also on a failed read
|
|
// — because an unresolved policy reads as "not managed" and would show the
|
|
// path the policy exists to hide.
|
|
const hideHostPaths =
|
|
experimentalSettings === undefined || experimentalSettings.enableManagedSandboxOnly === true;
|
|
const policyEnabled = experimentalSettings?.enableIsolatedWorkspaces === true
|
|
&& Boolean(project?.executionWorkspacePolicy?.enabled);
|
|
|
|
const workspace = issue.currentExecutionWorkspace as ExecutionWorkspace | null | undefined;
|
|
const { data: environments } = useQuery({
|
|
queryKey: queryKeys.environments.list(companyId!),
|
|
queryFn: () => environmentsApi.list(companyId!),
|
|
enabled: Boolean(companyId) && environmentsEnabled,
|
|
});
|
|
|
|
const {
|
|
data: reusableExecutionWorkspaces,
|
|
isLoading: reusableExecutionWorkspacesLoading,
|
|
isError: reusableExecutionWorkspacesError,
|
|
} = useQuery({
|
|
queryKey: queryKeys.executionWorkspaces.list(companyId!, {
|
|
projectId: issue.projectId ?? undefined,
|
|
projectWorkspaceId: issue.projectWorkspaceId ?? undefined,
|
|
reuseEligible: true,
|
|
}),
|
|
queryFn: () =>
|
|
executionWorkspacesApi.list(companyId!, {
|
|
projectId: issue.projectId ?? undefined,
|
|
projectWorkspaceId: issue.projectWorkspaceId ?? undefined,
|
|
reuseEligible: true,
|
|
}),
|
|
enabled: Boolean(companyId) && Boolean(issue.projectId) && editing,
|
|
});
|
|
|
|
const selectableReusableWorkspaces = reusableExecutionWorkspaces ?? [];
|
|
|
|
const selectedReusableExecutionWorkspace =
|
|
selectableReusableWorkspaces.find((w) => w.id === issue.executionWorkspaceId)
|
|
?? workspace
|
|
?? null;
|
|
|
|
const currentSelection = shouldPresentExistingWorkspaceSelection(issue)
|
|
? "reuse_existing"
|
|
: (
|
|
issue.executionWorkspacePreference
|
|
?? issue.executionWorkspaceSettings?.mode
|
|
?? defaultExecutionWorkspaceModeForProject(project)
|
|
);
|
|
|
|
const [draftSelection, setDraftSelection] = useState(currentSelection);
|
|
const [draftExecutionWorkspaceId, setDraftExecutionWorkspaceId] = useState(issue.executionWorkspaceId ?? "");
|
|
const projectEnvironmentId = environmentsEnabled
|
|
? project?.executionWorkspacePolicy?.environmentId ?? null
|
|
: null;
|
|
const currentReusableEnvironmentId = selectedReusableExecutionWorkspace?.config?.environmentId ?? null;
|
|
const currentEnvironmentId = environmentsEnabled
|
|
? (
|
|
(currentSelection === "reuse_existing" && currentReusableEnvironmentId)
|
|
?? workspace?.config?.environmentId
|
|
?? projectEnvironmentId
|
|
)
|
|
: null;
|
|
const currentEnvironment =
|
|
environments?.find((environment) => environment.id === currentEnvironmentId)
|
|
?? null;
|
|
|
|
useEffect(() => {
|
|
if (editing) return;
|
|
setDraftSelection(currentSelection);
|
|
setDraftExecutionWorkspaceId(issue.executionWorkspaceId ?? "");
|
|
}, [currentSelection, editing, issue.executionWorkspaceId]);
|
|
|
|
const activeNonDefaultWorkspace = Boolean(workspace && workspace.mode !== "shared_workspace");
|
|
|
|
const configuredReusableWorkspace =
|
|
selectableReusableWorkspaces.find((w) => w.id === draftExecutionWorkspaceId)
|
|
?? (draftExecutionWorkspaceId === issue.executionWorkspaceId ? selectedReusableExecutionWorkspace : null);
|
|
|
|
const selectedReusableWorkspaceLink = workspaceDetailLink({
|
|
projectId: project?.id,
|
|
issueProjectWorkspaceId: issue.projectWorkspaceId,
|
|
workspace: selectedReusableExecutionWorkspace,
|
|
});
|
|
const currentWorkspaceLink = workspaceDetailLink({
|
|
projectId: project?.id,
|
|
issueProjectWorkspaceId: issue.projectWorkspaceId,
|
|
workspace,
|
|
});
|
|
|
|
const canSaveWorkspaceConfig = draftSelection !== "reuse_existing" || draftExecutionWorkspaceId.length > 0;
|
|
const draftWorkspaceBranchName =
|
|
draftSelection === "reuse_existing" && configuredReusableWorkspace?.mode !== "shared_workspace"
|
|
? configuredReusableWorkspace?.branchName ?? null
|
|
: null;
|
|
|
|
const buildWorkspaceDraftUpdate = useCallback(() => ({
|
|
executionWorkspacePreference: draftSelection,
|
|
executionWorkspaceId: draftSelection === "reuse_existing" ? draftExecutionWorkspaceId || null : null,
|
|
executionWorkspaceSettings: {
|
|
mode:
|
|
draftSelection === "reuse_existing"
|
|
? issueExecutionWorkspaceModeForExistingWorkspace(configuredReusableWorkspace?.mode)
|
|
: draftSelection,
|
|
environmentId: null,
|
|
},
|
|
}), [
|
|
configuredReusableWorkspace?.mode,
|
|
draftExecutionWorkspaceId,
|
|
draftSelection,
|
|
]);
|
|
|
|
useEffect(() => {
|
|
if (!onDraftChange) return;
|
|
onDraftChange(buildWorkspaceDraftUpdate(), {
|
|
canSave: canSaveWorkspaceConfig,
|
|
workspaceBranchName: draftWorkspaceBranchName,
|
|
});
|
|
}, [buildWorkspaceDraftUpdate, canSaveWorkspaceConfig, draftWorkspaceBranchName, onDraftChange]);
|
|
|
|
const handleSave = useCallback(() => {
|
|
if (!canSaveWorkspaceConfig) return;
|
|
onUpdate(buildWorkspaceDraftUpdate());
|
|
setEditing(false);
|
|
}, [
|
|
buildWorkspaceDraftUpdate,
|
|
canSaveWorkspaceConfig,
|
|
onUpdate,
|
|
]);
|
|
|
|
const handleCancel = useCallback(() => {
|
|
setDraftSelection(currentSelection);
|
|
setDraftExecutionWorkspaceId(issue.executionWorkspaceId ?? "");
|
|
setEditing(false);
|
|
}, [currentSelection, issue.executionWorkspaceId]);
|
|
|
|
if (!policyEnabled || !project) return null;
|
|
|
|
const showEditingControls = livePreview || editing;
|
|
|
|
return (
|
|
<div className="rounded-lg border border-border p-3 space-y-2">
|
|
{/* Header row */}
|
|
<div className="flex items-center justify-between gap-2">
|
|
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
|
<GitBranch className="h-3.5 w-3.5 text-muted-foreground" />
|
|
{activeNonDefaultWorkspace && workspace
|
|
? workspaceModeLabel(workspace.mode)
|
|
: configuredWorkspaceLabel(currentSelection, selectedReusableExecutionWorkspace)}
|
|
{workspace ? statusBadge(workspace.status) : statusBadge("idle")}
|
|
</div>
|
|
<div className="flex items-center gap-1">
|
|
{showEditingControls ? (
|
|
<>
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="h-6 px-2 text-xs text-muted-foreground"
|
|
onClick={handleCancel}
|
|
>
|
|
<X className="h-3 w-3 mr-1" />Cancel
|
|
</Button>
|
|
<Button
|
|
size="sm"
|
|
className="h-6 px-2 text-xs"
|
|
onClick={handleSave}
|
|
disabled={!canSaveWorkspaceConfig}
|
|
>
|
|
Save
|
|
</Button>
|
|
</>
|
|
) : (
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="h-6 px-2 text-xs text-muted-foreground"
|
|
onClick={() => setEditing(true)}
|
|
>
|
|
<Pencil className="h-3 w-3 mr-1" />Edit
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Read-only info */}
|
|
{!showEditingControls && (
|
|
<div className="space-y-1.5 text-xs">
|
|
{workspace?.branchName && (
|
|
<div className="flex items-center gap-1.5">
|
|
<GitBranch className="h-3 w-3 text-muted-foreground shrink-0" />
|
|
<CopyableInline value={workspace.branchName} mono />
|
|
</div>
|
|
)}
|
|
{workspace?.cwd && !hideHostPaths && (
|
|
<div className="flex items-center gap-1.5">
|
|
<FolderOpen className="h-3 w-3 text-muted-foreground shrink-0" />
|
|
<CopyableInline value={workspace.cwd} mono />
|
|
</div>
|
|
)}
|
|
{workspace?.repoUrl && (
|
|
<div className="flex items-center gap-1.5 text-muted-foreground">
|
|
<span className="text-(length:--text-micro)">Repo:</span>
|
|
<CopyableInline value={workspace.repoUrl} mono />
|
|
</div>
|
|
)}
|
|
{environmentsEnabled && currentEnvironmentId && (
|
|
<div className="text-muted-foreground" style={{ overflowWrap: "anywhere" }}>
|
|
Environment: <span className="text-foreground">{currentEnvironment?.name ?? currentEnvironmentId}</span>
|
|
{currentSelection === "reuse_existing" && currentReusableEnvironmentId === currentEnvironmentId
|
|
? " · reused workspace"
|
|
: !issue.executionWorkspaceSettings?.environmentId && projectEnvironmentId === currentEnvironmentId
|
|
? " · project default"
|
|
: null}
|
|
</div>
|
|
)}
|
|
{!workspace && (
|
|
<div className="text-muted-foreground">
|
|
{currentSelection === "isolated_workspace"
|
|
? "A fresh isolated workspace will be created when this task runs."
|
|
: currentSelection === "reuse_existing"
|
|
? "This task will reuse an existing workspace when it runs."
|
|
: "This task will use the project default workspace configuration when it runs."}
|
|
</div>
|
|
)}
|
|
{currentSelection === "reuse_existing" && selectedReusableExecutionWorkspace && (
|
|
<div className="text-muted-foreground" style={{ overflowWrap: "anywhere" }}>
|
|
Reusing:{" "}
|
|
{selectedReusableWorkspaceLink ? (
|
|
<Link
|
|
to={selectedReusableWorkspaceLink}
|
|
className="hover:text-foreground hover:underline"
|
|
>
|
|
<BreakablePath text={selectedReusableExecutionWorkspace.name} />
|
|
</Link>
|
|
) : (
|
|
<BreakablePath text={selectedReusableExecutionWorkspace.name} />
|
|
)}
|
|
</div>
|
|
)}
|
|
{workspace && currentWorkspaceLink && (
|
|
<div className="pt-0.5">
|
|
<Link
|
|
to={currentWorkspaceLink}
|
|
className="text-(length:--text-micro) text-muted-foreground hover:text-foreground hover:underline"
|
|
>
|
|
View workspace details →
|
|
</Link>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Editing controls */}
|
|
{editing && (
|
|
<div className="space-y-2 pt-1">
|
|
<select
|
|
className="w-full rounded border border-border bg-transparent px-2 py-1.5 text-xs outline-none"
|
|
value={draftSelection}
|
|
onChange={(e) => {
|
|
const nextMode = e.target.value;
|
|
setDraftSelection(nextMode);
|
|
if (nextMode !== "reuse_existing") {
|
|
setDraftExecutionWorkspaceId("");
|
|
} else if (!draftExecutionWorkspaceId && issue.executionWorkspaceId) {
|
|
setDraftExecutionWorkspaceId(issue.executionWorkspaceId);
|
|
}
|
|
}}
|
|
>
|
|
{EXECUTION_WORKSPACE_OPTIONS.map((option) => (
|
|
<option key={option.value} value={option.value}>
|
|
{option.value === "reuse_existing" && configuredReusableWorkspace?.mode === "isolated_workspace"
|
|
? "Existing isolated workspace"
|
|
: option.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
|
|
{draftSelection === "reuse_existing" && (
|
|
<ReusableExecutionWorkspaceSelect
|
|
value={draftExecutionWorkspaceId}
|
|
workspaces={selectableReusableWorkspaces}
|
|
onValueChange={(workspaceId) => setDraftExecutionWorkspaceId(workspaceId)}
|
|
loading={reusableExecutionWorkspacesLoading}
|
|
error={reusableExecutionWorkspacesError}
|
|
/>
|
|
)}
|
|
|
|
{/* Current workspace summary when editing */}
|
|
{workspace && (
|
|
<div className="text-(length:--text-micro) text-muted-foreground space-y-0.5 pt-1 border-t border-border/50">
|
|
<div style={{ overflowWrap: "anywhere" }}>
|
|
Current:{" "}
|
|
{currentWorkspaceLink ? (
|
|
<Link
|
|
to={currentWorkspaceLink}
|
|
className="hover:text-foreground hover:underline"
|
|
>
|
|
<BreakablePath text={workspace.name} />
|
|
</Link>
|
|
) : (
|
|
<BreakablePath text={workspace.name} />
|
|
)}
|
|
{" · "}
|
|
{workspace.status}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Workspace file discovery — calm row under the workspace identity. */}
|
|
{!showEditingControls && onBrowseFiles && (
|
|
<div className="flex flex-wrap items-center gap-x-4 gap-y-1 border-t border-border/50 pt-2 text-xs">
|
|
<button
|
|
type="button"
|
|
onClick={onBrowseFiles}
|
|
className="inline-flex items-center gap-1.5 text-muted-foreground transition-colors hover:text-foreground"
|
|
>
|
|
<FolderSearch className="h-3.5 w-3.5 shrink-0" />
|
|
Browse files…
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={onOpenFileByPath ?? onBrowseFiles}
|
|
className="inline-flex items-center gap-1.5 text-muted-foreground transition-colors hover:text-foreground"
|
|
>
|
|
<FileSearch className="h-3.5 w-3.5 shrink-0" />
|
|
Open file by path…
|
|
</button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|