mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-08 12:33:05 +01:00
## Thinking Path > - Paperclip lets people manage agent work through the board. > - The board reads task, agent, settings, plugin, and run data from the server. > - A deploy can interrupt those reads after content is already visible. > - Local error branches can replace that content with an error or show raw codes. > - This pull request moves the remaining reads to the shared recovery behavior. > - The query-error guard prevents new local error patterns from returning. ## Linked Issues or Issue Description **What happened?** Loaded lists, settings, task panels, and manual reads could clear their content or show errors during a server restart. Some reads also disabled the shared retry policy. **Expected behavior** Keep loaded content during a temporary failure. Show the shared connection banner. Retry reads after recovery. Replace content after a real access denial or missing resource, with readable copy. **Steps to reproduce** Open a task, settings page, or run log. Return 503 with `tenant_app_unavailable` from the API. Restore the API and check that content refreshes. Repeat with 403 and 404 to check the failure state. Related merged work: Refs #15754, Refs #15772, Refs #17960. This change covers remaining reads and enforcement. Browser persistence and the outage browser suite follow separately. ## What Changed - Repair an existing PostgreSQL deadline fixture at UTC boundaries. A daily cap defers a heartbeat until both its original interval and the next UTC day allow it. Keep the counted run in its seeded day and cover noon, just before midnight and the first second after midnight with explicit clocks and real PostgreSQL. Production scheduling is unchanged. - Integrate the saved list, settings, shell, task, and manual-read recovery changes against current master. Preserve the current task, Inbox, and run-log structure. - Add `useResilientFetch` for component-local reads. Preserve loaded data, cancel stale requests, and retry through the shared connectivity policy. Keep browser and pairing capabilities in memory. - Retain run log chunks across stream changes and catch up after recovery without duplicate chunks or stalled requests. - Keep genuine authorization and missing-resource failures visible. Translate known single-word codes such as `forbidden`. Show known skills and disconnected-app failures before sibling loading states. Keep Retry bound to its failed request. - Make the query-error guard enforce by default and run it in the CI policy job. Document the narrow exceptions and the read recovery contract. - Invalidate pending OAuth discovery when the operator leaves setup or its context changes. Keep reserved-popup cleanup bound to the current attempt. ## Verification - Current read head `09d1db29dea` is merge-ready: all 59 check runs are completed (54 successful, three skipped, two neutral), the legacy Snyk status is successful, and both required `ci / verify` and `ci / e2e` gates pass. Greptile Apex reviewed this exact head at 5/5 with no unresolved threads; the branch has no merge conflicts. The current CI run is `41748339602`. - Current read head `09d1db29dea` includes master `683fa4725e9`. The latest change touches only the existing server deadline test fixture. Application source remains the previously verified `86376fa751e` revision: all 60 affected skills/disconnected-app tests and both application UI typechecks passed, along with token gates and the enforcing query-error guard. Those UI suites were not repeated for this test-only repair. - The fixture repair passes all seven deadline integration cases and the complete server typecheck, including the server test layer. The old assertion deterministically fails at 23:59:06.888 UTC; its one-second-old run also fails the first-second-of-day probe. The corrected fixture passes noon and both midnight probes. The permanent three-case coverage uses seeded 2099 clocks. - Twelve new regressions fail against the previous implementation. Both skills variants and disconnected-app pages show either request's 403 or 429 while the sibling pauses or remains fetching. Permission failures stay visible. Retry stays usable for its failed request and recovers independently. An initial test-fixture query-key typo was corrected before the passing run. The finding is replied to and resolved. Greptile reviewed prior application revision `86376fa751e` at 5/5 with no new actionable findings or unresolved threads. The current test-only head has now received its own Apex 5/5 review with no unresolved threads, and its CI is successful as recorded above. - The preceding OAuth fix passed all 237 setup tests on both application branches. Its ten regressions prove that Back, Cancel, unmount, or context changes retire initial discovery without creating a connection, caching old identities, navigating an abandoned popup, or closing a newer attempt. - Earlier master integration `e992f770339` passed all 309 tests across eight affected Slack, recovery, retry, submission and task files, plus UI typecheck, token gates, enforcing query-error scan and seven guard tests. The integration preserves Slack workspace reconnect and shared recovery, readable execution errors, source-inspection company scoping, and current submission behavior. Newly inherited retained-file recovery controls keep cached data through transient failures and hide it after definitive denial. - The preceding cache head `97c0bc3966f` passed 1,038 focused cache/write/editor/account/task/API tests. All 22 built-UI outage/write/loading cases passed in 4.7 minutes on exact browser head `b7deaaee5da`, with strict checking of all three specs. The latest skills/app rendering fix is covered by its affected component suites; those broader cases were not repeated for this separate read path. - Historical broader UI, CLI and build results and unresolved aggregate server/DB/adapter failures remain in the PR discussion. Interrupted CI runs were audited and recorded separately; they are not counted as passes. Controlled local outages do not prove hosted authentication or a real Cloud restart/deploy. Real hosted acceptance remains required after merge and deployment. Commands for the latest fix: ```sh pnpm --filter @paperclipai/ui exec vitest run src/pages/CompanySkills.test.tsx src/pages/apps/AppNotConnected.test.tsx pnpm --filter @paperclipai/ui typecheck pnpm check:token-gates node scripts/check-query-error-rendering.mjs --enforce --summary ``` ## Risks This migration touches many read surfaces. The main risks are initial loading, request cancellation, retained authorization state, and run-log paging. The tests cover those states. There are no server, schema, dependency, or API contract changes. The follow-up browser suite and hosted deploy acceptance are required before release acceptance. Recovered commits retain their original authors. If squash-merging, preserve `Co-Authored-By: Bender (Fable) <bender@agents.paperclip.ing>` and the Paperclip trailer. ## Model Used OpenAI `gpt-6.1-sol` through Codex, with xhigh reasoning effort, tool use, and code execution. The context window size is not exposed. Saved source commits keep their original authorship. ## 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 described the issue in-PR following the bug report template - [x] I have not referenced internal/instance-local Paperclip issues or links - [x] My branch name describes the change and contains no internal ticket id - [x] The affected local tests pass; broader limitations are recorded above - [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 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 --------- Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com> Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Bender (Fable) <bender@agents.paperclip.ing> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1655 lines
70 KiB
TypeScript
1655 lines
70 KiB
TypeScript
import { useWorkspaceIsolationControls } from "@/hooks/useWorkspaceIsolationControls";
|
|
import { useEffect, useMemo, useState } from "react";
|
|
import { Link, Navigate, useLocation, useNavigate, useParams } from "@/lib/router";
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import type { ExecutionWorkspace, Issue, Project, ProjectWorkspace, RoutineListItem, WorkspaceOperation } from "@paperclipai/shared";
|
|
import { Copy, ExternalLink, Loader2, Play, Repeat } from "lucide-react";
|
|
import { QueryErrorState, useQueryView } from "@/components/QueryView";
|
|
import { describeError } from "@/api/errors";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle, CardAction } from "@/components/ui/card";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Separator } from "@/components/ui/separator";
|
|
import { Tabs } from "@/components/ui/tabs";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import { CopyText } from "../components/CopyText";
|
|
import { ExecutionWorkspaceCloseDialog } from "../components/ExecutionWorkspaceCloseDialog";
|
|
import { MissingPluginTabPlaceholder } from "../components/MissingPluginTabPlaceholder";
|
|
import { agentsApi } from "../api/agents";
|
|
import { executionWorkspacesApi } from "../api/execution-workspaces";
|
|
import { heartbeatsApi } from "../api/heartbeats";
|
|
import { issuesApi } from "../api/issues";
|
|
import { projectsApi } from "../api/projects";
|
|
import { routinesApi } from "../api/routines";
|
|
import { IssuesList } from "../components/IssuesList";
|
|
import { PageTabBar } from "../components/PageTabBar";
|
|
import { SummarySlotCard } from "../components/SummarySlotCard";
|
|
import { usePublishSharedQueryData, useSharedPollingQuery } from "../hooks/useSharedPolling";
|
|
import { PluginSlotMount, PluginSlotOutlet, usePluginSlots } from "@/plugins/slots";
|
|
import {
|
|
RoutineRunVariablesDialog,
|
|
type RoutineRunDialogSubmitData,
|
|
} from "../components/RoutineRunVariablesDialog";
|
|
import {
|
|
buildWorkspaceRuntimeControlSections,
|
|
buildWorkspaceServiceControlEntries,
|
|
resolveWorkspaceServiceControlRequests,
|
|
WorkspaceRuntimeControls,
|
|
type WorkspaceRuntimeControlRequest,
|
|
} from "../components/WorkspaceRuntimeControls";
|
|
import { WorkspaceServiceControlBar } from "../components/WorkspaceServiceControlBar";
|
|
import { useBreadcrumbs } from "../context/BreadcrumbContext";
|
|
import { useCompany } from "../context/CompanyContext";
|
|
import { useManagedSandboxOnly } from "../hooks/useManagedSandboxOnly";
|
|
import { useToastActions } from "../context/ToastContext";
|
|
import { collectLiveIssueIds } from "../lib/liveIssueIds";
|
|
import { queryKeys } from "../lib/queryKeys";
|
|
import { cn, formatDateTime, issueUrl, projectRouteRef, projectWorkspaceUrl } from "../lib/utils";
|
|
import {
|
|
getWorkspaceSpecificRoutineVariableNames,
|
|
routineHasWorkspaceSpecificVariables,
|
|
sortWorkspaceRoutinesByName,
|
|
} from "../lib/workspace-routines";
|
|
import { useUpdateIssueMutation } from "../hooks/useUpdateIssueMutation";
|
|
|
|
type WorkspaceFormState = {
|
|
name: string;
|
|
cwd: string;
|
|
repoUrl: string;
|
|
baseRef: string;
|
|
branchName: string;
|
|
providerRef: string;
|
|
provisionCommand: string;
|
|
runtimeProvisionCommand: string;
|
|
teardownCommand: string;
|
|
cleanupCommand: string;
|
|
inheritRuntime: boolean;
|
|
workspaceRuntime: string;
|
|
};
|
|
|
|
type ConfiguredRuntimeServicePort = {
|
|
collection: "commands" | "services";
|
|
index: number;
|
|
name: string;
|
|
port: number | null;
|
|
invalidPort: boolean;
|
|
};
|
|
|
|
type ExecutionWorkspaceBaseTab = "services" | "configuration" | "runtime_logs" | "issues" | "routines";
|
|
type ExecutionWorkspacePluginTab = `plugin:${string}`;
|
|
type ExecutionWorkspaceTab = ExecutionWorkspaceBaseTab | ExecutionWorkspacePluginTab;
|
|
type OrderedExecutionWorkspaceTabItem = {
|
|
value: ExecutionWorkspaceTab;
|
|
label: string;
|
|
order: number;
|
|
};
|
|
|
|
const DEFAULT_PLUGIN_DETAIL_TAB_ORDER = 100;
|
|
const EXECUTION_WORKSPACE_BASE_TAB_ITEMS: OrderedExecutionWorkspaceTabItem[] = [
|
|
{ value: "issues", label: "Tasks", order: 10 },
|
|
{ value: "services", label: "Services", order: 20 },
|
|
{ value: "configuration", label: "Configuration", order: 30 },
|
|
{ value: "runtime_logs", label: "Runtime logs", order: 40 },
|
|
{ value: "routines", label: "Routines", order: 60 },
|
|
];
|
|
|
|
function isExecutionWorkspacePluginTab(value: string | null): value is ExecutionWorkspacePluginTab {
|
|
return typeof value === "string" && value.startsWith("plugin:");
|
|
}
|
|
|
|
function orderExecutionWorkspaceTabItems(items: OrderedExecutionWorkspaceTabItem[]) {
|
|
return items
|
|
.map((item, index) => ({ item, index }))
|
|
.sort((left, right) => left.item.order - right.item.order || left.index - right.index)
|
|
.map(({ item }) => item);
|
|
}
|
|
|
|
function resolveExecutionWorkspaceTab(pathname: string, workspaceId: string): ExecutionWorkspaceBaseTab | null {
|
|
const segments = pathname.split("/").filter(Boolean);
|
|
const executionWorkspacesIndex = segments.indexOf("execution-workspaces");
|
|
if (executionWorkspacesIndex === -1 || segments[executionWorkspacesIndex + 1] !== workspaceId) return null;
|
|
const tab = segments[executionWorkspacesIndex + 2];
|
|
if (tab === "services") return "services";
|
|
if (tab === "issues") return "issues";
|
|
if (tab === "routines") return "routines";
|
|
if (tab === "runtime-logs") return "runtime_logs";
|
|
if (tab === "configuration") return "configuration";
|
|
return null;
|
|
}
|
|
|
|
function executionWorkspaceTabPath(workspaceId: string, tab: ExecutionWorkspaceBaseTab) {
|
|
const segment = tab === "runtime_logs" ? "runtime-logs" : tab;
|
|
return `/execution-workspaces/${workspaceId}/${segment}`;
|
|
}
|
|
|
|
function LegacyWorkspaceTabRedirect({ workspaceId }: { workspaceId: string }) {
|
|
useEffect(() => {
|
|
try {
|
|
localStorage.removeItem(`paperclip:execution-workspace-tab:${workspaceId}`);
|
|
} catch {}
|
|
}, [workspaceId]);
|
|
|
|
return <Navigate to={executionWorkspaceTabPath(workspaceId, "issues")} replace />;
|
|
}
|
|
|
|
function isSafeExternalUrl(value: string | null | undefined) {
|
|
if (!value) return false;
|
|
try {
|
|
const parsed = new URL(value);
|
|
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function readText(value: string | null | undefined) {
|
|
return value ?? "";
|
|
}
|
|
|
|
function formatJson(value: Record<string, unknown> | null | undefined) {
|
|
if (!value || Object.keys(value).length === 0) return "";
|
|
return JSON.stringify(value, null, 2);
|
|
}
|
|
|
|
function formatOptionalDateTime(value: Date | string | null | undefined) {
|
|
return value ? formatDateTime(value) : "Never";
|
|
}
|
|
|
|
function normalizeText(value: string) {
|
|
const trimmed = value.trim();
|
|
return trimmed.length > 0 ? trimmed : null;
|
|
}
|
|
|
|
function parseWorkspaceRuntimeJson(value: string) {
|
|
const trimmed = value.trim();
|
|
if (!trimmed) return { ok: true as const, value: null as Record<string, unknown> | null };
|
|
|
|
try {
|
|
const parsed = JSON.parse(trimmed);
|
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
return {
|
|
ok: false as const,
|
|
error: "Workspace commands JSON must be a JSON object.",
|
|
};
|
|
}
|
|
return { ok: true as const, value: parsed as Record<string, unknown> };
|
|
} catch (error) {
|
|
return {
|
|
ok: false as const,
|
|
error: error instanceof Error ? error.message : "Invalid JSON.",
|
|
};
|
|
}
|
|
}
|
|
|
|
export function readConfiguredRuntimeServicePorts(runtimeConfig: Record<string, unknown> | null) {
|
|
if (!runtimeConfig) return [] as ConfiguredRuntimeServicePort[];
|
|
|
|
const entries: ConfiguredRuntimeServicePort[] = [];
|
|
const addServices = (collection: ConfiguredRuntimeServicePort["collection"], services: unknown, commandsRequireServiceKind: boolean) => {
|
|
if (!Array.isArray(services)) return;
|
|
services.forEach((service, index) => {
|
|
if (!service || typeof service !== "object" || Array.isArray(service)) return;
|
|
const config = service as Record<string, unknown>;
|
|
if (commandsRequireServiceKind && config.kind !== "service") return;
|
|
const portConfig = config.port;
|
|
const hasObjectPortValue = Boolean(
|
|
portConfig
|
|
&& typeof portConfig === "object"
|
|
&& !Array.isArray(portConfig)
|
|
&& Object.hasOwn(portConfig, "value"),
|
|
);
|
|
const portValue =
|
|
typeof portConfig === "number"
|
|
? portConfig
|
|
: hasObjectPortValue
|
|
? (portConfig as Record<string, unknown>).value
|
|
: null;
|
|
entries.push({
|
|
collection,
|
|
index,
|
|
name: typeof config.name === "string" && config.name.trim() ? config.name : `Service ${index + 1}`,
|
|
port: typeof portValue === "number" ? portValue : null,
|
|
invalidPort: (typeof portConfig === "number" || hasObjectPortValue)
|
|
&& (typeof portValue !== "number" || !Number.isInteger(portValue) || portValue < 1 || portValue > 65535),
|
|
});
|
|
});
|
|
};
|
|
|
|
addServices("commands", runtimeConfig.commands, true);
|
|
addServices("services", runtimeConfig.services, false);
|
|
return entries;
|
|
}
|
|
|
|
export function updateConfiguredRuntimeServicePort(input: {
|
|
runtimeConfig: Record<string, unknown>;
|
|
service: ConfiguredRuntimeServicePort;
|
|
port: string;
|
|
}) {
|
|
const runtimeConfig = structuredClone(input.runtimeConfig);
|
|
const entries = runtimeConfig[input.service.collection];
|
|
if (!Array.isArray(entries)) return runtimeConfig;
|
|
const entry = entries[input.service.index];
|
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return runtimeConfig;
|
|
const config = entry as Record<string, unknown>;
|
|
const existingPort = config.port && typeof config.port === "object" && !Array.isArray(config.port)
|
|
? config.port as Record<string, unknown>
|
|
: null;
|
|
|
|
const trimmedPort = input.port.trim();
|
|
if (!trimmedPort) {
|
|
if (existingPort) {
|
|
const autoPort: Record<string, unknown> = { ...existingPort, type: "auto" };
|
|
delete autoPort.value;
|
|
config.port = autoPort;
|
|
} else {
|
|
delete config.port;
|
|
}
|
|
return runtimeConfig;
|
|
}
|
|
const port = Number(trimmedPort);
|
|
if (!Number.isInteger(port) || port < 1 || port > 65535) return runtimeConfig;
|
|
config.port = { ...existingPort, type: "fixed", value: port };
|
|
return runtimeConfig;
|
|
}
|
|
|
|
export function getConfiguredRuntimeServicePortWarnings(services: ConfiguredRuntimeServicePort[]) {
|
|
const servicesByPort = new Map<number, ConfiguredRuntimeServicePort[]>();
|
|
for (const service of services) {
|
|
if (service.invalidPort || !service.port) continue;
|
|
const servicesForPort = servicesByPort.get(service.port) ?? [];
|
|
servicesForPort.push(service);
|
|
servicesByPort.set(service.port, servicesForPort);
|
|
}
|
|
|
|
return Array.from(servicesByPort.entries())
|
|
.filter(([, servicesForPort]) => servicesForPort.length > 1)
|
|
.map(([port, servicesForPort]) =>
|
|
`Port ${port} is assigned to multiple services: ${servicesForPort.map((service) => service.name).join(", ")}.`,
|
|
);
|
|
}
|
|
|
|
function formStateFromWorkspace(workspace: ExecutionWorkspace): WorkspaceFormState {
|
|
return {
|
|
name: workspace.name,
|
|
cwd: readText(workspace.cwd),
|
|
repoUrl: readText(workspace.repoUrl),
|
|
baseRef: readText(workspace.baseRef),
|
|
branchName: readText(workspace.branchName),
|
|
providerRef: readText(workspace.providerRef),
|
|
provisionCommand: readText(workspace.config?.provisionCommand),
|
|
runtimeProvisionCommand: readText(workspace.config?.runtimeProvisionCommand),
|
|
teardownCommand: readText(workspace.config?.teardownCommand),
|
|
cleanupCommand: readText(workspace.config?.cleanupCommand),
|
|
inheritRuntime: !workspace.config?.workspaceRuntime,
|
|
workspaceRuntime: formatJson(workspace.config?.workspaceRuntime),
|
|
};
|
|
}
|
|
|
|
function buildWorkspacePatch(initialState: WorkspaceFormState, nextState: WorkspaceFormState) {
|
|
const patch: Record<string, unknown> = {};
|
|
const configPatch: Record<string, unknown> = {};
|
|
|
|
const maybeAssign = (
|
|
key: keyof Pick<WorkspaceFormState, "name" | "cwd" | "repoUrl" | "baseRef" | "branchName" | "providerRef">,
|
|
) => {
|
|
if (initialState[key] === nextState[key]) return;
|
|
patch[key] = key === "name" ? (normalizeText(nextState[key]) ?? initialState.name) : normalizeText(nextState[key]);
|
|
};
|
|
|
|
maybeAssign("name");
|
|
maybeAssign("cwd");
|
|
maybeAssign("repoUrl");
|
|
maybeAssign("baseRef");
|
|
maybeAssign("branchName");
|
|
maybeAssign("providerRef");
|
|
|
|
const maybeAssignConfigText = (key: keyof Pick<WorkspaceFormState, "provisionCommand" | "runtimeProvisionCommand" | "teardownCommand" | "cleanupCommand">) => {
|
|
if (initialState[key] === nextState[key]) return;
|
|
configPatch[key] = normalizeText(nextState[key]);
|
|
};
|
|
|
|
maybeAssignConfigText("provisionCommand");
|
|
maybeAssignConfigText("runtimeProvisionCommand");
|
|
maybeAssignConfigText("teardownCommand");
|
|
maybeAssignConfigText("cleanupCommand");
|
|
|
|
if (initialState.inheritRuntime !== nextState.inheritRuntime || initialState.workspaceRuntime !== nextState.workspaceRuntime) {
|
|
const parsed = parseWorkspaceRuntimeJson(nextState.workspaceRuntime);
|
|
if (!parsed.ok) throw new Error(parsed.error);
|
|
configPatch.workspaceRuntime = nextState.inheritRuntime ? null : parsed.value;
|
|
}
|
|
|
|
if (Object.keys(configPatch).length > 0) {
|
|
patch.config = configPatch;
|
|
}
|
|
|
|
return patch;
|
|
}
|
|
|
|
function validateForm(form: WorkspaceFormState) {
|
|
const repoUrl = normalizeText(form.repoUrl);
|
|
if (repoUrl) {
|
|
try {
|
|
new URL(repoUrl);
|
|
} catch {
|
|
return "Repo URL must be a valid URL.";
|
|
}
|
|
}
|
|
|
|
if (!form.inheritRuntime) {
|
|
const runtimeJson = parseWorkspaceRuntimeJson(form.workspaceRuntime);
|
|
if (!runtimeJson.ok) {
|
|
return runtimeJson.error;
|
|
}
|
|
const invalidPort = readConfiguredRuntimeServicePorts(runtimeJson.value).find((service) => service.invalidPort);
|
|
if (invalidPort) return `${invalidPort.name} has an invalid fixed port.`;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function Field({
|
|
label,
|
|
hint,
|
|
children,
|
|
}: {
|
|
label: string;
|
|
hint?: string;
|
|
children: React.ReactNode;
|
|
}) {
|
|
return (
|
|
<label className="block space-y-2">
|
|
<div className="flex flex-col gap-0.5 sm:flex-row sm:items-baseline sm:justify-between sm:gap-3">
|
|
<span className="text-sm font-medium text-foreground">{label}</span>
|
|
{hint ? <span className="text-xs text-muted-foreground sm:text-right">{hint}</span> : null}
|
|
</div>
|
|
{children}
|
|
</label>
|
|
);
|
|
}
|
|
|
|
function workspaceOperationPhaseLabel(phase: string) {
|
|
switch (phase) {
|
|
case "worktree_prepare":
|
|
return "Worktree setup";
|
|
case "workspace_config_freshness":
|
|
return "Config freshness";
|
|
case "workspace_provision":
|
|
return "Provision";
|
|
case "workspace_seed":
|
|
return "Database seed";
|
|
case "workspace_runtime_provision":
|
|
return "Runtime provision";
|
|
case "workspace_teardown":
|
|
return "Teardown";
|
|
case "worktree_cleanup":
|
|
return "Worktree cleanup";
|
|
case "workspace_finalize":
|
|
return "Finalize";
|
|
default:
|
|
return phase;
|
|
}
|
|
}
|
|
|
|
export type RuntimeProvisionStatus =
|
|
| { kind: "eager" }
|
|
| { kind: "deferred" }
|
|
| { kind: "provisioning"; at: Date | null }
|
|
| { kind: "provisioned"; at: Date | null }
|
|
| { kind: "failed"; at: Date | null };
|
|
|
|
/**
|
|
* Derives the lazy runtime-provisioning state from the configured command and the
|
|
* database-seed or runtime-provision operation-log entries (most-recent first). Returns
|
|
* "eager" when no runtime provision command is configured (the legacy path).
|
|
*/
|
|
export function resolveRuntimeProvisionStatus(input: {
|
|
runtimeProvisionCommand: string | null | undefined;
|
|
operations: WorkspaceOperation[] | undefined;
|
|
}): RuntimeProvisionStatus {
|
|
const latest = (input.operations ?? []).find((operation) => (
|
|
operation.phase === "workspace_seed" || operation.phase === "workspace_runtime_provision"
|
|
)) ?? null;
|
|
if (latest) {
|
|
const at = latest.finishedAt ?? latest.startedAt ?? null;
|
|
if (latest.status === "running") return { kind: "provisioning", at };
|
|
if (latest.status === "succeeded") return { kind: "provisioned", at };
|
|
if (latest.status === "failed") return { kind: "failed", at };
|
|
// "skipped" falls through to the config-derived state below.
|
|
}
|
|
const configured = Boolean(input.runtimeProvisionCommand && input.runtimeProvisionCommand.trim());
|
|
return configured ? { kind: "deferred" } : { kind: "eager" };
|
|
}
|
|
|
|
function DetailRow({ label, children }: { label: string; children: React.ReactNode }) {
|
|
return (
|
|
<div className="flex flex-col gap-1.5 py-1.5 sm:flex-row sm:items-start sm:gap-3">
|
|
<div className="shrink-0 text-xs text-muted-foreground sm:w-32">{label}</div>
|
|
<div className="min-w-0 flex-1 text-sm">{children}</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function StatusPill({ children, className }: { children: React.ReactNode; className?: string }) {
|
|
return (
|
|
<div className={cn("inline-flex items-center rounded-full border border-border bg-background px-2.5 py-1 text-xs text-muted-foreground", className)}>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function RuntimeProvisionStatusValue({
|
|
status,
|
|
onViewLogs,
|
|
}: {
|
|
status: RuntimeProvisionStatus;
|
|
onViewLogs: () => void;
|
|
}) {
|
|
if (status.kind === "eager") {
|
|
return (
|
|
<span className="text-sm text-muted-foreground">Eager · provisioned during workspace setup</span>
|
|
);
|
|
}
|
|
if (status.kind === "deferred") {
|
|
return (
|
|
<div className="flex flex-col gap-1">
|
|
<StatusPill className="border-amber-500/40 text-amber-600 dark:text-amber-400">Deferred</StatusPill>
|
|
<span className="text-xs text-muted-foreground">
|
|
Runs once before the first runtime-service start.
|
|
</span>
|
|
</div>
|
|
);
|
|
}
|
|
if (status.kind === "provisioning") {
|
|
return (
|
|
<StatusPill className="border-border text-muted-foreground">
|
|
<Loader2 className="mr-1.5 h-3 w-3 animate-spin" />
|
|
Provisioning…
|
|
</StatusPill>
|
|
);
|
|
}
|
|
if (status.kind === "provisioned") {
|
|
return (
|
|
<StatusPill className="border-emerald-500/40 text-emerald-600 dark:text-emerald-400">
|
|
Provisioned{status.at ? ` · ${formatDateTime(status.at)}` : ""}
|
|
</StatusPill>
|
|
);
|
|
}
|
|
return (
|
|
<div className="flex flex-col gap-1">
|
|
<StatusPill className="border-destructive/50 text-destructive">
|
|
Provisioning failed{status.at ? ` · ${formatDateTime(status.at)}` : ""}
|
|
</StatusPill>
|
|
<button type="button" onClick={onViewLogs} className="self-start text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground">
|
|
View runtime logs
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function MonoValue({ value, copy }: { value: string; copy?: boolean }) {
|
|
return (
|
|
<div className="inline-flex max-w-full items-start gap-2">
|
|
<span className="break-all font-mono text-xs">{value}</span>
|
|
{copy ? (
|
|
<CopyText text={value} className="shrink-0 text-muted-foreground hover:text-foreground" copiedLabel="Copied">
|
|
<Copy className="h-3.5 w-3.5" />
|
|
</CopyText>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function WorkspaceLink({
|
|
project,
|
|
workspace,
|
|
}: {
|
|
project: Project;
|
|
workspace: ProjectWorkspace;
|
|
}) {
|
|
return <Link to={projectWorkspaceUrl(project, workspace.id)} className="hover:underline">{workspace.name}</Link>;
|
|
}
|
|
|
|
function ExecutionWorkspaceIssuesList({
|
|
companyId,
|
|
workspace,
|
|
issues,
|
|
isLoading,
|
|
error,
|
|
project,
|
|
}: {
|
|
companyId: string;
|
|
workspace: ExecutionWorkspace;
|
|
issues: Issue[];
|
|
isLoading: boolean;
|
|
error: Error | null;
|
|
project: Project | null;
|
|
}) {
|
|
const queryClient = useQueryClient();
|
|
|
|
const { data: agents } = useQuery({
|
|
queryKey: queryKeys.agents.list(companyId),
|
|
queryFn: () => agentsApi.list(companyId),
|
|
enabled: !!companyId,
|
|
});
|
|
|
|
const liveRunsQueryKey = queryKeys.liveRuns(companyId);
|
|
const sharedLiveRuns = useSharedPollingQuery({
|
|
companyId,
|
|
resourceKey: "live-runs",
|
|
queryKey: liveRunsQueryKey,
|
|
enabled: !!companyId,
|
|
// Event-sourced via LiveUpdatesProvider (issue 9627); no interval poll needed.
|
|
refetchInterval: false,
|
|
leaderOnly: true,
|
|
});
|
|
const { data: liveRuns, dataUpdatedAt: liveRunsUpdatedAt } = useQuery({
|
|
queryKey: liveRunsQueryKey,
|
|
queryFn: () => heartbeatsApi.liveRunsForCompany(companyId),
|
|
enabled: sharedLiveRuns.enabled,
|
|
refetchInterval: sharedLiveRuns.refetchInterval,
|
|
});
|
|
usePublishSharedQueryData(sharedLiveRuns, liveRuns, liveRunsUpdatedAt);
|
|
|
|
const liveIssueIds = useMemo(() => collectLiveIssueIds(liveRuns, issues), [issues, liveRuns]);
|
|
|
|
const updateIssue = useUpdateIssueMutation({
|
|
companyId,
|
|
invalidateKeys: [
|
|
queryKeys.issues.listByExecutionWorkspace(companyId, workspace.id),
|
|
queryKeys.issues.list(companyId),
|
|
...(project?.id ? [queryKeys.issues.listByProject(companyId, project.id)] : []),
|
|
],
|
|
});
|
|
|
|
const projectOptions = useMemo(
|
|
() => (project ? [{ id: project.id, name: project.name, workspaces: project.workspaces ?? [] }] : undefined),
|
|
[project],
|
|
);
|
|
const createIssueDefaults = useMemo(
|
|
() => ({
|
|
projectId: workspace.projectId,
|
|
...(workspace.projectWorkspaceId ? { projectWorkspaceId: workspace.projectWorkspaceId } : {}),
|
|
executionWorkspaceId: workspace.id,
|
|
executionWorkspaceMode: "reuse_existing",
|
|
}),
|
|
[workspace.id, workspace.projectId, workspace.projectWorkspaceId],
|
|
);
|
|
|
|
return (
|
|
<IssuesList
|
|
issues={issues}
|
|
isLoading={isLoading}
|
|
error={error}
|
|
agents={agents}
|
|
projects={projectOptions}
|
|
liveIssueIds={liveIssueIds}
|
|
projectId={project?.id}
|
|
viewStateKey="paperclip:execution-workspace-issues-view"
|
|
baseCreateIssueDefaults={createIssueDefaults}
|
|
onUpdateIssue={(id, data) => updateIssue.mutate({ id, data })}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function WorkspaceRoutineRow({
|
|
routine,
|
|
variableNames,
|
|
runningRoutineId,
|
|
onRunNow,
|
|
}: {
|
|
routine: RoutineListItem;
|
|
variableNames: string[];
|
|
runningRoutineId: string | null;
|
|
onRunNow: (routine: RoutineListItem) => void;
|
|
}) {
|
|
const isArchived = routine.status === "archived";
|
|
const isRunning = runningRoutineId === routine.id;
|
|
|
|
return (
|
|
<div className="flex flex-col gap-3 border-b border-border px-3 py-3 last:border-b-0 sm:flex-row sm:items-center">
|
|
<div className="min-w-0 flex-1 space-y-1.5">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<Link to={`/routines/${routine.id}`} className="truncate text-sm font-medium hover:underline">
|
|
{routine.title}
|
|
</Link>
|
|
{routine.status !== "active" ? (
|
|
<span className="text-xs text-muted-foreground">{routine.status}</span>
|
|
) : null}
|
|
</div>
|
|
<div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground">
|
|
<span>{routine.assigneeAgentId ? "Default agent set" : "Choose agent when running"}</span>
|
|
<span>Last run {formatOptionalDateTime(routine.lastRun?.triggeredAt ?? routine.lastTriggeredAt)}</span>
|
|
<span className="flex flex-wrap gap-1">
|
|
{variableNames.map((name) => (
|
|
<span key={name} className="rounded-sm bg-muted px-1.5 py-0.5 font-mono text-(length:--text-micro) text-muted-foreground">
|
|
{name}
|
|
</span>
|
|
))}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="w-full sm:w-auto"
|
|
disabled={isArchived || isRunning}
|
|
onClick={() => onRunNow(routine)}
|
|
>
|
|
{isRunning ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : <Play className="mr-2 h-4 w-4" />}
|
|
{isRunning ? "Running..." : "Run now"}
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function ExecutionWorkspaceRoutinesList({
|
|
workspace,
|
|
project,
|
|
}: {
|
|
workspace: ExecutionWorkspace;
|
|
project: Project | null;
|
|
}) {
|
|
const queryClient = useQueryClient();
|
|
const { pushToast } = useToastActions();
|
|
const [runDialogRoutine, setRunDialogRoutine] = useState<RoutineListItem | null>(null);
|
|
const [runningRoutineId, setRunningRoutineId] = useState<string | null>(null);
|
|
|
|
const routinesQuery = useQuery({
|
|
queryKey: queryKeys.routines.list(workspace.companyId, { projectId: workspace.projectId }),
|
|
queryFn: () => routinesApi.list(workspace.companyId, { projectId: workspace.projectId }),
|
|
});
|
|
// Read the routine list through the shared view: cached rows stay usable
|
|
// during a transient refetch failure,and a no-data failure shows readable
|
|
// copy with Retry.
|
|
const routinesView = useQueryView(routinesQuery);
|
|
|
|
const { data: agents } = useQuery({
|
|
queryKey: queryKeys.agents.list(workspace.companyId),
|
|
queryFn: () => agentsApi.list(workspace.companyId),
|
|
});
|
|
|
|
const workspaceRoutines = useMemo(
|
|
() => sortWorkspaceRoutinesByName((routinesQuery.data ?? []).filter(routineHasWorkspaceSpecificVariables)),
|
|
[routinesQuery.data],
|
|
);
|
|
|
|
const runRoutine = useMutation({
|
|
mutationFn: ({ id, data }: { id: string; data?: RoutineRunDialogSubmitData }) => routinesApi.run(id, {
|
|
...(data?.variables && Object.keys(data.variables).length > 0 ? { variables: data.variables } : {}),
|
|
...(data?.assigneeAgentId !== undefined ? { assigneeAgentId: data.assigneeAgentId } : {}),
|
|
...(data?.projectId !== undefined ? { projectId: data.projectId } : {}),
|
|
...(data?.executionWorkspaceId !== undefined ? { executionWorkspaceId: data.executionWorkspaceId } : {}),
|
|
...(data?.executionWorkspacePreference !== undefined
|
|
? { executionWorkspacePreference: data.executionWorkspacePreference }
|
|
: {}),
|
|
...(data?.executionWorkspaceSettings !== undefined
|
|
? { executionWorkspaceSettings: data.executionWorkspaceSettings }
|
|
: {}),
|
|
}),
|
|
onMutate: ({ id }) => {
|
|
setRunningRoutineId(id);
|
|
},
|
|
onSuccess: async (_, { id }) => {
|
|
setRunDialogRoutine(null);
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({ queryKey: ["routines", workspace.companyId] }),
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.routines.detail(id) }),
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.issues.listByExecutionWorkspace(workspace.companyId, workspace.id) }),
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.issues.list(workspace.companyId) }),
|
|
]);
|
|
pushToast({
|
|
title: "Routine started",
|
|
body: "Paperclip created a run using this execution workspace.",
|
|
tone: "success",
|
|
});
|
|
},
|
|
onSettled: () => {
|
|
setRunningRoutineId(null);
|
|
},
|
|
onError: (mutationError) => {
|
|
pushToast({
|
|
title: "Routine run failed",
|
|
body: describeError(mutationError).body,
|
|
tone: "error",
|
|
});
|
|
},
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<Card className="rounded-none">
|
|
<CardHeader>
|
|
<CardTitle>Workspace routines</CardTitle>
|
|
<CardDescription>
|
|
Routines that use workspace-specific variables can be run against this execution workspace.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{routinesView.kind === "loading" || routinesView.kind === "reconnecting" ? (
|
|
<p className="text-sm text-muted-foreground">Loading routines...</p>
|
|
) : routinesView.kind === "error" ? (
|
|
<QueryErrorState
|
|
size="inline"
|
|
error={routinesView.error}
|
|
action="load workspace routines"
|
|
onRetry={routinesView.retry}
|
|
retrying={routinesView.isFetching}
|
|
/>
|
|
) : workspaceRoutines.length === 0 ? (
|
|
<div className="flex flex-col items-center gap-2 py-10 text-center">
|
|
<Repeat className="h-5 w-5 text-muted-foreground" />
|
|
<p className="text-sm text-muted-foreground">
|
|
No routines use workspace-specific variables yet.
|
|
</p>
|
|
</div>
|
|
) : (
|
|
<div className="rounded-lg border border-border">
|
|
{workspaceRoutines.map((routine) => (
|
|
<WorkspaceRoutineRow
|
|
key={routine.id}
|
|
routine={routine}
|
|
variableNames={getWorkspaceSpecificRoutineVariableNames(routine)}
|
|
runningRoutineId={runningRoutineId}
|
|
onRunNow={setRunDialogRoutine}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<RoutineRunVariablesDialog
|
|
open={runDialogRoutine !== null}
|
|
onOpenChange={(next) => {
|
|
if (!next) setRunDialogRoutine(null);
|
|
}}
|
|
companyId={workspace.companyId}
|
|
routineName={runDialogRoutine?.title ?? null}
|
|
agents={agents ?? []}
|
|
projects={project ? [project] : []}
|
|
defaultProjectId={workspace.projectId}
|
|
defaultAssigneeAgentId={runDialogRoutine?.assigneeAgentId ?? null}
|
|
defaultExecutionWorkspace={workspace}
|
|
variables={runDialogRoutine?.variables ?? []}
|
|
isPending={runRoutine.isPending}
|
|
onSubmit={(data) => {
|
|
if (!runDialogRoutine) return;
|
|
runRoutine.mutate({ id: runDialogRoutine.id, data });
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export function ExecutionWorkspaceDetail() {
|
|
const { visible: workspaceIsolationControlsVisible, loaded: workspaceVisibilityLoaded } = useWorkspaceIsolationControls();
|
|
const { workspaceId } = useParams<{ workspaceId: string }>();
|
|
const location = useLocation();
|
|
const navigate = useNavigate();
|
|
const queryClient = useQueryClient();
|
|
const { setBreadcrumbs } = useBreadcrumbs();
|
|
const { selectedCompanyId, setSelectedCompanyId } = useCompany();
|
|
const { hideHostPaths } = useManagedSandboxOnly();
|
|
const [form, setForm] = useState<WorkspaceFormState | null>(null);
|
|
const [closeDialogOpen, setCloseDialogOpen] = useState(false);
|
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
|
const [runtimeActionErrorMessage, setRuntimeActionErrorMessage] = useState<string | null>(null);
|
|
const [runtimeActionMessage, setRuntimeActionMessage] = useState<string | null>(null);
|
|
const [pendingRuntimeActions, setPendingRuntimeActions] = useState<WorkspaceRuntimeControlRequest[]>([]);
|
|
const activeRouteTab = workspaceId ? resolveExecutionWorkspaceTab(location.pathname, workspaceId) : null;
|
|
const pluginTabFromSearch = useMemo(() => {
|
|
const tab = new URLSearchParams(location.search).get("tab");
|
|
return isExecutionWorkspacePluginTab(tab) ? tab : null;
|
|
}, [location.search]);
|
|
const activeTab: ExecutionWorkspaceTab | null = activeRouteTab ?? pluginTabFromSearch;
|
|
|
|
const workspaceQuery = useQuery({
|
|
queryKey: queryKeys.executionWorkspaces.detail(workspaceId!),
|
|
queryFn: () => executionWorkspacesApi.get(workspaceId!),
|
|
enabled: Boolean(workspaceId),
|
|
});
|
|
const workspaceView = useQueryView(workspaceQuery);
|
|
const workspace = workspaceQuery.data ?? null;
|
|
|
|
const projectQuery = useQuery({
|
|
queryKey: workspace?.projectId ? [...queryKeys.projects.detail(workspace.projectId), workspace.companyId] : ["projects", "detail", "__pending__"],
|
|
queryFn: () => projectsApi.get(workspace!.projectId!, workspace!.companyId),
|
|
enabled: Boolean(workspace?.projectId),
|
|
});
|
|
const project = projectQuery.data ?? null;
|
|
|
|
const sourceIssueQuery = useQuery({
|
|
queryKey: workspace?.sourceIssueId ? queryKeys.issues.detail(workspace.sourceIssueId) : ["issues", "detail", "__none__"],
|
|
queryFn: () => issuesApi.get(workspace!.sourceIssueId!),
|
|
enabled: Boolean(workspace?.sourceIssueId),
|
|
});
|
|
const sourceIssue = sourceIssueQuery.data ?? null;
|
|
|
|
const derivedWorkspaceQuery = useQuery({
|
|
queryKey: workspace?.derivedFromExecutionWorkspaceId
|
|
? queryKeys.executionWorkspaces.detail(workspace.derivedFromExecutionWorkspaceId)
|
|
: ["execution-workspaces", "detail", "__none__"],
|
|
queryFn: () => executionWorkspacesApi.get(workspace!.derivedFromExecutionWorkspaceId!),
|
|
enabled: Boolean(workspace?.derivedFromExecutionWorkspaceId),
|
|
});
|
|
const derivedWorkspace = derivedWorkspaceQuery.data ?? null;
|
|
const linkedIssuesQuery = useQuery({
|
|
queryKey: workspace
|
|
? queryKeys.issues.listByExecutionWorkspace(workspace.companyId, workspace.id)
|
|
: ["issues", "__execution-workspace__", "__none__"],
|
|
queryFn: () => issuesApi.list(workspace!.companyId, { executionWorkspaceId: workspace!.id }),
|
|
enabled: Boolean(workspace?.companyId),
|
|
});
|
|
const linkedIssuesView = useQueryView(linkedIssuesQuery);
|
|
const linkedIssues = linkedIssuesQuery.data ?? [];
|
|
|
|
const linkedProjectWorkspace = useMemo(
|
|
() => project?.workspaces.find((item) => item.id === workspace?.projectWorkspaceId) ?? null,
|
|
[project, workspace?.projectWorkspaceId],
|
|
);
|
|
|
|
const {
|
|
slots: workspacePluginDetailSlots,
|
|
isLoading: workspacePluginDetailSlotsLoading,
|
|
errorMessage: workspacePluginDetailSlotsError,
|
|
} = usePluginSlots({
|
|
slotTypes: ["detailTab"],
|
|
entityType: "execution_workspace",
|
|
companyId: workspace?.companyId ?? null,
|
|
enabled: !!workspace?.companyId,
|
|
});
|
|
const workspacePluginTabItems = useMemo(
|
|
() => workspacePluginDetailSlots.map((slot) => ({
|
|
value: `plugin:${slot.pluginKey}:${slot.id}` as ExecutionWorkspacePluginTab,
|
|
label: slot.displayName,
|
|
order: slot.order ?? DEFAULT_PLUGIN_DETAIL_TAB_ORDER,
|
|
slot,
|
|
})),
|
|
[workspacePluginDetailSlots],
|
|
);
|
|
const workspaceTabItems = useMemo(
|
|
() => orderExecutionWorkspaceTabItems([
|
|
...EXECUTION_WORKSPACE_BASE_TAB_ITEMS.filter((item) => item.value !== "configuration" || workspaceIsolationControlsVisible),
|
|
...workspacePluginTabItems,
|
|
]),
|
|
[workspacePluginTabItems, workspaceIsolationControlsVisible],
|
|
);
|
|
const inheritedRuntimeConfig = linkedProjectWorkspace?.runtimeConfig?.workspaceRuntime ?? null;
|
|
const effectiveRuntimeConfig = workspace?.config?.workspaceRuntime ?? inheritedRuntimeConfig;
|
|
const runtimeConfigSource =
|
|
workspace?.config?.workspaceRuntime
|
|
? "execution_workspace"
|
|
: inheritedRuntimeConfig
|
|
? "project_workspace"
|
|
: "none";
|
|
|
|
const configuredRuntimeConfig = useMemo(() => {
|
|
if (!form || form.inheritRuntime) return inheritedRuntimeConfig;
|
|
const parsed = parseWorkspaceRuntimeJson(form.workspaceRuntime);
|
|
return parsed.ok ? parsed.value : null;
|
|
}, [form, inheritedRuntimeConfig]);
|
|
const configuredRuntimeServicePorts = useMemo(
|
|
() => readConfiguredRuntimeServicePorts(configuredRuntimeConfig),
|
|
[configuredRuntimeConfig],
|
|
);
|
|
const configuredRuntimeServicePortWarnings = useMemo(
|
|
() => getConfiguredRuntimeServicePortWarnings(configuredRuntimeServicePorts),
|
|
[configuredRuntimeServicePorts],
|
|
);
|
|
|
|
const initialState = useMemo(() => (workspace ? formStateFromWorkspace(workspace) : null), [workspace]);
|
|
const isDirty = Boolean(form && initialState && JSON.stringify(form) !== JSON.stringify(initialState));
|
|
const projectRef = project ? projectRouteRef(project) : workspace?.projectId ?? "";
|
|
|
|
useEffect(() => {
|
|
if (!workspace?.companyId || workspace.companyId === selectedCompanyId) return;
|
|
setSelectedCompanyId(workspace.companyId, { source: "route_sync" });
|
|
}, [workspace?.companyId, selectedCompanyId, setSelectedCompanyId]);
|
|
|
|
useEffect(() => {
|
|
if (!workspace) return;
|
|
setForm(formStateFromWorkspace(workspace));
|
|
setErrorMessage(null);
|
|
setRuntimeActionErrorMessage(null);
|
|
setPendingRuntimeActions([]);
|
|
}, [workspace]);
|
|
|
|
useEffect(() => {
|
|
if (!workspace) return;
|
|
const crumbs = [
|
|
{ label: "Projects", href: "/projects" },
|
|
...(project ? [{ label: project.name, href: `/projects/${projectRef}` }] : []),
|
|
...(project ? [{ label: "Workspaces", href: `/projects/${projectRef}/workspaces` }] : []),
|
|
{ label: workspace.name },
|
|
];
|
|
setBreadcrumbs(crumbs);
|
|
}, [setBreadcrumbs, workspace, project, projectRef]);
|
|
|
|
const updateWorkspace = useMutation({
|
|
mutationFn: (patch: Record<string, unknown>) => executionWorkspacesApi.update(workspace!.id, patch),
|
|
onSuccess: (nextWorkspace) => {
|
|
queryClient.setQueryData(queryKeys.executionWorkspaces.detail(nextWorkspace.id), nextWorkspace);
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.executionWorkspaces.closeReadiness(nextWorkspace.id) });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.executionWorkspaces.workspaceOperations(nextWorkspace.id) });
|
|
if (project) {
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.projects.detail(project.id) });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.projects.detail(project.urlKey) });
|
|
}
|
|
if (sourceIssue) {
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.issues.detail(sourceIssue.id) });
|
|
}
|
|
setErrorMessage(null);
|
|
},
|
|
onError: (error) => {
|
|
setErrorMessage(describeError(error).body);
|
|
},
|
|
});
|
|
const workspaceOperationsQuery = useQuery({
|
|
queryKey: queryKeys.executionWorkspaces.workspaceOperations(workspaceId!),
|
|
queryFn: () => executionWorkspacesApi.listWorkspaceOperations(workspaceId!),
|
|
enabled: Boolean(workspaceId),
|
|
});
|
|
// Read workspace operations through the shared view: cached rows stay
|
|
// visible during a transient refetch failure,and a no-data failure shows
|
|
// readable copy with Retry.
|
|
|
|
const opsView = useQueryView(workspaceOperationsQuery);
|
|
const runtimeProvisionCommand =
|
|
workspace?.config?.runtimeProvisionCommand
|
|
?? project?.executionWorkspacePolicy?.workspaceStrategy?.runtimeProvisionCommand
|
|
?? null;
|
|
const runtimeProvisionStatus = useMemo(
|
|
() =>
|
|
resolveRuntimeProvisionStatus({
|
|
runtimeProvisionCommand,
|
|
operations: workspaceOperationsQuery.data,
|
|
}),
|
|
[runtimeProvisionCommand, workspaceOperationsQuery.data],
|
|
);
|
|
const controlRuntimeServices = useMutation({
|
|
mutationFn: (request: WorkspaceRuntimeControlRequest) =>
|
|
executionWorkspacesApi.controlRuntimeCommands(workspace!.id, request.action, request),
|
|
onSuccess: (result, request) => {
|
|
queryClient.setQueryData(queryKeys.executionWorkspaces.detail(result.workspace.id), result.workspace);
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.executionWorkspaces.overview(result.workspace.companyId) });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.executionWorkspaces.workspaceOperations(result.workspace.id) });
|
|
if (result.workspace.projectId) queryClient.invalidateQueries({ queryKey: queryKeys.projects.detail(result.workspace.projectId) });
|
|
setRuntimeActionErrorMessage(null);
|
|
setRuntimeActionMessage(
|
|
request.action === "run"
|
|
? "Workspace job completed."
|
|
: request.action === "stop"
|
|
? "Workspace service stopped."
|
|
: request.action === "restart"
|
|
? "Workspace service restarted."
|
|
: "Workspace service started.",
|
|
);
|
|
},
|
|
onError: (error) => {
|
|
setRuntimeActionMessage(null);
|
|
setRuntimeActionErrorMessage(describeError(error).body);
|
|
},
|
|
onSettled: (_result, _error, request) => {
|
|
setPendingRuntimeActions((current) => current.filter((pendingRequest) => pendingRequest !== request));
|
|
},
|
|
});
|
|
|
|
if (workspaceQuery.isLoading || workspaceView.kind === "reconnecting") {
|
|
return <p className="text-sm text-muted-foreground">Loading workspace…</p>;
|
|
}
|
|
if (workspaceView.kind === "error") {
|
|
return (
|
|
<QueryErrorState
|
|
size="page"
|
|
error={workspaceQuery.error}
|
|
action="load this workspace"
|
|
onRetry={workspaceView.retry}
|
|
retrying={workspaceView.isFetching}
|
|
/>
|
|
);
|
|
}
|
|
if (!workspace || !form || !initialState) return null;
|
|
|
|
const canRunWorkspaceCommands = Boolean(workspace.cwd);
|
|
const canStartRuntimeServices = Boolean(effectiveRuntimeConfig) && canRunWorkspaceCommands;
|
|
const runtimeControlSections = buildWorkspaceRuntimeControlSections({
|
|
runtimeConfig: effectiveRuntimeConfig,
|
|
runtimeServices: workspace.runtimeServices ?? [],
|
|
canStartServices: canStartRuntimeServices,
|
|
canRunJobs: canRunWorkspaceCommands,
|
|
});
|
|
const pendingRuntimeAction = controlRuntimeServices.isPending ? controlRuntimeServices.variables ?? null : null;
|
|
const serviceControlEntries = buildWorkspaceServiceControlEntries({
|
|
sections: runtimeControlSections,
|
|
runtimeServices: workspace.runtimeServices ?? [],
|
|
pendingRequests: pendingRuntimeActions,
|
|
});
|
|
const pluginSlotContext = {
|
|
companyId: workspace.companyId,
|
|
projectId: workspace.projectId,
|
|
entityId: workspace.id,
|
|
entityType: "execution_workspace" as const,
|
|
};
|
|
const activePluginTab = workspacePluginTabItems.find((item) => item.value === activeTab) ?? null;
|
|
|
|
if (activeTab === "configuration" && !workspaceVisibilityLoaded) return null;
|
|
if (workspaceId && activeTab === "configuration" && !workspaceIsolationControlsVisible) {
|
|
return <LegacyWorkspaceTabRedirect workspaceId={workspaceId} />;
|
|
}
|
|
|
|
if (workspaceId && activeTab === null) {
|
|
return <LegacyWorkspaceTabRedirect workspaceId={workspaceId} />;
|
|
}
|
|
|
|
const handleTabChange = (tab: ExecutionWorkspaceTab) => {
|
|
if (isExecutionWorkspacePluginTab(tab)) {
|
|
navigate(`/execution-workspaces/${workspace.id}?tab=${encodeURIComponent(tab)}`);
|
|
return;
|
|
}
|
|
navigate(executionWorkspaceTabPath(workspace.id, tab));
|
|
};
|
|
|
|
const saveChanges = () => {
|
|
const validationError = validateForm(form);
|
|
if (validationError) {
|
|
setErrorMessage(validationError);
|
|
return;
|
|
}
|
|
|
|
let patch: Record<string, unknown> = {};
|
|
try {
|
|
patch = buildWorkspacePatch(initialState, form);
|
|
} catch (error) {
|
|
setErrorMessage(describeError(error).body);
|
|
}
|
|
|
|
if (Object.keys(patch).length === 0) return;
|
|
updateWorkspace.mutate(patch);
|
|
};
|
|
|
|
const runRuntimeControlRequests = (requests: WorkspaceRuntimeControlRequest[]) => {
|
|
if (requests.length === 0) return;
|
|
setPendingRuntimeActions((current) => [...current, ...requests]);
|
|
for (const request of requests) controlRuntimeServices.mutate(request);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div className="space-y-4 overflow-hidden sm:space-y-6">
|
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
|
<div className="min-w-0 space-y-2">
|
|
<div className="text-xs font-medium uppercase tracking-(--tracking-eyebrow) text-muted-foreground">
|
|
Execution workspace
|
|
</div>
|
|
<h1 className="truncate text-xl font-semibold sm:text-2xl">{workspace.name}</h1>
|
|
</div>
|
|
<WorkspaceServiceControlBar
|
|
services={serviceControlEntries}
|
|
onAction={(action, serviceKey) => {
|
|
runRuntimeControlRequests(
|
|
resolveWorkspaceServiceControlRequests(runtimeControlSections, action, serviceKey),
|
|
);
|
|
}}
|
|
onViewLogs={() => handleTabChange("runtime_logs")}
|
|
onManageServices={() => handleTabChange("services")}
|
|
/>
|
|
</div>
|
|
{runtimeActionErrorMessage ? <p className="text-sm text-destructive">{runtimeActionErrorMessage}</p> : null}
|
|
{!runtimeActionErrorMessage && runtimeActionMessage ? <p className="text-sm text-muted-foreground">{runtimeActionMessage}</p> : null}
|
|
|
|
<PluginSlotOutlet
|
|
slotTypes={["toolbarButton", "contextMenuItem"]}
|
|
entityType="execution_workspace"
|
|
context={pluginSlotContext}
|
|
className="flex flex-wrap gap-2"
|
|
itemClassName="inline-flex"
|
|
missingBehavior="placeholder"
|
|
/>
|
|
|
|
<Tabs value={activeTab ?? "issues"} onValueChange={(value) => handleTabChange(value as ExecutionWorkspaceTab)}>
|
|
<PageTabBar
|
|
items={workspaceTabItems.map((item) => ({ value: item.value, label: item.label }))}
|
|
align="start"
|
|
value={activeTab ?? "issues"}
|
|
onValueChange={(value) => handleTabChange(value as ExecutionWorkspaceTab)}
|
|
/>
|
|
</Tabs>
|
|
|
|
{activeTab === "services" ? (
|
|
<WorkspaceRuntimeControls
|
|
sections={runtimeControlSections}
|
|
isPending={controlRuntimeServices.isPending}
|
|
pendingRequest={pendingRuntimeAction}
|
|
serviceEmptyMessage={
|
|
effectiveRuntimeConfig
|
|
? "No services have been started for this execution workspace yet."
|
|
: "No workspace command config is defined for this execution workspace yet."
|
|
}
|
|
jobEmptyMessage="No one-shot jobs are configured for this execution workspace yet."
|
|
disabledHint={
|
|
canStartRuntimeServices
|
|
? null
|
|
: "Execution workspaces need a working directory before local commands can run, and services also need runtime config."
|
|
}
|
|
onAction={(request) => runRuntimeControlRequests([request])}
|
|
/>
|
|
) : activeTab === "configuration" ? (
|
|
<div className="space-y-4 sm:space-y-6">
|
|
<Card className="rounded-none">
|
|
<CardHeader>
|
|
<CardTitle>Workspace settings</CardTitle>
|
|
<CardDescription>
|
|
Edit the concrete path, repo, branch, provisioning, teardown, and runtime overrides attached to this execution workspace. Saved changes affect future runs; Paperclip may refresh or replace a reused workspace when config changes.
|
|
</CardDescription>
|
|
<CardAction>
|
|
<Button
|
|
variant="destructive"
|
|
size="sm"
|
|
className="w-full sm:w-auto"
|
|
onClick={() => setCloseDialogOpen(true)}
|
|
disabled={workspace.status === "archived"}
|
|
>
|
|
{workspace.status === "cleanup_failed" ? "Retry close" : "Close workspace"}
|
|
</Button>
|
|
</CardAction>
|
|
</CardHeader>
|
|
|
|
<CardContent>
|
|
|
|
<div className="space-y-6">
|
|
<div className="space-y-4">
|
|
<div className="text-xs font-medium uppercase tracking-widest text-muted-foreground">General</div>
|
|
<Field label="Workspace name">
|
|
<Input
|
|
value={form.name}
|
|
onChange={(event) => setForm((current) => current ? { ...current, name: event.target.value } : current)}
|
|
placeholder="Execution workspace name"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
|
|
<Separator />
|
|
|
|
<div className="space-y-4">
|
|
<div className="text-xs font-medium uppercase tracking-widest text-muted-foreground">Source control</div>
|
|
<div className="grid gap-4 sm:grid-cols-2">
|
|
<Field label="Branch name" hint="Useful for isolated worktrees">
|
|
<Input
|
|
className="font-mono"
|
|
value={form.branchName}
|
|
onChange={(event) => setForm((current) => current ? { ...current, branchName: event.target.value } : current)}
|
|
placeholder="PAP-946-workspace"
|
|
/>
|
|
</Field>
|
|
|
|
<Field label="Base ref">
|
|
<Input
|
|
className="font-mono"
|
|
value={form.baseRef}
|
|
onChange={(event) => setForm((current) => current ? { ...current, baseRef: event.target.value } : current)}
|
|
placeholder="origin/main"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
|
|
<Field label="Repo URL">
|
|
<Input
|
|
value={form.repoUrl}
|
|
onChange={(event) => setForm((current) => current ? { ...current, repoUrl: event.target.value } : current)}
|
|
placeholder="https://github.com/org/repo"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
|
|
<Separator />
|
|
|
|
{/*
|
|
Both fields name a path on the execution host. Under the
|
|
managed-sandbox-only policy every agent runs in the
|
|
platform-managed environment, which owns the paths, so the
|
|
whole group and its separator disappear, and stay hidden
|
|
until that policy is known.
|
|
*/}
|
|
{!hideHostPaths && (
|
|
<>
|
|
<div className="space-y-4">
|
|
<div className="text-xs font-medium uppercase tracking-widest text-muted-foreground">Paths</div>
|
|
<Field label="Working directory">
|
|
<Input
|
|
className="font-mono"
|
|
value={form.cwd}
|
|
onChange={(event) => setForm((current) => current ? { ...current, cwd: event.target.value } : current)}
|
|
placeholder="/absolute/path/to/workspace"
|
|
/>
|
|
</Field>
|
|
|
|
<Field label="Provider path / ref">
|
|
<Input
|
|
className="font-mono"
|
|
value={form.providerRef}
|
|
onChange={(event) => setForm((current) => current ? { ...current, providerRef: event.target.value } : current)}
|
|
placeholder="/path/to/worktree or provider ref"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
|
|
<Separator />
|
|
</>
|
|
)}
|
|
|
|
{/*
|
|
Every lifecycle command runs a shell on the execution host and
|
|
its placeholder names a host script path. The platform-managed
|
|
environment owns that lifecycle, so the managed-sandbox-only
|
|
policy hides the group and its separator, and keeps them
|
|
hidden until that policy is known.
|
|
*/}
|
|
{!hideHostPaths && (
|
|
<>
|
|
<div className="space-y-4">
|
|
<div className="text-xs font-medium uppercase tracking-widest text-muted-foreground">Lifecycle commands</div>
|
|
<Field label="Provision command" hint="Runs when Paperclip prepares this execution workspace">
|
|
<Textarea
|
|
className="min-h-20 font-mono"
|
|
value={form.provisionCommand}
|
|
onChange={(event) => setForm((current) => current ? { ...current, provisionCommand: event.target.value } : current)}
|
|
placeholder="bash ./scripts/provision-worktree.sh"
|
|
/>
|
|
</Field>
|
|
|
|
<Field
|
|
label="Runtime provision command"
|
|
hint="Runs once before the first runtime-service start. Leave empty to keep eager provisioning."
|
|
>
|
|
<Textarea
|
|
className="min-h-20 font-mono"
|
|
value={form.runtimeProvisionCommand}
|
|
onChange={(event) => setForm((current) => current ? { ...current, runtimeProvisionCommand: event.target.value } : current)}
|
|
placeholder="bash ./scripts/provision-worktree-runtime.sh"
|
|
/>
|
|
</Field>
|
|
|
|
<Field label="Teardown command" hint="Runs when the execution workspace is archived or cleaned up">
|
|
<Textarea
|
|
className="min-h-20 font-mono"
|
|
value={form.teardownCommand}
|
|
onChange={(event) => setForm((current) => current ? { ...current, teardownCommand: event.target.value } : current)}
|
|
placeholder="bash ./scripts/teardown-worktree.sh"
|
|
/>
|
|
</Field>
|
|
|
|
<Field label="Cleanup command" hint="Workspace-specific cleanup before teardown">
|
|
<Textarea
|
|
className="min-h-16 font-mono"
|
|
value={form.cleanupCommand}
|
|
onChange={(event) => setForm((current) => current ? { ...current, cleanupCommand: event.target.value } : current)}
|
|
placeholder="pkill -f vite || true"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
|
|
<Separator />
|
|
</>
|
|
)}
|
|
|
|
<div className="space-y-4">
|
|
<div className="text-xs font-medium uppercase tracking-widest text-muted-foreground">Runtime config</div>
|
|
<div className="rounded-md border border-dashed border-border/70 bg-background px-4 py-3">
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between">
|
|
<div className="space-y-1">
|
|
<div className="text-sm font-medium text-foreground">
|
|
Runtime config source
|
|
</div>
|
|
<p className="text-sm text-muted-foreground">
|
|
{runtimeConfigSource === "execution_workspace"
|
|
? "This execution workspace currently overrides the project workspace runtime config."
|
|
: runtimeConfigSource === "project_workspace"
|
|
? "This execution workspace is inheriting the project workspace runtime config."
|
|
: "No runtime config is currently defined on this execution workspace or its project workspace."}
|
|
</p>
|
|
</div>
|
|
<Button
|
|
variant="outline"
|
|
className="w-full sm:w-auto"
|
|
size="sm"
|
|
disabled={!linkedProjectWorkspace?.runtimeConfig?.workspaceRuntime}
|
|
onClick={() =>
|
|
setForm((current) => current ? {
|
|
...current,
|
|
inheritRuntime: true,
|
|
workspaceRuntime: "",
|
|
} : current)
|
|
}
|
|
>
|
|
Reset to inherit
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<details className="rounded-md border border-dashed border-border/70 bg-background px-4 py-3">
|
|
<summary className="cursor-pointer text-sm font-medium">Advanced runtime JSON</summary>
|
|
<p className="mt-2 text-sm text-muted-foreground">
|
|
Override the inherited workspace command model only when this execution workspace truly needs different service or job behavior.
|
|
</p>
|
|
<div className="mt-3">
|
|
<Field label="Workspace commands JSON" hint="Legacy `services` arrays still work, but `commands` supports both services and jobs.">
|
|
<div className="mb-2 flex items-center gap-2 text-sm text-muted-foreground">
|
|
<input
|
|
id="inherit-runtime-config"
|
|
type="checkbox"
|
|
className="rounded border-border"
|
|
checked={form.inheritRuntime}
|
|
onChange={(event) => {
|
|
const checked = event.target.checked;
|
|
setForm((current) => {
|
|
if (!current) return current;
|
|
if (!checked && !current.workspaceRuntime.trim() && inheritedRuntimeConfig) {
|
|
return { ...current, inheritRuntime: checked, workspaceRuntime: formatJson(inheritedRuntimeConfig) };
|
|
}
|
|
return { ...current, inheritRuntime: checked };
|
|
});
|
|
}}
|
|
/>
|
|
<label htmlFor="inherit-runtime-config">Inherit project workspace runtime config</label>
|
|
</div>
|
|
<Textarea
|
|
className="min-h-64 font-mono sm:min-h-96"
|
|
value={form.workspaceRuntime}
|
|
onChange={(event) => setForm((current) => current ? { ...current, workspaceRuntime: event.target.value } : current)}
|
|
disabled={form.inheritRuntime}
|
|
placeholder={'{\n "commands": [\n {\n "id": "web",\n "name": "web",\n "kind": "service",\n "command": "pnpm dev",\n "cwd": ".",\n "port": { "type": "auto" }\n },\n {\n "id": "db-migrate",\n "name": "db:migrate",\n "kind": "job",\n "command": "pnpm db:migrate",\n "cwd": "."\n }\n ]\n}'}
|
|
/>
|
|
</Field>
|
|
</div>
|
|
</details>
|
|
|
|
{configuredRuntimeServicePorts.length > 0 ? (
|
|
<div className="space-y-3 rounded-md border border-border bg-muted/20 p-4">
|
|
<div>
|
|
<div className="text-sm font-medium">Service ports</div>
|
|
<p className="mt-1 text-sm text-muted-foreground">
|
|
Set a fixed port for a service or leave it blank to use its configured automatic behavior. Editing an inherited service creates an execution-workspace runtime override.
|
|
</p>
|
|
</div>
|
|
<div className="grid gap-3 sm:grid-cols-2">
|
|
{configuredRuntimeServicePorts.map((service) => (
|
|
<Field key={`${service.collection}-${service.index}`} label={service.name} hint="Fixed port">
|
|
<Input
|
|
type="number"
|
|
min="1"
|
|
max="65535"
|
|
inputMode="numeric"
|
|
value={service.port ?? ""}
|
|
onChange={(event) => {
|
|
setForm((current) => {
|
|
if (!current) return current;
|
|
const parsed = current.inheritRuntime
|
|
? { ok: true as const, value: inheritedRuntimeConfig }
|
|
: parseWorkspaceRuntimeJson(current.workspaceRuntime);
|
|
if (!parsed.ok || !parsed.value) return current;
|
|
return {
|
|
...current,
|
|
inheritRuntime: false,
|
|
workspaceRuntime: formatJson(updateConfiguredRuntimeServicePort({
|
|
runtimeConfig: parsed.value,
|
|
service,
|
|
port: event.target.value,
|
|
})),
|
|
};
|
|
});
|
|
}}
|
|
/>
|
|
</Field>
|
|
))}
|
|
</div>
|
|
{configuredRuntimeServicePortWarnings.length > 0 ? (
|
|
<div className="rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
|
{configuredRuntimeServicePortWarnings.map((warning) => <p key={warning}>{warning}</p>)}
|
|
</div>
|
|
) : null}
|
|
<p className="text-sm text-muted-foreground">
|
|
Paperclip checks fixed ports again when a service starts and rejects cross-workspace conflicts.
|
|
</p>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="mt-6 flex flex-col items-stretch gap-3 sm:flex-row sm:flex-wrap sm:items-center">
|
|
<Button className="w-full sm:w-auto" disabled={!isDirty || updateWorkspace.isPending} onClick={saveChanges}>
|
|
{updateWorkspace.isPending ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
|
|
Save changes
|
|
</Button>
|
|
<Button
|
|
variant="outline"
|
|
className="w-full sm:w-auto"
|
|
disabled={!isDirty || updateWorkspace.isPending}
|
|
onClick={() => {
|
|
setForm(initialState);
|
|
setErrorMessage(null);
|
|
setRuntimeActionErrorMessage(null);
|
|
setRuntimeActionMessage(null);
|
|
}}
|
|
>
|
|
Reset
|
|
</Button>
|
|
{errorMessage ? <p className="text-sm text-destructive">{errorMessage}</p> : null}
|
|
{!errorMessage && !isDirty ? <p className="text-sm text-muted-foreground">No unsaved changes.</p> : null}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<Card className="rounded-none">
|
|
<CardHeader>
|
|
<CardTitle>Workspace context</CardTitle>
|
|
<CardDescription>Linked objects and relationships</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<DetailRow label="Project">
|
|
{project ? <Link to={`/projects/${projectRef}`} className="hover:underline">{project.name}</Link> : <MonoValue value={workspace.projectId ?? "No project"} />}
|
|
</DetailRow>
|
|
<DetailRow label="Project workspace">
|
|
{project && linkedProjectWorkspace ? (
|
|
<WorkspaceLink project={project} workspace={linkedProjectWorkspace} />
|
|
) : workspace.projectWorkspaceId ? (
|
|
<MonoValue value={workspace.projectWorkspaceId} />
|
|
) : (
|
|
"None"
|
|
)}
|
|
</DetailRow>
|
|
<DetailRow label="Source task">
|
|
{sourceIssue ? (
|
|
<Link to={issueUrl(sourceIssue)} className="hover:underline">
|
|
{sourceIssue.identifier ?? sourceIssue.id} · {sourceIssue.title}
|
|
</Link>
|
|
) : workspace.sourceIssueId ? (
|
|
<MonoValue value={workspace.sourceIssueId} />
|
|
) : (
|
|
"None"
|
|
)}
|
|
</DetailRow>
|
|
<DetailRow label="Derived from">
|
|
{derivedWorkspace ? (
|
|
<Link to={executionWorkspaceTabPath(derivedWorkspace.id, workspaceIsolationControlsVisible ? "configuration" : "issues")} className="hover:underline">
|
|
{derivedWorkspace.name}
|
|
</Link>
|
|
) : workspace.derivedFromExecutionWorkspaceId ? (
|
|
<MonoValue value={workspace.derivedFromExecutionWorkspaceId} />
|
|
) : (
|
|
"None"
|
|
)}
|
|
</DetailRow>
|
|
<DetailRow label="Runtime provisioning">
|
|
<RuntimeProvisionStatusValue
|
|
status={runtimeProvisionStatus}
|
|
onViewLogs={() => handleTabChange("runtime_logs")}
|
|
/>
|
|
</DetailRow>
|
|
<DetailRow label="Workspace ID">
|
|
<MonoValue value={workspace.id} />
|
|
</DetailRow>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<Card className="rounded-none">
|
|
<CardHeader>
|
|
<CardTitle>Concrete location</CardTitle>
|
|
<CardDescription>Paths and refs</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<DetailRow label="Working dir">
|
|
{workspace.cwd ? <MonoValue value={workspace.cwd} copy /> : "None"}
|
|
</DetailRow>
|
|
<DetailRow label="Provider ref">
|
|
{workspace.providerRef ? <MonoValue value={workspace.providerRef} copy /> : "None"}
|
|
</DetailRow>
|
|
<DetailRow label="Repo URL">
|
|
{workspace.repoUrl && isSafeExternalUrl(workspace.repoUrl) ? (
|
|
<div className="inline-flex max-w-full items-start gap-2">
|
|
<a href={workspace.repoUrl} target="_blank" rel="noreferrer" className="inline-flex min-w-0 items-center gap-1 break-all hover:underline">
|
|
{workspace.repoUrl}
|
|
<ExternalLink className="h-3.5 w-3.5 shrink-0" />
|
|
</a>
|
|
<CopyText text={workspace.repoUrl} className="shrink-0 text-muted-foreground hover:text-foreground" copiedLabel="Copied">
|
|
<Copy className="h-3.5 w-3.5" />
|
|
</CopyText>
|
|
</div>
|
|
) : workspace.repoUrl ? (
|
|
<MonoValue value={workspace.repoUrl} copy />
|
|
) : (
|
|
"None"
|
|
)}
|
|
</DetailRow>
|
|
<DetailRow label="Base ref">
|
|
{workspace.baseRef ? <MonoValue value={workspace.baseRef} copy /> : "None"}
|
|
</DetailRow>
|
|
<DetailRow label="Branch">
|
|
{workspace.branchName ? <MonoValue value={workspace.branchName} copy /> : "None"}
|
|
</DetailRow>
|
|
<DetailRow label="Opened">{formatDateTime(workspace.openedAt)}</DetailRow>
|
|
<DetailRow label="Last used">{formatDateTime(workspace.lastUsedAt)}</DetailRow>
|
|
<DetailRow label="Cleanup">
|
|
{workspace.cleanupEligibleAt
|
|
? `${formatDateTime(workspace.cleanupEligibleAt)}${workspace.cleanupReason ? ` · ${workspace.cleanupReason}` : ""}`
|
|
: "Not scheduled"}
|
|
</DetailRow>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
) : activeTab === "runtime_logs" ? (
|
|
<Card className="rounded-none">
|
|
<CardHeader>
|
|
<CardTitle>Runtime and cleanup logs</CardTitle>
|
|
<CardDescription>Recent operations</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{(opsView.kind === "loading" || opsView.kind === "reconnecting") ? (
|
|
<p className="text-sm text-muted-foreground">Loading workspace operations…</p>
|
|
) : opsView.kind === "error" ? (
|
|
<QueryErrorState
|
|
size="inline"
|
|
error={opsView.error}
|
|
action="load workspace operations"
|
|
onRetry={opsView.retry}
|
|
retrying={opsView.isFetching}
|
|
/>
|
|
) : workspaceOperationsQuery.data && workspaceOperationsQuery.data.length > 0 ? (
|
|
<div className="space-y-3">
|
|
{workspaceOperationsQuery.data.map((operation) => (
|
|
<div key={operation.id} className="rounded-none border border-border/80 bg-background px-4 py-3">
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
|
|
<div className="space-y-1">
|
|
<div className="text-sm font-medium">{operation.command ?? workspaceOperationPhaseLabel(operation.phase)}</div>
|
|
<div className="text-xs text-muted-foreground">
|
|
{formatDateTime(operation.startedAt)}
|
|
{operation.finishedAt ? ` → ${formatDateTime(operation.finishedAt)}` : ""}
|
|
</div>
|
|
{operation.stderrExcerpt ? (
|
|
<div className="whitespace-pre-wrap break-words text-xs text-destructive">{operation.stderrExcerpt}</div>
|
|
) : operation.stdoutExcerpt ? (
|
|
<div className="whitespace-pre-wrap break-words text-xs text-muted-foreground">{operation.stdoutExcerpt}</div>
|
|
) : null}
|
|
</div>
|
|
<StatusPill className="self-start">{operation.status}</StatusPill>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">No workspace operations have been recorded yet.</p>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
) : activeTab === "issues" ? (
|
|
<div className="space-y-6">
|
|
<SummarySlotCard
|
|
companyId={workspace.companyId}
|
|
scopeKind="execution_workspace"
|
|
scopeId={workspace.id}
|
|
title="Workspace summary"
|
|
description="Summarizer keeps the latest workspace status, next step, and operator-needed items here."
|
|
/>
|
|
{linkedIssuesView.kind === "error" ? <QueryErrorState error={linkedIssuesView.error} action="load workspace tasks" onRetry={linkedIssuesView.retry} retrying={linkedIssuesView.isFetching} /> : (
|
|
<ExecutionWorkspaceIssuesList
|
|
companyId={workspace.companyId}
|
|
workspace={workspace}
|
|
issues={linkedIssues}
|
|
isLoading={linkedIssuesView.kind === "loading" || linkedIssuesView.kind === "reconnecting"}
|
|
error={null}
|
|
project={project}
|
|
/>
|
|
)}
|
|
</div>
|
|
) : activePluginTab ? (
|
|
<PluginSlotMount
|
|
slot={activePluginTab.slot}
|
|
context={pluginSlotContext}
|
|
missingBehavior="placeholder"
|
|
/>
|
|
) : isExecutionWorkspacePluginTab(activeTab) && workspacePluginDetailSlotsLoading ? (
|
|
<Card>
|
|
<CardContent className="py-6 text-sm text-muted-foreground">Loading workspace plugin...</CardContent>
|
|
</Card>
|
|
) : isExecutionWorkspacePluginTab(activeTab) && workspacePluginDetailSlotsError ? (
|
|
<Card>
|
|
<CardContent className="py-6 text-sm text-destructive">{workspacePluginDetailSlotsError}</CardContent>
|
|
</Card>
|
|
) : isExecutionWorkspacePluginTab(activeTab) ? (
|
|
<MissingPluginTabPlaceholder
|
|
defaultTabHref={executionWorkspaceTabPath(workspace.id, "issues")}
|
|
defaultTabLabel="Back to tasks"
|
|
/>
|
|
) : activeTab === "routines" ? (
|
|
<ExecutionWorkspaceRoutinesList
|
|
workspace={workspace}
|
|
project={project}
|
|
/>
|
|
) : (
|
|
<LegacyWorkspaceTabRedirect workspaceId={workspace.id} />
|
|
)}
|
|
</div>
|
|
<ExecutionWorkspaceCloseDialog
|
|
workspaceId={workspace.id}
|
|
workspaceName={workspace.name}
|
|
currentStatus={workspace.status}
|
|
open={closeDialogOpen}
|
|
onOpenChange={setCloseDialogOpen}
|
|
onClosed={(nextWorkspace) => {
|
|
queryClient.setQueryData(queryKeys.executionWorkspaces.detail(nextWorkspace.id), nextWorkspace);
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.executionWorkspaces.overview(nextWorkspace.companyId) });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.executionWorkspaces.closeReadiness(nextWorkspace.id) });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.executionWorkspaces.workspaceOperations(nextWorkspace.id) });
|
|
if (project) {
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.projects.detail(project.id) });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.executionWorkspaces.list(project.companyId, { projectId: project.id }) });
|
|
}
|
|
if (sourceIssue) {
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.issues.detail(sourceIssue.id) });
|
|
}
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
}
|