Compare commits

..

339 Commits

Author SHA1 Message Date
49be50aa99 chore: ignore local .gstack/ tooling dir 2026-10-23 05:14:12 +03:00
0b8a3a505e fix: ignore the project watcher's spurious self-notification on macOS
fs.watch's recursive FSEvents backend fires an extra "change" event whose
filename is just the watched project folder's own basename, both alongside
real file changes and once more asynchronously after the folder is removed
and the watcher closed. watchProject had no filter for it, so that bogus
event reached the renderer as a PROJECTS_CHANGED notification naming a path
that was never a real project file.

Reproduced deterministically outside vitest (plain fs.watch), then fixed by
skipping any event whose filename equals the watched directory's own name.
3 previously-flaky tests in projects.watch.test.ts (expecting an empty
`changed` array) now pass consistently across repeated runs; full desktop
suite is 111/111 green, tsc clean.
2026-10-21 04:00:58 +03:00
Konstantin Paulus
af570c164a
Merge pull request #104 from diffusionstudio/fix/auto-updater
feat: update version to 0.216.0 across all modules and implement auto…
2026-10-19 00:13:14 +02:00
konstantin-paulus
98ea0c986b feat: update version to 0.216.0 across all modules and implement auto-update notifications 2026-10-19 00:11:57 +02:00
Konstantin Paulus
68b633db3c
Merge pull request #102 from diffusionstudio/feat/alpha-mask
Feat/alpha mask
2026-10-17 17:40:32 +02:00
konstantin-paulus
a54e4152c3 feat: update package versions to 0.215.0 across all modules 2026-10-17 17:35:13 +02:00
konstantin-paulus
5aeb75118a feat: add credits display to node menu and update commands to include pricing logic 2026-10-17 17:26:44 +02:00
konstantin-paulus
744dbcb6b7 feat: update tool titles for clarity and consistency in toolbar 2026-10-17 17:18:54 +02:00
konstantin-paulus
b8869dd649 feat: add new icons for edit with prompt, remove background, and remove silences; update command icons 2026-10-17 17:09:21 +02:00
konstantin-paulus
e2d070f968 feat: add mask icon display in SubItemLayer component 2026-10-17 16:53:49 +02:00
konstantin-paulus
783edc2197 feat: add 'Use as mask' shortcut and implement mask application logic 2026-10-17 13:51:37 +02:00
konstantin-paulus
075732f237 feat: implement mask tool and replace clip path functionality with masks 2026-10-17 13:33:10 +02:00
konstantin-paulus
6a45d560d1 feat: add 'type' prop to mask for channel specification and update example usage 2026-10-16 16:38:37 +02:00
konstantin-paulus
0491460e1a Merge branch 'clip-mask-containers' into feat/alpha-mask 2026-10-16 16:16:05 +02:00
Konstantin Paulus
1ac2f5cc9a
Merge pull request #100 from diffusionstudio/feat/canvas-context-menu
Feat/canvas context menu
2026-10-16 11:23:22 +02:00
konstantin-paulus
f3d3a08cc2 feat: optimize canvas position handling by replacing ResizeObserver with computed effect 2026-10-16 11:19:50 +02:00
konstantin-paulus
f29396e13a feat: update package versions to 0.214.0 across all modules 2026-10-16 11:09:52 +02:00
konstantin-paulus
0cd29c91b8 feat: adjust submenu positioning by updating SUB_GUTTER constant 2026-10-16 10:52:06 +02:00
konstantin-paulus
efbc257512 feat: add clean-up command to arrange selected nodes in a grid layout 2026-10-16 10:41:59 +02:00
konstantin-paulus
78b0580c85 feat: update media actions in canvas context menu for enhanced functionality 2026-10-16 10:28:13 +02:00
konstantin-paulus
8107138490 feat: add keyboard shortcut for opening folder in context menu 2026-10-16 10:18:09 +02:00
konstantin-paulus
d68a336199 feat: add keyboard shortcut for delete action in folder context menu 2026-10-16 10:16:44 +02:00
konstantin-paulus
7b3e1fc5e1 feat: add media asset commands and integrate into canvas context menu 2026-10-16 10:14:37 +02:00
konstantin-paulus
b01a79a9e1 feat: refactor soundAsset function to use findGeometryAsset for improved asset retrieval 2026-10-16 00:32:49 +02:00
konstantin-paulus
a567775be1 feat: enhance FloatingProjectHeader with fullscreen detection and traffic light visibility 2026-10-16 00:26:22 +02:00
konstantin-paulus
53aa33ead9 feat: add folder rename cancellation functionality in asset management 2026-10-16 00:05:40 +02:00
konstantin-paulus
c897d7b4d0 feat: add folder move functionality to asset context menus 2026-10-15 23:56:33 +02:00
konstantin-paulus
41ea0e26ab feat: add palette option to command for better control over visibility in UI 2026-10-15 23:53:44 +02:00
konstantin-paulus
893eab6d02 feat: implement clipboard functionality for media import and enhance context menu options 2026-10-15 21:29:27 +02:00
konstantin-paulus
66bed78f88 feat: refactor auto-captions command and improve scene selection logic 2026-10-15 20:56:28 +02:00
konstantin-paulus
db9a6f668f feat: enhance context menus and commands with new shortcuts and improved structure 2026-10-15 15:42:33 +02:00
konstantin-paulus
5433beaebb feat: add keyboard shortcut for toggling prompt input with 'G' key 2026-10-15 14:53:37 +02:00
konstantin-paulus
250c4cc96f feat: update more-three-dots icon for improved clarity and consistency 2026-10-15 11:11:07 +02:00
konstantin-paulus
5681fd9bff feat: add icons for clipboard actions and chat functionality in shortcuts and window commands 2026-10-15 11:07:23 +02:00
konstantin-paulus
9d8327b48d feat: enhance context menu with improved layout and submenu offsets 2026-10-15 11:01:26 +02:00
konstantin-paulus
bbb2fad77a feat: enhance canvas behavior with dynamic panning on panel visibility changes 2026-10-15 10:57:59 +02:00
konstantin-paulus
9b3983d32a feat: add window commands for UI toggling and chat access 2026-10-15 10:52:01 +02:00
konstantin-paulus
6c6349a38f feat: add layer toggle commands and integrate context menus in timeline and canvas 2026-10-15 10:44:14 +02:00
konstantin-paulus
d3d2a0b468 feat: implement node context menu for right-click actions on canvas nodes 2026-10-15 10:37:18 +02:00
konstantin-paulus
3bf9f55067 fix: adjust padding in command palette list class for improved layout 2026-10-15 10:15:49 +02:00
konstantin-paulus
c530e9ca09 feat: adjust item and row height in command palette for improved UI 2026-10-15 10:13:23 +02:00
konstantin-paulus
56a8f09e53 Refactor command palette and action bar components
- Removed unused ActionBarMenu and related components from action-bar.tsx.
- Simplified ExportCurrentFrameCommand and ExportVideoCommand by removing ActionBar dependencies.
- Integrated LayeredCommand and LayerSection types into commands context for better structure.
- Enhanced CommandPalette to support layered commands with options.
- Deleted PresetMenu component as its functionality was integrated into the command handling.
- Improved overall code organization and readability across affected files.
2026-10-15 10:05:40 +02:00
konstantin-paulus
748f31ac45 feat: implement recent commands tracking in the command palette 2026-10-15 09:42:23 +02:00
konstantin-paulus
c413432d75 feat: implement focus handling for the composer on chat tab activation 2026-10-14 23:46:50 +02:00
konstantin-paulus
8d657e578e feat: refactor asset insertion logic to support new scene creation and improve handling of empty assets 2026-10-14 22:49:16 +02:00
konstantin-paulus
2609b28820 feat: enhance asset import functionality with selection management 2026-10-14 22:40:49 +02:00
konstantin-paulus
090669c999 feat: add label to context menu group for improved organization 2026-10-14 20:55:20 +02:00
konstantin-paulus
9ccaac43ce feat: enhance context and dropdown menus with grouping and improved item alignment 2026-10-14 20:51:36 +02:00
konstantin-paulus
e53775d581 feat: add "TRANSCRIPT" filter option to asset filtering 2026-10-14 20:33:27 +02:00
konstantin-paulus
82ebd30df7 feat: refactor context menu integration and add insert options for assets 2026-10-14 20:16:07 +02:00
konstantin-paulus
b8f06155ed feat: implement remove silence command and related functionality 2026-10-14 19:43:25 +02:00
konstantin-paulus
96d7242faa feat: add project folder commands and enhance command ordering in palette 2026-10-14 17:12:21 +02:00
konstantin-paulus
c95e6afc1d feat: update toolbar drag-and-drop functionality with slot anchoring 2026-10-14 16:42:06 +02:00
konstantin-paulus
d8ca02ae02 feat: implement dynamic toolbar slot positioning and update related components 2026-10-14 16:28:33 +02:00
konstantin-paulus
ec84c73d62 feat: enhance command structure with ready state and update execution logic 2026-10-14 14:38:02 +02:00
konstantin-paulus
9617d8adec feat: add export current frame and video commands with preset menus 2026-10-14 14:23:34 +02:00
konstantin-paulus
c21f56a705 feat: implement escape key functionality to close prompt input and update command section order 2026-10-14 12:54:23 +02:00
konstantin-paulus
2a54059ea8 feat: add timeline navigation shortcuts and corresponding icons 2026-10-14 12:32:33 +02:00
konstantin-paulus
f964e5c798 feat: add reload window command and keyboard shortcuts for asset management 2026-10-14 12:02:41 +02:00
konstantin-paulus
29f214bc39 feat: add generate command and update auto-captions command title 2026-10-14 11:47:03 +02:00
konstantin-paulus
bb4ac3bdd8 Refactor command handling and UI components
- Introduced a new CommandBar component to manage command actions and their UI.
- Replaced ActionBar in ClipPathBar and ObjectMaskBar with the new CommandBar.
- Added new command functionalities including AutoCaptions, EditWithPrompt, MakeVideo, RemoveBackground, Rerun, ReuseSettings, and Upscale.
- Implemented CommandPalette for command selection via keyboard shortcuts.
- Updated useAutoCaptions and useTransforms hooks for better scene management.
- Removed deprecated ActionBar component and adjusted related imports.
- Enhanced commands context management for better command registration and execution flow.
2026-10-14 11:32:21 +02:00
konstantin-paulus
17e09d1cc4 feat: bump version to 0.213.1 across all packages 2026-10-14 00:23:21 +02:00
Konstantin Paulus
5d93ffee9c
Merge pull request #99 from diffusionstudio/feat/multi-asset-selection
Feat/multi asset selection
2026-10-14 00:16:04 +02:00
konstantin-paulus
b9dcc6193e feat: bump version to 0.213.0 across all packages 2026-10-14 00:11:25 +02:00
konstantin-paulus
db5a4e90ad feat: update timeline colors to match engine constants for improved consistency 2026-10-13 23:58:37 +02:00
konstantin-paulus
a3cd943478 feat: refine asset attachment logic to handle file modification time more accurately 2026-10-13 23:44:40 +02:00
konstantin-paulus
5ac1c05eca feat: add SVG thumbnail support and improve getSvgDimensions function 2026-10-13 23:24:51 +02:00
konstantin-paulus
7760cb569d feat: enhance asset and folder item components to support multiple selections and context menu actions 2026-10-13 23:21:43 +02:00
konstantin-paulus
fb8a924a7a feat: add MiddleEllipsis component for improved text truncation and update asset and folder item components to utilize it 2026-10-13 21:04:33 +02:00
konstantin-paulus
e5a4024bdc feat: enhance createProjectList to support optional project record updates 2026-10-13 10:33:37 +02:00
Konstantin Paulus
ccf990a25b
Merge pull request #97 from diffusionstudio/feat/draft-projects
Feat/draft projects
2026-10-13 10:01:59 +02:00
konstantin-paulus
be7c406fb3 feat: update package versions to 0.212.0 across all modules 2026-10-13 10:00:11 +02:00
konstantin-paulus
83e734a590 feat: implement project moving functionality and enhance save location picker 2026-10-13 09:52:23 +02:00
konstantin-paulus
a5717bfb66 feat: update project folder handling and improve UI elements 2026-10-13 09:32:57 +02:00
konstantin-paulus
78fe83fbf8 feat: add collections management to dashboard
- Introduced a new `view-grid.svg` icon for the dashboard.
- Implemented `DashboardSidebarCollections` component to manage collections in the sidebar.
- Updated `DashboardProjectsView` to support project scopes including drafts and collections.
- Enhanced `DashboardPage` to handle collection navigation and state.
- Created `collections.ts` for collection-related database operations.
- Modified project-related functions to support collection filing.
- Updated database schema to include collections.
- Refactored context menus to include collection management options.
2026-10-13 09:23:19 +02:00
konstantin-paulus
bd11bc6b05 feat: implement multi-project deletion and selection functionality 2026-10-12 23:56:48 +02:00
konstantin-paulus
852b3d5138 feat: display all sorted projects instead of limiting to a maximum visible count 2026-10-12 22:31:38 +02:00
konstantin-paulus
47d38fb602 docs: add warning about avoiding cloud-synced locations for project folders 2026-10-12 12:36:33 +02:00
konstantin-paulus
9a42b13865 refactor: simplify project handling by removing unused folder logic and updating related comments 2026-10-12 12:29:12 +02:00
konstantin-paulus
58af16065d feat: add project relocation and missing project handling functionality 2026-10-12 11:59:11 +02:00
konstantin-paulus
fb50341b0f feat: reopen session in new project folder and resume conversation 2026-10-12 11:46:25 +02:00
konstantin-paulus
c6a5c721e4 feat: add support for opening project folders in various code editors 2026-10-12 11:39:51 +02:00
konstantin-paulus
9bc577c771 refactor: streamline project creation and saving process
- Removed the ensureProjectsRoot function and related logic, simplifying project creation to directly create a project without waiting for a root.
- Deleted the DashboardProjectsFolderBar component and its references, as it was no longer needed.
- Updated the createProject function to eliminate the generation of random project names, now defaulting to a simple "Untitled" draft.
- Introduced a new FolderMenu component for managing project folders, including saving functionality.
- Enhanced the ProjectProvider context to handle draft saving and folder management, including keyboard shortcuts for saving.
- Updated documentation to reflect changes in project saving behavior and context reporting.
2026-10-12 11:19:53 +02:00
konstantin-paulus
450495c44b Refactor project renaming logic and documentation
- Updated comments in the project renaming functions to clarify that only the display name is changed while the folder name remains unchanged.
- Removed the unused `moveProjectRecord` function to streamline project record management.
- Adjusted related components to reflect the updated renaming behavior, ensuring consistency across the application.
2026-10-12 09:35:19 +02:00
Konstantin Paulus
90ba4d0a2d
Merge pull request #91 from stevemclin/fix/timeline-shift-wheel-horizontal-scroll
fix(timeline): read Shift as a sideways wheel gesture
2026-10-11 16:59:40 +01:00
konstantin-paulus
8a1313b777 Refactor clip path handling and enhance SVG support
- Updated the handling of clip paths in various components, replacing references to `isClipPath` with `isClipShape` for consistency.
- Enhanced the `ClipPathsSettings` component to correctly select and manage clip path shapes.
- Added support for `<mask>` and `<clipPath>` elements in the documentation, clarifying their usage and properties.
- Improved the handling of ambiguous SVG tags by including `<mask>` and `<clipPath>` in the relevant sets.
- Introduced a new `clip-path.tsx` file to manage clip path functionalities, ensuring better organization and maintainability of the codebase.
2026-10-11 11:47:17 +02:00
Konstantin Paulus
eeb0238603
Merge pull request #96 from diffusionstudio/path-primitive
Path primitive
2026-10-10 23:45:49 +01:00
konstantin-paulus
d3260cb452 Update package versions to 0.211.0 across all relevant files
- Incremented version number from 0.210.0 to 0.211.0 in package.json and package-lock.json for the editor, cli, desktop, web, and jsx packages.
- Ensured consistency in versioning across the project to reflect the latest updates.
2026-10-11 00:35:54 +02:00
konstantin-paulus
ed4a04fb44 Add AI credits icon and update references in components
- Introduced a new SVG icon for AI credits in ai-credits.svg.
- Updated references in ActionBar and PromptInputActions components to use the new ai-credits icon instead of ai-generate.
- Modified the DashboardPage to reflect the new icon for the AI credits sidebar item, enhancing visual consistency across the application.
2026-10-11 00:19:43 +02:00
konstantin-paulus
d6c76e690d Add stroke cap customization to StrokeInspector component
- Introduced stroke cap options in the StrokeInspector, allowing users to select between butt, round, and square caps.
- Updated the component's state management to handle the new cap property alongside existing stroke properties.
- Enhanced the UI with a new SegmentedIconTabs control for cap selection, improving user experience and customization capabilities.
2026-10-11 00:08:17 +02:00
konstantin-paulus
7a2eee7fe0 Update model options in genai configuration
- Replaced 'nano-banana-2.1' and 'flux-2-klein' with 'FLUX.2 Klein' and 'Grok Imagine 2.0' in the MODEL_OPTIONS array to reflect new model offerings.
- Restored 'Nano Banana Pro' and 'Seedream 5.0 Pro' to maintain a comprehensive list of available models.
- Enhanced comments for clarity on model ordering and relevance.
2026-10-10 22:03:00 +02:00
konstantin-paulus
747a719148 Remove unused SVG icons and refactor StrokeInspector component
- Deleted obsolete SVG icons: preferences-adjust-vertical.svg, stroke.dash-offset.svg, stroke.dash.svg, and stroke.gap.svg to streamline asset management.
- Refactored the StrokeInspector component to replace the DropdownMenu with a Select component for improved user experience and consistency in line style selection.
- Updated related imports and adjusted the handling of line style options to enhance clarity and maintainability.
2026-10-10 21:50:57 +02:00
konstantin-paulus
daeb15f948 Update @diffusionstudio/api-contract to version 0.5.0 and enhance model configurations
- Upgraded the @diffusionstudio/api-contract dependency across multiple packages to version 0.5.0.
- Added new model configurations for image, video, and voice categories, including 'nano-banana-2.1', 'flux-3-image', 'minimax-h3-max', and 'elevenlabs-v4'.
- Updated documentation to reflect the new models and their capabilities, ensuring accurate references for users.
2026-10-10 21:29:04 +02:00
konstantin-paulus
fc13c899f9 Enhance keyframe drag functionality and update drag gesture handling
- Updated the updateDragGestures function to include scene parameter for better context during drag operations.
- Introduced beginKeyframeDrag and applyKeyframeDrag functions to manage keyframe dragging, ensuring keyframes are moved correctly in relation to their clips.
- Refactored handleKeyframe to utilize the new keyframe drag functions, simplifying the drag logic and improving code clarity.
- Adjusted rendering logic in renderKeyframeTrack to streamline keyframe handling during drag events.
2026-10-10 16:54:57 +02:00
konstantin-paulus
1fc4d16bf8 Enhance project initialization handling and update project configuration
- Updated the SceneInitOverlay component to differentiate between new and existing projects, ensuring the prompt only appears for projects that have never had content.
- Introduced a new useProjectConfig hook to manage project state and track whether the stage has been initialized.
- Enhanced ProjectConfig class to include reactive signals for loaded and initialized states, allowing for better project lifecycle management.
- Updated documentation to clarify the role of the initialized state in project management.
2026-10-10 14:22:17 +02:00
konstantin-paulus
d5190170d6 Add stroke dash properties and related SVG icons for enhanced stroke customization
- Introduced new SVG icons for stroke styles, including solid, dashed, and various dash configurations.
- Updated the StrokeInspector component to support line styles with dash properties (dash, dashGap, dashOffset).
- Enhanced the stroke handling in the rendering system to apply dash styles correctly.
- Updated documentation to include new stroke properties and their usage in animations and styling.
- Improved entity serialization and deserialization to handle new stroke dash attributes effectively.
2026-10-10 14:19:16 +02:00
konstantin-paulus
e13b7f9edc Refactor path tool to enhance vertex handling and add preview functionality
- Removed extensive comments from the path tool for clarity and conciseness.
- Introduced a new PREVIEW_RADIUS constant for better control over vertex preview size.
- Updated the vertexDot function to accept a customizable radius parameter.
- Enhanced the drawPenTool function to include a visual preview of where the next vertex will be placed.
- Improved the drawPathEditor function to indicate potential vertex addition points on the outline.
2026-10-10 13:09:50 +02:00
konstantin-paulus
2c736e5f4a Add PivotRow component and integrate pivot functionality into transform settings
- Introduced a new PivotRow component to manage pivot properties (pivotX, pivotY) for entities.
- Updated TransformSettings to conditionally display PivotRow instead of AnchorRow based on the entity's pivot state.
- Enhanced the clip-path and group handling logic to utilize pivot instead of anchor for transformations.
- Updated documentation to reflect the new pivot properties and their usage in the context of groups and transformations.
2026-10-10 13:02:21 +02:00
konstantin-paulus
bd3a67db17 Remove obsolete tool.pen-small.svg icon and update path handling in node.tsx to use vector-path instead. 2026-10-10 01:09:35 +02:00
konstantin-paulus
3970904400 Refactor SVG icons and enhance path settings component
- Updated path SVG icons to improve design consistency and removed the obsolete path.trim-offset.svg file.
- Introduced new vector-path and vector-side-count SVG icons for enhanced visual representation.
- Modified the AppearanceSettings component to use the new vector-side-count icon.
- Enhanced the PathSettings component with dropdown menus for managing path addons, improving user interaction and customization options.
2026-10-10 01:03:50 +02:00
konstantin-paulus
1e11b17ae7 Add README for icon assets detailing usage and conversion process
- Created a README.md file in the icons directory to document the usage of SVG icons within the application.
- Included guidelines for converting Figma icons to the 25×25 pixel grid format, ensuring sharp rendering on 1x screens.
- Provided detailed instructions on geometry reading, redrawing, and cleaning up SVG files for consistency and quality.
- Enhanced documentation to support developers in maintaining and adding new icons effectively.
2026-10-10 00:46:47 +02:00
konstantin-paulus
b1aa6618b6 Refactor icon components and remove unnecessary size classes
- Removed size classes from Icon components in various files to standardize icon sizes.
- Deleted unused SVG icon files to clean up the assets directory.
- Updated related components to ensure consistent icon rendering without size specifications.
2026-10-10 00:15:51 +02:00
konstantin-paulus
0e57cd2edc Refactor EditValue to PropValue across edit types
- Removed the EditValue type and replaced it with PropValue in edit-types.ts and edit.ts files.
- Updated related interfaces and functions to ensure consistency in type usage for properties in editing operations.
- Enhanced type clarity by standardizing the value types used in source edits and property management.
2026-10-09 23:28:10 +02:00
konstantin-paulus
dd49464d56 Enhance entity serialization with new path properties
- Added support for VectorPath, EvenOdd, ViewBox, and PathTrim properties in the EntityRecord interface.
- Updated the serializeEntity function to handle new path-related data, ensuring full precision for VectorPath.
- Enhanced the deserializeEntity function to correctly parse and set new path properties from EntityRecord.
- Improved keyframe handling to include path data for keyframes, allowing for more detailed animation control.
2026-10-09 23:18:46 +02:00
konstantin-paulus
5552978747 Enhance path editing capabilities and introduce new SVG icons
- Updated the source file to include 'path' in the set of ambiguous SVG tags.
- Added new SVG icons for path trimming (trim-start, trim-end, trim-offset) and a small pen tool icon.
- Implemented a PathSettings component to manage path-specific properties such as fill rule and trim settings.
- Enhanced the Toolbar and ToolMenu components to include the new Pen tool for drawing and editing paths.
- Integrated path editing functionality, allowing users to edit vertices and manage path outlines directly on the canvas.
- Updated the inspector components to support path properties and interactions, improving the overall user experience for path manipulation.
- Enhanced documentation to include details about the new path features and SVG elements.
2026-10-09 23:18:37 +02:00
konstantin-paulus
eaacc15fc8 Add ellipse and polygon shapes to drawing tools
- Introduced new shape tools for Ellipse and Polygon, enhancing the drawing capabilities within the application.
- Updated the Toolbar component to include shape tools, allowing users to select and utilize these new shapes.
- Enhanced the ToolMenu to provide options for selecting Ellipse and Polygon tools.
- Implemented functionality for managing point counts in polygons and added relevant controls in the AppearanceSettings.
- Updated the rendering engine to support the new shapes, ensuring they can be drawn and manipulated effectively.
- Enhanced documentation to include details about the new shapes and their properties.
2026-10-09 13:44:11 +02:00
konstantin-paulus
3dbdb22953 Refactor canvas component and remove DrawOverlay
- Removed the DrawOverlay component from the canvas, streamlining the rendering process.
- Updated the Canvas component to reference the new draw tool functionality instead of DrawOverlay.
- Introduced a new DrawTool trait to manage drawing interactions, enhancing the overall drawing experience in the application.
- Updated engine initialization to include the DrawTool, ensuring proper integration with the existing systems.
2026-10-09 12:34:32 +02:00
konstantin-paulus
83df6a2a4b Add withEmptiedTracks function to manage keyframe tracks
- Introduced the withEmptiedTracks function to identify and remove keyframe tracks that no longer have keyframes associated with them.
- Updated the deleteSelection function to utilize withEmptiedTracks, ensuring that tracks are removed when their last keyframes are deleted.
- Enhanced keyframe management logic for improved performance and maintainability in the engine.
2026-10-09 12:25:41 +02:00
konstantin-paulus
21cb4d0e17 Refactor LayoutPanel component for improved dropdown menu structure
- Simplified the rendering of the layout dropdown menu within the LayoutPanel component.
- Removed unnecessary conditional rendering, streamlining the code for better readability and maintainability.
- Ensured consistent functionality while enhancing the overall structure of the dropdown menu.
2026-10-09 12:19:46 +02:00
konstantin-paulus
4e64fd8229 Refactor keyframe handling for paint properties
- Replaced Keyframe component with PaintKeyframe to manage keyframes for paint properties more effectively.
- Updated SolidFillPicker and FillItem components to utilize the new PaintKeyframe for improved keyframe management.
- Enhanced keyframe logic in the engine to support multiple paint properties, ensuring consistent behavior across paint types.
- Improved overall code clarity and maintainability by consolidating keyframe functionality related to paint.
2026-10-09 12:14:38 +02:00
konstantin-paulus
9f09a76ded Integrate Tooltip functionality into SegmentedIconTabs component
- Added Tooltip support to the SegmentedIconTabs component, enhancing user experience by providing additional context for icon tabs.
- Wrapped button elements with TooltipTrigger and included TooltipContent for improved accessibility and information display.
2026-10-09 11:41:34 +02:00
konstantin-paulus
09f227f49e Enhance StrokeInspector with visual icons and slider functionality
- Added icons to the ControlledTextField components for stroke weight and miter limit, improving visual cues for users.
- Enabled slider functionality for both inputs, enhancing user interaction and experience.
2026-10-09 11:40:10 +02:00
konstantin-paulus
5b7846382f Enhance TextPanel component with font size controls
- Added an icon to the ControlledTextField for better visual representation of font size adjustments.
- Enabled slider functionality for the font size input, improving user interaction and experience.
2026-10-09 11:19:10 +02:00
konstantin-paulus
81ab54fed1 Enhance FloatingInspector components with onClose functionality
- Added onClose prop to FloatingInspector in various inspector components to improve user experience by allowing the inspectors to close properly.
- Updated AnimationInspector, BackgroundSettings, CaptionSettings, EffectsInspector, ExportInspector, FillPicker, GradientFillPicker, ObjectMaskInspector, ShadowInspector, SourceRows, StrokeInspector, TransitionSettings, and Variables components to utilize the new onClose functionality.
- Improved overall interaction by ensuring inspectors can be closed from within their respective contexts.
2026-10-09 11:16:02 +02:00
konstantin-paulus
d14c0f3c59 Implement viewport clamping for FloatingInspector component
- Added a clampToViewport function to ensure the FloatingInspector remains within the viewport boundaries during resizing.
- Replaced the previous resize event listener with a ResizeObserver for more efficient handling of size changes.
- Updated the root reference management to observe and unobserve the element correctly, enhancing the component's responsiveness to layout changes.
2026-10-09 10:54:00 +02:00
konstantin-paulus
bdbe912409 Enhance stroke and fill handling in inspector components
- Updated FillPicker to manage stroke paint placement and gradient handling more effectively.
- Refactored StrokeInspector to utilize the new useStrokePaint hook for improved paint management.
- Adjusted rendering logic in strokes and related components to support both solid and gradient paints.
- Enhanced documentation to clarify stroke and fill interactions, including the use of paint children in strokes.
- Improved overall user experience by ensuring consistent behavior across fill and stroke components.
2026-10-09 10:49:36 +02:00
konstantin-paulus
acb7092faa Add angular gradient support in fill-picker and related components
- Introduced AngularGradientPaint to support angular gradients in the fill-picker component.
- Updated fill-row and gradient-picker components to recognize and handle angular gradients.
- Enhanced gradient handling logic to accommodate angular gradient properties and interactions.
- Updated documentation to reflect the new angular gradient capabilities and usage examples.
- Refactored gradient tool logic to include angular gradient manipulation and rendering.
2026-10-08 23:15:53 +02:00
konstantin-paulus
83c38cc53a Update color-opacity-picker component to enhance styling
- Modified the class names in the NumberField and HexColorInput components to include `last:rounded-r-md`, improving the visual appearance of the input fields.
- Ensured consistent styling across both components for better user experience.
2026-10-08 15:54:35 +02:00
konstantin-paulus
e836ffce14 Add shimmer effect for ongoing caption generation
- Introduced a new `shimmer` function to visually indicate when a scene is being captioned, enhancing user experience.
- Updated the `generateCaptions` function to prevent multiple caption generations on the same scene.
- Added `Shimmering` trait to manage the shimmer state and timing.
- Updated rendering logic to include the shimmer effect around scenes during processing.
- Added `@diffusionstudio/api-contract` dependency to `package-lock.json` for improved API integration.
2026-10-08 10:02:02 +02:00
Konstantin Paulus
38ecaef5c3
Merge pull request #92 from diffusionstudio/api-v2-migration
Api v2 migration
2026-10-07 23:39:25 +01:00
konstantin-paulus
32ab74e482 Update model references and package dependencies for improved functionality
- Removed outdated API reference from the `.env.example` file.
- Updated `@diffusionstudio/api-contract` dependency version to `^0.4.0` in both `package.json` files.
- Replaced model name `gemini-3.5-flash` with `qwen3.8-omni-flash` in configuration and documentation, ensuring alignment with the latest model capabilities.
- Added a note in the editor documentation regarding project management in cloud-synced folders to prevent issues with media handling.
2026-10-08 00:29:26 +02:00
konstantin-paulus
3e376ca95f Enhance analytics tracking in desktop and web applications
- Updated the `startAnalytics` function to accept a `WindowHost` parameter, allowing for improved tracking of app usage.
- Introduced a timer to track app usage every minute when the window is active.
- Added similar usage tracking functionality in the web application's analytics module, ensuring consistent tracking across platforms.
2026-10-07 18:28:03 +02:00
konstantin-paulus
42ede69691 Add transcript parsing functionality and integrate with asset resolution
- Introduced a new `parseTranscriptJson` function to handle various transcript JSON formats, ensuring robust parsing and error handling.
- Updated the `resolveTranscript` function to utilize `parseTranscriptJson` for improved transcript processing, replacing direct JSON parsing.
- Enhanced the overall structure and clarity of transcript handling within the media captioning system.
2026-10-07 17:22:42 +02:00
konstantin-paulus
e6573a717d Enhance asset metadata handling in AssetInfoPanel
- Introduced `createResource` to fetch job details associated with the asset, improving the retrieval of generation information.
- Updated logic to extract prompt and model details from the job data, enhancing the clarity of asset generation metadata.
- Refactored the use of asset properties to ensure accurate representation of asset creation and modification dates.
2026-10-07 15:16:21 +02:00
konstantin-paulus
35f4cf6c26 Refactor media tool documentation and update command references
- Updated documentation for various media tools to reflect the removal of the `media` prefix from command names, enhancing clarity and consistency.
- Adjusted links and references in the documentation to point to the new command structures for `grab`, `transcribe`, `filmstrip`, `waveform`, and `listen`.
- Added new documentation for the `filmstrip`, `grab`, `listen`, `probe`, and `transcribe` tools, detailing their functionalities and usage.
- Improved error handling descriptions and examples in the documentation to assist users in understanding tool operations better.
2026-10-07 15:06:38 +02:00
konstantin-paulus
55e1f1189f Refactor media command structure and update documentation
- Removed the `media` prefix from various commands (`media_grab`, `media_transcribe`, etc.) to simplify usage and improve consistency across the CLI and API.
- Updated the corresponding handlers and references in the codebase to reflect the new command names.
- Enhanced the README and documentation to clarify the changes in command structure and provide updated examples for users.
- Introduced new handlers for `grab`, `transcribe`, `filmstrip`, `waveform`, and `listen`, ensuring they align with the updated command naming conventions.
- Improved error handling and validation in the new command implementations for better user experience.
2026-10-07 15:04:15 +02:00
konstantin-paulus
6e25123941 Refactor audio handling and enhance media processing tools
- Introduced a new `audioFile` function to extract audio from assets, ensuring only the audio track is uploaded for analysis and transcription.
- Updated `mediaListen` and `mediaTranscribe` handlers to utilize the new audio extraction logic, improving efficiency and clarity in processing audio and video assets.
- Implemented error handling for audio analysis and transcription, ensuring robust responses for unsupported formats and empty audio tracks.
- Added `requireSignIn` and `apiError` functions to manage user authentication and API error handling, enhancing the reliability of tool operations.
- Updated documentation to reflect changes in audio processing and tool functionalities, providing clearer guidance for users.
2026-10-07 14:49:57 +02:00
konstantin-paulus
116eae23b8 Update cost calculation logic in estimate function to reflect model's minimum pricing
- Adjusted the chargeOf function to ensure that the cost calculation returns the model's minimum price instead of a fixed value of 1, aligning with API pricing requirements.
- Updated documentation comments for clarity on pricing logic and conditions for undefined values.
2026-10-07 14:32:07 +02:00
konstantin-paulus
e8c1bde745 Update model configurations and tool requests for improved functionality
- Replaced outdated model names in the configuration with new models: `remove-background` and `upscale-image` are now `bria-rmbg-2.0` and `seedvr-2`, respectively.
- Updated the `request` logic in the `use-transforms` file to reflect the new model names for background removal and image/video upscaling.
- Changed the transcription model from `transcribe` to `universal-3.5-pro` in the captions generation process.
- Adjusted documentation to align with the new model names and their functionalities, ensuring clarity for users.
2026-10-07 14:13:27 +02:00
konstantin-paulus
4e232a3c5d Update package versions to 0.210.0 across all modules
- Bumped version numbers in package.json and package-lock.json for the editor, CLI, desktop, web, and JSX packages to 0.210.0, ensuring consistency across the project.
- This update may include new features, bug fixes, or improvements as part of the version increment.
2026-10-07 12:35:25 +02:00
konstantin-paulus
9d09dbf0ca Remove unused large hailuo icon and update model configurations to reflect new icon names and descriptions. Adjusted model options for Grok Imagine and Krea to use appropriate icons, and modified video model configurations for Kling and Flux to enhance clarity and consistency. 2026-10-07 12:29:13 +02:00
konstantin-paulus
fe3f1d68e7 Implement estimate option in generate tool for cost and time prediction
- Added an `--estimate` option to the `generate` command, allowing users to retrieve the estimated credits and execution time without starting a job.
- Updated the `generate` function to handle the new estimate logic, returning a structured response with `credits` and `etaSeconds`.
- Enhanced documentation to clarify the usage of the estimate feature and its implications for job execution.
- Modified related types and validation to accommodate the new estimate functionality, ensuring robust input handling.
2026-10-07 12:04:03 +02:00
konstantin-paulus
f10a6917f9 Enhance generate tool to include model fields and improve input validation
- Updated the `generate` function to declare every model's fields by name, allowing clients to send only the declared properties.
- Introduced a new `modelFields` constant that aggregates fields from both API and local models, enhancing input validation.
- Added tests to verify the correct declaration of model fields and ensure proper parsing of input data.
2026-10-07 11:20:22 +02:00
konstantin-paulus
1f0476833b Update waveform rendering logic to clarify export behavior
- Enhanced documentation to specify that waveforms are only drawn in the editor and not included in exports, particularly when part of a scene composition.
- Modified the condition for rendering waveforms in real-time to ensure it only occurs when the entity is not part of a parent node, improving rendering accuracy.
2026-10-07 10:51:14 +02:00
konstantin-paulus
5c685e15b0 Refactor object mask handling and enhance effects inspector functionality
- Updated EffectsInspector and ObjectMaskInspector components to utilize the getParentNode function for improved mask grouping.
- Modified useObjectMasks hook to accept a clip parameter, allowing for more accurate retrieval of object masks based on the current video context.
- Enhanced objectMaskGroups function to categorize masks based on the associated video footage, improving user experience when selecting masks from the library.
2026-10-07 10:47:07 +02:00
konstantin-paulus
6ce93217bb Enhance effects inspector and object mask handling
- Added a new "Opacity" effect option to the EFFECT_OPTIONS array for better control over layer effects.
- Refactored the EffectsInspector component to utilize grouped object masks, improving the organization of mask options in the dropdown menu.
- Updated the ObjectMaskInspector to support selection from grouped masks, enhancing user experience when choosing masks from the library.
- Modified the useObjectMasks hook to return grouped masks, streamlining the retrieval of masks by their respective folders.
2026-10-07 10:43:17 +02:00
konstantin-paulus
e18ab84562 Remove media segment functionality and related tests
- Eliminated the `media_segment` command and its associated options from the CLI, streamlining the media handling process.
- Removed references to `media_segment` in the API handlers and tests, ensuring a cleaner codebase.
- Updated the `present` function to no longer handle `media_segment`, focusing on other media processing tasks.
- Adjusted related documentation to reflect the removal of the `media_segment` functionality, enhancing clarity for developers.
2026-10-07 10:29:55 +02:00
konstantin-paulus
21589f4843 Enhance audio handling in media generation and update documentation
- Updated the `generate` function to support audio field references for scenes, allowing users to transcribe audio from scene mixes.
- Introduced new utility functions for audio encoding and scene reference validation, improving the handling of audio uploads.
- Modified the `requireScene` function to include a reason parameter for better error messaging.
- Updated documentation to reflect the new capabilities for transcribing scenes and handling audio, enhancing clarity for developers.
2026-10-07 00:23:55 +02:00
konstantin-paulus
6a0ef3c188 Implement generate and job endpoints in the web API
- Added `generate` and `job` handlers to facilitate media generation and job management through the API.
- Enhanced the `generate` function to handle file uploads and return job details, including estimated run time and credit costs.
- Implemented the `job` function to retrieve job status and results, allowing users to poll for job completion and access generated files.
- Updated documentation to reflect the new endpoints and their usage, improving clarity for developers integrating with the API.
2026-10-06 23:14:59 +02:00
konstantin-paulus
d2e56157a4 Enhance authentication event tracking to differentiate new users
- Updated the authentication state change handler to track sign-in events specifically for new users by introducing an `isNewUser` check.
- Modified the condition for tracking the 'signed_in' event to ensure it only triggers for new users, improving the accuracy of user engagement analytics.
2026-10-06 18:24:23 +02:00
konstantin-paulus
73e578f47c Refactor analytics tracking and configuration in desktop application
- Replaced the Umami tracking implementation with a new analytics system that utilizes a queue for event tracking.
- Introduced `configureAnalytics` function to set API URL and token for event tracking.
- Updated event tracking methods to handle canvas edits and code changes, improving the granularity of analytics data.
- Modified main channels to reflect the new analytics configuration, enhancing the integration between the main and renderer processes.
- Improved documentation and code organization for better maintainability and clarity.
2026-10-06 18:11:41 +02:00
konstantin-paulus
8d9dfb690c Update placement logic for beside function to improve alignment
- Changed documentation and implementation in the `beside` function to clarify that the spot is now top-aligned with the reference box instead of level.
- Adjusted the calculation of `minY` to align with the top of the box, enhancing the placement logic for better visual consistency on the canvas.
2026-10-06 16:22:09 +02:00
konstantin-paulus
62c1f1533d Refactor recent projects display in DashboardHomeView for responsive grid layout
- Introduced dynamic column calculation for recent projects based on available width, improving responsiveness.
- Replaced fixed column count with a calculated grid layout that adapts to screen size, enhancing user experience.
- Updated documentation for constants related to recent project card dimensions and grid configuration.
2026-10-06 16:12:39 +02:00
konstantin-paulus
68b3095405 Enhance project deletion logic to handle non-existent directories
- Updated the `deleteProject` function to check if the directory exists before attempting to move it to the trash, preventing errors when trying to delete already deleted projects.
- Improved documentation to clarify that a project can still be removed from the list even if its folder is already gone.
2026-10-06 16:08:32 +02:00
konstantin-paulus
2c536d913d Implement upgrade dialog visibility control in purchase success component
- Added `hideUpgradeDialog` function to manage the visibility of the upgrade dialog.
- Integrated `hideUpgradeDialog` call in the `show` function of the `PurchaseSuccess` component to ensure the dialog is closed when a new purchase is displayed, enhancing user experience by preventing overlapping dialogs.
2026-10-06 16:04:23 +02:00
konstantin-paulus
105f81de89 Add credit display and tooltip functionality in action bar and prompt input components
- Introduced a new `TransformButton` component to encapsulate the credit display and tooltip functionality for transformation actions in the action bar.
- Updated the `ActionBar` component to utilize `TransformButton`, enhancing the user experience by providing clear credit information for each action.
- Enhanced the `PromptInputActions` component to show estimated credits for rerun actions, improving user awareness of costs.
- Refactored the `use-estimate` module to support dynamic credit calculations and formatting, ensuring accurate cost representation throughout the application.
2026-10-06 15:30:11 +02:00
SteveMclin
e5efb565c5 fix(timeline): read Shift as a sideways wheel gesture
Shift+wheel never scrolled the timeline sideways on Windows or Linux. The
handler only moved horizontally when the event itself carried a deltaX, and
a mouse on those platforms keeps reporting the gesture on deltaY: the
browser swaps its default action for Shift, not the event's axes. macOS and
trackpads set deltaX themselves, which is why the bug only showed up on
Windows and Linux mice.

The axis is now read out of the deltas while Shift is held, in both the
timeline canvas and the row-label scroller, which had the same blind spot.
A delta that needs borrowing only wins when it is the larger of the two, so
a trackpad's own horizontal delta is still used as it arrives.
2026-10-06 15:15:50 +02:00
konstantin-paulus
932c92d5f6 Add credit estimation feature in PromptInput component
- Integrated a new `useEstimate` hook to calculate the cost of generation based on the current configuration.
- Updated the `PromptInput` component to display estimated credits required for generation, enhancing user awareness of costs.
- Improved the UI to show credit information dynamically, providing a better user experience during prompt generation.
2026-10-06 13:37:24 +02:00
konstantin-paulus
ecf97f8cc1 Add duration range support in model options and prompt input
- Introduced a new `durationRange` property in the `ModelOption` interface to allow models to specify a range of valid durations.
- Implemented a `DurationRangeMenu` component in the `PromptInput` to enable users to select durations within the specified range, including presets and custom input.
- Updated the `fitToModel` function to utilize the new duration range when configuring model options, enhancing the flexibility of duration selection.
- Enhanced the UI to dynamically display and handle duration selections, improving overall user experience.
2026-10-06 13:31:05 +02:00
konstantin-paulus
f4e7e7f54f Add duration selection functionality with slider in PromptInput component
- Introduced a new DurationMenu component that allows users to select durations using a slider.
- Refactored duration handling to utilize a list of available durations, improving user interaction.
- Updated the duration accessor to return a number or undefined for better type safety.
- Enhanced the UI to display the selected duration dynamically, improving overall usability.
2026-10-06 13:10:11 +02:00
konstantin-paulus
75f0bfc8fc Remove "Add audio" functionality from the action bar and related components
- Deleted the "Add audio" button from the ActionBar and its associated logic in the PromptInputActions component.
- Updated the TransformType definition to exclude "addAudio" and removed related handling in the use-transforms module.
- Adjusted the model configuration to reflect the removal of audio-related transformations, streamlining the available options for users.
2026-10-06 12:53:36 +02:00
konstantin-paulus
14feb5d4f7 Add Gemini 3.8 Flash TTS model and voice options
- Introduced the "gemini-3.8-flash-tts" model with associated voice options to the configuration.
- Added a new `GEMINI_VOICE_OPTIONS` array, detailing various prebuilt voices with descriptions and preview URLs.
- Updated the default model for the VOICE mode to use the new Gemini model, enhancing the voice generation capabilities in the application.
2026-10-06 12:46:45 +02:00
konstantin-paulus
56fb94104b Refactor prompt input handling and introduce saved configuration functionality
- Replaced `createDefaultConfig` with `restoreConfig` in multiple components to utilize saved configurations for prompt input.
- Added `saved-config.ts` to manage saving and loading prompt configurations across sessions, enhancing user experience by preserving state.
- Updated the `PromptInput` component to load saved configurations on initialization and save changes automatically.
- Adjusted the `openPromptInput` method to accept optional configurations, allowing for more flexible prompt handling.
- Modified model defaults in `config.ts` to reflect updated model options, ensuring consistency across the application.
2026-10-06 12:25:32 +02:00
konstantin-paulus
8d3965fa9c Enhance model menu with keyboard navigation and search functionality
- Introduced keyboard navigation for the model selection menu, allowing users to highlight options using arrow keys and select with Enter.
- Refactored the search input to support dynamic filtering of model options based on user input, improving accessibility and usability.
- Updated the `SearchInput` component to accept a ref and onKeyDown handler for better integration with the model menu.
- Enhanced the overall user experience by ensuring focus management and visual feedback during selection.
2026-10-06 12:12:16 +02:00
konstantin-paulus
e5b8971aac Update model options and refactor default model handling
- Reordered and updated the `MODEL_OPTIONS` to enhance clarity and relevance, introducing new models and adjusting their positions.
- Refactored the `fitToModel` and `createDefaultConfig` functions to utilize a new `defaultModelOption` for improved model selection based on mode.
- Removed deprecated model entries to streamline the configuration and ensure consistency across components.
2026-10-06 12:02:35 +02:00
konstantin-paulus
8616127c50 Enhance model configuration with resolution support
- Added resolution handling to the generation configuration, allowing models to specify available output resolutions.
- Updated the `MODEL_OPTIONS` and `MODEL_MODES` to include new models and their respective resolutions.
- Refactored the `fitToModel` function to accommodate resolution selection, ensuring compatibility with model capabilities.
- Integrated resolution options into the `PromptInput` component for user selection, improving the overall user experience.
- Adjusted type definitions to include resolution in the generation configuration, enhancing type safety across components.
2026-10-06 11:43:38 +02:00
konstantin-paulus
e3af57b136 Refactor generation configuration and type handling
- Moved generation configuration types from `schemas.ts` to `types.ts` for better organization and clarity.
- Updated imports across components to utilize the new `types.ts` file, ensuring consistent type usage.
- Refactored the `createDefaultConfig` and `fitToModel` functions in `requests.ts` to streamline model configuration handling.
- Removed deprecated `schemas.ts` file to clean up the codebase and improve maintainability.
2026-10-06 10:52:46 +02:00
konstantin-paulus
9bde5fe6ef Add file attachment handling and paste support in agent chat
- Introduced functionality for handling pasted files as attachments, including image previews.
- Enhanced the `fileAttachment` function to support generating object URLs for image previews.
- Implemented a `createPasteHandler` to manage paste events and display error messages for failed uploads.
- Updated the `Composer` and `DashboardHomeView` components to integrate paste handling.
- Added server-side support for uploading attachments, ensuring unique paths for each upload.
- Enhanced the protocol to include an `attachments.upload` method for handling file uploads.
2026-10-05 23:37:30 +02:00
konstantin-paulus
b83d6e4b80 Enhance focus behavior and clean up UI components
- Added a CSS rule to remove focus outlines for non-input elements, improving visual clarity.
- Removed unnecessary focus-related classes from various UI components, streamlining their styles.
- Updated button and dialog components to enhance user experience by simplifying focus management.
2026-10-05 23:25:59 +02:00
konstantin-paulus
6f14ce551a Add focus behavior to PromptInput component on mount
- Implemented `onMount` lifecycle method to automatically focus the textarea and set the selection range to the end of the current value when the component is rendered.
- This enhancement improves user experience by allowing immediate interaction with the input field.
2026-10-05 23:22:12 +02:00
konstantin-paulus
e4c4cdad4b Refactor API client and job handling logic
- Simplified the API client setup by consolidating authorization logic into the `httpBatchLink`.
- Updated job handling to replace subscription-based polling with a more efficient polling mechanism using `jobs.get`.
- Improved error handling during job polling to allow for retries before giving up on failed polls.
- Enhanced code clarity by removing deprecated subscription logic and unnecessary comments.
2026-10-05 23:12:45 +02:00
konstantin-paulus
d29d18b33c Export generating utility functions to enhance modularity and facilitate generation processes in the runtime package. 2026-10-05 23:02:31 +02:00
konstantin-paulus
42753381ff Refactor generative AI components and consolidate generation logic
- Replaced individual generation hooks for image, video, voice, and audio with a unified `useGenerate` hook to streamline generation processes.
- Updated the `ActionBar` and `PromptInputActions` components to utilize the new `useGenerate` hook for rerunning generation jobs.
- Enhanced media selection handling by refactoring the `useMediaSelection` hook to return image and video media more efficiently.
- Removed deprecated placeholder functionality and related imports, improving code clarity and maintainability.
- Introduced a new `requests.ts` file to manage API request configurations for generation tasks.
- Updated the `useGenerationRecords` hook to track job information more effectively, including the first job and total credits.
- Improved transform handling in the `useTransforms` hook to apply transformations over selected media nodes.
- Added auto-caption generation functionality in the `useAutoCaptions` hook, integrating with the project context.
- Removed unused files and code related to legacy generation methods, enhancing overall project structure.
2026-10-05 23:02:23 +02:00
konstantin-paulus
77eee77313 Add purchase success poster and enhance success dialog
- Introduced a new poster image for the purchase success dialog.
- Added CSS animations for the poster and button interactions to improve user experience.
- Refactored the `PurchaseSuccess` component to handle purchase details and display animations.
- Updated success URL handling to include purchase information for better tracking.
2026-10-05 16:31:03 +02:00
konstantin-paulus
8ff93b159b Update dependencies and enhance dashboard components
- Added `@trpc/client` and `@trpc/server` dependencies to `package-lock.json` and `package.json`.
- Updated `.env.example` to include the new API URL for Diffusion Studio.
- Refactored dashboard components to utilize the new `@diffusionstudio/api-contract`, replacing legacy backend calls.
- Improved user experience in the dashboard by updating plan and billing information handling.
- Removed deprecated backend code and adjusted related components for better maintainability.
2026-10-05 15:37:48 +02:00
konstantin-paulus
631d457373 Export sourceFiles function for external use and integrate migrateGenerations in compileProject to handle legacy asset migrations. This enhances project compatibility with previous versions. 2026-10-04 11:33:51 +02:00
konstantin-paulus
1a8968a396 Refactor generative AI components and update dependencies
- Removed unused imports and code related to generative assets in various components.
- Updated the `package-lock.json` to remove `@diffusionstudio/api-contract` and `@trpc` dependencies.
- Introduced a placeholder mechanism for generative AI features that are currently being rebuilt.
- Adjusted the CLI and documentation to reflect changes in available commands and features.
- Enhanced the handling of timeouts in the CLI client for media analysis and rendering tasks.
2026-10-04 11:12:49 +02:00
Konstantin Paulus
fefcde9df7
Merge pull request #90 from diffusionstudio/agent-plugins
Agent plugins
2026-10-03 16:30:32 +01:00
konstantin-paulus
c99d8c2d3a Update package versions to 0.209.1 across all modules
- Incremented version numbers in `package.json` and `package-lock.json` for the main editor, CLI, desktop, and web applications to reflect the new release.
2026-10-02 10:27:42 +02:00
konstantin-paulus
c4fbd51f1d Add WINDOW_SHOW channel and integrate into upgrade dialog
- Introduced a new channel `WINDOW_SHOW` to manage window visibility.
- Updated `main-channels.ts` to define the new channel and its request/response structure.
- Integrated the `WINDOW_SHOW` channel in `main.ts` to handle window display requests.
- Modified the `showUpgradeDialog` function in `upgrade-dialog.tsx` to call the new channel when the dialog is opened, enhancing user experience.
2026-10-02 09:47:21 +02:00
konstantin-paulus
371841b253 Implement file attachment handling in agent chat
- Added functionality to pick files from the system and handle dropped attachments in the chat composer.
- Introduced a new `pickAttachments` function to facilitate file selection, enhancing user experience.
- Updated the composer and home view to integrate the new attachment handling, allowing users to add files easily.
- Refactored attachment merging logic to streamline the process of managing attachments in the chat interface.
2026-10-02 09:26:14 +02:00
konstantin-paulus
f2d6f553b3 Refine alt-drag interaction handling in DocumentEditor
- Updated the alt-drag functionality to clarify that it duplicates elements before moving them, enhancing the user experience.
- Introduced a call to `transformSystem` during dragstart when alt is pressed and duplicates are present, ensuring proper state management during interactions.
- Improved documentation to reflect these changes for better understanding of the interaction model.
2026-10-02 09:19:01 +02:00
konstantin-paulus
b59fdff188 Enhance config write handling and claim management
- Introduced a mechanism to manage overlapping config writes, ensuring that only the last write is retained while previous writes are settled.
- Added a claims system to track writes and prevent unnecessary updates, improving performance during rapid changes.
- Updated tests to verify the behavior of config writes and outside edits, ensuring accurate reporting and state management.
2026-10-02 09:10:24 +02:00
konstantin-paulus
ef3a20d4ba Add GitHub workflow for bumping winget package
- Created a new workflow to automate the process of updating the winget package for each published release.
- The workflow retrieves the latest release tag, validates it, and submits updates to the winget-pkgs repository using the Komac tool.
- Includes error handling for draft releases and ensures the installer URL is accessible before submission.
- Requires a WINGET_TOKEN secret for authentication during the submission process.
2026-10-02 08:45:36 +02:00
konstantin-paulus
f1f6d87862 Add prePackage hook for Windows signing validation
- Implemented a prePackage hook in the Forge configuration to check for necessary environment variables for Windows signing.
- Updated the windowsSign function to return undefined instead of throwing an error if required variables are missing, improving error handling during the signing process.
2026-10-01 10:38:37 +02:00
Konstantin Paulus
3a979f1660
Merge pull request #89 from diffusionstudio/tray
Tray
2026-10-01 09:03:36 +01:00
konstantin-paulus
ce9724df2c Update package versions to 0.209.0 across all modules
- Incremented version numbers in `package.json` and `package-lock.json` for the main editor, CLI, desktop, and web applications to reflect the new release.
2026-10-01 10:02:22 +02:00
konstantin-paulus
7215d92631 Update README to reflect new branding message
- Changed the tagline from "The professional video editor built for agents" to "Turn your agent into a professional video editor" to better convey the application's purpose and appeal.
2026-10-01 09:52:52 +02:00
konstantin-paulus
dd961f9ec2 Add tray menu icons and enhance theme support
- Introduced new tray menu icons for various application states (open, hide, ready, busy, project, quit) to improve user experience.
- Enhanced the `AppTray` class to support dynamic icon updates based on the current theme (light/dark).
- Updated the context menu to include icons alongside labels for better visual representation.
- Added a new script command in `package.json` for generating tray menu icons.
2026-10-01 09:23:27 +02:00
konstantin-paulus
d2f0ecb1de Enhance CLI and Desktop Functionality
- Updated the CLI to include a new `window` command for managing the application window state (show/hide).
- Improved the background launch logic to prevent launching the app if it is already running in the background.
- Added new tray icons for different application states (busy, idle, window) to enhance user experience.
- Refactored the `agent-chat` module to improve the handling of the agent chat endpoint and its lifecycle.
- Introduced a `WindowHost` class to manage the main window's lifecycle, ensuring it only exists when needed and integrates with the tray functionality.
- Removed the deprecated `headless` module and adjusted related logic to streamline the application flow.
- Updated the DAPI server to support window management, allowing tools to interact with the main window effectively.
2026-10-01 09:11:07 +02:00
Konstantin Paulus
a69468fb5d
Merge pull request #86 from diffusionstudio/google-font-integration
Release v0.208.0
2026-09-30 11:49:58 +01:00
konstantin-paulus
f7f6ee02a3 Update package versions to 0.208.0 across all modules
- Incremented version numbers in `package.json` and `package-lock.json` for the main editor, CLI, desktop, and web applications to reflect the new release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 12:47:39 +02:00
konstantin-paulus
f2a82581c9 Update Caption Text Styles and Highlight Color
- Changed font family from 'Poppins' to 'Outfit' and adjusted font weights in both `guinea.ts` and `spotlight.ts` for consistency in text styling.
- Updated the highlight color in `spotlight.ts` to improve visual distinction in captions.
2026-09-30 12:43:02 +02:00
konstantin-paulus
11995532b6 Refactor Export Progress Component and Enhance Cancel Functionality
- Updated the `ExportProgress` component to include an alert dialog for confirming export cancellation, improving user experience during export operations.
- Removed unnecessary props from the component, simplifying its interface and enhancing maintainability.
- Adjusted the rendering logic to display audio or video export status based on the `audioOnly` prop.
- Modified the `ExportProvider` to pass the new `audioOnly` state, ensuring accurate progress reporting.
- Streamlined the `RenderOverlayState` to focus on essential properties, enhancing clarity in the export process.
2026-09-30 12:29:16 +02:00
konstantin-paulus
fc63b73214 Add Google Fonts Support and Enhance Font Picker Functionality
- Introduced new options for the `fonts` command to filter by provider and popular fonts, enhancing user experience in font selection.
- Updated the documentation to reflect the inclusion of Google Fonts and local fonts, clarifying how to access and utilize them in projects.
- Implemented a new `FontDropdown` component in the web inspector for improved font selection, allowing users to choose from popular and Google Fonts seamlessly.
- Refactored existing components to integrate the new font selection logic, ensuring consistency across the application.
2026-09-30 11:57:25 +02:00
konstantin-paulus
b06d5b21c7 Remove Tracking Settings Component from Inspector
- Deleted the `TrackingSettings` component and its associated logic from the inspector, streamlining the sidebar functionality.
- Updated the inspector to no longer display tracking settings for shape targets, improving clarity and focus on relevant settings.
2026-09-30 10:49:14 +02:00
konstantin-paulus
f00276fd86 Enhance Animation Documentation and Logic
- Updated the animations documentation to clarify the behavior of presets, emphasizing that they scale or shift the node's authored properties rather than replacing them.
- Modified the `applyAnimation` function to ensure that computed values are compounded correctly for overlapping animations, improving the accuracy of visual effects during animation playback.
2026-09-29 22:21:23 +02:00
konstantin-paulus
d302d4b938 Remove redundant assignment of computed.chars in resetAnimatedValues function to prevent static node issues with text motion overrides. 2026-09-29 20:36:28 +02:00
konstantin-paulus
5310ff0324 Sync lockfile jsx version to 0.207.0 2026-09-29 10:07:43 +02:00
Konstantin Paulus
52e3a2a997
Merge pull request #85 from diffusionstudio/motion-tracking
Motion tracking
2026-09-29 08:48:49 +01:00
konstantin-paulus
8c5529eacf Implement Background Track Handling in Media Segment Tool
- Enhanced the `present` function to support background track processing in the `media_segment` tool, allowing for real-time tracking and reporting of mask states.
- Introduced a new `presentContext` function to manage the output of background tracks, including their progress and contact sheets.
- Updated the `context` tool to report the status of ongoing background tracks, including their state and associated images.
- Modified the `media_segment` tool to return tracking states and paths, improving integration with the `<mask>` component in the editor.
- Enhanced documentation to clarify the new behavior and usage of background tracks in the context of media segmentation.
2026-09-29 01:29:31 +02:00
konstantin-paulus
22d32d9c22 Enhance Support for Mask Assets Across Components
- Updated various components to recognize and handle mask assets, including `getLayerIcon`, `insertAsset`, and `resolveStill`.
- Modified rendering and styling logic in the timeline to accommodate mask types, ensuring consistent behavior with other asset types.
- Enhanced documentation to clarify the handling of mask assets in the timeline and related functionalities.
2026-09-29 01:00:11 +02:00
konstantin-paulus
a6e27ef3f2 Implement Clip Path Tool and Enhance Toolbar Functionality
- Added the `ClipPathBar` component to the toolbar for managing clip paths.
- Updated the toolbar logic to clear the clip path target when switching tools.
- Refactored the toolbar's tool selection to use a `Switch` statement for better readability.
- Integrated clip path functionality into the inspector, allowing users to begin clip paths directly from the UI.
- Updated cursor settings to reflect the new clip path tool type.
- Enhanced keyboard shortcuts to support clip path actions, improving user interaction.
2026-09-29 00:42:45 +02:00
konstantin-paulus
77f7513960 Update package versions to 0.207.0 across all modules
- Incremented version numbers in `package.json` and `package-lock.json` for the main editor, CLI, desktop, web applications, and JSX package to reflect the new release.
- Ensured consistency in versioning across all related packages to maintain compatibility.
2026-09-29 00:08:50 +02:00
konstantin-paulus
794c5d8a83 Enhance Asset Thumbnail Component to Support Mask Assets
- Updated the `AssetThumbnail` component to recognize and handle mask assets by introducing a new `hasPicture` function.
- Modified the thumbnail rendering logic to include masks alongside images and videos, improving asset representation.
- Enhanced documentation to clarify the types of assets supported for thumbnail generation.
2026-09-28 23:31:43 +02:00
konstantin-paulus
ae33eabe52 Enhance Text Editing Functionality in JSX Elements
- Added tests to verify that text edits preserve associated paint elements and only replace the text content within JSX elements.
- Updated the `setText` function to ensure that only the text is replaced while retaining other child elements, such as paint and comments.
- Improved the logic for identifying which parts of an element's children are considered as text, enhancing the accuracy of text replacements.
- Enhanced documentation to clarify the behavior of text replacements in JSX structures.
2026-09-28 23:22:22 +02:00
konstantin-paulus
a2ff21575a Refactor Appearance Settings and Source Rows Integration
- Updated the `AppearanceSettings` component to include `SourceRows`, which displays source information only when the node has an intrinsic paint or fill.
- Removed the deprecated `SourceSettings` component from the `Inspector`, streamlining the inspector's structure.
- Enhanced the `SourceRows` component to manage media and solid fill display logic, improving clarity and usability in the appearance panel.
- Adjusted documentation and comments for better understanding of the source rendering logic.
2026-09-28 23:03:08 +02:00
konstantin-paulus
b195be7d01 Enhance Text Rendering and Inspector Logic
- Updated the `DrawOverlay` component to include a `SolidPaint` element within the `Text` component, allowing for customizable text color.
- Modified the `Inspector` component to expand the target check for text elements, improving the settings display for text-related shapes.
- Refactored the `SolidFillRow` logic to dynamically determine the property to edit based on the node type, enhancing flexibility in color management.
2026-09-28 22:00:34 +02:00
konstantin-paulus
67e783e5c8 Add Media Segment Tool for Object Tracking in Video
- Introduced the `media_segment` tool to segment objects in video footage using SAM 2.1, allowing users to track objects and generate mask files.
- Implemented input validation for prompts, ensuring at least one point or a bounding box is provided for segmentation.
- Enhanced the output structure to include mask paths and tracking details, improving integration with the `<mask>` component in the editor.
- Added comprehensive documentation for the new tool, detailing usage, input parameters, and expected outputs.
- Updated related components and tests to support the new functionality, ensuring robust performance and user experience.
2026-09-28 15:35:40 +02:00
konstantin-paulus
16fe0cbec0 Update DropdownMenuContent and SelectContent for Improved Height Management
- Modified the `DropdownMenuContent` in `EffectsInspector` to include a maximum height constraint, enhancing usability by preventing overflow.
- Updated the `SelectContent` in `ObjectMaskInspector` to similarly enforce a maximum height, ensuring a consistent and user-friendly interface across components.
2026-09-28 14:39:20 +02:00
konstantin-paulus
95b9531719 Implement Object Mask Tool Integration and Refactor Logic
- Introduced the `useObjectMaskTool` hook for reactive management of the object mask tool's state, including mode, operation, and brush radius.
- Refactored the `ObjectMaskBar` and related components to utilize the new hook, enhancing clarity and maintainability.
- Updated interaction logic to streamline the handling of object mask operations, ensuring consistent behavior across the application.
- Improved documentation and code organization to support the new structure and enhance developer understanding.
2026-09-28 14:35:08 +02:00
konstantin-paulus
7e788582a4 Enhance Object Mask Bar and Interaction Logic
- Updated the `OpMenu` component to conditionally disable based on the object mask mode, improving user experience by preventing invalid operations.
- Refined the `handleObjectMaskInteraction` function to clarify the brush's behavior, ensuring it only adds to the mask while points can subtract.
- Adjusted the brush outline drawing logic to simplify the visual feedback during interactions, enhancing clarity for users.
- Improved documentation for better understanding of the interaction mechanics and brush functionality.
2026-09-28 14:13:03 +02:00
konstantin-paulus
b603f8b1da Refactor Object Mask Bar and Enhance Progress Display
- Updated the `ObjectMaskBar` to improve the tracking progress display, utilizing a new `FixedWidth` component for better alignment and readability.
- Removed deprecated destination logic from the tooltip content, streamlining the user interface.
- Introduced `ModelProgress` component to show model loading progress alongside its label, enhancing user feedback during operations.
- Added `resetObjectMaskTools` function to reset object mask settings when the tool is put down, improving user experience and consistency.
- Improved overall code organization and documentation for better maintainability.
2026-09-28 13:04:51 +02:00
konstantin-paulus
b528d8844c Enhance Object Mask Bar with Hover Functionality and Improved Documentation
- Introduced hover functionality in the `ObjectMaskBar` to display model-specific hints, enhancing user interaction.
- Updated model notes for clarity on when to use each model, improving user guidance.
- Refactored the `ModelMenu` to integrate the new hover state and tooltip-like hints, streamlining the user experience.
- Improved overall code organization and documentation for better maintainability and clarity.
2026-09-28 12:35:46 +02:00
konstantin-paulus
3f38c5eb60 Enhance Object Mask Tool Functionality and UI Integration
- Integrated the `ObjectMaskBar` into the `Toolbar`, allowing for dynamic display based on the selected tool.
- Updated the `Inspector` component to remove the deprecated `ObjectMaskPanel`, streamlining the interface.
- Refactored shortcut handling to include new actions for the object mask tool, improving user interaction.
- Enhanced object mask interaction logic to support dynamic operation modes (add/subtract) based on user input.
- Improved overall code organization and documentation for better clarity and maintainability.
2026-09-28 12:27:37 +02:00
konstantin-paulus
caefe16d67 Refactor Object Mask Handling and Introduce useObjectMasks Hook
- Updated the `EffectsInspector`, `ObjectMaskInspector`, and `TrackingSettings` components to utilize the new `useObjectMasks` hook for improved mask management.
- Removed deprecated functions and streamlined mask retrieval logic, enhancing performance and readability.
- Adjusted rendering conditions to reflect the new structure, ensuring accurate display of footage and associated masks.
- Improved overall code organization and documentation to support the new mask handling approach.
2026-09-28 11:50:33 +02:00
konstantin-paulus
f40cadc07f Add Tracking Settings to Inspector Component
- Integrated the new `TrackingSettings` component into the `Inspector`, allowing users to manage tracking options for shapes.
- Updated the rendering logic to conditionally display `TrackingSettings` based on the selected target, enhancing user interaction and functionality.
- Improved the overall structure of the inspector to accommodate the new settings, ensuring a cohesive user experience across components.
2026-09-28 11:36:25 +02:00
konstantin-paulus
5d1d023ea0 Remove Object Mask SVG Icon and Update Toolbar References
- Deleted the `tool.object-mask.svg` file to streamline icon assets.
- Updated the `Toolbar` component to reference the new icon name for the Object Mask tool, ensuring consistency in the UI.
- Refactored the `EffectsInspector` and `ObjectMaskInspector` components to improve mask handling and UI interactions, enhancing overall user experience.
2026-09-28 10:42:36 +02:00
konstantin-paulus
c7eb628ac0 Refactor Object Mask Commit Logic and Cleanup
- Removed the unused `slug` function from the `copy.tsx` file to streamline the codebase.
- Updated the `commit.tsx` file to enhance the naming convention for stored mask files, ensuring they follow the format `Tracking <n>.mask` within the appropriate folder.
- Improved documentation to clarify the structure of mask file storage and the logic for generating unique tracking names.
- Refactored the asset storage logic to utilize a more concise approach for folder and name generation, enhancing code readability.
2026-09-28 10:17:44 +02:00
konstantin-paulus
4d5d9fc780 Refactor Mask Terminology and Functionality
- Updated references from "matte" to "mask" across various components and files to align with new terminology.
- Adjusted related logic in the `EffectsInspector`, `ObjectMaskInspector`, and other components to ensure consistent behavior with the updated mask handling.
- Refactored caching and serialization processes to accommodate the new mask structure, enhancing overall functionality.
- Improved documentation and type definitions to reflect the transition from mattes to masks, ensuring clarity for developers.
2026-09-28 10:14:19 +02:00
konstantin-paulus
cde1cc1b53 Refactor Mask Functionality to Clip Path
- Renamed mask-related components and functions to reflect the new terminology of "clip path" throughout the codebase.
- Introduced a new `ClipPathsSettings` component for managing clip paths in the inspector.
- Updated the `Inspector` to integrate clip path settings and adjusted related logic to accommodate the new structure.
- Enhanced the `ObjectMenu` to change "Set mask target" to "Set clip path target" for clarity.
- Refactored various utility functions and traits to replace mask references with clip path equivalents, ensuring consistent behavior across the application.
- Updated documentation and type definitions to reflect the transition from masks to clip paths, improving clarity for developers.
2026-09-28 09:56:30 +02:00
konstantin-paulus
b7866279fa Implement Object Mask Tool Enhancements and UI Integration
- Added new `ObjectMaskPanel` component to manage object masks within the effects inspector.
- Introduced functionality for adding and managing object masks, including dropdown menus for selecting masks and controls for editing.
- Enhanced the `EffectsInspector` to support object mask interactions, including displaying existing masks and allowing users to track new objects.
- Implemented brush functionality for painting masks directly onto video clips, improving user experience for object segmentation.
- Updated cursor styles for the object mask tool to provide clearer visual feedback during interactions.
- Refactored related components and utilities to support the new object mask features, ensuring seamless integration with existing functionality.
2026-09-28 09:41:49 +02:00
konstantin-paulus
88f74f8bfe Enhance SAM 2.1 model structure and GPU processing
- Updated `package.json` to include new model export for `./models`.
- Expanded `constants.ts` to define new types and structures for SAM 2.1 models, including `Sam2Model` and `Sam2Geometry`.
- Refactored `gpu.ts` to utilize dynamic image sizes and geometry for frame processing, improving flexibility in GPU operations.
- Enhanced `load.ts` to support model-specific loading and progress tracking, optimizing the user experience during model initialization.
- Updated `mask.ts` to redefine mask handling with logits and improved painting functionality for strokes.
- Refactored `tracker.ts` to integrate new model structures and enhance video tracking capabilities with corrected masks.
- Improved documentation and type definitions across the codebase for better clarity and usability.
2026-09-27 23:43:47 +02:00
konstantin-paulus
37f6195ba0 Enhance model loading and session creation for SAM 2.1
- Introduced `readFloat16Initializer` function in `onnx.ts` to read float16 initializers from model bytes, improving model loading capabilities.
- Updated `createSession` function in `sessions.ts` to accept additional options for session configuration, allowing for enhanced flexibility during model execution.
- Modified the `load` function in `load.ts` to utilize the new initializer and pass position tokens to the `Sam2Video` constructor, optimizing video processing.
- Refactored `Sam2Video` class to handle position tokens, ensuring accurate representation of the vision encoder's positional embeddings during video tracking.
2026-09-26 23:05:43 +02:00
konstantin-paulus
e63f1c7a0f Implement Object Mask Tool and Enhance UI Components
- Added the `Object Mask` tool to the toolbar and sidebar menu, allowing users to select and utilize this new functionality.
- Introduced a new SVG icon for the `Object Mask` tool to improve visual representation in the UI.
- Updated the `Inspector` component to display the `ObjectMaskPanel` when the `Object Mask` tool is selected.
- Enhanced the `Effect` options to include `opacity`, allowing for more refined control over visual effects.
- Updated documentation to reflect the new `<mask>` element and its properties, improving clarity for developers.
- Refactored related components to ensure seamless integration of the new tool and its functionalities.
2026-09-26 20:40:12 +02:00
konstantin-paulus
1882b539c9 Enhance SAM 2.1 video tracking functionality and update export parameters
- Updated `export.py` to include model size as a parameter for ONNX graph exports, improving flexibility in model loading.
- Refactored the `load` function to accept a checkpoint string, allowing dynamic model loading based on specified size.
- Introduced new methods in `tracker.ts` for holding and previewing frames, enhancing the user experience during object segmentation.
- Updated type exports in `video.ts` to include `FrameRequest`, facilitating better integration with the tracking system.
- Improved documentation and comments throughout the codebase for clarity on new features and functionality.
2026-09-26 16:45:06 +02:00
konstantin-paulus
70b2fa3ddf Remove convert_fp16.py script and introduce export.py for ONNX model export
- Deleted the `convert_fp16.py` script, which was responsible for converting ONNX models from fp32 to fp16.
- Added `export.py` script to export fixed-shape ONNX graphs for SAM 2.1 video tracking, ensuring compatibility with input parameters for image size and memory frames.
- Updated `constants.ts` to reflect changes in model repository links and fixed shapes for `IMAGE_SIZE` and `MEMORY_FRAMES`.
- Adjusted memory management and constants in various source files to align with the new export functionality.
2026-09-26 10:22:23 +02:00
konstantin-paulus
6d275f1a61 Add fp16 conversion script and update model repository links
- Introduced `convert_fp16.py` script for converting ONNX models from fp32 to fp16, optimizing memory usage while maintaining input/output compatibility.
- Updated `MODEL_REPO` in `constants.ts` to point to the new fp16 model repository, reflecting changes in model file sizes.
- Enhanced `weights.ts` to retain model files in the cache, improving file management during model loading.
2026-09-26 09:39:17 +02:00
konstantin-paulus
6c3901e543 Add SAM 2.1 video object segmentation and tracking package
- Introduced the `@diffusionstudio/sam2` package for video object segmentation and tracking in the browser using ONNX Runtime on WebGPU.
- Added essential files including `package.json`, `tsconfig.json`, and various source files for core functionality, constants, and GPU processing.
- Implemented model file fetching and caching from Hugging Face, along with memory management for tracking objects across frames.
- Included shaders for preprocessing video frames and transposing feature maps for memory attention.
- Established a comprehensive API for loading models, processing frames, and tracking objects with segmentation masks.
- Ensured type definitions and module exports for seamless integration with existing projects.
2026-09-25 23:36:58 +02:00
konstantin-paulus
6879ea773f Update package-lock.json and README for CLI enhancements
- Added 'diffusion' as a new command in package-lock.json alongside 'dapi'.
- Revised README to describe a new promotional video for https://typesafe.ai/, improving clarity and alignment with branding.
2026-09-24 23:09:47 +02:00
konstantin-paulus
666cdced1f Update version to 0.206.0 and enhance CLI functionality
- Bumped version for @diffusionstudio/editor, @diffusionstudio/cli, @diffusionstudio/desktop to 0.206.0.
- Updated README to reflect changes in download options for macOS and Windows.
- Refactored CLI commands to use 'diffusion' instead of 'dapi' for consistency.
- Added new scripts for Windows asset generation and improved build workflows.
- Introduced new dependencies for enhanced functionality in the desktop application.
2026-09-23 15:53:34 +02:00
konstantin-paulus
2a3632aad5 Remove Windows support implementation plan document
- Deleted the `WINDOWS.md` file, which contained the implementation plan for Windows support in the desktop application.
- This document outlined goals, design decisions, and stages for achieving feature parity with macOS, but is no longer needed as the project progresses.
2026-09-23 15:49:32 +02:00
konstantin-paulus
2f05fbea8f Refactor CLI installation and status handling to support diffusion command
- Updated the CLI installation logic to use `diffusion` instead of `dapi`, including changes to link paths and installation scripts for macOS.
- Enhanced the status checking functions to reflect the new command structure, ensuring accurate detection of installed links.
- Adjusted comments and documentation throughout the codebase to improve clarity regarding the `diffusion` command and its aliases.
- Ensured backward compatibility by maintaining `dapi` as an alias where necessary.
2026-09-23 15:31:40 +02:00
konstantin-paulus
7a9393d4e2 Refactor CLI command references from dapi to diffusion in source files
- Updated all instances of the CLI command from `dapi` to `diffusion` in the desktop and web applications for consistency.
- Adjusted related comments and documentation to reflect the new command name, improving clarity for users and developers.
- Ensured that the changes are applied across relevant files, including configuration and dashboard components.
2026-09-23 15:21:24 +02:00
konstantin-paulus
943912f247 Add OpenCode support in MCP configuration
- Introduced OpenCode as a new agent in the MCP configuration, updating the `ServerEntry` type to include boolean values.
- Enhanced the `agentTarget` function to accommodate OpenCode's specific entry format.
- Updated tests to verify OpenCode's integration and ensure proper handling of its configuration settings.
- Added OpenCode's icon to the agent icons mapping in the web application.
2026-09-23 15:05:22 +02:00
konstantin-paulus
1539fbc2e9 Refactor CLI command names from dapi to diffusion across documentation and codebase
- Updated all instances of the CLI command from `dapi` to `diffusion` in README, documentation, and source files for consistency.
- Adjusted related scripts and examples to reflect the new command name, enhancing clarity for users and developers.
- Ensured backward compatibility by maintaining `dapi` as an alias where necessary.
2026-09-23 14:49:01 +02:00
konstantin-paulus
baeaad6b0a Update package versions to 0.206.0 across all modules
- Bumped version number from 0.205.2 to 0.206.0 in package.json and package-lock.json for the editor, CLI, desktop, and web applications, ensuring consistency across the project.
2026-09-23 14:37:21 +02:00
konstantin-paulus
dc8f95eba7 Update installation spinner asset and adjust background colors in win-assets.py
- Replaced the installation spinner GIF with an updated version to enhance the installation UI.
- Modified background and track colors in the `win-assets.py` script for improved visual consistency during the installation process.
2026-09-22 15:32:41 +02:00
konstantin-paulus
bdf04a858e Add Windows-specific assets and update build scripts
- Introduced `assets/icon-win.png` for a Windows-optimized application icon.
- Added `assets/install-spinner.gif` for a custom installation spinner, enhancing the user experience during installation.
- Replaced the previous `make-ico.sh` script with a new `win-assets.py` script to generate both the icon and spinner assets, streamlining the asset generation process.
- Updated `package.json` to include new npm scripts for generating Windows assets, improving build automation.
2026-09-22 15:26:26 +02:00
konstantin-paulus
3beb859f31 Enhance Windows build process in forge.config.ts
- Added a preMake hook to ensure the presence of 7zip binaries for Windows builds.
- Introduced the ensure7zip function to copy necessary 7zip files if they are missing, improving the Windows signing process.
2026-09-22 15:04:49 +02:00
konstantin-paulus
39e65953ea Add description to MakerSquirrel configuration in forge.config.ts 2026-09-22 14:55:05 +02:00
konstantin-paulus
3198fbade4 Update README and enhance Windows signing process
- Revised the README to include download options for both macOS and Windows, improving clarity for users.
- Enhanced the `release.yml` workflow to include a new `publish-windows` job for signing and publishing Windows builds using Azure Artifact Signing.
- Updated `forge.config.ts` to implement Windows signing configuration, ensuring all executables and packages are properly signed.
- Improved the desktop app download functionality to support both macOS and Windows, providing a better user experience across platforms.
2026-09-22 14:28:29 +02:00
konstantin-paulus
98251a55cd Update Windows documentation and enhance DAPI functionality
- Revised `WINDOWS.md` to reflect the successful execution of various DAPI commands on Windows, including checks for drag, double-click, scaling, theme switch, and fullscreen functionality.
- Updated the status of the CLI installation process on Windows, confirming the dev path runs and the packaged path awaits installer checks.
- Clarified the status of agent connections and session handling, ensuring accurate documentation of current capabilities and remaining tasks.
2026-09-22 10:53:01 +02:00
konstantin-paulus
82bc3fd294 Enhance Windows DAPI functionality and update environment handling
- Updated `WINDOWS.md` to reflect the successful execution of `dapi fonts` and `dapi screenshot` on Windows, including functionality from minimized windows.
- Improved temporary directory handling in `present.ts` to resolve issues with short names in the `%TEMP%` directory.
- Modified `knownDirs` in `env.ts` to ensure proper paths for local application data on Windows, enhancing compatibility for the agent chat feature.
2026-09-22 10:46:13 +02:00
konstantin-paulus
1324e365cf Update Windows documentation and enhance DAPI functionality
- Revised the `WINDOWS.md` file to reflect the current status of DAPI tools running on Windows, including successful connections and functionality checks.
- Implemented a new `tempDir` function in `present.ts` to ensure correct handling of temporary directories on Windows, improving compatibility.
- Updated the `store.ts` file to reorder preferred models for better prioritization in the agent chat feature.
2026-09-22 10:35:14 +02:00
konstantin-paulus
79765f55ad Enhance CLI linking process and update Windows documentation
- Updated the `dev-link.mjs` script to add the `dapi` command to the user PATH on Windows, improving accessibility for users.
- Revised the README to include instructions for running tests and clarified the linking process for the CLI.
- Enhanced the `WINDOWS.md` documentation to reflect the new user PATH entry functionality and its integration with the CLI installation process.
2026-09-22 09:54:37 +02:00
konstantin-paulus
2e1ccb14f9 Refactor CLI linking process and update documentation
- Replaced the `symlink:create` and `shim:create` scripts with a unified `link` script for creating a `dapi` command link on both macOS and Windows.
- Introduced a new `dev-link.mjs` script to handle the linking logic, ensuring the latest CLI build is accessible.
- Updated the README and various documentation files to reflect the new linking process and clarify installation instructions for the CLI.
- Removed the obsolete `dev-shim.mjs` script, streamlining the development workflow.
2026-09-22 09:37:31 +02:00
konstantin-paulus
4d4d2ebe39 Refactor Windows color mode handling and remove Mica implementation
- Simplified the color mode handling for Windows by removing the preference parameter from the `WINDOW_SET_COLOR_MODE` channel, ensuring a more straightforward integration with the title bar overlay.
- Eliminated the Mica implementation due to inconsistencies in visual appearance compared to macOS, reverting to a solid window style.
- Updated the `PreferencesMenu` to retrieve stored theme preferences more robustly, enhancing user experience.
- Removed unused backdrop-related code and CSS, streamlining the application and improving maintainability.
2026-09-21 16:59:10 +02:00
konstantin-paulus
a34c00d46a Enhance Windows Mica integration and sidebar styling
- Updated the Windows Mica implementation to improve color consistency between dark and light modes, adjusting sidebar transparency for better visual coherence.
- Modified CSS to define sidebar colors based on the Mica backdrop, ensuring appropriate alpha levels for dark mode.
- Refined the Windows title bar component to eliminate its background, allowing the sidebar color to show through, enhancing the overall aesthetic.
2026-09-21 16:53:15 +02:00
konstantin-paulus
7145e692be Implement Windows Mica support and enhance color mode handling
- Introduced Mica support for Windows 11, allowing the app to utilize a transparent backdrop that follows the system theme.
- Updated the color mode handling to differentiate between the displayed mode and user preference, ensuring a consistent user experience.
- Enhanced the title bar overlay logic to accommodate Mica, improving visual integration with the Windows environment.
- Adjusted the preload and main channels to pass backdrop information, enabling transparent rendering in the web context.
- Refactored various components to ensure proper functionality and styling under the new backdrop conditions.
2026-09-21 16:47:22 +02:00
konstantin-paulus
9c9768dee7 Refactor basename function to improve path handling
- Updated the `basename` function to trim trailing slashes from the input path, ensuring more accurate extraction of the base name.
- Enhanced the logic to handle both forward and backward slashes, improving compatibility across different operating systems.
2026-09-21 15:40:15 +02:00
konstantin-paulus
88b584f01b Update Windows overlay colors for improved UI consistency
- Adjusted the symbol colors in the Windows overlay to align with the sidebar's muted foreground, enhancing visual coherence across the application.
- Updated comments to clarify the design intent behind the Windows overlay and its color scheme.
2026-09-21 15:20:54 +02:00
konstantin-paulus
7904774023 Refactor dashboard components for improved Windows support and search functionality
- Updated the `DashboardProjectsView` to manage its own search state, removing the need for props.
- Enhanced the `DashboardSearchBar` and `DashboardSearchPanel` for consistent rendering across platforms.
- Introduced a new `DashboardSidebarTitleBar` component for Windows, aligning with native window controls.
- Adjusted styles in various components to ensure proper layout and functionality on Windows desktop.
2026-09-21 15:16:27 +02:00
konstantin-paulus
e556af4bfd Enhance Windows title bar functionality and dashboard search integration
- Added a `class` prop to the `WindowsTitleBar` component for improved styling flexibility.
- Updated the `DashboardPage` to conditionally render the `DashboardSearchBar` based on the current view, ensuring search functionality is only available in the projects view.
- Refactored the project search handling to streamline user experience when switching views.
2026-09-21 14:55:09 +02:00
konstantin-paulus
0d332f417c Add Windows title bar support and refactor dashboard components
- Introduced a Windows-specific title bar (`WindowsTitleBar`) for the dashboard and editor, enhancing the UI on Windows platforms.
- Updated `DashboardProjectsView` to accept search props, allowing for search functionality from the title bar.
- Refactored `DashboardSearchBar` and `DashboardSearchPanel` to conditionally render based on the platform, improving layout consistency.
- Adjusted styles and layout in various components to accommodate the new title bar, ensuring a seamless user experience across platforms.
- Enhanced project navigation and search handling to maintain context when switching views.
2026-09-21 14:41:48 +02:00
konstantin-paulus
1bcbea6093 Remove whoami command and related references from the CLI and documentation
- Deleted the `whoami` command from the CLI, including its associated action and description.
- Updated various documentation files to remove references to the `whoami` tool, ensuring consistency across the project.
- Adjusted related test cases and API handlers to reflect the removal of the `whoami` functionality.
2026-09-20 20:52:52 +02:00
konstantin-paulus
307a6a4a76 Implement Windows CLI shim and update installation process
- Added a new `dev-shim.mjs` script for creating and removing a Windows shim for the `dapi` command, ensuring it points to the correct executable.
- Updated the `package.json` to include new npm scripts for creating and removing the shim.
- Refactored the CLI installation logic to support Windows, including the addition of `refreshCliShim` to rewrite the shim on app updates.
- Enhanced the `mcp-config` to accommodate Windows-specific command handling for the `dapi` binary.
- Introduced tests for the Windows CLI installation and cloud sync functionalities to ensure reliability across platforms.
2026-09-20 15:28:14 +02:00
Konstantin Paulus
57c39834bb
Restore 'How it works' section in README
Reintroduced the 'How it works' section in the README with details about Diffusion Studio's functionality and editing capabilities.
2026-09-20 12:01:19 +02:00
konstantin-paulus
233cf487e5 Merge branch 'main' into windows-support-impl 2026-09-18 14:57:46 +02:00
Konstantin Paulus
0add88db09
Merge pull request #78 from diffusionstudio/chat-improvements
Chat improvements
2026-09-18 09:56:10 +02:00
konstantin-paulus
1a10ee1583 Enhance caption positioning logic in media runtime
- Updated the caption positioning function to account for `Sequential` traits, ensuring proper handling of parent nodes that are not spatial constructs.
- Improved the logic for retrieving the parent node, enhancing the accuracy of caption placement within the media runtime.
2026-09-18 09:35:22 +02:00
konstantin-paulus
e0ff7ecaea Refactor attachment display in agent chat components
- Updated the `AttachmentChip` component to include a border and change the background to transparent, enhancing visual clarity.
- Modified the `UserItem` component layout to improve the display of attachments and conditionally render the item text, ensuring better organization and readability.
2026-09-18 09:24:38 +02:00
konstantin-paulus
ac7f6aa247 Enhance project navigation with return state management
- Integrated `useReturnHere` hook to capture the current location state for project navigation, allowing users to return to the previous view after opening a project.
- Updated navigation calls in `DashboardHomeView`, `DashboardProjectsView`, and `FileMenu` components to include the return state, improving user experience by maintaining context.
- Refactored `ProjectMenu` and `ProjectPage` to utilize location state for consistent navigation behavior across the application.
2026-09-17 23:28:57 +02:00
konstantin-paulus
a0f843fcac Refactor prop handling in JSX editing
- Removed the `isWritable` function, simplifying the logic for determining if a prop can be overwritten.
- Updated the `applyEdits` method to allow overwriting props with expressions, ensuring user edits take precedence over existing values.
- Clarified comments to reflect the new behavior of prop value handling, enhancing code readability and maintainability.
2026-09-17 23:27:54 +02:00
konstantin-paulus
0afd65d33e Update project menu navigation to use dynamic dashboard route
- Modified the `handleOpenDashboard` function in the ProjectMenu component to navigate using a new `dashboardRoute` function, enhancing routing flexibility based on the current dashboard view.
- Introduced `dashboardRoute` in the dashboard page to determine the correct path based on the last viewed dashboard state, improving user experience and navigation consistency.
2026-09-17 21:08:40 +02:00
konstantin-paulus
0110f8c2d2 Implement auto-scrolling feature in Transcript component
- Added a new `pin` function to ensure the chat view automatically scrolls to the bottom when new messages are received or when the chat key changes.
- Updated the effect dependencies to include both `chatKey` and message length, enhancing the user experience by keeping the latest messages in view.
2026-09-17 20:51:23 +02:00
konstantin-paulus
5166153c29 Refactor agent chat components and update sidebar functionality
- Removed the right sidebar component and replaced it with a left sidebar structure, enhancing the layout for better usability.
- Updated sidebar tab labels from "Editor" to "Assets" to reflect the new structure.
- Adjusted the sidebar width calculations and related settings to accommodate the new layout.
- Enhanced the ChatPanel and HeaderActions components for improved integration with the updated sidebar.
- Streamlined the Assets component to include SidebarTabs for consistent navigation.
2026-09-17 20:42:52 +02:00
konstantin-paulus
e7c71ba21e Enhance cask bump workflow with tag validation and retry logic
- Added validation to ensure only valid version tags (vX.Y.Z) are used for cask updates, preventing erroneous bumps.
- Implemented retry logic for downloading the DMG file to handle potential 404 errors during the release event, improving reliability.
2026-09-17 13:26:44 +02:00
konstantin-paulus
f1e6809c20 Remove unused skill management and prompt serving functionality
- Deleted the `prompts-session.ts` and its associated test file, as they are no longer needed.
- Removed the `Skill` type and related functions from `docs.ts`, streamlining the codebase by eliminating unnecessary complexity.
- Updated the `DapiServer` class to reflect these changes by removing the `servePrompts` call, ensuring the server's functionality remains focused on essential features.
2026-09-17 13:18:34 +02:00
konstantin-paulus
cb1116b23d Enhance desktop analytics tracking and event handling
- Updated the analytics module to support direct event posting to Umami from the main process, addressing the renderer's limitations in Electron.
- Introduced a new `trackEvent` function for product events, allowing the renderer to send analytics data through the main process.
- Modified the `trackInstall` function to streamline install tracking and ensure it only sends data on the first launch of a packaged build.
- Added a new `ANALYTICS_TRACK` channel in main-channels for handling analytics events from the renderer.
- Refactored the analytics tracking logic in the web context to improve event handling and reporting consistency.
2026-09-17 10:50:15 +02:00
konstantin-paulus
6d2d52450e Update package versions to 0.205.2 across all modules
- Incremented version number from 0.205.1 to 0.205.2 in package.json and package-lock.json for the editor, CLI, desktop, and web applications.
- Ensured consistency in versioning across all related packages.
2026-09-17 10:31:01 +02:00
konstantin-paulus
cb852b0ca5 Update brand documentation and assets
- Renamed and clarified sections in design, library, and video guides to enhance consistency and understanding.
- Removed outdated logo assets and adjusted references to branding terminology throughout the documentation.
- Updated color and typography guidelines to reflect a more neutral and flexible approach.
- Streamlined instructions for applying the brand style and using reusable components.
- Enhanced clarity in voice and language guidelines to ensure alignment with the updated brand identity.
2026-09-17 10:27:49 +02:00
konstantin-paulus
f0040775d1 Add skill management and prompt serving functionality
- Introduced a new `Skill` type to represent skills with their names, descriptions, and paths.
- Implemented `skills` function to read skills from `INSTRUCTIONS.md` and filter out missing pages.
- Added `skillPrompt` function to generate a prompt for each skill, including its content.
- Created `servePrompts` function to register skills as prompts in the MCP server, allowing clients to access them via slash commands.
- Added tests for the `servePrompts` functionality to ensure skills are listed and served correctly.
2026-09-17 10:07:43 +02:00
konstantin-paulus
46cef22b26 Enhance Windows support and update dependencies
- Added support for Squirrel.Windows in the desktop app, including configuration for the installer and metadata.
- Updated package-lock.json to include the latest version of @electron-forge/maker-squirrel and other dependencies.
- Modified build scripts to improve compatibility and streamline installation processes.
- Documented the current status of Windows implementation in WINDOWS.md, outlining next steps for CI integration.
2026-09-16 10:53:54 +02:00
konstantin-paulus
c9e655856c Add initial Windows support implementation plan
- Created a new document outlining the implementation plan for Windows support in the desktop app, aiming to match macOS features.
- Defined stages for development, starting with an installer and progressing to window chrome and menu integration.
- Included design decisions and specific tasks for each stage to ensure a cohesive development process.
- Established goals for functionality, including installer creation, window behavior, and CLI integration.
2026-09-16 10:26:43 +02:00
Konstantin Paulus
b31741213f
Merge pull request #68 from diffusionstudio/subagent-fix
Subagent fix
2026-09-14 21:20:02 +02:00
konstantin-paulus
5529819672 v0.205.1
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-14 21:03:21 +02:00
konstantin-paulus
5a229bd7a9 Update ClaudeSession to disallow specific tools and modify Codex spawn arguments
- Added `disallowedTools` property to `ClaudeSession` to restrict usage of "Agent" and "Task".
- Updated the arguments in `spawnAppServer` function in `codex.ts` to disable multi-agent features, enhancing configuration control.
2026-09-14 21:01:21 +02:00
konstantin-paulus
2593b928fe Refactor import statement in document.ts for consistency
- Updated the import statement for runtime components in document.ts to maintain consistent formatting and improve readability.
2026-09-14 11:56:13 +02:00
Konstantin Paulus
805affff28
Merge pull request #63 from diffusionstudio/mcp-support
Mcp support
2026-09-14 11:40:33 +02:00
konstantin-paulus
53a9ecc7d9 Merge remote-tracking branch 'origin/main' into mcp-support 2026-09-14 11:40:13 +02:00
konstantin-paulus
9cfdc0d921 Update package.json to add test script for workspaces
- Added a new `test` script to the `scripts` section of package.json, enabling testing across workspaces when present.
- Ensured consistency in script execution by maintaining the existing `check` script functionality.
2026-09-14 11:26:26 +02:00
konstantin-paulus
8691f37399 Refactor project creation and dashboard interaction logic
- Updated the `createNewProject` function to simplify project creation flow by removing unnecessary parameters and handling folder selection directly.
- Modified the `DashboardPage` component to replace the project creation logic with folder picking functionality, enhancing user experience.
- Removed unused imports and streamlined interaction handling in the `interactions.ts` file, improving code clarity and maintainability.
- Adjusted the `DocumentEditor` class to reset asset selection when a new selection is made, ensuring consistent state management.
2026-09-14 11:14:43 +02:00
konstantin-paulus
5d94b6d794 Add dynamic textarea height adjustment in DashboardHomeView
- Introduced a new constant `PROMPT_MAX_HEIGHT_PX` to limit the maximum height of the textarea.
- Implemented a height adjustment mechanism for the textarea that dynamically sets its height based on content, ensuring it does not exceed the defined maximum height.
- Updated the textarea class to allow for vertical scrolling when content exceeds the visible area, enhancing user experience.
2026-09-14 00:27:48 +02:00
konstantin-paulus
763ce7aa5c Enhance playhead management and update scene documentation
- Added `playhead` property to the scene, allowing the editor to track the playhead's position when the project is opened, improving playback accuracy.
- Introduced `editPlayhead` function to manage playhead updates, ensuring the file reflects the playhead's position during scrubbing and timeline interactions.
- Updated documentation to clarify the role of the `playhead` property in the scene, emphasizing its importance for project state management.
2026-09-14 00:16:55 +02:00
konstantin-paulus
3cf1453968 Enhance model selection logic in agent chat store
- Introduced a new constant `PREFERRED_MODELS` to prioritize model families during selection.
- Updated the `currentModel` function to first check for remembered models, then preferred models, and finally fallback to the first ready default, improving the model selection process for users.
2026-09-13 21:38:01 +02:00
konstantin-paulus
7d9d2330a5 Enhance app launch functionality and update route key
- Modified the `launchApp` function in `cli-client.ts` to ensure the environment is correctly passed when launching the app, preventing issues with Electron running as Node.
- Updated the `ROUTE_KEY` in `persist-route.tsx` to a new versioned key, improving route persistence management.
2026-09-13 21:27:24 +02:00
konstantin-paulus
2874735936 Update scene and stage documentation, and adjust default camera settings
- Enhanced the `scene.md` documentation to clarify the `workarea` property and its implications for playback and export.
- Revised the `stage.md` documentation to provide clearer guidance on the `camera` property, emphasizing the importance of setting a camera for non-standard compositions.
- Updated the default camera settings in the `world.ts` and `types.ts` files to better frame typical project dimensions, ensuring a more intuitive starting point for users.
2026-09-13 21:15:22 +02:00
konstantin-paulus
f023adb4cd Remove legacy skills cleanup functionality
- Deleted the `skills-cleanup.ts` file and removed the `pruneLegacySkills` function from `main.ts`, streamlining the codebase by eliminating unused features related to legacy skills management.
- Updated the main application logic to reflect the removal of the legacy skills pruning process.
2026-09-13 20:35:38 +02:00
konstantin-paulus
6bde47b9a1 Replace and remove SVG icons in the assets directory
- Deleted the old `agent-cursor.svg` and `antigravity.svg` icons, along with several other outdated icons.
- Introduced new SVG icons including `agent.claude-code.svg`, `agent.codex.svg`, `agent.cursor.svg`, `agent.devin-windsurf.svg`, `agent.google-antigravity.svg`, `agent.google-gemini-cli.svg`, `agent.vscode-copilot.svg`, and `dapi-cli.svg`.
- Updated the dashboard component to utilize new icons and improved the layout for better user experience.
- Refactored the `mcp-view.tsx` to enhance the handling of agent connections with a new toggle switch component.
2026-09-13 16:51:07 +02:00
konstantin-paulus
df9d7d9f84 Remove fetch command and related functionality from the application
- Deleted the `fetch` command from the CLI and associated handlers, streamlining the toolset.
- Updated documentation to reflect the removal of the `fetch` command, emphasizing the use of `yt-dlp` directly for downloading videos.
- Adjusted various components and types to remove references to `fetch`, ensuring consistency across the codebase.
- Enhanced error handling to clarify the absence of the `fetch` functionality.
2026-09-13 16:08:07 +02:00
konstantin-paulus
04f388ff33 Add project initialization tests and refactor project handling logic
- Introduced a new test suite in `projects.init.test.ts` to validate the behavior of the `initProject` function, ensuring it correctly initializes new projects and handles existing project directories.
- Refactored the `initProject` function in `projects.ts` to streamline project setup, including improved handling of entry files and package.json records.
- Enhanced error handling for invalid paths in the `initProject` function, ensuring only absolute paths are accepted.
- Updated the `scaffold` function to utilize the new `ensureRecord` function, improving code clarity and maintainability.
- Added tests for various scenarios, including creating new projects, preserving existing project data, and handling invalid inputs, to ensure robust project management functionality.
2026-09-13 15:53:07 +02:00
konstantin-paulus
223a39b87b Refactor project listing and update project handling logic
- Removed the `PROJECTS_LIST` channel and associated `listProjects` function, streamlining project retrieval to focus on direct project records.
- Updated the `MainRequestMap` to reflect the removal of the `PROJECTS_LIST` channel.
- Introduced `openProjectFromList` function to handle project opening logic, ensuring accurate project state management.
- Adjusted various components to utilize the new project handling methods, enhancing overall project management and user experience.
2026-09-13 13:19:47 +02:00
konstantin-paulus
c5bdfd88aa Update package versions to 0.205.0 across all modules
- Bumped version numbers in `package.json` and `package-lock.json` for the main editor and all related applications (CLI, desktop, web, and JSX) to 0.205.0, ensuring consistency across the project.
2026-09-13 12:35:37 +02:00
konstantin-paulus
b36383c50f Add PROJECTS_SCAN channel and implement project scanning functionality
- Introduced a new `PROJECTS_SCAN` channel in `main-channels.ts` to facilitate scanning for project folders.
- Implemented the `scanProjects` function in `projects.ts` to retrieve direct child directories of a specified root that could hold projects.
- Updated the main process in `main.ts` to handle requests for scanning projects.
- Adjusted the `DashboardProjectsFolderBar` component to improve the display of the selected projects folder.
- Refactored project root handling to utilize localStorage for better performance and user experience.
2026-09-13 12:30:39 +02:00
konstantin-paulus
79a27580df Refactor project creation logic and streamline dashboard interactions
- Introduced a new `createNewProject` function to centralize project creation logic, improving code reuse and clarity.
- Removed desktop-specific checks from project creation in `DashboardHomeView` and `DashboardProjectsView`, simplifying the user experience.
- Updated the `DashboardPage` to handle keyboard shortcuts for creating new projects, enhancing accessibility and user interaction.
- Improved error handling during project creation to provide clearer feedback to users.
2026-09-13 12:18:31 +02:00
konstantin-paulus
9e8b209f04 Refactor project handling and update request parameters
- Updated the `ProjectInfo` documentation to clarify project folder definitions.
- Changed request parameters in `MainRequestMap` for `PROJECTS_LIST` and `PROJECTS_RESOLVE` to use `dirs` and `dir` respectively, enhancing clarity and consistency.
- Refactored the `listProjects` function to accept an array of directories instead of a single root, improving project listing logic.
- Adjusted the `resolveProject` function to streamline project resolution based on directory input.
- Updated various components to reflect changes in project data handling, ensuring compatibility with the new structure.
2026-09-13 12:00:54 +02:00
konstantin-paulus
d9d5f3a19c Update build configuration and resource staging for runtime
- Added `runtime` to `.gitignore` to prevent unnecessary file tracking.
- Updated `forge.config.ts` to include `runtime` in the `extraResource` array for proper resource staging.
- Modified `package.json` scripts to include a new `stage:runtime` command, ensuring the runtime is staged alongside other resources during build processes.
- Adjusted `projects.ts` to load modules from the new `runtime` directory, enhancing the application's resource management.
2026-09-13 11:13:03 +02:00
konstantin-paulus
ba792a3295 Enhance attachment tile styling and improve composer layout
- Added a `class` prop to the `AttachmentTile` component for customizable styling.
- Updated the `composer.tsx` to apply a new class for better layout and spacing of attachment tiles, improving the overall user interface.
2026-09-13 10:44:03 +02:00
konstantin-paulus
f92a8339a4 Refactor documentation and enhance instruction clarity
- Updated the README to clarify how the app's MCP server interacts with agents, emphasizing the guidance provided during sessions.
- Removed outdated comments and code related to skill directories in `skills-cleanup.ts`, streamlining the cleanup process.
- Simplified the `docs.test.ts` file by removing unnecessary tests and focusing on the core functionality of the instructions.
- Refactored the `docs.ts` file to improve the instructions function, ensuring it accurately reflects the current documentation structure and skill usage.
- Enhanced the `server.ts` file by removing the registration of prompts, as this functionality has been deprecated, and clarified the documentation structure in comments.
- Updated `INSTRUCTIONS.md` to provide clearer guidance on using skills and their corresponding documentation, improving user onboarding.
2026-09-13 10:28:18 +02:00
konstantin-paulus
8346fcdcb2 Add atomic file writing functionality and enhance project file handling
- Introduced a new `atomic.ts` module for atomic file writing, ensuring that files are written to temporary locations before being renamed to their final destination, preventing partial reads.
- Updated the `onWrite` callback in `SourceContext` to include the text being written, allowing watchers to differentiate between app writes and external changes.
- Refactored file writing logic in `edit.ts`, `projects.ts`, and `main.ts` to utilize the new atomic writing method, enhancing reliability during file operations.
- Added tests to verify the behavior of the new atomic writing functionality and its interaction with the file watcher.
- Improved project file handling to ensure that changes made by the app do not trigger unnecessary reloads in the watcher.
2026-09-13 01:07:29 +02:00
konstantin-paulus
2367cb78da Refactor media selection and enhance prompt input component
- Updated the `PromptInput` component to improve layout responsiveness by adjusting the maximum width.
- Refactored the `useMediaSelection` hook to streamline the selection of media nodes, introducing a new `resolve` function for better clarity.
- Enhanced the `useGenerationRecords` function to utilize the updated media selection logic, ensuring accurate source declarations.
- Added a new `sourceWidth` function in the `AssetThumbnail` component to optimize thumbnail sizing based on asset dimensions and display settings.
- Adjusted the `PartialAssetItem` component to improve icon sizing for better visual consistency.
2026-09-12 23:23:01 +02:00
konstantin-paulus
65d80a5b17 Enhance file writing and logging functionality in desktop and web applications
- Updated the file writing logic in `main.ts` to ensure that generated asset folders are properly marked to prevent unwanted reloads during writes.
- Introduced detailed logging for model call procedures in `trpc.ts`, capturing input arguments and execution time for better debugging and monitoring.
- Simplified logging in `gen-ai.ts` by removing unnecessary details from generation logs.
- Enhanced asset management in `library.ts` by adding functionality to handle partial assets and ensuring unique paths for stored assets.
2026-09-12 22:52:20 +02:00
konstantin-paulus
4acfb3e447 Add keyboard shortcuts for seeking playhead to selection and timeline edges 2026-09-12 22:12:20 +02:00
konstantin-paulus
1bbe992345 Refactor and enhance transform functionality in the asset management system
- Replaced the `useModifiers` hook with `useTransforms` to better reflect the new transform functionality.
- Updated components to utilize the new `useTransforms` hook, including `ActionBar` and `PromptInputActions`, improving the handling of transformations.
- Introduced new `TransformItem` component for managing transform actions in the UI.
- Refactored asset handling logic to accommodate the new transform types and ensure compatibility with existing features.
- Removed deprecated modifier-related code and documentation, streamlining the codebase and enhancing clarity.
- Updated documentation to reflect changes in transform functionality and usage examples.
2026-09-12 16:31:36 +02:00
konstantin-paulus
28ad0372db Enhance asset management and introduce partial asset handling
- Updated the `Assets` component to include support for partial assets, allowing for better management of assets that are still generating.
- Introduced a new `PartialAssetItem` component to represent partial documents in the asset panel, providing options to retry or delete failed generations.
- Modified the `AssetInfoPanel` to display information about partial assets, including their status and error messages.
- Refactored the `useAssetSelection` hook to accommodate both assets and partial assets, improving the selection logic.
- Updated the `FolderItem` component to count partial assets alongside regular assets, enhancing folder statistics.
- Removed the `sourceErrorSystem` as part of the cleanup, streamlining error handling for asset generations.
- Added documentation updates to reflect changes in asset handling and the introduction of partial assets.
2026-09-12 15:52:41 +02:00
konstantin-paulus
d97d63baec Remove ldrs dependency and introduce activity styles for agent chat
- Removed the `ldrs` package from `package.json` and `package-lock.json` to streamline dependencies.
- Added a new `activity.css` file to enhance the visual representation of agent chat activities.
- Updated components to utilize the new activity styles, improving the user experience during chat interactions.
- Refactored the `RunningIndicator` and `Transcript` components to align with the new styling and functionality.
2026-09-12 15:05:22 +02:00
konstantin-paulus
a0ccde9e59 Add ldrs dependency and enhance Transcript component
- Added the `ldrs` package to `package.json` and `package-lock.json` for improved functionality.
- Updated the `Transcript` component to include a `waiting` prop, allowing for better handling of chat states.
- Integrated a `RunningIndicator` to visually represent ongoing chat processes when not waiting for user input.
2026-09-12 11:55:25 +02:00
konstantin-paulus
277d44e636 Add MCP server command and enhance dashboard integration
- Introduced a new CLI command to serve the MCP server over stdio for agents unable to connect via URL.
- Updated the dashboard to include a dedicated MCP section, allowing users to manage agent connections and view MCP status.
- Enhanced the sidebar navigation to include a link to the MCP settings, improving user accessibility.
- Added new types and handlers for MCP-related requests in the main application logic.
- Updated the dashboard components to support displaying MCP-related information and actions.
2026-09-12 10:59:38 +02:00
konstantin-paulus
7a95fada7a Refactor MCP integration and update dependencies
- Removed the `@modelcontextprotocol/sdk` dependency from `package-lock.json` and `package.json`.
- Updated the CLI client to connect via Streamable HTTP instead of a socket, enhancing communication with the MCP server.
- Simplified the `ping` and `call` functions in `cli-client.ts` to utilize the new connection method.
- Removed the `mcp-proxy.ts` file as it is no longer needed with the new HTTP integration.
- Updated documentation to reflect changes in MCP server access and removed references to the socket transport.
- Cleaned up unused imports and refactored related code for improved clarity and maintainability.
2026-09-12 09:18:46 +02:00
konstantin-paulus
c893dd6537 Enhance tool item functionality to support image display
- Updated the `ToolItem` component to include support for displaying images associated with tool results.
- Modified the `expandable` logic to account for images in addition to existing detail and output properties.
- Introduced a new `collectResult` function to process tool result parts, allowing for the inclusion of images while managing output text.
- Added tests for the `collectResult` function to ensure proper handling of text and image parts, including limits on the number of images and text truncation.
2026-09-12 00:41:57 +02:00
konstantin-paulus
ae07aa4bc9 Add keyboard shortcut indication for prompt input in DashboardHomeView
- Introduced a visual cue for the "Tab" key using the Kbd component to enhance user experience.
- Implemented logic to set the prompt when the "Tab" key is pressed and the input field is empty.
- Updated aria attributes to improve accessibility and provide context for keyboard shortcuts.
2026-09-11 23:54:55 +02:00
konstantin-paulus
093aa671ac Enhance media_transcribe tool and logging functionality
- Updated the `media_transcribe` command to write transcripts to a JSON file, including an output option for specifying the file path.
- Implemented a new `presentTranscript` function to handle the writing of transcripts and return relevant metadata.
- Added filtering options for the `logs` command, including `since` and `contains`, to improve log retrieval capabilities.
- Introduced tests for the new logging features and updated documentation to reflect changes in the `media_transcribe` tool and logging options.
2026-09-11 23:20:46 +02:00
konstantin-paulus
7372c40429 Update documentation references and refactor knowledge handling
- Changed references from `knowledge` to `docs` in README and various files to reflect the new documentation structure.
- Updated `.gitignore` to exclude the `docs` directory instead of `knowledge`.
- Refactored `forge.config.ts` and `main.ts` to utilize the new `docs` directory for staging resources.
- Introduced `stage-docs.mjs` script to manage the staging of documentation files.
- Added new documentation files under `docs/`, including `INSTRUCTIONS.md`, brand guidelines, and design specifications.
- Removed outdated `knowledge` related tests and files to streamline the codebase.
2026-09-11 20:33:57 +02:00
konstantin-paulus
716d25c5a4 Refactor HistoryMenu component for improved chat status display
- Updated icon sizes for better visibility in the HistoryMenu.
- Added conditional rendering for chat status messages based on the selected chat.
- Replaced RemoveButton with a button element for enhanced accessibility and interaction.
- Streamlined the layout and styling of chat items in the dropdown menu.
2026-09-11 18:42:36 +02:00
konstantin-paulus
db2a3bd1f3 Implement agent chat functionality in desktop and web applications
- Added `agent-chat.ts` to manage the agent chat host process, including spawning and communication with the host.
- Updated `main.ts` and `main-channels.ts` to integrate agent chat endpoint handling and lifecycle management.
- Introduced new components for the agent chat interface, including `ChatPanel`, `Composer`, and `HeaderActions`, enhancing user interaction.
- Implemented file attachment handling in the chat with `attachments.tsx` and related functionality.
- Updated package dependencies to include `@diffusionstudio/agent-chat` and related libraries for improved chat capabilities.
- Refactored project deletion logic to ensure associated chats are properly managed.
2026-09-11 18:31:56 +02:00
konstantin-paulus
b13dec966a Add agent chat design specification document 2026-09-11 14:25:10 +02:00
konstantin-paulus
90cf84aa9b Add new agent icons and refactor agent handling in DashboardHomeView 2026-09-11 14:19:57 +02:00
konstantin-paulus
f0e66b3dd6 Remove headless mode functionality and related components
- Deleted references to headless mode in `main-channels.ts`, `main.ts`, and `auth.tsx`, streamlining the codebase by eliminating unused features.
- Removed the `HeadlessIndicator` component from the web application, enhancing clarity and maintainability.
- Updated the login page to reflect the removal of headless mode, simplifying the authentication flow.
2026-09-11 11:23:45 +02:00
konstantin-paulus
1532bf0e34 Refactor and remove unused CLI and MCP setup functionality
- Deleted `cli-install.ts`, `mcp-install.ts`, `mcp-config.ts`, and their associated tests to streamline the codebase and eliminate unused components.
- Removed references to CLI installation and MCP registration in `setup.ts`, `menu.ts`, and other related files, enhancing clarity and maintainability.
- Updated `stage-cli.mjs` to reflect changes in CLI handling, simplifying the staging process for the dapi CLI.
- Refactored `main.ts` to remove setup-related logic, focusing on essential application functionality.
- Enhanced skills cleanup logic to ensure legacy skills are properly managed without the removed components.
2026-09-11 11:11:05 +02:00
konstantin-paulus
2e4c673989 Refactor DashboardSidebarSection for improved clarity
- Removed the title prop from `DashboardSidebarSection` in the `DashboardPage` component to simplify its usage.
- Enhanced the conditional rendering logic for the sidebar, maintaining a clean and user-friendly interface.
2026-09-11 10:21:41 +02:00
konstantin-paulus
8fbec32a57 Add arrow-left icon and refactor DashboardSidebar components
- Introduced a new `arrow-left.svg` icon for navigation purposes.
- Added `DashboardSidebarTopSpacer` component to manage spacing in the sidebar.
- Refactored `DashboardSidebarNav` and `DashboardSidebarSection` components for improved structure and clarity.
- Enhanced `DashboardPage` to conditionally render sidebar elements based on navigation state, improving user experience.
2026-09-11 00:09:47 +02:00
konstantin-paulus
50c8375a64 Remove agent detection and related functionality
- Deleted `agent-detect.ts`, `agent-links.ts`, and their associated tests to streamline the codebase and eliminate unused components.
- Removed references to agent handling in `main.ts` and `main-channels.ts`, enhancing clarity and maintainability.
- Updated `DashboardHomeView` to utilize a fixed list of agents, simplifying the agent selection process and improving user experience.
2026-09-10 23:35:26 +02:00
konstantin-paulus
6eedc18141 Refactor DashboardHomeView component to simplify agent handling
- Removed unused agent setup logic and related imports, streamlining the component's functionality.
- Updated the submission logic to eliminate unnecessary agent checks, enhancing clarity and performance.
- Adjusted error messages for improved user feedback when opening projects, ensuring a better user experience.
2026-09-10 23:19:55 +02:00
konstantin-paulus
2ca853ff70 Remove McpSetupBanner component and related functionality
- Deleted the `McpSetupBanner` component from the canvas, streamlining the UI by removing unnecessary elements.
- Updated `canvas.tsx` to reflect the removal of the `McpSetupBanner`, enhancing code clarity.
- Refactored `agents.ts` to remove unused types and functions related to MCP setup, improving maintainability.
- Enhanced the `DashboardHomeView` component with a new placeholder implementation for better user experience.
2026-09-10 23:11:22 +02:00
konstantin-paulus
2e7b8bf3e9 Refactor dashboard project card implementation and cleanup
- Replaced `DashboardCardButton` with `DashboardProjectCard` in `home-view.tsx` for improved project representation.
- Removed unused imports and refactored event handling for project selection and deletion.
- Cleaned up `projects-view.tsx` by removing deprecated context menu code and unused signals related to project renaming, enhancing code clarity and maintainability.
2026-09-10 15:41:53 +02:00
konstantin-paulus
7ddd530eb2 Implement CLI uninstallation and enhance menu integration
- Added `uninstallCli` function to remove the `dapi` symlink from PATH, handling various outcomes such as removal, absence, cancellation, and errors.
- Introduced `isCliLinked` function to check for the presence of the symlink, improving the detection of CLI installation status.
- Updated `disconnectSetup` to include CLI uninstallation alongside MCP disconnection, ensuring a complete cleanup process.
- Enhanced `disconnectAgentsFromMenu` to provide user feedback on CLI removal status, integrating it with the existing agent disconnection logic.
- Refactored `refreshAppMenu` to reflect the current setup state, ensuring accurate menu visibility based on agent and CLI status.
2026-09-10 15:39:08 +02:00
konstantin-paulus
9d36f71dec Enhance MCP configuration management and menu functionality
- Introduced `removeServer` function in `mcp-config.ts` to facilitate the removal of MCP entries while preserving other configurations.
- Updated `mcp-install.ts` to include `unregisterMcp` function, allowing for the disconnection of agents from the MCP configuration.
- Enhanced `menu.ts` with `disconnectAgentsFromMenu` and `refreshAppMenu` functions to manage agent disconnection and update menu visibility accordingly.
- Refactored `ensureSetup` in `setup.ts` to call `refreshAppMenu`, ensuring the menu reflects the current agent connection status after setup.
- Added tests in `mcp-config.test.ts` to validate the new removal functionality for both JSON and TOML configurations.
2026-09-10 15:35:48 +02:00
konstantin-paulus
ad22093920 Add RemoveButton component for consistent removal functionality
- Introduced a new `RemoveButton` component to standardize the removal action across the application.
- Updated `home-view.tsx` and `prompt-input.tsx` to replace existing button implementations with the new `RemoveButton`, enhancing code reusability and maintainability.
- Adjusted styles and positioning for the new button to ensure consistent UI behavior and appearance.
2026-09-10 14:57:44 +02:00
konstantin-paulus
bdc10b212f Enhance agent link functionality to support file and folder attachments
- Updated `AgentLaunch` type in `agent-links.ts` to include an optional `attachments` property for dropped files and folders.
- Modified `agentLink` function to append attachment paths to the prompt, ensuring they are included in the generated URL.
- Added tests in `agent-links.test.ts` to verify correct formatting of prompts with attachments and handling of empty attachment lists.
- Updated `main-channels.ts` and `main.ts` to accommodate the new `attachments` parameter in agent launch requests.
- Enhanced `home-view.tsx` to manage dropped files and folders, including drag-and-drop functionality for user attachments.
2026-09-10 14:49:46 +02:00
konstantin-paulus
f053820268 Implement setup status and verification enhancements
- Added a new `SETUP_STATUS` channel in `main-channels.ts` to retrieve the current setup status of the application.
- Introduced `setupStatus` and `verifySetup` functions in `setup.ts` to provide detailed information about MCP registration and CLI installation status.
- Updated `main.ts` to handle the new `SETUP_STATUS` channel and improve the setup process.
- Enhanced `agents.ts` with new functions for agent setup status and connection, improving user experience during agent management.
- Integrated `McpSetupBanner` in the canvas component to provide visual feedback on MCP setup status in the UI.
2026-09-10 11:20:38 +02:00
konstantin-paulus
48c6672f51 Enhance project deletion functionality in dashboard components
- Introduced a `DeleteProjectDialog` component to manage project deletion interactions in both `home-view.tsx` and `projects-view.tsx`.
- Refactored the project deletion logic to utilize a signal for pending deletions, improving state management.
- Updated the `clearSelection` function to use a new `createBackgroundClickHandler` for better click handling outside of project cards.
- Removed deprecated alert dialog code related to project deletion, streamlining the user interface.
2026-09-10 10:43:40 +02:00
konstantin-paulus
ac10ecca25 Refactor setup and agent connection logic
- Replaced CLI installation and MCP registration logic with a unified `ensureSetup` function in `main.ts` and `menu.ts` to streamline agent connection.
- Updated `main-channels.ts` to include new types and channels for setup results, enhancing type safety and clarity.
- Refactored `agents.ts` to rename `connectAgents` to `ensureAgentSetup`, aligning with the new setup process.
- Improved the `home-view.tsx` component to utilize the new `ensureAgentSetup` function for better agent management.
- Enhanced user feedback in the menu dialogs to provide clearer information about agent connections and CLI tool status.
2026-09-10 01:03:00 +02:00
konstantin-paulus
ada3dcb3bc Refactor agent detection and linking logic
- Simplified the `markerExists` function in `agent-detect.ts` to streamline path checks.
- Removed unnecessary `requires` property from agent variants in `agent-links.ts`, simplifying agent configuration.
- Updated tests in `agent-links.test.ts` to reflect the removal of VS Code checks and enhance clarity.
- Introduced new SVG icons for agents in the assets directory, improving visual representation in the UI.
- Enhanced the `home-view.tsx` component to utilize the new `agentIcon` function for dynamic icon rendering.
2026-09-09 17:52:55 +02:00
konstantin-paulus
0e3a1e02f8 Add agent detection and linking functionality
- Introduced `agent-detect.ts` to manage agent availability checks and link generation based on installed applications.
- Created `agent-links.ts` to define agent configurations, including their deep links and required markers for detection.
- Implemented tests in `agent-links.test.ts` to validate agent link generation and availability logic.
- Updated `main-channels.ts` to include new channels for listing agents and opening their links.
- Enhanced `main.ts` to handle agent-related requests and integrate with the new agent detection system.
- Added `pickProjectFolder` function to allow users to select project folders directly.
- Refactored dashboard components to utilize the new agent functionality, improving user interaction with coding agents.
- Updated documentation to reflect the new agent features and usage instructions.
2026-09-09 17:37:47 +02:00
konstantin-paulus
7f0e7d9d12 Update README and refactor MCP server configuration
- Revised README.md to clarify the app's MCP server functionality and updated prompt usage instructions, replacing `dapi` references with `diffusion` for consistency.
- Refactored MCP server configuration to use `diffusion` as the server name instead of `dapi`, ensuring alignment with the updated terminology.
- Enhanced tests to reflect changes in server naming and configuration, ensuring accurate validation of the new structure.
- Added new skills and prompts for `editor` and `watch`, improving user guidance and interaction with the app's features.
2026-09-09 14:52:29 +02:00
konstantin-paulus
9fc1926acf Remove onboarding page and related references
- Deleted the OnboardingPage component and its associated logic from the codebase to streamline the authentication flow.
- Updated the AuthGate component to directly render children if the user is authenticated or headless, removing the onboarding check.
- Adjusted the DesktopAppDownloadSource type to exclude onboarding as a download source, reflecting the removal of the onboarding functionality.
2026-09-09 14:17:57 +02:00
konstantin-paulus
b8ec5a39f7 Refactor tool environment references for consistency
- Replaced all instances of `runsIn` with `environment` across the DAPI codebase to standardize terminology.
- Updated related tests and tool definitions to reflect the new property name, ensuring alignment in functionality and documentation.
- Enhanced error handling in the DapiServer class to maintain robustness with the updated property references.
2026-09-09 14:14:11 +02:00
konstantin-paulus
312ce2e1b3 Refactor CLI dependencies and update documentation
- Removed Babel-related dependencies from apps/cli/package.json and package-lock.json to streamline the build process.
- Added esbuild as a devDependency in apps/cli/package.json for improved bundling.
- Updated README.md to provide a more detailed description of the dapi CLI tool, clarifying its role as a client of the MCP server and stdio proxy.
- Deleted untyped-modules.d.ts to eliminate unnecessary type declarations for Babel presets.
- Enhanced comments in stage-cli.mjs to clarify the staging process for the dapi CLI within the Electron app.
2026-09-09 14:04:57 +02:00
konstantin-paulus
28135e68cc Update documentation and refine tool references
- Revised the README.md to clarify the app's MCP server functionality and the CLI tool descriptions, ensuring consistency in terminology.
- Updated various sections to replace `dapi` references with direct tool names, enhancing clarity for users.
- Improved instructions for using the CLI commands, including examples and command syntax, to better guide users in their interactions with the app.
- Enhanced the knowledge base documentation to reflect recent changes in tool functionalities and command structures, ensuring users have access to the latest information.
2026-09-09 14:01:06 +02:00
konstantin-paulus
d5a298f004 Refactor CLI tool descriptions and improve input validation
- Removed fallback parameters from the `field` function in CLI tools to simplify input handling.
- Updated command options for `media_grab`, `media_filmstrip`, and `media_waveform` to remove default descriptions, relying on schema definitions instead.
- Enhanced the `logs` and `fonts` tools to provide clearer descriptions for input fields.
- Improved the `windowFields` schema to include default value descriptions for better user guidance.
- Adjusted the `models` tool to specify model types in the description, enhancing clarity for users.
2026-09-09 11:41:19 +02:00
konstantin-paulus
5c0e109cd5 Refactor CLI tool input handling and update documentation
- Replaced the `time` argument with `times` in the CLI commands for consistency across tools.
- Updated the `capture` and `media_grab` tools to handle multiple timestamps, improving flexibility in frame extraction.
- Refactored input validation to utilize `zod` for better error handling and user feedback.
- Removed the `help.ts` module as its functionality has been integrated into the main CLI structure.
- Updated documentation to reflect changes in command syntax and input handling, ensuring clarity for users.
2026-09-09 11:37:43 +02:00
konstantin-paulus
4d4cdda91e Refactor knowledge base integration and update documentation
- Replaced references to 'docs' and 'skills' with 'knowledge' in various configurations and scripts to streamline the knowledge base integration.
- Removed the `stage-docs.mjs` and `stage-skills.mjs` scripts, replacing them with `stage-knowledge.mjs` to facilitate the staging of the knowledge base.
- Updated `README.md` and other documentation to reflect the new structure and paths for the knowledge base resources.
- Adjusted the DAPI server and related components to serve knowledge resources, ensuring agents can access the latest documentation and instructions.
- Enhanced test cases to validate the new knowledge base structure and resource accessibility.
2026-09-08 23:51:36 +02:00
konstantin-paulus
45d1ca0bc5 Remove example files and README for cleanup
- Deleted all example files demonstrating the JSX API, including various compositions and their respective functionalities.
- Removed the README.md file that provided instructions and descriptions for the examples.
- Cleared the tsconfig.json for examples, ensuring no residual configurations remain.
- This cleanup prepares the repository for a more streamlined focus on core functionalities without the example clutter.
2026-09-08 23:23:31 +02:00
konstantin-paulus
a7039fe8b2 Enhance MCP server integration and add help functionality
- Added `zod` as a dependency in package-lock.json and apps/cli/package.json for input validation.
- Introduced new help.ts module to provide descriptions and validation for CLI commands, ensuring consistency with the app's tool catalog.
- Refactored cli-client.ts to improve timeout handling for tool calls, enhancing error management.
- Created mcp-proxy.ts to facilitate communication between agents and the app's MCP server.
- Updated index.ts to streamline command execution and improve error handling.
- Implemented mcp-config.ts and mcp-install.ts for managing MCP server configurations across different agents.
- Enhanced desktop application to support MCP registration from the menu, improving user experience.
2026-09-08 12:17:03 +02:00
Konstantin Paulus
4a652f589c
Merge pull request #61 from diffusionstudio/jkl-implementation
Jkl implementation
2026-09-06 17:37:10 +02:00
konstantin-paulus
059e1f6e76 Update dependencies and refactor CLI integration
- Added @modelcontextprotocol/sdk as a dependency in package-lock.json and apps/cli/package.json.
- Removed unused @types/ws dependency from package-lock.json and apps/cli/package.json.
- Refactored cli-client.ts to utilize the new SDK for tool interactions, enhancing modularity and performance.
- Updated media handling functions in index.ts to streamline output handling and improve clarity.
- Deleted obsolete protocol.ts and ytdlp.ts files, consolidating functionality within the new SDK.
- Introduced edit-types.ts to define types for source edits, improving type safety and maintainability in the editing process.
- Updated package.json files to include vitest for testing support in both CLI and desktop applications.
2026-09-03 15:53:35 +02:00
konstantin-paulus
905d649141 Refactor CLI and DAPI integration
- Removed @trpc/client and @trpc/server dependencies from package-lock.json and apps/cli/package.json.
- Updated TypeScript configuration in apps/cli/tsconfig.json to simplify compiler options.
- Refactored cli-client.ts to replace TRPC client calls with direct calls to the DAPI, enhancing modularity and performance.
- Adjusted media handling functions in index.ts to utilize the new call method for better clarity and maintainability.
- Cleaned up protocol.ts by introducing encoding and decoding functions for replies, improving data handling consistency.
2026-09-03 10:04:02 +02:00
konstantin-paulus
4d94b87881 Integrate @diffusionstudio/dapi into CLI and desktop applications
- Added @diffusionstudio/dapi as a dependency in package-lock.json, apps/cli/package.json, apps/desktop/package.json, and apps/web/package.json.
- Refactored imports in CLI and desktop source files to utilize types and constants from @diffusionstudio/dapi, enhancing code modularity and maintainability.
- Removed the cli-channels.ts file as its functionality is now encapsulated within the new dapi package.
- Introduced a new MCP server design proposal in docs/mcp-server.md, outlining the transition to a unified API for tool interactions.
2026-09-03 09:40:50 +02:00
1024 changed files with 51176 additions and 14186 deletions

37
.github/workflows/build-windows.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: Build Windows
# An unsigned Windows installer on demand, for testing the Windows build
# before it is part of the release (see apps/desktop/WINDOWS.md). Signing
# and publishing join the Release workflow in a later stage.
on:
workflow_dispatch:
jobs:
make-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- name: Provide client env for web build
shell: bash
run: cp apps/web/.env.example apps/web/.env
- name: Build and make the installer
shell: bash
env:
SKIP_SIGN: "1"
run: npm run make --workspace=@diffusionstudio/desktop
- uses: actions/upload-artifact@v4
with:
name: diffusion-studio-windows-${{ runner.arch }}
path: apps/desktop/out/make/squirrel.windows/**
if-no-files-found: error

View File

@ -19,8 +19,14 @@ jobs:
if [ -z "$TAG" ]; then
TAG=$(curl -sf https://api.github.com/repos/diffusionstudio/editor/releases/latest | jq -r .tag_name)
fi
# Draft releases carry a placeholder tag (untagged-<hash>); never write that into the cask.
if ! echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Refusing to bump cask: '$TAG' is not a vX.Y.Z tag" >&2
exit 1
fi
VERSION="${TAG#v}"
curl -sfL -o app.dmg "https://github.com/diffusionstudio/editor/releases/download/${TAG}/Diffusion-Studio-arm64.dmg"
# The release event can fire before the DMG upload finishes; 404s are retried too.
curl -sfL --retry 10 --retry-delay 30 --retry-all-errors -o app.dmg "https://github.com/diffusionstudio/editor/releases/download/${TAG}/Diffusion-Studio-arm64.dmg"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "sha256=$(shasum -a 256 app.dmg | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"

72
.github/workflows/bump-winget.yml vendored Normal file
View File

@ -0,0 +1,72 @@
name: Bump winget package
# Opens a pull request on microsoft/winget-pkgs for each published release,
# the Windows counterpart of bump-cask.yml. Komac reads the manifest of the
# version already in winget-pkgs, swaps in the new installer URL and its
# checksum, and submits from the token owner's fork of winget-pkgs. The
# package's first version is submitted by hand; this only updates it.
#
# Needs the WINGET_TOKEN secret: a classic personal access token with the
# `public_repo` scope (Komac cannot open the pull request with a
# fine-grained one), whose account has a fork of microsoft/winget-pkgs.
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: Release tag to submit (vX.Y.Z). Empty means the latest release.
required: false
env:
PACKAGE_ID: DiffusionStudio.DiffusionStudio
KOMAC_VERSION: 2.16.0
KOMAC_SHA256: 7d2707fa6210f2789a3702de49fbd150b736dbf426ee0b9bc8e098736f9fd82d
jobs:
bump-winget:
if: ${{ !github.event.release.prerelease }}
runs-on: ubuntu-latest
steps:
- name: Resolve release
id: info
env:
TAG: ${{ github.event.release.tag_name || inputs.tag }}
run: |
if [ -z "$TAG" ]; then
TAG=$(curl -sf https://api.github.com/repos/diffusionstudio/editor/releases/latest | jq -r .tag_name)
fi
# Draft releases carry a placeholder tag (untagged-<hash>); never submit that.
if ! echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Refusing to bump winget: '$TAG' is not a vX.Y.Z tag" >&2
exit 1
fi
URL="https://github.com/diffusionstudio/editor/releases/download/${TAG}/Diffusion-Studio-x64-Setup.exe"
# Komac downloads the installer to hash it; make sure it is there first (retrying like bump-cask.yml).
curl -sfIL --retry 10 --retry-delay 30 --retry-all-errors -o /dev/null "$URL"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
echo "url=$URL" >> "$GITHUB_OUTPUT"
- name: Install Komac
run: |
curl -sfL -o komac.tar.gz "https://github.com/russellbanks/Komac/releases/download/v${KOMAC_VERSION}/komac-${KOMAC_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
echo "${KOMAC_SHA256} komac.tar.gz" | sha256sum -c -
tar -xzf komac.tar.gz komac
./komac --version
- name: Submit to winget-pkgs
env:
GITHUB_TOKEN: ${{ secrets.WINGET_TOKEN }}
VERSION: ${{ steps.info.outputs.version }}
URL: ${{ steps.info.outputs.url }}
TAG: ${{ steps.info.outputs.tag }}
# On a rerun Komac finds the pull request it opened before and, in CI,
# exits without opening another.
run: |
./komac update "$PACKAGE_ID" \
--version "$VERSION" \
--urls "$URL" \
--release-notes-url "https://github.com/diffusionstudio/editor/releases/tag/${TAG}" \
--submit

View File

@ -54,3 +54,106 @@ jobs:
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: npm run publish --workspace=@diffusionstudio/desktop
# Signed with Azure Artifact Signing; apps/desktop/WINDOWS.md (stage 5) has
# the account setup and the secrets and variables this job expects. Runs
# after the macOS job so both append their assets to the one draft release
# instead of racing to create it. Squirrel's RELEASES file and the nupkg
# land next to the setup exe; the updater needs all three.
publish-windows:
needs: publish-macos
runs-on: windows-latest
# The environment name is the subject of the OIDC token that Azure's
# federated credential for this repository is bound to.
environment: release
permissions:
contents: write
id-token: write # OIDC sign-in to Azure, no client secret
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Check versions match tag
shell: bash
run: |
TAG="${GITHUB_REF_NAME#v}"
for PKG in package.json apps/desktop/package.json apps/cli/package.json apps/web/package.json; do
V="$(node -p "require('./$PKG').version")"
if [ "$V" != "$TAG" ]; then
echo "Version mismatch in $PKG: $V, tag is $TAG"
exit 1
fi
done
- run: npm ci
- name: Provide client env for web build
shell: bash
run: cp apps/web/.env.example apps/web/.env
- name: Sign in to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# signtool.exe from the newest Windows SDK on the runner (the dlib needs
# 10.0.2261.755 or later), the Artifact Signing dlib from NuGet, and a
# metadata file naming the account. forge.config.ts reads the three
# paths from the environment. Authentication goes through the Azure CLI
# session from the step above; every other credential source is
# excluded so a misconfiguration fails fast instead of timing out.
- name: Set up Artifact Signing
shell: pwsh
env:
ENDPOINT: ${{ vars.ARTIFACT_SIGNING_ENDPOINT }}
ACCOUNT: ${{ vars.ARTIFACT_SIGNING_ACCOUNT }}
PROFILE: ${{ vars.ARTIFACT_SIGNING_PROFILE }}
run: |
$ErrorActionPreference = "Stop"
foreach ($name in "ENDPOINT", "ACCOUNT", "PROFILE") {
if (-not (Get-Item "env:$name").Value) { throw "Repository variable ARTIFACT_SIGNING_$name is not set" }
}
$signtool = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin\10.0.*\x64\signtool.exe" |
Sort-Object { [version]$_.Directory.Parent.Name } | Select-Object -Last 1
if (-not $signtool) { throw "signtool.exe not found in the Windows SDK" }
$dir = Join-Path $env:RUNNER_TEMP "artifact-signing"
nuget install Microsoft.ArtifactSigning.Client -ExcludeVersion -OutputDirectory $dir
$dlib = Join-Path $dir "Microsoft.ArtifactSigning.Client\bin\x64\Azure.CodeSigning.Dlib.dll"
if (-not (Test-Path $dlib)) { throw "Artifact Signing dlib not found at $dlib" }
$metadata = Join-Path $dir "metadata.json"
@{
Endpoint = $env:ENDPOINT
CodeSigningAccountName = $env:ACCOUNT
CertificateProfileName = $env:PROFILE
CorrelationId = "$env:GITHUB_REPOSITORY $env:GITHUB_REF_NAME"
ExcludeCredentials = @(
"EnvironmentCredential",
"WorkloadIdentityCredential",
"ManagedIdentityCredential",
"SharedTokenCacheCredential",
"VisualStudioCredential",
"VisualStudioCodeCredential",
"AzurePowerShellCredential",
"AzureDeveloperCliCredential",
"InteractiveBrowserCredential"
)
} | ConvertTo-Json | Set-Content -Path $metadata -Encoding utf8
"WINDOWS_SIGNTOOL_PATH=$($signtool.FullName)" >> $env:GITHUB_ENV
"WINDOWS_SIGN_DLIB=$dlib" >> $env:GITHUB_ENV
"WINDOWS_SIGN_METADATA=$metadata" >> $env:GITHUB_ENV
- name: Build, sign, and publish draft release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run publish --workspace=@diffusionstudio/desktop

3
.gitignore vendored
View File

@ -39,4 +39,5 @@ out/
# AI
skills-lock.json
.agents
.claude
.claude
.gstack/

106
README.md
View File

@ -4,10 +4,10 @@
</a>
</p>
<p align="center">The professional video editor built for agents</p>
<p align="center">Turn your agent into a professional video editor</p>
<p align="center">
<a href="https://www.diffusion.studio/download"><img src="https://img.shields.io/badge/Download-macOS%20Apple%20Silicon-161616?style=flat&logo=apple&logoColor=F8F8F8&labelColor=000000" alt="Download for macOS (Apple Silicon)" /></a>
<a href="https://www.diffusion.studio/download"><img src="https://img.shields.io/badge/Download-macOS%20%7C%20Windows-161616?style=flat&labelColor=000000" alt="Download for macOS or Windows" /></a>
<a href="https://discord.com/invite/zPQJrNGuFB"><img src="https://img.shields.io/discord/1115673443141156924?style=flat&logo=discord&logoColor=F8F8F8&label=Discord&labelColor=000000&color=161616" alt="Discord" /></a>
<a href="https://x.com/diffusionhq"><img src="https://img.shields.io/badge/Follow%20for-Updates-161616?style=flat&logo=x&logoColor=F8F8F8&labelColor=000000" alt="Follow on X" /></a>
<a href="https://www.ycombinator.com/companies/diffusion-studio"><img src="https://img.shields.io/badge/Combinator-F24-161616?style=flat&logo=ycombinator&logoColor=F8F8F8&labelColor=000000" alt="Y Combinator F24" /></a>
@ -49,25 +49,16 @@ The agent handles everything from there:
Beyond finishing a cut, it covers:
- **Motion graphics**: explainers, promos, and title sequences
- **Generative assets**: images, video, and voiceover, declared in code and composited into the timeline
- **Clipping**: highlights from a long video, reformatted for social
- **Video understanding**: summaries, scene search, quotes with timestamps
## How it works
Diffusion Studio uses [SolidJS](https://www.solidjs.com) modules as the document source. Think IDE, but it renders a video canvas instead of text.
Editing works both ways: change something on the canvas and the code updates; change the code and the canvas redraws.
The desktop app includes command-line tools that let agents watch and listen to footage, edit it on a timeline, and render the result.
## Getting started
Download the desktop app, it walks you through setting everything up:
Download the desktop app for macOS (Apple Silicon) or Windows (x64), it walks you through setting everything up:
<a href="https://www.diffusion.studio/download"><img src="https://img.shields.io/badge/Download-Diffusion%20Studio-161616?style=for-the-badge&logo=apple&logoColor=F8F8F8&labelColor=000000" alt="Download Diffusion Studio" /></a>
<a href="https://www.diffusion.studio/download"><img src="https://img.shields.io/badge/Download-Diffusion%20Studio-161616?style=for-the-badge&labelColor=000000" alt="Download Diffusion Studio" /></a>
Use with Claude Code, Codex, Cursor, Copilot, or Gemini CLI. `/editor` is the main skill you'll use. Ask for what you want in plain language. Behind it is `dapi`, the CLI that drives the app.
Use with Claude Code, Codex, Cursor, Copilot, or Gemini CLI. The app registers its MCP server with your agent, so just ask for what you want in plain language.
## Prompt examples
@ -75,11 +66,11 @@ Use with Claude Code, Codex, Cursor, Copilot, or Gemini CLI. `/editor` is the ma
<summary><b>Motion graphics</b></summary>
```text
/editor Create a ~20-second promo for vercel-labs/native in Vercel's presentation style. Research its official website, GitHub, and brand guidelines; use authentic assets and verified product features, with crisp typography, polished motion, and a strong final CTA.
Create a polished, 20-second SaaS product promo video for https://typesafe.ai/. Use the website’s branding and highlight the product’s main benefit with animated UI mockups, concise on-screen text, and smooth transitions. End with a clear call to action.
```
```text
/editor Recreate the 3blue1brown animation from https://youtu.be/HEfHFsfGXjs, closely matching its visual style, pacing, framing, colors, labels, and transitions. Use the exact collision mathematics from Gregory Galperin's original paper, do not approximate the physics.
Recreate the 3blue1brown animation from https://youtu.be/HEfHFsfGXjs, closely matching its visual style, pacing, framing, colors, labels, and transitions. Use the exact collision mathematics from Gregory Galperin's original paper, do not approximate the physics.
```
</details>
@ -88,11 +79,11 @@ Use with Claude Code, Codex, Cursor, Copilot, or Gemini CLI. `/editor` is the ma
<summary><b>Video editing</b></summary>
```text
/editor edit the footage in /path/to/folder
Edit the footage in /path/to/folder
```
```text
/editor turn this footage into a polished YouTube video. Add readable captions and an attention-grabbing graphic in the opening to give viewers a strong visual hook.
Turn this footage into a polished YouTube video. Add readable captions and an attention-grabbing graphic in the opening to give viewers a strong visual hook.
```
</details>
@ -101,11 +92,11 @@ Use with Claude Code, Codex, Cursor, Copilot, or Gemini CLI. `/editor` is the ma
<summary><b>Clipping</b></summary>
```text
/editor Can you pull the best 30-second moment from https://youtu.be/MtQ0qxyf-Ds and make a vertical version for social?
Can you pull the best 30-second moment from https://youtu.be/MtQ0qxyf-Ds and make a vertical version for social?
```
```text
/editor Make a 15-second version of this launch video. https://x.com/claudeai/status/2045156267690213649
Make a 15-second version of this launch video. https://x.com/claudeai/status/2045156267690213649
```
</details>
@ -114,11 +105,11 @@ Use with Claude Code, Codex, Cursor, Copilot, or Gemini CLI. `/editor` is the ma
<summary><b>Video understanding and reasoning</b></summary>
```text
/watch In three bullets, explain what starts the conflict. Include timestamps. https://youtu.be/aqz-KE-bpKQ
In three bullets, explain what starts the conflict. Include timestamps. https://youtu.be/aqz-KE-bpKQ
```
```text
/watch Name three recurring locations and give one visual cue that distinguishes each. https://youtu.be/dQw4w9WgXcQ
Name three recurring locations and give one visual cue that distinguishes each. https://youtu.be/dQw4w9WgXcQ
```
</details>
@ -131,9 +122,17 @@ Both were created by prompting. The compositions are published in [diffusionstud
| --- | --- |
| <img src="assets/launch-video.gif" alt="Launch video" width="420" /> | <img src="assets/raise-announcement.gif" alt="Raise announcement" width="420" /> |
## How it works
Diffusion Studio uses [SolidJS](https://www.solidjs.com) modules as the document source. Think IDE, but it renders a video canvas instead of text.
Editing works both ways: change something on the canvas and the code updates; change the code and the canvas redraws.
The desktop app includes command-line tools that let agents watch and listen to footage, edit it on a timeline, and render the result.
## Compositions as code
A project is a folder of that JSX: `dapi open <dir>` once, then edit the files. Saving recompiles the entry file and mounts it directly into the editor's ECS.
A project is a folder of that JSX: `open` a folder once (`diffusion open <dir>` from a shell), then edit the files. Saving recompiles the entry file and mounts it directly into the editor's ECS.
Every element carries an `id`, which is how the write-back finds its target: a rect dragged on the canvas, a clip trimmed on the timeline, or a retyped line lands as a prop on the element that authored it.
@ -141,10 +140,6 @@ The root is a `<stage>` holding one `<scene>` per frame you cut in:
```tsx
import { For } from "solid-js";
import { generate } from "@diffusionstudio/jsx";
const hero = generate.image({ prompt: "A neon city at night, cinematic", aspectRatio: "16:9" });
const motion = generate.video({ prompt: "slow camera push-in", startFrame: hero, duration: 5 });
const TITLES = [
{ text: "The Grid", start: 0, end: 2.5 },
@ -155,7 +150,7 @@ export default function Project() {
return (
<stage camera={[0.3, 0, 0, 0.3, 85, 150]}>
<scene name="Intro" width={1920} height={1080} fill="black" active>
<video src={motion} start={0} end={5} width={1920} height={1080} />
<video src="footage/city.mp4" start={0} end={5} width={1920} height={1080} />
<For each={TITLES}>
{(t) => (
<text
@ -182,38 +177,38 @@ Everything a mount produces stays a first-class editor node, so a person can pic
## Seeing and hearing the media
Cutting footage requires understanding it. The CLI ships the inspection tools an agent needs to work with media it cannot watch:
Cutting footage requires understanding it. The app exposes the inspection tools an agent needs to work with media it cannot watch — as MCP tools, and as the same commands in a shell:
```sh
dapi media probe clip.mp4 # container + codec metadata, like ffprobe
dapi media grab clip.mp4 -t 0 12 45 # decode frames to PNGs
dapi media filmstrip clip.mp4 # grid of video frames
dapi media waveform track.mp3 # audio waveform, silence flagged
dapi media transcribe interview.wav # timed, word-level transcript
dapi media listen interview.mp4 -p "what is said in the intro?" # ask a multimodal model
dapi capture intro -t 0 2 4 # the frames a render would produce, by scene id
diffusion probe clip.mp4 # container + codec metadata, like ffprobe
diffusion grab clip.mp4 -t 0 12 45 # decode frames to PNGs
diffusion filmstrip clip.mp4 # grid of video frames
diffusion waveform track.mp3 # audio waveform, silence flagged
diffusion transcribe interview.wav # timed, word-level transcript
diffusion listen interview.mp4 -p "what is said in the intro?" # ask a multimodal model
diffusion capture intro -t 0 2 4 # the frames a render would produce, by scene id
```
Each command is the MCP tool of the same name: `diffusion grab` is `grab`, `--per-sheet` is `perSheet`.
| Command | Purpose |
| --- | --- |
| `dapi open` | Launch the app and open (or create) a project folder, anywhere on disk |
| `dapi context` | Summary of app state |
| `dapi capture` | Render frames of a scene, as an export would, to a labelled contact sheet or one PNG per position |
| `dapi check` | Check a node's subtree for structural mistakes (black-frame gaps, never-visible nodes, failed sources) and report subtree stats |
| `dapi media …` | Inspect a file by id or path: `probe`, `grab`, `filmstrip`, `waveform`, `transcribe`, `listen` |
| `dapi models` / `dapi voices` / `dapi fonts` | Discover generation models, speech voices, local fonts |
| `dapi screenshot` / `dapi logs` | The app itself: capture the window, read recent console output |
| `dapi fetch` | Download a video from yt/tt/ig |
| `dapi whoami` | The authenticated account |
| `dapi report` | Report a bug in the CLI or the app: diagnostics bundled, filed as a GitHub issue via `gh` |
| `diffusion open` | Launch the app and open (or create) a project folder, anywhere on disk |
| `diffusion context` | Summary of app state |
| `diffusion capture` | Render frames of a scene, as an export would, to a labelled contact sheet or one PNG per position |
| `diffusion check` | Check a node's subtree for structural mistakes (black-frame gaps, never-visible nodes, failed sources) and report subtree stats |
| `diffusion probe` / `grab` / `filmstrip` / `waveform` / `transcribe` / `listen` | Inspect a file by id or path |
| `diffusion fonts` | Discover Google Fonts and local font families |
| `diffusion screenshot` / `diffusion logs` | The app itself: capture the window, read recent console output |
| `diffusion report` | Report a bug in the tools or the app: diagnostics bundled, filed as a GitHub issue via `gh` |
Conventions throughout: single results are one JSON value, collections are JSON Lines, errors go to stderr with exit code `1`. Everything is built to be piped, grepped, and driven by a program.
Conventions throughout: every result is one JSON object, the same structured content the MCP tool returns; errors go to stderr with exit code `1`. Everything is built to be piped, grepped, and driven by a program.
## Documentation
- [CLI reference](reference/README.md): every command, its options, and its output
- [JSX reference](reference/jsx/README.md): the composition markup with elements, timing, paints, generative assets, and captions
- [Examples](examples/README.md): runnable compositions, from basic scenes and generative assets to three.js and raw WebGPU
- [Tool reference](docs/reference/tools/README.md): every tool and CLI command, its options, and its output
- [JSX reference](docs/reference/jsx/README.md): the composition markup with elements, timing, paints, and captions
- [Examples](docs/examples/README.md): runnable compositions, from basic scenes to three.js and raw WebGPU
## Repository layout
@ -221,10 +216,10 @@ Conventions throughout: single results are one JSON value, collections are JSON
| --- | --- | --- |
| `apps/web` | `@diffusionstudio/web` | The editor UI (Solid + Vite) |
| `apps/desktop` | `@diffusionstudio/desktop` | Electron shell hosting the editor |
| `apps/cli` | `@diffusionstudio/cli` | The `dapi` CLI |
| `apps/cli` | `@diffusionstudio/cli` | The `diffusion` CLI (`dapi` alias): a client of the app's MCP server |
| `packages/runtime` | `@diffusionstudio/runtime` | Headless editor runtime: the koota world, traits, actions, systems, media decoding, capture. No DOM, no Solid |
| `packages/reconciler` | `@diffusionstudio/reconciler` | Evaluates a compiled project bundle and reconciles its element tree onto runtime entities, via Solid's universal renderer |
| `packages/jsx` | `@diffusionstudio/jsx` | The authoring API: element vocabulary, types, and generated assets (`generate.*`) |
| `packages/jsx` | `@diffusionstudio/jsx` | The authoring API: element vocabulary and types |
| `packages/assets` | `@diffusionstudio/assets` | A project's asset library: the `assets.yml` manifest, content hashing, probing, resolution |
| `packages/encoder` | `@diffusionstudio/encoder` | Offline video/audio/image encoding over runtime worlds (mediabunny) |
| `packages/koota-solid` | `@diffusionstudio/koota-solid` | Solid bindings for koota, ported from `@koota/react` |
@ -243,19 +238,18 @@ cp apps/web/.env.example apps/web/.env # required: the app won't run without i
npm run dev
```
To put `dapi` on your PATH (macOS/Homebrew layout; adjust the link target for other setups), link it once:
To put `diffusion` (and its `dapi` alias) on your PATH, link it once (`unlink` undoes it):
```sh
npm run symlink:create --workspace=@diffusionstudio/cli
npm run link --workspace=@diffusionstudio/cli
```
The link points at the CLI build, which `npm run dev:desktop` refreshes on every start, so the linked `dapi` always runs the latest code.
Before sending a PR:
```sh
npm run check # typecheck all workspaces
npm run lint # lint all workspaces
npm run test # ensure tests are green
```
## License

View File

@ -1,35 +1,27 @@
{
"name": "@diffusionstudio/cli",
"private": true,
"version": "0.204.2",
"version": "0.216.0",
"license": "MPL-2.0",
"bin": {
"diffusion": "./dist/index.js",
"dapi": "./dist/index.js"
},
"exports": {
"./protocol": "./src/protocol.ts",
"./channels": "./src/cli-channels.ts"
},
"scripts": {
"build": "esbuild src/index.ts --bundle --platform=node --format=cjs --external:esbuild --external:@babel/core --external:@babel/preset-typescript --external:babel-preset-solid --external:bufferutil --external:utf-8-validate --outfile=dist/index.js && chmod +x dist/index.js",
"build": "esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.js && node -e \"process.platform !== 'win32' && require('node:fs').chmodSync('dist/index.js', 0o755)\"",
"check": "tsc --noEmit",
"symlink:remove": "rm -f /opt/homebrew/bin/dapi",
"symlink:create": "npm run build && ln -sf \"$PWD/dist/index.js\" /opt/homebrew/bin/dapi"
"link": "npm run build && node scripts/dev-link.mjs",
"unlink": "node scripts/dev-link.mjs --remove"
},
"dependencies": {
"@babel/core": "^7.29.7",
"@trpc/client": "^11.18.0",
"@trpc/server": "^11.18.0",
"@babel/preset-typescript": "^7.27.1",
"babel-preset-solid": "^1.9.12",
"@diffusionstudio/dapi": "*",
"@modelcontextprotocol/sdk": "^1.30.0",
"commander": "^14.0.3",
"esbuild": "^0.28.1",
"ws": "^8.18.3"
"zod": "^4.4.3"
},
"devDependencies": {
"@types/babel__core": "^7.20.5",
"@types/node": "^24.10.1",
"@types/ws": "^8.18.1",
"esbuild": "^0.28.1",
"typescript": "~5.9.3"
}
}

View File

@ -0,0 +1,119 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Puts `diffusion` (and a `dapi` alias) on the PATH, running this workspace's
// build, for developing against the CLI. `npm run dev:desktop` rebuilds the
// CLI on every start, so the link keeps running the latest code. `dapi` is
// where a dev build of the desktop app looks for the binary it registers
// with agents and reports in the settings CLI card (apps/desktop/src/cli-install.ts
// and mcp-install.ts), so that name and path are load-bearing; `diffusion` is
// added alongside it purely for typing at a shell.
//
// macOS symlinks in Homebrew's bin, `/opt/homebrew/bin/{dapi,diffusion}`,
// which is user-writable, so no admin prompt. The packaged app uses
// `/usr/local/bin` instead and the two never collide.
// Windows `%LOCALAPPDATA%\DiffusionStudio\bin\{dapi,diffusion}.cmd`, the same
// file the packaged app keeps its own shim in (apps/desktop/src/cli-windows.ts).
// A packaged app rewrites the `dapi` one on launch, so run this again
// after using one. The folder is added to the user PATH the way the
// packaged app's "Install CLI" does it; `--remove` leaves that
// entry, since a packaged install may still use it.
//
// node scripts/dev-link.mjs create the link
// node scripts/dev-link.mjs --remove delete it
import { execFileSync } from "node:child_process";
import { existsSync, mkdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join, win32 } from "node:path";
import { fileURLToPath } from "node:url";
const script = join(dirname(fileURLToPath(import.meta.url)), "..", "dist", "index.js");
const remove = process.argv.includes("--remove");
const NAMES = ["dapi", "diffusion"];
if (process.platform === "win32") {
const local = process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local");
const dir = join(local, "DiffusionStudio", "bin");
const shims = NAMES.map((name) => join(dir, `${name}.cmd`));
if (remove) {
for (const shim of shims) {
rmSync(shim, { force: true });
console.log(`dev-link: removed ${shim}`);
}
process.exit(0);
}
const batch = (path) => path.replaceAll("%", "%%");
mkdirSync(dir, { recursive: true });
for (const shim of shims) {
writeFileSync(shim, ["@echo off", "setlocal", `node "${batch(script)}" %*`, ""].join("\r\n"));
console.log(`dev-link: ${shim} -> ${script}`);
}
if (addToUserPath(dir)) {
console.log(`dev-link: added ${dir} to your PATH; open a new terminal to run \`diffusion\`.`);
}
} else if (process.platform === "darwin") {
const dir = "/opt/homebrew/bin";
const links = NAMES.map((name) => join(dir, name));
if (remove) {
for (const link of links) {
rmSync(link, { force: true });
console.log(`dev-link: removed ${link}`);
}
process.exit(0);
}
if (!existsSync(dir)) {
console.error(`dev-link: ${dir} does not exist (Homebrew is not installed, or is an Intel install); ` +
`the dev build of the app only recognises a link there.`);
process.exit(1);
}
for (const link of links) {
rmSync(link, { force: true });
symlinkSync(script, link);
console.log(`dev-link: ${link} -> ${script}`);
}
} else {
console.error(`dev-link: no link location for ${process.platform}; put ${script} on your PATH yourself.`);
process.exit(1);
}
// The user PATH in HKCU\Environment, edited the same way as
// apps/desktop/src/cli-windows.ts: through the registry, so the %VARIABLE%
// entries already there stay unexpanded, with a throwaway variable deletion
// to make .NET broadcast the change to new terminals. Returns whether the
// entry was added.
function addToUserPath(dir) {
const normalize = (entry) => win32.normalize(entry).replace(/[\\/]+$/, "").toLowerCase();
const powershell = (script, env) =>
execFileSync(
"powershell.exe",
["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script],
{ env: { ...process.env, ...env }, windowsHide: true, encoding: "utf8" },
);
const current = powershell(`
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment')
[Console]::Out.Write($key.GetValue('Path', '', 'DoNotExpandEnvironmentNames'))
`);
const entries = current.split(";").filter((entry) => entry.trim() !== "");
if (entries.some((entry) => normalize(entry) === normalize(dir))) return false;
powershell(
`
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true)
$kind = if ($key.GetValueNames() -contains 'Path') { $key.GetValueKind('Path') } else { 'ExpandString' }
$key.SetValue('Path', $env:DAPI_USER_PATH, $kind)
[Environment]::SetEnvironmentVariable('DAPI_PATH_BROADCAST', $null, 'User')
`,
{ DAPI_USER_PATH: [...entries, dir].join(";") },
);
return true;
}

View File

@ -1,194 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Wire-level channel for the CLI handshake. Each CLI command hosts a
// short-lived WebSocket server; main's only job is to relay the connect
// info to the renderer, which then dials the CLI directly. Main never sees
// request payloads.
export const CLI_WIRE = {
CONNECT: "cli:connect",
} as const;
// Sent by the CLI to main over the unix socket, relayed verbatim to the
// renderer. The token guards the loopback WebSocket server against other
// local processes racing to connect first.
export type CliHandshake = { port: number; token: string };
export type CliHandshakeReply = { ok: true } | { ok: false; error: string };
// One tRPC request/reply pair per WebSocket connection. `path` is the
// dot-joined procedure path in the renderer's router (e.g. "media.frame");
// procedure inputs and outputs are typed end-to-end via the AppRouter type,
// so the wire envelope stays untyped.
export type CliRequest = {
path: string;
input: unknown;
};
export type CliReply =
| { ok: true; data: unknown }
| { ok: false; error: string };
export type AssetRef = { path: string };
export type MediaProbeRequest = AssetRef;
export type FrameQuality = "small" | "medium" | "large" | "fullres";
export type MediaFrameRequest = AssetRef & {
times?: number[];
count?: number;
start?: number;
end?: number;
quality?: FrameQuality;
auto?: boolean;
combine?: boolean;
perSheet?: number;
};
/** Beyond this the cells get too small to be worth the tokens; use `filmstrip`. */
export const MAX_FRAMES_PER_SHEET = 12;
/**
* One written image: a single frame stamped with its timecode, or a contact
* sheet stamped with the span it covers (`0f-08s10f`).
*/
export type TimecodedImage = { timecode: string; base64: string };
export type MediaFrameResult = TimecodedImage[];
export type CaptureRequest = {
id: string;
frames?: number[];
combine?: boolean;
perSheet?: number;
};
export type CaptureResult = TimecodedImage[];
export type MediaTranscribeRequest = AssetRef;
export type TranscriptWord = { text: string; start: number; end: number };
export type TranscriptSegment = { text: string; words: TranscriptWord[] };
export type MediaTranscribeResult = { segments: TranscriptSegment[] };
export type MediaFilmstripRequest = AssetRef & { start?: number; end?: number; scale?: number };
export type MediaFilmstripResult = { base64: string };
export type MediaWaveformRequest = AssetRef & { start?: number; end?: number; scale?: number };
export type MediaWaveformResult = {
base64: string;
silences: Array<{ start: number; end: number }>;
};
export type MediaListenRequest = AssetRef & { prompt?: string; start?: number; end?: number; stripVideo?: boolean };
export type MediaListenResult = { result?: string; start?: number; end?: number };
export type CheckRequest = { id: string };
export type CheckIssueCode =
| "black-frames"
| "no-visuals"
| "never-visible"
| "zero-duration"
| "transparent"
| "source-error";
/**
* One structural finding. `ranges` (where present) are seconds relative to
* the checked node's start — the same clock `capture --time` uses.
*/
export type CheckIssue = {
code: CheckIssueCode;
severity: "error" | "warning";
message: string;
/** Source stamp of the offending node; absent when the issue is about the subtree as a whole. */
node?: string;
ranges?: Array<{ start: number; end: number }>;
};
export type CheckResult = {
stats: {
/** Nodes in the subtree, the checked node included. */
nodes: number;
byKind: Record<string, number>;
/** Deepest nesting level below the checked node (0 = no children). */
depth: number;
/** Seconds the checked node plays (its workarea, when one is set). */
duration: number;
};
issues: CheckIssue[];
};
export type ExportFormat = "mp4" | "webm" | "ogg" | "mov";
// The settings shape mirrors the scene's `diffusion.export.<id>` entry in the
// project's package.json (see the web app's engine/project-config), spelled
// out here so the wire seam stays dependency-free. Codecs are strings on the
// wire; the app validates them against what the encoder accepts.
export type ExportVideoSettings = {
enabled?: boolean;
codec?: string;
bitrate?: number;
fps?: number;
resolution?: number;
};
export type ExportAudioSettings = {
enabled?: boolean;
codec?: string;
sampleRate?: number;
bitrate?: number;
};
export type ExportSettings = {
format?: ExportFormat;
video?: ExportVideoSettings;
audio?: ExportAudioSettings;
};
/**
* `path` is the absolute output file, whose extension picks the container;
* omitted, the app writes `exports/<id>.<format>` in the project folder.
* Everything else — codecs, bitrates, resolution — is read from the scene's
* export entry in the project's package.json.
*/
export type ExportRequest = { id: string; path?: string };
/**
* `config` echoes the settings the export was made with — the package.json
* entry (or the defaults), with the container the extension resolved to — so
* a caller sees what its config edit actually did. `width`/`height` are the
* encoded pixel size (0×0 for an audio-only export); `duration` is seconds.
*/
export type ExportResult = {
path: string;
width: number;
height: number;
duration: number;
size: number;
config: ExportSettings;
};
export type GeneratedAsset = { id: string; name: string; type: string };
export type ModelsRequest = { type?: "image" | "video" | "audio" };
export type ModelInfo = {
type: "image" | "video" | "audio";
id: string;
name: string;
durations?: string[];
aspectRatios?: string[];
features?: Array<"start-frame" | "end-frame" | "audio">;
};
export type VoiceInfo = { id: string; label: string; description: string };
export type ScreenshotResult = { base64: string; width: number; height: number };
export type LogLevel = "debug" | "info" | "warning" | "error";
export type LogEntry = { ts: number; level: LogLevel; message: string; source: string };
export type LogsRequest = { tail?: number; level?: LogLevel };

View File

@ -2,166 +2,133 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { connect } from "node:net";
import { randomBytes } from "node:crypto";
import type { AddressInfo } from "node:net";
import { WebSocketServer } from "ws";
import { createTRPCClient, TRPCClientError } from "@trpc/client";
import type { TRPCLink } from "@trpc/client";
import { observable } from "@trpc/server/observable";
import { SOCKET_PATH } from "./protocol";
import type { CliHandshake, CliHandshakeReply, CliReply, CliRequest } from "./protocol";
import type { AppRouter } from "../../web/src/context/dapi";
import { execFile, spawn } from "node:child_process";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { MCP_URL } from "@diffusionstudio/dapi";
import { version } from "../../../package.json";
const DEFAULT_TIMEOUT_MS = 60000;
export const GENERATE_TIMEOUT_MS = 600000;
export const EXPORT_TIMEOUT_MS = 3600000;
import type { ToolInput, ToolName, ToolOutput } from "@diffusionstudio/dapi";
// Asks the app (via the unix socket) to have the renderer dial our WebSocket
// server. Main replies once the connect info has been delivered, so a
// rejection here means the app is down or the renderer never became ready.
function requestConnection(handshake: CliHandshake, timeoutMs: number): Promise<void> {
return new Promise((resolve, reject) => {
const sock = connect(SOCKET_PATH);
let buf = "";
let settled = false;
const settle = (fn: () => void) => {
if (settled) return;
settled = true;
sock.destroy();
fn();
};
export const APP_NAME = "Diffusion Studio";
sock.setEncoding("utf8");
sock.setTimeout(timeoutMs, () =>
settle(() => reject(new Error("Timed out waiting for the app to accept the connection"))),
);
sock.on("connect", () => sock.end(JSON.stringify(handshake)));
sock.on("data", (chunk) => {
buf += chunk;
});
sock.on("end", () => {
let reply: CliHandshakeReply;
try {
reply = JSON.parse(buf) as CliHandshakeReply;
} catch (e) {
settle(() => reject(e instanceof Error ? e : new Error(String(e))));
return;
}
if (reply.ok) settle(resolve);
else settle(() => reject(new Error(reply.error)));
});
sock.on("error", (err) => settle(() => reject(err)));
});
}
async function transport(request: CliRequest, timeoutMs: number): Promise<unknown> {
const token = randomBytes(16).toString("hex");
// Frame batches and other base64 replies can exceed ws's 100 MiB default,
// so disable the payload cap; the server only lives for one request.
const wss = new WebSocketServer({ host: "127.0.0.1", port: 0, maxPayload: 0 });
// Renders, media analysis and file transfers outlive the 60s default.
const TIMEOUTS: Record<string, number> = {
export: 3_600_000,
capture: 600_000,
transcribe: 600_000,
listen: 600_000,
generate: 600_000,
job: 600_000,
};
/**
* Calls one tool in the running app over an MCP session on its HTTP
* endpoint — the same URL agents register. Typed by the catalog: the input is
* what the tool's schema accepts, the output its structured content. One
* session per call; a command makes one or two, and the process exits when
* it settles.
*/
export async function call<N extends ToolName>(name: N, input: ToolInput<N>): Promise<ToolOutput<N>> {
const client = await connect();
try {
const reply = await new Promise<CliReply>((resolve, reject) => {
let settled = false;
const timer = setTimeout(() => {
settle(() => reject(new Error("Timed out waiting for response")));
}, timeoutMs);
const settle = (fn: () => void) => {
if (settled) return;
settled = true;
clearTimeout(timer);
fn();
};
wss.on("error", (err) => settle(() => reject(err)));
wss.on("connection", (ws, req) => {
const url = new URL(req.url ?? "/", "ws://127.0.0.1");
if (url.searchParams.get("token") !== token) {
ws.terminate();
return;
}
ws.on("message", (raw) => {
try {
const parsed = JSON.parse(raw.toString()) as CliReply;
settle(() => resolve(parsed));
} catch (e) {
settle(() => reject(e instanceof Error ? e : new Error(String(e))));
}
});
ws.on("close", () =>
settle(() => reject(new Error("App disconnected before replying"))),
);
ws.on("error", (err) => settle(() => reject(err)));
ws.send(JSON.stringify(request));
});
wss.once("listening", () => {
const { port } = wss.address() as AddressInfo;
requestConnection({ port, token }, timeoutMs).catch((err) =>
settle(() => reject(err instanceof Error ? err : new Error(String(err)))),
);
});
const result = await client.callTool({ name, arguments: input as Record<string, unknown> }, undefined, {
timeout: TIMEOUTS[name] ?? 60_000,
});
if (reply.ok) return reply.data;
throw new Error(reply.error);
if (result.isError) {
const text = (result.content as Array<{ type: string; text?: string }>)
.filter((block) => block.type === "text")
.map((block) => block.text)
.join("\n");
throw new Error(text || `${name} failed`);
}
return result.structuredContent as ToolOutput<N>;
} finally {
// Tear down explicitly so no lingering handles keep the Node event loop
// alive past `console.log(result)` and block the CLI from exiting.
for (const client of wss.clients) client.terminate();
wss.close();
await client.close().catch(() => { });
}
}
// Terminating link: each operation runs over its own short-lived WebSocket
// server that the renderer dials in to. Long-running procedures pass
// { context: { timeoutMs } } at the call site.
const cliLink: TRPCLink<AppRouter> =
() =>
({ op }) =>
observable((observer) => {
const timeoutMs =
typeof op.context.timeoutMs === "number" ? op.context.timeoutMs : DEFAULT_TIMEOUT_MS;
transport({ path: op.path, input: op.input }, timeoutMs)
.then((data) => {
observer.next({ result: { data } });
observer.complete();
})
.catch((err) => observer.error(TRPCClientError.from(err as Error)));
// No cancellation: the CLI process exits when the command settles.
return () => {};
});
export const editor = createTRPCClient<AppRouter>({ links: [cliLink] });
// Transport failures surface as TRPCClientError wrapping the socket error;
// unwrap to reach errno codes like ENOENT/ECONNREFUSED.
export function errnoCode(e: unknown): string | undefined {
if (!(e instanceof TRPCClientError)) return undefined;
return (e.cause as NodeJS.ErrnoException | undefined)?.code;
/** Liveness: a round-trip through the app's MCP server. */
export async function ping(): Promise<void> {
const client = await connect();
try {
await client.ping();
} finally {
await client.close().catch(() => { });
}
}
// Bridges the cold-start gap after launching the app. Main only delivers the
// handshake once the renderer has finished loading, and `ping` is answered
// by the always-mounted app router, so a single round-trip proves the app is
// fully up. The retry loop only handles the brief window before the handshake
// socket itself binds (ENOENT/ECONNREFUSED).
export async function waitForCliSocket(timeoutMs = 30000): Promise<void> {
// Connecting is where "the app is not running" shows up: the `initialize`
// request's fetch is refused, see `isAppDown`.
async function connect(): Promise<Client> {
const client = new Client({ name: "diffusion", version });
await client.connect(new StreamableHTTPClientTransport(new URL(MCP_URL)));
return client;
}
/**
* Nothing is listening on the app's port. Node's fetch reports that as a
* `fetch failed` TypeError whose cause carries the errno, so the chain of
* causes is searched.
*/
export function isAppDown(e: unknown): boolean {
for (let error = e, depth = 0; error && depth < 5; error = (error as { cause?: unknown }).cause, depth++) {
const code = (error as NodeJS.ErrnoException).code;
if (code === "ECONNREFUSED" || code === "ECONNRESET") return true;
}
return false;
}
function launchWin32(background: boolean): Promise<boolean> {
if (!process.versions.electron) return Promise.resolve(false);
const { ELECTRON_RUN_AS_NODE: _, ...env } = process.env;
return new Promise((res) => {
const child = spawn(process.execPath, background ? ["--hidden"] : [], {
detached: true,
stdio: "ignore",
env,
});
child.once("error", () => res(false));
child.once("spawn", () => {
child.unref();
res(true);
});
});
}
function launchDarwin(background: boolean): Promise<boolean> {
const args = background ? ["-g", "-a", APP_NAME, "--args", "--hidden"] : ["-a", APP_NAME];
const { ELECTRON_RUN_AS_NODE: _, ...env } = process.env;
return new Promise((res) => execFile("open", args, { env }, (err) => res(!err)));
}
/**
* Launches the app, or surfaces the running instance
*/
export function launchApp(background: boolean): Promise<boolean> {
if (process.platform === "win32") return launchWin32(background);
if (process.platform === "darwin") return launchDarwin(background);
return Promise.resolve(false);
}
/**
* Bridges the cold-start gap after launching the app: retries while the app
* looks down, until it answers a ping.
*/
export async function waitForApp(timeoutMs = 30000): Promise<void> {
const start = Date.now();
let lastError: unknown = null;
while (Date.now() - start < timeoutMs) {
try {
await editor.ping.query();
return;
return await ping();
} catch (e) {
if (!isAppDown(e)) throw e;
lastError = e;
const code = errnoCode(e);
if (code !== "ENOENT" && code !== "ECONNREFUSED") throw e;
await new Promise((r) => setTimeout(r, 200));
}
}
throw lastError instanceof Error
? lastError
: new Error("Timed out waiting for the app to start");
const detail = lastError instanceof Error ? ` (${lastError.message})` : "";
throw new Error(`${APP_NAME} did not answer within ${Math.round(timeoutMs / 1000)}s of launching${detail}`);
}

View File

@ -1,16 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { platform, tmpdir } from "node:os";
import { join } from "node:path";
// One socket / named pipe per host. On macOS tmpdir is per-user; on Linux /tmp
// is global but the socket file's owner-only mode 0600 keeps it isolated.
//
// Kept separate from cli-channels so the renderer can import the channel
// registry and envelope types without pulling in node:os / node:path.
export const SOCKET_PATH =
platform() === "win32"
? "\\\\.\\pipe\\diffusion-studio"
: join(tmpdir(), "diffusion-studio.sock");

View File

@ -1,103 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { spawnSync } from "node:child_process";
import { platform } from "node:os";
export type FontVariant = {
weight: string;
style: "normal" | "italic";
source: string;
};
export type FontFamily = {
family: string;
variants: FontVariant[];
};
// JXA script that walks every registered font family via NSFontManager and
// emits each variant's CSS-style weight, italic flag, and CSS `local()` source.
// Embedded inline so the CLI binary is self-contained — runs via `osascript`.
const LIST_FONTS_JXA = `
ObjC.import("AppKit");
function nsfmWeightToCss(w) {
if (w <= 1) return "100";
if (w <= 2) return "200";
if (w <= 3) return "300";
if (w <= 5) return "400";
if (w <= 6) return "500";
if (w <= 8) return "600";
if (w <= 9) return "700";
if (w <= 11) return "800";
return "900";
}
function run() {
var fm = $.NSFontManager.sharedFontManager;
var families = fm.availableFontFamilies;
var out = [];
for (var i = 0; i < families.count; i++) {
var family = ObjC.unwrap(families.objectAtIndex(i));
if (family.charAt(0) === ".") continue;
var members = fm.availableMembersOfFontFamily(family);
if (!members || members.isNil()) continue;
var variants = [];
for (var j = 0; j < members.count; j++) {
var m = members.objectAtIndex(j);
var fontName = ObjC.unwrap(m.objectAtIndex(0));
var styleName = ObjC.unwrap(m.objectAtIndex(1));
var weight = ObjC.unwrap(m.objectAtIndex(2));
var traits = ObjC.unwrap(m.objectAtIndex(3));
var fullName = styleName === "Regular" ? family : family + " " + styleName;
variants.push({
weight: nsfmWeightToCss(weight),
style: (traits & 1) !== 0 ? "italic" : "normal",
source: "local('" + fullName + "'), local('" + fontName + "')",
});
}
if (variants.length > 0) out.push({ family: family, variants: variants });
}
return JSON.stringify(out);
}
`;
export type ListLocalFontsOptions = {
familyPattern?: string;
weights?: string[];
style?: "normal" | "italic";
limit?: number;
};
export function listLocalFonts(options: ListLocalFontsOptions = {}): FontFamily[] {
if (platform() !== "darwin") {
throw new Error("fonts is only supported on macOS.");
}
const result = spawnSync("osascript", ["-l", "JavaScript", "-e", LIST_FONTS_JXA], {
encoding: "utf8",
maxBuffer: 16 * 1024 * 1024,
});
if (result.status !== 0) {
throw new Error(result.stderr.trim() || "Failed to enumerate fonts.");
}
const all = JSON.parse(result.stdout.trim()) as FontFamily[];
const pattern = options.familyPattern?.toLowerCase();
const weights = options.weights && options.weights.length > 0 ? new Set(options.weights) : null;
const { style, limit } = options;
const out: FontFamily[] = [];
for (const family of all) {
if (pattern && !family.family.toLowerCase().includes(pattern)) continue;
const variants = family.variants.filter((v) => {
if (weights && !weights.has(v.weight)) return false;
if (style && v.style !== style) return false;
return true;
});
if (variants.length === 0) continue;
out.push({ family: family.family, variants });
if (limit !== undefined && out.length >= limit) break;
}
return out;
}

File diff suppressed because it is too large Load Diff

49
apps/cli/src/mcp-proxy.ts Normal file
View File

@ -0,0 +1,49 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// `diffusion mcp`: the entry point for agents that only run stdio servers (Claude
// Desktop). A message pipe between stdio and the app's HTTP endpoint: each
// side is an SDK transport, so session handling and SSE framing are theirs,
// and nothing here looks inside a message. Stdout belongs to the protocol;
// anything for a human goes to stderr.
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { MCP_URL } from "@diffusionstudio/dapi";
import { APP_NAME, isAppDown, launchApp, ping, waitForApp } from "./cli-client";
import type { JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js";
export async function runProxy(): Promise<void> {
try {
await ping();
} catch (e) {
if (!isAppDown(e)) throw e;
// Launching is macOS's job; elsewhere the user starts the app by hand.
if (!(await launchApp(true))) {
throw new Error(`${APP_NAME} is not running. Launch the app first, then retry.`);
}
await waitForApp();
}
const upstream = new StreamableHTTPClientTransport(new URL(MCP_URL));
const stdio = new StdioServerTransport();
const fail = (error: Error): void => {
console.error(`[diffusion mcp] ${error.message}`);
process.exit(1);
};
upstream.onmessage = (message: JSONRPCMessage) => void stdio.send(message).catch(fail);
stdio.onmessage = (message: JSONRPCMessage) => void upstream.send(message).catch(fail);
upstream.onerror = (error) => console.error(`[diffusion mcp] ${error.message}`);
stdio.onerror = (error) => console.error(`[diffusion mcp] ${error.message}`);
// The app went away (quit, or the session was closed): the agent sees EOF.
upstream.onclose = () => process.exit(0);
// The agent went away: tell the app, which ends the session.
stdio.onclose = () => void upstream.close().finally(() => process.exit(0));
await upstream.start();
await stdio.start();
}

View File

@ -1,11 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Public wire protocol consumed by both the CLI binary and any host that
// embeds the CLI socket server (the Diffusion Studio desktop app). Importing
// from `@diffusionstudio/cli/protocol` is the OSS-friendly seam: this module has no
// dependency on proprietary code, so the package stays extractable into its
// own repo.
export * from "./cli-channels";
export * from "./cli-socket-path";

View File

@ -1,15 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Babel presets ship no type declarations; they are only ever passed opaquely
// into @babel/core's `presets` option.
declare module "babel-preset-solid" {
const preset: unknown;
export default preset;
}
declare module "@babel/preset-typescript" {
const preset: unknown;
export default preset;
}

View File

@ -1,74 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { spawn, spawnSync } from "node:child_process";
// Resolve the binary once. YT_DLP_PATH mirrors DIFFUSION_APP_PATH: an escape
// hatch for pinned or non-PATH installs.
const BIN = process.env.YT_DLP_PATH ?? "yt-dlp";
// Fails with an actionable message before any download is attempted. ENOENT is
// the "not installed" case; a non-zero status means the binary is present but
// broken.
function assertInstalled(): void {
const probe = spawnSync(BIN, ["--version"], { encoding: "utf8" });
if (probe.error) {
if ((probe.error as NodeJS.ErrnoException).code === "ENOENT") {
throw new Error(
`yt-dlp not found. Install it (brew install yt-dlp, or pipx install yt-dlp) ` +
`or set YT_DLP_PATH to its location.`,
);
}
throw new Error(probe.error.message);
}
if (probe.status !== 0) {
throw new Error(probe.stderr?.trim() || "yt-dlp is present but not runnable.");
}
}
export type FetchOptions = {
output?: string;
format?: string;
audio?: boolean;
raw?: string[];
};
// Downloads the URL and resolves to the final file path(s) on disk. yt-dlp's
// own `after_move:filepath` reports what actually landed (post extraction /
// rename), so we never guess the name. --quiet silences stdout chatter while
// --progress forces the progress bar to stderr, keeping stdout to just the
// paths we capture.
export function fetchVideo(url: string, opts: FetchOptions = {}): Promise<string[]> {
assertInstalled();
const args = ["--quiet", "--no-warnings", "--progress", "--print", "after_move:filepath"];
if (opts.output) args.push("-o", opts.output);
if (opts.format) {
args.push("-f", opts.format);
} else if (!opts.audio) {
// Default to mp4: prefer mp4/m4a streams, then remux the merged result so
// the landed file is a .mp4 even when only WebM/mkv sources were available.
// An explicit -f or --audio opts out.
args.push("-f", "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]/bv*+ba/b", "--merge-output-format", "mp4");
}
if (opts.audio) args.push("-x");
if (opts.raw?.length) args.push(...opts.raw);
args.push(url);
return new Promise((resolve, reject) => {
// stdout: resolved paths (captured); stderr: live progress (inherited).
const child = spawn(BIN, args, { stdio: ["ignore", "pipe", "inherit"] });
let out = "";
child.stdout.setEncoding("utf8");
child.stdout.on("data", (chunk) => (out += chunk));
child.on("error", reject);
child.on("close", (code) => {
if (code === 0) {
resolve(out.split("\n").map((line) => line.trim()).filter(Boolean));
} else {
reject(new Error(`yt-dlp exited with code ${code}.`));
}
});
});
}

View File

@ -2,40 +2,9 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.tsbuildinfo",
// The AppRouter type import in cli-client.ts pulls renderer sources into
// this program, so the web app's compiler settings (DOM, solid JSX, vite
// types, aliases) apply here on top of the node ones.
"useDefineForClassFields": true,
"erasableSyntaxOnly": false,
"lib": [
"es2024",
"DOM",
"DOM.Iterable"
],
"types": [
"node",
"vite-plugin-solid-svg/types-component-solid",
"vite/client",
"@types/audioworklet",
"@types/wicg-file-system-access",
"@webgpu/types"
],
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
"baseUrl": "./",
"paths": {
"@/*": [
"../web/src/*"
],
"@desktop/*": [
"../desktop/src/*"
]
}
"lib": ["es2024"],
"types": ["node"],
"resolveJsonModule": true
},
"include": [
"src",
"../web/src/vite-env.d.ts"
]
"include": ["src"]
}

View File

@ -2,5 +2,5 @@ dist
web
out
cli
runtime
docs
skills

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Application manifest embedded into "Diffusion Studio.exe" on Windows
(win32metadata['application-manifest'] in forge.config.ts). The packager
replaces Electron's own manifest wholesale, so this is Electron 43's
manifest (read out of electron.exe) plus one addition: longPathAware, which
lets the app open project folders whose paths exceed MAX_PATH, such as
deep node_modules trees. Windows honours it only when the LongPathsEnabled
policy is on, which it is on Windows 11 by default. Keep the rest in step
with Electron when the Electron version changes.
-->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<disableWindowFiltering xmlns="http://schemas.microsoft.com/SMI/2011/WindowsSettings">true</disableWindowFiltering>
</asmv3:windowsSettings>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/pm</dpiAware>
</asmv3:windowsSettings>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<longPathAware>true</longPathAware>
</asmv3:windowsSettings>
</asmv3:application>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<maxversiontested Id="10.0.18362.0"/>
</application>
</compatibility>
</assembly>

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="#000" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round">
<path d="M6.5 2.5l1.25 3.25L11 7 7.75 8.25 6.5 11.5 5.25 8.25 2 7l3.25-1.25z"/><path d="M12 10l.6 1.4 1.4.6-1.4.6L12 14l-.6-1.4L10 12l1.4-.6z" fill="#000" stroke-width="0.75"/>
</svg>

After

Width:  |  Height:  |  Size: 338 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="#000" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round">
<mask id="gap"><rect width="16" height="16" fill="#fff" stroke="none"/><path d="M2.5 2.5l11 11" stroke="#000" stroke-width="3.25"/></mask>
<g mask="url(#gap)"><path d="M1.75 8S4 3.75 8 3.75 14.25 8 14.25 8 12 12.25 8 12.25 1.75 8 1.75 8z"/><circle cx="8" cy="8" r="2"/></g><path d="M2.5 2.5l11 11"/>
</svg>

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="#000" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round">
<rect x="2" y="3" width="12" height="10" rx="2"/><path d="M2 6h12"/>
</svg>

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="#000" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round">
<path d="M2 4.5A1.5 1.5 0 0 1 3.5 3h2.75l1.5 1.5h4.75A1.5 1.5 0 0 1 14 6v5.5a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 11.5z"/>
</svg>

After

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="#000" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round">
<path d="M8 2v5.5"/><path d="M4.75 4.25a5.25 5.25 0 1 0 6.5 0"/>
</svg>

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="#000" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round">
<circle cx="8" cy="8" r="6"/><path d="M5.5 8.25l1.75 1.75 3.25-3.5"/>
</svg>

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 999 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -2,15 +2,23 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import type { ForgeConfig } from '@electron-forge/shared-types';
import { MakerDMG } from '@electron-forge/maker-dmg';
import { MakerSquirrel } from '@electron-forge/maker-squirrel';
import { MakerZIP } from '@electron-forge/maker-zip';
import { PublisherGithub } from '@electron-forge/publisher-github';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { copyFileSync, existsSync, readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { arch } from 'node:os';
import { dirname, join } from 'node:path';
import type { ForgeConfig } from '@electron-forge/shared-types';
import type { MakerSquirrelConfig } from '@electron-forge/maker-squirrel';
const { version } = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf8'));
const sign = windowsSign();
const config: ForgeConfig = {
packagerConfig: {
name: 'Diffusion Studio',
@ -18,6 +26,12 @@ const config: ForgeConfig = {
appCategoryType: 'public.app-category.video',
appVersion: version,
icon: './assets/icon',
win32metadata: {
CompanyName: 'Diffusion Studio',
ProductName: 'Diffusion Studio',
FileDescription: 'Diffusion Studio',
'application-manifest': join(__dirname, 'assets', 'app.manifest'),
},
protocols: [{ name: 'Diffusion Studio', schemes: ['diffusion'] }],
prune: false,
ignore: (path) =>
@ -27,21 +41,35 @@ const config: ForgeConfig = {
!path.startsWith('/dist/') &&
path !== '/web' &&
!path.startsWith('/web/'),
// Staged by scripts/stage-{cli,docs,skills}.mjs; end up at
// Contents/Resources/{cli,docs,skills}.
extraResource: ['./cli', './docs', './skills'],
// Staged by scripts/stage-{cli,runtime,docs}.mjs; end up at
// Contents/Resources/{cli,runtime,docs}.
extraResource: ['./cli', './runtime', './docs'],
osxSign: process.env.SKIP_SIGN ? undefined : {},
osxNotarize:
process.env.APPLE_ID && process.env.APPLE_PASSWORD && process.env.APPLE_TEAM_ID
? {
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_PASSWORD,
teamId: process.env.APPLE_TEAM_ID,
}
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_PASSWORD,
teamId: process.env.APPLE_TEAM_ID,
}
: undefined,
windowsSign: sign,
},
makers: [
new MakerZIP({}, ['darwin']),
new MakerSquirrel({
name: 'DiffusionStudio',
authors: 'Diffusion Studio',
description: 'The professional video editor built for agents',
exe: 'Diffusion Studio.exe',
setupExe: `Diffusion-Studio-${process.arch}-Setup.exe`,
setupIcon: './assets/icon.ico',
loadingGif: './assets/install-spinner.gif',
// Shown by Add/Remove Programs; Squirrel only takes a URL.
iconUrl: 'https://raw.githubusercontent.com/diffusionstudio/editor/main/apps/desktop/assets/icon.ico',
noMsi: true,
windowsSign: sign,
}),
new MakerDMG({
name: `Diffusion-Studio-${process.arch}`,
icon: './assets/icon.icns',
@ -64,6 +92,55 @@ const config: ForgeConfig = {
draft: true,
}),
],
hooks: {
prePackage: async () => {
if (process.platform === 'win32' && !process.env.SKIP_SIGN && !sign) {
throw new Error(
'Windows signing needs WINDOWS_SIGNTOOL_PATH, WINDOWS_SIGN_DLIB and WINDOWS_SIGN_METADATA; set SKIP_SIGN=1 for an unsigned build.',
);
}
},
preMake: async () => ensure7zip(),
},
};
function windowsSign() {
if (process.platform !== 'win32' || process.env.SKIP_SIGN) {
return undefined;
}
const {
WINDOWS_SIGNTOOL_PATH: signToolPath,
WINDOWS_SIGN_DLIB: dlib,
WINDOWS_SIGN_METADATA: metadata
} = process.env;
if (!signToolPath || !dlib || !metadata) {
return undefined;
}
return {
signToolPath,
automaticallySelectCertificate: false,
signWithParams: ['/dlib', dlib, '/dmdf', metadata],
timestampServer: 'http://timestamp.acs.microsoft.com',
hashes: ['sha256'],
} as unknown as MakerSquirrelConfig;
}
function ensure7zip() {
if (process.platform !== 'win32') return;
const require = createRequire(__filename);
const winstaller = require.resolve('electron-winstaller/package.json', {
paths: [dirname(require.resolve('@electron-forge/maker-squirrel/package.json'))],
});
const vendor = join(dirname(winstaller), 'vendor');
for (const ext of ['exe', 'dll']) {
const target = join(vendor, `7z.${ext}`);
if (!existsSync(target)) copyFileSync(join(vendor, `7z-${arch()}.${ext}`), target);
}
}
export default config;

View File

@ -1,7 +1,7 @@
{
"name": "@diffusionstudio/desktop",
"private": true,
"version": "0.204.2",
"version": "0.216.0",
"license": "MPL-2.0",
"repository": {
"type": "git",
@ -10,35 +10,44 @@
"main": "dist/main.js",
"scripts": {
"build:preload": "esbuild src/preload.ts --bundle --platform=node --format=cjs --external:electron --outfile=dist/preload.js",
"build:main": "esbuild src/main.ts --bundle --platform=node --format=cjs --external:electron --external:esbuild --external:@babel/core --external:@babel/preset-typescript --external:babel-preset-solid --outfile=dist/main.js",
"build:main": "esbuild src/main.ts --bundle --platform=node --format=cjs --loader:.png=binary --external:electron --external:esbuild --external:@babel/core --external:@babel/preset-typescript --external:babel-preset-solid --outfile=dist/main.js",
"build:native": "node scripts/build-native.mjs",
"build": "npm run check && npm run build:main && npm run build:preload && npm run build:native",
"build": "npm run check && npm run build:main && npm run build:preload && npm run build:agent-host && npm run build:native",
"build:web": "npm --prefix ../web run build:desktop",
"stage:cli": "npm --prefix ../cli run build && node scripts/stage-cli.mjs",
"stage:runtime": "node scripts/stage-runtime.mjs",
"stage:docs": "node scripts/stage-docs.mjs",
"stage:skills": "node scripts/stage-skills.mjs",
"check": "tsc --noEmit",
"dev": "npm run build && electron-forge start",
"package": "npm run build && npm run build:web && npm run stage:cli && npm run stage:docs && npm run stage:skills && electron-forge package",
"make": "npm run build && npm run build:web && npm run stage:cli && npm run stage:docs && npm run stage:skills && electron-forge make",
"publish": "npm run build && npm run build:web && npm run stage:cli && npm run stage:docs && npm run stage:skills && electron-forge publish",
"make:icns": "sh scripts/make-icns.sh"
"package": "npm run build && npm run build:web && npm run stage:cli && npm run stage:runtime && npm run stage:docs && electron-forge package",
"make": "npm run build && npm run build:web && npm run stage:cli && npm run stage:runtime && npm run stage:docs && electron-forge make",
"publish": "npm run build && npm run build:web && npm run stage:cli && npm run stage:runtime && npm run stage:docs && electron-forge publish",
"make:icns": "sh scripts/make-icns.sh",
"test": "vitest run",
"build:agent-host": "esbuild ../../packages/agent-chat/src/bin.ts --bundle --platform=node --format=esm --target=node20 --external:electron \"--external:@anthropic-ai/claude-agent-sdk-*\" --banner:js=\"import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);\" --outfile=dist/agent-host.mjs",
"make:ico": "python3 scripts/win-assets.py ico",
"make:spinner": "python3 scripts/win-assets.py spinner",
"make:tray-menu": "sh scripts/tray-menu-icons.sh"
},
"devDependencies": {
"@electron-forge/cli": "^7.11.1",
"@electron-forge/maker-dmg": "^7.11.1",
"@electron-forge/maker-squirrel": "^7.11.2",
"@electron-forge/maker-zip": "^7.11.1",
"@electron-forge/publisher-github": "^7.11.1",
"@types/babel__core": "^7.20.5",
"@types/node": "^24.10.1",
"electron": "^43.1.1",
"typescript": "~5.9.3"
"typescript": "~5.9.3",
"vitest": "^4.0.0"
},
"dependencies": {
"@babel/core": "^7.29.7",
"@babel/preset-typescript": "^7.27.1",
"@diffusionstudio/cli": "*",
"@diffusionstudio/agent-chat": "*",
"@diffusionstudio/dapi": "*",
"@diffusionstudio/jsx": "*",
"@modelcontextprotocol/sdk": "^1.30.0",
"babel-preset-solid": "^1.9.12",
"esbuild": "^0.28.1",
"nanoid": "^6.0.1",

View File

@ -4,12 +4,19 @@
// Stages the dapi CLI into apps/desktop/cli so electron-forge can ship it as
// an app resource (Contents/Resources/cli). The staged layout:
// cli/dapi.js bundled CLI (built by apps/cli)
// cli/node_modules deps the bundle keeps external (esbuild, babel)
// cli/bin/dapi shell wrapper, the file that gets linked into PATH
// cli/dapi.js bundled CLI (built by apps/cli), self-contained
// cli/bin/dapi macOS shell wrapper: what Claude Desktop runs as
// `dapi mcp` (registered by mcp-install.ts) and the file
// that gets linked into PATH
// cli/bin/dapi.cmd Windows wrapper, relative to the install folder. PATH
// and the agents get a shim outside the install folder
// instead (src/cli-windows.ts), since Squirrel moves the
// app on every update; this one is for running the CLI
// straight out of an install.
// Each host stages its own wrapper; `--all` stages both, so a macOS host can
// produce a Windows tree for inspection.
import { execFileSync } from "node:child_process";
import { chmodSync, cpSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { chmodSync, cpSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
@ -17,40 +24,16 @@ const desktopDir = join(dirname(fileURLToPath(import.meta.url)), "..");
const cliDir = join(desktopDir, "..", "cli");
const stageDir = join(desktopDir, "cli");
// Must match the --external list in the apps/cli build script, minus ws's
// optional native addons (bufferutil, utf-8-validate): those are external
// only so the bundle doesn't choke on them, and ws falls back to its JS
// implementations when they are absent.
const EXTERNALS = ["esbuild", "@babel/core", "@babel/preset-typescript", "babel-preset-solid"];
const cliPkg = JSON.parse(readFileSync(join(cliDir, "package.json"), "utf8"));
rmSync(stageDir, { recursive: true, force: true });
mkdirSync(join(stageDir, "bin"), { recursive: true });
cpSync(join(cliDir, "dist", "index.js"), join(stageDir, "dapi.js"));
writeFileSync(
join(stageDir, "package.json"),
JSON.stringify(
{
name: "dapi-runtime",
private: true,
dependencies: Object.fromEntries(EXTERNALS.map((name) => [name, cliPkg.dependencies[name]])),
},
null,
2,
),
);
execFileSync("npm", ["install", "--omit=dev", "--no-audit", "--no-fund", "--no-package-lock"], {
cwd: stageDir,
stdio: "inherit",
});
// The wrapper runs the CLI bundle on the app's own Electron binary in Node
// mode, so users need no separate Node install. It resolves symlinks first
// because both Homebrew and the in-app installer link it into PATH.
const all = process.argv.includes("--all");
const wrapper = `#!/bin/sh
SELF="$0"
while [ -L "$SELF" ]; do
@ -64,27 +47,23 @@ DIR="$(cd "$(dirname "$SELF")" && pwd)"
export DIFFUSION_APP_PATH="$(cd "$DIR/../../../.." && pwd)"
ELECTRON_RUN_AS_NODE=1 exec "$DIR/../../../MacOS/Diffusion Studio" "$DIR/../dapi.js" "$@"
`;
writeFileSync(join(stageDir, "bin", "dapi"), wrapper);
chmodSync(join(stageDir, "bin", "dapi"), 0o755);
// Mach-O files inside Resources are not reached by the app-bundle signing
// pass, and notarization rejects unsigned executables; sign them here.
if (process.platform === "darwin" && !process.env.SKIP_SIGN) {
const identities = execFileSync("security", ["find-identity", "-v", "-p", "codesigning"], {
encoding: "utf8",
});
const identity = identities.match(/"(Developer ID Application: [^"]+)"/)?.[1];
if (identity) {
const esbuildDir = join(stageDir, "node_modules", "@esbuild");
for (const pkg of readdirSync(esbuildDir)) {
const bin = join(esbuildDir, pkg, "bin", "esbuild");
execFileSync("codesign", ["--force", "--options", "runtime", "--timestamp", "--sign", identity, bin], {
stdio: "inherit",
});
}
} else {
console.warn("stage-cli: no Developer ID identity found, leaving esbuild binary unsigned");
}
if (all || process.platform !== "win32") {
writeFileSync(join(stageDir, "bin", "dapi"), wrapper);
chmodSync(join(stageDir, "bin", "dapi"), 0o755);
}
// Staged at <install>\resources\cli\bin, three folders below the executable.
const cmdWrapper = [
"@echo off",
"setlocal",
'set "ELECTRON_RUN_AS_NODE=1"',
'"%~dp0..\\..\\..\\Diffusion Studio.exe" "%~dp0..\\dapi.js" %*',
"",
].join("\r\n");
if (all || process.platform === "win32") {
writeFileSync(join(stageDir, "bin", "dapi.cmd"), cmdWrapper);
}
console.log(`stage-cli: staged dapi at ${stageDir}`);

View File

@ -2,12 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Stages the authoring docs into apps/desktop/docs so electron-forge can ship
// them as an app resource (Contents/Resources/docs). The layout mirrors the
// repo — reference/ beside examples/ — because the relative links between the
// pages assume it. scaffold() copies the tree into each project's
// .diffusion/docs, so what an agent reads in a project is exactly what was
// staged here (see src/projects.ts).
// Stages the docs into apps/desktop/docs so electron-forge can ship them as
// an app resource (Contents/Resources/docs). The app's MCP server sends
// INSTRUCTIONS.md on connect along with this folder's path; agents read the
// rest as plain files. The tree is copied as it is in the repo, because the
// relative links between the pages assume that layout.
import { cpSync, mkdirSync, rmSync } from "node:fs";
import { dirname, join } from "node:path";
@ -19,8 +18,9 @@ const stageDir = join(desktopDir, "docs");
rmSync(stageDir, { recursive: true, force: true });
mkdirSync(stageDir, { recursive: true });
for (const name of ["reference", "examples"]) {
cpSync(join(repoRoot, name), join(stageDir, name), { recursive: true });
}
cpSync(join(repoRoot, "docs"), stageDir, {
recursive: true,
filter: (path) => !path.endsWith(".DS_Store") && !path.endsWith(".gitkeep"),
});
console.log(`stage-docs: staged docs at ${stageDir}`);
console.log(`stage-docs: staged the docs at ${stageDir}`);

View File

@ -0,0 +1,85 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Stages the main process's external dependencies into apps/desktop/runtime
// so electron-forge can ship them as an app resource (Contents/Resources/
// runtime). A packaged app has no node_modules of its own: everything else
// is bundled into dist/main.js, but esbuild (native binary) and the babel
// toolchain stay external and are loaded from here at run time (see `load`
// in src/projects.ts). The staged layout:
// runtime/package.json the externals, pinned to the workspace's versions
// runtime/node_modules a fresh `npm install --omit=dev` of them
//
// The list of externals is read from the build:main script so that it cannot
// drift from what the bundle actually leaves unresolved.
import { execFileSync } from "node:child_process";
import { createRequire } from "node:module";
import { existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, closeSync, rmSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { npm } from "../../../scripts/lib/npm.mjs";
const desktopDir = join(dirname(fileURLToPath(import.meta.url)), "..");
const stageDir = join(desktopDir, "runtime");
const require = createRequire(join(desktopDir, "package.json"));
const pkg = JSON.parse(readFileSync(join(desktopDir, "package.json"), "utf8"));
const externals = [...pkg.scripts["build:main"].matchAll(/--external:(\S+)/g)]
.map((match) => match[1])
// Electron is provided by the host binary, not installed.
.filter((name) => name !== "electron");
// Pin what the workspace has installed (and was tested against), not the
// ranges in package.json.
const dependencies = Object.fromEntries(
externals.map((name) => [name, require(`${name}/package.json`).version]),
);
rmSync(stageDir, { recursive: true, force: true });
mkdirSync(stageDir, { recursive: true });
writeFileSync(
join(stageDir, "package.json"),
JSON.stringify({ name: "desktop-runtime", private: true, dependencies }, null, 2),
);
npm(["install", "--omit=dev", "--no-audit", "--no-fund", "--no-package-lock"], { cwd: stageDir });
// Mach-O files inside Resources are not reached by the app-bundle signing
// pass, and notarization rejects unsigned executables; sign them here.
// esbuild's postinstall hard-links the native binary over its bin/esbuild
// shim, so the same executable can sit in two places.
const MACHO_MAGIC = new Set([0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xcafebabe]);
function isMachO(path) {
const fd = openSync(path, "r");
try {
const header = Buffer.alloc(4);
return readSync(fd, header, 0, 4, 0) === 4 && MACHO_MAGIC.has(header.readUInt32BE(0));
} finally {
closeSync(fd);
}
}
const esbuildDir = join(stageDir, "node_modules", "@esbuild");
const binaries = [
join(stageDir, "node_modules", "esbuild", "bin", "esbuild"),
...(existsSync(esbuildDir) ? readdirSync(esbuildDir).map((name) => join(esbuildDir, name, "bin", "esbuild")) : []),
].filter((path) => existsSync(path) && isMachO(path));
if (process.platform === "darwin" && !process.env.SKIP_SIGN) {
const identities = execFileSync("security", ["find-identity", "-v", "-p", "codesigning"], { encoding: "utf8" });
const identity = identities.match(/"(Developer ID Application: [^"]+)"/)?.[1];
if (identity) {
for (const bin of binaries) {
execFileSync("codesign", ["--force", "--options", "runtime", "--timestamp", "--sign", identity, bin], {
stdio: "inherit",
});
}
} else {
console.warn("stage-runtime: no Developer ID identity found, leaving esbuild binaries unsigned");
}
}
console.log(`stage-runtime: staged ${externals.join(", ")} at ${stageDir}`);

View File

@ -1,51 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Stages the agent skills into apps/desktop/skills so electron-forge can ship
// them as an app resource (Contents/Resources/skills). The app symlinks agent
// skill directories at these staged copies (see src/skills-install.ts), so
// auto-updates keep installed skills in lockstep with the dapi they document.
//
// Prefers a sibling checkout of diffusionstudio/skills next to the repo root
// (the dev setup); falls back to a shallow clone (CI).
import { execFileSync } from "node:child_process";
import { cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const SKILLS_REPO = "https://github.com/diffusionstudio/skills.git";
const desktopDir = join(dirname(fileURLToPath(import.meta.url)), "..");
const repoRoot = join(desktopDir, "..", "..");
const stageDir = join(desktopDir, "skills");
const sibling = join(repoRoot, "..", "skills");
let sourceDir = sibling;
let tempDir = null;
if (!existsSync(join(sibling, "editor", "SKILL.md"))) {
tempDir = mkdtempSync(join(tmpdir(), "stage-skills-"));
execFileSync("git", ["clone", "--depth", "1", SKILLS_REPO, tempDir], { stdio: "inherit" });
sourceDir = tempDir;
}
// A skill is a top-level directory with a SKILL.md.
const skills = readdirSync(sourceDir, { withFileTypes: true })
.filter((e) => e.isDirectory() && !e.name.startsWith("."))
.filter((e) => existsSync(join(sourceDir, e.name, "SKILL.md")))
.map((e) => e.name);
if (skills.length === 0) {
throw new Error(`stage-skills: no skills found in ${sourceDir}`);
}
rmSync(stageDir, { recursive: true, force: true });
mkdirSync(stageDir, { recursive: true });
for (const name of skills) {
cpSync(join(sourceDir, name), join(stageDir, name), { recursive: true });
}
if (tempDir) rmSync(tempDir, { recursive: true, force: true });
console.log(`stage-skills: staged ${skills.join(", ")} at ${stageDir}`);

View File

@ -0,0 +1,15 @@
#!/bin/sh
# Regenerates the Windows tray menu icons: assets/tray/menu/<name>.svg ->
# <name>.png (16px) and <name>@2x.png (32px). Black on transparent; the app
# recolors them to match the menu's light or dark theme. macOS uses SF
# Symbols instead and does not need these.
#
# Needs rsvg-convert (brew install librsvg).
set -e
cd "$(dirname "$0")/../assets/tray/menu"
for svg in *.svg; do
name="${svg%.svg}"
rsvg-convert -w 16 -h 16 "$svg" -o "$name.png"
rsvg-convert -w 32 -h 32 "$svg" -o "$name@2x.png"
done

View File

@ -0,0 +1,178 @@
#!/usr/bin/env python3
# Regenerates the Windows-only assets:
#
# python3 scripts/win-assets.py ico -> assets/icon.ico
# python3 scripts/win-assets.py spinner -> assets/install-spinner.gif
# python3 scripts/win-assets.py -> both
#
# Source is assets/icon-win.png (1024x1024). Unlike the macOS icon it fills
# the canvas with no margin and no drop shadow, which is what Windows expects.
#
# Needs Pillow (pip install pillow) and, for the spinner, Geist Medium; set
# WIN_ASSETS_FONT to its path if it is not in ~/Library/Fonts.
#
# icon.ico carries every size Windows asks for at 100-200% scaling. 40px and
# up are Lanczos downscales of the source; 32px and below are drawn from
# scratch (flat red rounded square, white hexagon ring) because a downscaled
# glossy icon turns to mush at taskbar size. All entries are 32-bit BGRA with
# an alpha channel; the 256px one is PNG-compressed as Vista+ allows.
#
# install-spinner.gif is Squirrel's whole install UI: shown 1:1 in a
# borderless window until the app launches. White background, icon,
# one label, one indeterminate bar in the app's primary blue.
import io
import math
import os
import struct
import sys
from PIL import Image, ImageDraw, ImageFilter, ImageFont
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
ASSETS = os.path.join(ROOT, 'assets')
SOURCE = os.path.join(ASSETS, 'icon-win.png')
RED = (255, 25, 52)
BLUE = (0, 140, 255) # --primary in apps/web/src/index.css, hsla(207, 100%, 50%)
WHITE = (255, 255, 255)
BACKGROUND = (255, 255, 255)
TEXT = (22, 22, 24)
TRACK = (224, 224, 224)
def source():
im = Image.open(SOURCE).convert('RGBA')
if im.size != (1024, 1024):
sys.exit(f'{SOURCE} must be 1024x1024, got {im.size}')
return im
# --- icon.ico ---------------------------------------------------------------
ICO_SIZES = [256, 128, 96, 64, 48, 40, 32, 24, 20, 16]
def drawn_frame(size):
ss = 16
w = size * ss
im = Image.new('RGBA', (w, w), (0, 0, 0, 0))
d = ImageDraw.Draw(im)
d.rounded_rectangle((0, 0, w - 1, w - 1), radius=0.22 * size * ss, fill=RED + (255,))
stroke = max(2, round(0.10 * size * 2) / 2) * ss
radius = (0.38 * size - stroke / ss / 2) * ss
c = w / 2
pts = [
(c + radius * math.sin(math.radians(60 * i)), c - radius * math.cos(math.radians(60 * i)))
for i in range(6)
]
d.line(pts + [pts[0], pts[1]], fill=WHITE + (255,), width=int(stroke), joint='curve')
for x, y in pts:
d.ellipse((x - stroke / 2, y - stroke / 2, x + stroke / 2, y + stroke / 2), fill=WHITE + (255,))
return im.resize((size, size), Image.LANCZOS)
def scaled_frame(src, size):
im = src.resize((size, size), Image.LANCZOS)
if size <= 128:
im = im.filter(ImageFilter.UnsharpMask(radius=0.6, percent=50, threshold=0))
return im
def dib(im):
w, h = im.size
px = im.load()
rows = b''.join(
bytes(b for x in range(w) for b in (px[x, y][2], px[x, y][1], px[x, y][0], px[x, y][3]))
for y in range(h - 1, -1, -1)
)
stride = ((w + 31) // 32) * 4
mask = bytes(stride * h) # AND mask all-visible; alpha carries transparency
header = struct.pack('<IiiHHIIiiII', 40, w, h * 2, 1, 32, 0, len(rows) + len(mask), 2835, 2835, 0, 0)
return header + rows + mask
def make_ico():
src = source()
blobs = []
for size in ICO_SIZES:
frame = drawn_frame(size) if size <= 32 else scaled_frame(src, size)
if size == 256:
buf = io.BytesIO()
frame.save(buf, 'PNG', optimize=True)
blobs.append(buf.getvalue())
else:
blobs.append(dib(frame))
out = struct.pack('<HHH', 0, 1, len(ICO_SIZES))
offset = 6 + 16 * len(ICO_SIZES)
entries = b''
for size, blob in zip(ICO_SIZES, blobs):
entries += struct.pack('<BBBBHHII', size % 256, size % 256, 0, 0, 1, 32, len(blob), offset)
offset += len(blob)
path = os.path.join(ASSETS, 'icon.ico')
with open(path, 'wb') as f:
f.write(out + entries + b''.join(blobs))
print(f'wrote {os.path.relpath(path, ROOT)}')
# --- install-spinner.gif ----------------------------------------------------
W, H = 440, 280
FPS, SECONDS = 20, 2.4
LABEL = 'Installing Diffusion Studio'
def font():
path = os.environ.get('WIN_ASSETS_FONT') or os.path.expanduser('~/Library/Fonts/Geist-Medium.ttf')
if not os.path.exists(path):
sys.exit(f'Geist Medium not found at {path}; set WIN_ASSETS_FONT')
return ImageFont.truetype(path, 15)
def make_spinner():
icon = source().resize((88, 88), Image.LANCZOS)
label_font = font()
n = int(FPS * SECONDS)
track_w, track_h, bar_w = 200, 4, 70
tx, ty = (W - track_w) // 2, 214
frames = []
for i in range(n):
im = Image.new('RGB', (W, H), BACKGROUND)
d = ImageDraw.Draw(im)
im.paste(icon, ((W - 88) // 2, 58), icon)
tw = d.textlength(LABEL, font=label_font)
d.text((round((W - tw) / 2), 166), LABEL, font=label_font, fill=TEXT)
d.rounded_rectangle((tx, ty, tx + track_w, ty + track_h), radius=2, fill=TRACK)
p = 0.5 - 0.5 * math.cos(math.pi * i / n) # ease in-out, one sweep per loop
x0 = tx - bar_w + p * (track_w + bar_w)
a, b = max(tx, x0), min(tx + track_w, x0 + bar_w)
if b - a >= 6:
d.rounded_rectangle((a, ty, b, ty + track_h), radius=2, fill=BLUE)
frames.append(im)
# One shared palette so nothing flickers between frames, taken from a
# mid-loop frame where the bar is fully on the track so its colour is kept.
palette = frames[n // 2].quantize(colors=128, method=Image.Quantize.MEDIANCUT)
quantized = [f.quantize(palette=palette, dither=Image.Dither.NONE) for f in frames]
# Median cut averages the background with the icon's antialiased fringe;
# pin the slot every background pixel landed in to the exact colour.
for q in quantized:
entries = list(q.getpalette())
slot = q.getpixel((0, 0))
entries[slot * 3:slot * 3 + 3] = BACKGROUND
q.putpalette(entries)
path = os.path.join(ASSETS, 'install-spinner.gif')
quantized[0].save(
path,
save_all=True,
append_images=quantized[1:],
duration=int(1000 / FPS),
loop=0,
optimize=False,
)
print(f'wrote {os.path.relpath(path, ROOT)}')
if __name__ == '__main__':
what = sys.argv[1:] or ['ico', 'spinner']
for target in what:
{'ico': make_ico, 'spinner': make_spinner}[target]()

View File

@ -0,0 +1,131 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { app, utilityProcess } from "electron";
import { randomBytes } from "node:crypto";
import { join } from "node:path";
import type { UtilityProcess } from "electron";
type AgentChatOptions = { dataDir: string; mcpUrl: string | null; version: string };
const DEV_ORIGIN = "http://localhost:5173";
const RESTART_DELAYS_MS = [1000, 2000, 5000, 10_000];
const STOP_GRACE_MS = 3000;
// How long an ask for the endpoint waits for a host it had to start.
const START_WAIT_MS = 10_000;
let child: UtilityProcess | null = null;
let endpoint: { url: string } | null = null;
let options: AgentChatOptions | null = null;
let token = "";
let restarts = 0;
let restartTimer: ReturnType<typeof setTimeout> | null = null;
let stopped = false;
const waiting = new Set<() => void>();
function spawn(): void {
if (!options || stopped) return;
const path = join(app.getAppPath(), "dist", "agent-host.mjs");
const proc = utilityProcess.fork(path, [], { serviceName: "Agent Chat", stdio: "inherit" });
child = proc;
proc.on("spawn", () => {
proc.postMessage({
type: "start",
config: {
token,
dataDir: options!.dataDir,
mcp: options!.mcpUrl ? { name: "diffusion", url: options!.mcpUrl } : null,
version: options!.version,
allowedOrigins: app.isPackaged ? ["file://", "null"] : ["file://", "null", DEV_ORIGIN],
},
});
});
proc.on("message", (message: { type?: string; url?: string; message?: string }) => {
if (message?.type === "listening" && typeof message.url === "string") {
endpoint = { url: message.url };
restarts = 0;
for (const wake of [...waiting]) {
wake();
}
console.log(`[agent-chat] host listening at ${message.url.replace(/token=.*$/, "token=…")}`);
} else if (message?.type === "error") {
console.error(`[agent-chat] host failed to start: ${message.message}`);
}
});
proc.on("exit", (code) => {
if (child !== proc) return;
child = null;
endpoint = null;
if (stopped) return;
const delay = RESTART_DELAYS_MS[Math.min(restarts, RESTART_DELAYS_MS.length - 1)]!;
restarts += 1;
console.error(`[agent-chat] host exited (${code}); restarting in ${delay} ms`);
restartTimer = setTimeout(() => {
restartTimer = null;
spawn();
}, delay);
});
}
/** Generates the token; the host is forked when it is first needed. Call once, after `whenReady`. */
export function configureAgentChat(next: AgentChatOptions): void {
options = next;
token = randomBytes(32).toString("base64url");
stopped = false;
restarts = 0;
}
/** Where the host is listening, starting it when it is not running; null when it does not come up in time. */
export function agentChatEndpoint(): Promise<{ url: string } | null> {
if (endpoint || stopped || !options) {
return Promise.resolve(endpoint);
}
// Not running and not about to restart: this is the first ask.
if (!child && !restartTimer) {
spawn();
}
return new Promise((resolve) => {
const wake = () => {
clearTimeout(timer);
waiting.delete(wake);
resolve(endpoint);
};
const timer = setTimeout(wake, START_WAIT_MS);
waiting.add(wake);
});
}
/** Best effort: a host that does not come up leaves the chats behind. They aren't trashed with the folder. */
export async function deleteProjectChats(projectId: string): Promise<void> {
if (!projectId) return;
const running = await agentChatEndpoint();
if (running) {
child?.postMessage({ type: "deleteProject", projectId });
}
}
/** Asks the host to stop (it kills its harness trees), then kills it after a grace period. */
export function stopAgentChat(): void {
stopped = true;
if (restartTimer) clearTimeout(restartTimer);
restartTimer = null;
const proc = child;
child = null;
endpoint = null;
if (!proc) return;
try {
proc.postMessage({ type: "stop" });
} catch {
// Already gone.
}
const timer = setTimeout(() => proc.kill(), STOP_GRACE_MS);
proc.once("exit", () => clearTimeout(timer));
}

View File

@ -3,69 +3,107 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { app } from "electron";
import { randomUUID } from "node:crypto";
import { join } from "node:path";
import { access, writeFile } from "node:fs/promises";
import { stat, writeFile } from "node:fs/promises";
import type { ClientEventName, TrackedEvent, TrackProps } from "@diffusionstudio/api-contract";
import type { WindowHost } from "./window-host";
const enabled = app.isPackaged || process.env.DIFFUSION_ANALYTICS === "1";
const FLUSH_INTERVAL_MS = 30_000;
const BATCH_MAX = 100;
const QUEUE_MAX = 2_000;
const queue: TrackedEvent[] = [];
let apiUrl: string | null = null;
let token: string | null | undefined;
/** Canvas edits by kind, and source files changed from outside the app, since the last flush. */
let canvasEdits: Record<string, number> = {};
let changedFiles = new Set<string>();
export function configureAnalytics(config: { apiUrl: string; token: string | null }): void {
apiUrl = config.apiUrl;
token = config.token;
}
export function track(name: ClientEventName, props: TrackProps = {}): void {
if (!enabled) return;
// Undefined values would fail validation; JSON leaves them out.
queue.push({
id: randomUUID(),
at: new Date().toISOString(),
name,
props: JSON.parse(JSON.stringify(props)),
});
if (queue.length > QUEUE_MAX) {
queue.splice(0, queue.length - QUEUE_MAX);
}
}
/** Edits the canvas wrote back to the source (move, insert, remove, …). */
export function countCanvasEdits(kinds: string[]): void {
for (const kind of kinds) {
canvasEdits[kind] = (canvasEdits[kind] ?? 0) + 1;
}
}
/** A source file changed from outside the app: an agent or an editor writing code. */
export function countCodeChange(path: string): void {
changedFiles.add(path);
}
/**
* Install tracking, proxied by the first launch of a packaged build. The
* renderer's Umami script never fires inside Electron (its `data-domains`
* gate does not match the `file://` origin), so main posts one event
* directly to Umami's send API and drops a marker file in `userData` to
* never send it again. Offline first launches retry on the next launch.
* Starts the flush and usage timers and records the launch. The first launch of an
* install is recorded once, guarded by a marker file in `userData`; its age
* goes on every `app_opened`, so install-to-sign-up time needs no device id.
*/
export async function startAnalytics(windows: WindowHost): Promise<void> {
if (!enabled) return;
const UMAMI_ENDPOINT = "https://cloud.umami.is/api/send";
const UMAMI_WEBSITE_ID = "e898e381-6ce3-4f5f-a485-8327ec9aa88b";
const HOSTNAME = "desktop.diffusion.studio";
const MARKER_FILE = "install-tracked";
setInterval(flush, FLUSH_INTERVAL_MS);
setInterval(() => (windows.current() && track("app_used")), 60_000);
// Umami discards events whose User-Agent trips its bot filter, which both
// Node's fetch default and Electron's own UA do — send a plain browser UA
// that still attributes the right OS.
function userAgent(): string {
const platform =
process.platform === "darwin"
? "Macintosh; Intel Mac OS X 10_15_7"
: process.platform === "win32"
? "Windows NT 10.0; Win64; x64"
: "X11; Linux x86_64";
return `Mozilla/5.0 (${platform}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36`;
}
const marker = join(app.getPath("userData"), "install-tracked");
const installedAt = await stat(marker).then((info) => info.birthtimeMs, () => null);
export async function trackInstall(): Promise<void> {
if (!app.isPackaged) return;
const marker = join(app.getPath("userData"), MARKER_FILE);
try {
await access(marker);
return;
} catch {
// No marker yet — this is the first (tracked) launch.
if (installedAt === null) {
track("app_installed", { arch: process.arch });
await writeFile(marker, new Date().toISOString()).catch(() => { });
}
track("app_opened", { install_age_s: Math.round((Date.now() - (installedAt ?? Date.now())) / 1000) });
}
async function flush(): Promise<void> {
const edits = Object.values(canvasEdits).reduce((sum, n) => sum + n, 0);
if (edits) {
track("canvas_edited", { edits, ...canvasEdits });
}
if (changedFiles.size) {
track("code_changed", { files: changedFiles.size });
}
canvasEdits = {};
changedFiles = new Set();
if (!queue.length || !apiUrl || token === undefined) return;
const batch = queue.splice(0, BATCH_MAX);
try {
const response = await fetch(UMAMI_ENDPOINT, {
const response = await fetch(`${apiUrl}/api/v2/trpc/events.track`, {
method: "POST",
headers: { "Content-Type": "application/json", "User-Agent": userAgent() },
body: JSON.stringify({
type: "event",
payload: {
website: UMAMI_WEBSITE_ID,
hostname: HOSTNAME,
url: "/desktop/install",
name: "desktop_install",
data: {
platform: process.platform,
arch: process.arch,
version: app.getVersion(),
},
},
}),
headers: { "Content-Type": "application/json", ...(token ? { Authorization: `Bearer ${token}` } : {}) },
body: JSON.stringify({ source: "desktop", appVersion: app.getVersion(), platform: process.platform, events: batch }),
signal: AbortSignal.timeout(10_000),
});
if (response.ok) {
await writeFile(marker, new Date().toISOString());
}
// Sent, or a batch the API will never take (400): either way it is done.
if (response.ok || response.status === 400) return;
} catch {
// Offline or Umami unreachable — retried on the next launch.
// Offline or the API unreachable.
}
queue.unshift(...batch);
}

View File

@ -0,0 +1,49 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Writes that land whole. Anything may be reading a project's files while the
// app writes them — a compile, the user's editor, the watcher reading a file
// back to see whether it really changed — and a reader that catches a file
// halfway through a write sees source no one wrote. So a write goes to a temp
// file beside its target and is renamed over it, which the filesystem does in
// one step.
import { rename, unlink, writeFile } from "node:fs/promises";
import { basename, dirname, join } from "node:path";
/**
* The prefix every temp file the app writes carries. Recognisable rather than
* unique, so the project watcher can ignore the whole class of them without
* anyone having to declare each one as it is written.
*/
export const TEMP_PREFIX = ".dstmp-";
/** Whether `path` — of any form — names one of our temp files. */
export const isTempPath = (path: string): boolean => basename(path).startsWith(TEMP_PREFIX);
let sequence = 0;
/**
* A free path beside `path` to write at until the content is whole. Beside it
* rather than in the system's temp folder, because a rename is only atomic
* within a filesystem.
*/
export function tempPathFor(path: string): string {
return join(dirname(path), `${TEMP_PREFIX}${basename(path)}.${process.pid}-${++sequence}`);
}
/**
* Writes `text` to `path` as one step: a temp file beside it, renamed over it.
* A failed write takes its temp file with it.
*/
export async function writeFileAtomic(path: string, text: string): Promise<void> {
const temp = tempPathFor(path);
try {
await writeFile(temp, text, "utf8");
await rename(temp, path);
} catch (error) {
await unlink(temp).catch(() => { });
throw error;
}
}

View File

@ -2,46 +2,175 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { app } from "electron";
import { execFile } from "node:child_process";
import { existsSync } from "node:fs";
import { existsSync, lstatSync, unlinkSync } from "node:fs";
import { join } from "node:path";
import type { CliInstallResult } from "./main-channels";
import { addShimToPath, removeShimFromPath, shimOnPath, shimPath, writeShim } from "./cli-windows";
export const CLI_LINK_PATH = "/usr/local/bin/dapi";
import type { CliInstallResult, CliStatus, CliUninstallResult } from "./main-channels";
export const CLI_LINK_DIR = "/usr/local/bin";
// The dev workflow links the workspace build into Homebrew's bin instead
// (`symlink:create` in apps/cli), so both locations count as installed.
const DEV_LINK_PATH = "/opt/homebrew/bin/dapi";
// (`npm run link` in apps/cli), so that location counts as installed too.
const DEV_LINK_DIR = "/opt/homebrew/bin";
export function isCliInstalled(): boolean {
return existsSync(CLI_LINK_PATH) || existsSync(DEV_LINK_PATH);
// `diffusion` is what we point to first when reporting status; `dapi` rides
// alongside it as an alias, and is also what an install from before this
// pair existed left behind.
const LINK_NAMES = ["diffusion", "dapi"] as const;
const linkPaths = (dir: string): string[] => LINK_NAMES.map((name) => `${dir}/${name}`);
/**
* Whether `path` is a symlink — dangling or not, since a link left behind
* by a deleted bundle is exactly what removal is for. `existsSync` follows
* links and would miss that case.
*/
function isLink(path: string): boolean {
return lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink() ?? false;
}
// Linking into /usr/local/bin needs elevation; osascript shows the standard
// macOS admin prompt so the app itself never asks for credentials.
function linkCli(): Promise<void> {
const wrapper = join(process.resourcesPath, "cli", "bin", "dapi");
const shell = `mkdir -p /usr/local/bin && ln -sf '${wrapper}' '${CLI_LINK_PATH}'`;
/** The first of the two locations that holds any of our links, or null. */
function installedDir(): string | null {
for (const dir of [CLI_LINK_DIR, DEV_LINK_DIR]) {
if (linkPaths(dir).some((path) => isLink(path) || existsSync(path))) {
return dir;
}
}
return null;
}
/**
* Rewrites the Windows shim so it names this executable. Runs on every
* packaged launch, because an update moved the app to a new folder; the
* agents' MCP entries point at the shim whether or not it is on PATH.
*/
export function refreshCliShim(): void {
if (process.platform !== "win32" || !app.isPackaged) return;
writeShim().catch((e) => console.error("cli shim: could not write", e));
}
async function cliStatusWin32(): Promise<CliStatus> {
const installed = await shimOnPath().catch(() => false);
if (installed) {
return { installed: true, path: shimPath(), managed: true, available: true };
}
return { installed: false, path: null, managed: false, available: app.isPackaged };
}
async function cliStatusDarwin(): Promise<CliStatus> {
const dir = installedDir();
if (dir) {
const path = linkPaths(dir).find((candidate) => isLink(candidate) || existsSync(candidate))!;
return { installed: true, path, managed: isLink(path), available: true };
}
return { installed: false, path: null, managed: false, available: app.isPackaged };
}
/** Where `diffusion` (or its `dapi` alias) stands on this machine, without asking for a password. */
export async function cliStatus(): Promise<CliStatus> {
if (process.platform === "win32") return cliStatusWin32();
if (process.platform === "darwin") return cliStatusDarwin();
return { installed: false, path: null, managed: false, available: false };
}
// The standard macOS admin prompt, for the one shell line that needs it.
function elevated(shell: string): Promise<void> {
const script = `do shell script "${shell.replaceAll('"', '\\"')}" with administrator privileges`;
return new Promise((resolve, reject) => {
execFile("osascript", ["-e", script], (err) => (err ? reject(err) : resolve()));
});
}
/** osascript error -128: the user dismissed the prompt. Not an error, not done. */
const cancelled = (e: unknown): boolean => ((e as Error).message ?? "").includes("-128");
async function installCliDarwin(): Promise<CliInstallResult> {
const wrapper = join(process.resourcesPath, "cli", "bin", "dapi");
const links = linkPaths(CLI_LINK_DIR).map((path) => `ln -sf '${wrapper}' '${path}'`).join(" && ");
try {
await elevated(`mkdir -p ${CLI_LINK_DIR} && ${links}`);
return { status: "installed" };
} catch (e) {
return cancelled(e) ? { status: "cancelled" } : { status: "error", error: (e as Error).message };
}
}
async function installCliWin32(): Promise<CliInstallResult> {
try {
await writeShim();
await addShimToPath();
return { status: "installed" };
} catch (e) {
return { status: "error", error: (e as Error).message };
}
}
export async function installCli(): Promise<CliInstallResult> {
if (!app.isPackaged) {
return {
status: "error",
error: "Installing the CLI is only available in the packaged app. Use `npm run symlink:create` in development.",
error: `Installing the CLI is only available in the packaged app. Use \`npm run link\` in apps/cli in development.`,
};
}
if (process.platform === "win32") return installCliWin32();
if (process.platform === "darwin") return installCliDarwin();
return {
status: "error",
error: `Installing the CLI is only available on Windows and macOS.`,
};
}
async function uninstallCliWin32(): Promise<CliUninstallResult> {
try {
await linkCli();
return { status: "installed" };
if (!(await shimOnPath())) return { status: "absent" };
await removeShimFromPath();
return { status: "removed" };
} catch (e) {
const message = (e as Error).message ?? "";
if (message.includes("-128")) return { status: "cancelled" }; // user cancelled the admin prompt
return { status: "error", error: message };
return { status: "error", error: (e as Error).message };
}
}
async function uninstallCliDarwin(): Promise<CliUninstallResult> {
const dir = installedDir();
if (!dir) return { status: "absent" };
const present = linkPaths(dir).filter((path) => isLink(path) || existsSync(path));
const notLinks = present.filter((path) => !isLink(path));
if (notLinks.length > 0) {
const is = notLinks.length > 1 ? "are not links" : "is not a link";
return { status: "error", error: `${notLinks.join(", ")} ${is}, so nothing was removed.` };
}
try {
for (const path of present) unlinkSync(path);
return { status: "removed" };
} catch (e) {
const code = (e as NodeJS.ErrnoException).code;
if (code !== "EACCES" && code !== "EPERM") return { status: "error", error: (e as Error).message };
}
try {
await elevated(`rm -f ${present.map((path) => `'${path}'`).join(" ")}`);
return { status: "removed" };
} catch (e) {
return cancelled(e) ? { status: "cancelled" } : { status: "error", error: (e as Error).message };
}
}
/**
* Takes the `diffusion`/`dapi` links off PATH, whichever of the two
* locations holds them.
*/
export async function uninstallCli(): Promise<CliUninstallResult> {
if (process.platform === "win32") return uninstallCliWin32();
if (process.platform === "darwin") return uninstallCliDarwin();
return {
status: "error",
error: `Uninstalling the CLI is only available on Windows and macOS.`,
};
}

View File

@ -1,160 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { existsSync, unlinkSync } from "node:fs";
import { createServer } from "node:net";
import type { Server, Socket } from "node:net";
import { app, BrowserWindow } from "electron";
import { CLI_WIRE, SOCKET_PATH } from "@diffusionstudio/cli/protocol";
import type { CliHandshake, CliHandshakeReply } from "@diffusionstudio/cli/protocol";
import { mainBridge } from "./main-manager";
import { MAIN_CHANNELS } from "./main-channels";
let cliServer: Server | null = null;
let currentWindow: BrowserWindow | null = null;
let headless = false;
let windowLifecycleBound = false;
export function isHeadless(): boolean {
return headless;
}
function enableHeadless(): void {
if (headless) return;
headless = true;
if (currentWindow && !currentWindow.isDestroyed()) {
mainBridge.emit(currentWindow, MAIN_CHANNELS.HEADLESS_MODE, { active: true });
}
}
// Resolves once the current window has finished loading.
function waitForRendererReady(timeoutMs = 30000): Promise<void> {
if (!currentWindow || currentWindow.isDestroyed()) {
return Promise.reject(new Error("No window"));
}
if (currentWindow.webContents.isCrashed()) {
return Promise.reject(new Error("Renderer crashed"));
}
if (!currentWindow.webContents.isLoading()) {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
console.warn(`[cli-server] renderer not ready after ${timeoutMs}ms`);
reject(new Error("App did not become ready in time"));
}, timeoutMs);
const cleanup = () => {
clearTimeout(timer);
currentWindow?.webContents.off("did-finish-load", onLoad);
currentWindow?.webContents.off("did-fail-load", onFail);
};
const onLoad = () => {
cleanup();
resolve();
};
const onFail = () => {
cleanup();
reject(new Error(`Renderer failed to load`));
};
currentWindow?.webContents.on("did-finish-load", onLoad);
currentWindow?.webContents.on("did-fail-load", onFail);
});
}
function bindWindowLifecycle(): void {
if (windowLifecycleBound) return;
windowLifecycleBound = true;
app.on("browser-window-created", (_event, window) => {
currentWindow = window;
window.on("closed", () => {
if (currentWindow === window) currentWindow = null;
});
});
// Catch any window that was created before the server started.
const windows = BrowserWindow.getAllWindows();
if (windows.length > 0) currentWindow = windows[windows.length - 1]!;
}
// Relays the CLI's connect info to the renderer, which dials the CLI's
// WebSocket server directly. The reply confirms delivery only; from there
// the request/response traffic bypasses main entirely.
async function deliverHandshake(handshake: CliHandshake, sock: Socket): Promise<void> {
let reply: CliHandshakeReply;
try {
await waitForRendererReady();
if (!currentWindow || currentWindow.isDestroyed()) {
throw new Error("No window");
}
currentWindow.webContents.send(CLI_WIRE.CONNECT, handshake);
reply = { ok: true };
} catch (err) {
reply = { ok: false, error: (err as Error).message };
}
if (!sock.destroyed) sock.end(JSON.stringify(reply));
}
export function startCliServer() {
cleanupStaleSocket();
bindWindowLifecycle();
cliServer = createServer({ allowHalfOpen: true }, (sock: Socket) => {
enableHeadless();
let buf = "";
sock.setEncoding("utf8");
sock.setTimeout(60000, () => sock.destroy());
sock.on("data", (chunk) => {
buf += chunk;
});
sock.on("end", async () => {
sock.setTimeout(0);
let handshake: CliHandshake;
try {
handshake = JSON.parse(buf) as CliHandshake;
if (typeof handshake.port !== "number" || typeof handshake.token !== "string") {
throw new Error("Malformed handshake");
}
} catch {
sock.end(JSON.stringify({ ok: false, error: "Invalid handshake" }));
return;
}
await deliverHandshake(handshake, sock);
});
sock.on("error", () => {
// Client hung up; nothing to do.
});
});
cliServer.on("error", (err) => {
console.error("CLI server error:", err);
});
cliServer.listen(SOCKET_PATH);
}
export function stopCliServer() {
if (!cliServer) return;
cliServer.close();
cliServer = null;
cleanupStaleSocket();
}
/**
* Clean up a stale socket file (Unix). Safe because the single-instance lock
* guarantees no other instance of ours is running.
*/
function cleanupStaleSocket() {
try {
if (process.platform !== "win32" && existsSync(SOCKET_PATH)) {
unlinkSync(SOCKET_PATH);
}
} catch {
// Best-effort.
}
}

View File

@ -0,0 +1,57 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// The parts of the Windows CLI install that are decisions rather than system
// calls: where the shim lives, what it says, and how the user's PATH is
// edited without disturbing the entries around ours.
import { describe, expect, it } from "vitest";
import { pathHas, pathWith, pathWithout, shimContent, shimDir, shimPath, stagedScript } from "./cli-windows";
const local = "C:\\Users\\me\\AppData\\Local";
const exe = `${local}\\DiffusionStudio\\app-1.2.0\\Diffusion Studio.exe`;
const dir = `${local}\\DiffusionStudio\\bin`;
describe("shim", () => {
it("lives outside the versioned app folder", () => {
expect(shimDir({ LOCALAPPDATA: local })).toBe(dir);
expect(shimPath({ LOCALAPPDATA: local })).toBe(`${dir}\\dapi.cmd`);
});
it("runs the staged CLI on the app's executable in Node mode", () => {
expect(stagedScript(exe)).toBe(`${local}\\DiffusionStudio\\app-1.2.0\\resources\\cli\\dapi.js`);
expect(shimContent(exe).split("\r\n")).toEqual([
"@echo off",
"setlocal",
'set "ELECTRON_RUN_AS_NODE=1"',
`"${exe}" "${stagedScript(exe)}" %*`,
"",
]);
});
it("escapes percent signs, which batch files would expand", () => {
expect(shimContent("C:\\Users\\100%me\\app.exe", "C:\\x\\dapi.js")).toContain('"C:\\Users\\100%%me\\app.exe"');
});
});
describe("user PATH", () => {
const path = "%USERPROFILE%\\.cargo\\bin;C:\\Tools";
it("appends the folder once, leaving other entries as written", () => {
expect(pathWith(path, dir)).toBe(`${path};${dir}`);
expect(pathWith(`${path};${dir}`, dir)).toBe(`${path};${dir}`);
expect(pathWith("", dir)).toBe(dir);
});
it("matches without case and trailing separators", () => {
expect(pathHas(`${path};${dir.toUpperCase()}\\`, dir)).toBe(true);
expect(pathHas(path, dir)).toBe(false);
});
it("removes every spelling of the folder and nothing else", () => {
expect(pathWithout(`${dir}\;${path};${dir.toLowerCase()}`, dir)).toBe(path);
expect(pathWithout(path, dir)).toBe(path);
});
});

View File

@ -0,0 +1,151 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// The `diffusion` (and `dapi` alias) commands on Windows. Squirrel installs
// every version into its own `app-<version>` folder, so nothing durable may
// point at the wrapper the app ships in its resources. What goes on PATH
// (and, for `dapi.cmd`, into the agents' MCP configs) is a pair of shims in a
// folder that never moves:
// %LOCALAPPDATA%\DiffusionStudio\bin\dapi.cmd
// %LOCALAPPDATA%\DiffusionStudio\bin\diffusion.cmd
// The app rewrites both on every packaged launch and from Squirrel's update
// hook, so they always name the current executable. Installing the CLI is
// then only a matter of putting that folder on the user's PATH, which needs
// no administrator.
//
// Nothing here imports electron, so the Squirrel hooks can use it before the
// app is ready and the tests can run it anywhere.
import { execFile } from "node:child_process";
import { mkdir, rm } from "node:fs/promises";
import { homedir } from "node:os";
import { win32 } from "node:path";
import { writeFileAtomic } from "./atomic";
/** The folder that holds the shim: the one entry we add to PATH. */
export function shimDir(env: NodeJS.ProcessEnv = process.env): string {
const local = env.LOCALAPPDATA || win32.join(homedir(), "AppData", "Local");
return win32.join(local, "DiffusionStudio", "bin");
}
export function shimPath(env: NodeJS.ProcessEnv = process.env): string {
return win32.join(shimDir(env), "dapi.cmd");
}
// `dapi.cmd` is the one `mcp-install.ts` registers with agents, so its name
// and behavior above stay fixed. `diffusion.cmd` rides beside it purely so
// the name on PATH matches the one in the docs; both run the same script.
export function shimPaths(env: NodeJS.ProcessEnv = process.env): string[] {
return ["dapi.cmd", "diffusion.cmd"].map((name) => win32.join(shimDir(env), name));
}
/** `dapi.js` as the packaged app stages it, next to `execPath`'s resources. */
export function stagedScript(execPath: string): string {
return win32.join(win32.dirname(execPath), "resources", "cli", "dapi.js");
}
// A literal `%` would start a variable expansion inside a batch file.
const batch = (path: string): string => path.replaceAll("%", "%%");
/**
* The shim's text: the CLI bundle on the app's own Electron binary in Node
* mode, like the macOS wrapper, but with both paths spelled out because the
* shim does not live beside them.
*/
export function shimContent(execPath: string, script: string = stagedScript(execPath)): string {
return [
"@echo off",
"setlocal",
'set "ELECTRON_RUN_AS_NODE=1"',
`"${batch(execPath)}" "${batch(script)}" %*`,
"",
].join("\r\n");
}
/** Points the shim at `execPath`. Safe to repeat; the write lands whole. */
export async function writeShim(execPath: string = process.execPath, script?: string): Promise<void> {
await mkdir(shimDir(), { recursive: true });
const content = shimContent(execPath, script);
await Promise.all(shimPaths().map((path) => writeFileAtomic(path, content)));
}
export async function removeShim(): Promise<void> {
await rm(shimDir(), { recursive: true, force: true });
}
// PATH entries compare without case and without a trailing separator.
const normalize = (entry: string): string => entry.trim().replace(/[\\/]+$/, "").toLowerCase();
const entries = (path: string): string[] => path.split(";").filter((entry) => entry.trim() !== "");
export function pathHas(path: string, dir: string): boolean {
return entries(path).some((entry) => normalize(entry) === normalize(dir));
}
/** `path` with `dir` appended, or unchanged when it is already there. */
export function pathWith(path: string, dir: string): string {
return pathHas(path, dir) ? path : [...entries(path), dir].join(";");
}
/** `path` without any spelling of `dir`. */
export function pathWithout(path: string, dir: string): string {
return entries(path)
.filter((entry) => normalize(entry) !== normalize(dir))
.join(";");
}
// The user PATH lives in HKCU\Environment. It is read and written through the
// registry rather than [Environment]::Get/SetEnvironmentVariable, which would
// expand every %VARIABLE% in the entries that are already there and store the
// result as a plain string. `setx` is out too: it truncates at 1024
// characters. Removing a variable that does not exist is the cheap way to
// make .NET broadcast WM_SETTINGCHANGE, so new terminals see the change.
// The value travels through the environment so nothing needs quoting.
const READ_PATH = `
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment')
[Console]::Out.Write($key.GetValue('Path', '', 'DoNotExpandEnvironmentNames'))
`;
const WRITE_PATH = `
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true)
$kind = if ($key.GetValueNames() -contains 'Path') { $key.GetValueKind('Path') } else { 'ExpandString' }
$value = if ($env:DAPI_USER_PATH) { $env:DAPI_USER_PATH } else { '' }
$key.SetValue('Path', $value, $kind)
[Environment]::SetEnvironmentVariable('DAPI_PATH_BROADCAST', $null, 'User')
`;
function powershell(script: string, env: NodeJS.ProcessEnv = {}): Promise<string> {
return new Promise((resolve, reject) => {
execFile(
"powershell.exe",
["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script],
{ env: { ...process.env, ...env }, windowsHide: true },
(err, stdout) => (err ? reject(err) : resolve(stdout)),
);
});
}
export const readUserPath = (): Promise<string> => powershell(READ_PATH);
export async function writeUserPath(path: string): Promise<void> {
await powershell(WRITE_PATH, { DAPI_USER_PATH: path });
}
/** Whether the shim folder is on the user's PATH. */
export async function shimOnPath(): Promise<boolean> {
return pathHas(await readUserPath(), shimDir());
}
export async function addShimToPath(): Promise<void> {
const path = await readUserPath();
const next = pathWith(path, shimDir());
if (next !== path) await writeUserPath(next);
}
export async function removeShimFromPath(): Promise<void> {
const path = await readUserPath();
const next = pathWithout(path, shimDir());
if (next !== path) await writeUserPath(next);
}

View File

@ -0,0 +1,47 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// The files on the system clipboard: what a copy in Finder or Explorer (or
// of a recording in a screenshot app) leaves there. The renderer reads
// pictures itself, but the web clipboard API knows nothing of files, and
// outside a paste event this is the only way to them.
import { clipboard } from "electron";
import { fileURLToPath } from "node:url";
/** The files on the clipboard, by path, in the order they were copied. */
export function clipboardPaths(): string[] {
switch (process.platform) {
case "darwin": {
// Every file of a copy is in the filenames list, a plist of paths; the
// file URL type only holds the first.
const plist = clipboard.read("NSFilenamesPboardType");
const paths = [...plist.matchAll(/<string>([^<]*)<\/string>/g)].map((match) => unescapeXml(match[1]!));
if (paths.length) return paths;
const url = clipboard.read("public.file-url");
return url.startsWith("file:") ? [fileURLToPath(url)] : [];
}
case "win32": {
// Only the first file of a copy: the full list is in CF_HDROP, which
// Electron cannot read.
const path = clipboard.readBuffer("FileNameW").toString("utf16le").split("\0")[0];
return path ? [path] : [];
}
default:
return clipboard
.read("text/uri-list")
.split(/\r?\n/)
.filter((line) => line.startsWith("file:"))
.map((url) => fileURLToPath(url));
}
}
function unescapeXml(text: string): string {
return text
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'")
.replace(/&amp;/g, "&");
}

View File

@ -0,0 +1,49 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { describe, expect, it } from "vitest";
import { dropboxRoots, isUnder, windowsCloudSyncKind } from "./cloud-sync-windows";
const home = "C:\\Users\\me";
describe("isUnder", () => {
it("compares the way Windows does: no case, whole segments", () => {
expect(isUnder("c:\\users\\ME\\OneDrive\\Videos\\clip", "C:\\Users\\me\\OneDrive")).toBe(true);
expect(isUnder("C:\\Users\\me\\OneDrive", "C:\\Users\\me\\OneDrive\\")).toBe(true);
expect(isUnder("C:\\Users\\me\\OneDrive-old\\clip", "C:\\Users\\me\\OneDrive")).toBe(false);
});
});
describe("dropboxRoots", () => {
it("reads every linked account's folder", () => {
const info = JSON.stringify({
personal: { path: "D:\\Dropbox", host: 1 },
business: { path: "D:\\Dropbox (Acme)", host: 2 },
});
expect(dropboxRoots(info)).toEqual(["D:\\Dropbox", "D:\\Dropbox (Acme)"]);
});
it("finds nothing in a file it cannot read", () => {
expect(dropboxRoots("{ not json")).toEqual([]);
expect(dropboxRoots("null")).toEqual([]);
expect(dropboxRoots('{"personal":{}}')).toEqual([]);
});
});
describe("windowsCloudSyncKind", () => {
// No LOCALAPPDATA: nothing is read from disk, only the fixed locations apply.
const env = { OneDrive: "C:\\Users\\me\\OneDrive" };
it("names the service a folder sits under", async () => {
expect(await windowsCloudSyncKind("C:\\Users\\me\\OneDrive\\Projects\\a", home, env)).toBe("OneDrive");
expect(await windowsCloudSyncKind("C:\\Users\\me\\Dropbox\\a", home, env)).toBe("Dropbox");
expect(await windowsCloudSyncKind("C:\\Users\\me\\iCloudDrive\\a", home, env)).toBe("iCloud Drive");
});
it("leaves plain local disk alone", async () => {
expect(await windowsCloudSyncKind("C:\\Users\\me\\Videos\\a", home, env)).toBeNull();
expect(await windowsCloudSyncKind("G:\\My Drive\\a", home, env)).toBeNull();
});
});

View File

@ -0,0 +1,89 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Where the sync services keep their folders on Windows. macOS marks a synced
// folder with a File Provider attribute that can simply be asked for; Windows
// has nothing like it, so each service is found the way it announces itself:
// OneDrive through its environment variables, Dropbox through the info.json
// it writes for exactly this purpose, Google Drive through the streaming
// drive it mounts, iCloud through its fixed folder.
import { access, readFile } from "node:fs/promises";
import { win32 } from "node:path";
/** A folder a service syncs, and the service's name as the warning spells it. */
export type SyncRoot = [dir: string, label: string];
const exists = (path: string): Promise<boolean> => access(path).then(() => true, () => false);
/** Whether `path` is `root` or inside it, the way Windows compares paths: without case. */
export function isUnder(path: string, root: string): boolean {
const child = win32.resolve(path).toLowerCase();
const parent = win32.resolve(root).toLowerCase().replace(/\\+$/, "");
return child === parent || child.startsWith(parent + "\\");
}
/** The folders named in Dropbox's info.json: one per linked account, personal and business. */
export function dropboxRoots(infoJson: string): string[] {
try {
const info: unknown = JSON.parse(infoJson);
if (typeof info !== "object" || info === null) return [];
return Object.values(info)
.map((account) => (account as { path?: unknown } | null)?.path)
.filter((path): path is string => typeof path === "string" && path !== "");
} catch {
return [];
}
}
/** Every sync root that can be named without looking at the path in question. */
export async function windowsSyncRoots(home: string, env: NodeJS.ProcessEnv = process.env): Promise<SyncRoot[]> {
const roots: SyncRoot[] = [[win32.join(home, "iCloudDrive"), "iCloud Drive"]];
for (const key of ["OneDrive", "OneDriveConsumer", "OneDriveCommercial"]) {
const dir = env[key];
if (dir) roots.push([dir, "OneDrive"]);
}
const dropbox: string[] = [];
for (const base of [env.LOCALAPPDATA, env.APPDATA]) {
if (!base) continue;
const text = await readFile(win32.join(base, "Dropbox", "info.json"), "utf8").catch(() => null);
if (text) dropbox.push(...dropboxRoots(text));
}
// No info.json (an old or half-installed client): the default location.
if (dropbox.length === 0) dropbox.push(win32.join(home, "Dropbox"));
for (const dir of dropbox) roots.push([dir, "Dropbox"]);
// Google Drive in mirror mode keeps a real folder, by default in the home.
if (await driveFsInstalled(env)) {
roots.push([win32.join(home, "My Drive"), "Google Drive"], [win32.join(home, "Google Drive"), "Google Drive"]);
}
return roots;
}
function driveFsInstalled(env: NodeJS.ProcessEnv): Promise<boolean> {
return env.LOCALAPPDATA ? exists(win32.join(env.LOCALAPPDATA, "Google", "DriveFS")) : Promise.resolve(false);
}
/**
* Whether `path` is on Google Drive's streaming drive: a drive letter of its
* own (G: unless the user moved it) whose root holds `My Drive`. The letter is
* only in the client's database, so the drive is recognised by that shape,
* and only on a machine that has the client.
*/
export async function onGoogleDriveStream(path: string, env: NodeJS.ProcessEnv = process.env): Promise<boolean> {
const root = win32.parse(win32.resolve(path)).root;
if (!/^[a-z]:\\$/i.test(root)) return false;
return (await driveFsInstalled(env)) && (await exists(win32.join(root, "My Drive")));
}
/** The service syncing `path` on Windows, or null. */
export async function windowsCloudSyncKind(path: string, home: string, env: NodeJS.ProcessEnv = process.env): Promise<string | null> {
for (const [dir, label] of await windowsSyncRoots(home, env)) {
if (isUnder(path, dir)) return label;
}
return (await onGoogleDriveStream(path, env)) ? "Google Drive" : null;
}

View File

@ -0,0 +1,56 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { instructions } from "./docs";
// The docs in miniature, laid out like the repo's `docs/`.
const root = mkdtempSync(join(tmpdir(), "dapi-docs-"));
const docsDir = join(root, "docs");
const repoDocs = join(__dirname, "..", "..", "..", "..", "docs");
beforeAll(() => {
mkdirSync(join(docsDir, "skills"), { recursive: true });
writeFileSync(join(docsDir, "INSTRUCTIONS.md"), "Diffusion Studio is running.\n\nRead `skills/editor.md`.\n");
writeFileSync(join(docsDir, "skills", "editor.md"), "# Editing\n\nHow to edit.\n");
writeFileSync(join(docsDir, "skills", "watch.md"), "# Watching\n\nHow to watch.\n");
});
afterAll(() => rmSync(root, { recursive: true, force: true }));
describe("instructions", () => {
it("is INSTRUCTIONS.md verbatim, followed by where the docs sit on disk", () => {
const text = instructions(docsDir);
expect(text.startsWith("Diffusion Studio is running.\n\nRead `skills/editor.md`.")).toBe(true);
expect(text).toContain(`The docs, including every page named above, are the files at \`${docsDir}\``);
});
it("falls back to a one-liner when nothing is staged", () => {
const text = instructions(null);
expect(text).toContain("The tools are the whole API");
expect(text).not.toContain("skills/editor.md");
});
it("builds from the repo's own docs without broken instructions", () => {
if (!existsSync(repoDocs)) return;
const text = instructions(repoDocs);
expect(text).toContain(repoDocs);
expect(text).not.toContain("dapi://");
expect(text).not.toContain("\\`");
});
});
describe("the repo's INSTRUCTIONS.md", () => {
it("names the skills, and every page it names exists", () => {
if (!existsSync(repoDocs)) return;
const text = readFileSync(join(repoDocs, "INSTRUCTIONS.md"), "utf8");
const pages = [...text.matchAll(/`((?:skills|reference|guides|examples|brand)\/[^`]*?\.(?:md|tsx?))`/g)].map((m) => m[1]);
expect(pages).toContain("skills/editor.md");
expect(pages).toContain("skills/watch.md");
for (const page of pages) expect(existsSync(join(repoDocs, ...page.split("/")))).toBe(true);
});
});

View File

@ -0,0 +1,36 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { readFileSync } from "node:fs";
import { join } from "node:path";
export const INSTRUCTIONS_FILE = "INSTRUCTIONS.md";
const FALLBACK_INSTRUCTIONS =
"Diffusion Studio, a video editor, is running on this machine and you are connected to it. The tools are the whole API; their descriptions are authoritative.";
/**
* The text every client gets on connect: INSTRUCTIONS.md from the docs, then
* where the docs sit on disk. The page names the skills and everything else
* it wants read — adding one is editing that file, not this one; the paths in
* it are relative to the docs, and the sentence below is what anchors them.
*/
export function instructions(docsDir: string | null): string {
const text = docsDir ? readText(join(docsDir, INSTRUCTIONS_FILE)) : null;
const parts = [text?.trim() || FALLBACK_INSTRUCTIONS];
if (docsDir) {
parts.push(
`The docs, including every page named above, are the files at \`${docsDir}\`: the skills, the tool and JSX reference, guides, runnable examples, and the brand kit (fonts, imagery, components to copy). They belong to the app; read them, never edit them.`,
);
}
return parts.join("\n\n");
}
function readText(path: string): string | null {
try {
return readFileSync(path, "utf8");
} catch {
return null;
}
}

View File

@ -0,0 +1,34 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import type { LogEntry, ToolArgs, ToolResult } from "@diffusionstudio/dapi";
/** The main window, as the `window` tool drives it. */
export type AppWindow = {
/** Whether the window is out for the user. */
visible(): boolean;
/** Shows and focuses it, creating it when there is none. */
show(): Promise<void>;
/** Puts it away; the app keeps running in the background. */
hide(): void;
};
/** What a main-process handler gets besides its arguments. */
export type MainContext = {
/** Fires when the caller cancels or goes away. */
signal: AbortSignal;
/** The app's console buffer, oldest first. */
logs(): LogEntry[];
/** The app's version. */
version: string;
/** The main window. */
window: AppWindow;
};
/** The tools that need the file system, a child process or the window itself, not a renderer. */
export type MainToolName = "logs" | "report" | "window";
export type MainHandler<N extends MainToolName> = (args: ToolArgs<N>, ctx: MainContext) => Promise<ToolResult<N>>;
export type MainHandlers = { readonly [N in MainToolName]: MainHandler<N> };

View File

@ -0,0 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { logs } from "./logs";
import { report } from "./report";
import { window } from "./window";
import type { MainHandlers } from "../handler";
/** Every tool main answers itself, keyed by its catalog name. */
export const mainHandlers: MainHandlers = { logs, report, window };

View File

@ -0,0 +1,43 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { describe, expect, it } from "vitest";
import { LOG_MESSAGE_MAX, LOG_TAIL } from "@diffusionstudio/dapi";
import { logs } from "./logs";
import type { LogEntry } from "@diffusionstudio/dapi";
import type { MainContext } from "../handler";
const entry = (ts: number, message: string, level: LogEntry["level"] = "info"): LogEntry => ({ ts, level, message, source: "" });
const noWindow = { visible: () => false, show: async () => {}, hide: () => {} };
const ctx = (entries: LogEntry[]): MainContext => ({ signal: new AbortController().signal, logs: () => entries, version: "0", window: noWindow });
describe("logs", () => {
it("returns the last LOG_TAIL entries when no tail is given", async () => {
const buffer = Array.from({ length: LOG_TAIL + 5 }, (_, i) => entry(i, `m${i}`));
const { entries } = await logs({}, ctx(buffer));
expect(entries).toHaveLength(LOG_TAIL);
expect(entries[0]!.ts).toBe(5);
});
it("filters by level, since, and contains before taking the tail", async () => {
const buffer = [
entry(1, "Export 10%"),
entry(2, "export 50%"),
entry(3, "render done"),
entry(4, "EXPORT failed", "error"),
entry(5, "export 90%", "debug"),
];
const { entries } = await logs({ since: 1, contains: "export", level: "info", tail: 1 }, ctx(buffer));
expect(entries.map((e) => e.ts)).toEqual([4]);
const all = await logs({ since: 1, contains: "export" }, ctx(buffer));
expect(all.entries.map((e) => e.ts)).toEqual([2, 4, 5]);
});
it("cuts long messages and says how much was dropped", async () => {
const { entries } = await logs({}, ctx([entry(1, "x".repeat(LOG_MESSAGE_MAX + 10))]));
expect(entries[0]!.message).toBe(`${"x".repeat(LOG_MESSAGE_MAX)}… (10 more chars)`);
});
});

View File

@ -0,0 +1,38 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { LOG_MESSAGE_MAX, LOG_TAIL } from "@diffusionstudio/dapi";
import type { LogEntry, LogLevel } from "@diffusionstudio/dapi";
import type { MainHandler } from "../handler";
const LEVEL_RANK: Record<LogLevel, number> = { debug: 0, info: 1, warning: 2, error: 3 };
export const logs: MainHandler<"logs"> = async ({ tail = LOG_TAIL, level, since, contains }, ctx) => {
const min = level === undefined ? 0 : LEVEL_RANK[level];
const needle = contains?.toLowerCase();
const entries = ctx
.logs()
.filter(
(e) =>
LEVEL_RANK[e.level] >= min &&
(since === undefined || e.ts > since) &&
(needle === undefined || e.message.toLowerCase().includes(needle)),
);
return { entries: entries.slice(-tail).map(clip) };
};
function clip(entry: LogEntry): LogEntry {
const over = entry.message.length - LOG_MESSAGE_MAX;
return over > 0 ? { ...entry, message: `${entry.message.slice(0, LOG_MESSAGE_MAX)}… (${over} more chars)` } : entry;
}
/** One log entry as a line: local time, level, message, source. */
export function formatLogEntry(entry: LogEntry): string {
const pad = (n: number, w = 2) => String(n).padStart(w, "0");
const d = new Date(entry.ts);
const time = `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad(d.getMilliseconds(), 3)}`;
const source = entry.source ? ` (${entry.source})` : "";
return `${time} [${entry.level}] ${entry.message}${source}`;
}

View File

@ -4,50 +4,41 @@
import { spawn } from "node:child_process";
import { arch, platform, release } from "node:os";
import { DapiError, ISSUE_LOG_TAIL } from "@diffusionstudio/dapi";
import { formatLogEntry } from "./logs";
import type { MainHandler } from "../handler";
const REPO = "diffusionstudio/editor";
export const GH_MISSING =
const GH_MISSING =
"gh (GitHub CLI) is not installed, so the issue cannot be filed. Install it from https://cli.github.com, run `gh auth login`, then retry.";
export type IssueInput = {
title: string;
body?: string;
commands?: string[];
logs?: string[]; // already formatted log lines, oldest first
appStatus: string; // "running", "not running", "not checked", or why it was unreachable
version: string;
};
function fence(language: string, content: string): string {
return `\`\`\`${language}\n${content}\n\`\`\``;
}
function environmentTable(input: IssueInput): string {
function environmentTable(version: string): string {
const rows: Array<[string, string]> = [
["dapi", input.version],
["app", version],
["platform", `${platform()} ${release()} (${arch()})`],
["node", process.version],
["app", input.appStatus],
["electron", process.versions.electron ?? "unknown"],
];
return ["| | |", "| --- | --- |", ...rows.map(([k, v]) => `| ${k} | ${v} |`)].join("\n");
}
export function buildIssueBody(input: IssueInput): string {
function buildIssueBody(input: { body?: string; commands?: string[]; logs: string[]; version: string }): string {
const sections: string[] = [];
if (input.body?.trim()) sections.push(input.body.trim());
if (input.commands?.length) sections.push(`## Repro\n\n${fence("sh", input.commands.join("\n"))}`);
sections.push(`## Environment\n\n${environmentTable(input)}`);
if (input.logs?.length) sections.push(`## App logs\n\n${fence("", input.logs.join("\n"))}`);
sections.push(`## Environment\n\n${environmentTable(input.version)}`);
if (input.logs.length) sections.push(`## App logs\n\n${fence("", input.logs.join("\n"))}`);
return `${sections.join("\n\n")}\n`;
}
// --repo is explicit because dapi runs from the user's project, not a checkout
// of the editor; the body goes over stdin so a long log tail can't blow the
// argv size limit.
export function createIssue(title: string, body: string): Promise<string> {
// --repo is explicit because the app is not a checkout of the editor; the body
// goes over stdin so a long log tail can't blow the argv size limit.
function createIssue(title: string, body: string): Promise<string> {
return new Promise((resolve, reject) => {
const gh = spawn("gh", ["issue", "create", "--repo", REPO, "--title", title, "--body-file", "-"]);
@ -57,7 +48,7 @@ export function createIssue(title: string, body: string): Promise<string> {
gh.stderr.on("data", (chunk) => (stderr += chunk));
gh.on("error", (e) => {
reject((e as NodeJS.ErrnoException).code === "ENOENT" ? new Error(GH_MISSING) : e);
reject((e as NodeJS.ErrnoException).code === "ENOENT" ? new DapiError("unsupported", GH_MISSING) : e);
});
gh.on("close", (code) => {
if (code !== 0) {
@ -73,7 +64,16 @@ export function createIssue(title: string, body: string): Promise<string> {
resolve(url);
});
gh.stdin.on("error", () => { }); // gh exiting early (auth failure) breaks the pipe
gh.stdin.on("error", () => {}); // gh exiting early (auth failure) breaks the pipe
gh.stdin.end(body);
});
}
export const report: MainHandler<"report"> = async ({ title, body, commands, logs }, ctx) => {
const summary = title.trim();
if (!summary) throw new DapiError("invalid-input", "A one-line title is required.");
const tail = logs ?? ISSUE_LOG_TAIL;
const lines = tail > 0 ? ctx.logs().slice(-tail).map(formatLogEntry) : [];
const url = await createIssue(summary, buildIssueBody({ body, commands, logs: lines, version: ctx.version }));
return { url };
};

View File

@ -0,0 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import type { MainHandler } from "../handler";
export const window: MainHandler<"window"> = async ({ visible }, ctx) => {
if (visible === true) {
await ctx.window.show();
} else if (visible === false) {
ctx.window.hide();
}
return { visible: ctx.window.visible() };
};

View File

@ -0,0 +1,96 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { request } from "node:http";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { z } from "zod";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { DapiHttpServer } from "./http";
// An ephemeral port: the fixed one may be held by a running app.
const PORT = 3200 + Math.floor(Math.random() * 500);
const PATH = "/mcp";
let server: DapiHttpServer;
let sessionsCreated = 0;
beforeAll(async () => {
server = new DapiHttpServer({
host: "127.0.0.1",
port: PORT,
path: PATH,
createSession() {
sessionsCreated++;
const session = new McpServer({ name: "test", version: "0.0.0" }, { instructions: "Test instructions." });
session.registerTool(
"echo",
{ inputSchema: z.object({ text: z.string() }), outputSchema: z.object({ text: z.string() }) },
async ({ text }) => ({ content: [{ type: "text", text }], structuredContent: { text } }),
);
session.registerResource("note", "dapi://note", { mimeType: "text/plain" }, async () => ({
contents: [{ uri: "dapi://note", mimeType: "text/plain", text: "hello" }],
}));
return session;
},
});
await server.start();
});
afterAll(() => server.stop());
async function connect(): Promise<Client> {
const client = new Client({ name: "test-client", version: "0.0.0" });
await client.connect(new StreamableHTTPClientTransport(new URL(server.url)));
return client;
}
describe("mcp over http", () => {
it("serves a session: instructions, tools, resources", async () => {
const client = await connect();
expect(client.getInstructions()).toBe("Test instructions.");
expect((await client.listTools()).tools.map((t) => t.name)).toEqual(["echo"]);
const result = await client.callTool({ name: "echo", arguments: { text: "hi" } });
expect(result.structuredContent).toEqual({ text: "hi" });
const note = await client.readResource({ uri: "dapi://note" });
expect(note.contents[0]).toMatchObject({ text: "hello" });
await client.close();
});
it("gives each client its own session", async () => {
const before = sessionsCreated;
const a = await connect();
const b = await connect();
expect(sessionsCreated - before).toBe(2);
await a.close();
await b.close();
});
it("rejects a stale session id and a non-mcp path", async () => {
const stale = await fetch(server.url, {
method: "POST",
headers: { "content-type": "application/json", accept: "application/json, text/event-stream", "mcp-session-id": "nope" },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "ping" }),
});
expect(stale.status).toBe(404);
const elsewhere = await fetch(`http://127.0.0.1:${PORT}/other`);
expect(elsewhere.status).toBe(404);
});
it("rejects a request whose Host is not loopback (dns rebinding)", async () => {
// node's fetch drops a custom Host header, so go through node:http.
const status = await new Promise<number>((resolve, reject) => {
const req = request(
{ host: "127.0.0.1", port: PORT, path: PATH, method: "POST", headers: { host: "evil.example", "content-type": "application/json", accept: "application/json, text/event-stream" } },
(res) => {
res.resume();
res.on("end", () => resolve(res.statusCode ?? 0));
},
);
req.on("error", reject);
req.end(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "x", version: "0" } } }));
});
expect(status).toBe(403);
});
});

View File

@ -0,0 +1,126 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// MCP over Streamable HTTP on a fixed loopback port: the transport agents
// register by URL. One MCP session per client, keyed by the session id the
// transport hands out on `initialize`; later requests carry it in a header.
// No token: the server binds to loopback and rejects any Host header that is
// not the loopback address, which is what keeps browser pages from reaching
// it. Everything else running as the user can already reach the app.
import { randomUUID } from "node:crypto";
import { createServer } from "node:http";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
import type { IncomingMessage, Server, ServerResponse } from "node:http";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
export type HttpServerDeps = {
host: string;
port: number;
/** The URL path the endpoint answers on; anything else is 404. */
path: string;
/** A fresh MCP server with the tools and resources registered, one per session. */
createSession(): McpServer;
};
type Session = { transport: StreamableHTTPServerTransport; server: McpServer };
const SESSION_HEADER = "mcp-session-id";
export class DapiHttpServer {
private readonly deps: HttpServerDeps;
private readonly sessions = new Map<string, Session>();
private server: Server | null = null;
constructor(deps: HttpServerDeps) {
this.deps = deps;
}
/** Resolves once listening; rejects when the port is taken, so the caller can say so. */
start(): Promise<void> {
return new Promise((resolve, reject) => {
const server = createServer((req, res) => void this.handle(req, res));
server.once("error", reject);
server.listen(this.deps.port, this.deps.host, () => {
server.off("error", reject);
server.on("error", (error) => console.error("[dapi] http server error:", error));
this.server = server;
resolve();
});
});
}
stop(): void {
for (const { transport, server } of this.sessions.values()) {
void transport.close();
void server.close();
}
this.sessions.clear();
this.server?.close();
this.server = null;
}
get url(): string {
return `http://${this.deps.host}:${this.deps.port}${this.deps.path}`;
}
private async handle(req: IncomingMessage, res: ServerResponse): Promise<void> {
const url = new URL(req.url ?? "/", this.url);
if (url.pathname !== this.deps.path) {
res.writeHead(404, { "content-type": "text/plain" }).end("Not found");
return;
}
try {
const id = header(req, SESSION_HEADER);
const existing = id === undefined ? undefined : this.sessions.get(id);
if (existing) {
await existing.transport.handleRequest(req, res);
return;
}
if (id !== undefined) {
// The transport would answer the same way; answering here keeps a
// stale id from allocating a server it never initializes.
res.writeHead(404, { "content-type": "application/json" }).end(
JSON.stringify({ jsonrpc: "2.0", error: { code: -32001, message: "Session not found" }, id: null }),
);
return;
}
// No session: either an `initialize`, which the transport answers with
// a new id, or a stray request it rejects with 400.
await this.open().transport.handleRequest(req, res);
} catch (error) {
console.error("[dapi] http request failed:", error);
if (!res.headersSent) res.writeHead(500, { "content-type": "text/plain" }).end("Internal error");
}
}
private open(): Session {
const server = this.deps.createSession();
const hosts = [this.deps.host, "localhost"];
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: () => randomUUID(),
enableDnsRebindingProtection: true,
allowedHosts: [...hosts, ...hosts.map((host) => `${host}:${this.deps.port}`)],
onsessioninitialized: (id) => {
this.sessions.set(id, session);
},
onsessionclosed: (id) => {
this.sessions.delete(id);
},
});
const session: Session = { transport, server };
transport.onclose = () => {
if (transport.sessionId !== undefined) this.sessions.delete(transport.sessionId);
};
// connect() starts the transport; it does not block on I/O.
void server.connect(transport);
return session;
}
}
function header(req: IncomingMessage, name: string): string | undefined {
const value = req.headers[name];
return Array.isArray(value) ? value[0] : value;
}

View File

@ -0,0 +1,180 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { basename, dirname, join } from "node:path";
import { afterAll, describe, expect, it, vi } from "vitest";
import { present, toCallToolResult } from "./present";
const dir = mkdtempSync(join(tmpdir(), "dapi-present-"));
afterAll(() => rmSync(dir, { recursive: true, force: true }));
const png = (byte: number, size = 8) => new Uint8Array(size).fill(byte);
describe("present", () => {
it("writes capture frames by timecode into the requested directory and returns their paths", async () => {
const out = join(dir, "frames");
const presented = await present("capture", { id: "intro", output: out }, [
{ timecode: "0f", png: png(1) },
{ timecode: "1s", png: png(2) },
]);
expect(presented.output).toEqual({ images: [{ timecode: "0f", path: join(out, "0f.png") }, { timecode: "1s", path: join(out, "1s.png") }] });
expect(readFileSync(join(out, "1s.png"))).toEqual(Buffer.from(png(2)));
});
it("picks a fresh temp directory when none is given", async () => {
const presented = await present("grab", { path: "/c.mp4" }, [{ timecode: "0f", png: png(3) }]);
const { path } = (presented.output as { images: Array<{ path: string }> }).images[0]!;
expect(path).toMatch(/dapi-grab-.*[\\/]0f\.png$/);
rmSync(join(path, ".."), { recursive: true, force: true });
});
it("keeps a preview's other fields next to the path", async () => {
const file = join(dir, "wave.png");
const presented = await present("waveform", { path: "/c.mp4", output: file }, { png: png(4), silences: [{ start: 0, end: 1 }] });
expect(presented.output).toEqual({ path: file, silences: [{ start: 0, end: 1 }] });
});
it("writes a preview or transcript into an output that names an existing directory", async () => {
const out = join(dir, "into");
mkdirSync(out, { recursive: true });
const preview = await present("waveform", { path: "/c.mp4", output: out }, { png: png(7), silences: [] });
const previewPath = (preview.output as { path: string }).path;
expect(dirname(previewPath)).toBe(out);
expect(basename(previewPath)).toMatch(/^dapi-waveform-.*\.png$/);
expect(readFileSync(previewPath)).toEqual(Buffer.from(png(7)));
const transcript = await present("transcribe", { path: "/c.mp4", output: out }, { segments: [] });
const transcriptPath = (transcript.output as { path: string }).path;
expect(transcriptPath).toMatch(/dapi-transcript-.*\.json$/);
expect(JSON.parse(readFileSync(transcriptPath, "utf8"))).toEqual({ segments: [] });
});
it("names screenshots by time and never overwrites one", async () => {
const first = await present("screenshot", { output: dir }, { png: png(5), width: 10, height: 10 });
const second = await present("screenshot", { output: dir }, { png: png(6), width: 10, height: 10 });
const a = (first.output as { path: string }).path;
const b = (second.output as { path: string }).path;
expect(a).toMatch(/diffusion-studio_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\.png$/);
expect(b).not.toBe(a);
});
it("writes a transcript to a file, unchanged, and returns its path and size", async () => {
const file = join(dir, "talk.json");
const segments = [{ text: "Hi there", words: [{ text: "Hi", start: 0, end: 0.2 }, { text: "there", start: 0.3, end: 0.6 }] }];
const presented = await present("transcribe", { path: "/c.mp4", output: file }, { segments });
expect(presented).toEqual({ output: { path: file, segments: 1, words: 2 }, images: [] });
expect(JSON.parse(readFileSync(file, "utf8"))).toEqual({ segments });
});
it("passes other results through untouched", async () => {
expect(await present("check", { id: "x" }, { stats: {}, issues: [] })).toEqual({ output: { stats: {}, issues: [] }, images: [] });
});
});
describe("toCallToolResult", () => {
it("inlines a few small images and always carries the output as text and structure", () => {
const result = toCallToolResult({ output: { images: [] }, images: [{ path: "/a.png", png: png(1) }] });
expect(result.structuredContent).toEqual({ images: [] });
expect(result.content[0]).toEqual({ type: "text", text: '{"images":[]}' });
expect(result.content[1]).toMatchObject({ type: "image", mimeType: "image/png" });
});
it("sends paths only when there are many images or a large one", () => {
const many = Array.from({ length: 5 }, (_, i) => ({ path: `/${i}.png`, png: png(i) }));
expect(toCallToolResult({ output: {}, images: many }).content).toHaveLength(1);
const large = [{ path: "/big.png", png: png(0, (1 << 20) + 1) }];
expect(toCallToolResult({ output: {}, images: large }).content).toHaveLength(1);
});
});
describe("present a generation job", () => {
const job = (id: string, status: string, assets: Array<Record<string, unknown>>) => ({
job: { id, status, credits: 4, etaSeconds: 10, etaRemainingSeconds: null, error: null, assets },
saveTo: null as string | null,
});
const file = (filename: string) => ({ url: `https://files.test/${filename}`, filename, mimeType: "image/png", size: 8 });
it("passes a job still running through as the API has it", async () => {
const running = job("j-running", "running", []);
expect((await present("job", { id: "j-running" }, running)).output).toEqual(running.job);
});
it("downloads a succeeded job's files once, to the output numbered and with the made extension", async () => {
const fetch = vi.fn(async (url: string) => new Response(new Uint8Array([url.length])));
vi.stubGlobal("fetch", fetch);
try {
const out = join(dir, "generated", "fox.jpg");
const done = { ...job("j-done", "succeeded", [file("red-fox.png"), file("red-fox-2.png")]), saveTo: out };
const first = await present("job", { id: "j-done" }, done);
const again = await present("job", { id: "j-done" }, done);
const assets = (first.output as { assets: Array<Record<string, unknown>> }).assets;
expect(assets.map((asset) => asset.path)).toEqual([join(dir, "generated", "fox-1.png"), join(dir, "generated", "fox-2.png")]);
expect(assets[0]).not.toHaveProperty("url");
expect(assets[0]).toMatchObject({ filename: "red-fox.png", mimeType: "image/png" });
expect(again.output).toEqual(first.output);
expect(fetch).toHaveBeenCalledTimes(2);
} finally {
vi.unstubAllGlobals();
}
});
it("writes a single file at the output, over a file already there", async () => {
vi.stubGlobal("fetch", async () => new Response("new"));
try {
const out = join(dir, "single.png");
writeFileSync(out, "old");
const presented = await present("job", { id: "j-one" }, { ...job("j-one", "succeeded", [file("x.png")]), saveTo: out });
expect((presented.output as { assets: Array<{ path: string }> }).assets[0]!.path).toBe(out);
expect(readFileSync(out, "utf8")).toBe("new");
} finally {
vi.unstubAllGlobals();
}
});
it("saves into a directory of the job's own under the temp dir when no directory is given", async () => {
vi.stubGlobal("fetch", async () => new Response(new Uint8Array([1])));
try {
const presented = await present("generate", { model: "flux-2-klein" }, job("j-temp", "succeeded", [file("a.png")]));
const path = (presented.output as { assets: Array<{ path: string }> }).assets[0]!.path;
expect(path).toMatch(/dapi-generate-j-temp[\\/]a\.png$/);
rmSync(dirname(path), { recursive: true, force: true });
} finally {
vi.unstubAllGlobals();
}
});
it("leaves files the renderer saved into the library as they are", async () => {
const saved = job("j-lib", "succeeded", [{ filename: "a.png", path: "/p/assets/a.png", src: "a.png" }]);
expect((await present("job", { id: "j-lib" }, saved)).output).toEqual(saved.job);
});
it("writes a local job's files from their bytes, to the output, once", async () => {
const out = join(dir, "masks", "skater.mask");
const done = { ...job("local-mask", "succeeded", [{ filename: "Tracking 1.mask", mimeType: "", size: 4, bytes: png(9, 4) }]), saveTo: out };
const first = await present("job", { id: "local-mask" }, done);
writeFileSync(out, "edited since");
const again = await present("job", { id: "local-mask" }, done);
const assets = (first.output as { assets: Array<Record<string, unknown>> }).assets;
expect(assets).toEqual([{ filename: "Tracking 1.mask", mimeType: "", size: 4, path: out }]);
expect(again.output).toEqual(first.output);
expect(readFileSync(out, "utf8")).toBe("edited since");
});
it("writes a local job's picture to the temp dir, inline only the first time, and names it in its details", async () => {
const details = { frameRate: 30, start: 1, end: 1.033, frames: 1, bbox: null, lost: [] };
const preview = { ...job("local-preview", "succeeded", []), image: png(8) };
preview.job = { ...preview.job, details } as typeof preview.job;
const first = await present("generate", { model: "sam-2.1" }, preview);
const image = (first.output as { details: { image: string } }).details.image;
expect(image).toMatch(/dapi-local-preview\.png$/);
expect(first.output).toEqual({ ...preview.job, details: { ...details, image } });
expect(first.images).toEqual([{ path: image, png: png(8) }]);
expect(readFileSync(image)).toEqual(Buffer.from(png(8)));
const again = await present("job", { id: "local-preview" }, preview);
expect(again).toEqual({ output: first.output, images: [] });
rmSync(image, { force: true });
});
});

View File

@ -0,0 +1,207 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { existsSync, realpathSync } from "node:fs";
import { mkdir, mkdtemp, stat, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { basename, dirname, join } from "node:path";
import { randomUUID } from "node:crypto";
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { generatedPath } from "@diffusionstudio/dapi";
import type { GenerationResult, TimecodedImage, ToolArgs, ToolName, ToolOutput, ToolResult } from "@diffusionstudio/dapi";
/** A file the tool wrote, kept in memory only long enough to decide whether to inline it. */
export type WrittenImage = { path: string; png: Uint8Array };
export type Presented = { output: unknown; images: WrittenImage[] };
/** More than this, or any image larger than INLINE_MAX_BYTES, and the caller gets paths only. */
const INLINE_MAX_IMAGES = 4;
const INLINE_MAX_BYTES = 1 << 20;
const APP_SLUG = "diffusion-studio";
/**
* The temp dir with its real spelling. On Windows `%TEMP%` is often set with short names
*/
function tempDir(): string {
const dir = tmpdir();
try {
return realpathSync.native(dir);
} catch {
return dir;
}
}
export async function present(name: ToolName, args: unknown, result: unknown): Promise<Presented> {
switch (name) {
case "capture":
return presentImages(result as ToolResult<"capture">, (args as ToolArgs<"capture">).output, "capture");
case "grab":
return presentImages(result as ToolResult<"grab">, (args as ToolArgs<"grab">).output, "grab");
case "filmstrip":
return presentPreview(result as ToolResult<"filmstrip">, (args as ToolArgs<"filmstrip">).output, "filmstrip");
case "waveform":
return presentPreview(result as ToolResult<"waveform">, (args as ToolArgs<"waveform">).output, "waveform");
case "screenshot":
return presentScreenshot(result as ToolResult<"screenshot">, (args as ToolArgs<"screenshot">).output);
case "transcribe":
return presentTranscript(result as ToolResult<"transcribe">, (args as ToolArgs<"transcribe">).output);
case "generate":
if ((args as ToolArgs<"generate">).estimate) return { output: result, images: [] };
return presentJob(result as GenerationResult);
case "job":
return presentJob(result as GenerationResult);
default:
return { output: result, images: [] };
}
}
// Frames and contact sheets arrive in the same shape: each image is stamped
// with its timecode (`08s10f`, or `0f-08s10f` for a sheet), which is the
// filename too.
async function presentImages(images: TimecodedImage[], output: string | undefined, kind: string): Promise<Presented> {
const dir = output ?? (await mkdtemp(join(tempDir(), `dapi-${kind}-`)));
await mkdir(dir, { recursive: true });
const written: WrittenImage[] = [];
const refs: ToolOutput<"capture">["images"] = [];
for (const { timecode, png } of images) {
const path = join(dir, `${timecode}.png`);
await writeFile(path, png);
written.push({ path, png });
refs.push({ timecode, path });
}
return { output: { images: refs }, images: written };
}
/**
* Where a single-file tool writes: `output` when given, a fresh name under
* the temp dir otherwise. An `output` that names an existing directory gets
* the fresh name inside it rather than an EISDIR from writeFile.
*/
async function singleFilePath(output: string | undefined, name: string): Promise<string> {
if (output === undefined) return join(tempDir(), name);
const existing = await stat(output).catch(() => null);
if (existing?.isDirectory()) return join(output, name);
await mkdir(dirname(output), { recursive: true });
return output;
}
async function presentPreview(
result: { png: Uint8Array } & Record<string, unknown>,
output: string | undefined,
kind: string,
): Promise<Presented> {
const { png, ...rest } = result;
const path = await singleFilePath(output, `dapi-${kind}-${randomUUID()}.png`);
await writeFile(path, png);
return { output: { path, ...rest }, images: [{ path, png }] };
}
async function presentScreenshot(result: ToolResult<"screenshot">, output: string | undefined): Promise<Presented> {
const dir = output ?? tempDir();
await mkdir(dir, { recursive: true });
const taken = new Date();
let attempt = 1;
let path = join(dir, screenshotFilename(taken, attempt));
while (existsSync(path)) path = join(dir, screenshotFilename(taken, ++attempt));
await writeFile(path, result.png);
const presented: ToolOutput<"screenshot"> = { path, width: result.width, height: result.height };
return { output: presented, images: [{ path, png: result.png }] };
}
async function presentTranscript(transcript: ToolResult<"transcribe">, output: string | undefined): Promise<Presented> {
const path = await singleFilePath(output, `dapi-transcript-${randomUUID()}.json`);
await writeFile(path, JSON.stringify(transcript, null, 2));
const words = transcript.segments.reduce((sum, segment) => sum + segment.words.length, 0);
const presented: ToolOutput<"transcribe"> = { path, segments: transcript.segments.length, words };
return { output: presented, images: [] };
}
/** Files of succeeded jobs saved to disk, by job id: the first poll that sees a job succeed saves them, the rest reuse the paths. */
const jobFiles = new Map<string, Promise<string[]>>();
/** Pictures of local jobs, by job id: each is written to the temp dir, and shown inline, the first poll it comes with. */
const jobImages = new Map<string, string>();
/**
* A job's files bound for disk are saved once it has succeeded — downloaded
* from their `url`, or written from the `bytes` a local model made — to
* `saveTo` (see `generatedPath`; a file already there is written over, as the
* other tools' outputs are) or under their own names into a directory of the
* job's own under the temp dir, and their `url` or `bytes` is swapped for the
* `path`. Files the renderer saved into the library arrive with their paths.
* A local job's picture goes to the temp dir, named in `details.image`.
*/
async function presentJob({ job, saveTo, image }: GenerationResult): Promise<Presented> {
const images: WrittenImage[] = [];
let shown = job;
if (image) {
let path = jobImages.get(job.id);
if (path === undefined) {
path = join(tempDir(), `dapi-${job.id}.png`);
await writeFile(path, image);
jobImages.set(job.id, path);
images.push({ path, png: image });
}
shown = { ...job, details: { ...job.details, image: path } };
}
const pending = job.assets.filter((file) => file.url !== undefined || file.bytes !== undefined);
if (job.status !== "succeeded" || pending.length === 0) return { output: shown, images };
let paths = jobFiles.get(job.id);
if (!paths) {
const temp = join(tempDir(), `dapi-generate-${job.id}`);
const targets = job.assets.map((file, i) =>
saveTo === null ? join(temp, basename(file.filename)) : generatedPath(saveTo, file.filename, i, job.assets.length),
);
paths = saveAll(job.assets, targets);
paths.catch(() => jobFiles.delete(job.id));
jobFiles.set(job.id, paths);
}
const written = await paths;
const assets = job.assets.map(({ url: _url, bytes: _bytes, ...file }, i) => ({ ...file, path: written[i] }));
return { output: { ...shown, assets }, images };
}
async function saveAll(files: GenerationResult["job"]["assets"], targets: string[]): Promise<string[]> {
for (const [i, file] of files.entries()) {
await mkdir(dirname(targets[i]!), { recursive: true });
await writeFile(targets[i]!, file.bytes ?? (await download(file.url!, file.filename)));
}
return targets;
}
async function download(url: string, filename: string): Promise<Uint8Array> {
const response = await fetch(url);
if (!response.ok) throw new Error(`Could not download ${filename} (${response.status})`);
return new Uint8Array(await response.arrayBuffer());
}
function screenshotFilename(taken: Date, attempt: number): string {
const pad = (value: number) => String(value).padStart(2, "0");
const date = [taken.getFullYear(), pad(taken.getMonth() + 1), pad(taken.getDate())].join("-");
const time = [pad(taken.getHours()), pad(taken.getMinutes()), pad(taken.getSeconds())].join("-");
return `${APP_SLUG}_${date}_${time}${attempt > 1 ? `-${attempt}` : ""}.png`;
}
/** The MCP result: the output as text and structured content, plus the images when they are few and small. */
export function toCallToolResult({ output, images }: Presented): CallToolResult {
const content: CallToolResult["content"] = [{ type: "text", text: JSON.stringify(output) }];
const inline = images.length <= INLINE_MAX_IMAGES && images.every((image) => image.png.byteLength <= INLINE_MAX_BYTES);
if (inline) {
for (const { png } of images) {
content.push({ type: "image", data: Buffer.from(png).toString("base64"), mimeType: "image/png" });
}
}
return { content, structuredContent: output as Record<string, unknown> };
}
/** A failure the agent reads as a sentence, not a protocol error. */
export function toErrorResult(error: unknown): CallToolResult {
return { isError: true, content: [{ type: "text", text: (error as Error).message }] };
}

View File

@ -0,0 +1,163 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { randomUUID } from "node:crypto";
import { ipcMain } from "electron";
import { DAPI_WIRE, DapiError } from "@diffusionstudio/dapi";
import type { BrowserWindow } from "electron";
import type { DapiCall, DapiCancel, DapiReply } from "@diffusionstudio/dapi";
type InFlight = {
resolve(data: unknown): void;
reject(error: Error): void;
};
/** Where renderer calls find their window. */
export type RendererHost = {
/** The main window, created hidden when there is none; `fresh` when this call created it. */
acquire(): { window: BrowserWindow; fresh: boolean };
/** The project the editor last had open, to reopen in a window created for a call. */
lastProject(): string | null;
};
/**
* Runs renderer tools from main: one `dapi:call` per request, answered by
* `dapi:reply`, or `dapi:cancel` if the caller gives up. There may be no
* window when a call arrives — it is only kept while something needs it — so
* a call creates one, and waits for it to load and to reopen the project the
* agent was working on. A window that reloads or dies fails the calls it was
* answering.
*/
export class RendererCalls {
private readonly host: RendererHost;
private readonly inFlight = new Map<string, InFlight>();
private readonly tracked = new WeakSet<BrowserWindow>();
// Settles once the current window has loaded, and reopened the project
// when it was created for a call. Every call waits on it.
private ready: Promise<BrowserWindow> | null = null;
constructor(host: RendererHost) {
this.host = host;
}
start(): void {
ipcMain.on(DAPI_WIRE.REPLY, (_event, reply: DapiReply) => {
const call = this.inFlight.get(reply.id);
if (!call) return;
this.inFlight.delete(reply.id);
if (reply.ok) call.resolve(reply.data);
else call.reject(reply.error.code ? new DapiError(reply.error.code, reply.error.message) : new Error(reply.error.message));
});
}
async call(tool: string, args: unknown, signal: AbortSignal): Promise<unknown> {
const window = await this.window(tool);
if (window.isDestroyed()) {
throw new Error("The app window closed before replying");
}
return this.send(window, tool, args, signal);
}
// The window to answer on. One created here is tracked, and gets the last
// project reopened — unless the call is itself an `open` — since the calls
// that follow assume the project the agent opened is still open. A project
// that no longer opens is left to the call to report.
private window(tool: string): Promise<BrowserWindow> {
const { window, fresh } = this.host.acquire();
// Loaded before, but it may have reloaded since.
if (!fresh && this.ready) {
return this.ready.then(loaded);
}
this.track(window);
const dir = fresh && tool !== "open" ? this.host.lastProject() : null;
const ready = loaded(window).then(async (loadedWindow) => {
if (dir) {
await this.send(loadedWindow, "open", { dir }, new AbortController().signal).catch((error: Error) =>
console.warn(`[dapi] could not reopen ${dir}: ${error.message}`),
);
}
return loadedWindow;
});
this.ready = ready;
// A window that failed to load is not waited on again: the next call
// finds out afresh.
ready.catch(() => {
if (this.ready === ready) this.ready = null;
});
return ready;
}
private send(window: BrowserWindow, tool: string, args: unknown, signal: AbortSignal): Promise<unknown> {
const id = randomUUID();
return new Promise((resolve, reject) => {
const onAbort = () => {
this.inFlight.delete(id);
if (!window.isDestroyed()) window.webContents.send(DAPI_WIRE.CANCEL, { id } satisfies DapiCancel);
reject(new DapiError("canceled", "The call was canceled."));
};
signal.addEventListener("abort", onAbort, { once: true });
this.inFlight.set(id, {
resolve: (data) => {
signal.removeEventListener("abort", onAbort);
resolve(data);
},
reject: (error) => {
signal.removeEventListener("abort", onAbort);
reject(error);
},
});
window.webContents.send(DAPI_WIRE.CALL, { id, tool, args } satisfies DapiCall);
});
}
private track(window: BrowserWindow): void {
if (this.tracked.has(window)) return;
this.tracked.add(window);
const fail = (why: string) => () => this.failAll(why);
window.webContents.on("did-start-loading", fail("The app reloaded before replying"));
window.webContents.on("render-process-gone", fail("The app's renderer crashed"));
window.on("closed", () => {
this.ready = null;
this.failAll("The app window closed before replying");
});
}
private failAll(message: string): void {
const calls = [...this.inFlight.values()];
this.inFlight.clear();
for (const call of calls) call.reject(new Error(message));
}
}
// Resolves with the window once it has finished loading.
function loaded(window: BrowserWindow, timeoutMs = 30000): Promise<BrowserWindow> {
if (window.isDestroyed()) return Promise.reject(new Error("The app has no window"));
if (window.webContents.isCrashed()) return Promise.reject(new Error("The app's renderer crashed"));
if (!window.webContents.isLoading()) return Promise.resolve(window);
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
cleanup();
reject(new Error("The app did not become ready in time"));
}, timeoutMs);
const cleanup = () => {
clearTimeout(timer);
window.webContents.off("did-finish-load", onLoad);
window.webContents.off("did-fail-load", onFail);
};
const onLoad = () => {
cleanup();
resolve(window);
};
const onFail = () => {
cleanup();
reject(new Error("The app failed to load"));
};
window.webContents.on("did-finish-load", onLoad);
window.webContents.on("did-fail-load", onFail);
});
}

View File

@ -0,0 +1,138 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { MCP_HOST, MCP_PATH, MCP_PORT, isDapiError, tools } from "@diffusionstudio/dapi";
import { mainHandlers } from "./handlers";
import { DapiHttpServer } from "./http";
import { instructions } from "./docs";
import { RendererCalls } from "./renderer-calls";
import { serveCatalog } from "./tools-session";
import type { TrackProps } from "@diffusionstudio/api-contract";
import type { LogEntry } from "@diffusionstudio/dapi";
import type { AppWindow, MainContext, MainToolName } from "./handler";
import type { RendererHost } from "./renderer-calls";
/**
* The name the server introduces itself with, and so the namespace an agent
* shows the tools under: `mcp__diffusion__<tool>`. The same word as our URL
* scheme and the CLI's primary name (`dapi` still works there too, as an
* alias).
*/
const SERVER_NAME = "diffusion";
export type DapiServerDeps = {
version: string;
/** The app's console buffer, for `logs` and `report`. */
logs(): LogEntry[];
/** The main window: where renderer tools run, and what `window` shows and hides. */
window: AppWindow & RendererHost & {
/** Keeps the window from idling out while a call runs; returns the release. */
hold(): () => void;
};
/** The staged docs: INSTRUCTIONS.md, their path, and the skill headers, all for every session. Null when not staged. */
docsDir: string | null;
/** Told about every finished call, as `tool_called` analytics props. */
onToolCall?(props: TrackProps): void;
};
/**
* The app's MCP server: Streamable HTTP on a fixed loopback port, the URL
* agents register and the `diffusion` CLI calls. Each client gets its own MCP
* session over one catalog. Main-process tools run here; renderer tools are
* forwarded over IPC and their results presented (files written, small
* images inlined) before they go back out.
*/
export class DapiServer {
private readonly deps: DapiServerDeps;
private readonly renderer: RendererCalls;
private readonly http: DapiHttpServer;
private instructionsText: string | null = null;
private httpReady: Promise<boolean> = Promise.resolve(false);
constructor(deps: DapiServerDeps) {
this.deps = deps;
this.renderer = new RendererCalls(deps.window);
for (const tool of tools) {
if (tool.environment === "main" && !(tool.name in mainHandlers)) {
throw new Error(`Main-process tool "${tool.name}" has no handler`);
}
}
this.http = new DapiHttpServer({
host: MCP_HOST,
port: MCP_PORT,
path: MCP_PATH,
createSession: () => this.createSession(),
});
}
/** The URL agents register. */
get url(): string {
return this.http.url;
}
start(): void {
this.renderer.start();
// A taken port is the one way this fails. The app is still usable
// without agents, so it is logged, not fatal; `mcpUrl()` says so.
this.httpReady = this.http.start().then(
() => true,
(error: Error) => {
console.error(`[dapi] cannot serve MCP at ${this.url}: ${error.message}`);
return false;
},
);
}
/** The HTTP URL once it is being served; null when the port could not be bound. */
async mcpUrl(): Promise<string | null> {
return (await this.httpReady) ? this.url : null;
}
stop(): void {
this.http.stop();
}
/** One MCP server over the whole catalog. The docs and skills are plain files; the instructions say where. */
private createSession(): McpServer {
this.instructionsText ??= instructions(this.deps.docsDir);
// `name` is the machine identity, and matches the key we write into agent
// configs; `title` is what a client shows a person.
const session = new McpServer({ name: SERVER_NAME, title: "Diffusion Studio", version: this.deps.version }, { instructions: this.instructionsText });
serveCatalog(session, async (tool, args, signal) => {
const release = this.deps.window.hold();
const startedAt = performance.now();
// The failure's code (`not-found`, `busy`, …), never its message: messages name the user's files.
let error: string | undefined;
try {
return await (tool.environment === "main" ?
this.runInMain(tool.name as MainToolName, args, signal)
: this.renderer.call(tool.name, args, signal));
} catch (thrown) {
error = isDapiError(thrown) ? thrown.code : "error";
throw thrown;
} finally {
release();
const client = session.server.getClientVersion();
this.deps.onToolCall?.({
tool: tool.name,
client: client?.name,
client_version: client?.version,
ok: !error,
error,
duration_ms: Math.round(performance.now() - startedAt),
});
}
});
return session;
}
private runInMain(name: MainToolName, args: unknown, signal: AbortSignal): Promise<unknown> {
const ctx: MainContext = { signal, logs: this.deps.logs, version: this.deps.version, window: this.deps.window };
// Each handler takes its own parsed args; the map's union type cannot
// express that pairing, so the call site widens.
return (mainHandlers[name] as (args: unknown, ctx: MainContext) => Promise<unknown>)(args, ctx);
}
}

View File

@ -0,0 +1,69 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
import { JSON_SCHEMA_DIALECT, tools } from "@diffusionstudio/dapi";
import { serveCatalog } from "./tools-session";
const CONTEXT = { rootDir: null, projectDir: null, currentTime: null, fontFamilies: [] };
let client: Client;
const calls: Array<{ name: string; args: unknown }> = [];
beforeAll(async () => {
const session = new McpServer({ name: "test", version: "0.0.0" });
serveCatalog(session, async (tool, args) => {
calls.push({ name: tool.name, args });
switch (tool.name) {
case "context":
return CONTEXT;
case "check":
throw new Error("No project open — run open first");
default:
return {};
}
});
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await session.connect(serverTransport);
client = new Client({ name: "test-client", version: "0.0.0" });
await client.connect(clientTransport);
});
afterAll(() => client.close());
describe("serveCatalog", () => {
it("lists every tool with its schemas in JSON Schema 2020-12, the dialect clients validate", async () => {
const listed = (await client.listTools()).tools;
expect(listed.map((tool) => tool.name)).toEqual(tools.map((tool) => tool.name));
for (const tool of listed) {
expect(tool.inputSchema.$schema, `${tool.name} input`).toBe(JSON_SCHEMA_DIALECT);
expect(tool.outputSchema?.$schema, `${tool.name} output`).toBe(JSON_SCHEMA_DIALECT);
expect(tool.description, tool.name).toBeTruthy();
}
const fonts = listed.find((tool) => tool.name === "fonts")!;
expect(fonts.inputSchema.properties).toHaveProperty("family");
expect(fonts.outputSchema?.properties).toHaveProperty("families");
});
it("validates arguments before the tool runs, and runs it with the parsed ones", async () => {
const before = calls.length;
const bad = await client.callTool({ name: "fonts", arguments: { limit: 0 } });
expect(bad.isError).toBe(true);
expect(JSON.stringify(bad.content)).toContain("limit");
expect(calls.length).toBe(before);
const result = await client.callTool({ name: "context", arguments: {} });
expect(result.structuredContent).toEqual(CONTEXT);
expect(calls.at(-1)).toEqual({ name: "context", args: {} });
});
it("returns a handler's failure as a readable error result, not a protocol error", async () => {
const result = await client.callTool({ name: "check", arguments: { id: "intro" } });
expect(result.isError).toBe(true);
expect(result.content).toEqual([{ type: "text", text: "No project open — run open first" }]);
});
});

View File

@ -0,0 +1,44 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import { toolJsonSchemas, tools } from "@diffusionstudio/dapi";
import { present, toCallToolResult, toErrorResult } from "./present";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { GenericTool, ToolName } from "@diffusionstudio/dapi";
/** Runs one tool wherever it lives (main or renderer) and returns the handler's raw result. */
export type ToolRunner = (tool: GenericTool, args: unknown, signal: AbortSignal) => Promise<unknown>;
/**
* Serves the whole catalog on an MCP session: every tool registered with the
* SDK, which validates arguments against the zod schema and structured
* content against the output schema, and a `tools/list` of our own.
*
* The list is ours because the SDK's converts the zod schemas to JSON Schema
* draft-07, and the validators clients run reject that dialect — Claude Code
* fails every call on the `outputSchema` before it reaches the app. What
* clients get instead is the same schema in 2020-12 (see `toolJsonSchemas`);
* `tools/call` and the validation behind it stay the SDK's.
*/
export function serveCatalog(session: McpServer, run: ToolRunner): void {
for (const tool of tools) {
session.registerTool(
tool.name,
{ title: tool.title, description: tool.description, inputSchema: tool.input, outputSchema: tool.output },
async (args, extra) => {
try {
const result = await run(tool, args, extra.signal);
return toCallToolResult(await present(tool.name as ToolName, args, result));
} catch (error) {
return toErrorResult(error);
}
},
);
}
session.server.setRequestHandler(ListToolsRequestSchema, () => ({
tools: tools.map((tool) => ({ name: tool.name, title: tool.title, description: tool.description, ...toolJsonSchemas(tool) })),
}));
}

View File

@ -0,0 +1,137 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// The shapes of a source edit and its outcome: the contract between the
// canvas (renderer) and the edit writer (main). Types only, with no Node
// imports, so the renderer's program can include it without Node's types.
import type { InspectValue, PropValue } from "@diffusionstudio/jsx";
export type { PropValue };
export interface SourceContext {
/** Absolute path of the project folder. */
dir: string;
/**
* Called with the project-relative path of every file about to be written
* and the exact text it is about to hold, so that whatever is watching the
* folder can tell the write apart from someone else's.
*/
onWrite?: (file: string, text: string) => void;
}
/**
* Overwrites props of the element named by `source` (a `SOURCE_ATTR` value),
* and — for a `<text>` — what it says. `text` is its literal content, which is
* its children rather than a prop and so arrives on its own; an element that
* only says something new comes with no props at all.
*/
export interface SourceSet {
kind: "set";
source: string;
props: Record<string, PropValue>;
text?: string;
}
/**
* Adds `<tag {...props} />` under the element named by `parent`, in front of
* the child named by `before` or last. `source` is the pending name the canvas
* knows the new element by; the write answers with the real one in `ids`.
* A parent may itself be pending when it was inserted earlier in the same
* write. `text`, when present, is the element's literal text content
* (`<text>Hello</text>`); without it the element is written self-closing.
*/
export interface SourceInsert {
kind: "insert";
source: string;
parent: string;
tag: string;
props: Record<string, PropValue>;
before?: string;
text?: string;
}
/**
* Moves the element named by `source` under the one named by `parent`, in
* front of the child named by `before` or last. The element travels as it was
* written — its own text, re-indented for where it lands — so a move is the
* one edit that does not touch what an element says, only where it says it.
* Both ends must be in one file: an element cannot move into another module's
* JSX any more than a project could have put it there.
*/
export interface SourceMove {
kind: "move";
source: string;
parent: string;
before?: string;
}
/**
* Removes the element named by `source` from the file, and with it everything
* it contains: its children are its text, and go the way a move takes them
* along. Addressed like a move — an unnamed element is a position, and cutting
* text renumbers positions, so the element is found before anything is cut.
*/
export interface SourceRemove {
kind: "remove";
source: string;
}
/**
* One iteration of a loop as the canvas rendered it: for every composition
* element of the loop body, by its source, the props it came out with and (for
* a `<text>`) its literal content — the values that were computed from the
* item, spelled as literals. `pending` is the name the canvas already knows
* that iteration's copy of the element by; the write answers with the real
* one in `ids`. The first iteration keeps the body's own names, so it carries
* none.
*/
export type SourceIteration = Record<string, { props: Record<string, PropValue>; text?: string; pending?: string }>;
/**
* Replaces the `<For>`/`<Index>` around the element named by `source` with
* one copy of its body per iteration, each spelling out what that iteration
* rendered. Nothing that comes after this in the same write can address a
* looped element (see `inLoop`): the loop is a recipe for elements, and a
* change to one of them means writing them down first.
*/
export interface SourceUnroll {
kind: "unroll";
source: string;
iterations: SourceIteration[];
}
/**
* Overwrites the initializer of an `@inspect`-annotated top-level const (see
* @diffusionstudio/jsx's inspect). Addressed by file and variable name — a
* const's name is unique in its module, so no id is needed — and only written
* when the declaration still carries the annotation and holds a literal: an
* initializer someone rewrote into an expression is theirs again.
*/
export interface SourceVariable {
kind: "variable";
file: string;
name: string;
value: InspectValue;
}
export type SourceEdit = SourceSet | SourceInsert | SourceMove | SourceRemove | SourceUnroll | SourceVariable;
export interface WriteResult {
/** Sources that could not be written, as `id` or `id (prop)`. */
skipped: string[];
/**
* Elements that earned a name in this write, as `old source id -> new one`.
* The canvas re-stamps its entities with these, so identity does not have to
* wait for a recompile.
*/
ids?: Record<string, string>;
/**
* The loops this write unrolled, by the `source` of the `SourceUnroll` that
* asked. An unroll not listed here was declined, and the canvas takes its
* loop back (see the edit writer).
*/
unrolled?: string[];
error?: string;
}

View File

@ -0,0 +1,77 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// The canvas shows an edit before the file has it, and an export and the next
// open render the file: an edit the write left out would move back. So the
// user wins — a prop is written over whatever the source held for it.
import { tmpdir } from "node:os";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { applyEdits } from "./edit";
const FILE = "main.tsx";
let dir: string;
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), "edit-test-"));
});
afterEach(async () => {
await rm(dir, { recursive: true, force: true });
});
describe("applyEdits", () => {
it("writes a prop over a literal and over an expression alike", async () => {
await writeFile(
join(dir, FILE),
`const X = 100;\nexport default () => <video id="clip" x={X} y={20} rotation={ticker() * 2} />;\n`,
);
const result = await applyEdits({ dir }, [
{ kind: "set", source: `${FILE}:clip`, props: { x: 555, y: 42, rotation: 90 } },
]);
expect(result.skipped).toEqual([]);
const text = await readFile(join(dir, FILE), "utf8");
expect(text).toContain(`<video id="clip" x={555} y={42} rotation={90} />`);
// The constant is someone else's too, and stays.
expect(text).toContain(`const X = 100;`);
});
it("keeps a text's paint when what it says changes", async () => {
await writeFile(join(dir, FILE), `export default () => <scene id="s"></scene>;\n`);
// The draw tool's insert: the text, then its paint under it.
await applyEdits({ dir }, [
{ kind: "insert", source: "pending#1", parent: `${FILE}:s`, tag: "text", props: {}, text: "Text" },
{ kind: "insert", source: "pending#2", parent: "pending#1", tag: "solidPaint", props: { color: "#FFFFFF" } },
]);
const inserted = await readFile(join(dir, FILE), "utf8");
const id = /<text id="([^"]+)"/.exec(inserted)![1];
// Then typing into it, once the insert has its name.
const result = await applyEdits({ dir }, [{ kind: "set", source: `${FILE}:${id}`, props: {}, text: "Hello" }]);
expect(result.skipped).toEqual([]);
const text = await readFile(join(dir, FILE), "utf8");
expect(text).toMatch(/<text id="[^"]+">Hello\s*<solidPaint id="[^"]+" color="#FFFFFF" \/>\s*<\/text>/);
});
it("replaces every part of what a text says, and only that", async () => {
await writeFile(
join(dir, FILE),
`export default () => (\n <text id="t">\n Hello {name}!\n <solidPaint color="#FFFFFF" />\n {/* note */}\n </text>\n);\n`,
);
const result = await applyEdits({ dir }, [{ kind: "set", source: `${FILE}:t`, props: {}, text: "Bye" }]);
expect(result.skipped).toEqual([]);
const text = await readFile(join(dir, FILE), "utf8");
expect(text).toContain(` <text id="t">\n Bye\n <solidPaint color="#FFFFFF" />\n {/* note */}\n </text>`);
});
});

View File

@ -4,14 +4,16 @@
import { randomInt } from "node:crypto";
import { readdir, readFile, writeFile } from "node:fs/promises";
import { readdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import { IndentationText, Project, SyntaxKind } from "ts-morph";
import { ID_ATTR, INSPECT_TAG, formatSource, isCompositionTag, isLoopTag, isSerializedAssetRef, parseSource } from "@diffusionstudio/jsx";
import { ID_ATTR, INSPECT_TAG, formatSource, isCompositionTag, isLoopTag, parseSource } from "@diffusionstudio/jsx";
import type { InspectValue, PropValue, SerializedAssetRef } from "@diffusionstudio/jsx";
import { writeFileAtomic } from "./atomic";
import type { PropValue } from "@diffusionstudio/jsx";
import type {
ArrowFunction,
FunctionExpression,
@ -24,136 +26,18 @@ import type {
SourceFile,
} from "ts-morph";
export type { PropValue, SerializedAssetRef };
/**
* A value an edit can carry: what a source spells as a literal, or a
* `generate.*` declaration in its wire form, spelled as the call that
* reproduces it (see `setProp`).
*/
export type EditValue = PropValue | SerializedAssetRef;
export interface SourceContext {
/** Absolute path of the project folder. */
dir: string;
/** Called with the project-relative path of every file written. */
onWrite?: (file: string) => void;
}
/**
* Overwrites props of the element named by `source` (a `SOURCE_ATTR` value),
* and — for a `<text>` — what it says. `text` is its literal content, which is
* its children rather than a prop and so arrives on its own; an element that
* only says something new comes with no props at all.
*/
export interface SourceSet {
kind: "set";
source: string;
props: Record<string, EditValue>;
text?: string;
}
/**
* Adds `<tag {...props} />` under the element named by `parent`, in front of
* the child named by `before` or last. `source` is the pending name the canvas
* knows the new element by; the write answers with the real one in `ids`.
* A parent may itself be pending when it was inserted earlier in the same
* write. `text`, when present, is the element's literal text content
* (`<text>Hello</text>`); without it the element is written self-closing.
*/
export interface SourceInsert {
kind: "insert";
source: string;
parent: string;
tag: string;
props: Record<string, EditValue>;
before?: string;
text?: string;
}
/**
* Moves the element named by `source` under the one named by `parent`, in
* front of the child named by `before` or last. The element travels as it was
* written — its own text, re-indented for where it lands — so a move is the
* one edit that does not touch what an element says, only where it says it.
* Both ends must be in one file: an element cannot move into another module's
* JSX any more than a project could have put it there.
*/
export interface SourceMove {
kind: "move";
source: string;
parent: string;
before?: string;
}
/**
* Removes the element named by `source` from the file, and with it everything
* it contains: its children are its text, and go the way a move takes them
* along. Addressed like a move — an unnamed element is a position, and cutting
* text renumbers positions, so the element is found before anything is cut.
*/
export interface SourceRemove {
kind: "remove";
source: string;
}
/**
* One iteration of a loop as the canvas rendered it: for every composition
* element of the loop body, by its source, the props it came out with and (for
* a `<text>`) its literal content — the values that were computed from the
* item, spelled as literals. `pending` is the name the canvas already knows
* that iteration's copy of the element by; the write answers with the real
* one in `ids`. The first iteration keeps the body's own names, so it carries
* none.
*/
export type SourceIteration = Record<string, { props: Record<string, EditValue>; text?: string; pending?: string }>;
/**
* Replaces the `<For>`/`<Index>` around the element named by `source` with
* one copy of its body per iteration, each spelling out what that iteration
* rendered. Nothing that comes after this in the same write can address a
* looped element (see `inLoop`): the loop is a recipe for elements, and a
* change to one of them means writing them down first.
*/
export interface SourceUnroll {
kind: "unroll";
source: string;
iterations: SourceIteration[];
}
/**
* Overwrites the initializer of an `@inspect`-annotated top-level const (see
* @diffusionstudio/jsx's inspect). Addressed by file and variable name — a
* const's name is unique in its module, so no id is needed — and only written
* when the declaration still carries the annotation and holds a literal: an
* initializer someone rewrote into an expression is theirs again.
*/
export interface SourceVariable {
kind: "variable";
file: string;
name: string;
value: InspectValue;
}
export type SourceEdit = SourceSet | SourceInsert | SourceMove | SourceRemove | SourceUnroll | SourceVariable;
export interface WriteResult {
/** Sources that could not be written, as `id` or `id (prop)`. */
skipped: string[];
/**
* Elements that earned a name in this write, as `old source id -> new one`.
* The canvas re-stamps its entities with these, so identity does not have to
* wait for a recompile.
*/
ids?: Record<string, string>;
/**
* The loops this write unrolled, by the `source` of the `SourceUnroll` that
* asked. An unroll not listed here was declined, and the canvas takes its
* loop back (see the edit writer).
*/
unrolled?: string[];
error?: string;
}
export type * from "./edit-types";
import type {
SourceContext,
SourceEdit,
SourceInsert,
SourceIteration,
SourceMove,
SourceRemove,
SourceUnroll,
SourceVariable,
WriteResult,
} from "./edit-types";
/** The opening half of a JSX element — where its attributes live. */
type JsxTag = JsxOpeningElement | JsxSelfClosingElement;
@ -266,29 +150,14 @@ const initializerText = (value: PropValue): string =>
? `"${value}"`
: `{${literalText(value)}}`;
/** A declaration's wire form as the `generate.*` call that reproduces it. */
function generateCallText(ref: SerializedAssetRef): string {
const { type, ...options } = ref.$generate;
return `generate.${type}(${literalText(options as Record<string, PropValue>)})`;
}
/**
* Writes a prop onto a tag as one would write it: `muted`, not `muted={true}`,
* and no attribute at all rather than `muted={false}`, since absence is what a
* boolean prop's false reads as. A declaration is spelled as its `generate.*`
* call — the caller makes sure `generate` is imported (see
* `ensureGenerateImport`).
* boolean prop's false reads as.
*/
function setProp(tag: JsxTag, name: string, value: EditValue): void {
function setProp(tag: JsxTag, name: string, value: PropValue): void {
const attribute = attributeOf(tag, name);
if (isSerializedAssetRef(value)) {
const initializer = `{${generateCallText(value)}}`;
if (attribute) attribute.setInitializer(initializer);
else tag.addAttribute({ name, initializer });
return;
}
if (value === true) {
if (attribute) attribute.removeInitializer();
else tag.addAttribute({ name });
@ -304,40 +173,6 @@ function setProp(tag: JsxTag, name: string, value: EditValue): void {
else tag.addAttribute({ name, initializer: initializerText(value) });
}
/** Where `generate` comes from — the module every project authors against. */
const GENERATE_MODULE = "@diffusionstudio/jsx";
/**
* Makes sure `generate` is in scope once a declaration has been spelled into
* the file: added to the module's existing import, or as an import of its own
* after the last one — or above the first statement, past the file's header
* comments, when there are no imports at all. Idempotent.
*/
function ensureGenerateImport(sourceFile: SourceFile): void {
const declarations = sourceFile.getImportDeclarations();
const importable = declarations.find(
(declaration) =>
declaration.getModuleSpecifierValue() === GENERATE_MODULE &&
!declaration.isTypeOnly() &&
!declaration.getNamespaceImport(),
);
if (importable) {
const named = importable.getNamedImports();
if (named.some((specifier) => specifier.getName() === "generate" && !specifier.getAliasNode())) return;
importable.addNamedImport("generate");
return;
}
const statement = `import { generate } from "${GENERATE_MODULE}";`;
const last = declarations.at(-1);
if (last) sourceFile.insertText(last.getEnd(), `\n${statement}`);
else {
const first = sourceFile.getStatements()[0];
sourceFile.insertText(first ? first.getStart() : 0, `${statement}\n\n`);
}
}
/**
* Text content as JSX spells it: bare when JSX would read it back verbatim,
* otherwise as a string expression (JSX collapses whitespace around line
@ -349,8 +184,10 @@ function jsxText(text: string): string {
/**
* Replaces what an element says between its tags; a self-closing one is opened
* up around the new text. Everything outside the body keeps its bytes, so an
* element that says something else is otherwise the element it was.
* up around the new text. Only the text is replaced: the elements it holds
* besides (its paint, a stroke, a range) stay, and so does everything outside
* the body, so an element that says something else is otherwise the element
* it was.
*/
function setText(sourceFile: SourceFile, tag: JsxTag, text: string): void {
const element = elementOf(tag);
@ -362,7 +199,44 @@ function setText(sourceFile: SourceFile, tag: JsxTag, text: string): void {
return;
}
sourceFile.replaceText([element.getOpeningElement().getEnd(), element.getClosingElement().getStart()], content);
const ranges = element.getJsxChildren().filter(isSaid).map(saidRange);
// Nothing said yet: it is said first, the way an insert spells it.
if (!ranges.length) {
if (content) sourceFile.insertText(element.getOpeningElement().getEnd(), content);
return;
}
// The first part says all of it and the rest say nothing. Later parts go
// first, so the positions of the earlier ones still hold.
for (const range of ranges.slice(1).reverse()) sourceFile.replaceText(range, "");
sourceFile.replaceText(ranges[0]!, content);
}
/**
* Whether a child of an element is part of what it says: text JSX keeps, or
* an expression with no element in it. A comment (an expression with nothing
* in it) says nothing.
*/
function isSaid(child: Node): boolean {
if (child.isKind(SyntaxKind.JsxText)) return !child.containsOnlyTriviaWhiteSpaces();
const expression = child.asKind(SyntaxKind.JsxExpression)?.getExpression();
if (!expression) return false;
return !JSX_KINDS.some((kind) => expression.isKind(kind) || expression.getFirstDescendantByKind(kind));
}
const JSX_KINDS = [SyntaxKind.JsxElement, SyntaxKind.JsxSelfClosingElement, SyntaxKind.JsxFragment] as const;
/**
* Where a part of what an element says is spelled. For text, that is without
* the whitespace JSX drops around line breaks: the layout of the body is the
* file's, not the text's.
*/
function saidRange(child: Node): [number, number] {
if (!child.isKind(SyntaxKind.JsxText)) return [child.getStart(), child.getEnd()];
const raw = child.getFullText();
const leading = /^[ \t]*\n\s*/.exec(raw)?.[0].length ?? 0;
const trailing = /\s*\n[ \t]*$/.exec(raw)?.[0].length ?? 0;
return [child.getPos() + leading, child.getEnd() - trailing];
}
// ---------------------------------------------------------------------------
@ -575,42 +449,11 @@ function isLiteral(node: Node): boolean {
return false;
}
/**
* A `generate.*` call over a literal spec: what the writer spells a
* declaration as, and so an initializer it may also overwrite. One whose
* argument computes anything is authored reactivity, like any expression.
*/
function isGenerateCall(node: Node): boolean {
const call = node.asKind(SyntaxKind.CallExpression);
const callee = call?.getExpression().asKind(SyntaxKind.PropertyAccessExpression);
if (!call || !callee || !callee.getExpression().isKind(SyntaxKind.Identifier)) return false;
if (callee.getExpression().getText() !== "generate") return false;
const args = call.getArguments();
return args.length === 1 && isLiteral(args[0]!);
}
/**
* A prop is only written back when the source holds a plain literal (or a
* declaration the writer itself spells). Anything else — a signal, a prop of
* the surrounding component, an expression — is someone's reactivity, and a
* drag has no business overwriting it.
*/
function isWritable(attribute: JsxAttribute): boolean {
const initializer = attribute.getInitializer();
if (!initializer) return true;
if (initializer.isKind(SyntaxKind.StringLiteral)) return true;
if (!initializer.isKind(SyntaxKind.JsxExpression)) return false;
const expression = initializer.getExpression();
return expression !== undefined && (isLiteral(expression) || isGenerateCall(expression));
}
// ---------------------------------------------------------------------------
// Files
/** Every project source file, project-relative and `/`-separated. */
async function sourceFiles(dir: string, prefix = ""): Promise<string[]> {
export async function sourceFiles(dir: string, prefix = ""): Promise<string[]> {
let entries;
try {
entries = await readdir(prefix ? join(dir, ...prefix.split("/")) : dir, { withFileTypes: true });
@ -731,9 +574,11 @@ class SourceWriter {
open.text = text;
// Claimed before the write lands: a watcher must never see this change
// arrive without knowing whose it was.
this.context.onWrite?.(path);
await writeFile(absolute(this.context.dir, path), text, "utf8");
// arrive without knowing whose it was, and what says whose it is are the
// bytes themselves — so they go with the claim. Written whole, because
// the same watcher reads the file straight back.
this.context.onWrite?.(path, text);
await writeFileAtomic(absolute(this.context.dir, path), text);
}
}
@ -779,10 +624,10 @@ class SourceWriter {
}
/**
* Writes prop values back into the JSX that produced them. Props whose source
* is an expression rather than a literal are reported as skipped and left
* alone; an element that is written to and has no id gets one, so that the
* next edit to renumber the file cannot strand it.
* Writes prop values back into the JSX that produced them, over whatever
* was there — a literal or an expression. An element that is written to and
* has no id gets one, so that the next edit to renumber the file cannot
* strand it.
*/
public async applyEdits(edits: SourceEdit[]): Promise<WriteResult> {
const skipped: string[] = [];
@ -911,14 +756,11 @@ class SourceWriter {
break;
}
const attribute = attributeOf(tag, name);
if (attribute && !isWritable(attribute)) {
skipped.push(`${edit.source} (${name})`);
continue;
}
// Whatever the source held for it: the user wins. An expression
// there (`x={MARGIN}`) is replaced by the value like a literal is —
// the canvas already shows the edit, and an export and the next open
// render the file, so a prop left as it was would move back.
setProp(tag, name, value);
if (isSerializedAssetRef(value)) ensureGenerateImport(sourceFile);
wrote = true;
}
@ -956,8 +798,8 @@ class SourceWriter {
/**
* Overwrites the initializer of an `@inspect`-annotated top-level const.
* False when no top-level const of that name carries the annotation, or when
* its initializer is not a literal anymore — an expression there is authored
* reactivity again, the same rule `isWritable` applies to a prop.
* its initializer is not a literal anymore: the annotation promises the
* inspector a value, and an expression there is no longer one.
*/
private setVariable(sourceFile: SourceFile, edit: SourceVariable): boolean {
for (const statement of sourceFile.getVariableStatements()) {
@ -1015,7 +857,6 @@ class SourceWriter {
insertChild(sourceFile, parent, child, before);
for (const [name, value] of Object.entries(edit.props)) {
setProp(findTag(sourceFile, id)!, name, value);
if (isSerializedAssetRef(value)) ensureGenerateImport(sourceFile);
}
ids[edit.source] = formatSource(file, id);
return true;
@ -1255,7 +1096,6 @@ class SourceWriter {
}
for (const [name, value] of Object.entries(record.props)) {
setProp(found(), name, value);
if (isSerializedAssetRef(value)) ensureGenerateImport(sourceFile);
}
const element = elementOf(found());

View File

@ -0,0 +1,64 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Code editors a project folder can be opened in. A project is a folder of
// JSX, so editing it by hand is a real way of working on it, and the app's
// watcher puts whatever the editor saves on the canvas.
import { app } from "electron";
import { execFile, spawn } from "node:child_process";
import { isAbsolute } from "node:path";
export type EditorId = "vscode" | "cursor" | "zed";
export type EditorInfo = { id: EditorId; label: string };
/**
* The editors offered, in menu order. Each is found by the URL scheme it
* registers with the OS when installed: asking who handles it answers both
* whether the editor is there and where, on macOS and Windows alike, without
* knowing where anyone keeps their applications.
*/
const EDITORS: Array<EditorInfo & { protocol: string }> = [
{ id: "vscode", label: "VS Code", protocol: "vscode://" },
{ id: "cursor", label: "Cursor", protocol: "cursor://" },
{ id: "zed", label: "Zed", protocol: "zed://" },
];
/** Where the app handling `protocol` lives (the .app on macOS, the .exe on Windows), or null when none does. */
async function handlerPath(protocol: string): Promise<string | null> {
try {
return (await app.getApplicationInfoForProtocol(protocol)).path || null;
} catch {
return null;
}
}
/** The editors installed here, in menu order. */
export async function installedEditors(): Promise<EditorInfo[]> {
const found = await Promise.all(EDITORS.map(async (editor) => ((await handlerPath(editor.protocol)) ? editor : null)));
return found.filter((editor) => editor !== null).map(({ id, label }) => ({ id, label }));
}
/** Opens the folder `dir` in the editor `id`. */
export async function openInEditor(id: EditorId, dir: string): Promise<void> {
const editor = EDITORS.find((candidate) => candidate.id === id);
if (!editor) throw new Error(`Unknown editor "${id}".`);
if (!isAbsolute(dir)) throw new Error(`The folder must be an absolute path (got "${dir}").`);
const path = await handlerPath(editor.protocol);
if (!path) throw new Error(`${editor.label} is not installed.`);
if (process.platform === "darwin") {
await new Promise<void>((resolve, reject) => {
execFile("/usr/bin/open", ["-a", path, dir], (error) => (error ? reject(error) : resolve()));
});
return;
}
// Windows: the editor's own executable takes a folder to open, and outlives the app.
const child = spawn(path, [dir], { detached: true, stdio: "ignore" });
child.on("error", (error) => console.error(`[editors] could not start ${editor.label}:`, error));
child.unref();
}

View File

@ -0,0 +1,136 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Projects from before generation was removed are pointed at what their
// declarations produced. The keys below are in the shape the generation code
// wrote them: the request, defaults applied, inputs by asset id.
import { tmpdir } from "node:os";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { migrateGenerations } from "./legacy-generations";
const FILE = "index.tsx";
const asset = (id: string, path: string, key?: string) => ({
id,
path,
source: `assets/${path}`,
type: "IMAGE",
mimeType: "image/png",
createdAt: "2026-01-01T00:00:00.000Z",
...(key ? { generation: { key, id: "run" } } : {}),
});
const HERO_KEY = JSON.stringify({ type: "image", model: "flux", prompt: "A neon city", aspectRatio: "16:9", seed: 7, refIds: [] });
const MOTION_KEY = JSON.stringify({ type: "video", model: "kling", prompt: "push in", aspectRatio: "16:9", duration: 5, audio: false, seed: 3, startFrameId: "hero01" });
const UPSCALE_KEY = JSON.stringify({ type: "upscale", inputId: "photo1" });
const MANIFEST = {
version: 1,
folders: [],
assets: [
asset("hero01", "generated/A neon city.png", HERO_KEY),
asset("motion", "generated/push in.mp4", MOTION_KEY),
asset("photo1", "photos/me.png"),
asset("upsc01", "generated/me (Upscaled).png", UPSCALE_KEY),
asset("capt01", "generated/Captions 1.json", "transcript:v1:intro:123"),
asset("capt02", "generated/Captions 2.json", "transcript:v1:outro:0"),
// A failed generation's record: no bytes, so no answer.
{ id: "fail01", path: "generated/a fox", type: "IMAGE", createdAt: "2026-01-01", generation: { key: "x" }, state: "error" },
],
};
let dir: string;
const written: string[] = [];
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), "legacy-generations-test-"));
written.length = 0;
});
afterEach(async () => {
await rm(dir, { recursive: true, force: true });
});
async function migrate(source: string, manifest: unknown = MANIFEST): Promise<string> {
await writeFile(join(dir, FILE), source);
await migrateGenerations({ dir, onWrite: (file) => written.push(file) }, manifest);
return readFile(join(dir, FILE), "utf8");
}
describe("migrateGenerations", () => {
it("points declarations at the assets they made, chains and consts included, and drops the import", async () => {
const text = await migrate(`import { For } from "solid-js";
import { generate, transform } from "@diffusionstudio/jsx";
const hero = generate.image({ prompt: "A neon city", aspectRatio: "16:9", seed: 7 });
const motion = generate.video({ prompt: "push in", startFrame: hero, seed: 3 });
export default () => (
<scene id="intro">
<video id="a" src={motion} />
<image id="b" src={transform.upscale("photos/me.png")} />
</scene>
);
`);
expect(text).toContain(`const hero = "generated/A neon city.png";`);
expect(text).toContain(`const motion = "generated/push in.mp4";`);
expect(text).toContain(`<image id="b" src="generated/me (Upscaled).png" />`);
expect(text).not.toContain("@diffusionstudio/jsx");
expect(text).toContain(`import { For } from "solid-js";`);
expect(written).toEqual([FILE]);
});
it("keeps a declaration nothing matches beside an empty source, so the project still loads", async () => {
const text = await migrate(`import { generate } from "@diffusionstudio/jsx";
export default () => <image id="c" src={generate.image({ prompt: "never made", seed: 1 })} />;
`);
expect(text).toContain(`src={"" /* no generated asset matched; generation was removed: generate.image({ prompt: "never made", seed: 1 }) */}`);
expect(text).not.toContain("import { generate }");
});
it("does not take a key whose recorded fields differ from what the call spells", async () => {
const text = await migrate(`import { generate } from "@diffusionstudio/jsx";
export default () => <image id="c" src={generate.image({ prompt: "A neon city", seed: 8 })} />;
`);
expect(text).not.toContain("A neon city.png");
});
it("gives a src-less caption the transcript of its scene and seed", async () => {
const text = await migrate(`export default () => (
<stage>
<scene id="intro"><captions id="c1" preset="classic" seed={123} /></scene>
<scene id="outro"><Captions id="c2" /></scene>
<scene id="other"><captions id="c3" /></scene>
</stage>
);
`);
expect(text).toContain(`<captions id="c1" preset="classic" src="generated/Captions 1.json" />`);
expect(text).toContain(`<Captions src="generated/Captions 2.json" id="c2" />`);
// No transcript was ever made for this scene: left as it was.
expect(text).toContain(`<captions id="c3" />`);
});
it("writes nothing to a migrated project, or without a readable library", async () => {
const source = `import { generate } from "@diffusionstudio/jsx";
export default () => <image id="c" src={generate.image({ prompt: "A neon city", seed: 7 })} />;
`;
expect(await migrate(source, null)).toBe(source);
expect(written).toEqual([]);
const migrated = await migrate(source);
expect(migrated).toContain(`src="generated/A neon city.png"`);
written.length = 0;
await migrateGenerations({ dir, onWrite: (file) => written.push(file) }, MANIFEST);
expect(written).toEqual([]);
});
});

View File

@ -0,0 +1,509 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* A one-time rewrite of projects written before generation was removed from
* the JSX. Those projects declare assets with `generate.*` / `transform.*`
* calls and caption scenes with a `<captions>` that has no `src`; neither
* loads any more. What they produced is still in the library: every asset a
* generation landed as carries its `generation.key` in `assets.yml`, the
* request as it was sent. So each declaration is matched against those keys
* and replaced by the library path of the asset it made, and each `src`-less
* `<captions>` gets the transcript its scene was given.
*
* Runs before every compile and writes nothing to a project with nothing left
* to migrate. A declaration that matches no asset is replaced by an empty
* source with the call kept beside it in a comment, so the project loads and
* nothing the user wrote is lost. Delete this file once projects from before
* the removal no longer need opening.
*/
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { Project, SyntaxKind } from "ts-morph";
import { ID_ATTR } from "@diffusionstudio/jsx";
import { writeFileAtomic } from "./atomic";
import { sourceFiles } from "./edit";
import type { CallExpression, JsxOpeningElement, JsxSelfClosingElement, Node, SourceFile } from "ts-morph";
import type { SourceContext } from "./edit-types";
/** The module the declarations were imported from. */
const JSX_MODULE = "@diffusionstudio/jsx";
/** Defaults the generation applied, and so baked into its key, when the call left them out. */
const DEFAULTS: Record<string, Record<string, unknown>> = {
image: { aspectRatio: "16:9" },
video: { aspectRatio: "16:9", duration: 5, audio: false },
};
/**
* Fields whose defaults lived in the app's model lists rather than here: when
* the call leaves one out, any value in the key is taken to be the default.
*/
const FREE_WHEN_OMITTED = new Set(["model", "voice"]);
type Namespace = "generate" | "transform";
/** A `generate.*` / `transform.*` call, with its argument read as a value. */
interface Declaration {
namespace: Namespace;
type: string;
node: CallExpression;
argument: unknown;
}
/** A value the source computes rather than spells; a declaration over one cannot be matched. */
const UNKNOWN = Symbol("unknown");
interface ManifestEntry {
id: string;
path: string;
key?: string;
}
/** What the library knows: entries newest first, as the manifest lists them. */
class Library {
private readonly entries: ManifestEntry[];
public constructor(entries: ManifestEntry[]) {
this.entries = entries;
}
/** The id of the asset an input named: an id, or a library path. */
public idOf(input: string): string | undefined {
const path = normalizePath(input);
return this.entries.find((entry) => entry.id === input || entry.path === path)?.id;
}
/** The newest asset whose generation key, parsed, satisfies `matches`. */
public generated(matches: (key: Record<string, unknown>) => boolean): ManifestEntry | undefined {
for (const entry of this.entries) {
if (!entry.key?.startsWith("{")) continue;
try {
const key = JSON.parse(entry.key) as unknown;
if (key && typeof key === "object" && matches(key as Record<string, unknown>)) return entry;
} catch {
// Not a key this migration knows how to read.
}
}
return undefined;
}
/** The transcript a scene was given under `key`. */
public byKey(key: string): ManifestEntry | undefined {
return this.entries.find((entry) => entry.key === key);
}
}
/** Library entries that have bytes and a generation key; anything else is no answer. */
function readEntries(manifest: unknown): ManifestEntry[] {
const assets = (manifest as { assets?: unknown } | null)?.assets;
if (!Array.isArray(assets)) return [];
return assets.flatMap((record): ManifestEntry[] => {
if (!record || typeof record !== "object") return [];
const r = record as Record<string, unknown>;
if (typeof r.id !== "string" || typeof r.path !== "string" || typeof r.source !== "string") return [];
const generation = r.generation as { key?: unknown } | undefined;
const key = typeof generation?.key === "string" ? generation.key : undefined;
return [{ id: r.id, path: normalizePath(r.path), key }];
});
}
const normalizePath = (path: string): string =>
path.replace(/\\/g, "/").split("/").filter((part) => part && part !== ".").join("/");
/** Whether the project might hold anything to migrate; saves parsing the rest. */
const mayNeedMigration = (text: string): boolean => text.includes(JSX_MODULE) || /<captions\b/i.test(text);
/**
* Rewrites every source file of the project that still declares generations
* or `src`-less captions. Returns the project-relative files it wrote.
*/
export async function migrateGenerations(context: SourceContext, manifest: unknown): Promise<string[]> {
// Without a readable library every declaration would look unmatched.
if (!Array.isArray((manifest as { assets?: unknown } | null)?.assets)) return [];
const library = new Library(readEntries(manifest));
const project = new Project({ useInMemoryFileSystem: true, skipLoadingLibFiles: true });
const written: string[] = [];
for (const path of await sourceFiles(context.dir)) {
const absolute = join(context.dir, ...path.split("/"));
let text: string;
try {
text = await readFile(absolute, "utf8");
} catch {
continue;
}
if (!mayNeedMigration(text)) continue;
const next = migrateText(project, path, text, library);
if (next === text) continue;
context.onWrite?.(path, next);
await writeFileAtomic(absolute, next);
written.push(path);
}
if (written.length) console.log(`[projects] migrated generated assets in ${written.join(", ")}`);
return written;
}
/** The file's text with its declarations and captions migrated; the same text when there is nothing to do. */
function migrateText(project: Project, path: string, text: string, library: Library): string {
const sourceFile = project.createSourceFile(`/${path}`, text, { overwrite: true });
try {
// A file mid-edit is not one to rewrite.
if (project.getProgram().getSyntacticDiagnostics(sourceFile).length) return text;
const edits = [...declarationEdits(sourceFile, library), ...captionEdits(sourceFile, library)];
if (!edits.length) return text;
let next = text;
for (const edit of outermost(edits).sort((a, b) => b.start - a.start)) {
next = next.slice(0, edit.start) + edit.text + next.slice(edit.end);
}
return dropUnusedImports(project, path, next);
} finally {
project.removeSourceFile(sourceFile);
}
}
interface TextEdit {
start: number;
end: number;
text: string;
}
/** Edits not inside another: replacing an outer call takes the calls inside it along. */
function outermost(edits: TextEdit[]): TextEdit[] {
return edits.filter((edit) => !edits.some((other) => other !== edit
&& other.start <= edit.start && edit.end <= other.end
&& (other.start !== edit.start || other.end !== edit.end)));
}
// ---------------------------------------------------------------------------
// Declarations
/** The local names `generate` and `transform` were imported under. */
function namespaces(sourceFile: SourceFile): Map<string, Namespace> {
const names = new Map<string, Namespace>();
for (const declaration of sourceFile.getImportDeclarations()) {
if (declaration.getModuleSpecifierValue() !== JSX_MODULE) continue;
for (const specifier of declaration.getNamedImports()) {
const imported = specifier.getName();
if (imported !== "generate" && imported !== "transform") continue;
names.set(specifier.getAliasNode()?.getText() ?? imported, imported);
}
}
return names;
}
function declarationEdits(sourceFile: SourceFile, library: Library): TextEdit[] {
const names = namespaces(sourceFile);
if (!names.size) return [];
const declarations = new Map<CallExpression, Declaration>();
const read = (node: Node, seen: Set<Node>): unknown => readValue(node, names, declarations, seen);
for (const call of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {
read(call, new Set());
}
const paths = new Map<Declaration, string | undefined>();
const resolve = (declaration: Declaration): string | undefined => {
if (!paths.has(declaration)) paths.set(declaration, match(declaration, library, resolve));
return paths.get(declaration);
};
return [...declarations.values()].map((declaration) => {
const path = resolve(declaration);
return replacement(declaration.node, path, path === undefined ? declaration.node.getText() : undefined);
});
}
/**
* A node read as the value it spells: literals, arrays, object literals, a
* const it names (followed in this file), or a declaration. `UNKNOWN` for
* anything the source computes.
*/
function readValue(
node: Node,
names: Map<string, Namespace>,
declarations: Map<CallExpression, Declaration>,
seen: Set<Node>,
): unknown {
const read = (child: Node): unknown => readValue(child, names, declarations, seen);
if (node.isKind(SyntaxKind.ParenthesizedExpression)) return read(node.getExpression());
if (node.isKind(SyntaxKind.AsExpression) || node.isKind(SyntaxKind.SatisfiesExpression)) return read(node.getExpression());
if (node.isKind(SyntaxKind.StringLiteral) || node.isKind(SyntaxKind.NoSubstitutionTemplateLiteral)) return node.getLiteralValue();
if (node.isKind(SyntaxKind.NumericLiteral)) return node.getLiteralValue();
if (node.isKind(SyntaxKind.TrueKeyword)) return true;
if (node.isKind(SyntaxKind.FalseKeyword)) return false;
if (node.isKind(SyntaxKind.NullKeyword)) return null;
if (node.isKind(SyntaxKind.Identifier) && node.getText() === "undefined") return undefined;
if (node.isKind(SyntaxKind.PrefixUnaryExpression) && node.getOperatorToken() === SyntaxKind.MinusToken) {
const operand = read(node.getOperand());
return typeof operand === "number" ? -operand : UNKNOWN;
}
if (node.isKind(SyntaxKind.ArrayLiteralExpression)) {
const items = node.getElements().map(read);
return items.includes(UNKNOWN) ? UNKNOWN : items;
}
if (node.isKind(SyntaxKind.ObjectLiteralExpression)) {
const object: Record<string, unknown> = {};
for (const property of node.getProperties()) {
if (property.isKind(SyntaxKind.PropertyAssignment)) {
const name = property.getNameNode();
if (name.isKind(SyntaxKind.ComputedPropertyName)) return UNKNOWN;
const key = name.isKind(SyntaxKind.StringLiteral) ? name.getLiteralValue() : name.getText();
object[key] = read(property.getInitializerOrThrow());
} else if (property.isKind(SyntaxKind.ShorthandPropertyAssignment)) {
object[property.getName()] = read(property.getNameNode());
} else {
return UNKNOWN;
}
}
return Object.values(object).includes(UNKNOWN) ? UNKNOWN : object;
}
// A const, followed to its initializer once: a cycle reads as unknown.
if (node.isKind(SyntaxKind.Identifier)) {
const initializer = constInitializer(node);
if (!initializer || seen.has(initializer)) return UNKNOWN;
seen.add(initializer);
return read(initializer);
}
if (node.isKind(SyntaxKind.CallExpression)) {
const known = declarations.get(node);
if (known) return known;
const callee = node.getExpression().asKind(SyntaxKind.PropertyAccessExpression);
const namespace = callee && names.get(callee.getExpression().getText());
if (!callee || !namespace || !callee.getExpression().isKind(SyntaxKind.Identifier)) return UNKNOWN;
const [argument] = node.getArguments();
const declaration: Declaration = {
namespace,
type: callee.getName(),
node,
argument: argument ? read(argument) : UNKNOWN,
};
declarations.set(node, declaration);
return declaration;
}
return UNKNOWN;
}
/** The initializer of the top-level or block-scoped `const` an identifier names, in its own file. */
function constInitializer(identifier: Node): Node | undefined {
const symbol = identifier.getSymbol();
const declaration = symbol?.getDeclarations()[0]?.asKind(SyntaxKind.VariableDeclaration);
if (!declaration || declaration.getVariableStatement()?.getDeclarationKind() !== "const") return undefined;
if (!declaration.getNameNode().isKind(SyntaxKind.Identifier)) return undefined;
return declaration.getInitializer();
}
const isDeclaration = (value: unknown): value is Declaration =>
typeof value === "object" && value !== null && "namespace" in value && "node" in value;
/**
* The library path of the asset a declaration made, or undefined when no
* generation key matches it. Inputs are matched first, by id, which is how
* the key recorded them.
*/
function match(
declaration: Declaration,
library: Library,
resolve: (declaration: Declaration) => string | undefined,
): string | undefined {
const idOf = (input: unknown): string | undefined => {
if (typeof input === "string") return library.idOf(input);
if (isDeclaration(input)) {
const path = resolve(input);
return path === undefined ? undefined : library.idOf(path);
}
return undefined;
};
const { type, argument } = declaration;
if (declaration.namespace === "transform") {
const inputId = idOf(argument);
if (inputId === undefined) return undefined;
return library.generated((key) => key.type === type && key.inputId === inputId && Object.keys(key).length === 2)?.path;
}
if (!argument || typeof argument !== "object" || isDeclaration(argument) || Array.isArray(argument)) return undefined;
const options = argument as Record<string, unknown>;
if (typeof options.prompt !== "string") return undefined;
// What the key must hold, field by field; `undefined` means it must not hold the field.
const expected: Record<string, unknown> = { type, ...DEFAULTS[type] };
for (const [name, value] of Object.entries(options)) {
if (name === "refs" || name === "startFrame" || name === "endFrame") continue;
expected[name] = value;
}
expected.seed = options.seed;
switch (type) {
case "image": {
const refs = Array.isArray(options.refs) ? options.refs : [];
const refIds = refs.map(idOf);
if (refIds.includes(undefined)) return undefined;
expected.refIds = refIds;
break;
}
case "video": {
for (const [option, field] of [["startFrame", "startFrameId"], ["endFrame", "endFrameId"]] as const) {
if (options[option] === undefined) {
expected[field] = undefined;
continue;
}
const id = idOf(options[option]);
if (id === undefined) return undefined;
expected[field] = id;
}
break;
}
case "audio":
expected.duration = options.duration;
break;
case "voice":
break;
default:
return undefined;
}
return library.generated((key) => Object.entries(expected).every(([name, value]) => {
if (value === undefined) return FREE_WHEN_OMITTED.has(name) || !(name in key);
return JSON.stringify(key[name]) === JSON.stringify(value);
}))?.path;
}
/**
* The edit putting `path` where the call was: an attribute's `{call}` becomes
* `"path"`, anything else the string literal. With no path, an empty source
* stands in and the call is kept beside it in a comment.
*/
function replacement(call: CallExpression, path: string | undefined, unmatched?: string): TextEdit {
const comment = unmatched === undefined
? ""
: ` /* no generated asset matched; generation was removed: ${unmatched.replace(/\*\//g, "* /")} */`;
const literal = JSON.stringify(path ?? "");
const expression = call.getParent()?.asKind(SyntaxKind.JsxExpression);
if (expression?.getParent()?.isKind(SyntaxKind.JsxAttribute)) {
if (!comment && path !== undefined && !/["&\p{Cc}\u2028\u2029]/u.test(path)) {
return { start: expression.getStart(), end: expression.getEnd(), text: literal };
}
return { start: call.getStart(), end: call.getEnd(), text: literal + comment };
}
return { start: call.getStart(), end: call.getEnd(), text: literal + comment };
}
// ---------------------------------------------------------------------------
// Captions
type JsxTag = JsxOpeningElement | JsxSelfClosingElement;
const lower = (tag: JsxTag): string => tag.getTagNameNode().getText().toLowerCase();
const idOf = (tag: JsxTag): string | undefined =>
tag.getAttribute(ID_ATTR)?.asKind(SyntaxKind.JsxAttribute)?.getInitializer()?.asKind(SyntaxKind.StringLiteral)?.getLiteralValue();
/**
* A `<captions>` without a `src` used to transcribe its scene, keyed by the
* scene's id and the caption's `seed`. The transcript is in the library under
* that key; the caption is pointed at it and loses the `seed`.
*/
function captionEdits(sourceFile: SourceFile, library: Library): TextEdit[] {
const edits: TextEdit[] = [];
const tags: JsxTag[] = [
...sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement),
...sourceFile.getDescendantsOfKind(SyntaxKind.JsxOpeningElement),
];
for (const tag of tags) {
if (lower(tag) !== "captions") continue;
const attributes = tag.getAttributes();
if (tag.getAttribute("src") || attributes.some((attribute) => attribute.isKind(SyntaxKind.JsxSpreadAttribute))) continue;
const sceneId = enclosingSceneId(tag);
if (sceneId === undefined) continue;
const seedAttribute = tag.getAttribute("seed")?.asKind(SyntaxKind.JsxAttribute);
let seed = 0;
if (seedAttribute) {
const value = seedAttribute.getInitializer()?.asKind(SyntaxKind.JsxExpression)?.getExpression();
const literal = value?.asKind(SyntaxKind.NumericLiteral)?.getLiteralValue();
if (literal === undefined) continue;
seed = literal;
}
const transcript = library.byKey(`transcript:v1:${sceneId}:${seed}`);
if (!transcript) continue;
const src = `src=${JSON.stringify(transcript.path)}`;
if (seedAttribute) {
edits.push({ start: seedAttribute.getStart(), end: seedAttribute.getEnd(), text: src });
} else {
const at = tag.getTagNameNode().getEnd();
edits.push({ start: at, end: at, text: ` ${src}` });
}
}
return edits;
}
/** The id of the `<scene>` element a tag sits inside, in the same JSX tree. */
function enclosingSceneId(tag: JsxTag): string | undefined {
for (const ancestor of tag.getAncestors()) {
const opening = ancestor.asKind(SyntaxKind.JsxElement)?.getOpeningElement();
if (opening && lower(opening) === "scene") return idOf(opening);
}
return undefined;
}
// ---------------------------------------------------------------------------
// Imports
/** Takes `generate` / `transform` out of the imports once nothing uses them. */
function dropUnusedImports(project: Project, path: string, text: string): string {
const sourceFile = project.createSourceFile(`/${path}`, text, { overwrite: true });
try {
for (const declaration of sourceFile.getImportDeclarations()) {
if (declaration.getModuleSpecifierValue() !== JSX_MODULE) continue;
let removed = false;
for (const specifier of declaration.getNamedImports()) {
const name = specifier.getName();
if (name !== "generate" && name !== "transform") continue;
const local = specifier.getAliasNode()?.getText() ?? name;
const used = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)
.some((identifier) => identifier.getText() === local && !identifier.getFirstAncestorByKind(SyntaxKind.ImportDeclaration));
if (used) continue;
specifier.remove();
removed = true;
}
// Only an import this emptied goes; one that imported nothing by name was never ours.
if (removed && !declaration.getNamedImports().length && !declaration.getDefaultImport() && !declaration.getNamespaceImport()) {
declaration.remove();
}
}
return sourceFile.getFullText();
} finally {
project.removeSourceFile(sourceFile);
}
}

View File

@ -7,10 +7,13 @@
// through these via an envelope carrying the logical MAIN_CHANNELS name and
// (for requests) a UUID for correlation.
//
// CLI traffic uses a separate wire pair (CLI_WIRE in @diffusionstudio/cli/protocol);
// main forwards it opaquely without inspecting channel names.
import type { LogEntry, ScreenshotResult } from "@diffusionstudio/cli/protocol";
import type { SourceEdit, WriteResult } from "./edit";
// Tool calls from the MCP server use their own wire (DAPI_WIRE in
// @diffusionstudio/dapi), in the other direction: main asks, the renderer answers.
import type { LogEntry, ScreenshotResult } from "@diffusionstudio/dapi";
import type { SourceEdit, WriteResult } from "./edit-types";
import type { AgentId } from "./mcp-config";
import type { EditorId, EditorInfo } from "./editors";
import type { MissingProjectChoice, SaveAction } from "./projects";
export const MAIN_WIRE = {
REQUEST: "main:request",
@ -23,34 +26,39 @@ export type MainWireChannel = (typeof MAIN_WIRE)[keyof typeof MAIN_WIRE];
// Logical channels. Two categories:
// • Renderer→Main requests (request + response)
// • Main→Renderer events (push, no response)
// Renderer-state queries used to live here; they now answer CLI requests
// directly via the CLI bridge.
// Tool calls are not here: they arrive from main over DAPI_WIRE and are
// answered by the renderer's handlers (apps/web/src/dapi).
export const MAIN_CHANNELS = {
// Renderer→Main requests
APP_OPEN_EXTERNAL: "app:open-external",
APP_SHOW_IN_FOLDER: "app:show-in-folder",
APP_EDITORS_LIST: "app:editors-list",
APP_OPEN_IN_EDITOR: "app:open-in-editor",
ANALYTICS_CONFIGURE: "analytics:configure",
AUTH_GET_PENDING_CALLBACK: "auth:get-pending-callback",
CHECKOUT_GET_PENDING_CALLBACK: "checkout:get-pending-callback",
CLI_IS_INSTALLED: "cli:is-installed",
CLI_INSTALL: "cli:install",
SKILLS_IS_INSTALLED: "skills:is-installed",
SKILLS_INSTALL: "skills:install",
WINDOW_IS_FULLSCREEN: "window:is-fullscreen",
WINDOW_SET_COLOR_MODE: "window:set-color-mode",
WINDOW_CAPTURE: "window:capture",
WINDOW_SET_BUSY: "window:set-busy",
WINDOW_SHOW: "window:show",
CLIPBOARD_PATHS: "clipboard:paths",
FILE_TRANSFER: "file:transfer",
FILE_WRITE_OPEN: "file:write-open",
FILE_WRITE_CHUNK: "file:write-chunk",
FILE_WRITE_CLOSE: "file:write-close",
FILE_WRITE_ABORT: "file:write-abort",
HEADLESS_GET_MODE: "headless:get-mode",
LOGS_GET: "logs:get",
PROJECTS_PICK_ROOT: "projects:pick-root",
PROJECTS_DEFAULT_ROOT: "projects:default-root",
PROJECTS_LIST: "projects:list",
PROJECTS_PICK_FOLDER: "projects:pick-folder",
PROJECTS_GET: "projects:get",
PROJECTS_INIT: "projects:init",
PROJECTS_RESOLVE: "projects:resolve",
PROJECTS_FIND_MOVED: "projects:find-moved",
PROJECTS_ASK_MISSING: "projects:ask-missing",
PROJECTS_CREATE: "projects:create",
PROJECTS_PICK_SAVE: "projects:pick-save",
PROJECTS_SAVE: "projects:save",
PROJECTS_MOVE: "projects:move",
PROJECTS_RENAME: "projects:rename",
PROJECTS_DUPLICATE: "projects:duplicate",
PROJECTS_DELETE: "projects:delete",
@ -66,19 +74,24 @@ export const MAIN_CHANNELS = {
PROJECTS_FS_STAT: "projects:fs-stat",
PROJECTS_FS_REMOVE: "projects:fs-remove",
PROJECTS_FS_REAL_PATH: "projects:fs-real-path",
AGENT_CHAT_ENDPOINT: "agent-chat:endpoint",
MCP_STATUS: "mcp:status",
MCP_APPLY: "mcp:apply",
CLI_STATUS: "cli:status",
CLI_INSTALL: "cli:install",
CLI_UNINSTALL: "cli:uninstall",
// Main→Renderer events
AUTH_CALLBACK: "auth:callback",
CHECKOUT_CALLBACK: "checkout:callback",
WINDOW_FULLSCREEN_CHANGE: "window:fullscreen-change",
HEADLESS_MODE: "headless:mode",
PROJECTS_CHANGED: "projects:changed",
} as const;
/**
* A project folder under the projects root: a real npm package with a JSX
* entry. Its package.json is the project record: `projectId` is what the
* project is, `displayName` the human name, `main` the entry file.
* A project folder, wherever it lives: a real npm package with a JSX entry.
* Its package.json is the project record: `projectId` is what the project
* is, `displayName` the human name, `main` the entry file.
*/
export type ProjectInfo = {
/**
@ -87,7 +100,7 @@ export type ProjectInfo = {
* since — `PROJECTS_RESOLVE` is what gives one out.
*/
id: string;
/** Folder name. Renaming the project moves it, so it is not the identity. */
/** Folder name. The user can move or rename it, so it is not the identity. */
name: string;
/** Human name from package.json `displayName` (falls back to the folder name). */
displayName: string;
@ -99,44 +112,104 @@ export type ProjectInfo = {
modifiedAt: string;
/** birthtime of the folder, ISO string. */
createdAt: string;
/**
* Whether the folder is a draft's: in the app's drafts folder, named after
* the id, until the user saves it somewhere of their choosing.
*/
draft: boolean;
};
export type CompileResult =
| { ok: true; code: string }
| { ok: false; error: string };
{ ok: true; code: string } | { ok: false; error: string };
// Outcome of linking the bundled dapi CLI into PATH. "cancelled" means the
export type { SourceEdit, WriteResult };
export type { AgentId };
export type { EditorId, EditorInfo };
export type { MissingProjectChoice };
// One agent the settings page lists: whether it is set up on this machine,
// whether its config already carries the app's MCP entry, and — for the
// agents that need the bundled `dapi` binary — why this build cannot
// connect it (null when it can).
export type McpAgentStatus = {
id: AgentId;
label: string;
detected: boolean;
connected: boolean;
/** Absolute path of the config file the entry goes into. */
config: string;
unavailable: string | null;
};
/** `url` is the HTTP endpoint any other agent can be pointed at by hand. */
export type McpStatus = { url: string; agents: McpAgentStatus[] };
export type McpApplyRequest = { add: AgentId[]; remove: AgentId[] };
// Per agent: written, taken out, or left as it was with the reason.
export type McpApplyResult = {
added: AgentId[];
removed: AgentId[];
failures: { id: AgentId; error: string }[];
};
// Where the `diffusion` command stands. `managed` means what is there is a
// symlink (the app's own, or the dev workflow's Homebrew link), which
// "Uninstall" can remove; `available` that this build can create the app's
// link (a dev build cannot: that is `npm run link` in apps/cli).
export type CliStatus = {
installed: boolean;
path: string | null;
managed: boolean;
available: boolean;
};
// Outcome of linking the bundled diffusion CLI into PATH. "cancelled" means the
// user dismissed the macOS admin prompt — not an error, not installed.
export type CliInstallResult =
| { status: "installed" }
| { status: "cancelled" }
| { status: "error"; error: string };
// Outcome of symlinking the bundled skills into the agent skill directories.
export type SkillsInstallResult =
| { status: "installed" }
// Outcome of taking the symlink back out. "absent" means there was none to
// remove; "cancelled" that the admin prompt was dismissed and it stays.
export type CliUninstallResult =
| { status: "removed" }
| { status: "absent" }
| { status: "cancelled" }
| { status: "error"; error: string };
export type { SourceEdit, WriteResult };
export type MainChannel = (typeof MAIN_CHANNELS)[keyof typeof MAIN_CHANNELS];
// Events fed by a `diffusion://` deep link. Main routes each link to exactly
// one of these by its host, so auth and checkout never consume each other's.
export type DeepLinkChannel =
| typeof MAIN_CHANNELS.AUTH_CALLBACK
| typeof MAIN_CHANNELS.CHECKOUT_CALLBACK;
typeof MAIN_CHANNELS.AUTH_CALLBACK | typeof MAIN_CHANNELS.CHECKOUT_CALLBACK;
export type MainRequestMap = {
[MAIN_CHANNELS.APP_OPEN_EXTERNAL]: { request: { url: string }; response: void };
[MAIN_CHANNELS.AUTH_GET_PENDING_CALLBACK]: { request: void; response: string | null };
[MAIN_CHANNELS.CHECKOUT_GET_PENDING_CALLBACK]: { request: void; response: string | null };
[MAIN_CHANNELS.CLI_IS_INSTALLED]: { request: void; response: boolean };
[MAIN_CHANNELS.CLI_INSTALL]: { request: void; response: CliInstallResult };
[MAIN_CHANNELS.SKILLS_IS_INSTALLED]: { request: void; response: boolean };
[MAIN_CHANNELS.SKILLS_INSTALL]: { request: void; response: SkillsInstallResult };
[MAIN_CHANNELS.APP_OPEN_EXTERNAL]: {
request: { url: string };
response: void;
};
// Where main sends events and as whom: on launch and every auth change.
[MAIN_CHANNELS.ANALYTICS_CONFIGURE]: {
request: { apiUrl: string; token: string | null };
response: void;
};
[MAIN_CHANNELS.AUTH_GET_PENDING_CALLBACK]: {
request: void;
response: string | null;
};
[MAIN_CHANNELS.CHECKOUT_GET_PENDING_CALLBACK]: {
request: void;
response: string | null;
};
[MAIN_CHANNELS.WINDOW_IS_FULLSCREEN]: { request: void; response: boolean };
[MAIN_CHANNELS.WINDOW_SET_COLOR_MODE]: { request: { mode: "light" | "dark" }; response: void };
[MAIN_CHANNELS.WINDOW_CAPTURE]: { request: void; response: ScreenshotResult };
[MAIN_CHANNELS.WINDOW_SET_BUSY]: { request: { busy: boolean }; response: void };
[MAIN_CHANNELS.WINDOW_SHOW]: { request: void; response: void };
[MAIN_CHANNELS.CLIPBOARD_PATHS]: { request: void; response: string[] };
[MAIN_CHANNELS.FILE_TRANSFER]: {
request: { selector: string; absolutePath: string };
response: void;
@ -158,51 +231,140 @@ export type MainRequestMap = {
response: void;
};
// Reveals a file or folder in the OS file manager (Finder on macOS).
[MAIN_CHANNELS.APP_SHOW_IN_FOLDER]: { request: { path: string }; response: void };
[MAIN_CHANNELS.HEADLESS_GET_MODE]: { request: void; response: boolean };
[MAIN_CHANNELS.APP_SHOW_IN_FOLDER]: {
request: { path: string };
response: void;
};
// The code editors installed here that a folder can be opened in.
[MAIN_CHANNELS.APP_EDITORS_LIST]: {
request: void;
response: EditorInfo[];
};
[MAIN_CHANNELS.APP_OPEN_IN_EDITOR]: {
request: { id: EditorId; dir: string };
response: void;
};
[MAIN_CHANNELS.LOGS_GET]: { request: void; response: LogEntry[] };
[MAIN_CHANNELS.PROJECTS_PICK_ROOT]: { request: void; response: string | null };
[MAIN_CHANNELS.PROJECTS_DEFAULT_ROOT]: { request: void; response: string | null };
[MAIN_CHANNELS.PROJECTS_LIST]: { request: { root: string }; response: ProjectInfo[] };
[MAIN_CHANNELS.PROJECTS_GET]: { request: { dir: string }; response: ProjectInfo | null };
[MAIN_CHANNELS.PROJECTS_INIT]: { request: { dir: string }; response: ProjectInfo };
[MAIN_CHANNELS.PROJECTS_RESOLVE]: {
request: { root: string; ref: string };
[MAIN_CHANNELS.PROJECTS_PICK_FOLDER]: {
request: void;
response: string | null;
};
[MAIN_CHANNELS.PROJECTS_GET]: {
request: { dir: string };
response: ProjectInfo | null;
};
[MAIN_CHANNELS.PROJECTS_CREATE]: {
request: { root: string; displayName: string };
[MAIN_CHANNELS.PROJECTS_INIT]: {
request: { dir: string };
response: ProjectInfo;
};
[MAIN_CHANNELS.PROJECTS_RESOLVE]: {
request: { dir: string };
response: ProjectInfo | null;
};
// The project `id` in a folder beside `dir`, which no longer holds it (a
// folder renamed or moved in Finder); null when none does.
[MAIN_CHANNELS.PROJECTS_FIND_MOVED]: {
request: { dir: string; id: string };
response: ProjectInfo | null;
};
// Asks what to do about a project whose folder can't be found.
[MAIN_CHANNELS.PROJECTS_ASK_MISSING]: {
request: { displayName: string; dir: string };
response: MissingProjectChoice;
};
// A new project, as a draft called "Untitled" until it is saved.
[MAIN_CHANNELS.PROJECTS_CREATE]: {
request: void;
response: ProjectInfo;
};
// Where to save a draft, or move a saved project; `name` fills the picker.
[MAIN_CHANNELS.PROJECTS_PICK_SAVE]: {
request: { dir: string; name: string; startIn: string | null; action: SaveAction };
response: string | null;
};
[MAIN_CHANNELS.PROJECTS_SAVE]: {
request: { dir: string; target: string };
response: ProjectInfo;
};
[MAIN_CHANNELS.PROJECTS_MOVE]: {
request: { dir: string; target: string };
response: ProjectInfo;
};
// Renames the project: `displayName` in the record, and the folder with it.
[MAIN_CHANNELS.PROJECTS_RENAME]: {
request: { dir: string; displayName: string };
response: ProjectInfo;
};
[MAIN_CHANNELS.PROJECTS_DUPLICATE]: { request: { dir: string }; response: ProjectInfo };
[MAIN_CHANNELS.PROJECTS_DUPLICATE]: {
request: { dir: string };
response: ProjectInfo;
};
[MAIN_CHANNELS.PROJECTS_DELETE]: { request: { dir: string }; response: void };
[MAIN_CHANNELS.PROJECTS_COMPILE]: { request: { dir: string }; response: CompileResult };
[MAIN_CHANNELS.PROJECTS_COMPILE]: {
request: { dir: string };
response: CompileResult;
};
[MAIN_CHANNELS.PROJECTS_WRITE]: {
request: { dir: string; edits: SourceEdit[] };
response: WriteResult;
};
[MAIN_CHANNELS.PROJECTS_WATCH]: { request: { dir: string }; response: void };
[MAIN_CHANNELS.PROJECTS_UNWATCH]: { request: { dir: string }; response: void };
[MAIN_CHANNELS.PROJECTS_UNWATCH]: {
request: { dir: string };
response: void;
};
// The asset manifest (`assets.yml`) as plain data; null when there is none.
[MAIN_CHANNELS.PROJECTS_MANIFEST_READ]: { request: { dir: string }; response: unknown };
[MAIN_CHANNELS.PROJECTS_MANIFEST_WRITE]: { request: { dir: string; manifest: unknown }; response: void };
[MAIN_CHANNELS.PROJECTS_MANIFEST_READ]: {
request: { dir: string };
response: unknown;
};
[MAIN_CHANNELS.PROJECTS_MANIFEST_WRITE]: {
request: { dir: string; manifest: unknown };
response: void;
};
// The project's config: the `diffusion` field of its package.json, as
// parsed (null when absent). The renderer owns its shape; see
// `engine/project-config` in the web app.
[MAIN_CHANNELS.PROJECTS_CONFIG_READ]: { request: { dir: string }; response: unknown };
[MAIN_CHANNELS.PROJECTS_CONFIG_WRITE]: { request: { dir: string; config: unknown }; response: void };
[MAIN_CHANNELS.PROJECTS_CONFIG_READ]: {
request: { dir: string };
response: unknown;
};
[MAIN_CHANNELS.PROJECTS_CONFIG_WRITE]: {
request: { dir: string; config: unknown };
response: void;
};
// Project file system, for the asset library. `source` is project-relative
// or absolute; `path` is always project-relative. Writes stream through the
// FILE_WRITE_* channels (which create parent directories).
[MAIN_CHANNELS.PROJECTS_FS_LIST]: { request: { dir: string; source: string }; response: FsEntry[] };
[MAIN_CHANNELS.PROJECTS_FS_STAT]: { request: { dir: string; source: string }; response: FsStat | null };
[MAIN_CHANNELS.PROJECTS_FS_REMOVE]: { request: { dir: string; path: string }; response: void };
[MAIN_CHANNELS.PROJECTS_FS_REAL_PATH]: { request: { dir: string; source: string }; response: string | null };
[MAIN_CHANNELS.PROJECTS_FS_LIST]: {
request: { dir: string; source: string };
response: FsEntry[];
};
[MAIN_CHANNELS.PROJECTS_FS_STAT]: {
request: { dir: string; source: string };
response: FsStat | null;
};
[MAIN_CHANNELS.PROJECTS_FS_REMOVE]: {
request: { dir: string; path: string };
response: void;
};
[MAIN_CHANNELS.PROJECTS_FS_REAL_PATH]: {
request: { dir: string; source: string };
response: string | null;
};
// Where the agent chat host listens (`ws://127.0.0.1:PORT/?token=…`); null
// while it is starting or restarting. The only desktop IPC the chat uses.
[MAIN_CHANNELS.AGENT_CHAT_ENDPOINT]: {
request: void;
response: { url: string } | null;
};
// The app's MCP server in the agents' configs (see mcp-install.ts), and
// the `diffusion` command on PATH (see cli-install.ts). The install/uninstall
// calls put the macOS admin prompt on screen.
[MAIN_CHANNELS.MCP_STATUS]: { request: void; response: McpStatus };
[MAIN_CHANNELS.MCP_APPLY]: { request: McpApplyRequest; response: McpApplyResult };
[MAIN_CHANNELS.CLI_STATUS]: { request: void; response: CliStatus };
[MAIN_CHANNELS.CLI_INSTALL]: { request: void; response: CliInstallResult };
[MAIN_CHANNELS.CLI_UNINSTALL]: { request: void; response: CliUninstallResult };
};
export type FsEntry = {
@ -220,7 +382,6 @@ export type MainEventMap = {
[MAIN_CHANNELS.AUTH_CALLBACK]: { url: string };
[MAIN_CHANNELS.CHECKOUT_CALLBACK]: { url: string };
[MAIN_CHANNELS.WINDOW_FULLSCREEN_CHANGE]: { fullscreen: boolean };
[MAIN_CHANNELS.HEADLESS_MODE]: { active: boolean };
// A file inside a watched project folder changed (path relative to `dir`).
[MAIN_CHANNELS.PROJECTS_CHANGED]: { dir: string; path: string };
};

View File

@ -4,33 +4,46 @@
import { app, BrowserWindow, nativeImage, session, shell } from "electron";
import { dirname, join } from "node:path";
import { mkdir, open, unlink } from "node:fs/promises";
import { existsSync } from "node:fs";
import { mkdir, open, rename, unlink } from "node:fs/promises";
import { randomUUID } from "node:crypto";
import type { FileHandle } from "node:fs/promises";
import { updateElectronApp } from "update-electron-app";
import { startCliServer, stopCliServer, isHeadless } from "./cli-server";
import { installCli, isCliInstalled } from "./cli-install";
import { healSkillsLinks, installSkills, isSkillsInstalled } from "./skills-install";
import { trackInstall } from "./analytics";
import type { IUpdateInfo } from "update-electron-app";
import { makeUserNotifier, updateElectronApp } from "update-electron-app";
import { tempPathFor } from "./atomic";
import { DapiServer } from "./dapi/server";
import { agentChatEndpoint, configureAgentChat, deleteProjectChats, stopAgentChat } from "./agent-chat";
import { cliStatus, installCli, refreshCliShim, uninstallCli } from "./cli-install";
import { applyMcp, healMcpRegistrations, mcpStatus } from "./mcp-install";
import { configureAnalytics, countCanvasEdits, startAnalytics, track } from "./analytics";
import { setupAppMenu } from "./menu";
import { clipboardPaths } from "./clipboard";
import { installedEditors, openInEditor } from "./editors";
import { AppTray } from "./tray";
import { WindowHost } from "./window-host";
import { handleSquirrelEvent } from "./squirrel";
import { mainBridge } from "./main-manager";
import { MAIN_CHANNELS } from "./main-channels";
import {
compileProject,
createProject,
defaultRoot,
deleteProject,
duplicateProject,
getProject,
askAboutMissingProject,
findMovedProject,
initProject,
listProjects,
pickRoot,
pickFolder,
pickSaveLocation,
renameProject,
resolveProject,
saveProject,
moveProject,
unwatchAll,
listEntries,
realPathEntry,
markSelfWriteAbsolute,
noteContent,
noteRenamed,
readConfig,
readManifest,
removeEntry,
@ -42,12 +55,27 @@ import {
writeProject,
} from "./projects";
import type { DeepLinkChannel } from "./main-channels";
import type { LogEntry } from "@diffusionstudio/cli/protocol";
import type { LogEntry } from "@diffusionstudio/dapi";
const DEV_URL = "http://localhost:5173";
const WINDOW_IDLE_MS = 10 * 60 * 1000;
const AUTH_PROTOCOL = "diffusion";
const MACOS_CORNER_RADIUS = 18;
const MACOS_BACKDROP = { blur: 80, red: 0.07, green: 0.07, blue: 0.07, alpha: 0.9 };
// Window Controls Overlay on Windows: as tall as the renderer's `h-10` drag
// strip, coloured like the sidebar it sits on (`--sidebar`), with symbols in
// `--muted-foreground` like the other title bar icons. The dark value is that
// token flattened onto the sidebar, since the overlay takes opaque colours.
const WINDOWS_OVERLAY_HEIGHT = 40;
const WINDOWS_OVERLAY_COLORS = {
dark: { color: "#121212", symbolColor: "#a1a1a1" },
light: { color: "#f7f7f7", symbolColor: "#737373" },
};
// A Squirrel.Windows install/update/uninstall launch: housekeeping only, the
// app quits on its own. Decided first so nothing below starts a service or
// checks for updates on a launch that is about to end.
const squirrelLaunch = handleSquirrelEvent();
app.setName("Diffusion Studio");
app.commandLine.appendSwitch("enable-blink-features", "CanvasDrawElement");
@ -79,13 +107,55 @@ function applyBackdrop() {
setNativeBackdrop(mainWindow.getNativeWindowHandle(), blur, red, green, blue, alpha);
}
if (app.isPackaged && !process.argv.includes("--hidden")) {
updateElectronApp({ repo: "diffusionstudio/editor" });
function setColorMode(mode: "dark" | "light") {
if (process.platform === "darwin" || !mainWindow || mainWindow.isDestroyed()) return;
mainWindow.setTitleBarOverlay({ ...WINDOWS_OVERLAY_COLORS[mode], height: WINDOWS_OVERLAY_HEIGHT });
}
const openWrites = new Map<string, { handle: FileHandle; path: string }>();
// A downloaded update is offered while the user has the window out; one that
// lands while the app runs in the background waits for the next show, since
// the app rarely quits on its own to apply it.
const notifyUser = makeUserNotifier();
let pendingUpdate: IUpdateInfo | null = null;
function offerUpdate() {
if (!pendingUpdate || !windows.visible()) return;
const info = pendingUpdate;
pendingUpdate = null;
notifyUser(info);
}
if (app.isPackaged && !squirrelLaunch) {
updateElectronApp({
repo: "diffusionstudio/editor",
onNotifyUser: function (info) {
pendingUpdate = info;
offerUpdate();
},
});
}
const openWrites = new Map<string, { handle: FileHandle; path: string; temp: string; reserved: boolean }>();
let mainWindow: BrowserWindow | null = null;
let lastProject: string | null = null;
const windows = new WindowHost({
create: createWindow,
idleMs: WINDOW_IDLE_MS,
onChange: () => {
tray.refresh();
offerUpdate();
},
});
const tray = new AppTray({
visible: () => windows.visible(),
active: () => windows.active(),
project: () => lastProject,
show: () => void windows.show(),
hide: () => windows.hide(),
});
// Deep links that arrived before the renderer could take them, keyed by the
// channel they belong to so auth and checkout never drain each other's link.
@ -97,6 +167,32 @@ const pendingDeepLinks = new Map<DeepLinkChannel, string>();
const LOG_BUFFER_MAX = 2000;
const logBuffer: LogEntry[] = [];
// The docs the MCP instructions point agents at: staged into the bundle by
// scripts/stage-docs.mjs (Contents/Resources/docs) when packaged; the repo's
// own `docs/` in development, so edits show up without a staging step. Null
// when neither exists.
function docsDir(): string | null {
const dir = app.isPackaged ? join(process.resourcesPath, "docs") : join(app.getAppPath(), "..", "..", "docs");
return existsSync(dir) ? dir : null;
}
// The MCP server agents and the diffusion CLI talk to. Started once the app is
// ready; renderer tools create the window when there is none.
const dapi = new DapiServer({
version: app.getVersion(),
logs: () => logBuffer,
docsDir: docsDir(),
window: {
visible: () => windows.visible(),
show: () => windows.show(),
hide: () => windows.hide(),
acquire: () => windows.acquire(),
hold: () => windows.hold(),
lastProject: () => lastProject,
},
onToolCall: (props) => track("tool_called", props),
});
function pushLog(level: LogEntry["level"], message: string, source: string) {
logBuffer.push({ ts: Date.now(), level, message, source });
if (logBuffer.length > LOG_BUFFER_MAX) logBuffer.shift();
@ -176,20 +272,38 @@ async function setFileInputFiles(selector: string, absolutePath: string) {
});
}
function createWindow(show = true) {
mainWindow = new BrowserWindow({
// The main window, not shown: WindowHost decides when it is.
function createWindow(): BrowserWindow {
const options: Electron.BrowserWindowConstructorOptions = {
show: false,
width: 1200,
height: 800,
titleBarStyle: "hiddenInset",
trafficLightPosition: { x: 14, y: 14 },
...(process.platform === "darwin"
? { vibrancy: "sidebar" as const, backgroundColor: "#00000000" }
: { backgroundColor: "#1c1c1c" }),
webPreferences: {
preload: join(app.getAppPath(), "dist", "preload.js"),
backgroundThrottling: false,
},
});
}
if (process.platform === "darwin") {
options.titleBarStyle = "hiddenInset" as const;
options.trafficLightPosition = { x: 14, y: 14 };
options.vibrancy = "sidebar" as const;
options.backgroundColor = "#00000000";
}
if (process.platform === "win32") {
options.titleBarStyle = "hidden" as const;
options.titleBarOverlay = { ...WINDOWS_OVERLAY_COLORS.dark, height: WINDOWS_OVERLAY_HEIGHT };
options.autoHideMenuBar = true;
options.backgroundColor = WINDOWS_OVERLAY_COLORS.dark.color;
if (!app.isPackaged) {
options.icon = join(app.getAppPath(), "assets", "icon-dev.png");
}
}
mainWindow = new BrowserWindow(options);
captureConsole(mainWindow);
@ -199,10 +313,6 @@ function createWindow(show = true) {
mainWindow.once("ready-to-show", () => {
applyCornerRadius(MACOS_CORNER_RADIUS);
applyBackdrop();
if (show) {
mainWindow?.show();
}
});
mainWindow.on("show", () => {
@ -220,6 +330,7 @@ function createWindow(show = true) {
});
mainWindow.on("closed", () => {
mainWindow = null;
unwatchAll();
});
if (!app.isPackaged) {
@ -227,6 +338,8 @@ function createWindow(show = true) {
} else {
mainWindow.loadFile(join(app.getAppPath(), "web", "index.html"));
}
return mainWindow;
}
if (process.defaultApp && process.argv.length >= 2) {
@ -237,33 +350,34 @@ if (process.defaultApp && process.argv.length >= 2) {
app.setAsDefaultProtocolClient(AUTH_PROTOCOL);
}
if (app.requestSingleInstanceLock()) {
if (squirrelLaunch) {
// Update.exe is at work; handleSquirrelEvent quits the app when it is done.
} else if (app.requestSingleInstanceLock()) {
if (isHiddenLaunch(process.argv)) {
app.dock?.hide();
}
app.on("second-instance", (_event, argv) => {
const url = findProtocolUrl(argv);
if (url) deliverDeepLink(url);
const hidden = isHiddenLaunch(argv);
if (mainWindow && !mainWindow.isDestroyed()) {
if (hidden) return;
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
mainWindow.focus();
} else {
createWindow(!hidden);
if (url) {
deliverDeepLink(url);
}
if (!isHiddenLaunch(argv)) {
windows.show();
}
});
app.on("open-url", (event, url) => {
event.preventDefault();
deliverDeepLink(url);
windows.show();
});
mainBridge.handle(MAIN_CHANNELS.APP_OPEN_EXTERNAL, ({ url }) => shell.openExternal(url));
mainBridge.handle(MAIN_CHANNELS.APP_SHOW_IN_FOLDER, ({ path }) => shell.showItemInFolder(path));
mainBridge.handle(MAIN_CHANNELS.CLI_IS_INSTALLED, () => isCliInstalled());
mainBridge.handle(MAIN_CHANNELS.CLI_INSTALL, () => installCli());
mainBridge.handle(MAIN_CHANNELS.SKILLS_IS_INSTALLED, () => isSkillsInstalled());
mainBridge.handle(MAIN_CHANNELS.SKILLS_INSTALL, () => installSkills());
mainBridge.handle(MAIN_CHANNELS.APP_EDITORS_LIST, () => installedEditors());
mainBridge.handle(MAIN_CHANNELS.APP_OPEN_IN_EDITOR, ({ id, dir }) => openInEditor(id, dir));
mainBridge.handle(MAIN_CHANNELS.ANALYTICS_CONFIGURE, (config) => configureAnalytics(config));
mainBridge.handle(MAIN_CHANNELS.AUTH_GET_PENDING_CALLBACK, () =>
takePendingDeepLink(MAIN_CHANNELS.AUTH_CALLBACK),
);
@ -271,32 +385,59 @@ if (app.requestSingleInstanceLock()) {
takePendingDeepLink(MAIN_CHANNELS.CHECKOUT_CALLBACK),
);
mainBridge.handle(MAIN_CHANNELS.WINDOW_IS_FULLSCREEN, () => mainWindow?.isFullScreen() ?? false);
mainBridge.handle(MAIN_CHANNELS.WINDOW_SET_COLOR_MODE, ({ mode }) => setColorMode(mode));
mainBridge.handle(MAIN_CHANNELS.WINDOW_SET_BUSY, ({ busy }) => windows.setBusy(busy));
mainBridge.handle(MAIN_CHANNELS.WINDOW_SHOW, () => windows.show());
mainBridge.handle(MAIN_CHANNELS.WINDOW_CAPTURE, async () => {
if (!mainWindow || mainWindow.isDestroyed()) throw new Error("No main window");
const image = await mainWindow.webContents.capturePage(undefined, { stayHidden: true });
const { width, height } = image.getSize();
return { base64: image.toPNG().toString("base64"), width, height };
const png = image.toPNG();
// A plain Uint8Array over the PNG, so the renderer sees bytes and not a Buffer.
return { png: new Uint8Array(png.buffer, png.byteOffset, png.byteLength), width, height };
});
mainBridge.handle(MAIN_CHANNELS.HEADLESS_GET_MODE, () => isHeadless());
mainBridge.handle(MAIN_CHANNELS.CLIPBOARD_PATHS, () => clipboardPaths());
mainBridge.handle(MAIN_CHANNELS.LOGS_GET, () => logBuffer);
mainBridge.handle(MAIN_CHANNELS.PROJECTS_PICK_ROOT, () => pickRoot(mainWindow));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_DEFAULT_ROOT, () => defaultRoot(mainWindow));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_LIST, ({ root }) => listProjects(root));
mainBridge.handle(MAIN_CHANNELS.AGENT_CHAT_ENDPOINT, () => agentChatEndpoint());
mainBridge.handle(MAIN_CHANNELS.MCP_STATUS, () => mcpStatus());
mainBridge.handle(MAIN_CHANNELS.MCP_APPLY, (request) => applyMcp(request));
mainBridge.handle(MAIN_CHANNELS.CLI_STATUS, () => cliStatus());
mainBridge.handle(MAIN_CHANNELS.CLI_INSTALL, () => installCli());
mainBridge.handle(MAIN_CHANNELS.CLI_UNINSTALL, () => uninstallCli());
mainBridge.handle(MAIN_CHANNELS.PROJECTS_PICK_FOLDER, () => pickFolder(mainWindow));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_GET, ({ dir }) => getProject(dir));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_INIT, ({ dir }) => initProject(mainWindow, dir));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_RESOLVE, ({ root, ref }) => resolveProject(root, ref));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_CREATE, ({ root, displayName }) =>
createProject(root, displayName),
mainBridge.handle(MAIN_CHANNELS.PROJECTS_RESOLVE, ({ dir }) => resolveProject(dir));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_FIND_MOVED, ({ dir, id }) => findMovedProject(dir, id));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_ASK_MISSING, ({ displayName, dir }) =>
askAboutMissingProject(mainWindow, displayName, dir),
);
mainBridge.handle(MAIN_CHANNELS.PROJECTS_CREATE, () => createProject());
mainBridge.handle(MAIN_CHANNELS.PROJECTS_PICK_SAVE, ({ dir, name, startIn, action }) =>
pickSaveLocation(mainWindow, dir, name, startIn, action),
);
mainBridge.handle(MAIN_CHANNELS.PROJECTS_SAVE, ({ dir, target }) => saveProject(dir, target));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_MOVE, ({ dir, target }) => moveProject(dir, target));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_RENAME, ({ dir, displayName }) => renameProject(dir, displayName));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_DUPLICATE, ({ dir }) => duplicateProject(dir));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_DELETE, ({ dir }) => deleteProject(dir));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_DELETE, ({ dir }) => deleteProject(dir).then(deleteProjectChats));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_COMPILE, ({ dir }) => compileProject(dir));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_WRITE, ({ dir, edits }) => writeProject(dir, edits));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_WATCH, ({ dir }, event) =>
watchProject(BrowserWindow.fromWebContents(event.sender), dir),
);
mainBridge.handle(MAIN_CHANNELS.PROJECTS_UNWATCH, ({ dir }) => unwatchProject(dir));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_WRITE, ({ dir, edits }) => {
countCanvasEdits(edits.map((edit) => edit.kind));
return writeProject(dir, edits);
});
mainBridge.handle(MAIN_CHANNELS.PROJECTS_WATCH, ({ dir }, event) => {
lastProject = dir;
tray.refresh();
watchProject(BrowserWindow.fromWebContents(event.sender), dir);
});
mainBridge.handle(MAIN_CHANNELS.PROJECTS_UNWATCH, ({ dir }) => {
if (lastProject === dir) {
lastProject = null;
tray.refresh();
}
unwatchProject(dir);
});
mainBridge.handle(MAIN_CHANNELS.PROJECTS_MANIFEST_READ, ({ dir }) => readManifest(dir));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_MANIFEST_WRITE, ({ dir, manifest }) => writeManifest(dir, manifest));
mainBridge.handle(MAIN_CHANNELS.PROJECTS_CONFIG_READ, ({ dir }) => readConfig(dir));
@ -311,17 +452,29 @@ if (app.requestSingleInstanceLock()) {
mainBridge.handle(MAIN_CHANNELS.FILE_WRITE_OPEN, async ({ path, exclusive }) => {
await mkdir(dirname(path), { recursive: true });
markSelfWriteAbsolute(path);
const handle = await open(path, exclusive ? "wx" : "w");
// `exclusive` means the name must be free, so it is taken now rather than
// at the rename below — the empty file that reserves it is renamed over
// when the write finishes, and removed when it is abandoned.
if (exclusive) {
noteContent(path, "");
await (await open(path, "wx")).close();
}
// The bytes go to a temp file beside the destination and are renamed into
// place once they are whole. Nothing ever sees half an asset — not the
// watcher, not a scan of the library, not an import — so there is no
// window anyone has to be kept out of.
const temp = tempPathFor(path);
const handle = await open(temp, "wx");
const id = randomUUID();
openWrites.set(id, { handle, path });
openWrites.set(id, { handle, path, temp, reserved: exclusive === true });
return { id };
});
mainBridge.handle(MAIN_CHANNELS.FILE_WRITE_CHUNK, async ({ id, data, position }) => {
const entry = openWrites.get(id);
if (!entry) throw new Error(`No open file for write id ${id}`);
markSelfWriteAbsolute(entry.path);
await entry.handle.write(data, 0, data.byteLength, position);
});
@ -329,11 +482,21 @@ if (app.requestSingleInstanceLock()) {
const entry = openWrites.get(id);
if (!entry) return;
openWrites.delete(id);
markSelfWriteAbsolute(entry.path);
await entry.handle.close();
try {
await entry.handle.close();
// Claimed before the rename, which is the first and only moment the
// destination changes (see `noteRenamed`).
await noteRenamed(entry.temp, entry.path);
await rename(entry.temp, entry.path);
} catch (error) {
await unlink(entry.temp).catch(() => { });
throw error;
}
});
// Abort: close the fd and delete the partial file (cancel / error cleanup).
// Abort: close the fd and drop the temp file (cancel / error cleanup). The
// destination is left alone — an abandoned write never reached it — bar the
// name an `exclusive` open reserved, which is given back.
mainBridge.handle(MAIN_CHANNELS.FILE_WRITE_ABORT, async ({ id }) => {
const entry = openWrites.get(id);
if (!entry) return;
@ -341,7 +504,11 @@ if (app.requestSingleInstanceLock()) {
try {
await entry.handle.close();
} finally {
await unlink(entry.path).catch(() => { });
await unlink(entry.temp).catch(() => { });
if (entry.reserved) {
noteContent(entry.path, null);
await unlink(entry.path).catch(() => { });
}
}
});
@ -359,35 +526,39 @@ if (app.requestSingleInstanceLock()) {
const url = findProtocolUrl(process.argv);
if (url) deliverDeepLink(url);
startCliServer();
healSkillsLinks();
trackInstall();
createWindow(!isHiddenLaunch(process.argv));
dapi.start();
// The chat's sessions get the MCP server by URL.
dapi.mcpUrl().then((url) =>
configureAgentChat({
dataDir: join(app.getPath("userData"), "agent-chat"),
mcpUrl: url,
version: app.getVersion(),
}),
);
refreshCliShim();
healMcpRegistrations();
startAnalytics(windows);
tray.start();
// Opened by a person (Finder, Dock, Start menu): show the editor
if (!isHiddenLaunch(process.argv)) {
windows.show();
}
});
app.on("before-quit", () => {
unwatchAll();
stopCliServer();
stopAgentChat();
dapi.stop();
tray.destroy();
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
// No window is no reason to quit: the app keeps serving agents from the
// tray, and the window is destroyed whenever it idles out. Only Quit ends it.
app.on("window-all-closed", () => { });
app.on("activate", () => {
if (!mainWindow || mainWindow.isDestroyed()) {
createWindow();
return;
}
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
mainWindow.focus();
});
// The Dock icon, or launching the app again while it runs.
app.on("activate", () => windows.show());
} else {
app.quit();
}

View File

@ -0,0 +1,203 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { describe, expect, it } from "vitest";
import {
AGENT_TARGETS,
agentTarget,
needsBinary,
readServer,
removeServer,
runsOurProxy,
sameCommand,
upsertServer,
} from "./mcp-config";
const spec = {
url: "http://127.0.0.1:3274/mcp",
command: "/Applications/Diffusion Studio.app/Contents/Resources/cli/bin/dapi",
args: ["mcp"],
};
describe("per-agent entries", () => {
it("spells the URL the way each agent expects", () => {
expect(agentTarget("claude-code").entry(spec)).toEqual({ type: "http", url: spec.url });
expect(agentTarget("cursor").entry(spec)).toEqual({ url: spec.url });
expect(agentTarget("vscode").entry(spec)).toEqual({ type: "http", url: spec.url });
expect(agentTarget("codex").entry(spec)).toEqual({ url: spec.url });
expect(agentTarget("antigravity").entry(spec)).toEqual({ serverUrl: spec.url });
expect(agentTarget("gemini-cli").entry(spec)).toEqual({ httpUrl: spec.url });
expect(agentTarget("windsurf").entry(spec)).toEqual({ serverUrl: spec.url });
expect(agentTarget("opencode").entry(spec)).toEqual({ type: "remote", enabled: true, url: spec.url });
});
it("gives Claude Desktop the stdio proxy, and nobody else", () => {
expect(agentTarget("claude-desktop").entry(spec)).toEqual({ command: spec.command, args: ["mcp"] });
expect(AGENT_TARGETS.filter(needsBinary).map((t) => t.id)).toEqual(["claude-desktop"]);
});
it("has a unique id per agent", () => {
expect(new Set(AGENT_TARGETS.map((t) => t.id)).size).toBe(AGENT_TARGETS.length);
});
});
describe("json configs", () => {
it("creates the file from nothing", () => {
const text = upsertServer(null, "mcpServers", { type: "http", url: spec.url });
expect(JSON.parse(text)).toEqual({ mcpServers: { diffusion: { type: "http", url: spec.url } } });
expect(text.endsWith("\n")).toBe(true);
});
it("uses VS Code's root key", () => {
const text = upsertServer(null, "servers", { type: "http", url: spec.url });
expect(JSON.parse(text)).toEqual({ servers: { diffusion: { type: "http", url: spec.url } } });
expect(readServer(text, "servers")).toEqual({ url: spec.url });
// The same file read under the other root key has nothing of ours.
expect(readServer(text, "mcpServers")).toBeNull();
});
it("uses OpenCode's root key and keeps the boolean flag", () => {
const text = upsertServer(null, "mcp", { type: "remote", enabled: true, url: spec.url });
expect(JSON.parse(text)).toEqual({ mcp: { diffusion: { type: "remote", enabled: true, url: spec.url } } });
expect(readServer(text, "mcp")).toEqual({ url: spec.url });
});
it("keeps other servers and unrelated keys", () => {
const before = JSON.stringify({
numStartups: 12,
mcpServers: { other: { command: "x", args: [] } },
projects: { "/a": { allowedTools: [] } },
});
const after = JSON.parse(upsertServer(before, "mcpServers", { url: spec.url }));
expect(after.numStartups).toBe(12);
expect(after.projects).toEqual({ "/a": { allowedTools: [] } });
expect(after.mcpServers.other).toEqual({ command: "x", args: [] });
expect(after.mcpServers.diffusion).toEqual({ url: spec.url });
});
it("replaces a stdio entry with a URL entry, and reads either", () => {
const before = upsertServer(null, "mcpServers", { command: "/old/dapi", args: ["mcp"] });
expect(readServer(before, "mcpServers")).toEqual({ command: "/old/dapi", args: ["mcp"] });
const after = upsertServer(before, "mcpServers", { type: "http", url: spec.url });
expect(readServer(after, "mcpServers")).toEqual({ url: spec.url });
expect(JSON.parse(after).mcpServers.diffusion.command).toBeUndefined();
});
it("reads the URL under each agent's key", () => {
for (const key of ["url", "httpUrl", "serverUrl"]) {
expect(readServer(upsertServer(null, "mcpServers", { [key]: spec.url }), "mcpServers")).toEqual({ url: spec.url });
}
});
it("refuses to overwrite a file it cannot parse", () => {
expect(() => upsertServer("{ not json", "mcpServers", { url: spec.url })).toThrow();
expect(() => upsertServer("[1, 2]", "mcpServers", { url: spec.url })).toThrow();
expect(readServer("{ not json", "mcpServers")).toBeNull();
});
it("treats an empty file as no config", () => {
expect(readServer("", "mcpServers")).toBeNull();
expect(JSON.parse(upsertServer(" \n", "mcpServers", { url: spec.url }))).toEqual({ mcpServers: { diffusion: { url: spec.url } } });
});
it("removes our entry and nothing else", () => {
const before = JSON.stringify({
numStartups: 12,
mcpServers: { other: { command: "x", args: [] }, diffusion: { type: "http", url: spec.url } },
});
const after = removeServer(before, "mcpServers");
expect(after).not.toBeNull();
expect(JSON.parse(after as string)).toEqual({ numStartups: 12, mcpServers: { other: { command: "x", args: [] } } });
expect(readServer(after, "mcpServers")).toBeNull();
});
it("has nothing to remove from a config without our entry", () => {
expect(removeServer(null, "mcpServers")).toBeNull();
expect(removeServer("", "mcpServers")).toBeNull();
expect(removeServer(JSON.stringify({ mcpServers: { other: { url: "u" } } }), "mcpServers")).toBeNull();
expect(removeServer("{ not json", "mcpServers")).toBeNull();
});
});
describe("toml configs (codex)", () => {
it("appends a table to an existing config", () => {
const before = 'model = "o3"\n\n[mcp_servers.other]\ncommand = "x"\n';
const after = upsertServer(before, "toml", { url: spec.url });
expect(after).toBe('model = "o3"\n\n[mcp_servers.other]\ncommand = "x"\n\n[mcp_servers.diffusion]\nurl = "http://127.0.0.1:3274/mcp"\n');
expect(readServer(after, "toml")).toEqual({ url: spec.url });
});
it("replaces our table in place and leaves the next one alone", () => {
const before = '[mcp_servers.diffusion]\ncommand = "/old/dapi"\nargs = ["mcp"]\n\n[mcp_servers.other]\ncommand = "x"\n';
expect(readServer(before, "toml")).toEqual({ command: "/old/dapi", args: ["mcp"] });
const after = upsertServer(before, "toml", { url: spec.url });
expect(after).toBe('[mcp_servers.diffusion]\nurl = "http://127.0.0.1:3274/mcp"\n[mcp_servers.other]\ncommand = "x"\n');
expect(readServer(after, "toml")).toEqual({ url: spec.url });
});
it("starts a file from nothing", () => {
const text = upsertServer(null, "toml", { url: spec.url });
expect(text).toBe('[mcp_servers.diffusion]\nurl = "http://127.0.0.1:3274/mcp"\n');
});
it("escapes quotes and backslashes in stdio paths", () => {
const odd = { command: 'C:\\Apps\\"Diffusion"\\dapi', args: ["mcp"] };
const text = upsertServer(null, "toml", odd);
expect(text).toContain('command = "C:\\\\Apps\\\\\\"Diffusion\\"\\\\dapi"');
expect(readServer(text, "toml")).toEqual({ command: odd.command, args: ["mcp"] });
});
it("reads nothing from a config without our table", () => {
expect(readServer('model = "o3"\n', "toml")).toBeNull();
expect(removeServer('model = "o3"\n', "toml")).toBeNull();
});
it("removes our table from the end of a config", () => {
const before = 'model = "o3"\n\n[mcp_servers.other]\ncommand = "x"\n';
const connected = upsertServer(before, "toml", { url: spec.url });
expect(removeServer(connected, "toml")).toBe(before);
});
it("removes our table from between others without leaving a gap", () => {
const before = 'model = "o3"\n\n[mcp_servers.diffusion]\nurl = "u"\n\n[mcp_servers.other]\ncommand = "x"\n';
expect(removeServer(before, "toml")).toBe('model = "o3"\n\n[mcp_servers.other]\ncommand = "x"\n');
});
it("empties a config that held only our table", () => {
expect(removeServer(upsertServer(null, "toml", { url: spec.url }), "toml")).toBe("");
});
});
describe("stdio entries across platforms", () => {
const shim = "C:\\Users\\me\\AppData\\Local\\DiffusionStudio\\bin\\dapi.cmd";
const windows = { url: spec.url, command: "cmd", args: ["/c", shim, "mcp"] };
it("keeps desktop apps' configs under appData and the dotfile agents under home", () => {
expect(agentTarget("claude-desktop").config).toEqual({ root: "appData", path: "Claude/claude_desktop_config.json" });
expect(agentTarget("vscode").config).toEqual({ root: "appData", path: "Code/User/mcp.json" });
expect(AGENT_TARGETS.filter((t) => t.config.root === "appData").map((t) => t.id)).toEqual(["claude-desktop", "vscode"]);
});
it("round-trips the Windows shape, where the shim rides in args", () => {
const entry = agentTarget("claude-desktop").entry(windows);
expect(entry).toEqual({ command: "cmd", args: ["/c", shim, "mcp"] });
const registered = readServer(upsertServer(null, "mcpServers", entry), "mcpServers");
expect(registered).toEqual({ command: "cmd", args: ["/c", shim, "mcp"] });
expect(sameCommand(registered!, entry)).toBe(true);
});
it("recognises our proxy by its path, as the command or as an argument", () => {
expect(runsOurProxy({ command: spec.command, args: ["mcp"] })).toBe(true);
expect(runsOurProxy({ command: "/private/var/folders/x/AppTranslocation/y/d/cli/bin/dapi" })).toBe(true);
expect(runsOurProxy({ command: "cmd", args: ["/c", shim, "mcp"] })).toBe(true);
expect(runsOurProxy({ command: "cmd", args: ["/c", "C:\\tools\\other.cmd"] })).toBe(false);
expect(runsOurProxy({ command: "/opt/homebrew/bin/dapi", args: ["mcp"] })).toBe(false);
});
it("sees a moved shim as a different command", () => {
const moved = { command: "cmd", args: ["/c", shim.replace("me", "you"), "mcp"] };
expect(sameCommand(moved, agentTarget("claude-desktop").entry(windows))).toBe(false);
expect(sameCommand({ command: spec.command, args: ["mcp"] }, agentTarget("claude-desktop").entry(spec))).toBe(true);
});
});

View File

@ -0,0 +1,277 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// How the app's MCP server is written into each agent's config, as pure
// text transforms: no file system, no Electron, so the merge rules are
// testable. `mcp-install.ts` decides which files and does the I/O.
/**
* The two ways to reach the app. Agents that speak Streamable HTTP get the
* URL, which is the same on every machine; the rest get the bundled `dapi`
* binary in stdio proxy mode. On Windows that binary is a `.cmd`, which
* nothing can spawn without a shell, so the command is `cmd` and the shim's
* path rides in `args`.
*/
export type McpServerSpec = { url: string; command: string; args: string[] };
/**
* The key our entry lives under in every agent's server map, and so the
* namespace an agent shows us under: `mcp__diffusion__<tool>` and
* `/diffusion:<prompt>`. The same word as our URL scheme and the CLI's
* primary name (`dapi` still works there too, as an alias).
*/
export const SERVER_NAME = "diffusion";
/** One agent's config entry: what its file format spells a server as. */
export type ServerEntry = Record<string, string | string[] | boolean>;
/** The stable id an agent is addressed by over IPC and in the UI. */
export type AgentId =
| "claude-code"
| "claude-desktop"
| "cursor"
| "vscode"
| "codex"
| "antigravity"
| "gemini-cli"
| "windsurf"
| "opencode";
/** How a config file spells its server map: JSON under `mcpServers` (or VS Code's `servers`, or OpenCode's `mcp`), or Codex's TOML tables. */
export type ConfigFormat = "mcpServers" | "servers" | "mcp" | "toml";
/**
* A path under one of the two per-user roots. `appData` is where desktop apps
* keep their files (Electron's `appData`: ~/Library/Application Support on
* macOS, %APPDATA% on Windows), which keeps this table the same on every
* platform; `mcp-install.ts` knows where the roots are.
*/
export type AgentPath = { root: "home" | "appData"; path: string };
export type AgentTarget = {
id: AgentId;
/** Human name, for the UI. */
label: string;
/** Path whose presence means the agent is set up on this machine. */
marker: AgentPath;
/** Path of the config file our entry goes into. */
config: AgentPath;
format: ConfigFormat;
/** The entry for this agent: which transport it gets, under the keys its format uses. */
entry(spec: McpServerSpec): ServerEntry;
};
const http = (key: string, extra: ServerEntry = {}) => (spec: McpServerSpec): ServerEntry => ({ ...extra, [key]: spec.url });
const stdio = (spec: McpServerSpec): ServerEntry => ({ command: spec.command, args: [...spec.args] });
const home = (path: string): AgentPath => ({ root: "home", path });
const appData = (path: string): AgentPath => ({ root: "appData", path });
// Agents whose MCP config we know how to write, in the order the UI lists
// them. Claude Code's user scope is the top-level `mcpServers` of
// ~/.claude.json, the same file `claude mcp add --scope user` edits. VS Code
// keeps its user-level servers under `servers` in the profile's mcp.json.
// Antigravity shares one config across its IDE and CLI, and only accepts
// `serverUrl`. Claude Desktop's file takes stdio commands only, so it gets
// the proxy.
export const AGENT_TARGETS: readonly AgentTarget[] = [
{ id: "claude-code", label: "Claude Code", marker: home(".claude"), config: home(".claude.json"), format: "mcpServers", entry: http("url", { type: "http" }) },
{
id: "claude-desktop",
label: "Claude Desktop",
marker: appData("Claude"),
config: appData("Claude/claude_desktop_config.json"),
format: "mcpServers",
entry: stdio,
},
{ id: "cursor", label: "Cursor", marker: home(".cursor"), config: home(".cursor/mcp.json"), format: "mcpServers", entry: http("url") },
{
id: "vscode",
label: "VS Code (Copilot)",
marker: appData("Code"),
config: appData("Code/User/mcp.json"),
format: "servers",
entry: http("url", { type: "http" }),
},
{ id: "codex", label: "Codex", marker: home(".codex"), config: home(".codex/config.toml"), format: "toml", entry: http("url") },
{ id: "antigravity", label: "Antigravity", marker: home(".gemini/antigravity"), config: home(".gemini/config/mcp_config.json"), format: "mcpServers", entry: http("serverUrl") },
{ id: "gemini-cli", label: "Gemini CLI", marker: home(".gemini"), config: home(".gemini/settings.json"), format: "mcpServers", entry: http("httpUrl") },
{ id: "windsurf", label: "Devin (Windsurf)", marker: home(".codeium/windsurf"), config: home(".codeium/windsurf/mcp_config.json"), format: "mcpServers", entry: http("serverUrl") },
{ id: "opencode", label: "OpenCode", marker: home(".config/opencode"), config: home(".config/opencode/opencode.json"), format: "mcp", entry: http("url", { type: "remote", enabled: true }) },
];
export function agentTarget(id: AgentId): AgentTarget {
const target = AGENT_TARGETS.find((candidate) => candidate.id === id);
if (!target) throw new Error(`Unknown agent: ${id}`);
return target;
}
/** Whether the agent runs our entry over stdio, and so needs the `dapi` binary. */
export function needsBinary(target: AgentTarget): boolean {
return "command" in target.entry({ url: "http://x", command: "x", args: [] });
}
/**
* The config with our entry set, leaving everything else as it was. `text`
* is the file's current content, or null when there is none yet. Throws
* when the file cannot be parsed: a config we cannot read is not one we
* should overwrite.
*/
export function upsertServer(text: string | null, format: ConfigFormat, entry: ServerEntry): string {
return format === "toml" ? upsertToml(text, entry) : upsertJson(text, format, entry);
}
/**
* The config with our entry taken out, everything else untouched; null when
* the file has no entry of ours (or cannot be parsed), so there is nothing
* to write back. Other servers and unrelated keys stay as they were.
*/
export function removeServer(text: string | null, format: ConfigFormat): string | null {
if (readServer(text, format) === null) return null;
return format === "toml" ? removeToml(text as string) : removeJson(text as string, format);
}
/** Where our entry currently points, whatever keys the agent spells it with; null when there is none. */
export type Registered = { url?: string; command?: string; args?: string[] };
export function readServer(text: string | null, format: ConfigFormat): Registered | null {
if (text === null) return null;
const entry = format === "toml" ? readToml(text) : readJson(text, format);
if (!entry) return null;
const url = entry.url ?? entry.httpUrl ?? entry.serverUrl;
const command = entry.command;
if (typeof url !== "string" && typeof command !== "string") return null;
const args = Array.isArray(entry.args) ? entry.args.filter((arg): arg is string => typeof arg === "string") : null;
return {
...(typeof url === "string" ? { url } : {}),
...(typeof command === "string" ? { command } : {}),
...(typeof command === "string" && args ? { args } : {}),
};
}
// What a path to our proxy has in it: the app's name inside a macOS bundle
// (or the translocated mount a quarantined bundle ran from), the Squirrel
// package id in the Windows shim folder.
const OUR_PATHS = ["Diffusion Studio", "/AppTranslocation/", "\\DiffusionStudio\\"];
/**
* Whether a stdio entry runs our proxy — from wherever the app was when the
* entry was written — rather than something the user put under our name by
* hand. The path is the command itself, or on Windows an argument to `cmd`.
*/
export function runsOurProxy(registered: Registered): boolean {
return [registered.command ?? "", ...(registered.args ?? [])].some((part) =>
OUR_PATHS.some((marker) => part.includes(marker)),
);
}
/** Whether a stdio entry already is what `entry` would write. */
export function sameCommand(registered: Registered, entry: ServerEntry): boolean {
const args = Array.isArray(entry.args) ? entry.args : [];
return (
registered.command === entry.command &&
(registered.args ?? []).length === args.length &&
(registered.args ?? []).every((arg, index) => arg === args[index])
);
}
// --- JSON ------------------------------------------------------------------
type JsonFormat = Exclude<ConfigFormat, "toml">;
type JsonConfig = Record<string, unknown>;
function parseJson(text: string | null): JsonConfig {
if (text === null || text.trim() === "") return {};
const parsed: unknown = JSON.parse(text);
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
throw new Error("expected a JSON object at the top level");
}
return parsed as JsonConfig;
}
function serverMap(config: JsonConfig, root: JsonFormat): Record<string, unknown> {
const servers = config[root];
return typeof servers === "object" && servers !== null && !Array.isArray(servers)
? (servers as Record<string, unknown>)
: {};
}
function upsertJson(text: string | null, root: JsonFormat, entry: ServerEntry): string {
const config = parseJson(text);
config[root] = { ...serverMap(config, root), [SERVER_NAME]: entry };
return `${JSON.stringify(config, null, 2)}\n`;
}
function removeJson(text: string, root: JsonFormat): string {
const config = parseJson(text);
const { [SERVER_NAME]: _ours, ...servers } = serverMap(config, root);
config[root] = servers;
return `${JSON.stringify(config, null, 2)}\n`;
}
function readJson(text: string, root: JsonFormat): Record<string, unknown> | null {
let config: JsonConfig;
try {
config = parseJson(text);
} catch {
return null;
}
const entry = serverMap(config, root)[SERVER_NAME];
return typeof entry === "object" && entry !== null ? (entry as Record<string, unknown>) : null;
}
// --- TOML (Codex) ----------------------------------------------------------
// Our table, from its header up to the next table header or the end. A
// header line is `[...]` at column 0; indented or commented ones are not.
const TOML_TABLE = new RegExp(String.raw`^\[mcp_servers\.${SERVER_NAME}\][^\n]*\n(?:(?!\[)[^\n]*\n?)*`, "m");
function tomlString(value: string): string {
return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
}
function tomlValue(value: string | string[] | boolean): string {
if (typeof value === "boolean") return String(value);
return Array.isArray(value) ? `[${value.map(tomlString).join(", ")}]` : tomlString(value);
}
function tomlTable(entry: ServerEntry): string {
const lines = Object.entries(entry).map(([key, value]) => `${key} = ${tomlValue(value)}`);
return [`[mcp_servers.${SERVER_NAME}]`, ...lines, ""].join("\n");
}
function upsertToml(text: string | null, entry: ServerEntry): string {
const current = text ?? "";
const table = tomlTable(entry);
if (TOML_TABLE.test(current)) return current.replace(TOML_TABLE, table);
const separator = current === "" || current.endsWith("\n\n") ? "" : current.endsWith("\n") ? "\n" : "\n\n";
return `${current}${separator}${table}`;
}
// Drops our table, then the blank lines it used to sit between so the file
// does not end in (or contain) a growing gap after a connect/disconnect cycle.
function removeToml(text: string): string {
const rest = text.replace(TOML_TABLE, "").replace(/\n{3,}/g, "\n\n").trimEnd();
return rest === "" ? "" : `${rest}\n`;
}
function readToml(text: string): Record<string, unknown> | null {
const table = text.match(TOML_TABLE)?.[0];
if (!table) return null;
const entry: Record<string, unknown> = {};
for (const line of table.split("\n").slice(1)) {
const scalar = line.match(/^(\w+)\s*=\s*"((?:[^"\\]|\\.)*)"\s*$/);
if (scalar) {
entry[scalar[1]] = untomlString(scalar[2]);
continue;
}
const list = line.match(/^(\w+)\s*=\s*\[([^\]]*)\]\s*$/);
if (list) entry[list[1]] = [...list[2].matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((m) => untomlString(m[1]));
}
return entry;
}
function untomlString(value: string): string {
return value.replaceAll('\\"', '"').replaceAll("\\\\", "\\");
}

View File

@ -0,0 +1,182 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Registers the app's MCP server with the agents on this machine, one agent
// at a time as the settings page asks: the fixed loopback URL for agents
// that speak HTTP, the bundled `dapi mcp` proxy for the rest. No PATH
// symlink and no admin prompt — that is `cli-install.ts`, for people who
// type `diffusion` (or its `dapi` alias).
import { app } from "electron";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { MCP_URL } from "@diffusionstudio/dapi";
import { shimPath } from "./cli-windows";
import {
AGENT_TARGETS,
agentTarget,
needsBinary,
readServer,
removeServer,
runsOurProxy,
sameCommand,
upsertServer,
} from "./mcp-config";
import type { AgentPath, AgentTarget, McpServerSpec } from "./mcp-config";
import type { McpAgentStatus, McpApplyRequest, McpApplyResult, McpStatus } from "./main-channels";
// The dev workflow links the workspace build into Homebrew's bin
// (`npm run link` in apps/cli); that is the binary a dev build registers.
const DEV_BINARY = "/opt/homebrew/bin/dapi";
/**
* The bundled `dapi` binary, or null when none is available (an unstaged dev
* build). On Windows it is the shim outside the install folder, the one path
* that survives an update; a packaged app writes it on every launch, so it
* counts as there even in the moment before that write lands.
*/
export function dapiBinary(): string | null {
if (process.platform === "win32") {
const shim = shimPath();
return app.isPackaged || existsSync(shim) ? shim : null;
}
const command = app.isPackaged ? join(process.resourcesPath, "cli", "bin", "dapi") : DEV_BINARY;
return existsSync(command) ? command : null;
}
function spec(): McpServerSpec {
const binary = dapiBinary();
if (!binary) {
return { url: MCP_URL, command: "", args: [] };
}
// A `.cmd` only runs through a shell, and the agents spawn without one.
if (process.platform === "win32") {
return { url: MCP_URL, command: "cmd", args: ["/c", binary, "mcp"] };
}
return { url: MCP_URL, command: binary, args: ["mcp"] };
}
function resolvePath(location: AgentPath): string {
if (location.root === "home") {
return join(homedir(), location.path);
}
if (location.root === "appData") {
return join(app.getPath("appData"), location.path);
}
throw new Error(`Unknown agent path root: ${location.root}`);
}
function readConfig(target: AgentTarget): string | null {
const path = resolvePath(target.config);
return existsSync(path) ? readFileSync(path, "utf8") : null;
}
function writeConfig(target: AgentTarget, text: string): void {
const path = resolvePath(target.config);
mkdirSync(dirname(path), { recursive: true });
writeFileSync(path, text);
}
/**
* Why this agent cannot be connected from this build, or null when it can.
* Only the stdio agents have reasons: a build without the `diffusion` binary has
* nothing for them to run, and a quarantined first launch runs from a
* translocated read-only mount whose path won't survive the next launch —
* registering it would dangle.
*/
function unavailableReason(target: AgentTarget, current: McpServerSpec): string | null {
if (!needsBinary(target)) return null;
if (current.command === "") return "Needs the diffusion command line tool, which this build does not include.";
if (app.isPackaged && current.command.includes("/AppTranslocation/")) {
return "Move Diffusion Studio to the Applications folder and relaunch it first.";
}
return null;
}
function agentStatus(target: AgentTarget, current: McpServerSpec): McpAgentStatus {
const registered = readServer(readConfig(target), target.format);
return {
id: target.id,
label: target.label,
detected: existsSync(resolvePath(target.marker)),
connected: registered !== null,
config: resolvePath(target.config),
unavailable: unavailableReason(target, current),
};
}
/** Every agent we know, with whether it is on this machine and whether its config carries our entry. */
export function mcpStatus(): McpStatus {
const current = spec();
return { url: current.url, agents: AGENT_TARGETS.map((target) => agentStatus(target, current)) };
}
/**
* Writes our entry into the configs of `add` and takes it out of the configs
* of `remove`, one file at a time, so one unreadable config does not stop
* the rest. Other servers in the same file are left alone either way.
*/
export function applyMcp(request: McpApplyRequest): McpApplyResult {
const current = spec();
const result: McpApplyResult = { added: [], removed: [], failures: [] };
for (const id of request.add) {
const target = agentTarget(id);
const reason = unavailableReason(target, current);
if (reason) {
result.failures.push({ id, error: reason });
continue;
}
try {
writeConfig(target, upsertServer(readConfig(target), target.format, target.entry(current)));
result.added.push(id);
} catch (e) {
result.failures.push({ id, error: `${target.config.path}: ${(e as Error).message}` });
}
}
for (const id of request.remove) {
const target = agentTarget(id);
try {
const next = removeServer(readConfig(target), target.format);
if (next !== null) writeConfig(target, next);
result.removed.push(id);
} catch (e) {
result.failures.push({ id, error: `${target.config.path}: ${(e as Error).message}` });
}
}
return result;
}
/**
* Launch-time self-heal for the stdio agents: an entry that still runs the
* proxy from a bundle that moved (or was translocated when it was written)
* is rewritten to the binary this build has. Entries the user wrote by hand
* for something else are left alone.
*/
export function healMcpRegistrations(): void {
if (!app.isPackaged) return;
const current = spec();
if (current.command === "" || current.command.includes("/AppTranslocation/")) return;
for (const target of AGENT_TARGETS) {
const text = readConfig(target);
const registered = readServer(text, target.format);
if (!registered?.command) continue;
if (!runsOurProxy(registered)) continue;
const entry = target.entry(current);
if (sameCommand(registered, entry)) continue;
try {
writeConfig(target, upsertServer(text, target.format, entry));
} catch {
// best effort — the settings page remains as a manual fix
}
}
}

View File

@ -2,44 +2,21 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { app, dialog, Menu } from "electron";
import { app, Menu } from "electron";
import type { MenuItemConstructorOptions } from "electron";
import { CLI_LINK_PATH, installCli } from "./cli-install";
async function installCliFromMenu() {
const result = await installCli();
if (result.status === "cancelled") return;
if (result.status === "installed") {
await dialog.showMessageBox({
type: "info",
message: "The dapi command line tool was installed.",
detail: `Linked at ${CLI_LINK_PATH}. Run "dapi --help" in a terminal to get started.`,
});
} else {
await dialog.showMessageBox({
type: "error",
message: "Could not install the dapi command line tool.",
detail: result.error,
});
}
}
export function setupAppMenu() {
if (process.platform !== "darwin") return;
// The app submenu is a macOS convention. Elsewhere the same role menus sit
// behind Alt (the window hides the bar) and exist for their accelerators:
// reload, devtools, zoom, quit.
const template: MenuItemConstructorOptions[] = []
const template: MenuItemConstructorOptions[] = [
{
if (process.platform === "darwin") {
template.push({
label: app.name,
submenu: [
{ role: "about" },
{ type: "separator" },
{
label: "Install dapi Command Line Tool…",
enabled: app.isPackaged,
click: installCliFromMenu,
},
{ type: "separator" },
{ role: "services" },
{ type: "separator" },
{ role: "hide" },
@ -48,12 +25,15 @@ export function setupAppMenu() {
{ type: "separator" },
{ role: "quit" },
],
},
});
}
template.push(
{ role: "fileMenu" },
{ role: "editMenu" },
{ role: "viewMenu" },
{ role: "windowMenu" },
];
);
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}

View File

@ -4,16 +4,17 @@
import { contextBridge, ipcRenderer, webUtils } from "electron";
import { MAIN_WIRE } from "./main-channels";
import { CLI_WIRE } from "@diffusionstudio/cli/channels";
import { DAPI_WIRE } from "@diffusionstudio/dapi";
import type { IpcRendererEvent } from "electron";
const ALLOWED_RENDERER_TO_MAIN: ReadonlySet<string> = new Set([MAIN_WIRE.REQUEST]);
const ALLOWED_RENDERER_TO_MAIN: ReadonlySet<string> = new Set([MAIN_WIRE.REQUEST, DAPI_WIRE.REPLY]);
const ALLOWED_MAIN_TO_RENDERER: ReadonlySet<string> = new Set([
MAIN_WIRE.RESPONSE,
MAIN_WIRE.EVENT,
CLI_WIRE.CONNECT,
DAPI_WIRE.CALL,
DAPI_WIRE.CANCEL,
]);
contextBridge.exposeInMainWorld("desktop", {

View File

@ -0,0 +1,98 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// A new project is a draft: made without asking, in the app's own folder,
// named after its id — until it is saved, which moves it where the user said
// and names it after the folder they chose.
import { tmpdir } from "node:os";
import { mkdir, mkdtemp, readdir, readFile, rm } from "node:fs/promises";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
let userData = "";
vi.mock("electron", () => ({
app: { isPackaged: false, getPath: (name: string) => (name === "userData" ? userData : tmpdir()) },
dialog: {},
shell: {},
ipcMain: { on: () => { } },
}));
const { createProject, draftsRoot, duplicateProject, moveProject, readManifest, saveProject, writeManifest } =
await import("./projects");
let root: string;
beforeEach(async () => {
root = await mkdtemp(join(tmpdir(), "drafts-test-"));
userData = join(root, "userData");
});
afterEach(async () => {
await rm(root, { recursive: true, force: true });
});
describe("drafts", () => {
it("creates a draft in the drafts folder, named after its id", async () => {
const project = await createProject();
expect(project.draft).toBe(true);
expect(project.dir).toBe(join(draftsRoot(), project.id));
expect(project.name).toBe(project.id);
expect(project.displayName).toBe("Untitled");
expect(project.entry).toBe("index.tsx");
});
it("duplicates a draft as a draft with an id of its own", async () => {
const source = await createProject();
const copy = await duplicateProject(source.dir);
expect(copy.draft).toBe(true);
expect(copy.id).not.toBe(source.id);
expect(copy.dir).toBe(join(draftsRoot(), copy.id));
});
it("saves a draft by moving it and naming it after the folder", async () => {
const draft = await createProject();
const target = join(root, "Saved", "My Ad");
const saved = await saveProject(draft.dir, target);
expect(saved).toMatchObject({ id: draft.id, dir: target, name: "My Ad", displayName: "My Ad", draft: false });
expect(await readdir(draftsRoot())).toEqual([]);
const pkg = JSON.parse(await readFile(join(target, "package.json"), "utf8"));
expect(pkg.projectId).toBe(draft.id);
});
it("lands a write asked for before the save in the saved folder", async () => {
const draft = await createProject();
const target = join(root, "My Ad");
const manifest = { version: 1, folders: [], assets: [{ id: "a" }] };
const writing = writeManifest(draft.dir, manifest);
await saveProject(draft.dir, target);
await writing;
expect(await readManifest(target)).toEqual(manifest);
expect(await readdir(draftsRoot())).toEqual([]);
});
it("refuses a folder that exists, and a project that is not a draft", async () => {
const draft = await createProject();
const taken = join(root, "taken");
await mkdir(taken);
await expect(saveProject(draft.dir, taken)).rejects.toThrow(/already exists/);
const saved = await saveProject(draft.dir, join(root, "saved"));
await expect(saveProject(saved.dir, join(root, "again"))).rejects.toThrow(/saved already/);
});
it("moves a saved project, keeping its name, and refuses to move a draft", async () => {
const draft = await createProject();
await expect(moveProject(draft.dir, join(root, "elsewhere"))).rejects.toThrow(/Save the draft/);
const saved = await saveProject(draft.dir, join(root, "My Ad"));
const target = join(root, "Archive", "Ad Folder");
const moved = await moveProject(saved.dir, target);
expect(moved).toMatchObject({ id: draft.id, dir: target, name: "Ad Folder", displayName: "My Ad", draft: false });
expect(await readdir(root)).not.toContain("My Ad");
});
});

View File

@ -0,0 +1,86 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// What `open` writes into a folder, and what it refuses: the promise the
// tool reference makes is that a folder opened from anywhere on disk stays
// the user's, gaining an entry and the record and nothing else.
import { tmpdir } from "node:os";
import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("electron", () => ({
app: { isPackaged: false, getPath: () => tmpdir() },
dialog: {},
shell: {},
ipcMain: { on: () => { } },
}));
const { initProject } = await import("./projects");
let root: string;
beforeEach(async () => {
root = await mkdtemp(join(tmpdir(), "init-test-"));
});
afterEach(async () => {
await rm(root, { recursive: true, force: true });
});
describe("initProject", () => {
it("turns a missing folder into a project with an entry and a record, nothing else", async () => {
const dir = join(root, "fresh");
const project = await initProject(null, dir);
expect(project.id).toMatch(/^[\w-]{21}$/);
expect(project.name).toBe("fresh");
expect(project.entry).toBe("index.tsx");
expect((await readdir(dir)).sort()).toEqual(["index.tsx", "package.json"]);
const pkg = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
expect(pkg).toMatchObject({ projectId: project.id, displayName: "fresh", main: "index.tsx" });
});
it("leaves a folder that is already a project untouched", async () => {
const dir = join(root, "kept");
await initProject(null, dir);
const before = await readFile(join(dir, "package.json"), "utf8");
await writeFile(join(dir, "notes.txt"), "mine");
const again = await initProject(null, dir);
expect(again.id).toBe(JSON.parse(before).projectId);
expect(await readFile(join(dir, "package.json"), "utf8")).toBe(before);
expect((await readdir(dir)).sort()).toEqual(["index.tsx", "notes.txt", "package.json"]);
});
it("keeps what a package.json already says and only adds the record fields", async () => {
const dir = join(root, "partial");
await mkdir(dir);
await writeFile(join(dir, "main.tsx"), "export default () => <stage />;\n");
await writeFile(join(dir, "package.json"), JSON.stringify({ name: "partial", main: "main.tsx", scripts: { build: "x" } }, null, 2) + "\n");
const project = await initProject(null, dir);
const pkg = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
expect(pkg.name).toBe("partial");
expect(pkg.main).toBe("main.tsx");
expect(pkg.scripts).toEqual({ build: "x" });
expect(pkg.projectId).toBe(project.id);
expect((await readdir(dir)).sort()).toEqual(["main.tsx", "package.json"]);
});
it("leaves a JavaScript project entirely alone", async () => {
const dir = join(root, "js");
await mkdir(dir);
await writeFile(join(dir, "index.jsx"), "export default () => null;\n");
const project = await initProject(null, dir);
expect(project.id).toBe("");
expect(await readdir(dir)).toEqual(["index.jsx"]);
});
it("refuses a relative path and a path that is a file", async () => {
await expect(initProject(null, "relative/project")).rejects.toThrow(/absolute path/);
const file = join(root, "a-file");
await writeFile(file, "");
await expect(initProject(null, file)).rejects.toThrow(/not a folder/);
expect(await readFile(file, "utf8")).toBe("");
});
});

View File

@ -0,0 +1,51 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// A project folder renamed or moved in Finder is found again next to where it
// was, by the id in its record.
import { tmpdir } from "node:os";
import { mkdir, mkdtemp, rename, rm } from "node:fs/promises";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("electron", () => ({
app: { isPackaged: false, getPath: () => tmpdir() },
dialog: {},
shell: {},
ipcMain: { on: () => { } },
}));
const { findMovedProject, initProject } = await import("./projects");
let root: string;
beforeEach(async () => {
root = await mkdtemp(join(tmpdir(), "locate-test-"));
});
afterEach(async () => {
await rm(root, { recursive: true, force: true });
});
describe("findMovedProject", () => {
it("finds a project renamed in place by its id", async () => {
const project = await initProject(null, join(root, "golden-river"));
await initProject(null, join(root, "another"));
await rename(project.dir, join(root, "My Ad"));
const found = await findMovedProject(project.dir, project.id);
expect(found).toMatchObject({ id: project.id, dir: join(root, "My Ad") });
});
it("finds nothing when the folder left its parent, or the parent is gone", async () => {
const project = await initProject(null, join(root, "golden-river"));
await mkdir(join(root, "elsewhere", "deeper"), { recursive: true });
await rename(project.dir, join(root, "elsewhere", "deeper", "My Ad"));
expect(await findMovedProject(project.dir, project.id)).toBeNull();
expect(await findMovedProject(join(root, "gone", "golden-river"), project.id)).toBeNull();
expect(await findMovedProject(project.dir, "")).toBeNull();
});
});

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,217 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// What the watcher must and must not report. The app writes the files it
// watches, so the whole question is whether a change is its own — answered by
// content (see `noteContent`), which is what these pin down.
import { tmpdir } from "node:os";
import { mkdir, mkdtemp, open, rename, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { MAIN_CHANNELS, MAIN_WIRE } from "./main-channels";
import { TEMP_PREFIX, tempPathFor, writeFileAtomic } from "./atomic";
vi.mock("electron", () => ({
app: { isPackaged: false, getPath: () => tmpdir() },
dialog: {},
shell: {},
ipcMain: { on: () => { } },
}));
const { noteContent, noteRenamed, readConfig, unwatchProject, watchProject, writeConfig, writeManifest } = await import("./projects");
let dir: string;
let changed: string[] = [];
/** A window that only remembers which project files it was told about. */
const window = {
isDestroyed: () => false,
webContents: {
isLoading: () => false,
send: (wire: string, envelope: { channel: string; data: { path: string } }) => {
if (wire === MAIN_WIRE.EVENT && envelope.channel === MAIN_CHANNELS.PROJECTS_CHANGED) {
changed.push(envelope.data.path);
}
},
},
} as unknown as Parameters<typeof watchProject>[0];
/** Long enough for an event to have arrived, for the cases where none may. */
const settle = (ms = 400): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
/** Waits for `path` to be reported, and fails the test when it never is. */
async function waitFor(path: string, timeout = 4000): Promise<void> {
const until = Date.now() + timeout;
while (Date.now() < until) {
if (changed.includes(path)) return;
await settle(25);
}
expect(changed).toContain(path);
}
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), "watch-test-"));
changed = [];
watchProject(window, dir);
await settle(100);
});
afterEach(async () => {
unwatchProject(dir);
await rm(dir, { recursive: true, force: true });
});
describe("watchProject", () => {
it("reports a file someone else writes", async () => {
await writeFile(join(dir, "index.tsx"), "export const stage = 1;\n", "utf8");
await waitFor("index.tsx");
});
// Without this the claim above proves nothing: a rename that never reached
// the watcher would look exactly like a claim that worked.
it("reports a file someone else replaces by rename", async () => {
await writeFileAtomic(join(dir, "index.tsx"), "export const stage = 1;\n");
await waitFor("index.tsx");
});
it("says nothing about a write the app claimed", async () => {
const file = join(dir, "index.tsx");
const text = "export const stage = 1;\n";
noteContent(file, text);
await writeFileAtomic(file, text);
await settle();
expect(changed).toEqual([]);
});
it("reports an outside edit that lands right after one of the app's own", async () => {
const file = join(dir, "index.tsx");
noteContent(file, "ours\n");
await writeFileAtomic(file, "ours\n");
// No claim: this one is someone else's, however close behind it comes.
await writeFile(file, "theirs\n", "utf8");
await waitFor("index.tsx");
});
it("says nothing about a write that changes nothing", async () => {
const file = join(dir, "notes.txt");
await writeFile(file, "same\n", "utf8");
await waitFor("notes.txt");
changed = [];
await writeFile(file, "same\n", "utf8");
await settle();
expect(changed).toEqual([]);
});
it("reports a file someone else deletes", async () => {
const file = join(dir, "notes.txt");
await writeFile(file, "here\n", "utf8");
await waitFor("notes.txt");
changed = [];
await rm(file);
await waitFor("notes.txt");
});
it("ignores the temp files an atomic write leaves in the folder", async () => {
await writeFile(join(dir, `${TEMP_PREFIX}index.tsx.1-1`), "half a file", "utf8");
await settle();
expect(changed).toEqual([]);
});
it("says nothing about an asset streamed to a temp file and renamed into place", async () => {
await mkdir(join(dir, "assets"), { recursive: true });
await waitFor("assets");
const file = join(dir, "assets", "clip.bin");
changed = [];
const temp = tempPathFor(file);
const handle = await open(temp, "wx");
// Positioned chunks, the way an encoder writes one.
await handle.write(Buffer.from("chunk one"), 0, 9, 0);
await settle();
await handle.write(Buffer.from(" and two"), 0, 8, 9);
await handle.close();
await settle();
// Nothing has appeared where the library looks, so there is nothing to say.
expect(changed).toEqual([]);
await noteRenamed(temp, file);
await rename(temp, file);
await settle();
expect(changed).toEqual([]);
});
it("reports an asset someone else renames into place", async () => {
await mkdir(join(dir, "assets"), { recursive: true });
await waitFor("assets");
changed = [];
const temp = tempPathFor(join(dir, "assets", "clip.bin"));
await writeFile(temp, "theirs", "utf8");
await rename(temp, join(dir, "assets", "clip.bin"));
await waitFor("assets/clip.bin");
});
// The claim for a file too big to hash is its size and mtime, which a rename
// has to carry across untouched for `noteRenamed` to mean anything.
it("says nothing about a file too big to hash, claimed before its rename", async () => {
const file = join(dir, "assets", "big.bin");
await mkdir(join(dir, "assets"), { recursive: true });
await waitFor("assets");
changed = [];
const temp = tempPathFor(file);
await writeFile(temp, Buffer.alloc(9 * 1024 * 1024, 7));
await noteRenamed(temp, file);
await rename(temp, file);
await settle();
expect(changed).toEqual([]);
});
it("says nothing about the manifest it writes itself", async () => {
await writeManifest(dir, { assets: [{ source: "assets/clip.mp4" }] });
await settle();
expect(changed).toEqual([]);
});
// A slider in the export settings writes the config on every move, so the
// next write is claimed before the event for the last one is answered.
it("says nothing about config writes that overlap, and keeps the last", async () => {
await writeFile(join(dir, "package.json"), `${JSON.stringify({ name: "p" }, null, 2)}\n`, "utf8");
await waitFor("package.json");
changed = [];
const writes: Promise<void>[] = [];
for (let bitrate = 1; bitrate <= 40; bitrate++) {
writes.push(writeConfig(dir, { export: { intro: { video: { bitrate } } } }));
await settle(8);
}
await Promise.all(writes);
await settle();
expect(changed).toEqual([]);
expect(await readConfig(dir)).toEqual({ export: { intro: { video: { bitrate: 40 } } } });
});
it("reports an outside edit that lands between two of the app's own", async () => {
const file = join(dir, "index.tsx");
noteContent(file, "ours\n");
noteContent(file, "ours again\n");
await writeFileAtomic(file, "ours\n");
await writeFile(file, "theirs\n", "utf8");
await waitFor("index.tsx");
changed = [];
await writeFileAtomic(file, "ours again\n");
await settle();
expect(changed).toEqual([]);
});
});

View File

@ -1,191 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { app } from "electron";
import { existsSync, lstatSync, mkdirSync, readdirSync, readlinkSync, rmSync, symlinkSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import type { SkillsInstallResult } from "./main-channels";
const AGENT_SKILLS_DIRS = [
".adal/skills",
".agents/skills",
".aider-desk/skills",
".astrbot/data/skills",
".augment/skills",
".autohand/skills",
".bob/skills",
".claude/skills",
".clawdbot/skills",
".codeartsdoer/skills",
".codebuddy/skills",
".codeium/windsurf/skills",
".codemaker/skills",
".codestudio/skills",
".codex/skills",
".commandcode/skills",
".config/agents/skills",
".config/crush/skills",
".config/devin/skills",
".config/goose/skills",
".config/kimchi/harness/skills",
".config/opencode/skills",
".continue/skills",
".copilot/skills",
".cursor/skills",
".deepagents/agent/skills",
".factory/skills",
".firebender/skills",
".forge/skills",
".gemini/antigravity-cli/skills",
".gemini/antigravity/skills",
".gemini/skills",
".grok/skills",
".hermes/skills",
".iflow/skills",
".inferencesh/skills",
".jazz/skills",
".junie/skills",
".kilocode/skills",
".kiro/skills",
".kode/skills",
".lingma/skills",
".mcpjam/skills",
".minimax/skills",
".moltbot/skills",
".moxby/skills",
".mux/skills",
".neovate/skills",
".ona/skills",
".openclaw/skills",
".openhands/skills",
".pi/agent/skills",
".pochi/skills",
".posit/assistant/skills",
".qoder-cn/skills",
".qoder/skills",
".qwen/skills",
".reasonix/skills",
".roo/skills",
".rovodev/skills",
".snowflake/cortex/skills",
".tabnine/agent/skills",
".terramind/skills",
".tinycloud/skills",
".trae-cn/skills",
".trae/skills",
".vibe/skills",
".zcode/skills",
".zencoder/skills",
];
const FALLBACK_AGENT_DIR = ".claude/skills";
function stagedSkillsDir(): string {
return app.isPackaged
? join(process.resourcesPath, "skills")
: join(app.getAppPath(), "skills");
}
function stagedSkillNames(): string[] {
const dir = stagedSkillsDir();
if (!existsSync(dir)) return [];
return readdirSync(dir, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name);
}
// Agents whose config dir exists on this machine, falling back to Claude Code
// so a machine with no agent yet still gets set up for the primary one.
function targetAgentDirs(): string[] {
const home = homedir();
const present = AGENT_SKILLS_DIRS.filter((dir) => existsSync(join(home, dirname(dir))));
return (present.length > 0 ? present : [FALLBACK_AGENT_DIR]).map((dir) => join(home, dir));
}
// `existsSync` follows symlinks, so a dangling link doesn't count.
export function isSkillsInstalled(): boolean {
const home = homedir();
const marker = stagedSkillNames()[0] ?? "editor";
return AGENT_SKILLS_DIRS.some((dir) => existsSync(join(home, dir, marker, "SKILL.md")));
}
// ln -sf semantics that never clobber real files: an existing symlink is
// repointed (ours or the skills CLI's — the user asked to install), but a
// real directory (a `skills add --copy` install) is left alone.
function linkSkill(linkPath: string, target: string): void {
try {
if (!lstatSync(linkPath).isSymbolicLink()) return;
rmSync(linkPath);
} catch {
// nothing at linkPath
}
symlinkSync(target, linkPath);
}
export function installSkills(): SkillsInstallResult {
const source = stagedSkillsDir();
// A quarantined first launch runs from a translocated read-only mount whose
// path won't survive the next launch — linking to it would dangle.
if (source.includes("/AppTranslocation/")) {
return {
status: "error",
error: "Move Diffusion Studio to the Applications folder and relaunch it, then try again.",
};
}
const skills = stagedSkillNames();
if (skills.length === 0) {
return {
status: "error",
error: app.isPackaged
? "The app bundle is missing its skills resources."
: "Skills are not staged — run `npm run stage:skills` in apps/desktop.",
};
}
try {
for (const agentDir of targetAgentDirs()) {
mkdirSync(agentDir, { recursive: true });
for (const name of skills) {
linkSkill(join(agentDir, name), join(source, name));
}
}
return { status: "installed" };
} catch (e) {
return { status: "error", error: (e as Error).message };
}
}
/**
* Launch-time self-heal: links created by installSkills break when the app
* moves or was translocated when they were made. Any symlink that targets a
* Diffusion Studio bundle but not the running app's resources is repointed.
* Links owned by the skills CLI and copied installs are left alone.
*/
export function healSkillsLinks(): void {
if (!app.isPackaged) return;
const source = stagedSkillsDir();
if (source.includes("/AppTranslocation/")) return;
const home = homedir();
for (const dir of AGENT_SKILLS_DIRS) {
for (const name of stagedSkillNames()) {
const linkPath = join(home, dir, name);
let target: string;
try {
target = readlinkSync(linkPath);
} catch {
continue; // missing, or not a symlink
}
const ours = target.includes("Diffusion Studio") || target.includes("/AppTranslocation/");
const current = join(source, name);
if (!ours || target === current) continue;
try {
rmSync(linkPath);
symlinkSync(current, linkPath);
} catch {
// best effort — the install button remains as a manual fix
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More