Skip to main content
Glama
README.md
# ![legends-capcut](assets/banner.png)

[![release](https://img.shields.io/github/v/release/avalonreset/legends-capcut?label=release&sort=date&style=flat-square&labelColor=000000&color=ff0000)](https://github.com/avalonreset/legends-capcut/releases/latest)
[![checks](https://img.shields.io/github/actions/workflow/status/avalonreset/legends-capcut/checks.yml?branch=main&label=checks&style=flat-square&labelColor=000000)](https://github.com/avalonreset/legends-capcut/actions/workflows/checks.yml)
[![python](https://img.shields.io/badge/python-3.11%2B-000000?style=flat-square&labelColor=000000&color=ff0000)](pyproject.toml)
[![platforms](https://img.shields.io/badge/platforms-windows%20%7C%20macos%20%7C%20linux-000000?style=flat-square&labelColor=000000&color=ff0000)](routes.json)
[![license](https://img.shields.io/github/license/avalonreset/legends-capcut?label=license&style=flat-square&labelColor=000000&color=666666)](LICENSE)

**Agent-native editing for CapCut Desktop: compile a plain JSON timeline into a real CapCut project, read any project back into scenes, patch one scene surgically, watch the editor play it back, and critique every scene before a human ever opens the file.**

## `>_ agent handoff`

Paste this into your coding agent, then talk to it in plain english about the cut you want.

```text
Install or update legends-capcut via cto-legends (https://github.com/avalonreset/cto-legends): run `cto-legends install legends-capcut --apply`, then `cto-legends handoff legends-capcut` and follow the returned recipe to verify `legends-capcut doctor`.
```

After that you never type a flag. Say "build the launch teaser from these clips and the song", "S04 drags, cut it to two seconds", "swap the third shot for the drone clip" or "watch the last ten seconds and tell me what reads badly", and the agent turns it into the right command.

## Why `legends-capcut` exists

CapCut Desktop is where a lot of good short form video actually gets finished, and it has no public automation surface at all. Ask an unguided agent to edit a CapCut project and it fails in the same predictable ways: it hand-writes a `draft_content.json` that CapCut silently refuses to open, it rewrites the whole timeline to change one clip, it forgets the `Timelines` copy CapCut actually prefers, it leaves orphan media in `Resources`, and it cannot see what it just made. `legends-capcut` closes every one of those gaps.

### Beat 1: one compiler, both directions

- **End-to-end bidirectional compiler.** A timeline spec goes in and a complete CapCut project folder comes out, with video, overlay, text and audio tracks, transitions, in and out animations, keyframes, beat markers, audio fades and ducking. `inspect` runs the other way and decodes any project, including ones you cut by hand, into scenes `S01`, `S02` and onward.
- **Surgical single-scene patcher.** Replace, trim, extend or shorten one scene, rewrite its statement, add a scale punch or hide it. Later scenes ripple, untouched tracks stay byte-identical, and a replacement plus a new duration lands in one call.
- **Live `gui watch` playback eyes.** The agent launches CapCut, opens the project, scrubs, fires the real shortcut combos from your active keymap and captures a playback contact sheet of what the editor actually rendered.
- **Perpetual storyboards.** Every scene gets a six-frame strip with timecode, motion deltas, density class and on-screen copy, so an agent can review a whole cut in one image instead of guessing from JSON.
- **Reveal-aware readability and overstay critic.** The audit measures when each scene finishes revealing, how long it then holds static and whether its text can be absorbed in the time it gets, and flags scenes that are too tight or overstay their welcome.
- **A CLI and MCP pair.** Every operation exists as a `legends-capcut` command and as a matching `capcut_*` MCP tool, with the same JSON in and out, so any agent host can drive it.

### Beat 2: opinionated curation

There are plenty of ways to make video with code. Most of them render a flat file and hand you something you cannot touch afterward. `legends-capcut` is here because the finished artifact should be a CapCut project a human can open, nudge and export, not a dead render. The agent does the tedious assembly and the review passes; the human keeps the editor they already trust.

It chains cleanly into the rest of the stack. `legends-yt-dlp` and `legends-obs` bring in source footage and screen captures. `legends-stable-audio-3` scores the cut, and `beat-sync` turns that track into beat markers the compiler snaps scenes to. `legends-captions` covers burned-in active-word captions. An optional local Windows desktop bridge supplies the hands behind the `gui` commands (the core compiler, reader, patcher, beat sync, storyboards, and readability critic run standalone with zero GUI bridge). When the cut is approved, `legends-youtube` takes the export to a draft upload.

### Beat 3: gentlemanly control without babysitting

You do not have to supervise every keystroke, because the tool refuses to do anything you would have to clean up after.

- It only writes to projects it generated itself, which carry a `.legends_capcut_generated.json` marker. Your hand-cut projects are read only.
- Every patch is validated in memory before a single byte lands. A refused patch writes nothing and copies no media.
- Writes go through a temp file and an atomic rename, and the root draft, its `.bak` and the `Timelines` copies always move together.
- `inspect`, `scan-effects`, `keymap` and `doctor` never write anything, and nothing in the package talks to the network.
- The GUI commands drive the visible CapCut window. Nothing runs hidden and nothing bypasses your PowerShell policy.

So you hand over the brief, glance at the storyboard and the critic's verdict, and open the project in CapCut when it is ready for your taste.

## Quick start

```bash
legends-capcut doctor
legends-capcut build spec.json "My Cut" --review-burnin --register
legends-capcut inspect "My Cut"
legends-capcut patch-scene "My Cut" S03 --replace media/drone.mp4 --duration 2.0
legends-capcut storyboard "My Cut" out/storyboard
legends-capcut audit-readability "My Cut"
legends-capcut review-burnin "My Cut" hide
legends-capcut validate "My Cut"
```

Every command prints one JSON object. Exit code `0` means success, `2` means a refused or invalid request, `1` means an unexpected failure.

## Reference

<details>
<summary><strong>Install and optional extras</strong></summary>

Through the router (recommended for agents): see the handoff block above.

Standalone from source:

```bash
pip install "legends-capcut @ git+https://github.com/avalonreset/legends-capcut"
```

Optional extras:

```bash
pip install "legends-capcut[beats]"   # numpy, scipy, pillow for beat sync and charts
pip install "legends-capcut[audio]"   # soundfile and faster-whisper for the vocal presence check
pip install "legends-capcut[vision]"  # numpy and pillow for storyboards, readability probes and GUI capture
```

The core needs only the Python standard library. `ffmpeg` and `ffprobe` on `PATH` are used for media probing, cover frames and audio decoding when present.

</details>

<details>
<summary><strong>Plane by plane</strong></summary>

| Plane | What you get |
| --- | --- |
| Draft compiler | Timeline spec in, complete CapCut project folder out: video, overlay, text and audio tracks, transitions, in and out animations, keyframes, beat markers, audio fades and ducking, review burn-in. |
| Draft reader | `inspect` decodes any project into scenes with source paths, statements, transitions, animations and keyframes. Read only. |
| Scene patcher | Replace, trim, extend or shorten one scene, rewrite its statement, add or remove a scale punch, hide it. Later scenes ripple; untouched tracks stay byte-identical. |
| Track flags | Mute or hide any track the same way the CapCut track header does. |
| Effect scanner | Catalogs the effects, transitions, animations, adjustments and blend modes already cached on this machine, so a spec can ask for `"Pull In"` by name. |
| Keymap reader | Resolves the active CapCut shortcut preset and returns the real combo for each core action, falling back to factory defaults. |
| Beat sync | Tempo, beats, downbeats and song sections from an audio file, plus a diagnostic PNG. |
| Vision | Perpetual storyboard contact sheets and a reveal-aware readability and pacing audit. |
| GUI | Launch CapCut, open a project, scrub, watch playback, take screenshots, fire keymap actions. Windows only. |

The full capability list is in [CAPABILITIES.md](CAPABILITIES.md).

</details>

<details>
<summary><strong>A minimal timeline spec</strong></summary>

```json
{
  "name": "Launch Teaser",
  "canvas": {"width": 1920, "height": 1080, "fps": 30},
  "video_track": [
    {"path": "media/hook.mp4", "duration_s": 3.0, "statement": "Edit by talking",
     "transition": {"name": "Dissolve", "duration_ms": 400}},
    {"path": "media/proof.png", "duration_s": 4.0, "scale_punch": true,
     "animation_in": {"name": "Fade In", "duration_ms": 300}}
  ],
  "audio_track": [{"path": "media/music.wav", "fade_in_ms": 200, "fade_out_ms": 600,
                   "duck": [{"start_s": 1.0, "end_s": 3.0, "db": -12}]}],
  "beat_map_path": "media/music.beat_map.json"
}
```

A bare project name such as `"My Cut"` lands in CapCut's configured drafts folder (override with `--drafts-root` or `LEGENDS_CAPCUT_DRAFTS_ROOT`); any path with a separator is used as given. The full spec reference, with every clip field and the explicit `tracks` form, is in [docs/AGENT-RECIPE.md](docs/AGENT-RECIPE.md).

</details>

<details>
<summary><strong>MCP server</strong></summary>

```bash
legends-capcut mcp
```

Speaks MCP over stdio (newline-delimited JSON-RPC). Register it with any MCP client:

```json
{"mcpServers": {"legends-capcut": {"command": "legends-capcut", "args": ["mcp"]}}}
```

Tools are named `capcut_*` and mirror the CLI one to one. Each returns structured JSON; failures come back as `{"ok": false, "error_type": ..., "error": ...}` with `isError` set.

</details>

<details>
<summary><strong>Route map for agents (<code>routes.json</code>)</strong></summary>

[routes.json](routes.json) lists every operation with its intent, CLI form, MCP tool, required arguments, access level (`read`, `write-generated-draft`, `write-output` or `gui-control`) and supported platforms. The router skill at [skills/cto-legends/SKILL.md](skills/cto-legends/SKILL.md) is pinned to the canonical copy; see [docs/router-provenance.json](docs/router-provenance.json).

</details>

<details>
<summary><strong>Python API</strong></summary>

```python
from legends_capcut import compile_draft, inspect_draft, patch_scene, set_track_flags

res = compile_draft("spec.json", "My Cut", include_review_burnin=True)
scenes = inspect_draft(res["draft_dir"])["scenes"]
patch_scene(res["draft_dir"], "S02", extend_s=1.0)
set_track_flags(res["draft_dir"], "burnin", hidden=True)
```

</details>

<details>
<summary><strong>Safety details</strong></summary>

- `inspect`, `scan-effects`, `keymap` and `doctor` never write anything.
- Writes only go to projects this package generated, which carry a `.legends_capcut_generated.json` marker. Hand-made projects are refused with `PermissionError`.
- A small list of protected project names is refused outright, even if a marker is present.
- Every write goes through a temp file and an atomic rename, updates the root draft, its `.bak`, and the `Timelines` copies together, then re-runs the validator. Patches are validated in memory first, so a change that would not validate writes nothing, and replacement media is copied into `Resources` only after validation passes.
- Draft paths are confined to the project folder: unsafe timeline ids, symlinked or junctioned targets and placeholder paths that climb out of the draft are refused.
- The optional `capcut_gui_*` tools drive the visible CapCut window on Windows via a local PowerShell desktop bridge (`LEGENDS_SHELL_PS1` or `legends-shell` on `PATH`), running under your normal PowerShell execution policy. All core compiler, reader, validator, patcher, beat sync, storyboard, and readability commands run standalone without it.
- Installed CapCut application files are only ever read.

Format internals for CapCut Desktop 9.2 (draft layout, timing units, track flags, material buckets, editing while CapCut is open) are documented in [docs/CAPCUT-928-INTERNALS.md](docs/CAPCUT-928-INTERNALS.md). See [SECURITY.md](SECURITY.md) for reporting.

</details>

<details>
<summary><strong>Development</strong></summary>

```bash
pip install -e ".[test,beats]"
python -m pytest tests -v
python scripts/check_release.py
```

Banner and social preview art are rendered by `scripts/render_banner.py` (Pillow) from a locally supplied font; the font itself is not redistributed. See [CONTRIBUTING.md](CONTRIBUTING.md) and [CHANGELOG.md](CHANGELOG.md).

</details>

## Contributing, support and license

Contributions are welcome under the [Code of Conduct](CODE_OF_CONDUCT.md); start with [CONTRIBUTING.md](CONTRIBUTING.md). Questions go through [SUPPORT.md](SUPPORT.md), and vulnerabilities through [SECURITY.md](SECURITY.md). MIT licensed; see [LICENSE](LICENSE), [NOTICE](NOTICE) and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).