From 30ba1f005a9e870b729f1ceeedfe39f36fb32c9d Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Tue, 9 Jun 2026 13:54:59 -0700 Subject: [PATCH] FN-6119: open CE docs in built-in file viewer Expose the dashboard file viewer to plugin views and wire Compound Engineering artifacts to it. - add an openFile callback to the dashboard plugin view context and pass through the app host implementation - switch Compound Engineering artifact Open actions to the built-in file viewer with matching styling and coverage - document the new plugin context capability and add a published changeset for the CLI package Files changed: .changeset/ce-docs-built-in-viewer.md | 5 +++ docs/PLUGIN_AUTHORING.md | 2 +- packages/dashboard/app/App.tsx | 1 + packages/dashboard/app/plugins/types.ts | 2 ++ .../src/dashboard-interop.d.ts | 1 + .../src/dashboard/CompoundEngineeringView.css | 16 +++++++++ .../src/dashboard/CompoundEngineeringView.tsx | 24 +++++++------- .../__tests__/CompoundEngineeringView.test.tsx | 38 ++++++++++++++++++++++ 8 files changed, 76 insertions(+), 13 deletions(-) Fusion-Task-Id: FN-6119 Fusion-Task-Lineage: 8feb461c-b1d2-4059-9aa1-ffc756d15196 --- .changeset/ce-docs-built-in-viewer.md | 5 +++ docs/PLUGIN_AUTHORING.md | 2 +- packages/dashboard/app/App.tsx | 1 + packages/dashboard/app/plugins/types.ts | 2 + .../src/dashboard-interop.d.ts | 1 + .../src/dashboard/CompoundEngineeringView.css | 16 ++++++++ .../src/dashboard/CompoundEngineeringView.tsx | 24 ++++++------ .../CompoundEngineeringView.test.tsx | 38 +++++++++++++++++++ 8 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 .changeset/ce-docs-built-in-viewer.md diff --git a/.changeset/ce-docs-built-in-viewer.md b/.changeset/ce-docs-built-in-viewer.md new file mode 100644 index 0000000000..d38800751c --- /dev/null +++ b/.changeset/ce-docs-built-in-viewer.md @@ -0,0 +1,5 @@ +--- +"@runfusion/fusion": patch +--- + +Expose the dashboard file viewer to plugin views and use it for Compound Engineering artifact documents. diff --git a/docs/PLUGIN_AUTHORING.md b/docs/PLUGIN_AUTHORING.md index 8fac1aa646..e3dcb02104 100644 --- a/docs/PLUGIN_AUTHORING.md +++ b/docs/PLUGIN_AUTHORING.md @@ -769,7 +769,7 @@ Bundled workspace plugin pattern: Runtime host context contract: - Registered views receive a `context` object from the dashboard host (`PluginDashboardViewContext`). -- Context includes the active `projectId`, current visible `tasks`, optional `workflowSteps`, and `openTaskDetail` for launching the native task detail flow. +- Context includes the active `projectId`, current visible `tasks`, optional `workflowSteps`, `openTaskDetail` for launching the native task detail flow, and `openFile(path, options?)` for opening project-relative files in the dashboard's built-in file viewer. - Keep view-specific UI behavior in the plugin; treat host context as service/data injection only. Placement guidance: diff --git a/packages/dashboard/app/App.tsx b/packages/dashboard/app/App.tsx index 1f820b06bd..3703cbfc8e 100644 --- a/packages/dashboard/app/App.tsx +++ b/packages/dashboard/app/App.tsx @@ -1446,6 +1446,7 @@ function AppInner() { workflowSteps, subscribePluginEvents, openTaskDetail: (task: Task | TaskDetail, initialTab?: DetailTaskTab) => openDetailTask(task, initialTab), + openFile: openFileInBrowser, renderTaskCard: (task: Task | TaskDetail) => ( void; + /** Open a project-relative file in the dashboard's built-in file viewer. */ + openFile: (path: string, options?: { workspace?: string; line?: number; col?: number }) => void; renderTaskCard?: (task: Task | TaskDetail) => ReactNode; addToast?: (message: string, type?: PluginToastType) => void; /** diff --git a/plugins/fusion-plugin-compound-engineering/src/dashboard-interop.d.ts b/plugins/fusion-plugin-compound-engineering/src/dashboard-interop.d.ts index a51b4163de..330d466df1 100644 --- a/plugins/fusion-plugin-compound-engineering/src/dashboard-interop.d.ts +++ b/plugins/fusion-plugin-compound-engineering/src/dashboard-interop.d.ts @@ -24,6 +24,7 @@ declare module "@fusion/dashboard/app/plugins/types" { tasks: Task[]; workflowSteps: WorkflowStep[]; openTaskDetail: (task: Task | TaskDetail, initialTab?: DetailTaskTab) => void; + openFile: (path: string, options?: { workspace?: string; line?: number; col?: number }) => void; renderTaskCard?: (task: Task | TaskDetail) => ReactNode; addToast?: (message: string, type?: PluginToastType) => void; subscribePluginEvents?: ( diff --git a/plugins/fusion-plugin-compound-engineering/src/dashboard/CompoundEngineeringView.css b/plugins/fusion-plugin-compound-engineering/src/dashboard/CompoundEngineeringView.css index 8aa771300a..eabe1ff9ac 100644 --- a/plugins/fusion-plugin-compound-engineering/src/dashboard/CompoundEngineeringView.css +++ b/plugins/fusion-plugin-compound-engineering/src/dashboard/CompoundEngineeringView.css @@ -135,6 +135,22 @@ opacity: 0.55; } +.ce-artifact-open { + appearance: none; + background: none; + border: none; + color: var(--color-primary, #2563eb); + cursor: pointer; + font: inherit; + padding: 0; + text-decoration: underline; +} + +.ce-artifact-open:hover, +.ce-artifact-open:focus-visible { + color: var(--color-primary-hover, #1d4ed8); +} + .ce-artifact-error .ce-artifact-error-msg { color: var(--color-danger, #d23); font-size: 0.78rem; diff --git a/plugins/fusion-plugin-compound-engineering/src/dashboard/CompoundEngineeringView.tsx b/plugins/fusion-plugin-compound-engineering/src/dashboard/CompoundEngineeringView.tsx index a7d7917e14..49506a298a 100644 --- a/plugins/fusion-plugin-compound-engineering/src/dashboard/CompoundEngineeringView.tsx +++ b/plugins/fusion-plugin-compound-engineering/src/dashboard/CompoundEngineeringView.tsx @@ -7,7 +7,6 @@ import { useArtifacts } from "./hooks/useArtifacts.js"; import { useViewportMode } from "./hooks/useViewportMode.js"; import { useCeSession, type CeSessionSubscribe } from "./hooks/useCeSession.js"; import { useCeSessions, type CeSessionsSubscribe } from "./hooks/useCeSessions.js"; -import { getArtifactPreviewUrl } from "./hooks/api.js"; import { CeFlow } from "./CeFlow.js"; import { getStage, listStages, type CeStageDefinition } from "../session/stage-registry.js"; import type { CeArtifactEntry, CeArtifactGroup } from "../artifacts/discovery.js"; @@ -170,14 +169,14 @@ function EmptyState({ onStart }: { onStart: () => void }) { function ArtifactRow({ entry, - projectId, onSelect, selected, + openFile, }: { entry: CeArtifactEntry; - projectId?: string; onSelect: (id: string) => void; selected: boolean; + openFile?: PluginDashboardViewContext["openFile"]; }) { if (entry.kind === "error") { return ( @@ -196,28 +195,28 @@ function ArtifactRow({ {entry.name} {entry.path} - openFile?.(entry.path)} > Open - + ); } function StageGroup({ group, - projectId, onSelect, selectedId, + openFile, }: { group: CeArtifactGroup; - projectId?: string; onSelect: (id: string) => void; selectedId?: string; + openFile?: PluginDashboardViewContext["openFile"]; }) { const empty = group.entries.length === 0; return ( @@ -236,9 +235,9 @@ function StageGroup({ ))} @@ -261,6 +260,7 @@ export function CompoundEngineeringView(props: CompoundEngineeringViewProps) { // host doesn't supply it, the hook falls back to polling. const subscribePluginEvents = (props.context as PluginDashboardViewContext | undefined) ?.subscribePluginEvents; + const openFile = props.context?.openFile; const subscribe = useMemo(() => { if (!subscribePluginEvents) return undefined; return (sessionId, _projectId, onSessionEvent) => @@ -415,9 +415,9 @@ export function CompoundEngineeringView(props: CompoundEngineeringViewProps) { ))} diff --git a/plugins/fusion-plugin-compound-engineering/src/dashboard/__tests__/CompoundEngineeringView.test.tsx b/plugins/fusion-plugin-compound-engineering/src/dashboard/__tests__/CompoundEngineeringView.test.tsx index 6a91782667..0adffa55b9 100644 --- a/plugins/fusion-plugin-compound-engineering/src/dashboard/__tests__/CompoundEngineeringView.test.tsx +++ b/plugins/fusion-plugin-compound-engineering/src/dashboard/__tests__/CompoundEngineeringView.test.tsx @@ -119,6 +119,44 @@ describe("CompoundEngineeringView", () => { expect(screen.getAllByTestId("ce-group-empty").length).toBeGreaterThan(0); }); + it("opens an artifact in the built-in file viewer via context.openFile", async () => { + const openFile = vi.fn(); + listArtifacts.mockResolvedValue( + makeResult({ + strategy: [ + { kind: "artifact", id: "strategy:STRATEGY.md", stage: "strategy", path: "STRATEGY.md", name: "STRATEGY.md", size: 10, updatedAt: 1 }, + ], + }), + ); + render( + , + ); + + await screen.findByTestId("ce-artifact"); + fireEvent.click(screen.getByTestId("ce-artifact-open")); + expect(openFile).toHaveBeenCalledWith("STRATEGY.md"); + }); + + it("renders artifact open button without crashing when openFile is not in context", async () => { + listArtifacts.mockResolvedValue( + makeResult({ + strategy: [ + { kind: "artifact", id: "strategy:STRATEGY.md", stage: "strategy", path: "STRATEGY.md", name: "STRATEGY.md", size: 10, updatedAt: 1 }, + ], + }), + ); + render(); + + await screen.findByTestId("ce-artifact"); + const open = screen.getByTestId("ce-artifact-open"); + expect(open).toBeInTheDocument(); + fireEvent.click(open); + }); + it("renders an error entry for an unreadable artifact (not a crash or silent drop)", async () => { listArtifacts.mockResolvedValue( makeResult({