@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/src/clipen/bootstrap.py
CHANGED
|
@@ -20,20 +20,18 @@ from pathlib import Path
|
|
|
20
20
|
from types import ModuleType
|
|
21
21
|
from typing import Iterator, Mapping, Sequence, TextIO
|
|
22
22
|
|
|
23
|
+
from clipen import __version__, own_ffmpeg
|
|
23
24
|
from clipen.asr_release import (
|
|
24
25
|
ASR_SOFTWARE_LICENSE,
|
|
25
|
-
ASR_SOFTWARE_LICENSE_URL,
|
|
26
26
|
DOWNLOAD_BYTES,
|
|
27
|
-
INSTALLED_BYTES,
|
|
28
|
-
LICENSE_NOTICE,
|
|
29
27
|
MODEL_NAME,
|
|
30
|
-
MODEL_REPOSITORY,
|
|
31
|
-
MODEL_REVISION,
|
|
32
28
|
PROGRESS_RECORD_PREFIX,
|
|
33
29
|
quick_release_is_ready,
|
|
34
30
|
release_root,
|
|
35
31
|
)
|
|
32
|
+
from clipen.i18n import current, normalize, save_language, saved_language, speaking, system_language, tr
|
|
36
33
|
from clipen.own_python import sealed_environment
|
|
34
|
+
from clipen.terminal import FRAME_OPEN, Terminal, display_width
|
|
37
35
|
|
|
38
36
|
try:
|
|
39
37
|
import fcntl as _fcntl
|
|
@@ -42,6 +40,9 @@ except ImportError: # Windows does not provide POSIX advisory file locks.
|
|
|
42
40
|
|
|
43
41
|
|
|
44
42
|
_RUNTIME_SCHEMA = 1
|
|
43
|
+
# Rough download sizes, so the person knows what setup costs before agreeing to it.
|
|
44
|
+
_RUNTIME_DOWNLOAD_BYTES = 80_000_000
|
|
45
|
+
_CHROMIUM_DOWNLOAD_BYTES = 150_000_000
|
|
45
46
|
_PIP_VERSION = "26.2.1"
|
|
46
47
|
_SETUPTOOLS_VERSION = "84.0.0"
|
|
47
48
|
_WHEEL_VERSION = "0.48.0"
|
|
@@ -58,6 +59,8 @@ _REMOVABLE_DIRECTORIES = (
|
|
|
58
59
|
"models",
|
|
59
60
|
"cache",
|
|
60
61
|
"logs",
|
|
62
|
+
"fonts", # Open fonts the AI fetched by name.
|
|
63
|
+
"ffmpeg",
|
|
61
64
|
# What `npx @clipen/clipen-cli` set up: Clipen's own Python and its copies of the program. They go
|
|
62
65
|
# last, since the uninstaller itself runs from them.
|
|
63
66
|
"app",
|
|
@@ -77,7 +80,12 @@ class BootstrapError(RuntimeError):
|
|
|
77
80
|
|
|
78
81
|
def _require_posix_file_locking() -> ModuleType:
|
|
79
82
|
if _fcntl is None:
|
|
80
|
-
raise BootstrapError(
|
|
83
|
+
raise BootstrapError(
|
|
84
|
+
tr(
|
|
85
|
+
"這個開發版本尚不支援 Windows;第一次設定需要 POSIX 檔案鎖",
|
|
86
|
+
"This version does not support Windows yet; first-time setup needs POSIX file locks",
|
|
87
|
+
)
|
|
88
|
+
)
|
|
81
89
|
return _fcntl
|
|
82
90
|
|
|
83
91
|
|
|
@@ -153,7 +161,9 @@ def _runtime_fingerprint(repo_root: Path, *, project_version: bytes | None) -> s
|
|
|
153
161
|
):
|
|
154
162
|
path = repo_root / relative
|
|
155
163
|
if not path.is_file() or path.is_symlink():
|
|
156
|
-
raise BootstrapError(
|
|
164
|
+
raise BootstrapError(
|
|
165
|
+
tr(f"缺少必要的 runtime 定義:{relative}", f"A required runtime definition is missing: {relative}")
|
|
166
|
+
)
|
|
157
167
|
digest.update(relative.encode())
|
|
158
168
|
contents = path.read_bytes()
|
|
159
169
|
if relative == "pyproject.toml" and project_version is not None:
|
|
@@ -222,7 +232,6 @@ def _ready_runtime(root: Path, fingerprint: str, repo_root: Path) -> Path | None
|
|
|
222
232
|
|
|
223
233
|
|
|
224
234
|
def _confirm_setup(
|
|
225
|
-
runtime: Path,
|
|
226
235
|
stdin: TextIO,
|
|
227
236
|
stdout: TextIO,
|
|
228
237
|
*,
|
|
@@ -230,48 +239,63 @@ def _confirm_setup(
|
|
|
230
239
|
profile_path: Path | None = None,
|
|
231
240
|
asr_root: Path | None = None,
|
|
232
241
|
include_runtime: bool = True,
|
|
242
|
+
include_ffmpeg: bool = False,
|
|
233
243
|
) -> bool:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if include_runtime
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if asr_root is not None:
|
|
240
|
-
print(" • 隔離的本機語音辨識執行環境", file=stdout)
|
|
241
|
-
print(f" • 固定版本 {MODEL_NAME} 模型", file=stdout)
|
|
242
|
-
if command_path is not None and profile_path is not None:
|
|
243
|
-
print(f" • `clipen` 指令:{command_path}", file=stdout)
|
|
244
|
-
print(f" • 將 Clipen 加入 PATH:{profile_path}", file=stdout)
|
|
244
|
+
"""One short screen: how much is downloaded, how long it takes, and what changes on the Mac."""
|
|
245
|
+
terminal = Terminal(stdout)
|
|
246
|
+
download = (_RUNTIME_DOWNLOAD_BYTES if include_runtime else 0) + (DOWNLOAD_BYTES if asr_root is not None else 0)
|
|
247
|
+
if include_ffmpeg:
|
|
248
|
+
download += own_ffmpeg.DOWNLOAD_BYTES
|
|
245
249
|
if not _chrome_ready(Path.home()):
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
print(f"Clipen runtime:{runtime}", file=stdout)
|
|
250
|
+
download += _CHROMIUM_DOWNLOAD_BYTES
|
|
251
|
+
lines = [tr(f"需要下載約 {terminal.bold(_size(download))}", f"Downloads about {terminal.bold(_size(download))}")]
|
|
249
252
|
if asr_root is not None:
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
file=stdout,
|
|
253
|
+
lines[0] += tr("(大部分是語音辨識模型)", " (mostly the speech recognition model)")
|
|
254
|
+
lines.append(tr("依網路速度大約 5–15 分鐘", "About 5–15 minutes, depending on your connection"))
|
|
255
|
+
if command_path is not None and profile_path is not None:
|
|
256
|
+
lines.append(
|
|
257
|
+
tr(
|
|
258
|
+
f"會新增 {terminal.bold('clipen')} 指令(在 {profile_path.name} 加一行 PATH),之後直接輸入 clipen codex 就能開始",
|
|
259
|
+
f"Adds the {terminal.bold('clipen')} command (one PATH line in {profile_path.name}); afterwards just type clipen codex to start",
|
|
260
|
+
)
|
|
259
261
|
)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
fine_print = [
|
|
263
|
+
tr(
|
|
264
|
+
"全部放在 ~/Library/Application Support/Clipen,不會安裝或修改你電腦上的其他程式,也不需要 sudo",
|
|
265
|
+
"Everything goes in ~/Library/Application Support/Clipen; nothing else on your Mac is installed or changed, and no sudo",
|
|
266
|
+
),
|
|
267
|
+
tr(
|
|
268
|
+
"想移除時輸入 clipen uninstall,作品與毛片會保留",
|
|
269
|
+
"To remove it, type clipen uninstall; your projects and footage stay",
|
|
270
|
+
),
|
|
271
|
+
]
|
|
272
|
+
if asr_root is not None:
|
|
273
|
+
fine_print.insert(
|
|
274
|
+
0,
|
|
275
|
+
tr(
|
|
276
|
+
f"語音辨識模型 {MODEL_NAME} 採 Apache-2.0,執行程式 MLX Speech 採 {ASR_SOFTWARE_LICENSE}",
|
|
277
|
+
f"Speech model {MODEL_NAME} is Apache-2.0; the MLX Speech runtime is {ASR_SOFTWARE_LICENSE}",
|
|
278
|
+
),
|
|
264
279
|
)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
280
|
+
terminal.note(
|
|
281
|
+
tr("安裝 Clipen", "Install Clipen")
|
|
282
|
+
if include_runtime
|
|
283
|
+
else tr("Clipen 需要完成設定", "Clipen needs to finish setting up"),
|
|
284
|
+
lines,
|
|
285
|
+
fine_print,
|
|
286
|
+
)
|
|
269
287
|
if not stdin.isatty():
|
|
270
|
-
raise BootstrapError(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
288
|
+
raise BootstrapError(
|
|
289
|
+
tr(
|
|
290
|
+
"第一次設定需要在互動式 Terminal 中確認。",
|
|
291
|
+
"First-time setup needs confirming in an interactive Terminal.",
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
return terminal.confirm(tr("開始安裝?", "Start the install?"), stdin)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _size(count: int) -> str:
|
|
298
|
+
return f"{count / 1_000_000_000:.1f} GB" if count >= 1_000_000_000 else f"{round(count / 1_000_000)} MB"
|
|
275
299
|
|
|
276
300
|
|
|
277
301
|
# What the web UI is built from, inside apps/web.
|
|
@@ -300,13 +324,18 @@ def ensure_web_build(repo_root: Path, stream: TextIO = sys.stdout) -> None:
|
|
|
300
324
|
return
|
|
301
325
|
npm = shutil.which("npm")
|
|
302
326
|
if npm is None:
|
|
303
|
-
raise BootstrapError(
|
|
304
|
-
|
|
327
|
+
raise BootstrapError(
|
|
328
|
+
tr(
|
|
329
|
+
"從原始碼執行 Clipen 需要 Node.js 18 以上來建立操作介面:https://nodejs.org",
|
|
330
|
+
"Running Clipen from source needs Node.js 18 or later to build the interface: https://nodejs.org",
|
|
331
|
+
)
|
|
332
|
+
)
|
|
305
333
|
quiet = {"cwd": web, "check": True, "stdout": subprocess.DEVNULL}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
334
|
+
with Terminal(stream).spinner(tr("正在建立 Clipen 操作介面", "Building the Clipen interface")) as spinner:
|
|
335
|
+
if not (web / "node_modules").is_dir():
|
|
336
|
+
subprocess.run([npm, "ci", "--no-audit", "--no-fund"], **quiet)
|
|
337
|
+
subprocess.run([npm, "run", "build"], **quiet)
|
|
338
|
+
spinner.done(tr("操作介面建立完成", "Interface built"))
|
|
310
339
|
|
|
311
340
|
|
|
312
341
|
def _install_hint(repo_root: Path) -> str:
|
|
@@ -323,18 +352,45 @@ def _chrome_ready(home: Path) -> bool:
|
|
|
323
352
|
def _ensure_chrome(runtime: Path, data_root: Path, home: Path, stdout: TextIO) -> None:
|
|
324
353
|
if _chrome_ready(home):
|
|
325
354
|
return
|
|
326
|
-
print("這台 Mac 沒有 Google Chrome;正在下載 Clipen 畫元件用的 Chromium(約 150 MB)…", file=stdout)
|
|
327
355
|
log_root = data_root / "logs"
|
|
328
356
|
log_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
329
|
-
with (
|
|
357
|
+
with (
|
|
358
|
+
Terminal(stdout).spinner(
|
|
359
|
+
tr("正在下載繪製畫面用的瀏覽器(Chromium)", "Downloading the browser used to draw graphics (Chromium)")
|
|
360
|
+
) as spinner,
|
|
361
|
+
(log_root / "bootstrap-chromium.log").open("w", encoding="utf-8") as log,
|
|
362
|
+
):
|
|
330
363
|
_run_logged((str(runtime_python(runtime)), "-m", "playwright", "install", "chromium"), cwd=runtime, log=log)
|
|
331
|
-
|
|
364
|
+
spinner.done(tr("瀏覽器就緒", "Browser ready"))
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _ensure_ffmpeg(data_root: Path, environment: Mapping[str, str], stdout: TextIO) -> None:
|
|
368
|
+
"""Films are cut with ffmpeg; a Mac without it gets Clipen's own, kept in Clipen's folder."""
|
|
369
|
+
if not own_ffmpeg.needed(data_root, environment):
|
|
370
|
+
return
|
|
371
|
+
terminal = Terminal(stdout)
|
|
372
|
+
label = tr("正在下載影片處理工具(ffmpeg)", "Downloading the video tools (ffmpeg)")
|
|
373
|
+
with terminal.spinner(label) as spinner:
|
|
374
|
+
|
|
375
|
+
def progress(done: int, total: int) -> None:
|
|
376
|
+
spinner.update(f"{label} {terminal.progress_bar(done * 100 // total)} {_size(done)} / {_size(total)}")
|
|
377
|
+
|
|
378
|
+
try:
|
|
379
|
+
own_ffmpeg.install(data_root, progress)
|
|
380
|
+
except own_ffmpeg.FfmpegUnavailable as error:
|
|
381
|
+
raise BootstrapError(str(error)) from error
|
|
382
|
+
spinner.done(tr("影片處理工具就緒", "Video tools ready"))
|
|
332
383
|
|
|
333
384
|
|
|
334
385
|
def _command_script(repo_root: Path) -> str:
|
|
335
386
|
launcher = repo_root.resolve(strict=True) / "clipen"
|
|
336
387
|
if launcher.is_symlink() or not launcher.is_file() or not os.access(launcher, os.X_OK):
|
|
337
|
-
raise BootstrapError(
|
|
388
|
+
raise BootstrapError(
|
|
389
|
+
tr(
|
|
390
|
+
"Repo 內的 clipen launcher 不存在或不可執行",
|
|
391
|
+
"The clipen launcher in the repository is missing or not executable",
|
|
392
|
+
)
|
|
393
|
+
)
|
|
338
394
|
# Run the launcher with the Python that set Clipen up: a Mac's own python3 is too old.
|
|
339
395
|
python = Path(sys.executable).resolve()
|
|
340
396
|
# -I: the person's PYTHONPATH, PYTHONHOME and user site never reach Clipen's Python.
|
|
@@ -347,7 +403,12 @@ def _shell_profile(home: Path, environment: Mapping[str, str]) -> Path:
|
|
|
347
403
|
return home / ".zshrc"
|
|
348
404
|
if shell == "bash":
|
|
349
405
|
return home / (".bash_profile" if sys.platform == "darwin" else ".bashrc")
|
|
350
|
-
raise BootstrapError(
|
|
406
|
+
raise BootstrapError(
|
|
407
|
+
tr(
|
|
408
|
+
"目前只能自動設定 zsh 或 bash;請將 Clipen 的 bin 目錄手動加入 PATH",
|
|
409
|
+
"Only zsh and bash can be set up automatically; add Clipen's bin folder to PATH yourself",
|
|
410
|
+
)
|
|
411
|
+
)
|
|
351
412
|
|
|
352
413
|
|
|
353
414
|
def _profile_block(bin_root: Path) -> str:
|
|
@@ -356,11 +417,21 @@ def _profile_block(bin_root: Path) -> str:
|
|
|
356
417
|
|
|
357
418
|
def _replace_profile_block(contents: str, block: str) -> str:
|
|
358
419
|
if contents.count(_PROFILE_START) > 1 or contents.count(_PROFILE_END) > 1:
|
|
359
|
-
raise BootstrapError(
|
|
420
|
+
raise BootstrapError(
|
|
421
|
+
tr(
|
|
422
|
+
"shell 設定中有重複的 Clipen PATH 區塊,請先保留並回報問題",
|
|
423
|
+
"Your shell settings have a duplicate Clipen PATH block; keep it and report the problem",
|
|
424
|
+
)
|
|
425
|
+
)
|
|
360
426
|
start = contents.find(_PROFILE_START)
|
|
361
427
|
end = contents.find(_PROFILE_END)
|
|
362
428
|
if (start < 0) != (end < 0) or (start >= 0 and end < start):
|
|
363
|
-
raise BootstrapError(
|
|
429
|
+
raise BootstrapError(
|
|
430
|
+
tr(
|
|
431
|
+
"shell 設定中的 Clipen PATH 區塊不完整,請先保留並回報問題",
|
|
432
|
+
"The Clipen PATH block in your shell settings is incomplete; keep it and report the problem",
|
|
433
|
+
)
|
|
434
|
+
)
|
|
364
435
|
if start >= 0:
|
|
365
436
|
end += len(_PROFILE_END)
|
|
366
437
|
updated = contents[:start] + block + contents[end:]
|
|
@@ -372,11 +443,21 @@ def _replace_profile_block(contents: str, block: str) -> str:
|
|
|
372
443
|
|
|
373
444
|
def _remove_profile_block(contents: str) -> str:
|
|
374
445
|
if contents.count(_PROFILE_START) > 1 or contents.count(_PROFILE_END) > 1:
|
|
375
|
-
raise BootstrapError(
|
|
446
|
+
raise BootstrapError(
|
|
447
|
+
tr(
|
|
448
|
+
"shell 設定中有重複的 Clipen PATH 區塊,未進行移除",
|
|
449
|
+
"Your shell settings have a duplicate Clipen PATH block, so nothing was removed",
|
|
450
|
+
)
|
|
451
|
+
)
|
|
376
452
|
start = contents.find(_PROFILE_START)
|
|
377
453
|
end = contents.find(_PROFILE_END)
|
|
378
454
|
if (start < 0) != (end < 0) or (start >= 0 and end < start):
|
|
379
|
-
raise BootstrapError(
|
|
455
|
+
raise BootstrapError(
|
|
456
|
+
tr(
|
|
457
|
+
"shell 設定中的 Clipen PATH 區塊不完整,未進行移除",
|
|
458
|
+
"The Clipen PATH block in your shell settings is incomplete, so nothing was removed",
|
|
459
|
+
)
|
|
460
|
+
)
|
|
380
461
|
if start < 0:
|
|
381
462
|
return contents
|
|
382
463
|
end += len(_PROFILE_END)
|
|
@@ -409,28 +490,44 @@ def _install_command(
|
|
|
409
490
|
) -> tuple[Path, Path]:
|
|
410
491
|
bin_root = data_root / "bin"
|
|
411
492
|
if bin_root.exists() and (bin_root.is_symlink() or not bin_root.is_dir()):
|
|
412
|
-
raise BootstrapError("Clipen bin 目錄不是安全的實體目錄")
|
|
493
|
+
raise BootstrapError(tr("Clipen bin 目錄不是安全的實體目錄", "Clipen's bin folder is not a safe, real folder"))
|
|
413
494
|
bin_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
414
495
|
command_path = bin_root / "clipen"
|
|
415
496
|
script = _command_script(repo_root)
|
|
416
497
|
if command_path.exists() or command_path.is_symlink():
|
|
417
498
|
if command_path.is_symlink() or not command_path.is_file():
|
|
418
|
-
raise BootstrapError(
|
|
499
|
+
raise BootstrapError(
|
|
500
|
+
tr("Clipen 指令位置已被不安全的檔案占用", "An unsafe file is in the way of the clipen command")
|
|
501
|
+
)
|
|
419
502
|
try:
|
|
420
503
|
existing_command = command_path.read_text(encoding="utf-8")
|
|
421
504
|
except (OSError, UnicodeError) as error:
|
|
422
|
-
raise BootstrapError(
|
|
505
|
+
raise BootstrapError(
|
|
506
|
+
tr("無法安全讀取既有的 Clipen 指令", "The existing clipen command cannot be read safely")
|
|
507
|
+
) from error
|
|
423
508
|
if _COMMAND_MARKER not in existing_command:
|
|
424
|
-
raise BootstrapError(
|
|
509
|
+
raise BootstrapError(
|
|
510
|
+
tr(
|
|
511
|
+
"Clipen 指令位置已有其他程式,未進行覆寫",
|
|
512
|
+
"Another program already uses the clipen command, so it was not overwritten",
|
|
513
|
+
)
|
|
514
|
+
)
|
|
425
515
|
|
|
426
516
|
profile_path = _shell_profile(home, environment)
|
|
427
517
|
if profile_path.exists() or profile_path.is_symlink():
|
|
428
518
|
if profile_path.is_symlink() or not profile_path.is_file():
|
|
429
|
-
raise BootstrapError(
|
|
519
|
+
raise BootstrapError(
|
|
520
|
+
tr(
|
|
521
|
+
"shell 設定檔不是安全的實體檔案,未進行修改",
|
|
522
|
+
"Your shell settings file is not a safe, real file, so it was not changed",
|
|
523
|
+
)
|
|
524
|
+
)
|
|
430
525
|
try:
|
|
431
526
|
profile = profile_path.read_text(encoding="utf-8")
|
|
432
527
|
except (OSError, UnicodeError) as error:
|
|
433
|
-
raise BootstrapError(
|
|
528
|
+
raise BootstrapError(
|
|
529
|
+
tr("無法安全讀取 shell 設定檔", "Your shell settings file cannot be read safely")
|
|
530
|
+
) from error
|
|
434
531
|
profile_mode = stat.S_IMODE(profile_path.stat().st_mode)
|
|
435
532
|
else:
|
|
436
533
|
profile = ""
|
|
@@ -488,14 +585,19 @@ def _run_logged(command: Sequence[str], *, cwd: Path, log: TextIO) -> None:
|
|
|
488
585
|
env=sealed_environment(os.environ),
|
|
489
586
|
)
|
|
490
587
|
if completed.returncode != 0:
|
|
491
|
-
raise BootstrapError(
|
|
588
|
+
raise BootstrapError(
|
|
589
|
+
tr(
|
|
590
|
+
f"runtime 安裝命令失敗(結束代碼 {completed.returncode})",
|
|
591
|
+
f"The runtime install command failed (exit code {completed.returncode})",
|
|
592
|
+
)
|
|
593
|
+
)
|
|
492
594
|
|
|
493
595
|
|
|
494
596
|
def _install_runtime(staging: Path, repo_root: Path, fingerprint: str, log_path: Path) -> None:
|
|
495
597
|
venv.EnvBuilder(with_pip=True, clear=False, symlinks=False).create(staging)
|
|
496
598
|
python = runtime_python(staging)
|
|
497
599
|
if not python.is_file():
|
|
498
|
-
raise BootstrapError("無法建立 Clipen
|
|
600
|
+
raise BootstrapError(tr("無法建立 Clipen 執行環境", "Could not create Clipen's runtime"))
|
|
499
601
|
|
|
500
602
|
with log_path.open("w", encoding="utf-8") as log:
|
|
501
603
|
_run_logged(
|
|
@@ -569,8 +671,9 @@ def _install_asr_bundle(
|
|
|
569
671
|
)
|
|
570
672
|
captured = 0
|
|
571
673
|
process: subprocess.Popen[str] | None = None
|
|
674
|
+
terminal = Terminal(stdout)
|
|
572
675
|
progress_active = False
|
|
573
|
-
|
|
676
|
+
frame = 0
|
|
574
677
|
try:
|
|
575
678
|
with log_path.open("w", encoding="utf-8") as log:
|
|
576
679
|
process = subprocess.Popen(
|
|
@@ -593,32 +696,33 @@ def _install_asr_bundle(
|
|
|
593
696
|
captured += len(line.encode("utf-8"))
|
|
594
697
|
if captured > 4 * 1024 * 1024:
|
|
595
698
|
process.terminate()
|
|
596
|
-
raise BootstrapError(
|
|
699
|
+
raise BootstrapError(
|
|
700
|
+
tr("語音辨識設定輸出超過安全上限", "The speech recognition setup printed more than allowed")
|
|
701
|
+
)
|
|
597
702
|
is_progress = line.startswith(PROGRESS_RECORD_PREFIX)
|
|
598
703
|
visible_line = line[len(PROGRESS_RECORD_PREFIX) :].rstrip("\r\n") if is_progress else line
|
|
599
704
|
log.write(f"{visible_line}\n" if is_progress else visible_line)
|
|
600
705
|
log.flush()
|
|
601
|
-
if is_progress and
|
|
602
|
-
|
|
603
|
-
stdout.write(f"\r{visible_line}{padding}")
|
|
706
|
+
if is_progress and terminal.live:
|
|
707
|
+
terminal.overwrite(_progress_display(terminal, visible_line, frame))
|
|
604
708
|
progress_active = True
|
|
605
|
-
|
|
709
|
+
frame += 1
|
|
710
|
+
continue
|
|
711
|
+
if progress_active:
|
|
712
|
+
terminal.write()
|
|
713
|
+
progress_active = False
|
|
714
|
+
text = visible_line.rstrip("\r\n")
|
|
715
|
+
if text.startswith("✓ "):
|
|
716
|
+
terminal.step(text[2:])
|
|
606
717
|
else:
|
|
607
|
-
|
|
608
|
-
stdout.write("\n")
|
|
609
|
-
progress_active = False
|
|
610
|
-
progress_width = 0
|
|
611
|
-
stdout.write(f"{visible_line}\n" if is_progress else visible_line)
|
|
612
|
-
stdout.flush()
|
|
613
|
-
returncode = process.wait()
|
|
718
|
+
terminal.write(f"{terminal.paint('90', '│')} {text}")
|
|
614
719
|
if progress_active:
|
|
615
|
-
|
|
616
|
-
stdout.flush()
|
|
720
|
+
terminal.write()
|
|
617
721
|
progress_active = False
|
|
722
|
+
returncode = process.wait()
|
|
618
723
|
except BaseException:
|
|
619
724
|
if progress_active:
|
|
620
|
-
|
|
621
|
-
stdout.flush()
|
|
725
|
+
terminal.write()
|
|
622
726
|
if process is not None and process.poll() is None:
|
|
623
727
|
process.terminate()
|
|
624
728
|
try:
|
|
@@ -628,7 +732,21 @@ def _install_asr_bundle(
|
|
|
628
732
|
process.wait(timeout=5)
|
|
629
733
|
raise
|
|
630
734
|
if returncode != 0:
|
|
631
|
-
raise BootstrapError(
|
|
735
|
+
raise BootstrapError(
|
|
736
|
+
tr(
|
|
737
|
+
f"本機語音辨識設定失敗;診斷紀錄:{log_path}",
|
|
738
|
+
f"Setting up local speech recognition failed; log: {log_path}",
|
|
739
|
+
)
|
|
740
|
+
)
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
def _progress_display(terminal: Terminal, line: str, frame: int) -> str:
|
|
744
|
+
"""The installer's progress record, redrawn with a spinner and the brand-coloured bar."""
|
|
745
|
+
bar = re.match(r"([━─]+) +(\d+)%(.*)", line)
|
|
746
|
+
symbol = terminal.paint("35", "◒◐◓◑"[frame % 4])
|
|
747
|
+
if bar is None:
|
|
748
|
+
return f"{symbol} {line}"
|
|
749
|
+
return f"{symbol} {terminal.progress_bar(int(bar.group(2)), len(bar.group(1)))} {terminal.bold(bar.group(2) + '%')}{bar.group(3)}"
|
|
632
750
|
|
|
633
751
|
|
|
634
752
|
def ensure_runtime(
|
|
@@ -644,7 +762,9 @@ def ensure_runtime(
|
|
|
644
762
|
root = (data_root or clipen_data_root()) / "runtimes"
|
|
645
763
|
root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
646
764
|
if root.is_symlink():
|
|
647
|
-
raise BootstrapError(
|
|
765
|
+
raise BootstrapError(
|
|
766
|
+
tr("Clipen runtime 根目錄不能是 symbolic link", "Clipen's runtime folder cannot be a symbolic link")
|
|
767
|
+
)
|
|
648
768
|
runtime = root / fingerprint
|
|
649
769
|
|
|
650
770
|
with _bootstrap_lock(root):
|
|
@@ -652,25 +772,30 @@ def ensure_runtime(
|
|
|
652
772
|
if ready is not None:
|
|
653
773
|
return ready
|
|
654
774
|
if runtime.exists():
|
|
655
|
-
raise BootstrapError(
|
|
656
|
-
|
|
657
|
-
|
|
775
|
+
raise BootstrapError(
|
|
776
|
+
tr(
|
|
777
|
+
f"Clipen runtime 不完整,請先保留此目錄並回報問題:{runtime}",
|
|
778
|
+
f"Clipen's runtime is incomplete; keep this folder and report the problem: {runtime}",
|
|
779
|
+
)
|
|
780
|
+
)
|
|
781
|
+
if not confirmed and not _confirm_setup(stdin, stdout):
|
|
782
|
+
Terminal(stdout).outro(tr("已取消,沒有建立 Clipen runtime。", "Cancelled; no Clipen runtime was created."))
|
|
658
783
|
return None
|
|
659
784
|
|
|
660
785
|
staging = root / f".{fingerprint}.staging-{uuid.uuid4().hex}"
|
|
661
786
|
log_root = (data_root or clipen_data_root()) / "logs"
|
|
662
787
|
log_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
663
788
|
log_path = log_root / f"bootstrap-{fingerprint}.log"
|
|
664
|
-
print("正在建立 Clipen 執行環境…", file=stdout)
|
|
665
789
|
try:
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
790
|
+
with Terminal(stdout).spinner(tr("正在準備 Clipen 執行環境", "Preparing Clipen's runtime")) as spinner:
|
|
791
|
+
staging.mkdir(mode=0o700)
|
|
792
|
+
_install_runtime(staging, repo_root, fingerprint, log_path)
|
|
793
|
+
staging.rename(runtime)
|
|
794
|
+
spinner.done(tr("執行環境就緒", "Runtime ready"))
|
|
669
795
|
except Exception:
|
|
670
796
|
if staging.exists() and not staging.is_symlink():
|
|
671
797
|
shutil.rmtree(staging)
|
|
672
798
|
raise
|
|
673
|
-
print("✓ Clipen 執行環境建立完成", file=stdout)
|
|
674
799
|
return runtime
|
|
675
800
|
|
|
676
801
|
|
|
@@ -688,7 +813,7 @@ def ensure_installation(
|
|
|
688
813
|
selected_home = home or Path.home()
|
|
689
814
|
selected_environment = environment if environment is not None else os.environ
|
|
690
815
|
if platform.system() != "Darwin" or platform.machine() != "arm64":
|
|
691
|
-
raise BootstrapError("目前完整設定只支援 Apple 晶片的 macOS")
|
|
816
|
+
raise BootstrapError(tr("目前完整設定只支援 Apple 晶片的 macOS", "Full setup supports only Apple silicon Macs"))
|
|
692
817
|
fingerprint = runtime_fingerprint(repo_root)
|
|
693
818
|
ready = _ready_runtime(selected_data_root / "runtimes", fingerprint, repo_root)
|
|
694
819
|
runtime = ready or selected_data_root / "runtimes" / fingerprint
|
|
@@ -701,15 +826,17 @@ def ensure_installation(
|
|
|
701
826
|
command_path = selected_data_root / "bin" / "clipen"
|
|
702
827
|
profile_path = _shell_profile(selected_home, selected_environment)
|
|
703
828
|
if not _confirm_setup(
|
|
704
|
-
runtime,
|
|
705
829
|
stdin,
|
|
706
830
|
stdout,
|
|
707
831
|
command_path=None if command_ready else command_path,
|
|
708
832
|
profile_path=None if command_ready else profile_path,
|
|
709
833
|
asr_root=None if asr_ready else release_root(selected_data_root),
|
|
710
834
|
include_runtime=not runtime_ready,
|
|
835
|
+
include_ffmpeg=own_ffmpeg.needed(selected_data_root, selected_environment),
|
|
711
836
|
):
|
|
712
|
-
|
|
837
|
+
Terminal(stdout).outro(
|
|
838
|
+
tr("已取消,既有 Clipen 資料沒有變動。", "Cancelled; your Clipen data is unchanged.")
|
|
839
|
+
)
|
|
713
840
|
return None
|
|
714
841
|
if not runtime_ready:
|
|
715
842
|
installed_runtime = ensure_runtime(
|
|
@@ -727,9 +854,11 @@ def ensure_installation(
|
|
|
727
854
|
log_root = selected_data_root / "logs"
|
|
728
855
|
log_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
729
856
|
if log_root.is_symlink():
|
|
730
|
-
raise BootstrapError(
|
|
857
|
+
raise BootstrapError(
|
|
858
|
+
tr("Clipen log 目錄不能是 symbolic link", "Clipen's log folder cannot be a symbolic link")
|
|
859
|
+
)
|
|
731
860
|
asr_log = log_root / f"bootstrap-asr-{fingerprint}.log"
|
|
732
|
-
|
|
861
|
+
Terminal(stdout).write(Terminal(stdout).paint("90", "│"))
|
|
733
862
|
_install_asr_bundle(
|
|
734
863
|
runtime,
|
|
735
864
|
repo_root,
|
|
@@ -738,39 +867,48 @@ def ensure_installation(
|
|
|
738
867
|
stdout,
|
|
739
868
|
)
|
|
740
869
|
if not quick_release_is_ready(selected_data_root, asr_requirements):
|
|
741
|
-
raise BootstrapError(
|
|
870
|
+
raise BootstrapError(
|
|
871
|
+
tr(
|
|
872
|
+
f"語音辨識安裝未通過啟動檢查;診斷紀錄:{asr_log}",
|
|
873
|
+
f"The speech recognition install failed its start-up check; log: {asr_log}",
|
|
874
|
+
)
|
|
875
|
+
)
|
|
742
876
|
_ensure_chrome(runtime, selected_data_root, selected_home, stdout)
|
|
877
|
+
_ensure_ffmpeg(selected_data_root, selected_environment, stdout)
|
|
743
878
|
if not command_ready:
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
)
|
|
747
|
-
print(f"✓ 已建立指令:{command_path}", file=stdout)
|
|
748
|
-
print(f"✓ 已更新 PATH:{profile_path}", file=stdout)
|
|
749
|
-
print("下次開啟 Terminal 後可直接輸入:clipen codex(或 clipen claude)", file=stdout)
|
|
750
|
-
print("✓ Clipen 完整設定完成", file=stdout)
|
|
879
|
+
_install_command(repo_root, selected_data_root, selected_home, selected_environment)
|
|
880
|
+
Terminal(stdout).step(tr("已新增 clipen 指令", "Added the clipen command"))
|
|
751
881
|
return runtime
|
|
752
882
|
|
|
753
883
|
if stdin.isatty():
|
|
754
884
|
_ensure_chrome(runtime, selected_data_root, selected_home, stdout)
|
|
885
|
+
_ensure_ffmpeg(selected_data_root, selected_environment, stdout)
|
|
755
886
|
|
|
756
887
|
if not command_ready:
|
|
757
888
|
if not stdin.isatty():
|
|
758
889
|
return runtime
|
|
759
|
-
|
|
760
|
-
print(f"將建立:{selected_data_root / 'bin' / 'clipen'}", file=stdout)
|
|
890
|
+
terminal = Terminal(stdout)
|
|
761
891
|
profile_path = _shell_profile(selected_home, selected_environment)
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
892
|
+
terminal.note(
|
|
893
|
+
tr("Clipen 需要完成一次指令設定", "Clipen needs to set up its command once"),
|
|
894
|
+
[
|
|
895
|
+
tr(
|
|
896
|
+
f"將建立:{selected_data_root / 'bin' / 'clipen'}",
|
|
897
|
+
f"Creates: {selected_data_root / 'bin' / 'clipen'}",
|
|
898
|
+
),
|
|
899
|
+
tr(f"將更新 PATH:{profile_path}", f"Updates PATH in: {profile_path}"),
|
|
900
|
+
],
|
|
770
901
|
)
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
902
|
+
if not terminal.confirm(tr("完成設定?", "Finish setting up?"), stdin):
|
|
903
|
+
terminal.warn(
|
|
904
|
+
tr(
|
|
905
|
+
f"已略過;可再次執行 {_install_hint(repo_root)} 完成指令設定。",
|
|
906
|
+
f"Skipped; run {_install_hint(repo_root)} again to set up the command.",
|
|
907
|
+
)
|
|
908
|
+
)
|
|
909
|
+
return runtime
|
|
910
|
+
_install_command(repo_root, selected_data_root, selected_home, selected_environment)
|
|
911
|
+
Terminal(stdout).step(tr("已新增 clipen 指令", "Added the clipen command"))
|
|
774
912
|
return runtime
|
|
775
913
|
|
|
776
914
|
|
|
@@ -780,14 +918,17 @@ def completed_runtime(repo_root: Path, *, data_root: Path | None = None) -> Path
|
|
|
780
918
|
repo_root = repo_root.resolve(strict=True)
|
|
781
919
|
selected_data_root = data_root or clipen_data_root()
|
|
782
920
|
if platform.system() != "Darwin" or platform.machine() != "arm64":
|
|
783
|
-
raise BootstrapError("目前只支援 Apple 晶片的 macOS")
|
|
921
|
+
raise BootstrapError(tr("目前只支援 Apple 晶片的 macOS", "Supports only Apple silicon Macs"))
|
|
784
922
|
fingerprint = runtime_fingerprint(repo_root)
|
|
785
923
|
runtime = _ready_runtime(selected_data_root / "runtimes", fingerprint, repo_root)
|
|
786
924
|
requirements = repo_root / "requirements" / "asr-runtime.txt"
|
|
787
925
|
if runtime is None or not quick_release_is_ready(selected_data_root, requirements):
|
|
788
926
|
raise BootstrapError(
|
|
789
|
-
|
|
790
|
-
|
|
927
|
+
tr(
|
|
928
|
+
f"Clipen 尚未完成安裝;第一次請執行 {_install_hint(repo_root)},已有 clipen 指令時可執行 clipen install 修復",
|
|
929
|
+
f"Clipen is not fully installed. The first time, run {_install_hint(repo_root)}; "
|
|
930
|
+
"if you have the clipen command, clipen install repairs it",
|
|
931
|
+
)
|
|
791
932
|
)
|
|
792
933
|
return runtime
|
|
793
934
|
|
|
@@ -801,11 +942,13 @@ def _controller_is_running(data_root: Path) -> bool:
|
|
|
801
942
|
try:
|
|
802
943
|
descriptor = os.open(lock_path, flags)
|
|
803
944
|
except OSError as error:
|
|
804
|
-
raise BootstrapError(
|
|
945
|
+
raise BootstrapError(
|
|
946
|
+
tr("無法安全檢查 Clipen 是否仍在執行", "Cannot safely check whether Clipen is still running")
|
|
947
|
+
) from error
|
|
805
948
|
try:
|
|
806
949
|
info = os.fstat(descriptor)
|
|
807
950
|
if not stat.S_ISREG(info.st_mode):
|
|
808
|
-
raise BootstrapError("Clipen 執行鎖不是安全的實體檔案")
|
|
951
|
+
raise BootstrapError(tr("Clipen 執行鎖不是安全的實體檔案", "Clipen's run lock is not a safe, real file"))
|
|
809
952
|
try:
|
|
810
953
|
locking.flock(descriptor, locking.LOCK_EX | locking.LOCK_NB)
|
|
811
954
|
except BlockingIOError:
|
|
@@ -820,17 +963,28 @@ def _validate_removable_path(path: Path, data_root: Path, *, directory: bool) ->
|
|
|
820
963
|
if not path.exists() and not path.is_symlink():
|
|
821
964
|
return
|
|
822
965
|
if path.is_symlink() or path.parent.resolve(strict=True) != data_root:
|
|
823
|
-
raise BootstrapError(
|
|
966
|
+
raise BootstrapError(
|
|
967
|
+
tr(f"拒絕移除不安全的 Clipen 路徑:{path}", f"Refused to remove an unsafe Clipen path: {path}")
|
|
968
|
+
)
|
|
824
969
|
if directory:
|
|
825
970
|
if not path.is_dir() or path.is_mount():
|
|
826
|
-
raise BootstrapError(
|
|
971
|
+
raise BootstrapError(
|
|
972
|
+
tr(f"拒絕移除非一般目錄:{path}", f"Refused to remove something that is not a plain folder: {path}")
|
|
973
|
+
)
|
|
827
974
|
for current, directories, _files in os.walk(path, followlinks=False):
|
|
828
975
|
for name in directories:
|
|
829
976
|
candidate = Path(current) / name
|
|
830
977
|
if not candidate.is_symlink() and candidate.is_mount():
|
|
831
|
-
raise BootstrapError(
|
|
978
|
+
raise BootstrapError(
|
|
979
|
+
tr(
|
|
980
|
+
f"拒絕移除包含 mount point 的目錄:{candidate}",
|
|
981
|
+
f"Refused to remove a folder containing a mount point: {candidate}",
|
|
982
|
+
)
|
|
983
|
+
)
|
|
832
984
|
elif not path.is_file():
|
|
833
|
-
raise BootstrapError(
|
|
985
|
+
raise BootstrapError(
|
|
986
|
+
tr(f"拒絕移除非一般檔案:{path}", f"Refused to remove something that is not a plain file: {path}")
|
|
987
|
+
)
|
|
834
988
|
|
|
835
989
|
|
|
836
990
|
def uninstall_installation(
|
|
@@ -850,26 +1004,47 @@ def uninstall_installation(
|
|
|
850
1004
|
bin_root = selected_data_root / "bin"
|
|
851
1005
|
command_path = bin_root / "clipen"
|
|
852
1006
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1007
|
+
terminal = Terminal(stdout)
|
|
1008
|
+
terminal.intro("Clipen")
|
|
1009
|
+
terminal.note(
|
|
1010
|
+
tr("移除 Clipen", "Remove Clipen"),
|
|
1011
|
+
[
|
|
1012
|
+
tr(
|
|
1013
|
+
f"會移除 Clipen 程式、語音辨識模型和 {terminal.bold('clipen')} 指令",
|
|
1014
|
+
f"Removes the Clipen program, the speech model and the {terminal.bold('clipen')} command",
|
|
1015
|
+
)
|
|
1016
|
+
],
|
|
1017
|
+
[
|
|
1018
|
+
tr(
|
|
1019
|
+
"你的作品、毛片、參考作品和匯出檔都會保留",
|
|
1020
|
+
"Your projects, footage, reference work and exports are all kept",
|
|
1021
|
+
)
|
|
1022
|
+
],
|
|
1023
|
+
)
|
|
859
1024
|
if not stdin.isatty():
|
|
860
|
-
raise BootstrapError(
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
1025
|
+
raise BootstrapError(
|
|
1026
|
+
tr(
|
|
1027
|
+
"移除 Clipen 需要在互動式 Terminal 中確認",
|
|
1028
|
+
"Removing Clipen needs confirming in an interactive Terminal",
|
|
1029
|
+
)
|
|
1030
|
+
)
|
|
1031
|
+
if not terminal.confirm(tr("確定移除?", "Remove it?"), stdin, default=False):
|
|
1032
|
+
terminal.outro(tr("已取消,沒有移除任何內容。", "Cancelled; nothing was removed."))
|
|
865
1033
|
return False
|
|
866
1034
|
|
|
867
1035
|
if selected_data_root.exists() or selected_data_root.is_symlink():
|
|
868
1036
|
if selected_data_root.is_symlink() or not selected_data_root.is_dir():
|
|
869
|
-
raise BootstrapError(
|
|
1037
|
+
raise BootstrapError(
|
|
1038
|
+
tr("Clipen 資料根目錄不安全,未進行移除", "Clipen's data folder is not safe, so nothing was removed")
|
|
1039
|
+
)
|
|
870
1040
|
resolved_data_root = selected_data_root.resolve(strict=True)
|
|
871
1041
|
if _controller_is_running(resolved_data_root):
|
|
872
|
-
raise BootstrapError(
|
|
1042
|
+
raise BootstrapError(
|
|
1043
|
+
tr(
|
|
1044
|
+
"Clipen 仍在執行;請先在啟動它的 Terminal 按 Ctrl+C",
|
|
1045
|
+
"Clipen is still running; press Ctrl+C in the Terminal that started it",
|
|
1046
|
+
)
|
|
1047
|
+
)
|
|
873
1048
|
else:
|
|
874
1049
|
resolved_data_root = selected_data_root
|
|
875
1050
|
|
|
@@ -878,20 +1053,37 @@ def uninstall_installation(
|
|
|
878
1053
|
profile_mode = 0o600
|
|
879
1054
|
if profile_path.exists() or profile_path.is_symlink():
|
|
880
1055
|
if profile_path.is_symlink() or not profile_path.is_file():
|
|
881
|
-
raise BootstrapError(
|
|
1056
|
+
raise BootstrapError(
|
|
1057
|
+
tr(
|
|
1058
|
+
"shell 設定檔不是安全的實體檔案,未進行移除",
|
|
1059
|
+
"Your shell settings file is not a safe, real file, so nothing was removed",
|
|
1060
|
+
)
|
|
1061
|
+
)
|
|
882
1062
|
profile = profile_path.read_text(encoding="utf-8")
|
|
883
1063
|
updated_profile = _remove_profile_block(profile)
|
|
884
1064
|
profile_mode = stat.S_IMODE(profile_path.stat().st_mode)
|
|
885
1065
|
|
|
886
1066
|
if bin_root.exists() or bin_root.is_symlink():
|
|
887
1067
|
if bin_root.is_symlink() or not bin_root.is_dir():
|
|
888
|
-
raise BootstrapError(
|
|
1068
|
+
raise BootstrapError(
|
|
1069
|
+
tr("Clipen bin 目錄不安全,未進行移除", "Clipen's bin folder is not safe, so nothing was removed")
|
|
1070
|
+
)
|
|
889
1071
|
if command_path.exists() or command_path.is_symlink():
|
|
890
1072
|
if command_path.is_symlink() or not command_path.is_file():
|
|
891
|
-
raise BootstrapError(
|
|
1073
|
+
raise BootstrapError(
|
|
1074
|
+
tr(
|
|
1075
|
+
"clipen 指令位置不是安全的實體檔案,未進行移除",
|
|
1076
|
+
"The clipen command is not a safe, real file, so nothing was removed",
|
|
1077
|
+
)
|
|
1078
|
+
)
|
|
892
1079
|
command = command_path.read_text(encoding="utf-8")
|
|
893
1080
|
if not any(line.startswith(_MANAGED_COMMAND_PREFIX) for line in command.splitlines()[:3]):
|
|
894
|
-
raise BootstrapError(
|
|
1081
|
+
raise BootstrapError(
|
|
1082
|
+
tr(
|
|
1083
|
+
"clipen 指令不是由 Clipen 管理,未進行移除",
|
|
1084
|
+
"The clipen command is not managed by Clipen, so nothing was removed",
|
|
1085
|
+
)
|
|
1086
|
+
)
|
|
895
1087
|
|
|
896
1088
|
if selected_data_root.exists():
|
|
897
1089
|
for name in _REMOVABLE_DIRECTORIES:
|
|
@@ -920,40 +1112,176 @@ def uninstall_installation(
|
|
|
920
1112
|
path = resolved_data_root / name
|
|
921
1113
|
if selected_data_root.exists() and path.exists():
|
|
922
1114
|
shutil.rmtree(path)
|
|
923
|
-
|
|
924
|
-
|
|
1115
|
+
terminal.step(tr("Clipen 已移除", "Clipen removed"))
|
|
1116
|
+
terminal.outro(tr("作品資料與所有毛片均已保留。", "Your projects and all your footage are kept."))
|
|
925
1117
|
return True
|
|
926
1118
|
|
|
927
1119
|
|
|
928
1120
|
def _print_usage(stream: TextIO, repo_root: Path | None = None) -> None:
|
|
1121
|
+
"""What `clipen` can do, in the frame the installer draws: the logo, how to start, the other commands."""
|
|
929
1122
|
npm = repo_root is not None and (repo_root / ".clipen-npm").is_file()
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
1123
|
+
terminal = Terminal(stream)
|
|
1124
|
+
terminal.logo(tr(f"v{__version__} · AI 剪輯工作台", f"v{__version__} · AI video editing studio"))
|
|
1125
|
+
terminal.intro(f"Clipen {__version__}")
|
|
1126
|
+
|
|
1127
|
+
start = [
|
|
1128
|
+
("clipen claude", tr("用 Claude Code 開啟", "Open with Claude Code")),
|
|
1129
|
+
("clipen codex", tr("用 Codex 開啟", "Open with Codex")),
|
|
1130
|
+
]
|
|
1131
|
+
other = [
|
|
1132
|
+
*([] if npm else [("clipen install", tr("安裝", "Install"))]),
|
|
1133
|
+
("clipen update", tr("更新到最新版", "Update to the latest version")),
|
|
1134
|
+
("clipen language", tr("介面語言:en、zh-TW 或 auto", "Language: en, zh-TW or auto")),
|
|
1135
|
+
("clipen uninstall", tr("移除 Clipen,作品資料保留", "Remove Clipen; projects are kept")),
|
|
1136
|
+
]
|
|
1137
|
+
hint = tr(
|
|
1138
|
+
"在放毛片的資料夾裡執行,Clipen 會在瀏覽器打開。", "Run it in your footage folder; Clipen opens in the browser."
|
|
1139
|
+
)
|
|
1140
|
+
# One column for every command and one width for both boxes, so the two read as one list.
|
|
1141
|
+
width = max(len(name) for name, _ in start + other)
|
|
1142
|
+
inner = max([display_width(hint)] + [width + 2 + display_width(summary) for _, summary in start + other])
|
|
1143
|
+
|
|
1144
|
+
def rows(commands: Sequence[tuple[str, str]]) -> list[str]:
|
|
1145
|
+
return [
|
|
1146
|
+
f"{terminal.brand(name.ljust(width))} {summary}" + " " * (inner - width - 2 - display_width(summary))
|
|
1147
|
+
for name, summary in commands
|
|
1148
|
+
]
|
|
1149
|
+
|
|
1150
|
+
terminal.note(tr("開始剪片", "Start editing"), rows(start), [hint])
|
|
1151
|
+
terminal.note(tr("其他指令", "Other commands"), rows(other))
|
|
1152
|
+
terminal.outro(
|
|
1153
|
+
terminal.dim(tr("讓 AI 幫你剪影片,再用審片注記修改。", "AI edits your film; you revise it with review notes."))
|
|
1154
|
+
)
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
_NPM_PACKAGE = "@clipen/clipen-cli"
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
def _latest_version() -> str:
|
|
1161
|
+
"""The newest Clipen published on npm."""
|
|
1162
|
+
from urllib.request import Request, urlopen
|
|
1163
|
+
|
|
1164
|
+
request = Request(f"https://registry.npmjs.org/{_NPM_PACKAGE}/latest", headers={"User-Agent": "Clipen"})
|
|
1165
|
+
with urlopen(request, timeout=15) as response:
|
|
1166
|
+
return str(json.load(response)["version"])
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
def _version_key(version: str) -> tuple[int, ...]:
|
|
1170
|
+
return tuple(int(part) for part in re.findall(r"\d+", version.split("-")[0]))
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
def _update(repo_root: Path) -> int:
|
|
1174
|
+
"""`clipen update`: install the newest Clipen from npm, through the same installer npx runs."""
|
|
1175
|
+
terminal = Terminal()
|
|
1176
|
+
terminal.intro(f"Clipen {__version__}")
|
|
1177
|
+
if not (repo_root / ".clipen-npm").is_file():
|
|
1178
|
+
terminal.outro(
|
|
1179
|
+
tr(
|
|
1180
|
+
f"這份 Clipen 是從原始碼安裝的:在 {repo_root} 執行 git pull,再執行 ./clipen install。",
|
|
1181
|
+
f"This Clipen was installed from source: in {repo_root}, run git pull, then ./clipen install.",
|
|
1182
|
+
)
|
|
1183
|
+
)
|
|
1184
|
+
return 0
|
|
1185
|
+
try:
|
|
1186
|
+
with terminal.spinner(tr("正在檢查新版", "Checking for a new version")) as spinner:
|
|
1187
|
+
latest = _latest_version()
|
|
1188
|
+
spinner.done(tr("已檢查新版", "Checked for a new version"))
|
|
1189
|
+
except (OSError, ValueError, KeyError) as error:
|
|
1190
|
+
terminal.error(
|
|
1191
|
+
tr("無法檢查新版,請確認網路後再試。", "Could not check for a new version; check your connection.")
|
|
1192
|
+
)
|
|
1193
|
+
terminal.outro(terminal.dim(str(error)))
|
|
1194
|
+
return 1
|
|
1195
|
+
if _version_key(latest) <= _version_key(__version__):
|
|
1196
|
+
terminal.outro(tr(f"已經是最新版 Clipen {__version__}", f"Clipen {__version__} is the latest version"))
|
|
1197
|
+
return 0
|
|
1198
|
+
npx = shutil.which("npx")
|
|
1199
|
+
if npx is None:
|
|
1200
|
+
terminal.outro(tr("更新需要 Node.js:https://nodejs.org", "Updating needs Node.js: https://nodejs.org"))
|
|
1201
|
+
return 1
|
|
1202
|
+
terminal.outro(tr(f"開始更新到 {latest}…", f"Updating to {latest}…"))
|
|
1203
|
+
return subprocess.run([npx, "--yes", f"{_NPM_PACKAGE}@{latest}", "install"], check=False).returncode
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
def _language(arguments: Sequence[str]) -> int:
|
|
1207
|
+
"""`clipen language` shows the language Clipen speaks; with en, zh-TW or auto it changes it."""
|
|
1208
|
+
terminal = Terminal()
|
|
1209
|
+
if len(arguments) == 2:
|
|
1210
|
+
choice = arguments[1].strip().lower()
|
|
1211
|
+
if choice == "auto":
|
|
1212
|
+
save_language(None)
|
|
1213
|
+
elif normalize(choice):
|
|
1214
|
+
save_language(normalize(choice))
|
|
1215
|
+
else:
|
|
1216
|
+
Terminal(sys.stderr).error(tr("請選 en、zh-TW 或 auto", "Choose en, zh-TW or auto"))
|
|
1217
|
+
return 2
|
|
1218
|
+
with speaking(system_language()):
|
|
1219
|
+
names = {"en": "English", "zh-TW": "繁體中文"}
|
|
1220
|
+
chosen = saved_language()
|
|
1221
|
+
terminal.step(
|
|
1222
|
+
tr(f"Clipen 使用 {names[current()]}", f"Clipen speaks {names[current()]}")
|
|
1223
|
+
+ terminal.dim(
|
|
1224
|
+
tr("(手動設定)", " (set by you)") if chosen else tr("(跟著系統)", " (following the system)")
|
|
1225
|
+
)
|
|
1226
|
+
)
|
|
1227
|
+
return 0
|
|
933
1228
|
|
|
934
1229
|
|
|
935
1230
|
def main(repo_root: Path, arguments: Sequence[str]) -> int:
|
|
936
|
-
if
|
|
1231
|
+
if arguments and arguments[0] == "language" and len(arguments) <= 2:
|
|
1232
|
+
return _language(arguments)
|
|
1233
|
+
# The installer speaks the language of the Mac, or the one chosen with `clipen language`.
|
|
1234
|
+
with speaking(system_language()):
|
|
1235
|
+
return _main(repo_root, arguments)
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
def _main(repo_root: Path, arguments: Sequence[str]) -> int:
|
|
1239
|
+
if list(arguments) in ([], ["--help"], ["-h"]):
|
|
937
1240
|
_print_usage(sys.stdout, repo_root)
|
|
938
1241
|
return 0
|
|
939
1242
|
from clipen.provider_registry import PROVIDERS
|
|
940
1243
|
|
|
1244
|
+
if list(arguments) == ["update"]:
|
|
1245
|
+
return _update(repo_root)
|
|
941
1246
|
launch = len(arguments) == 1 and arguments[0] in PROVIDERS
|
|
942
1247
|
if list(arguments) not in (["install"], ["uninstall"]) and not launch:
|
|
943
|
-
|
|
1248
|
+
terminal = Terminal(sys.stderr)
|
|
1249
|
+
terminal.write(
|
|
1250
|
+
f"{terminal.paint('31', '✗')} {tr('沒有這個指令:', 'No such command: ')}{terminal.bold(' '.join(arguments))}"
|
|
1251
|
+
)
|
|
1252
|
+
terminal.write(terminal.dim(tr("執行 clipen 查看可用指令。", "Run clipen to see the commands.")))
|
|
944
1253
|
return 2
|
|
945
1254
|
try:
|
|
946
1255
|
_require_posix_file_locking()
|
|
947
1256
|
if list(arguments) == ["install"]:
|
|
1257
|
+
terminal = Terminal()
|
|
1258
|
+
# Installed through npx, the launcher has already drawn the logo and opened the frame.
|
|
1259
|
+
if not os.environ.get(FRAME_OPEN):
|
|
1260
|
+
terminal.logo(tr(f"v{__version__} · AI 剪輯工作台", f"v{__version__} · AI video editing studio"))
|
|
1261
|
+
terminal.intro(f"Clipen {__version__}")
|
|
948
1262
|
ensure_web_build(repo_root)
|
|
949
1263
|
runtime = ensure_installation(repo_root)
|
|
950
1264
|
if runtime is not None:
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
1265
|
+
terminal.note(
|
|
1266
|
+
tr("安裝完成,接下來這樣開始", "Installed. Here is how to start"),
|
|
1267
|
+
[
|
|
1268
|
+
tr(
|
|
1269
|
+
f"{terminal.brand('1')} 開一個新的 Terminal 視窗",
|
|
1270
|
+
f"{terminal.brand('1')} Open a new Terminal window",
|
|
1271
|
+
),
|
|
1272
|
+
tr(
|
|
1273
|
+
f"{terminal.brand('2')} cd 到你想放作品的資料夾",
|
|
1274
|
+
f"{terminal.brand('2')} cd to the folder for your projects",
|
|
1275
|
+
),
|
|
1276
|
+
tr(
|
|
1277
|
+
f"{terminal.brand('3')} 輸入 {terminal.bold('clipen codex')}",
|
|
1278
|
+
f"{terminal.brand('3')} Type {terminal.bold('clipen codex')}",
|
|
1279
|
+
),
|
|
1280
|
+
],
|
|
1281
|
+
)
|
|
1282
|
+
terminal.outro(
|
|
1283
|
+
terminal.dim(tr("想改用 Claude Code?輸入 clipen claude", "Prefer Claude Code? Type clipen claude"))
|
|
1284
|
+
)
|
|
957
1285
|
return 0
|
|
958
1286
|
if list(arguments) == ["uninstall"]:
|
|
959
1287
|
uninstall_installation()
|
|
@@ -961,22 +1289,26 @@ def main(repo_root: Path, arguments: Sequence[str]) -> int:
|
|
|
961
1289
|
ensure_web_build(repo_root)
|
|
962
1290
|
runtime = completed_runtime(repo_root)
|
|
963
1291
|
except KeyboardInterrupt:
|
|
964
|
-
|
|
965
|
-
|
|
1292
|
+
removing = list(arguments) == ["uninstall"]
|
|
1293
|
+
Terminal(sys.stderr).error(
|
|
1294
|
+
tr(
|
|
1295
|
+
f"Clipen {'移除' if removing else '設定'}已取消",
|
|
1296
|
+
f"Clipen {'removal' if removing else 'setup'} cancelled",
|
|
1297
|
+
)
|
|
1298
|
+
)
|
|
966
1299
|
return 130
|
|
967
1300
|
except (BootstrapError, OSError, subprocess.SubprocessError) as error:
|
|
968
|
-
action = {
|
|
969
|
-
"
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
print(f"Clipen {action}失敗:{error}", file=sys.stderr)
|
|
1301
|
+
action = {"install": ("安裝", "install"), "uninstall": ("移除", "removal")}.get(
|
|
1302
|
+
list(arguments)[0], ("啟動", "start")
|
|
1303
|
+
)
|
|
1304
|
+
Terminal(sys.stderr).error(tr(f"Clipen {action[0]}失敗:{error}", f"Clipen {action[1]} failed: {error}"))
|
|
973
1305
|
return 1
|
|
974
1306
|
if runtime is None:
|
|
975
1307
|
return 0
|
|
976
1308
|
|
|
977
1309
|
python = runtime_python(runtime)
|
|
978
1310
|
environment = {
|
|
979
|
-
**sealed_environment(os.environ),
|
|
1311
|
+
**own_ffmpeg.on_path(clipen_data_root(), sealed_environment(os.environ)),
|
|
980
1312
|
"CLIPEN_REPO_ROOT": str(repo_root.resolve(strict=True)),
|
|
981
1313
|
}
|
|
982
1314
|
os.execve(
|