@clipen/clipen-cli 1.0.6 → 1.0.8
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 +5 -4
- package/apps/web/dist/assets/{index-CaxEZKLc.css → index-CJ80KHsQ.css} +1 -1
- package/apps/web/dist/assets/index-C_4u_hVf.js +16 -0
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +237 -78
- 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 +26 -1
- package/src/clipen/analysis/setup_cli.py +59 -10
- package/src/clipen/bootstrap.py +411 -176
- package/src/clipen/cli.py +40 -15
- package/src/clipen/controller/app.py +37 -17
- package/src/clipen/controller/server.py +65 -27
- package/src/clipen/editing/agent_repository.py +8 -0
- package/src/clipen/editing/alignment_setup.py +40 -15
- package/src/clipen/editing/change_report.py +17 -0
- package/src/clipen/editing/coordinator.py +6 -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 +3 -3
- package/src/clipen/editing/production_media.py +18 -0
- package/src/clipen/editing/production_progress.py +46 -3
- package/src/clipen/editing/production_tools.py +3 -1
- package/src/clipen/editing/versions.py +53 -10
- package/src/clipen/finishing/audio.py +59 -45
- package/src/clipen/i18n.py +155 -0
- package/src/clipen/locale_en.py +528 -0
- package/src/clipen/mcp_editing/__main__.py +8 -0
- package/src/clipen/own_python.py +43 -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 +36 -1
- package/src/clipen/providers/liveness.py +39 -0
- package/src/clipen/rendering/custom_components.py +104 -2
- package/src/clipen/rendering/custom_render.py +45 -0
- package/src/clipen/skills/builtin/display.en.json +89 -0
- package/src/clipen/skills/builtin/references/graphics.md +1 -2
- package/src/clipen/skills/catalog.py +22 -0
- 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/src/clipen/bootstrap.py
CHANGED
|
@@ -20,19 +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__
|
|
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
|
|
33
|
+
from clipen.own_python import sealed_environment
|
|
34
|
+
from clipen.terminal import FRAME_OPEN, Terminal
|
|
36
35
|
|
|
37
36
|
try:
|
|
38
37
|
import fcntl as _fcntl
|
|
@@ -41,6 +40,9 @@ except ImportError: # Windows does not provide POSIX advisory file locks.
|
|
|
41
40
|
|
|
42
41
|
|
|
43
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
|
|
44
46
|
_PIP_VERSION = "26.2.1"
|
|
45
47
|
_SETUPTOOLS_VERSION = "84.0.0"
|
|
46
48
|
_WHEEL_VERSION = "0.48.0"
|
|
@@ -53,9 +55,14 @@ _REMOVABLE_DIRECTORIES = (
|
|
|
53
55
|
"runtime", # Legacy source runtime.
|
|
54
56
|
"runtimes",
|
|
55
57
|
"asr",
|
|
58
|
+
"alignment",
|
|
56
59
|
"models",
|
|
57
60
|
"cache",
|
|
58
61
|
"logs",
|
|
62
|
+
# What `npx @clipen/clipen-cli` set up: Clipen's own Python and its copies of the program. They go
|
|
63
|
+
# last, since the uninstaller itself runs from them.
|
|
64
|
+
"app",
|
|
65
|
+
"python",
|
|
59
66
|
)
|
|
60
67
|
_REMOVABLE_FILES = (
|
|
61
68
|
"setup.json", # Legacy setup receipt.
|
|
@@ -71,7 +78,12 @@ class BootstrapError(RuntimeError):
|
|
|
71
78
|
|
|
72
79
|
def _require_posix_file_locking() -> ModuleType:
|
|
73
80
|
if _fcntl is None:
|
|
74
|
-
raise BootstrapError(
|
|
81
|
+
raise BootstrapError(
|
|
82
|
+
tr(
|
|
83
|
+
"這個開發版本尚不支援 Windows;第一次設定需要 POSIX 檔案鎖",
|
|
84
|
+
"This version does not support Windows yet; first-time setup needs POSIX file locks",
|
|
85
|
+
)
|
|
86
|
+
)
|
|
75
87
|
return _fcntl
|
|
76
88
|
|
|
77
89
|
|
|
@@ -134,6 +146,9 @@ def _runtime_fingerprint(repo_root: Path, *, project_version: bytes | None) -> s
|
|
|
134
146
|
digest = hashlib.sha256()
|
|
135
147
|
digest.update(f"schema={_RUNTIME_SCHEMA}\n".encode())
|
|
136
148
|
digest.update(f"python={sys.version_info.major}.{sys.version_info.minor}\n".encode())
|
|
149
|
+
# The interpreter the runtime is built on: one built on another Python (a person's pyenv or Homebrew)
|
|
150
|
+
# is rebuilt on Clipen's own, so removing theirs can never break Clipen.
|
|
151
|
+
digest.update(f"interpreter={Path(sys.base_prefix).resolve()}\n".encode())
|
|
137
152
|
digest.update(f"platform={platform.system()}-{platform.machine()}\n".encode())
|
|
138
153
|
digest.update(f"repo={repo_root.resolve(strict=True)}\n".encode())
|
|
139
154
|
digest.update(f"bootstrap-tools={_PIP_VERSION},{_SETUPTOOLS_VERSION},{_WHEEL_VERSION}\n".encode())
|
|
@@ -144,7 +159,9 @@ def _runtime_fingerprint(repo_root: Path, *, project_version: bytes | None) -> s
|
|
|
144
159
|
):
|
|
145
160
|
path = repo_root / relative
|
|
146
161
|
if not path.is_file() or path.is_symlink():
|
|
147
|
-
raise BootstrapError(
|
|
162
|
+
raise BootstrapError(
|
|
163
|
+
tr(f"缺少必要的 runtime 定義:{relative}", f"A required runtime definition is missing: {relative}")
|
|
164
|
+
)
|
|
148
165
|
digest.update(relative.encode())
|
|
149
166
|
contents = path.read_bytes()
|
|
150
167
|
if relative == "pyproject.toml" and project_version is not None:
|
|
@@ -213,7 +230,6 @@ def _ready_runtime(root: Path, fingerprint: str, repo_root: Path) -> Path | None
|
|
|
213
230
|
|
|
214
231
|
|
|
215
232
|
def _confirm_setup(
|
|
216
|
-
runtime: Path,
|
|
217
233
|
stdin: TextIO,
|
|
218
234
|
stdout: TextIO,
|
|
219
235
|
*,
|
|
@@ -222,47 +238,50 @@ def _confirm_setup(
|
|
|
222
238
|
asr_root: Path | None = None,
|
|
223
239
|
include_runtime: bool = True,
|
|
224
240
|
) -> bool:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if include_runtime
|
|
228
|
-
print(" • Clipen 專用 Python 虛擬環境", file=stdout)
|
|
229
|
-
print(" • 鎖定版本的本機 Controller 與安全驗證套件", file=stdout)
|
|
230
|
-
if asr_root is not None:
|
|
231
|
-
print(" • 隔離的本機語音辨識執行環境", file=stdout)
|
|
232
|
-
print(f" • 固定版本 {MODEL_NAME} 模型", file=stdout)
|
|
233
|
-
if command_path is not None and profile_path is not None:
|
|
234
|
-
print(f" • `clipen` 指令:{command_path}", file=stdout)
|
|
235
|
-
print(f" • 將 Clipen 加入 PATH:{profile_path}", file=stdout)
|
|
241
|
+
"""One short screen: how much is downloaded, how long it takes, and what changes on the Mac."""
|
|
242
|
+
terminal = Terminal(stdout)
|
|
243
|
+
download = (_RUNTIME_DOWNLOAD_BYTES if include_runtime else 0) + (DOWNLOAD_BYTES if asr_root is not None else 0)
|
|
236
244
|
if not _chrome_ready(Path.home()):
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
print(f"Clipen runtime:{runtime}", file=stdout)
|
|
245
|
+
download += _CHROMIUM_DOWNLOAD_BYTES
|
|
246
|
+
lines = [tr(f"需要下載約 {terminal.bold(_size(download))}", f"Downloads about {terminal.bold(_size(download))}")]
|
|
240
247
|
if asr_root is not None:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
file=stdout,
|
|
248
|
+
lines[0] += tr("(大部分是語音辨識模型)", " (mostly the speech recognition model)")
|
|
249
|
+
lines.append(tr("依網路速度大約 5–15 分鐘", "About 5–15 minutes, depending on your connection"))
|
|
250
|
+
if command_path is not None and profile_path is not None:
|
|
251
|
+
lines.append(
|
|
252
|
+
tr(
|
|
253
|
+
f"會新增 {terminal.bold('clipen')} 指令,之後直接輸入 clipen codex 就能開始",
|
|
254
|
+
f"Adds the {terminal.bold('clipen')} command; afterwards just type clipen codex to start",
|
|
255
|
+
)
|
|
250
256
|
)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
257
|
+
fine_print = [tr("不會動到你原本的 Python,也不需要 sudo", "Leaves your own Python alone and needs no sudo")]
|
|
258
|
+
if asr_root is not None:
|
|
259
|
+
fine_print.insert(
|
|
260
|
+
0,
|
|
261
|
+
tr(
|
|
262
|
+
f"語音辨識模型 {MODEL_NAME} 採 Apache-2.0,執行程式 MLX Speech 採 {ASR_SOFTWARE_LICENSE}",
|
|
263
|
+
f"Speech model {MODEL_NAME} is Apache-2.0; the MLX Speech runtime is {ASR_SOFTWARE_LICENSE}",
|
|
264
|
+
),
|
|
255
265
|
)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
266
|
+
terminal.note(
|
|
267
|
+
tr("安裝 Clipen", "Install Clipen")
|
|
268
|
+
if include_runtime
|
|
269
|
+
else tr("Clipen 需要完成設定", "Clipen needs to finish setting up"),
|
|
270
|
+
lines,
|
|
271
|
+
fine_print,
|
|
272
|
+
)
|
|
260
273
|
if not stdin.isatty():
|
|
261
|
-
raise BootstrapError(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
274
|
+
raise BootstrapError(
|
|
275
|
+
tr(
|
|
276
|
+
"第一次設定需要在互動式 Terminal 中確認。",
|
|
277
|
+
"First-time setup needs confirming in an interactive Terminal.",
|
|
278
|
+
)
|
|
279
|
+
)
|
|
280
|
+
return terminal.confirm(tr("開始安裝?", "Start the install?"), stdin)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _size(count: int) -> str:
|
|
284
|
+
return f"{count / 1_000_000_000:.1f} GB" if count >= 1_000_000_000 else f"{round(count / 1_000_000)} MB"
|
|
266
285
|
|
|
267
286
|
|
|
268
287
|
# What the web UI is built from, inside apps/web.
|
|
@@ -291,13 +310,18 @@ def ensure_web_build(repo_root: Path, stream: TextIO = sys.stdout) -> None:
|
|
|
291
310
|
return
|
|
292
311
|
npm = shutil.which("npm")
|
|
293
312
|
if npm is None:
|
|
294
|
-
raise BootstrapError(
|
|
295
|
-
|
|
313
|
+
raise BootstrapError(
|
|
314
|
+
tr(
|
|
315
|
+
"從原始碼執行 Clipen 需要 Node.js 18 以上來建立操作介面:https://nodejs.org",
|
|
316
|
+
"Running Clipen from source needs Node.js 18 or later to build the interface: https://nodejs.org",
|
|
317
|
+
)
|
|
318
|
+
)
|
|
296
319
|
quiet = {"cwd": web, "check": True, "stdout": subprocess.DEVNULL}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
320
|
+
with Terminal(stream).spinner(tr("正在建立 Clipen 操作介面", "Building the Clipen interface")) as spinner:
|
|
321
|
+
if not (web / "node_modules").is_dir():
|
|
322
|
+
subprocess.run([npm, "ci", "--no-audit", "--no-fund"], **quiet)
|
|
323
|
+
subprocess.run([npm, "run", "build"], **quiet)
|
|
324
|
+
spinner.done(tr("操作介面建立完成", "Interface built"))
|
|
301
325
|
|
|
302
326
|
|
|
303
327
|
def _install_hint(repo_root: Path) -> str:
|
|
@@ -314,21 +338,31 @@ def _chrome_ready(home: Path) -> bool:
|
|
|
314
338
|
def _ensure_chrome(runtime: Path, data_root: Path, home: Path, stdout: TextIO) -> None:
|
|
315
339
|
if _chrome_ready(home):
|
|
316
340
|
return
|
|
317
|
-
print("這台 Mac 沒有 Google Chrome;正在下載 Clipen 畫元件用的 Chromium(約 150 MB)…", file=stdout)
|
|
318
341
|
log_root = data_root / "logs"
|
|
319
342
|
log_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
320
|
-
with (
|
|
343
|
+
with (
|
|
344
|
+
Terminal(stdout).spinner(
|
|
345
|
+
tr("正在下載繪製畫面用的瀏覽器(Chromium)", "Downloading the browser used to draw graphics (Chromium)")
|
|
346
|
+
) as spinner,
|
|
347
|
+
(log_root / "bootstrap-chromium.log").open("w", encoding="utf-8") as log,
|
|
348
|
+
):
|
|
321
349
|
_run_logged((str(runtime_python(runtime)), "-m", "playwright", "install", "chromium"), cwd=runtime, log=log)
|
|
322
|
-
|
|
350
|
+
spinner.done(tr("瀏覽器就緒", "Browser ready"))
|
|
323
351
|
|
|
324
352
|
|
|
325
353
|
def _command_script(repo_root: Path) -> str:
|
|
326
354
|
launcher = repo_root.resolve(strict=True) / "clipen"
|
|
327
355
|
if launcher.is_symlink() or not launcher.is_file() or not os.access(launcher, os.X_OK):
|
|
328
|
-
raise BootstrapError(
|
|
356
|
+
raise BootstrapError(
|
|
357
|
+
tr(
|
|
358
|
+
"Repo 內的 clipen launcher 不存在或不可執行",
|
|
359
|
+
"The clipen launcher in the repository is missing or not executable",
|
|
360
|
+
)
|
|
361
|
+
)
|
|
329
362
|
# Run the launcher with the Python that set Clipen up: a Mac's own python3 is too old.
|
|
330
363
|
python = Path(sys.executable).resolve()
|
|
331
|
-
|
|
364
|
+
# -I: the person's PYTHONPATH, PYTHONHOME and user site never reach Clipen's Python.
|
|
365
|
+
return f'#!/bin/sh\n{_COMMAND_MARKER}\nexec {shlex.quote(str(python))} -I {shlex.quote(str(launcher))} "$@"\n'
|
|
332
366
|
|
|
333
367
|
|
|
334
368
|
def _shell_profile(home: Path, environment: Mapping[str, str]) -> Path:
|
|
@@ -337,7 +371,12 @@ def _shell_profile(home: Path, environment: Mapping[str, str]) -> Path:
|
|
|
337
371
|
return home / ".zshrc"
|
|
338
372
|
if shell == "bash":
|
|
339
373
|
return home / (".bash_profile" if sys.platform == "darwin" else ".bashrc")
|
|
340
|
-
raise BootstrapError(
|
|
374
|
+
raise BootstrapError(
|
|
375
|
+
tr(
|
|
376
|
+
"目前只能自動設定 zsh 或 bash;請將 Clipen 的 bin 目錄手動加入 PATH",
|
|
377
|
+
"Only zsh and bash can be set up automatically; add Clipen's bin folder to PATH yourself",
|
|
378
|
+
)
|
|
379
|
+
)
|
|
341
380
|
|
|
342
381
|
|
|
343
382
|
def _profile_block(bin_root: Path) -> str:
|
|
@@ -346,11 +385,21 @@ def _profile_block(bin_root: Path) -> str:
|
|
|
346
385
|
|
|
347
386
|
def _replace_profile_block(contents: str, block: str) -> str:
|
|
348
387
|
if contents.count(_PROFILE_START) > 1 or contents.count(_PROFILE_END) > 1:
|
|
349
|
-
raise BootstrapError(
|
|
388
|
+
raise BootstrapError(
|
|
389
|
+
tr(
|
|
390
|
+
"shell 設定中有重複的 Clipen PATH 區塊,請先保留並回報問題",
|
|
391
|
+
"Your shell settings have a duplicate Clipen PATH block; keep it and report the problem",
|
|
392
|
+
)
|
|
393
|
+
)
|
|
350
394
|
start = contents.find(_PROFILE_START)
|
|
351
395
|
end = contents.find(_PROFILE_END)
|
|
352
396
|
if (start < 0) != (end < 0) or (start >= 0 and end < start):
|
|
353
|
-
raise BootstrapError(
|
|
397
|
+
raise BootstrapError(
|
|
398
|
+
tr(
|
|
399
|
+
"shell 設定中的 Clipen PATH 區塊不完整,請先保留並回報問題",
|
|
400
|
+
"The Clipen PATH block in your shell settings is incomplete; keep it and report the problem",
|
|
401
|
+
)
|
|
402
|
+
)
|
|
354
403
|
if start >= 0:
|
|
355
404
|
end += len(_PROFILE_END)
|
|
356
405
|
updated = contents[:start] + block + contents[end:]
|
|
@@ -362,11 +411,21 @@ def _replace_profile_block(contents: str, block: str) -> str:
|
|
|
362
411
|
|
|
363
412
|
def _remove_profile_block(contents: str) -> str:
|
|
364
413
|
if contents.count(_PROFILE_START) > 1 or contents.count(_PROFILE_END) > 1:
|
|
365
|
-
raise BootstrapError(
|
|
414
|
+
raise BootstrapError(
|
|
415
|
+
tr(
|
|
416
|
+
"shell 設定中有重複的 Clipen PATH 區塊,未進行移除",
|
|
417
|
+
"Your shell settings have a duplicate Clipen PATH block, so nothing was removed",
|
|
418
|
+
)
|
|
419
|
+
)
|
|
366
420
|
start = contents.find(_PROFILE_START)
|
|
367
421
|
end = contents.find(_PROFILE_END)
|
|
368
422
|
if (start < 0) != (end < 0) or (start >= 0 and end < start):
|
|
369
|
-
raise BootstrapError(
|
|
423
|
+
raise BootstrapError(
|
|
424
|
+
tr(
|
|
425
|
+
"shell 設定中的 Clipen PATH 區塊不完整,未進行移除",
|
|
426
|
+
"The Clipen PATH block in your shell settings is incomplete, so nothing was removed",
|
|
427
|
+
)
|
|
428
|
+
)
|
|
370
429
|
if start < 0:
|
|
371
430
|
return contents
|
|
372
431
|
end += len(_PROFILE_END)
|
|
@@ -399,28 +458,44 @@ def _install_command(
|
|
|
399
458
|
) -> tuple[Path, Path]:
|
|
400
459
|
bin_root = data_root / "bin"
|
|
401
460
|
if bin_root.exists() and (bin_root.is_symlink() or not bin_root.is_dir()):
|
|
402
|
-
raise BootstrapError("Clipen bin 目錄不是安全的實體目錄")
|
|
461
|
+
raise BootstrapError(tr("Clipen bin 目錄不是安全的實體目錄", "Clipen's bin folder is not a safe, real folder"))
|
|
403
462
|
bin_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
404
463
|
command_path = bin_root / "clipen"
|
|
405
464
|
script = _command_script(repo_root)
|
|
406
465
|
if command_path.exists() or command_path.is_symlink():
|
|
407
466
|
if command_path.is_symlink() or not command_path.is_file():
|
|
408
|
-
raise BootstrapError(
|
|
467
|
+
raise BootstrapError(
|
|
468
|
+
tr("Clipen 指令位置已被不安全的檔案占用", "An unsafe file is in the way of the clipen command")
|
|
469
|
+
)
|
|
409
470
|
try:
|
|
410
471
|
existing_command = command_path.read_text(encoding="utf-8")
|
|
411
472
|
except (OSError, UnicodeError) as error:
|
|
412
|
-
raise BootstrapError(
|
|
473
|
+
raise BootstrapError(
|
|
474
|
+
tr("無法安全讀取既有的 Clipen 指令", "The existing clipen command cannot be read safely")
|
|
475
|
+
) from error
|
|
413
476
|
if _COMMAND_MARKER not in existing_command:
|
|
414
|
-
raise BootstrapError(
|
|
477
|
+
raise BootstrapError(
|
|
478
|
+
tr(
|
|
479
|
+
"Clipen 指令位置已有其他程式,未進行覆寫",
|
|
480
|
+
"Another program already uses the clipen command, so it was not overwritten",
|
|
481
|
+
)
|
|
482
|
+
)
|
|
415
483
|
|
|
416
484
|
profile_path = _shell_profile(home, environment)
|
|
417
485
|
if profile_path.exists() or profile_path.is_symlink():
|
|
418
486
|
if profile_path.is_symlink() or not profile_path.is_file():
|
|
419
|
-
raise BootstrapError(
|
|
487
|
+
raise BootstrapError(
|
|
488
|
+
tr(
|
|
489
|
+
"shell 設定檔不是安全的實體檔案,未進行修改",
|
|
490
|
+
"Your shell settings file is not a safe, real file, so it was not changed",
|
|
491
|
+
)
|
|
492
|
+
)
|
|
420
493
|
try:
|
|
421
494
|
profile = profile_path.read_text(encoding="utf-8")
|
|
422
495
|
except (OSError, UnicodeError) as error:
|
|
423
|
-
raise BootstrapError(
|
|
496
|
+
raise BootstrapError(
|
|
497
|
+
tr("無法安全讀取 shell 設定檔", "Your shell settings file cannot be read safely")
|
|
498
|
+
) from error
|
|
424
499
|
profile_mode = stat.S_IMODE(profile_path.stat().st_mode)
|
|
425
500
|
else:
|
|
426
501
|
profile = ""
|
|
@@ -475,21 +550,22 @@ def _run_logged(command: Sequence[str], *, cwd: Path, log: TextIO) -> None:
|
|
|
475
550
|
stderr=subprocess.STDOUT,
|
|
476
551
|
check=False,
|
|
477
552
|
timeout=15 * 60,
|
|
478
|
-
env=
|
|
479
|
-
**os.environ,
|
|
480
|
-
"PIP_DISABLE_PIP_VERSION_CHECK": "1",
|
|
481
|
-
"PYTHONNOUSERSITE": "1",
|
|
482
|
-
},
|
|
553
|
+
env=sealed_environment(os.environ),
|
|
483
554
|
)
|
|
484
555
|
if completed.returncode != 0:
|
|
485
|
-
raise BootstrapError(
|
|
556
|
+
raise BootstrapError(
|
|
557
|
+
tr(
|
|
558
|
+
f"runtime 安裝命令失敗(結束代碼 {completed.returncode})",
|
|
559
|
+
f"The runtime install command failed (exit code {completed.returncode})",
|
|
560
|
+
)
|
|
561
|
+
)
|
|
486
562
|
|
|
487
563
|
|
|
488
564
|
def _install_runtime(staging: Path, repo_root: Path, fingerprint: str, log_path: Path) -> None:
|
|
489
565
|
venv.EnvBuilder(with_pip=True, clear=False, symlinks=False).create(staging)
|
|
490
566
|
python = runtime_python(staging)
|
|
491
567
|
if not python.is_file():
|
|
492
|
-
raise BootstrapError("無法建立 Clipen Python runtime")
|
|
568
|
+
raise BootstrapError(tr("無法建立 Clipen Python runtime", "Could not create Clipen's Python runtime"))
|
|
493
569
|
|
|
494
570
|
with log_path.open("w", encoding="utf-8") as log:
|
|
495
571
|
_run_logged(
|
|
@@ -563,8 +639,9 @@ def _install_asr_bundle(
|
|
|
563
639
|
)
|
|
564
640
|
captured = 0
|
|
565
641
|
process: subprocess.Popen[str] | None = None
|
|
642
|
+
terminal = Terminal(stdout)
|
|
566
643
|
progress_active = False
|
|
567
|
-
|
|
644
|
+
frame = 0
|
|
568
645
|
try:
|
|
569
646
|
with log_path.open("w", encoding="utf-8") as log:
|
|
570
647
|
process = subprocess.Popen(
|
|
@@ -578,8 +655,7 @@ def _install_asr_bundle(
|
|
|
578
655
|
errors="replace",
|
|
579
656
|
bufsize=1,
|
|
580
657
|
env={
|
|
581
|
-
**os.environ,
|
|
582
|
-
"PYTHONNOUSERSITE": "1",
|
|
658
|
+
**sealed_environment(os.environ),
|
|
583
659
|
"CLIPEN_REPO_ROOT": str(repo_root),
|
|
584
660
|
},
|
|
585
661
|
)
|
|
@@ -588,32 +664,33 @@ def _install_asr_bundle(
|
|
|
588
664
|
captured += len(line.encode("utf-8"))
|
|
589
665
|
if captured > 4 * 1024 * 1024:
|
|
590
666
|
process.terminate()
|
|
591
|
-
raise BootstrapError(
|
|
667
|
+
raise BootstrapError(
|
|
668
|
+
tr("語音辨識設定輸出超過安全上限", "The speech recognition setup printed more than allowed")
|
|
669
|
+
)
|
|
592
670
|
is_progress = line.startswith(PROGRESS_RECORD_PREFIX)
|
|
593
671
|
visible_line = line[len(PROGRESS_RECORD_PREFIX) :].rstrip("\r\n") if is_progress else line
|
|
594
672
|
log.write(f"{visible_line}\n" if is_progress else visible_line)
|
|
595
673
|
log.flush()
|
|
596
|
-
if is_progress and
|
|
597
|
-
|
|
598
|
-
stdout.write(f"\r{visible_line}{padding}")
|
|
674
|
+
if is_progress and terminal.live:
|
|
675
|
+
terminal.overwrite(_progress_display(terminal, visible_line, frame))
|
|
599
676
|
progress_active = True
|
|
600
|
-
|
|
677
|
+
frame += 1
|
|
678
|
+
continue
|
|
679
|
+
if progress_active:
|
|
680
|
+
terminal.write()
|
|
681
|
+
progress_active = False
|
|
682
|
+
text = visible_line.rstrip("\r\n")
|
|
683
|
+
if text.startswith("✓ "):
|
|
684
|
+
terminal.step(text[2:])
|
|
601
685
|
else:
|
|
602
|
-
|
|
603
|
-
stdout.write("\n")
|
|
604
|
-
progress_active = False
|
|
605
|
-
progress_width = 0
|
|
606
|
-
stdout.write(f"{visible_line}\n" if is_progress else visible_line)
|
|
607
|
-
stdout.flush()
|
|
608
|
-
returncode = process.wait()
|
|
686
|
+
terminal.write(f"{terminal.paint('90', '│')} {text}")
|
|
609
687
|
if progress_active:
|
|
610
|
-
|
|
611
|
-
stdout.flush()
|
|
688
|
+
terminal.write()
|
|
612
689
|
progress_active = False
|
|
690
|
+
returncode = process.wait()
|
|
613
691
|
except BaseException:
|
|
614
692
|
if progress_active:
|
|
615
|
-
|
|
616
|
-
stdout.flush()
|
|
693
|
+
terminal.write()
|
|
617
694
|
if process is not None and process.poll() is None:
|
|
618
695
|
process.terminate()
|
|
619
696
|
try:
|
|
@@ -623,7 +700,21 @@ def _install_asr_bundle(
|
|
|
623
700
|
process.wait(timeout=5)
|
|
624
701
|
raise
|
|
625
702
|
if returncode != 0:
|
|
626
|
-
raise BootstrapError(
|
|
703
|
+
raise BootstrapError(
|
|
704
|
+
tr(
|
|
705
|
+
f"本機語音辨識設定失敗;診斷紀錄:{log_path}",
|
|
706
|
+
f"Setting up local speech recognition failed; log: {log_path}",
|
|
707
|
+
)
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
def _progress_display(terminal: Terminal, line: str, frame: int) -> str:
|
|
712
|
+
"""The installer's progress record, redrawn with a spinner and the brand-coloured bar."""
|
|
713
|
+
bar = re.match(r"([━─]+) +(\d+)%(.*)", line)
|
|
714
|
+
symbol = terminal.paint("35", "◒◐◓◑"[frame % 4])
|
|
715
|
+
if bar is None:
|
|
716
|
+
return f"{symbol} {line}"
|
|
717
|
+
return f"{symbol} {terminal.progress_bar(int(bar.group(2)), len(bar.group(1)))} {terminal.bold(bar.group(2) + '%')}{bar.group(3)}"
|
|
627
718
|
|
|
628
719
|
|
|
629
720
|
def ensure_runtime(
|
|
@@ -639,7 +730,9 @@ def ensure_runtime(
|
|
|
639
730
|
root = (data_root or clipen_data_root()) / "runtimes"
|
|
640
731
|
root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
641
732
|
if root.is_symlink():
|
|
642
|
-
raise BootstrapError(
|
|
733
|
+
raise BootstrapError(
|
|
734
|
+
tr("Clipen runtime 根目錄不能是 symbolic link", "Clipen's runtime folder cannot be a symbolic link")
|
|
735
|
+
)
|
|
643
736
|
runtime = root / fingerprint
|
|
644
737
|
|
|
645
738
|
with _bootstrap_lock(root):
|
|
@@ -647,25 +740,30 @@ def ensure_runtime(
|
|
|
647
740
|
if ready is not None:
|
|
648
741
|
return ready
|
|
649
742
|
if runtime.exists():
|
|
650
|
-
raise BootstrapError(
|
|
651
|
-
|
|
652
|
-
|
|
743
|
+
raise BootstrapError(
|
|
744
|
+
tr(
|
|
745
|
+
f"Clipen runtime 不完整,請先保留此目錄並回報問題:{runtime}",
|
|
746
|
+
f"Clipen's runtime is incomplete; keep this folder and report the problem: {runtime}",
|
|
747
|
+
)
|
|
748
|
+
)
|
|
749
|
+
if not confirmed and not _confirm_setup(stdin, stdout):
|
|
750
|
+
Terminal(stdout).outro(tr("已取消,沒有建立 Clipen runtime。", "Cancelled; no Clipen runtime was created."))
|
|
653
751
|
return None
|
|
654
752
|
|
|
655
753
|
staging = root / f".{fingerprint}.staging-{uuid.uuid4().hex}"
|
|
656
754
|
log_root = (data_root or clipen_data_root()) / "logs"
|
|
657
755
|
log_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
658
756
|
log_path = log_root / f"bootstrap-{fingerprint}.log"
|
|
659
|
-
print("正在建立 Clipen 執行環境…", file=stdout)
|
|
660
757
|
try:
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
758
|
+
with Terminal(stdout).spinner(tr("正在準備 Clipen 執行環境", "Preparing Clipen's runtime")) as spinner:
|
|
759
|
+
staging.mkdir(mode=0o700)
|
|
760
|
+
_install_runtime(staging, repo_root, fingerprint, log_path)
|
|
761
|
+
staging.rename(runtime)
|
|
762
|
+
spinner.done(tr("執行環境就緒", "Runtime ready"))
|
|
664
763
|
except Exception:
|
|
665
764
|
if staging.exists() and not staging.is_symlink():
|
|
666
765
|
shutil.rmtree(staging)
|
|
667
766
|
raise
|
|
668
|
-
print("✓ Clipen 執行環境建立完成", file=stdout)
|
|
669
767
|
return runtime
|
|
670
768
|
|
|
671
769
|
|
|
@@ -683,7 +781,7 @@ def ensure_installation(
|
|
|
683
781
|
selected_home = home or Path.home()
|
|
684
782
|
selected_environment = environment if environment is not None else os.environ
|
|
685
783
|
if platform.system() != "Darwin" or platform.machine() != "arm64":
|
|
686
|
-
raise BootstrapError("目前完整設定只支援 Apple 晶片的 macOS")
|
|
784
|
+
raise BootstrapError(tr("目前完整設定只支援 Apple 晶片的 macOS", "Full setup supports only Apple silicon Macs"))
|
|
687
785
|
fingerprint = runtime_fingerprint(repo_root)
|
|
688
786
|
ready = _ready_runtime(selected_data_root / "runtimes", fingerprint, repo_root)
|
|
689
787
|
runtime = ready or selected_data_root / "runtimes" / fingerprint
|
|
@@ -696,7 +794,6 @@ def ensure_installation(
|
|
|
696
794
|
command_path = selected_data_root / "bin" / "clipen"
|
|
697
795
|
profile_path = _shell_profile(selected_home, selected_environment)
|
|
698
796
|
if not _confirm_setup(
|
|
699
|
-
runtime,
|
|
700
797
|
stdin,
|
|
701
798
|
stdout,
|
|
702
799
|
command_path=None if command_ready else command_path,
|
|
@@ -704,7 +801,9 @@ def ensure_installation(
|
|
|
704
801
|
asr_root=None if asr_ready else release_root(selected_data_root),
|
|
705
802
|
include_runtime=not runtime_ready,
|
|
706
803
|
):
|
|
707
|
-
|
|
804
|
+
Terminal(stdout).outro(
|
|
805
|
+
tr("已取消,既有 Clipen 資料沒有變動。", "Cancelled; your Clipen data is unchanged.")
|
|
806
|
+
)
|
|
708
807
|
return None
|
|
709
808
|
if not runtime_ready:
|
|
710
809
|
installed_runtime = ensure_runtime(
|
|
@@ -717,13 +816,16 @@ def ensure_installation(
|
|
|
717
816
|
if installed_runtime is None:
|
|
718
817
|
return None
|
|
719
818
|
runtime = installed_runtime
|
|
720
|
-
|
|
819
|
+
# A rebuilt runtime may be on a different Python from the one speech recognition was set up on.
|
|
820
|
+
if not asr_ready or not runtime_ready:
|
|
721
821
|
log_root = selected_data_root / "logs"
|
|
722
822
|
log_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
723
823
|
if log_root.is_symlink():
|
|
724
|
-
raise BootstrapError(
|
|
824
|
+
raise BootstrapError(
|
|
825
|
+
tr("Clipen log 目錄不能是 symbolic link", "Clipen's log folder cannot be a symbolic link")
|
|
826
|
+
)
|
|
725
827
|
asr_log = log_root / f"bootstrap-asr-{fingerprint}.log"
|
|
726
|
-
|
|
828
|
+
Terminal(stdout).write(Terminal(stdout).paint("90", "│"))
|
|
727
829
|
_install_asr_bundle(
|
|
728
830
|
runtime,
|
|
729
831
|
repo_root,
|
|
@@ -732,16 +834,16 @@ def ensure_installation(
|
|
|
732
834
|
stdout,
|
|
733
835
|
)
|
|
734
836
|
if not quick_release_is_ready(selected_data_root, asr_requirements):
|
|
735
|
-
raise BootstrapError(
|
|
837
|
+
raise BootstrapError(
|
|
838
|
+
tr(
|
|
839
|
+
f"語音辨識安裝未通過啟動檢查;診斷紀錄:{asr_log}",
|
|
840
|
+
f"The speech recognition install failed its start-up check; log: {asr_log}",
|
|
841
|
+
)
|
|
842
|
+
)
|
|
736
843
|
_ensure_chrome(runtime, selected_data_root, selected_home, stdout)
|
|
737
844
|
if not command_ready:
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
)
|
|
741
|
-
print(f"✓ 已建立指令:{command_path}", file=stdout)
|
|
742
|
-
print(f"✓ 已更新 PATH:{profile_path}", file=stdout)
|
|
743
|
-
print("下次開啟 Terminal 後可直接輸入:clipen codex(或 clipen claude)", file=stdout)
|
|
744
|
-
print("✓ Clipen 完整設定完成", file=stdout)
|
|
845
|
+
_install_command(repo_root, selected_data_root, selected_home, selected_environment)
|
|
846
|
+
Terminal(stdout).step(tr("已新增 clipen 指令", "Added the clipen command"))
|
|
745
847
|
return runtime
|
|
746
848
|
|
|
747
849
|
if stdin.isatty():
|
|
@@ -750,21 +852,28 @@ def ensure_installation(
|
|
|
750
852
|
if not command_ready:
|
|
751
853
|
if not stdin.isatty():
|
|
752
854
|
return runtime
|
|
753
|
-
|
|
754
|
-
print(f"將建立:{selected_data_root / 'bin' / 'clipen'}", file=stdout)
|
|
855
|
+
terminal = Terminal(stdout)
|
|
755
856
|
profile_path = _shell_profile(selected_home, selected_environment)
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
857
|
+
terminal.note(
|
|
858
|
+
tr("Clipen 需要完成一次指令設定", "Clipen needs to set up its command once"),
|
|
859
|
+
[
|
|
860
|
+
tr(
|
|
861
|
+
f"將建立:{selected_data_root / 'bin' / 'clipen'}",
|
|
862
|
+
f"Creates: {selected_data_root / 'bin' / 'clipen'}",
|
|
863
|
+
),
|
|
864
|
+
tr(f"將更新 PATH:{profile_path}", f"Updates PATH in: {profile_path}"),
|
|
865
|
+
],
|
|
764
866
|
)
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
867
|
+
if not terminal.confirm(tr("完成設定?", "Finish setting up?"), stdin):
|
|
868
|
+
terminal.warn(
|
|
869
|
+
tr(
|
|
870
|
+
f"已略過;可再次執行 {_install_hint(repo_root)} 完成指令設定。",
|
|
871
|
+
f"Skipped; run {_install_hint(repo_root)} again to set up the command.",
|
|
872
|
+
)
|
|
873
|
+
)
|
|
874
|
+
return runtime
|
|
875
|
+
_install_command(repo_root, selected_data_root, selected_home, selected_environment)
|
|
876
|
+
Terminal(stdout).step(tr("已新增 clipen 指令", "Added the clipen command"))
|
|
768
877
|
return runtime
|
|
769
878
|
|
|
770
879
|
|
|
@@ -774,14 +883,17 @@ def completed_runtime(repo_root: Path, *, data_root: Path | None = None) -> Path
|
|
|
774
883
|
repo_root = repo_root.resolve(strict=True)
|
|
775
884
|
selected_data_root = data_root or clipen_data_root()
|
|
776
885
|
if platform.system() != "Darwin" or platform.machine() != "arm64":
|
|
777
|
-
raise BootstrapError("目前只支援 Apple 晶片的 macOS")
|
|
886
|
+
raise BootstrapError(tr("目前只支援 Apple 晶片的 macOS", "Supports only Apple silicon Macs"))
|
|
778
887
|
fingerprint = runtime_fingerprint(repo_root)
|
|
779
888
|
runtime = _ready_runtime(selected_data_root / "runtimes", fingerprint, repo_root)
|
|
780
889
|
requirements = repo_root / "requirements" / "asr-runtime.txt"
|
|
781
890
|
if runtime is None or not quick_release_is_ready(selected_data_root, requirements):
|
|
782
891
|
raise BootstrapError(
|
|
783
|
-
|
|
784
|
-
|
|
892
|
+
tr(
|
|
893
|
+
f"Clipen 尚未完成安裝;第一次請執行 {_install_hint(repo_root)},已有 clipen 指令時可執行 clipen install 修復",
|
|
894
|
+
f"Clipen is not fully installed. The first time, run {_install_hint(repo_root)}; "
|
|
895
|
+
"if you have the clipen command, clipen install repairs it",
|
|
896
|
+
)
|
|
785
897
|
)
|
|
786
898
|
return runtime
|
|
787
899
|
|
|
@@ -795,11 +907,13 @@ def _controller_is_running(data_root: Path) -> bool:
|
|
|
795
907
|
try:
|
|
796
908
|
descriptor = os.open(lock_path, flags)
|
|
797
909
|
except OSError as error:
|
|
798
|
-
raise BootstrapError(
|
|
910
|
+
raise BootstrapError(
|
|
911
|
+
tr("無法安全檢查 Clipen 是否仍在執行", "Cannot safely check whether Clipen is still running")
|
|
912
|
+
) from error
|
|
799
913
|
try:
|
|
800
914
|
info = os.fstat(descriptor)
|
|
801
915
|
if not stat.S_ISREG(info.st_mode):
|
|
802
|
-
raise BootstrapError("Clipen 執行鎖不是安全的實體檔案")
|
|
916
|
+
raise BootstrapError(tr("Clipen 執行鎖不是安全的實體檔案", "Clipen's run lock is not a safe, real file"))
|
|
803
917
|
try:
|
|
804
918
|
locking.flock(descriptor, locking.LOCK_EX | locking.LOCK_NB)
|
|
805
919
|
except BlockingIOError:
|
|
@@ -814,17 +928,28 @@ def _validate_removable_path(path: Path, data_root: Path, *, directory: bool) ->
|
|
|
814
928
|
if not path.exists() and not path.is_symlink():
|
|
815
929
|
return
|
|
816
930
|
if path.is_symlink() or path.parent.resolve(strict=True) != data_root:
|
|
817
|
-
raise BootstrapError(
|
|
931
|
+
raise BootstrapError(
|
|
932
|
+
tr(f"拒絕移除不安全的 Clipen 路徑:{path}", f"Refused to remove an unsafe Clipen path: {path}")
|
|
933
|
+
)
|
|
818
934
|
if directory:
|
|
819
935
|
if not path.is_dir() or path.is_mount():
|
|
820
|
-
raise BootstrapError(
|
|
936
|
+
raise BootstrapError(
|
|
937
|
+
tr(f"拒絕移除非一般目錄:{path}", f"Refused to remove something that is not a plain folder: {path}")
|
|
938
|
+
)
|
|
821
939
|
for current, directories, _files in os.walk(path, followlinks=False):
|
|
822
940
|
for name in directories:
|
|
823
941
|
candidate = Path(current) / name
|
|
824
942
|
if not candidate.is_symlink() and candidate.is_mount():
|
|
825
|
-
raise BootstrapError(
|
|
943
|
+
raise BootstrapError(
|
|
944
|
+
tr(
|
|
945
|
+
f"拒絕移除包含 mount point 的目錄:{candidate}",
|
|
946
|
+
f"Refused to remove a folder containing a mount point: {candidate}",
|
|
947
|
+
)
|
|
948
|
+
)
|
|
826
949
|
elif not path.is_file():
|
|
827
|
-
raise BootstrapError(
|
|
950
|
+
raise BootstrapError(
|
|
951
|
+
tr(f"拒絕移除非一般檔案:{path}", f"Refused to remove something that is not a plain file: {path}")
|
|
952
|
+
)
|
|
828
953
|
|
|
829
954
|
|
|
830
955
|
def uninstall_installation(
|
|
@@ -844,26 +969,47 @@ def uninstall_installation(
|
|
|
844
969
|
bin_root = selected_data_root / "bin"
|
|
845
970
|
command_path = bin_root / "clipen"
|
|
846
971
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
972
|
+
terminal = Terminal(stdout)
|
|
973
|
+
terminal.intro("Clipen")
|
|
974
|
+
terminal.note(
|
|
975
|
+
tr("移除 Clipen", "Remove Clipen"),
|
|
976
|
+
[
|
|
977
|
+
tr(
|
|
978
|
+
f"會移除 Clipen 程式、語音辨識模型和 {terminal.bold('clipen')} 指令",
|
|
979
|
+
f"Removes the Clipen program, the speech model and the {terminal.bold('clipen')} command",
|
|
980
|
+
)
|
|
981
|
+
],
|
|
982
|
+
[
|
|
983
|
+
tr(
|
|
984
|
+
"你的作品、毛片、參考作品和匯出檔都會保留",
|
|
985
|
+
"Your projects, footage, reference work and exports are all kept",
|
|
986
|
+
)
|
|
987
|
+
],
|
|
988
|
+
)
|
|
853
989
|
if not stdin.isatty():
|
|
854
|
-
raise BootstrapError(
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
990
|
+
raise BootstrapError(
|
|
991
|
+
tr(
|
|
992
|
+
"移除 Clipen 需要在互動式 Terminal 中確認",
|
|
993
|
+
"Removing Clipen needs confirming in an interactive Terminal",
|
|
994
|
+
)
|
|
995
|
+
)
|
|
996
|
+
if not terminal.confirm(tr("確定移除?", "Remove it?"), stdin, default=False):
|
|
997
|
+
terminal.outro(tr("已取消,沒有移除任何內容。", "Cancelled; nothing was removed."))
|
|
859
998
|
return False
|
|
860
999
|
|
|
861
1000
|
if selected_data_root.exists() or selected_data_root.is_symlink():
|
|
862
1001
|
if selected_data_root.is_symlink() or not selected_data_root.is_dir():
|
|
863
|
-
raise BootstrapError(
|
|
1002
|
+
raise BootstrapError(
|
|
1003
|
+
tr("Clipen 資料根目錄不安全,未進行移除", "Clipen's data folder is not safe, so nothing was removed")
|
|
1004
|
+
)
|
|
864
1005
|
resolved_data_root = selected_data_root.resolve(strict=True)
|
|
865
1006
|
if _controller_is_running(resolved_data_root):
|
|
866
|
-
raise BootstrapError(
|
|
1007
|
+
raise BootstrapError(
|
|
1008
|
+
tr(
|
|
1009
|
+
"Clipen 仍在執行;請先在啟動它的 Terminal 按 Ctrl+C",
|
|
1010
|
+
"Clipen is still running; press Ctrl+C in the Terminal that started it",
|
|
1011
|
+
)
|
|
1012
|
+
)
|
|
867
1013
|
else:
|
|
868
1014
|
resolved_data_root = selected_data_root
|
|
869
1015
|
|
|
@@ -872,20 +1018,37 @@ def uninstall_installation(
|
|
|
872
1018
|
profile_mode = 0o600
|
|
873
1019
|
if profile_path.exists() or profile_path.is_symlink():
|
|
874
1020
|
if profile_path.is_symlink() or not profile_path.is_file():
|
|
875
|
-
raise BootstrapError(
|
|
1021
|
+
raise BootstrapError(
|
|
1022
|
+
tr(
|
|
1023
|
+
"shell 設定檔不是安全的實體檔案,未進行移除",
|
|
1024
|
+
"Your shell settings file is not a safe, real file, so nothing was removed",
|
|
1025
|
+
)
|
|
1026
|
+
)
|
|
876
1027
|
profile = profile_path.read_text(encoding="utf-8")
|
|
877
1028
|
updated_profile = _remove_profile_block(profile)
|
|
878
1029
|
profile_mode = stat.S_IMODE(profile_path.stat().st_mode)
|
|
879
1030
|
|
|
880
1031
|
if bin_root.exists() or bin_root.is_symlink():
|
|
881
1032
|
if bin_root.is_symlink() or not bin_root.is_dir():
|
|
882
|
-
raise BootstrapError(
|
|
1033
|
+
raise BootstrapError(
|
|
1034
|
+
tr("Clipen bin 目錄不安全,未進行移除", "Clipen's bin folder is not safe, so nothing was removed")
|
|
1035
|
+
)
|
|
883
1036
|
if command_path.exists() or command_path.is_symlink():
|
|
884
1037
|
if command_path.is_symlink() or not command_path.is_file():
|
|
885
|
-
raise BootstrapError(
|
|
1038
|
+
raise BootstrapError(
|
|
1039
|
+
tr(
|
|
1040
|
+
"clipen 指令位置不是安全的實體檔案,未進行移除",
|
|
1041
|
+
"The clipen command is not a safe, real file, so nothing was removed",
|
|
1042
|
+
)
|
|
1043
|
+
)
|
|
886
1044
|
command = command_path.read_text(encoding="utf-8")
|
|
887
1045
|
if not any(line.startswith(_MANAGED_COMMAND_PREFIX) for line in command.splitlines()[:3]):
|
|
888
|
-
raise BootstrapError(
|
|
1046
|
+
raise BootstrapError(
|
|
1047
|
+
tr(
|
|
1048
|
+
"clipen 指令不是由 Clipen 管理,未進行移除",
|
|
1049
|
+
"The clipen command is not managed by Clipen, so nothing was removed",
|
|
1050
|
+
)
|
|
1051
|
+
)
|
|
889
1052
|
|
|
890
1053
|
if selected_data_root.exists():
|
|
891
1054
|
for name in _REMOVABLE_DIRECTORIES:
|
|
@@ -893,10 +1056,11 @@ def uninstall_installation(
|
|
|
893
1056
|
for name in _REMOVABLE_FILES:
|
|
894
1057
|
_validate_removable_path(resolved_data_root / name, resolved_data_root, directory=False)
|
|
895
1058
|
|
|
1059
|
+
program = ("app", "python")
|
|
896
1060
|
if selected_data_root.exists():
|
|
897
1061
|
for name in _REMOVABLE_DIRECTORIES:
|
|
898
1062
|
path = resolved_data_root / name
|
|
899
|
-
if path.exists():
|
|
1063
|
+
if name not in program and path.exists():
|
|
900
1064
|
shutil.rmtree(path)
|
|
901
1065
|
for name in _REMOVABLE_FILES:
|
|
902
1066
|
path = resolved_data_root / name
|
|
@@ -909,19 +1073,68 @@ def uninstall_installation(
|
|
|
909
1073
|
bin_root.rmdir()
|
|
910
1074
|
if updated_profile != profile:
|
|
911
1075
|
_atomic_write(profile_path, updated_profile, profile_mode)
|
|
912
|
-
|
|
913
|
-
|
|
1076
|
+
for name in program:
|
|
1077
|
+
path = resolved_data_root / name
|
|
1078
|
+
if selected_data_root.exists() and path.exists():
|
|
1079
|
+
shutil.rmtree(path)
|
|
1080
|
+
terminal.step(tr("Clipen 已移除", "Clipen removed"))
|
|
1081
|
+
terminal.outro(tr("作品資料與所有毛片均已保留。", "Your projects and all your footage are kept."))
|
|
914
1082
|
return True
|
|
915
1083
|
|
|
916
1084
|
|
|
917
1085
|
def _print_usage(stream: TextIO, repo_root: Path | None = None) -> None:
|
|
918
1086
|
npm = repo_root is not None and (repo_root / ".clipen-npm").is_file()
|
|
919
|
-
print(
|
|
920
|
-
|
|
921
|
-
|
|
1087
|
+
print(
|
|
1088
|
+
tr(
|
|
1089
|
+
f"第一次安裝:{'npx @clipen/clipen-cli' if npm else './clipen install'}",
|
|
1090
|
+
f"First install: {'npx @clipen/clipen-cli' if npm else './clipen install'}",
|
|
1091
|
+
),
|
|
1092
|
+
file=stream,
|
|
1093
|
+
)
|
|
1094
|
+
print(tr("啟動 Clipen:clipen codex 或 clipen claude", "Start Clipen: clipen codex or clipen claude"), file=stream)
|
|
1095
|
+
print(
|
|
1096
|
+
tr(
|
|
1097
|
+
f"移除 Clipen:{'clipen uninstall' if npm else './clipen uninstall'}",
|
|
1098
|
+
f"Remove Clipen: {'clipen uninstall' if npm else './clipen uninstall'}",
|
|
1099
|
+
),
|
|
1100
|
+
file=stream,
|
|
1101
|
+
)
|
|
1102
|
+
print(tr("介面語言:clipen language en|zh-TW|auto", "Language: clipen language en | zh-TW | auto"), file=stream)
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
def _language(arguments: Sequence[str]) -> int:
|
|
1106
|
+
"""`clipen language` shows the language Clipen speaks; with en, zh-TW or auto it changes it."""
|
|
1107
|
+
terminal = Terminal()
|
|
1108
|
+
if len(arguments) == 2:
|
|
1109
|
+
choice = arguments[1].strip().lower()
|
|
1110
|
+
if choice == "auto":
|
|
1111
|
+
save_language(None)
|
|
1112
|
+
elif normalize(choice):
|
|
1113
|
+
save_language(normalize(choice))
|
|
1114
|
+
else:
|
|
1115
|
+
Terminal(sys.stderr).error(tr("請選 en、zh-TW 或 auto", "Choose en, zh-TW or auto"))
|
|
1116
|
+
return 2
|
|
1117
|
+
with speaking(system_language()):
|
|
1118
|
+
names = {"en": "English", "zh-TW": "繁體中文"}
|
|
1119
|
+
chosen = saved_language()
|
|
1120
|
+
terminal.step(
|
|
1121
|
+
tr(f"Clipen 使用 {names[current()]}", f"Clipen speaks {names[current()]}")
|
|
1122
|
+
+ terminal.dim(
|
|
1123
|
+
tr("(手動設定)", " (set by you)") if chosen else tr("(跟著系統)", " (following the system)")
|
|
1124
|
+
)
|
|
1125
|
+
)
|
|
1126
|
+
return 0
|
|
922
1127
|
|
|
923
1128
|
|
|
924
1129
|
def main(repo_root: Path, arguments: Sequence[str]) -> int:
|
|
1130
|
+
if arguments and arguments[0] == "language" and len(arguments) <= 2:
|
|
1131
|
+
return _language(arguments)
|
|
1132
|
+
# The installer speaks the language of the Mac, or the one chosen with `clipen language`.
|
|
1133
|
+
with speaking(system_language()):
|
|
1134
|
+
return _main(repo_root, arguments)
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
def _main(repo_root: Path, arguments: Sequence[str]) -> int:
|
|
925
1138
|
if list(arguments) in (["--help"], ["-h"]):
|
|
926
1139
|
_print_usage(sys.stdout, repo_root)
|
|
927
1140
|
return 0
|
|
@@ -934,15 +1147,34 @@ def main(repo_root: Path, arguments: Sequence[str]) -> int:
|
|
|
934
1147
|
try:
|
|
935
1148
|
_require_posix_file_locking()
|
|
936
1149
|
if list(arguments) == ["install"]:
|
|
1150
|
+
terminal = Terminal()
|
|
1151
|
+
# Installed through npx, the launcher has already drawn the logo and opened the frame.
|
|
1152
|
+
if not os.environ.get(FRAME_OPEN):
|
|
1153
|
+
terminal.logo(tr(f"v{__version__} · AI 剪輯工作台", f"v{__version__} · AI video editing studio"))
|
|
1154
|
+
terminal.intro(f"Clipen {__version__}")
|
|
937
1155
|
ensure_web_build(repo_root)
|
|
938
1156
|
runtime = ensure_installation(repo_root)
|
|
939
1157
|
if runtime is not None:
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
1158
|
+
terminal.note(
|
|
1159
|
+
tr("安裝完成,接下來這樣開始", "Installed. Here is how to start"),
|
|
1160
|
+
[
|
|
1161
|
+
tr(
|
|
1162
|
+
f"{terminal.brand('1')} 開一個新的 Terminal 視窗",
|
|
1163
|
+
f"{terminal.brand('1')} Open a new Terminal window",
|
|
1164
|
+
),
|
|
1165
|
+
tr(
|
|
1166
|
+
f"{terminal.brand('2')} cd 到你想放作品的資料夾",
|
|
1167
|
+
f"{terminal.brand('2')} cd to the folder for your projects",
|
|
1168
|
+
),
|
|
1169
|
+
tr(
|
|
1170
|
+
f"{terminal.brand('3')} 輸入 {terminal.bold('clipen codex')}",
|
|
1171
|
+
f"{terminal.brand('3')} Type {terminal.bold('clipen codex')}",
|
|
1172
|
+
),
|
|
1173
|
+
],
|
|
1174
|
+
)
|
|
1175
|
+
terminal.outro(
|
|
1176
|
+
terminal.dim(tr("想改用 Claude Code?輸入 clipen claude", "Prefer Claude Code? Type clipen claude"))
|
|
1177
|
+
)
|
|
946
1178
|
return 0
|
|
947
1179
|
if list(arguments) == ["uninstall"]:
|
|
948
1180
|
uninstall_installation()
|
|
@@ -950,24 +1182,27 @@ def main(repo_root: Path, arguments: Sequence[str]) -> int:
|
|
|
950
1182
|
ensure_web_build(repo_root)
|
|
951
1183
|
runtime = completed_runtime(repo_root)
|
|
952
1184
|
except KeyboardInterrupt:
|
|
953
|
-
|
|
954
|
-
|
|
1185
|
+
removing = list(arguments) == ["uninstall"]
|
|
1186
|
+
Terminal(sys.stderr).error(
|
|
1187
|
+
tr(
|
|
1188
|
+
f"Clipen {'移除' if removing else '設定'}已取消",
|
|
1189
|
+
f"Clipen {'removal' if removing else 'setup'} cancelled",
|
|
1190
|
+
)
|
|
1191
|
+
)
|
|
955
1192
|
return 130
|
|
956
1193
|
except (BootstrapError, OSError, subprocess.SubprocessError) as error:
|
|
957
|
-
action = {
|
|
958
|
-
"
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
print(f"Clipen {action}失敗:{error}", file=sys.stderr)
|
|
1194
|
+
action = {"install": ("安裝", "install"), "uninstall": ("移除", "removal")}.get(
|
|
1195
|
+
list(arguments)[0], ("啟動", "start")
|
|
1196
|
+
)
|
|
1197
|
+
Terminal(sys.stderr).error(tr(f"Clipen {action[0]}失敗:{error}", f"Clipen {action[1]} failed: {error}"))
|
|
962
1198
|
return 1
|
|
963
1199
|
if runtime is None:
|
|
964
1200
|
return 0
|
|
965
1201
|
|
|
966
1202
|
python = runtime_python(runtime)
|
|
967
1203
|
environment = {
|
|
968
|
-
**os.environ,
|
|
1204
|
+
**sealed_environment(os.environ),
|
|
969
1205
|
"CLIPEN_REPO_ROOT": str(repo_root.resolve(strict=True)),
|
|
970
|
-
"PYTHONNOUSERSITE": "1",
|
|
971
1206
|
}
|
|
972
1207
|
os.execve(
|
|
973
1208
|
python,
|