Skip to content

Open source CapCut alternative.

TypeScript
20.7 KB
Raw Blame
import { AI_SKILLS } from "@/cut/server/ai/catalog";
import { DOC_EXPORT_PRESETS } from "@/cut/lib/exportPresets";

/** Translate the shared catalog's references for this client: its state
 * read, its import, and the editor chat's Pexels-only web fetch, which
 * ChatGPT's own browsing stands in for. */
export function chatgptDescription(text: string): string {
  return text
    .replace(/\bget_state\b/g, "inspect_project")
    .replace(/\bimport_url\b/g, "import_media")
    .replace(/Search it with WebFetch — the one web tool you have, and it reaches only Pexels:/g, "Search it on the web:");
}

// These guides describe editing operations shared by every client. Additions
// are selected here after checking their commands and interaction model.
const SHARED_SKILLS = [
  "color-grading",
  "replicating-a-video",
  "transitions-and-fades",
  "text-videos",
  "text-creativity",
  "editing-taste",
  "talking-head-videos",
] as const;

const SKILLS: Record<string, string> = {
  ...Object.fromEntries(SHARED_SKILLS.map((name) => [name, chatgptDescription(AI_SKILLS[name])])),

  "editor-overview": `# Donkey Cut in ChatGPT
ChatGPT plans the edit and interprets the footage with the user. Donkey Cut imports media, measures it, applies editing commands, and renders the result.
Work on the connected account's cloud projects. Use list_projects or create_project, then open_project once. Keep that card throughout inspection, imports, edits, previews, undo and redo: reopening starts a fresh editor with empty history. The existing card shows edits immediately; render_preview and get_preview_status verify the saved preview. Recover a missing card with open_project and resume when ready. Local projects become accessible after the user saves them to cloud in Donkey Cut.
Read inspect_project for current assets, selection, tracks, captions, notes and settings. An editor_state mentioned in these guides is that returned state. Times are seconds and ids come from tool results.
Every editing operation is its own tool taking projectId. Each write is one undo step; the user's manual edits share that history. Read each result before continuing.
The card offers the timeline, preview and inspector. ChatGPT provides the conversation and calls the media and caption commands. When a required asset is missing, ask the user for a file or link, or discuss suitable stock. Ask about creative choices when the answer materially changes the requested result.`,

  "timeline-editing": `# Timeline editing
Inspect the project before editing. Every track uses start times and allows gaps. add_clip places a project asset; add_overlay_video places footage on an upper track. add_clip with blocks lays out placeholders for footage the user will supply, and replace_item fills them while retaining the edit's timing.
trim_clip uses source seconds. split_at and place_clip use timeline seconds. For uniform forward playback, timeline time = clip.start + (source time - clip.in) / clip.speed. For reverse playback use clip.out - source time. For speed curves use the reported len and returned timing data.
delete_item removes the item and its group, leaving a gap. remove_gap closes a gap on one row; with the magnet on (set_magnet), track 0 closes up on every edit. place_clip places by time; move_clip reorders by index. Growth pushes overlapping neighbors on the same row; shrinking leaves a gap. Read returned ids and timing after each mutation.
set_speed changes uniform speed or reverse playback; set_speed_curve adds a rate curve. detach_audio separates a clip's sound for independent editing. freeze_frame creates a still. set_framing adjusts fit, fill, zoom and pan; set_clip_keyframes animates a clip's transform.
Use select_items to find items from their recorded state and apply batch-capable tools with ids. Measure or watch first when the selection depends on media content. set_clip_hidden and track visibility tools preserve items while excluding them from playback and export.
Transitions sit at cuts and retain their positions as edits move footage. Inspect parkedTransitions after mutations and remove unused transitions. Read transitions-and-fades, color-grading or graphics for styling. Verify the changed span with capture_frame and listen_audio, and use undo or redo for the shared editor history.`,

  "watching-and-cutting": `# Watching footage and cutting by content
Inspect the project for asset ids, transcripts, trims, notes and existing coverage. ChatGPT interprets the returned frames and audio; Donkey Cut supplies measurements and timing. Watch footage before deciding cuts that depend on its content.
watch_video returns timestamped contact sheets, sceneChanges and coverage. Stamps are source seconds. Continue from coveredTo when truncated. For a request about the whole source, cover it until unwatchedSeconds reaches zero. For long footage, sweep coarsely to learn its structure, then inspect relevant spans closely. A source map or a transcript alone does not establish visual coverage. Use detail read or original to read text and match typography; scan is for structure. Check unreadSeconds and unreadFrom when legible coverage matters.
After every watch, record what you observed with note_source: source span, actions, cuts, and exact on-screen words. A further watch can be refused until those observations are recorded. Notes persist on the asset; returned contact sheets belong to this conversation. Read observed, recorded and unnoted to resume from existing evidence.
listen_audio returns playable source audio. Use the transcript for words and listen for delivery, music and timing. Respect coveredTo; continue from unheardFrom until unheardSeconds reaches zero when judging a whole source. Record observations with note_source. A clip_id scopes listening to its source trim; from and to are source seconds.
Use signal measurements for editing decisions: detect_silence locates quiet spans; detect_beats returns a beat grid and timelineBeats for a clip; measure_level measures loudness, including integratedLufs and truePeakDbtp per clip and for the whole mix, and returns volumeToMatch against a target. read_color_stats measures exposure, tonal range and color before grading. compare_to_source checks the edit against a reference; capture_frame shows the composited picture. detect_cuts, sample_color and track_element measure a source's cuts, colours and moving elements as numbers, inside the picture box find_picture keeps for a recorded or letterboxed source. detect_cuts keeps the box it finds on a source's first read.
find_filler identifies transcript fillers; find_highlights ranks transcript spans. Their results need the relevant visual or audio check before cutting. Caption creation is a separate edit requested by the user.
Plan cuts around complete thoughts and measured pauses. Split and delete in batches, read the resulting ids, then place clips to close intended gaps. Leave room around speech boundaries and run refine_speech_cuts with the requested pace. Listen around adjusted edges, widen a clipped word's trim, and check the changed cut visually. Source seconds drive watches, listens and trims; timeline seconds drive placement and splits. Use the clip timing data to map between them.
Report only the coverage you inspected and the changes tool results confirm. render_preview produces a playable saved revision for the user to review.`,

  "background-removal": `# Background removal
set_removal mode auto starts the free person matte. remove background keeps the subject; remove subject keeps the surroundings. mode custom tracks the described subject and spends credits. refine requests the paid quality pass when the user asks for an upgrade. mode off retains the stored settings.
The matte prepares in the editor. Read each clip's removal readiness and progress with inspect_project; a command returning successfully can still leave matting in progress. Check capture_frame after it is ready. Poll a returned command job with get_job_status; that job's completion and the matte's readiness are separate results.
For one exact instance among similar subjects, ask the user to use Custom, Brush and Erase in the Cutout inspector and press Apply. set_removal_stroke adds an outline, and set_removal_background fills behind the kept subject. A lower video track can carry independently editable scenery.`,

  "graphics": `# Titles, graphics and motion
Use add_title or add_text_sequence for words, add_shape for geometry, add_sticker for an imported image, and add_effect for a treatment over a time range. Each tool's schema lists the supported styles and parameters. set_background sets the project's background color. Use ids and fonts reported by inspect_project.
update_overlay changes text, position, size, color and other element fields, and accepts ids for changes shared by several elements. Layout coordinates are frame fractions. Keep text inside the project's reported safe zones and check legibility with capture_frame.
set_overlay_keyframes and set_clip_keyframes animate poses at exact times. set_group_camera moves one camera over a group of elements, and blur and motion blur soften what the camera is not on. set_overlay_animation supplies entrances, exits, loops, word motion, a typing caret and a one-shot press at a chosen moment. set_mask clips a layer to a shape and can animate the reveal. track_motion keys a mask or a pose to a hand, a head or a person in the footage, frame by frame. set_clip_effects treats one clip alone, inside its mask. Read text-videos for timed text and text-creativity for design choices.
Build composite effects as layers: add_overlay_video for copies of footage, masks for visible regions, shapes for bands, and text for labels. Match source trims so copied footage stays synchronized. Work out geometry and timing, build one representative piece, capture_frame to check it, then repeat and check the whole composition. create_sticker generates a new sticker and spends credits when the user requests it.`,

  "audio-and-subtitles": `# Audio and subtitles
Listen to the relevant source with listen_audio. Use detect_silence for pauses, detect_beats for music timing, and measure_level for level matching. Its volumeToMatch result can drive set_clip_volume or update_audio; use a fraction for a music bed beneath speech. Read watching-and-cutting for coverage and source-time rules.
update_audio edits soundtrack timing, source trim, volume, fades and ducking. A clip's duck lowers other audio while it plays. set_clip_sound applies EQ, compression and limiting to one clip; add_effect treats a time range of the mix. sync_audio lines a separately recorded audio file up with a video's own sound and binds it, so every clip of the video plays the recording; it refuses when no alignment is clear. set_split_edit starts a clip's sound before its picture or carries it past the cut, for J- and L-cuts. Each tool's schema lists the supported presets and settings.
When captions are requested, subtitles_generate transcribes the cut; sync_lyrics aligns supplied words with the audio. subtitles_from_visuals writes descriptions of silent footage when the user wants them. captions_generate rewrites existing captions. These model-backed operations use the account's applicable allowance or credits.
Use update_cue, delete_cue and merge_cue for corrections. subtitles_add_track, subtitles_remove_track and subtitles_translate_track manage languages. set_caption_look controls appearance and words per cue; subtitles_set_view controls visibility. set_caption_emphasis sets one or two key words apart in a caption every few lines when the user asks for emphasis, and update_cue x/y gives one caption its own spot. Each tool's schema lists the current choices, and text-videos covers timed text layouts. align_to_audio measures timing against the mix.
For requested audio generation, list_voices supplies voice ids, voiceover_generate speaks a script, read_subtitles_aloud voices timed cues, and generate_music makes music. Generation spends credits. Read the result for asset ids and placement, then inspect and listen to verify it. These tools work while the editor card is open.`,

  "ai-generation": `# Finding and creating media
Start with the user's project assets, attached files and links. import_media imports ChatGPT attachments or URLs into the cloud project. Poll a returned job with get_job_status, then use the asset ids in the completed result. Ask for missing footage or a reference when it is needed to fulfill the request.
stock_search finds existing footage, images and sounds; stock_add imports a chosen result. Inspect the media before placing it. ChatGPT can plan a sequence from the supplied footage and use add_clip with blocks to mark missing shots for the user.
Available generation commands include generate_image, voiceover_generate, generate_music and create_sticker. Use them when the user requests generated media; they spend account credits. Each tool's schema lists current options. Inspect returned asset ids and placement, and place an unplaced asset with add_clip or add_overlay_video when the user asked for it in the cut.
When a requested operation is unavailable, explain the limit and ask the user to supply the required media or complete that step in Donkey Cut.`,

  "media-and-library": `# Media and Library
inspect_project reports the open project's media. import_media brings files and links into it. add_clip and add_overlay_video place assets, replace_item changes an item's source, and file_asset files created media into Media or copies it to the Library. media_organize manages this project's folders and renames its files. convert_media converts project assets; read its result and inspect the updated assets before claiming completion.
read_folder browses project or Library folders and accessible Donkey folder links with paged results. library_add accepts share_link for shared assets. library_list reads reusable assets, folders and templates across projects. library_add copies an asset into the project; template_add restores a saved arrangement; save_template stores selected timeline items. library_organize manages that shelf. notes_list reads synced scripts and ideas; read_note opens current text by attachment id or note URL. note_save creates or edits a note and sets its Library folder when asked. Read replicating-a-project to reuse an existing edit.
delete_asset removes project media and its timeline uses. Library deletions can affect the user's synced shelf. These deletions require the user's explicit request; undo covers timeline edits and does not restore deleted source files.`,

  "replicating-a-project": `# Reusing a project
read_project inspects a source project by id or link, or a share link; list_projects finds the id of a project named by its title. Use its returned ids and document to understand the edit; use watch_video and listen_audio for media you need to judge. Ask for a reference the user can share when access fails.
replicate_project copies the requested edit or items and can map source roles to assets already in this project. Match by content and measured timing. Unmapped media copies from the reference. copy_project_media brings across media for a new arrangement.
Read the resulting adjustments and placement: trims can clamp to shorter replacement sources, and clips append to the current cut. Inspect the result, revise the requested text and timing, and check frames and audio. Apply background removal to replacement footage when requested. save_template and template_add support reusable arrangements.`,

  "publish-and-export": `# Publish and export
set_publish edits the project's caption, tags, sound title and handle. These fields describe the intended post.
export_video renders the saved cloud project with one of these presets: ${DOC_EXPORT_PRESETS.join(", ")}. Read its tool description for the preset choices. loudness masters the mix to a LUFS target for its destination, and stems adds a zip of one WAV per lane for mixing elsewhere. A returned export job is completed through get_export_status, and the card offers the finished download. render_preview and get_preview_status provide a playable preview for review. Only report a preview or export as ready when its result confirms completion.`,
};

// What each guide is for, as the plugin's skill description: ChatGPT reads
// it to decide when to load the guide.
const DESCRIPTIONS: Record<string, string> = {
  "color-grading": "Grade and match color in Donkey Cut: exposure, contrast, curves, wheels, hue bands, LUTs and presets. Use when the user asks to change the look or color of footage.",
  "replicating-a-video": "Recreate the structure and style of a reference video with the user's own footage in Donkey Cut. Use when the user shares a video to copy.",
  "transitions-and-fades": "Add transitions between clips and fade clips in and out in Donkey Cut. Use when the user asks for smoother cuts, fades or transition effects.",
  "text-videos": "Build Donkey Cut videos driven by on-screen text: lyric videos, kinetic typography, quotes and timed captions. Use when text is the main visual.",
  "text-creativity": "Choose fonts, colors, layout and motion for on-screen text in Donkey Cut. Use when the user wants titles or captions to look designed.",
  "editing-taste": "Pacing, hooks and structure for short social videos in Donkey Cut. Use when the user asks to make an edit better, tighter or more engaging.",
  "talking-head-videos": "Edit talking-head footage in Donkey Cut: cut pauses and filler, add captions, punch-ins and b-roll. Use for vlogs, interviews and direct-to-camera videos.",
  "editor-overview": "How Donkey Cut works inside ChatGPT: cloud projects, the editor card, shared undo history, and which tools read or edit. Use at the start of any Donkey Cut editing session.",
  "timeline-editing": "Place, trim, split, move, retime and delete clips on the Donkey Cut timeline. Use when the user asks to cut, reorder, speed up or rearrange footage.",
  "watching-and-cutting": "Watch and listen to footage, measure silence, beats and levels, and cut by content in Donkey Cut. Use before content-based edits such as removing pauses, picking highlights or cutting to music.",
  "background-removal": "Remove or replace the background behind a person or subject in a Donkey Cut clip. Use when the user asks for a cutout or a background swap.",
  "graphics": "Add and animate titles, shapes, stickers, masks and effects in Donkey Cut. Use when the user asks for on-screen text, graphics, motion or layered composites.",
  "audio-and-subtitles": "Mix audio, level and duck tracks, and create, style, translate or correct subtitles in Donkey Cut. Use for sound, music, voiceover and caption requests.",
  "ai-generation": "Find stock media and generate images, voiceover, music and stickers in Donkey Cut with the account's credits. Use when the user needs media the project does not have.",
  "media-and-library": "Import, organize, convert and delete Donkey Cut project media and Library assets. Use when the user manages files, folders, notes or templates.",
  "replicating-a-project": "Reuse another Donkey Cut project's edit, media or template in this one. Use when the user points at an existing project or share link to copy.",
  "publish-and-export": "Export the finished Donkey Cut video and set its publish caption and tags. Use when the user wants a file to download or post.",
};

/** The plugin's setup skill: ChatGPT runs it once the plugin is installed. */
const ONBOARDING_SKILL = {
  name: "setup",
  description: "Set up Donkey Cut after installing the plugin: confirm the connected account, then open or create the first cloud project. Use right after installation or when the user asks how to start with Donkey Cut.",
  body: `# Getting started with Donkey Cut
1. Call account_status. Tell the user their plan, AI credit balance and cloud storage in one line. Editing, previews and exports are free; hosted AI generation spends credits.
2. Call list_projects. When projects exist, name the three most recent and ask which to open. When there are none, ask what the video is for and its shape (9:16 for TikTok, Reels and Shorts, 16:9 for YouTube, 1:1 square), then call create_project.
3. Call open_project for the chosen project. The editor card holds the timeline, media panel and preview; keep it open while editing.
4. Ask the user to attach footage or paste a link, and bring it in with import_media.
Projects saved on a Mac or in a browser reach ChatGPT once the user saves them to the cloud in Donkey Cut. Ask before creating a project the user did not request.`,
};

export const SKILL_INDEX = Object.keys(SKILLS);

/** Every guide as a plugin skill, the setup skill first. */
export function pluginSkills(): { name: string; description: string; body: string }[] {
  return [ONBOARDING_SKILL, ...SKILL_INDEX.map((name) => ({ name, description: DESCRIPTIONS[name], body: SKILLS[name] }))];
}

export function readSkill(name: string): string | undefined {
  return Object.hasOwn(SKILLS, name) ? SKILLS[name] : undefined;
}