From 3568a86a66cdaf5e3d264bf0055f3b02f116084a Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Sat, 18 Jul 2026 12:06:00 -0700 Subject: [PATCH] FN-8284: add organization portability controls Add Command Center tools for safe organization portability and configuration recovery. - Register project-scoped organization export/import and revision rollback routes. - Add localized, responsive Command Center controls for bundle preview, import, and rollback. - Invalidate stale dry-run responses and retain only the exact previewed bundle for import. - Cover portability routes and editing-during-preview behavior with tests. Files changed: docs/dashboard-guide.md | 2 + .../command-center/CommandCenterControls.tsx | 3 + .../command-center/OrgPortabilityControls.css | 81 +++++++++ .../command-center/OrgPortabilityControls.tsx | 184 +++++++++++++++++++++ .../__tests__/CommandCenter.mobile-scroll.test.tsx | 2 + .../__tests__/OrgPortabilityControls.test.tsx | 94 +++++++++++ packages/dashboard/src/routes.ts | 2 + .../register-org-portability-routes.test.ts | 109 ++++++++++++ .../src/routes/register-org-portability-routes.ts | 129 +++++++++++++++ packages/i18n/locales/en/app.json | 37 +++++ 10 files changed, 643 insertions(+) Fusion-Task-Id: FN-8284 Fusion-Task-Lineage: 1fa06550-8064-417f-a8d0-40f693206404 Co-authored-by: Fusion (runfusion.ai) --- docs/dashboard-guide.md | 2 + .../command-center/CommandCenterControls.tsx | 3 + .../command-center/OrgPortabilityControls.css | 81 ++++++++ .../command-center/OrgPortabilityControls.tsx | 184 ++++++++++++++++++ .../CommandCenter.mobile-scroll.test.tsx | 2 + .../__tests__/OrgPortabilityControls.test.tsx | 94 +++++++++ packages/dashboard/src/routes.ts | 2 + .../register-org-portability-routes.test.ts | 109 +++++++++++ .../routes/register-org-portability-routes.ts | 129 ++++++++++++ packages/i18n/locales/en/app.json | 37 ++++ 10 files changed, 643 insertions(+) create mode 100644 packages/dashboard/app/components/command-center/OrgPortabilityControls.css create mode 100644 packages/dashboard/app/components/command-center/OrgPortabilityControls.tsx create mode 100644 packages/dashboard/app/components/command-center/__tests__/OrgPortabilityControls.test.tsx create mode 100644 packages/dashboard/src/routes/__tests__/register-org-portability-routes.test.ts create mode 100644 packages/dashboard/src/routes/register-org-portability-routes.ts diff --git a/docs/dashboard-guide.md b/docs/dashboard-guide.md index 137f31a6fc..d7f41e053b 100644 --- a/docs/dashboard-guide.md +++ b/docs/dashboard-guide.md @@ -1217,6 +1217,8 @@ Features: - **Overview controls dashboard** sits at the top of the Overview landing surface on desktop and mobile. It includes AI engine stop/start backed by `globalPause`, live scheduler status from executor stats, the shared Global Max Concurrent slider backed by `/api/global-concurrency`, range sliders for `maxConcurrent`, `maxTriageConcurrent`, and `maxWorktrees` that persist through `/api/settings`, and a compact theme dropdown with the same color-chip swatches and Shadcn variant list as Settings → Appearance. The four concurrency sliders ask for confirmation after a changed value settles; confirming persists the new cap, while cancel, backdrop, or Escape dismissal reverts to the last persisted value without saving. The global and current-project max-concurrent sliders show running-agent counts plus a current-use dot on the track once utilization data loads; triage and worktree sliders remain cap-only. These controls reuse existing APIs and App-level theme setters; they do not add a new backend route or second theme owner. +- **Org export / import** lets an operator download a portable organization JSON bundle or paste one for a dry-run preview before confirming the apply step. Exports are secret-scrubbed by default: credentials and tokens are never included, while safe secret references can remain for setup in the destination project. +- **Configuration versions** lists recorded project-setting revisions newest first. Select **Roll back** on any revision and confirm once to restore it; the restore is recorded as a new forward revision, so it can itself be undone without manually reconstructing settings. - **Overview** summarizes token usage/cost, autonomy, active nodes, sessions, agent runs, tasks done, model breadth, and real open signals, and includes the SDLC throughput funnel for the selected range at the bottom of the Overview content in loading, error, empty, and populated states. **Codebase tokens** is a local-only `cl100k_base`-calibrated pre-tokenization estimate; it does not upload source content or add a runtime tokenizer. **Disk size** is local apparent size (regular files and symlink entries only, not allocated blocks or directory bookkeeping). Both project-intrinsic cards render even before agent usage settles and show `Approx. (partial)` when bounded traversal is incomplete. Git projects scan non-ignored tracked files; non-git fallback excludes only directories whose basename starts with `.` or is exactly `node_modules`, `dist`, or `build`. Source candidates are lstat-gated regular files (symlinks and out-of-root candidates are skipped); disk walking does not follow symlinks. Defaults cap source scanning at 50,000 entries, 4 seconds, 64 MiB total, and 2 MiB/file, disk walking at 500,000 entries and 4 seconds, and cache results for two minutes. System telemetry now formats small byte quantities granularly as B/KB rather than displaying sub-MB values as 0 MB. Its token total and Live activity snapshot token metric refresh on a bounded live cadence and animate number changes while preserving reduced-motion preferences. The sessions card uses the selected-range `ActivityAnalytics.sessions` value already loaded for the overview. The Live activity snapshot also shows the current board-state count for tasks in progress, independent of the selected analytics date range. Overview's active-agent and daily activity values count durable-agent usage events plus ephemeral task-worker execution runs, including graph-owned workflow step sessions that publish `agentRuns` lifecycle rows, with the same agent counted once per day/range if both sources record activity. Overview includes a graph-rich software-factory snapshot with the existing top-model-consumers bar, tool-category bar, top-model token-share pie, and the daily activity multi-series line chart placed before the daily activity sparkline/trend so the richer line graph sits higher in the chart grid. These reuse the already-loaded tokens, tools, activity, and signals analytics; the signals count comes from `/api/command-center/signals` and renders unavailable (`—`) while the incidents-backed response is loading or unavailable. The chart reveal/glow accents are decorative and disabled when reduced-motion preferences are active. The SDLC completion rate is shown as a radial gauge and is calculated as cohort conversion from in-range triage entrants, so the rate is capped at 100% even when older tasks finish during the range. diff --git a/packages/dashboard/app/components/command-center/CommandCenterControls.tsx b/packages/dashboard/app/components/command-center/CommandCenterControls.tsx index 6691da99f6..c6f1de8f23 100644 --- a/packages/dashboard/app/components/command-center/CommandCenterControls.tsx +++ b/packages/dashboard/app/components/command-center/CommandCenterControls.tsx @@ -8,6 +8,7 @@ import { useConfirm } from "../../hooks/useConfirm"; // FNXC:GlobalConcurrencyControls 2026-06-25-22:45: Concurrency card adopts the shared global-concurrency hook so it and the footer EngineControlMenu read/write ONE source of truth (no more duplicated fetch/debounce/clobber logic). import { useGlobalConcurrency } from "../../hooks/useGlobalConcurrency"; import { ThemeDropdown } from "../ThemeDropdown"; +import { OrgPortabilityControls } from "./OrgPortabilityControls"; import type { TaskView } from "../../hooks/useViewState"; import "./CommandCenterControls.css"; @@ -388,6 +389,8 @@ export function CommandCenterControls({ projectId, colorTheme, themeMode, shadcn /> + +
diff --git a/packages/dashboard/app/components/command-center/OrgPortabilityControls.css b/packages/dashboard/app/components/command-center/OrgPortabilityControls.css new file mode 100644 index 0000000000..ac51f009a2 --- /dev/null +++ b/packages/dashboard/app/components/command-center/OrgPortabilityControls.css @@ -0,0 +1,81 @@ +/* +FNXC:CommandCenterConfig 2026-07-18-12:00: +The portability and history cards remain in the existing control grid on desktop +and collapse to one column at the Command Center mobile breakpoint. Shared +buttons retain the established token-based touch target instead of adding a +parallel control variant. +*/ +.cc-portability-card { + display: flex; + flex-direction: column; + gap: var(--space-sm); +} + +.cc-portability-card--versions { + grid-column: 1 / -1; +} + +.cc-portability-actions { + display: flex; + flex-wrap: wrap; + gap: var(--space-sm); +} + +.cc-portability-import-label { + color: var(--text); + font-size: 0.8125rem; +} + +.cc-portability-import-input { + min-block-size: calc(var(--space-2xl) * 3); + resize: vertical; +} + +.cc-portability-version-list { + display: grid; + gap: var(--space-sm); + margin: 0; + padding: 0; + list-style: none; +} + +.cc-portability-version { + display: flex; + align-items: center; + justify-content: space-between; + gap: var(--space-md); + padding-block: var(--space-sm); + border-block-end: 1px solid var(--border-subtle); +} + +.cc-portability-version span { + display: grid; + gap: var(--space-xs); + min-inline-size: 0; +} + +.cc-portability-version strong { + color: var(--text); + font-size: 0.8125rem; +} + +.cc-portability-version small { + color: var(--text-muted); + font-size: 0.75rem; +} + +@media (max-width: 768px) { + .cc-portability-actions { + flex-direction: column; + } + + .cc-portability-actions .cc-controls-action { + inline-size: 100%; + justify-content: center; + } + + .cc-portability-version { + align-items: stretch; + flex-direction: column; + } +} diff --git a/packages/dashboard/app/components/command-center/OrgPortabilityControls.tsx b/packages/dashboard/app/components/command-center/OrgPortabilityControls.tsx new file mode 100644 index 0000000000..02e902c7ab --- /dev/null +++ b/packages/dashboard/app/components/command-center/OrgPortabilityControls.tsx @@ -0,0 +1,184 @@ +import { useEffect, useRef, useState } from "react"; +import { Download, RotateCcw, Upload } from "lucide-react"; +import { useTranslation } from "react-i18next"; +import { api, withProjectId } from "../../api/legacy"; +import { useConfirm } from "../../hooks/useConfirm"; +import "./OrgPortabilityControls.css"; + +interface ConfigurationRevision { + id: string; + configKind: string; + createdAt: string; + source: "mutation" | "rollback"; + changedBy?: { kind?: string; id?: string }; +} + +interface OrgPortabilityControlsProps { + projectId?: string; + onSettingsRefresh: () => Promise; +} + +function downloadBundle(bundle: unknown) { + const href = URL.createObjectURL(new Blob([JSON.stringify(bundle, null, 2)], { type: "application/json" })); + const link = document.createElement("a"); + link.href = href; + link.download = "fusion-org-bundle.json"; + link.click(); + URL.revokeObjectURL(href); +} + +/* +FNXC:CommandCenterConfig 2026-07-18-12:00: +FR-05 puts portable org handoff and safe configuration undo beside operator +controls. Import accepts the core's secret-scrubbed bundle only, and rollback is +a single confirmed restore action rather than a manual reconstruction workflow. +*/ +export function OrgPortabilityControls({ projectId, onSettingsRefresh }: OrgPortabilityControlsProps) { + const { t } = useTranslation("app"); + const { confirm } = useConfirm(); + const [exportState, setExportState] = useState<"idle" | "working" | "success" | "error">("idle"); + const [importState, setImportState] = useState<"idle" | "previewing" | "previewed" | "importing" | "success" | "error">("idle"); + const [bundleText, setBundleText] = useState(""); + const [importError, setImportError] = useState(null); + const [preview, setPreview] = useState(null); + const [previewedBundle, setPreviewedBundle] = useState | null>(null); + const bundleVersion = useRef(0); + const [revisions, setRevisions] = useState(null); + const [revisionsError, setRevisionsError] = useState(null); + const [rollbackId, setRollbackId] = useState(null); + + const revisionPath = withProjectId("/config/revisions", projectId); + const loadRevisions = async () => { + try { + setRevisionsError(null); + const response = await api<{ revisions?: ConfigurationRevision[] }>(revisionPath); + setRevisions(Array.isArray(response.revisions) ? response.revisions : []); + } catch (error) { + setRevisions(null); + setRevisionsError(error instanceof Error ? error.message : t("commandCenter.portability.versions.loadError", "Unable to load configuration versions")); + } + }; + + useEffect(() => { void loadRevisions(); }, [projectId]); + + const exportOrg = async () => { + setExportState("working"); + try { + const response = await api<{ bundle: unknown }>(withProjectId("/org/export", projectId), { method: "POST" }); + downloadBundle(response.bundle); + setExportState("success"); + } catch { + setExportState("error"); + } + }; + + const parseBundle = (): Record | null => { + try { + const value = JSON.parse(bundleText) as unknown; + if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("invalid"); + return value as Record; + } catch { + setImportError(t("commandCenter.portability.import.invalid", "Paste a valid org bundle JSON document")); + setImportState("error"); + return null; + } + }; + + const previewImport = async () => { + const bundle = parseBundle(); + if (!bundle) return; + const previewVersion = bundleVersion.current; + setImportState("previewing"); + setImportError(null); + try { + const response = await api<{ result: unknown }>(withProjectId("/org/import", projectId), { method: "POST", body: JSON.stringify({ bundle, dryRun: true }) }); + if (bundleVersion.current !== previewVersion) return; + setPreview(response.result); + setPreviewedBundle(bundle); + setImportState("previewed"); + } catch (error) { + if (bundleVersion.current !== previewVersion) return; + setImportError(error instanceof Error ? error.message : t("commandCenter.portability.import.error", "Unable to preview import")); + setImportState("error"); + } + }; + + const applyImport = async () => { + if (!previewedBundle) return; + const approved = await confirm({ + title: t("commandCenter.portability.import.confirmTitle", "Import organization bundle?"), + message: t("commandCenter.portability.import.confirmMessage", "This applies the previewed configuration to this project."), + confirmLabel: t("commandCenter.portability.import.confirmApply", "Import bundle"), + cancelLabel: t("actions.cancel", "Cancel"), + }); + if (!approved) return; + setImportState("importing"); + try { + await api(withProjectId("/org/import", projectId), { method: "POST", body: JSON.stringify({ bundle: previewedBundle, dryRun: false }) }); + await onSettingsRefresh(); + await loadRevisions(); + setImportState("success"); + } catch (error) { + setImportError(error instanceof Error ? error.message : t("commandCenter.portability.import.error", "Unable to import bundle")); + setImportState("error"); + } + }; + + const rollback = async (revision: ConfigurationRevision) => { + const approved = await confirm({ + title: t("commandCenter.portability.versions.confirmTitle", "Roll back configuration?"), + message: t("commandCenter.portability.versions.confirmMessage", "Restore this version? The rollback is recorded as a new version."), + confirmLabel: t("commandCenter.portability.versions.confirmRollback", "Roll back"), + cancelLabel: t("actions.cancel", "Cancel"), + }); + if (!approved) return; + setRollbackId(revision.id); + try { + await api(withProjectId(`/config/revisions/${encodeURIComponent(revision.id)}/rollback`, projectId), { method: "POST" }); + await onSettingsRefresh(); + await loadRevisions(); + } catch (error) { + setRevisionsError(error instanceof Error ? error.message : t("commandCenter.portability.versions.rollbackError", "Unable to roll back configuration")); + } finally { + setRollbackId(null); + } + }; + + const exportLabel = exportState === "working" ? t("commandCenter.portability.export.working", "Exporting…") : t("commandCenter.portability.export.action", "Export org bundle"); + + return <> +
+
+

{t("commandCenter.portability.title", "Org export / import")}

{t("commandCenter.portability.description", "Download or preview a secret-scrubbed organization bundle.")}

+ {exportState === "success" ? t("commandCenter.portability.export.success", "Export ready") : exportState === "error" ? t("commandCenter.portability.export.error", "Export failed") : t("commandCenter.controls.status.ready", "Ready")} +
+
+ + +