@clipen/clipen-cli 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/apps/web/dist/assets/index-DPgSvXZ1.js +15 -0
- package/apps/web/dist/assets/index-DmPWV61v.css +1 -0
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +229 -68
- package/package.json +8 -2
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/qwen_worker.py +13 -4
- package/src/clipen/analysis/setup.py +2 -1
- package/src/clipen/analysis/setup_cli.py +58 -12
- package/src/clipen/bootstrap.py +499 -167
- package/src/clipen/cli.py +40 -15
- package/src/clipen/controller/app.py +120 -38
- package/src/clipen/controller/server.py +70 -27
- package/src/clipen/editing/agent_repository.py +8 -0
- package/src/clipen/editing/agent_tools.py +1 -1
- package/src/clipen/editing/caption_design.py +134 -0
- package/src/clipen/editing/change_report.py +17 -0
- package/src/clipen/editing/component_looks.py +3 -3
- package/src/clipen/editing/component_review.py +0 -38
- package/src/clipen/editing/coordinator.py +20 -0
- package/src/clipen/editing/evidence_jobs.py +3 -1
- package/src/clipen/editing/history_changes.py +56 -27
- package/src/clipen/editing/production_catalog.py +67 -13
- package/src/clipen/editing/production_media.py +13 -2
- package/src/clipen/editing/production_preview.py +11 -9
- package/src/clipen/editing/production_progress.py +48 -3
- package/src/clipen/editing/production_tools.py +11 -20
- package/src/clipen/editing/program_subtitles.py +5 -13
- package/src/clipen/editing/resolve_export.py +2 -183
- package/src/clipen/editing/skill_tools.py +142 -218
- package/src/clipen/editing/tool_receipts.py +2 -1
- package/src/clipen/editing/versions.py +55 -10
- package/src/clipen/editing/visual_preview.py +62 -0
- package/src/clipen/editing/workbench.py +21 -1
- package/src/clipen/i18n.py +155 -0
- package/src/clipen/locale_en.py +546 -0
- package/src/clipen/mcp_editing/__main__.py +8 -0
- package/src/clipen/media/storage.py +2 -2
- package/src/clipen/own_ffmpeg.py +113 -0
- package/src/clipen/projects/models.py +16 -1
- package/src/clipen/projects/picker.py +3 -1
- package/src/clipen/projects/storage.py +17 -1
- package/src/clipen/providers/claude_editing.py +3 -1
- package/src/clipen/providers/codex_editing.py +3 -1
- package/src/clipen/providers/editing_agent.py +42 -5
- package/src/clipen/providers/liveness.py +39 -0
- package/src/clipen/rendering/custom_components.py +216 -25
- package/src/clipen/rendering/custom_render.py +90 -54
- package/src/clipen/rendering/fetched_fonts.py +127 -0
- package/src/clipen/rendering/production_effects.py +24 -2
- package/src/clipen/rendering/program_components.py +18 -240
- package/src/clipen/rendering/renderer.py +23 -17
- package/src/clipen/rendering/titles.py +29 -12
- package/src/clipen/skills/builtin/SKILL.md +3 -3
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/display.en.json +89 -0
- package/src/clipen/skills/builtin/references/captions.md +12 -0
- package/src/clipen/skills/builtin/references/graphics.md +6 -6
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +9 -7
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +10 -7
- package/src/clipen/skills/catalog.py +22 -8
- package/src/clipen/skills/package.py +1 -10
- package/src/clipen/terminal.py +344 -0
- package/src/clipen/workspace.py +97 -28
- package/apps/web/dist/assets/index-C3Zw0WaM.js +0 -14
- package/apps/web/dist/assets/index-CaxEZKLc.css +0 -1
- package/src/clipen/editing/resolve_titles.py +0 -291
- package/src/clipen/rendering/program_creator.py +0 -804
- package/src/clipen/rendering/program_identities.py +0 -350
- package/src/clipen/rendering/program_motion.py +0 -186
- package/src/clipen/rendering/program_studio.py +0 -227
- package/src/clipen/rendering/program_styles.py +0 -321
- package/src/clipen/skills/builtin/components.json +0 -133
package/bin/clipen.js
CHANGED
|
@@ -5,17 +5,22 @@
|
|
|
5
5
|
// copied into Clipen's own folder first; the `clipen` command then runs from there. Clipen runs on
|
|
6
6
|
// its own fixed standalone Python, downloaded and checked into its folder: a Python the person
|
|
7
7
|
// installed (system, Homebrew, pyenv) is never used, so changing or removing it cannot break Clipen. Fonts are not in the package; they are downloaded from the sources pinned in
|
|
8
|
-
// fonts/manifest.json and checked against their SHA-256. Then the Python installer takes over
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
// fonts/manifest.json and checked against their SHA-256. Then the Python installer takes over, fetching
|
|
9
|
+
// ffmpeg too when the Mac has none.
|
|
10
|
+
import * as p from '@clack/prompts'
|
|
11
|
+
import chalk from 'chalk'
|
|
12
|
+
import { Command, CommanderError } from 'commander'
|
|
13
|
+
import { execFile, spawnSync } from 'node:child_process'
|
|
14
|
+
import crypto from 'node:crypto'
|
|
15
|
+
import { once } from 'node:events'
|
|
16
|
+
import fs from 'node:fs'
|
|
17
|
+
import os from 'node:os'
|
|
18
|
+
import path from 'node:path'
|
|
19
|
+
import { fileURLToPath } from 'node:url'
|
|
20
|
+
import { promisify } from 'node:util'
|
|
21
|
+
|
|
22
|
+
const PACKAGE = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
23
|
+
const { version: VERSION, description: DESCRIPTION } = JSON.parse(fs.readFileSync(path.join(PACKAGE, 'package.json'), 'utf8'))
|
|
19
24
|
const PYTHON = {
|
|
20
25
|
tag: '3.12.16+20261026',
|
|
21
26
|
url: 'https://github.com/astral-sh/python-build-standalone/releases/download/20261026/cpython-3.12.16%2B20261026-aarch64-apple-darwin-install_only_stripped.tar.gz',
|
|
@@ -25,37 +30,100 @@ const PYTHON = {
|
|
|
25
30
|
// What the program needs at run time; the rest of the package (this launcher) stays in npx's cache.
|
|
26
31
|
const PROGRAM = ['src', 'apps/web/dist', 'requirements', 'pyproject.toml', 'clipen', 'README.md', 'LICENSE']
|
|
27
32
|
const FONTS = 'src/clipen/rendering/fonts'
|
|
33
|
+
const COMMANDS = [
|
|
34
|
+
['install', ['安裝 Clipen(預設)', 'Install Clipen (default)']],
|
|
35
|
+
['update', ['更新到最新版', 'Update to the latest version']],
|
|
36
|
+
['codex', ['在目前目錄用 Codex 開啟 Clipen', 'Open Clipen here with Codex']],
|
|
37
|
+
['claude', ['在目前目錄用 Claude Code 開啟 Clipen', 'Open Clipen here with Claude Code']],
|
|
38
|
+
['uninstall', ['移除 Clipen 程式與執行環境(作品資料保留)', 'Remove the Clipen program and runtime (projects are kept)']],
|
|
39
|
+
]
|
|
40
|
+
const brand = chalk.hex('#e9b44c')
|
|
41
|
+
// The same wordmark the Python side draws (src/clipen/terminal.py), gold warming to amber.
|
|
42
|
+
const LOGO = [
|
|
43
|
+
' ██████╗██╗ ██╗██████╗ ███████╗███╗ ██╗',
|
|
44
|
+
'██╔════╝██║ ██║██╔══██╗██╔════╝████╗ ██║',
|
|
45
|
+
'██║ ██║ ██║██████╔╝█████╗ ██╔██╗ ██║',
|
|
46
|
+
'██║ ██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║',
|
|
47
|
+
'╚██████╗███████╗██║██║ ███████╗██║ ╚████║',
|
|
48
|
+
' ╚═════╝╚══════╝╚═╝╚═╝ ╚══════╝╚═╝ ╚═══╝',
|
|
49
|
+
]
|
|
50
|
+
const LOGO_COLOURS = [[246, 211, 122], [240, 198, 100], [233, 180, 76], [226, 160, 62], [218, 140, 52], [208, 120, 44]]
|
|
51
|
+
const ENGLISH_DESCRIPTION = 'Let AI edit your videos with Claude Code or Codex, then revise them with review notes on the timeline'
|
|
52
|
+
const megabytes = (bytes) => Math.round(bytes / 1e6)
|
|
28
53
|
|
|
29
|
-
|
|
30
|
-
|
|
54
|
+
class SetupError extends Error {}
|
|
55
|
+
|
|
56
|
+
// The language Clipen speaks, chosen as the Python side chooses it (src/clipen/i18n.py): CLIPEN_LANG,
|
|
57
|
+
// then the choice saved with `clipen language`, then the Mac's preferred language, then LANG.
|
|
58
|
+
function normalize(value) {
|
|
59
|
+
const lower = String(value ?? '').trim().toLowerCase().replaceAll('_', '-')
|
|
60
|
+
return lower.startsWith('zh') ? 'zh-TW' : lower.startsWith('en') ? 'en' : null
|
|
61
|
+
}
|
|
62
|
+
function settingsPath() { return path.join(dataRoot(), 'settings.json') }
|
|
63
|
+
function savedLanguage() {
|
|
64
|
+
try { return normalize(JSON.parse(fs.readFileSync(settingsPath(), 'utf8')).language) } catch { return null }
|
|
65
|
+
}
|
|
66
|
+
function macLanguage() {
|
|
67
|
+
if (process.platform !== 'darwin') return null
|
|
68
|
+
const read = spawnSync('/usr/bin/defaults', ['read', '-g', 'AppleLanguages'], { encoding: 'utf8', timeout: 2000 })
|
|
69
|
+
for (const entry of (read.stdout ?? '').replace(/[()]/g, ' ').split(',')) {
|
|
70
|
+
const found = normalize(entry.trim().replace(/^"|"$/g, ''))
|
|
71
|
+
if (found) return found
|
|
72
|
+
}
|
|
73
|
+
return null
|
|
74
|
+
}
|
|
75
|
+
const LANGUAGE = normalize(process.env.CLIPEN_LANG) ?? savedLanguage() ?? macLanguage()
|
|
76
|
+
?? normalize(process.env.LC_ALL) ?? normalize(process.env.LC_MESSAGES) ?? normalize(process.env.LANG) ?? 'en'
|
|
77
|
+
const t = (zh, en) => (LANGUAGE === 'en' ? en : zh)
|
|
78
|
+
|
|
79
|
+
// The spinner or progress bar on screen, so a failure can close it before the message is shown.
|
|
80
|
+
let active = null
|
|
81
|
+
|
|
82
|
+
function begin(indicator, message) {
|
|
83
|
+
indicator.start(message)
|
|
84
|
+
active = indicator
|
|
85
|
+
return indicator
|
|
31
86
|
}
|
|
32
87
|
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
88
|
+
function finish(message) {
|
|
89
|
+
active.stop(message)
|
|
90
|
+
active = null
|
|
36
91
|
}
|
|
37
92
|
|
|
38
|
-
|
|
39
|
-
|
|
93
|
+
/** The wordmark, where colour and width allow. */
|
|
94
|
+
function logo() {
|
|
95
|
+
if (!chalk.level || (process.stdout.columns ?? 80) < 50) return
|
|
96
|
+
console.log()
|
|
97
|
+
LOGO.forEach((line, index) => console.log(` ${chalk.rgb(...LOGO_COLOURS[index])(line)}`))
|
|
98
|
+
console.log(` ${chalk.dim(`v${VERSION} · ${t('AI 剪輯工作台', 'AI video editing studio')}`)}\n`)
|
|
40
99
|
}
|
|
41
100
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
|
|
45
|
-
const answer = await new Promise((resolve) => rl.question(question, resolve))
|
|
46
|
-
rl.close()
|
|
47
|
-
return ['', 'y', 'yes'].includes(answer.trim().toLowerCase())
|
|
101
|
+
function dataRoot() {
|
|
102
|
+
return path.join(os.homedir(), 'Library', 'Application Support', 'Clipen')
|
|
48
103
|
}
|
|
49
104
|
|
|
50
105
|
/** Download to a file and check it; nothing unchecked is ever kept. */
|
|
51
|
-
async function download(url, target, expected) {
|
|
106
|
+
async function download(url, target, expected, onProgress = () => {}) {
|
|
52
107
|
const response = await fetch(url, { redirect: 'follow' })
|
|
53
|
-
if (!response.ok)
|
|
108
|
+
if (!response.ok) throw new SetupError(t(`無法下載 ${url}(HTTP ${response.status})`, `Could not download ${url} (HTTP ${response.status})`))
|
|
109
|
+
const total = Number(response.headers.get('content-length')) || 0
|
|
54
110
|
const partial = `${target}.part`
|
|
55
|
-
|
|
56
|
-
|
|
111
|
+
const hash = crypto.createHash('sha256')
|
|
112
|
+
const file = fs.createWriteStream(partial)
|
|
113
|
+
let received = 0
|
|
114
|
+
try {
|
|
115
|
+
for await (const chunk of response.body) {
|
|
116
|
+
hash.update(chunk)
|
|
117
|
+
if (!file.write(chunk)) await once(file, 'drain')
|
|
118
|
+
received += chunk.length
|
|
119
|
+
onProgress(received, total)
|
|
120
|
+
}
|
|
121
|
+
} finally {
|
|
122
|
+
await new Promise((resolve) => file.end(resolve))
|
|
123
|
+
}
|
|
124
|
+
if (hash.digest('hex') !== expected) {
|
|
57
125
|
fs.rmSync(partial, { force: true })
|
|
58
|
-
|
|
126
|
+
throw new SetupError(t(`${path.basename(target)} 的檢查碼不符,已刪除下載的檔案;請稍後再試或回報問題。`, `${path.basename(target)} failed its checksum and was deleted; try again later or report the problem.`))
|
|
59
127
|
}
|
|
60
128
|
fs.renameSync(partial, target)
|
|
61
129
|
}
|
|
@@ -71,16 +139,29 @@ async function standalonePython() {
|
|
|
71
139
|
const target = path.join(root, PYTHON.tag)
|
|
72
140
|
fs.mkdirSync(root, { recursive: true, mode: 0o700 })
|
|
73
141
|
const archive = path.join(root, `cpython-${PYTHON.tag}.tar.gz`)
|
|
74
|
-
|
|
75
|
-
|
|
142
|
+
const label = t('正在下載 Clipen 安裝程式', 'Downloading the Clipen installer')
|
|
143
|
+
const bar = begin(p.progress({ max: 100, style: 'heavy' }), label)
|
|
144
|
+
let shown = 0
|
|
145
|
+
await download(PYTHON.url, archive, PYTHON.sha256, (received, total) => {
|
|
146
|
+
const percent = Math.floor((received * 100) / (total || PYTHON.bytes))
|
|
147
|
+
if (percent > shown && percent <= 100) {
|
|
148
|
+
bar.advance(percent - shown, `${label} ${chalk.dim(`${megabytes(received)} / ${megabytes(total || PYTHON.bytes)} MB`)}`)
|
|
149
|
+
shown = percent
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
bar.message(t('正在解壓縮', 'Unpacking'))
|
|
76
153
|
const staging = `${target}.staging-${process.pid}`
|
|
77
154
|
fs.rmSync(staging, { recursive: true, force: true })
|
|
78
155
|
fs.mkdirSync(staging)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
156
|
+
try {
|
|
157
|
+
await promisify(execFile)('tar', ['-xzf', archive, '-C', staging, '--strip-components', '1'])
|
|
158
|
+
} catch (error) {
|
|
159
|
+
throw new SetupError(t('Clipen 執行環境解壓縮失敗。', 'Unpacking Clipen\'s runtime failed.') + (error.stderr ? `\n${error.stderr.trim()}` : ''))
|
|
160
|
+
} finally {
|
|
161
|
+
fs.rmSync(archive, { force: true })
|
|
162
|
+
}
|
|
82
163
|
fs.renameSync(staging, target)
|
|
83
|
-
|
|
164
|
+
finish(t('安裝程式下載完成', 'Installer downloaded'))
|
|
84
165
|
return path.join(target, 'bin', 'python3')
|
|
85
166
|
}
|
|
86
167
|
|
|
@@ -92,55 +173,135 @@ async function program() {
|
|
|
92
173
|
fs.mkdirSync(root, { recursive: true, mode: 0o700 })
|
|
93
174
|
const staging = `${target}.staging-${process.pid}`
|
|
94
175
|
fs.rmSync(staging, { recursive: true, force: true })
|
|
176
|
+
const spin = begin(p.spinner(), t(`正在準備 Clipen ${VERSION}`, `Preparing Clipen ${VERSION}`))
|
|
95
177
|
for (const entry of PROGRAM) {
|
|
96
178
|
const from = path.join(PACKAGE, entry)
|
|
97
|
-
if (!fs.existsSync(from))
|
|
98
|
-
fs.
|
|
179
|
+
if (!fs.existsSync(from)) throw new SetupError(t(`套件缺少 ${entry}。`, `The package is missing ${entry}.`))
|
|
180
|
+
await fs.promises.cp(from, path.join(staging, entry), { recursive: true, filter: (file) => !file.includes('__pycache__') })
|
|
99
181
|
}
|
|
100
182
|
const fonts = path.join(staging, FONTS)
|
|
101
183
|
const manifest = JSON.parse(fs.readFileSync(path.join(fonts, 'manifest.json'), 'utf8'))
|
|
102
184
|
const missing = Object.values(manifest).filter((font) => !fs.existsSync(path.join(fonts, font.file)))
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
console.log('✓ 字型準備完成')
|
|
185
|
+
for (const [index, font] of missing.entries()) {
|
|
186
|
+
spin.message(`${t('正在下載字型', 'Downloading fonts')} ${chalk.dim(`${index + 1} / ${missing.length}`)}`)
|
|
187
|
+
await download(font.download_url, path.join(fonts, font.file), font.sha256)
|
|
107
188
|
}
|
|
108
189
|
fs.writeFileSync(path.join(staging, '.clipen-npm'), `${VERSION}\n`)
|
|
109
190
|
fs.renameSync(staging, target)
|
|
191
|
+
finish(t(`Clipen ${VERSION} 準備完成`, `Clipen ${VERSION} ready`))
|
|
110
192
|
return target
|
|
111
193
|
}
|
|
112
194
|
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
const missing = ['ffmpeg', 'ffprobe'].filter((name) => !has(name))
|
|
116
|
-
if (!missing.length) return
|
|
117
|
-
console.log('\n⚠ 找不到 ffmpeg:Clipen 輸出影片需要它。')
|
|
118
|
-
console.log(has('brew') ? ' 安裝方式:brew install ffmpeg' : ' 先安裝 Homebrew(https://brew.sh),再執行:brew install ffmpeg')
|
|
119
|
-
console.log(' 安裝好之後再執行 clipen codex 或 clipen claude 即可。\n')
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async function main() {
|
|
123
|
-
if (process.platform !== 'darwin' || process.arch !== 'arm64') fail('目前只支援 Apple 晶片(M 系列)的 Mac。')
|
|
124
|
-
const args = process.argv.slice(2)
|
|
125
|
-
const command = args.length ? args : ['install']
|
|
195
|
+
async function launch(command) {
|
|
196
|
+
if (process.platform !== 'darwin' || process.arch !== 'arm64') throw new SetupError(t('目前只支援 Apple 晶片(M 系列)的 Mac。', 'Clipen runs only on Apple silicon (M-series) Macs.'))
|
|
126
197
|
let python = findPython()
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
198
|
+
const programReady = fs.existsSync(path.join(dataRoot(), 'app', VERSION, '.clipen-npm'))
|
|
199
|
+
const download = (python ? 0 : PYTHON.bytes) + (programReady ? 0 : 40e6)
|
|
200
|
+
// Starting Clipen when everything is in place goes straight to the program, without a frame.
|
|
201
|
+
const framed = command === 'install' || download > 0
|
|
202
|
+
if (framed) {
|
|
203
|
+
logo()
|
|
204
|
+
p.intro(chalk.bgHex('#e9b44c').black(` Clipen ${VERSION} `))
|
|
205
|
+
}
|
|
206
|
+
// Asking to install is already the yes; only a download the person did not ask for is confirmed here.
|
|
207
|
+
if (download && command !== 'install') {
|
|
208
|
+
if (!process.stdin.isTTY) throw new SetupError(t('第一次設定需要在互動式 Terminal 中確認。', 'First-time setup needs confirming in an interactive Terminal.'))
|
|
209
|
+
const proceed = await p.confirm({ message: t(`需要先下載 Clipen 程式(約 ${megabytes(download)} MB),要繼續嗎?`, `Clipen needs to download its program first (about ${megabytes(download)} MB). Continue?`), active: t('是', 'Yes'), inactive: t('否', 'No'), initialValue: true })
|
|
210
|
+
if (p.isCancel(proceed) || !proceed) {
|
|
211
|
+
p.cancel(t('已取消,沒有下載任何東西。', 'Cancelled; nothing was downloaded.'))
|
|
212
|
+
return 0
|
|
213
|
+
}
|
|
137
214
|
}
|
|
138
215
|
if (!python) python = await standalonePython()
|
|
139
216
|
const target = await program()
|
|
140
|
-
if (command
|
|
217
|
+
if (command !== 'install' && framed) p.outro(chalk.dim(t(`正在開啟 clipen ${command}…`, `Opening clipen ${command}…`)))
|
|
218
|
+
// The installer continues this frame instead of drawing its own logo.
|
|
219
|
+
const env = command === 'install' ? { ...process.env, CLIPEN_FRAME_OPEN: '1' } : process.env
|
|
141
220
|
// -I: the person's PYTHONPATH, PYTHONHOME and user site never reach Clipen's Python.
|
|
142
|
-
const run = spawnSync(python, ['-I', path.join(target, 'clipen'),
|
|
143
|
-
|
|
221
|
+
const run = spawnSync(python, ['-I', path.join(target, 'clipen'), command], { stdio: 'inherit', env })
|
|
222
|
+
return run.status ?? 1
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
/** `clipen language`: say which language Clipen speaks; with en, zh-TW or auto, change it for every Clipen command. */
|
|
227
|
+
function language(choice) {
|
|
228
|
+
if (choice !== undefined) {
|
|
229
|
+
const chosen = choice.trim().toLowerCase() === 'auto' ? null : normalize(choice)
|
|
230
|
+
if (chosen === null && choice.trim().toLowerCase() !== 'auto') {
|
|
231
|
+
console.error(`${chalk.red('✗')} ${t('請選 en、zh-TW 或 auto', 'Choose en, zh-TW or auto')}`)
|
|
232
|
+
return 2
|
|
233
|
+
}
|
|
234
|
+
let settings = {}
|
|
235
|
+
try { settings = JSON.parse(fs.readFileSync(settingsPath(), 'utf8')) } catch { /* A first setting starts the file. */ }
|
|
236
|
+
if (chosen) settings.language = chosen
|
|
237
|
+
else delete settings.language
|
|
238
|
+
fs.mkdirSync(dataRoot(), { recursive: true, mode: 0o700 })
|
|
239
|
+
fs.writeFileSync(settingsPath(), `${JSON.stringify(settings, null, 2)}\n`)
|
|
240
|
+
}
|
|
241
|
+
const now = normalize(process.env.CLIPEN_LANG) ?? savedLanguage() ?? macLanguage() ?? normalize(process.env.LANG) ?? 'en'
|
|
242
|
+
const speak = (zh, en) => (now === 'en' ? en : zh)
|
|
243
|
+
const name = now === 'en' ? 'English' : '繁體中文'
|
|
244
|
+
console.log(`${chalk.green('◇')} ${speak(`Clipen 使用 ${name}`, `Clipen speaks ${name}`)} ${chalk.dim(savedLanguage() ? speak('(手動設定)', '(set by you)') : speak('(跟著系統)', '(following the system)'))}`)
|
|
245
|
+
return 0
|
|
144
246
|
}
|
|
145
247
|
|
|
146
|
-
|
|
248
|
+
function formatHelp(command, helper) {
|
|
249
|
+
const rows = (items, term, describe) => {
|
|
250
|
+
const width = Math.max(...items.map((item) => term(item).length))
|
|
251
|
+
return items.map((item) => ` ${brand(term(item).padEnd(width))} ${describe(item)}`)
|
|
252
|
+
}
|
|
253
|
+
return [
|
|
254
|
+
`${chalk.bold(t('用法:', 'Usage: '))}clipen ${chalk.dim(t('[指令]', '[command]'))}`,
|
|
255
|
+
'',
|
|
256
|
+
command.description(),
|
|
257
|
+
'',
|
|
258
|
+
chalk.bold(t('指令:', 'Commands:')),
|
|
259
|
+
...rows(helper.visibleCommands(command), (sub) => sub.name(), (sub) => sub.description()),
|
|
260
|
+
'',
|
|
261
|
+
chalk.bold(t('選項:', 'Options:')),
|
|
262
|
+
...rows(helper.visibleOptions(command), (option) => option.flags, (option) => option.description),
|
|
263
|
+
'',
|
|
264
|
+
chalk.dim(t('第一次使用:npx @clipen/clipen-cli', 'First time: npx @clipen/clipen-cli')),
|
|
265
|
+
'',
|
|
266
|
+
].join('\n')
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function main() {
|
|
270
|
+
let status = 0
|
|
271
|
+
const cli = new Command('clipen')
|
|
272
|
+
.description(t(DESCRIPTION, ENGLISH_DESCRIPTION))
|
|
273
|
+
.version(VERSION, '-v, --version', t('顯示版本', 'Show the version'))
|
|
274
|
+
.helpOption('-h, --help', t('顯示說明', 'Show help'))
|
|
275
|
+
.helpCommand(false)
|
|
276
|
+
.configureHelp({ formatHelp })
|
|
277
|
+
.configureOutput({ outputError: () => {} })
|
|
278
|
+
.exitOverride()
|
|
279
|
+
.action(async () => { status = await launch('install') })
|
|
280
|
+
for (const [name, summary] of COMMANDS) {
|
|
281
|
+
cli.command(name).description(t(...summary)).helpOption(false).action(async () => { status = await launch(name) })
|
|
282
|
+
}
|
|
283
|
+
cli.command('language').argument('[choice]').description(t('顯示或設定介面語言:en、zh-TW 或 auto', 'Show or set the language: en, zh-TW or auto')).helpOption(false)
|
|
284
|
+
.action((choice) => { status = language(choice) })
|
|
285
|
+
try {
|
|
286
|
+
await cli.parseAsync()
|
|
287
|
+
} catch (error) {
|
|
288
|
+
if (!(error instanceof CommanderError)) throw error
|
|
289
|
+
if (error.exitCode === 0) return 0
|
|
290
|
+
const given = process.argv.slice(2)
|
|
291
|
+
// An unknown word reaches the bare `clipen` action as an extra argument, not as an unknown command.
|
|
292
|
+
const reason = error.code === 'commander.unknownOption' ? t('沒有這個選項', 'No such option')
|
|
293
|
+
: COMMANDS.some(([name]) => name === given[0]) ? t('多了不需要的參數', 'Unexpected argument') : t('沒有這個指令', 'No such command')
|
|
294
|
+
console.error(`${chalk.red('✗')} ${reason}${t(':', ': ')}${chalk.bold(given.join(' '))}`)
|
|
295
|
+
console.error(chalk.dim(t('執行 clipen --help 查看可用指令。', 'Run clipen --help to see the commands.')))
|
|
296
|
+
return 1
|
|
297
|
+
}
|
|
298
|
+
return status
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
process.exitCode = await main()
|
|
303
|
+
} catch (error) {
|
|
304
|
+
active?.error(t('失敗', 'Failed'))
|
|
305
|
+
p.cancel(`${t('Clipen 安裝失敗:', 'Clipen install failed: ')}${error instanceof Error ? error.message : String(error)}`)
|
|
306
|
+
process.exitCode = 1
|
|
307
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipen/clipen-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "讓 AI 用 Claude Code 或 Codex 幫你剪影片,再用時間線上的審片注記修改",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"video-editing",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"url": "https://github.com/IMGMANISME/clipen/issues"
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
23
24
|
"bin": {
|
|
24
25
|
"clipen": "bin/clipen.js"
|
|
25
26
|
},
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"LICENSE"
|
|
37
38
|
],
|
|
38
39
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
40
|
+
"node": ">=20.12"
|
|
40
41
|
},
|
|
41
42
|
"os": [
|
|
42
43
|
"darwin"
|
|
@@ -51,5 +52,10 @@
|
|
|
51
52
|
},
|
|
52
53
|
"publishConfig": {
|
|
53
54
|
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@clack/prompts": "1.9.0",
|
|
58
|
+
"chalk": "5.6.2",
|
|
59
|
+
"commander": "14.0.3"
|
|
54
60
|
}
|
|
55
61
|
}
|
package/pyproject.toml
CHANGED
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "clipen"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.9"
|
|
8
8
|
description = "Let AI cut your video with Claude Code or Codex, and review it with notes on the timeline"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
package/src/clipen/__init__.py
CHANGED
|
@@ -392,7 +392,7 @@ def _transcribe(runtime, audio) -> tuple[str, list[float], bool]:
|
|
|
392
392
|
|
|
393
393
|
features = runtime.processor.feature_extractor(audio, sample_rate=16_000)
|
|
394
394
|
audio_length = int(features.audio_lengths.reshape(-1)[0])
|
|
395
|
-
prompt = runtime.processor.build_prompt(context="", audio_length=audio_length, language=
|
|
395
|
+
prompt = runtime.processor.build_prompt(context="", audio_length=audio_length, language=_SPOKEN[_language])
|
|
396
396
|
audio_features = runtime.model.get_audio_features(
|
|
397
397
|
mx.array(features.input_features, dtype=mx.float32),
|
|
398
398
|
feature_attention_mask=mx.array(features.feature_attention_mask, dtype=mx.int32),
|
|
@@ -530,12 +530,17 @@ def _result(runtime, convert, audio: Path) -> dict[str, object]:
|
|
|
530
530
|
}
|
|
531
531
|
)
|
|
532
532
|
return {
|
|
533
|
-
"language":
|
|
533
|
+
"language": _language,
|
|
534
534
|
"text": "\n".join(str(segment["text"]) for segment in segments),
|
|
535
535
|
"segments": segments,
|
|
536
536
|
}
|
|
537
537
|
|
|
538
538
|
|
|
539
|
+
# The language each request is recognised in; the worker serves one request at a time.
|
|
540
|
+
_SPOKEN = {"zh": "Chinese", "en": "English"}
|
|
541
|
+
_language = "zh"
|
|
542
|
+
|
|
543
|
+
|
|
539
544
|
def _load_runtime(model: Path):
|
|
540
545
|
import mlx_speech
|
|
541
546
|
|
|
@@ -543,10 +548,12 @@ def _load_runtime(model: Path):
|
|
|
543
548
|
|
|
544
549
|
|
|
545
550
|
def _serve(model: Path) -> int:
|
|
551
|
+
global _language
|
|
546
552
|
from opencc import OpenCC
|
|
547
553
|
|
|
548
554
|
runtime = _load_runtime(model)
|
|
549
|
-
|
|
555
|
+
# Chinese is written in Traditional characters; other languages stay as recognised.
|
|
556
|
+
traditional = OpenCC("s2twp").convert
|
|
550
557
|
_response({"type": "ready", "qwen3_asr_runtime": "mlx-speech-0.5.2"})
|
|
551
558
|
while line := sys.stdin.buffer.readline(_MAX_REQUEST_BYTES + 1):
|
|
552
559
|
if len(line) > _MAX_REQUEST_BYTES or not line.endswith(b"\n"):
|
|
@@ -560,8 +567,10 @@ def _serve(model: Path) -> int:
|
|
|
560
567
|
"output",
|
|
561
568
|
}:
|
|
562
569
|
raise ValueError("invalid request")
|
|
563
|
-
if request["language"]
|
|
570
|
+
if request["language"] not in _SPOKEN or request["initial_prompt"] is not None:
|
|
564
571
|
raise ValueError("unsupported request")
|
|
572
|
+
_language = request["language"]
|
|
573
|
+
convert = traditional if _language == "zh" else str
|
|
565
574
|
audio = _regular(request["audio"])
|
|
566
575
|
output = _regular(request["output"])
|
|
567
576
|
if output.stat().st_size != 0:
|
|
@@ -41,6 +41,7 @@ from clipen.asr_release import (
|
|
|
41
41
|
RELEASE_ID,
|
|
42
42
|
SUPERSEDED_RELEASE_IDS,
|
|
43
43
|
)
|
|
44
|
+
from clipen.i18n import tr
|
|
44
45
|
|
|
45
46
|
from .transcription import LocalModelSnapshot, Qwen3ASRAdapter
|
|
46
47
|
|
|
@@ -83,7 +84,7 @@ class ASRSetupStatus:
|
|
|
83
84
|
return {
|
|
84
85
|
"state": self.state.value,
|
|
85
86
|
"phase": self.phase,
|
|
86
|
-
"message": self.message,
|
|
87
|
+
"message": tr(self.message),
|
|
87
88
|
"error_code": self.error_code,
|
|
88
89
|
"completed_units": self.completed_units,
|
|
89
90
|
"total_units": self.total_units,
|
|
@@ -8,6 +8,7 @@ import time
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
10
|
from clipen.asr_release import NOTICE_VERSION, PROGRESS_RECORD_PREFIX
|
|
11
|
+
from clipen.i18n import speaking, system_language, tr
|
|
11
12
|
|
|
12
13
|
from .setup import ASRSetupError, ASRSetupManager, ASRSetupState, ASRSetupStatus
|
|
13
14
|
|
|
@@ -26,14 +27,23 @@ def _progress_line(status: ASRSetupStatus, elapsed: int) -> str:
|
|
|
26
27
|
percent = max(0, min(100, status.progress_percent))
|
|
27
28
|
width = 24
|
|
28
29
|
filled = min(width, percent * width // 100)
|
|
29
|
-
bar = "
|
|
30
|
+
bar = "━" * filled + "─" * (width - filled)
|
|
30
31
|
detail = ""
|
|
31
32
|
if status.detail_total_bytes > 0:
|
|
32
33
|
detail = f" · {_format_bytes(status.detail_completed_bytes)} / {_format_bytes(status.detail_total_bytes)}"
|
|
33
|
-
return
|
|
34
|
+
return tr(
|
|
35
|
+
f"{bar} {percent:3d}% {status.message}{detail} · {elapsed // 60} 分 {elapsed % 60} 秒",
|
|
36
|
+
f"{bar} {percent:3d}% {tr(status.message)}{detail} · {elapsed // 60}m {elapsed % 60}s",
|
|
37
|
+
)
|
|
34
38
|
|
|
35
39
|
|
|
36
40
|
def main(arguments: list[str] | None = None) -> int:
|
|
41
|
+
# The installer runs this in its own process; it speaks the same language.
|
|
42
|
+
with speaking(system_language()):
|
|
43
|
+
return _main(arguments)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _main(arguments: list[str] | None) -> int:
|
|
37
47
|
parser = argparse.ArgumentParser(add_help=False)
|
|
38
48
|
parser.add_argument("--data-root", required=True)
|
|
39
49
|
parser.add_argument("--requirements", required=True)
|
|
@@ -44,21 +54,44 @@ def main(arguments: list[str] | None = None) -> int:
|
|
|
44
54
|
Path(options.requirements),
|
|
45
55
|
)
|
|
46
56
|
except (OSError, ValueError, ASRSetupError) as error:
|
|
47
|
-
print(
|
|
57
|
+
print(
|
|
58
|
+
tr(f"無法準備本機語音辨識:{error}", f"Cannot prepare local speech recognition: {error}"),
|
|
59
|
+
file=sys.stderr,
|
|
60
|
+
flush=True,
|
|
61
|
+
)
|
|
48
62
|
return 1
|
|
49
63
|
|
|
50
64
|
try:
|
|
51
65
|
state = manager.status().state
|
|
52
66
|
if state is ASRSetupState.READY:
|
|
53
|
-
print(
|
|
67
|
+
print(
|
|
68
|
+
tr(
|
|
69
|
+
"正在確認語音辨識環境使用 Clipen 自己的 Python…",
|
|
70
|
+
"Checking speech recognition runs on Clipen's own Python…",
|
|
71
|
+
),
|
|
72
|
+
flush=True,
|
|
73
|
+
)
|
|
54
74
|
if manager.reseat_runtime():
|
|
55
|
-
print(
|
|
56
|
-
|
|
75
|
+
print(
|
|
76
|
+
tr(
|
|
77
|
+
"✓ 已改用 Clipen 自己的 Python 重建語音辨識環境(模型沿用)",
|
|
78
|
+
"✓ Rebuilt speech recognition on Clipen's own Python (model kept)",
|
|
79
|
+
),
|
|
80
|
+
flush=True,
|
|
81
|
+
)
|
|
82
|
+
print(tr("✓ 本機語音辨識已準備完成", "✓ Local speech recognition is ready"), flush=True)
|
|
57
83
|
return 0
|
|
58
84
|
if state is ASRSetupState.FAILED:
|
|
59
85
|
removed = manager.remove()
|
|
60
86
|
if removed.state is not ASRSetupState.SETUP_REQUIRED:
|
|
61
|
-
print(
|
|
87
|
+
print(
|
|
88
|
+
tr(
|
|
89
|
+
"無法安全清除不完整的語音辨識安裝",
|
|
90
|
+
"Cannot safely clear the incomplete speech recognition install",
|
|
91
|
+
),
|
|
92
|
+
file=sys.stderr,
|
|
93
|
+
flush=True,
|
|
94
|
+
)
|
|
62
95
|
return 1
|
|
63
96
|
manager.start_install(NOTICE_VERSION)
|
|
64
97
|
last_phase = None
|
|
@@ -81,26 +114,39 @@ def main(arguments: list[str] | None = None) -> int:
|
|
|
81
114
|
last_percent = status.progress_percent
|
|
82
115
|
last_reported_at = now
|
|
83
116
|
if status.state is ASRSetupState.READY:
|
|
84
|
-
print(
|
|
117
|
+
print(
|
|
118
|
+
tr(
|
|
119
|
+
"✓ 本機語音辨識與固定模型安裝完成",
|
|
120
|
+
"✓ Local speech recognition and its pinned model are installed",
|
|
121
|
+
),
|
|
122
|
+
flush=True,
|
|
123
|
+
)
|
|
85
124
|
return 0
|
|
86
125
|
if status.state is not ASRSetupState.INSTALLING:
|
|
87
126
|
diagnostics = manager.diagnostic_lines()
|
|
88
127
|
if diagnostics:
|
|
89
|
-
print("安裝器最後訊息:", file=sys.stderr, flush=True)
|
|
128
|
+
print(tr("安裝器最後訊息:", "Last installer output:"), file=sys.stderr, flush=True)
|
|
90
129
|
for line in diagnostics:
|
|
91
130
|
print(f" {line}", file=sys.stderr, flush=True)
|
|
92
131
|
print(
|
|
93
|
-
|
|
132
|
+
tr(
|
|
133
|
+
f"本機語音辨識設定失敗:{status.error_code or status.phase}",
|
|
134
|
+
f"Setting up local speech recognition failed: {status.error_code or status.phase}",
|
|
135
|
+
),
|
|
94
136
|
file=sys.stderr,
|
|
95
137
|
flush=True,
|
|
96
138
|
)
|
|
97
139
|
return 1
|
|
98
140
|
time.sleep(0.1)
|
|
99
141
|
except KeyboardInterrupt:
|
|
100
|
-
print("正在取消本機語音辨識設定…", flush=True)
|
|
142
|
+
print(tr("正在取消本機語音辨識設定…", "Cancelling the speech recognition setup…"), flush=True)
|
|
101
143
|
return 130
|
|
102
144
|
except ASRSetupError as error:
|
|
103
|
-
print(
|
|
145
|
+
print(
|
|
146
|
+
tr(f"本機語音辨識設定失敗:{error.code}", f"Setting up local speech recognition failed: {error.code}"),
|
|
147
|
+
file=sys.stderr,
|
|
148
|
+
flush=True,
|
|
149
|
+
)
|
|
104
150
|
return 1
|
|
105
151
|
finally:
|
|
106
152
|
manager.close(timeout=10)
|