@clipen/clipen-cli 1.0.7 → 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 +3 -2
- 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 +231 -61
- 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 +389 -164
- 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/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_progress.py +46 -3
- package/src/clipen/editing/versions.py +53 -10
- 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/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/skills/builtin/display.en.json +89 -0
- package/src/clipen/skills/builtin/references/graphics.md +0 -1
- 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/workspace.py
CHANGED
|
@@ -12,6 +12,8 @@ from dataclasses import dataclass
|
|
|
12
12
|
from datetime import datetime, timezone
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
|
|
15
|
+
from clipen.i18n import tr
|
|
16
|
+
|
|
15
17
|
from .filesystem import restrict_permissions
|
|
16
18
|
from .projects.storage import PROJECT_SCHEMA_VERSION
|
|
17
19
|
|
|
@@ -72,9 +74,9 @@ def prepare_workspace(current_directory: Path) -> WorkspacePaths:
|
|
|
72
74
|
try:
|
|
73
75
|
root = current_directory.resolve(strict=True)
|
|
74
76
|
except OSError as error:
|
|
75
|
-
raise WorkspaceError("Clipen 無法讀取目前的工作目錄。") from error
|
|
77
|
+
raise WorkspaceError(tr("Clipen 無法讀取目前的工作目錄。", "Clipen cannot read the current folder.")) from error
|
|
76
78
|
if not root.is_dir():
|
|
77
|
-
raise WorkspaceError("目前路徑不是可用的資料夾。")
|
|
79
|
+
raise WorkspaceError(tr("目前路徑不是可用的資料夾。", "The current path is not a usable folder."))
|
|
78
80
|
|
|
79
81
|
managed = root / ".clipen"
|
|
80
82
|
created = not managed.exists()
|
|
@@ -83,32 +85,47 @@ def prepare_workspace(current_directory: Path) -> WorkspacePaths:
|
|
|
83
85
|
except FileExistsError:
|
|
84
86
|
pass
|
|
85
87
|
except OSError as error:
|
|
86
|
-
raise WorkspaceError(
|
|
88
|
+
raise WorkspaceError(
|
|
89
|
+
tr("Clipen 無法在目前目錄建立工作區。", "Clipen cannot set up a workspace in this folder.")
|
|
90
|
+
) from error
|
|
87
91
|
if managed.is_symlink() or not managed.is_dir():
|
|
88
|
-
raise WorkspaceError(
|
|
92
|
+
raise WorkspaceError(
|
|
93
|
+
tr("目前目錄中的 .clipen 不是安全的工作區資料夾。", "The .clipen here is not a safe workspace folder.")
|
|
94
|
+
)
|
|
89
95
|
restrict_permissions(managed, 0o700)
|
|
90
96
|
|
|
91
97
|
manifest = managed / "workspace.json"
|
|
92
98
|
if manifest.exists():
|
|
93
99
|
if manifest.is_symlink() or not manifest.is_file():
|
|
94
|
-
raise WorkspaceError("Clipen 工作區識別檔不安全。")
|
|
100
|
+
raise WorkspaceError(tr("Clipen 工作區識別檔不安全。", "The Clipen workspace ID file is not safe."))
|
|
95
101
|
try:
|
|
96
102
|
value = json.loads(manifest.read_text(encoding="utf-8"))
|
|
97
103
|
except (OSError, UnicodeError, json.JSONDecodeError) as error:
|
|
98
|
-
raise WorkspaceError(
|
|
104
|
+
raise WorkspaceError(
|
|
105
|
+
tr("Clipen 工作區識別檔已損壞。", "The Clipen workspace ID file is damaged.")
|
|
106
|
+
) from error
|
|
99
107
|
if not isinstance(value, dict) or value.get("schema") != _WORKSPACE_SCHEMA:
|
|
100
|
-
raise WorkspaceError(
|
|
108
|
+
raise WorkspaceError(
|
|
109
|
+
tr("這個工作區需要其他版本的 Clipen。", "This workspace needs a different version of Clipen.")
|
|
110
|
+
)
|
|
101
111
|
workspace_id = value.get("workspace_id")
|
|
102
112
|
if not isinstance(workspace_id, str) or re.fullmatch(r"wsp_[0-9a-f]{32}", workspace_id) is None:
|
|
103
|
-
raise WorkspaceError("Clipen 工作區識別檔已損壞。")
|
|
113
|
+
raise WorkspaceError(tr("Clipen 工作區識別檔已損壞。", "The Clipen workspace ID file is damaged."))
|
|
104
114
|
created = False
|
|
105
115
|
else:
|
|
106
116
|
try:
|
|
107
117
|
existing_entries = tuple(managed.iterdir())
|
|
108
118
|
except OSError as error:
|
|
109
|
-
raise WorkspaceError(
|
|
119
|
+
raise WorkspaceError(
|
|
120
|
+
tr("Clipen 無法檢查目前目錄的工作區。", "Clipen cannot check the workspace in this folder.")
|
|
121
|
+
) from error
|
|
110
122
|
if existing_entries:
|
|
111
|
-
raise WorkspaceError(
|
|
123
|
+
raise WorkspaceError(
|
|
124
|
+
tr(
|
|
125
|
+
"目前目錄已有無法識別的 .clipen 資料,Clipen 沒有修改它。",
|
|
126
|
+
"This folder has .clipen data Clipen does not recognise; it was left unchanged.",
|
|
127
|
+
)
|
|
128
|
+
)
|
|
112
129
|
created = True
|
|
113
130
|
workspace_id = "wsp_" + uuid.uuid4().hex
|
|
114
131
|
_atomic_json(
|
|
@@ -123,7 +140,9 @@ def prepare_workspace(current_directory: Path) -> WorkspacePaths:
|
|
|
123
140
|
projects = managed / "projects"
|
|
124
141
|
projects.mkdir(mode=0o700, exist_ok=True)
|
|
125
142
|
if projects.is_symlink() or not projects.is_dir():
|
|
126
|
-
raise WorkspaceError(
|
|
143
|
+
raise WorkspaceError(
|
|
144
|
+
tr("Clipen 工作區中的 projects 不安全。", "The projects folder in this workspace is not safe.")
|
|
145
|
+
)
|
|
127
146
|
restrict_permissions(projects, 0o700)
|
|
128
147
|
|
|
129
148
|
return WorkspacePaths(
|
|
@@ -136,46 +155,96 @@ def prepare_workspace(current_directory: Path) -> WorkspacePaths:
|
|
|
136
155
|
)
|
|
137
156
|
|
|
138
157
|
|
|
158
|
+
def _read_project(database: Path) -> tuple:
|
|
159
|
+
"""The integrity check, schema version and project id, read without changing the project.
|
|
160
|
+
|
|
161
|
+
Read-only first. A read-only connection cannot rebuild the WAL index SQLite keeps beside a
|
|
162
|
+
database, and on some disks (exFAT) a project Clipen closed normally then reads as a disk I/O
|
|
163
|
+
error; a query-only connection lets SQLite rebuild that index and leaves the data untouched."""
|
|
164
|
+
uri = database.resolve(strict=True).as_uri()
|
|
165
|
+
for mode in ("ro", "rw"):
|
|
166
|
+
connection = sqlite3.connect(f"{uri}?mode={mode}", uri=True, timeout=5)
|
|
167
|
+
try:
|
|
168
|
+
connection.execute("PRAGMA query_only = ON")
|
|
169
|
+
return (
|
|
170
|
+
connection.execute("PRAGMA quick_check").fetchone(),
|
|
171
|
+
connection.execute("PRAGMA user_version").fetchone(),
|
|
172
|
+
connection.execute("SELECT project_id FROM project LIMIT 1").fetchone(),
|
|
173
|
+
)
|
|
174
|
+
except sqlite3.OperationalError:
|
|
175
|
+
if mode == "rw":
|
|
176
|
+
raise
|
|
177
|
+
finally:
|
|
178
|
+
connection.close()
|
|
179
|
+
raise AssertionError("unreachable")
|
|
180
|
+
|
|
181
|
+
|
|
139
182
|
def inspect_workspace_projects(workspace: WorkspacePaths) -> WorkspaceInspection:
|
|
140
183
|
"""Verify every managed project before the provider or Controller starts."""
|
|
141
184
|
|
|
142
185
|
try:
|
|
143
186
|
entries = tuple(workspace.projects_root.iterdir())
|
|
144
187
|
except OSError as error:
|
|
145
|
-
raise WorkspaceError(
|
|
188
|
+
raise WorkspaceError(
|
|
189
|
+
tr("Clipen 無法檢查目前目錄的作品。", "Clipen cannot check the projects in this folder.")
|
|
190
|
+
) from error
|
|
146
191
|
|
|
147
192
|
project_count = 0
|
|
148
193
|
for entry in entries:
|
|
149
194
|
if entry.name.startswith("prj_") and _PROJECT_DIRECTORY.fullmatch(entry.name) is None:
|
|
150
|
-
raise WorkspaceError(
|
|
195
|
+
raise WorkspaceError(
|
|
196
|
+
tr(
|
|
197
|
+
f"偵測到無法識別的作品資料夾:{entry.name}。Clipen 沒有修改它。",
|
|
198
|
+
f"Found a project folder Clipen does not recognise: {entry.name}. It was left unchanged.",
|
|
199
|
+
)
|
|
200
|
+
)
|
|
151
201
|
if _PROJECT_DIRECTORY.fullmatch(entry.name) is None:
|
|
152
202
|
continue
|
|
153
203
|
if entry.is_symlink() or not entry.is_dir() or os.path.ismount(entry):
|
|
154
|
-
raise WorkspaceError(
|
|
204
|
+
raise WorkspaceError(
|
|
205
|
+
tr(
|
|
206
|
+
f"作品 {entry.name} 的資料夾不安全,Clipen 沒有修改它。",
|
|
207
|
+
f"The folder of project {entry.name} is not safe; it was left unchanged.",
|
|
208
|
+
)
|
|
209
|
+
)
|
|
155
210
|
database = entry / "project.sqlite3"
|
|
156
211
|
try:
|
|
157
212
|
info = database.lstat()
|
|
158
213
|
except OSError as error:
|
|
159
|
-
raise WorkspaceError(
|
|
214
|
+
raise WorkspaceError(
|
|
215
|
+
tr(f"作品 {entry.name} 缺少可讀取的資料庫。", f"Project {entry.name} has no readable database.")
|
|
216
|
+
) from error
|
|
160
217
|
if not stat.S_ISREG(info.st_mode) or info.st_nlink != 1:
|
|
161
|
-
raise WorkspaceError(
|
|
218
|
+
raise WorkspaceError(
|
|
219
|
+
tr(
|
|
220
|
+
f"作品 {entry.name} 的資料庫不安全,Clipen 沒有修改它。",
|
|
221
|
+
f"The database of project {entry.name} is not safe; it was left unchanged.",
|
|
222
|
+
)
|
|
223
|
+
)
|
|
162
224
|
|
|
163
225
|
try:
|
|
164
|
-
|
|
165
|
-
connection = sqlite3.connect(uri, uri=True, timeout=5)
|
|
166
|
-
try:
|
|
167
|
-
connection.execute("PRAGMA query_only = ON")
|
|
168
|
-
check = connection.execute("PRAGMA quick_check").fetchone()
|
|
169
|
-
version = connection.execute("PRAGMA user_version").fetchone()
|
|
170
|
-
row = connection.execute("SELECT project_id FROM project LIMIT 1").fetchone()
|
|
171
|
-
finally:
|
|
172
|
-
connection.close()
|
|
226
|
+
check, version, row = _read_project(database)
|
|
173
227
|
except (OSError, sqlite3.Error) as error:
|
|
174
|
-
raise WorkspaceError(
|
|
228
|
+
raise WorkspaceError(
|
|
229
|
+
tr(
|
|
230
|
+
f"作品 {entry.name} 的資料庫已損壞或無法讀取。",
|
|
231
|
+
f"The database of project {entry.name} is damaged or unreadable.",
|
|
232
|
+
)
|
|
233
|
+
) from error
|
|
175
234
|
if check is None or check[0] != "ok" or row is None or row[0] != entry.name:
|
|
176
|
-
raise WorkspaceError(
|
|
235
|
+
raise WorkspaceError(
|
|
236
|
+
tr(
|
|
237
|
+
f"作品 {entry.name} 的資料內容不完整,Clipen 沒有修改它。",
|
|
238
|
+
f"Project {entry.name} is incomplete; it was left unchanged.",
|
|
239
|
+
)
|
|
240
|
+
)
|
|
177
241
|
if version is None or not isinstance(version[0], int) or not 1 <= version[0] <= PROJECT_SCHEMA_VERSION:
|
|
178
|
-
raise WorkspaceError(
|
|
242
|
+
raise WorkspaceError(
|
|
243
|
+
tr(
|
|
244
|
+
f"作品 {entry.name} 需要其他版本的 Clipen。",
|
|
245
|
+
f"Project {entry.name} needs a different version of Clipen.",
|
|
246
|
+
)
|
|
247
|
+
)
|
|
179
248
|
project_count += 1
|
|
180
249
|
|
|
181
250
|
return WorkspaceInspection(project_count)
|