Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, macos-15-intel, windows-latest]
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-15-intel, windows-latest]
runs-on: ${{ matrix.os }}
name: platform smoke (${{ matrix.os }})
steps:
Expand All @@ -132,8 +132,8 @@ jobs:
if: runner.os == 'macOS'
run: brew list --versions gnu-tar || brew install gnu-tar
- run: npm test
- name: Require native portable checks on macOS
if: runner.os == 'macOS'
- name: Require native portable checks on Linux and macOS
if: runner.os != 'Windows'
env:
CAPCUT_PORTABLE_REQUIRED: '1'
run: node --test test/portable.test.mjs
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ permissions:
contents: read

jobs:
portable-macos:
portable-native:
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-24.04-arm, target: linux-arm64 }
- { os: macos-15, target: darwin-arm64 }
- { os: macos-15-intel, target: darwin-x64 }
runs-on: ${{ matrix.os }}
Expand All @@ -27,18 +28,20 @@ jobs:
with:
node-version: '22'
cache: npm
- run: brew list --versions gnu-tar || brew install gnu-tar
- if: runner.os == 'macOS'
run: brew list --versions gnu-tar || brew install gnu-tar
- run: npm ci
- run: npm run build
- name: Verify the native portable CLI and bundled templates
env:
CAPCUT_PORTABLE_REQUIRED: '1'
CAPCUT_PORTABLE_EXPECT_TARGET: ${{ matrix.target }}
XDG_CONFIG_HOME: ${{ runner.temp }}/portable-config
CAPCUT_CLI_APP_VERSIONS: ${{ runner.temp }}/portable-config/versions.json
run: node --test test/portable.test.mjs
- name: Build the release archive
run: npm run pack:portable -- --out "$RUNNER_TEMP/portable"
- uses: actions/upload-artifact@v7
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: portable-${{ matrix.target }}
path: |
Expand All @@ -47,7 +50,7 @@ jobs:
if-no-files-found: error

release:
needs: portable-macos
needs: portable-native
runs-on: ubuntu-latest
permissions:
contents: write # create the GitHub Release
Expand Down Expand Up @@ -87,9 +90,9 @@ jobs:
env PATH= ./capcut-cli-v*-linux-x64/capcut --version
env PATH= ./capcut-cli-v*-linux-x64/capcut describe --compact

- uses: actions/download-artifact@v7
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
pattern: portable-darwin-*
pattern: portable-*
path: ${{ runner.temp }}/portable
merge-multiple: true
- name: Verify all release archive checksums
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to capcut-cli are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); the project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.36.0] - 2026-11-20

### Added
- Portable Linux arm64 downloads with a bundled Node runtime, license and SHA-256 checksum.
- Native arm64 archive checks before release publication, including both launchers, relocated paths and bundled-template compilation. Mismatched runtime architectures are rejected before an archive is created.

### Fixed
- Portable launchers resolve absolute and relative symbolic links, including chains, so links on PATH use the bundled runtime while preserving relative command arguments.
- A save whose final rename fails (for example a file held open by the editor on Windows) now removes its temporary file instead of leaving it beside the draft.

## [0.35.0] - 2026-11-19

### Added
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,27 @@ npm install -g capcut-cli

### Portable downloads without installing Node or npm

Download `capcut-cli-v0.35.0-linux-x64.tar.gz` and its `.sha256` file from the [release assets](https://github.com/renezander030/capcut-cli/releases). Verify and extract them together:
Download `capcut-cli-v0.36.0-linux-x64.tar.gz` and its `.sha256` file from the [release assets](https://github.com/renezander030/capcut-cli/releases). Verify and extract them together:

```sh
sha256sum -c capcut-cli-v0.35.0-linux-x64.tar.gz.sha256
tar -xzf capcut-cli-v0.35.0-linux-x64.tar.gz
./capcut-cli-v0.35.0-linux-x64/capcut --version
./capcut-cli-v0.35.0-linux-x64/capcut describe --compact
sha256sum -c capcut-cli-v0.36.0-linux-x64.tar.gz.sha256
tar -xzf capcut-cli-v0.36.0-linux-x64.tar.gz
./capcut-cli-v0.36.0-linux-x64/capcut --version
./capcut-cli-v0.36.0-linux-x64/capcut describe --compact
```

Keep the whole extracted directory together; it includes the Node runtime and its license. Both `capcut` and `capcut-cli` launchers work after moving the directory. This archive targets Linux x64 with glibc (not Alpine/musl); optional FFmpeg/Whisper tools remain separate. Windows continues to use the npm installation above. This is a portable directory, not a single-file executable.
On Linux arm64 (aarch64), choose `capcut-cli-v0.36.0-linux-arm64.tar.gz` and its matching `.sha256` file, then use the same verification and extraction commands with that filename. Use the archive matching the machine architecture; these archives bundle Node, not ffmpeg or the desktop editor.

Keep the whole extracted directory together; it includes the Node runtime and its license. Both `capcut` and `capcut-cli` launchers work after moving the directory. Linux archives target x64 or arm64 with glibc (not Alpine/musl); optional FFmpeg/Whisper tools remain separate. Windows continues to use the npm installation above. This is a portable directory, not a single-file executable.

You can add the extracted directory to `PATH` or create symbolic links to `capcut` and `capcut-cli` in a directory already on `PATH`. The launchers follow absolute and relative link chains using the system `/usr/bin/readlink`, and keep relative input and output paths relative to your working directory. Keep the extracted package in place while links point to it.

On macOS, choose `darwin-arm64` for Apple Silicon or `darwin-x64` for Intel. Download the matching archive and checksum from the same release, then verify and extract them (Apple Silicon example):

```sh
shasum -a 256 -c capcut-cli-v0.35.0-darwin-arm64.tar.gz.sha256
tar -xzf capcut-cli-v0.35.0-darwin-arm64.tar.gz
./capcut-cli-v0.35.0-darwin-arm64/capcut --version
shasum -a 256 -c capcut-cli-v0.36.0-darwin-arm64.tar.gz.sha256
tar -xzf capcut-cli-v0.36.0-darwin-arm64.tar.gz
./capcut-cli-v0.36.0-darwin-arm64/capcut --version
```

To build an archive from source, use a complete official Node distribution and run `npm run pack:portable -- --out ./portable` (or add `--node-root <node-distribution>`). Build on the target platform and architecture; macOS builds also require GNU tar (`brew install gnu-tar`) and `otool` from the command-line developer tools. The builder uses the local npm payload, downloads nothing, rejects runtimes linked to non-system macOS libraries, and refuses to overwrite existing artifacts. Archive users do not need these build tools.
Expand Down
2 changes: 1 addition & 1 deletion docs/command-reference.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capcut-cli",
"version": "0.35.0",
"version": "0.36.0",
"schema_version": 2,
"description": "Edit CapCut/JianYing draft_content.json directly. JSON in, JSON out.",
"global_flags": [
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capcut-cli",
"version": "0.35.0",
"version": "0.36.0",
"description": "Independent, unofficial CLI to create and edit CapCut projects — build drafts from scratch, add video/audio/text, subtitles, timing, speed, volume, templates, cut long-form to shorts. No API needed. Not affiliated with ByteDance.",
"type": "module",
"bin": {
Expand Down
16 changes: 14 additions & 2 deletions scripts/build-portable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function run(command, args, options = {}) {
/** Package the npm payload and a self-contained Node runtime; never downloads or publishes. */
export function buildPortable({ outDir, nodeRoot = resolve(dirname(process.execPath), ".."), root = sourceRoot }) {
const target = `${process.platform}-${process.arch}`;
if (!["linux-x64", "darwin-x64", "darwin-arm64"].includes(target)) throw new Error("Portable archives support Linux x64 and macOS x64/arm64 only");
if (!["linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64"].includes(target)) throw new Error("Portable archives support Linux and macOS x64/arm64 only");
const tar = process.platform === "darwin" ? "gtar" : "tar";
if (!run(tar, ["--version"]).includes("GNU tar")) throw new Error("Building portable archives requires GNU tar (gnu-tar on macOS)");
const node = join(nodeRoot, "bin", "node");
Expand Down Expand Up @@ -59,7 +59,19 @@ export function buildPortable({ outDir, nodeRoot = resolve(dirname(process.execP
copyFileSync(node, join(payload, "runtime", "node"));
chmodSync(join(payload, "runtime", "node"), 0o755);
copyFileSync(license, join(payload, "runtime", "LICENSE"));
const launcher = '#!/bin/sh\nbase=$(CDPATH= cd -- "${0%/*}" && pwd) || exit 1\nexec "$base/runtime/node" "$base/app/dist/index.js" "$@"\n';
const launcher = [
"#!/bin/sh",
'script=$0',
'case "$script" in */*) ;; *) script=$(command -v "$script") || exit 1 ;; esac',
'while [ -L "$script" ]; do',
' base=$(CDPATH= cd -P -- "${script%/*}" && pwd) || exit 1',
' target=$(/usr/bin/readlink "$script") || exit 1',
' case "$target" in /*) script=$target ;; *) script=$base/$target ;; esac',
'done',
'base=$(CDPATH= cd -P -- "${script%/*}" && pwd) || exit 1',
'exec "$base/runtime/node" "$base/app/dist/index.js" "$@"',
"",
].join("\n");
for (const command of ["capcut", "capcut-cli"]) {
writeFileSync(join(payload, command), launcher, { mode: 0o755 });
}
Expand Down
52 changes: 30 additions & 22 deletions scripts/generate-command-docs.mjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import { spawnSync } from "node:child_process";
import { writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";

const result = spawnSync(process.execPath, ["dist/index.js", "describe"], {
encoding: "utf-8",
maxBuffer: 16 * 1024 * 1024,
});
if (result.status !== 0) throw new Error(result.stderr || `describe exited ${result.status}`);
const schema = JSON.parse(result.stdout);
/** The generated command references for a `describe` schema: one renderer for the writer and its drift test. */
export function renderCommandDocs(schema) {
const rows = schema.commands.map(
(command) =>
`| \`${command.name}\` | \`${command.usage.replaceAll("|", "\\|")}\` | ${command.mutates ? "yes" : "no"} | ${command.summary} |`,
);
const markdown = [
"# Generated command reference",
"",
"> Generated by `npm run docs:commands` from the v2 command registry. Do not edit manually.",
"",
"| Command | Usage | Mutates | Summary |",
"|---|---|:---:|---|",
...rows,
"",
].join("\n");
return { json: `${JSON.stringify(schema, null, 2)}\n`, markdown };
}

writeFileSync("docs/command-reference.json", `${JSON.stringify(schema, null, 2)}\n`);
const rows = schema.commands.map(
(command) =>
`| \`${command.name}\` | \`${command.usage.replaceAll("|", "\\|")}\` | ${command.mutates ? "yes" : "no"} | ${command.summary} |`,
);
const markdown = [
"# Generated command reference",
"",
"> Generated by `npm run docs:commands` from the v2 command registry. Do not edit manually.",
"",
"| Command | Usage | Mutates | Summary |",
"|---|---|:---:|---|",
...rows,
"",
].join("\n");
writeFileSync("docs/command-reference.md", markdown);
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
const result = spawnSync(process.execPath, ["dist/index.js", "describe"], {
encoding: "utf-8",
maxBuffer: 16 * 1024 * 1024,
});
if (result.status !== 0) throw new Error(result.stderr || `describe exited ${result.status}`);
const docs = renderCommandDocs(JSON.parse(result.stdout));
writeFileSync("docs/command-reference.json", docs.json);
writeFileSync("docs/command-reference.md", docs.markdown);
}
10 changes: 8 additions & 2 deletions scripts/release-smoke.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
Expand All @@ -27,6 +27,13 @@ try {
};
assert.equal(invoke(["--version"]).stdout.trim(), expectedVersion);
assert.equal(load(join(packageRoot, "package.json")).version, expectedVersion);
// Users run the installed bin entries, not dist/index.js: both names must resolve and start.
for (const name of ["capcut", "capcut-cli"]) {
const shim = join(root, "node_modules", ".bin", process.platform === "win32" ? `${name}.cmd` : name);
const r = spawnSync(shim, ["--version"], { encoding: "utf8", shell: process.platform === "win32" });
assert.equal(r.status, 0, `${name}: ${r.stderr}`);
assert.equal(r.stdout.trim(), expectedVersion);
}
const lib = await import(pathToFileURL(join(packageRoot, "dist", "lib.js")));
assert.equal(typeof lib.loadDraft, "function");
assert.ok(existsSync(join(packageRoot, "docs", "command-reference.json")));
Expand Down Expand Up @@ -113,7 +120,6 @@ try {
assert.equal(existsSync(invalidOut), false);

const replacementDir = join(root, "new-media");
const { mkdirSync } = await import("node:fs");
mkdirSync(replacementDir);
const newClip = join(replacementDir, "clip.wav");
const newBytes = Buffer.from(wav);
Expand Down
20 changes: 18 additions & 2 deletions src/atomic-write.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomBytes } from "node:crypto";
import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, writeSync } from "node:fs";
import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, rmSync, writeSync } from "node:fs";
import { dirname } from "node:path";

function writeAndSync(path: string, content: string): void {
Expand Down Expand Up @@ -40,12 +40,28 @@ export function writeTemp(target: string, content: string): string {
throw new Error(`Could not create a temp file next to ${target} after 8 attempts.`);
}

/**
* Atomically replace (or create) `path`: temp+fsync+rename. A rename that fails
* (a target held open on Windows, a directory in the way) removes its own temp
* file and rethrows, as the multi-file draft commit does, so no scratch file is
* left beside the draft.
*/
export function replaceAtomic(path: string, content: string): void {
const temp = writeTemp(path, content);
try {
renameSync(temp, path);
} catch (error) {
rmSync(temp, { force: true });
throw error;
}
}

/**
* Atomically replace (or create) a small state file outside a draft: the user
* enums catalogue and the app-version tracker. Same temp+fsync+rename as a
* draft save, plus the parent directory created on demand.
*/
export function writeFileAtomic(path: string, content: string): void {
mkdirSync(dirname(path), { recursive: true });
renameSync(writeTemp(path, content), path);
replaceAtomic(path, content);
}
4 changes: 2 additions & 2 deletions src/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "node:fs";
import { basename, dirname, join, resolve } from "node:path";
import { appVersionEvidence, formatAppVersionDriftWarning, trackAppVersion } from "./app-versions.js";
import { writeTemp } from "./atomic-write.js";
import { replaceAtomic, writeTemp } from "./atomic-write.js";
import { stripBom } from "./bom.js";
import { journalDigest } from "./journal-digest.js";
import {
Expand Down Expand Up @@ -674,7 +674,7 @@ export function saveDraft(
// Exported for factory.ts (register): the same temp+fsync+rename write the
// draft save path uses, for metadata files outside commitDraftTargets.
export function writeAtomic(path: string, content: string): void {
renameSync(writeTemp(path, content), path);
replaceAtomic(path, content);
}

export function extractText(content: string): string {
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2333,11 +2333,11 @@ interface ImportApplyResult {
async function applyImportPlan(draft: Draft, filePath: string, plan: ImportPlan): Promise<ImportApplyResult> {
const { addAudio, addText, addVideo } = await import("./factory.js");
const result: ImportApplyResult = { tracks: 0, clips: 0, captions: 0, placeholders: [] };
const claimed = new Set(draft.tracks.map((t) => `${t.type}${t.name}`));
const claimed = new Set(draft.tracks.map((t) => `${t.type}\u0000${t.name}`));
const claimTrack = (kind: string, base: string): string => {
let name = base;
for (let n = 2; claimed.has(`${kind}${name}`); n++) name = `${base} (${n})`;
claimed.add(`${kind}${name}`);
for (let n = 2; claimed.has(`${kind}\u0000${name}`); n++) name = `${base} (${n})`;
claimed.add(`${kind}\u0000${name}`);
return name;
};
for (const track of plan.tracks) {
Expand Down
21 changes: 21 additions & 0 deletions test/atomic-temp.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,24 @@ describe("atomic state-file write: parent folder, private mode, no planted temp"
assert.equal(readFileSync(target, "utf-8"), "tracked");
});
});

describe("atomic write: a failed rename leaves no scratch file", () => {
const dirs = [];
after(() => {
for (const dir of dirs) rmSync(dir, { recursive: true, force: true });
});

it("removes its own temp and rethrows when the target cannot be replaced", () => {
for (const write of [writeAtomic, writeFileAtomic]) {
const dir = mkdtempSync(join(tmpdir(), "capcut-atomic-fail-"));
dirs.push(dir);
// A non-empty directory where the file should go: rename(2) refuses it on every platform.
const target = join(dir, "draft_content.json");
mkdirSync(target);
writeFileSync(join(target, "keep.txt"), "kept");
assert.throws(() => write(target, "{}"));
assert.deepEqual(readdirSync(dir), ["draft_content.json"]);
assert.equal(readFileSync(join(target, "keep.txt"), "utf-8"), "kept");
}
});
});
14 changes: 14 additions & 0 deletions test/command-reference.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { it } from "node:test";
import { renderCommandDocs } from "../scripts/generate-command-docs.mjs";
import { spawnCli } from "./helpers/spawn-cli.mjs";

// The packaged references are what `describe` says; regenerate them with `npm run docs:commands`.
it("committed command references equal what describe generates", () => {
const described = spawnCli(["describe"]);
assert.equal(described.status, 0, described.stderr);
const docs = renderCommandDocs(described.json);
assert.equal(readFileSync(new URL("../docs/command-reference.json", import.meta.url), "utf8"), docs.json);
assert.equal(readFileSync(new URL("../docs/command-reference.md", import.meta.url), "utf8"), docs.markdown);
});
Loading
Loading