@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.
Files changed (46) hide show
  1. package/README.md +5 -4
  2. package/apps/web/dist/assets/{index-CaxEZKLc.css → index-CJ80KHsQ.css} +1 -1
  3. package/apps/web/dist/assets/index-C_4u_hVf.js +16 -0
  4. package/apps/web/dist/index.html +2 -2
  5. package/bin/clipen.js +237 -78
  6. package/package.json +8 -2
  7. package/pyproject.toml +1 -1
  8. package/src/clipen/__init__.py +1 -1
  9. package/src/clipen/analysis/qwen_worker.py +13 -4
  10. package/src/clipen/analysis/setup.py +26 -1
  11. package/src/clipen/analysis/setup_cli.py +59 -10
  12. package/src/clipen/bootstrap.py +411 -176
  13. package/src/clipen/cli.py +40 -15
  14. package/src/clipen/controller/app.py +37 -17
  15. package/src/clipen/controller/server.py +65 -27
  16. package/src/clipen/editing/agent_repository.py +8 -0
  17. package/src/clipen/editing/alignment_setup.py +40 -15
  18. package/src/clipen/editing/change_report.py +17 -0
  19. package/src/clipen/editing/coordinator.py +6 -0
  20. package/src/clipen/editing/evidence_jobs.py +3 -1
  21. package/src/clipen/editing/history_changes.py +56 -27
  22. package/src/clipen/editing/production_catalog.py +3 -3
  23. package/src/clipen/editing/production_media.py +18 -0
  24. package/src/clipen/editing/production_progress.py +46 -3
  25. package/src/clipen/editing/production_tools.py +3 -1
  26. package/src/clipen/editing/versions.py +53 -10
  27. package/src/clipen/finishing/audio.py +59 -45
  28. package/src/clipen/i18n.py +155 -0
  29. package/src/clipen/locale_en.py +528 -0
  30. package/src/clipen/mcp_editing/__main__.py +8 -0
  31. package/src/clipen/own_python.py +43 -0
  32. package/src/clipen/projects/models.py +16 -1
  33. package/src/clipen/projects/picker.py +3 -1
  34. package/src/clipen/projects/storage.py +17 -1
  35. package/src/clipen/providers/claude_editing.py +3 -1
  36. package/src/clipen/providers/codex_editing.py +3 -1
  37. package/src/clipen/providers/editing_agent.py +36 -1
  38. package/src/clipen/providers/liveness.py +39 -0
  39. package/src/clipen/rendering/custom_components.py +104 -2
  40. package/src/clipen/rendering/custom_render.py +45 -0
  41. package/src/clipen/skills/builtin/display.en.json +89 -0
  42. package/src/clipen/skills/builtin/references/graphics.md +1 -2
  43. package/src/clipen/skills/catalog.py +22 -0
  44. package/src/clipen/terminal.py +344 -0
  45. package/src/clipen/workspace.py +97 -28
  46. package/apps/web/dist/assets/index-C3Zw0WaM.js +0 -14
@@ -0,0 +1,155 @@
1
+ """The language Clipen speaks: Traditional Chinese (``zh-TW``) or English (``en``).
2
+
3
+ Chinese is the source text everywhere. A string shown to people is written ``tr("中文", "English")``
4
+ where it is used; error messages keep their Chinese text and find their English in
5
+ :mod:`clipen.locale_en`, keyed by that text, so a raise site needs no change.
6
+
7
+ Each command line entry point speaks the system language for its run: ``CLIPEN_LANG``, then the
8
+ choice saved with ``clipen language``, then the Mac's preferred language, then ``LANG``. Each
9
+ browser request names its own language (``X-Clipen-Locale``), so the page and the terminal may
10
+ differ. The AI's attempt inherits the language of the request that started it through
11
+ ``CLIPEN_LANG``.
12
+
13
+ Standard library only: the installer reads it before any dependency exists.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ import os
20
+ import subprocess
21
+ import sys
22
+ from contextlib import contextmanager
23
+ from contextvars import ContextVar
24
+ from pathlib import Path
25
+ from typing import Iterator
26
+
27
+ LOCALES = ("zh-TW", "en")
28
+ ENVIRONMENT = "CLIPEN_LANG"
29
+ _SETTINGS = "settings.json"
30
+
31
+
32
+ def normalize(value: object) -> str | None:
33
+ """``zh``, ``zh_TW.UTF-8``, ``zh-Hant-TW`` and the like read as zh-TW; ``en…`` as en."""
34
+ if not isinstance(value, str):
35
+ return None
36
+ lower = value.strip().lower().replace("_", "-")
37
+ if lower.startswith("zh"):
38
+ return "zh-TW"
39
+ if lower.startswith("en"):
40
+ return "en"
41
+ return None
42
+
43
+
44
+ def data_root() -> Path:
45
+ if sys.platform == "darwin":
46
+ return Path.home() / "Library" / "Application Support" / "Clipen"
47
+ xdg_data = os.environ.get("XDG_DATA_HOME")
48
+ return Path(xdg_data) / "clipen" if xdg_data else Path.home() / ".local" / "share" / "clipen"
49
+
50
+
51
+ def saved_language(root: Path | None = None) -> str | None:
52
+ """The language saved with ``clipen language``; None means follow the system."""
53
+ try:
54
+ value = json.loads((root or data_root()).joinpath(_SETTINGS).read_text(encoding="utf-8"))
55
+ except (OSError, ValueError):
56
+ return None
57
+ return normalize(value.get("language")) if isinstance(value, dict) else None
58
+
59
+
60
+ def save_language(language: str | None, root: Path | None = None) -> None:
61
+ """Save a language, or None to follow the system again."""
62
+ folder = root or data_root()
63
+ path = folder / _SETTINGS
64
+ try:
65
+ settings = json.loads(path.read_text(encoding="utf-8"))
66
+ except (OSError, ValueError):
67
+ settings = {}
68
+ if not isinstance(settings, dict):
69
+ settings = {}
70
+ if language is None:
71
+ settings.pop("language", None)
72
+ else:
73
+ settings["language"] = language
74
+ folder.mkdir(mode=0o700, parents=True, exist_ok=True)
75
+ staging = path.with_name(path.name + ".tmp")
76
+ staging.write_text(json.dumps(settings, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
77
+ os.replace(staging, path)
78
+
79
+
80
+ def _mac_language() -> str | None:
81
+ if sys.platform != "darwin":
82
+ return None
83
+ try:
84
+ result = subprocess.run(
85
+ ["/usr/bin/defaults", "read", "-g", "AppleLanguages"],
86
+ capture_output=True,
87
+ text=True,
88
+ timeout=2,
89
+ check=False,
90
+ )
91
+ except (OSError, subprocess.SubprocessError):
92
+ return None
93
+ # The list prints as ( "en-TW", "zh-Hant-TW" ); the first one Clipen speaks wins.
94
+ for entry in result.stdout.replace("(", " ").replace(")", " ").split(","):
95
+ found = normalize(entry.strip().strip('"'))
96
+ if found:
97
+ return found
98
+ return None
99
+
100
+
101
+ def system_language() -> str:
102
+ """The language this process speaks when nothing more specific asks for one."""
103
+ for value in (os.environ.get(ENVIRONMENT), saved_language()):
104
+ found = normalize(value)
105
+ if found:
106
+ return found
107
+ # A Terminal often says en_US.UTF-8 whatever the person reads, so the Mac's own setting comes first.
108
+ found = _mac_language()
109
+ if found:
110
+ return found
111
+ for name in ("LC_ALL", "LC_MESSAGES", "LANG"):
112
+ found = normalize(os.environ.get(name))
113
+ if found:
114
+ return found
115
+ return "en"
116
+
117
+
118
+ # Chinese unless something asks otherwise: an entry point speaking the system language for its
119
+ # run, or a request naming its own. Library code never guesses, so tests read the same anywhere.
120
+ _current: ContextVar[str] = ContextVar("clipen_locale", default="zh-TW")
121
+
122
+
123
+ def current() -> str:
124
+ return _current.get()
125
+
126
+
127
+ def english() -> bool:
128
+ return current() == "en"
129
+
130
+
131
+ @contextmanager
132
+ def speaking(language: str | None) -> Iterator[None]:
133
+ """Speak this language inside the block (for one request, say); None keeps the current one."""
134
+ token = _current.set(normalize(language) or current())
135
+ try:
136
+ yield
137
+ finally:
138
+ _current.reset(token)
139
+
140
+
141
+ def tr(zh: str, en: str | None = None) -> str:
142
+ """The text in the current language. Without English given, the catalog is asked."""
143
+ if current() != "en":
144
+ return zh
145
+ if en is not None:
146
+ return en
147
+ from clipen.locale_en import MESSAGES, PATTERNS
148
+
149
+ if zh in MESSAGES:
150
+ return MESSAGES[zh]
151
+ for pattern, english_text in PATTERNS:
152
+ found = pattern.fullmatch(zh)
153
+ if found:
154
+ return english_text.format(*found.groups())
155
+ return zh