@clipen/clipen-cli 1.0.0 → 1.0.1
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 +60 -50
- package/package.json +7 -4
- package/pyproject.toml +18 -2
- package/requirements/dev.txt +2 -0
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/__init__.py +7 -7
- package/src/clipen/analysis/artifacts.py +4 -10
- package/src/clipen/analysis/audio.py +10 -8
- package/src/clipen/analysis/evidence_service.py +345 -167
- package/src/clipen/analysis/image_similarity.py +5 -14
- package/src/clipen/analysis/keyframes.py +5 -17
- package/src/clipen/analysis/models.py +5 -7
- package/src/clipen/analysis/qwen_worker.py +19 -54
- package/src/clipen/analysis/resources.py +2 -1
- package/src/clipen/analysis/runtime.py +1 -3
- package/src/clipen/analysis/service.py +16 -48
- package/src/clipen/analysis/setup.py +11 -25
- package/src/clipen/analysis/setup_cli.py +5 -15
- package/src/clipen/analysis/storage.py +96 -278
- package/src/clipen/analysis/transcription.py +40 -82
- package/src/clipen/analysis/visual.py +109 -48
- package/src/clipen/annotations/__init__.py +5 -2
- package/src/clipen/annotations/models.py +1 -1
- package/src/clipen/annotations/storage.py +132 -84
- package/src/clipen/annotations/suggestions.py +3 -8
- package/src/clipen/asr_release.py +4 -11
- package/src/clipen/bootstrap.py +65 -54
- package/src/clipen/{planning/models.py → candidates.py} +29 -47
- package/src/clipen/cli.py +2 -2
- package/src/clipen/controller/app.py +401 -214
- package/src/clipen/controller/server.py +28 -38
- package/src/clipen/domain/__init__.py +1 -1
- package/src/clipen/domain/media_time.py +3 -10
- package/src/clipen/domain/timeline.py +45 -47
- package/src/clipen/domain/validation.py +0 -1
- package/src/clipen/editing/__init__.py +1 -1
- package/src/clipen/editing/agent_models.py +4 -11
- package/src/clipen/editing/agent_repository.py +391 -170
- package/src/clipen/editing/agent_tools.py +180 -99
- package/src/clipen/editing/alignment.py +92 -52
- package/src/clipen/editing/alignment_setup.py +118 -70
- package/src/clipen/editing/alignment_worker.py +11 -9
- package/src/clipen/editing/change_report.py +95 -38
- package/src/clipen/editing/compiler.py +0 -1
- package/src/clipen/editing/component_looks.py +58 -34
- package/src/clipen/editing/component_review.py +34 -38
- package/src/clipen/editing/coordinator.py +213 -90
- package/src/clipen/editing/editorial_review.py +217 -95
- package/src/clipen/editing/evidence_jobs.py +457 -200
- package/src/clipen/editing/history_changes.py +129 -68
- package/src/clipen/editing/music_choices.py +8 -5
- package/src/clipen/editing/production_catalog.py +573 -136
- package/src/clipen/editing/production_limits.py +43 -17
- package/src/clipen/editing/production_media.py +376 -167
- package/src/clipen/editing/production_preview.py +322 -129
- package/src/clipen/editing/production_progress.py +164 -69
- package/src/clipen/editing/production_requirements.py +106 -39
- package/src/clipen/editing/production_tools.py +1064 -462
- package/src/clipen/editing/program_audio.py +211 -81
- package/src/clipen/editing/program_direction.py +59 -25
- package/src/clipen/editing/program_story.py +83 -45
- package/src/clipen/editing/program_subtitles.py +194 -96
- package/src/clipen/editing/programme_review.py +98 -50
- package/src/clipen/editing/prompt_history.py +64 -27
- package/src/clipen/editing/recut.py +65 -25
- package/src/clipen/editing/refinement_references.py +176 -86
- package/src/clipen/editing/resolve_export.py +449 -218
- package/src/clipen/editing/resolve_titles.py +162 -105
- package/src/clipen/editing/skill_tools.py +530 -154
- package/src/clipen/editing/source_dialogue.py +177 -67
- package/src/clipen/editing/speech_coverage.py +42 -22
- package/src/clipen/editing/speech_quality.py +6 -1
- package/src/clipen/editing/tool_receipts.py +78 -32
- package/src/clipen/editing/versions.py +122 -64
- package/src/clipen/editing/visual_preview.py +157 -61
- package/src/clipen/editing/workbench.py +104 -42
- package/src/clipen/finishing/audio.py +69 -30
- package/src/clipen/finishing/catalog.py +176 -93
- package/src/clipen/finishing/models.py +1 -1
- package/src/clipen/finishing/renderer.py +33 -14
- package/src/clipen/mcp_editing/__main__.py +3 -1
- package/src/clipen/mcp_editing/server.py +77 -34
- package/src/clipen/media/__init__.py +3 -3
- package/src/clipen/media/discovery.py +7 -20
- package/src/clipen/media/models.py +7 -18
- package/src/clipen/media/preview.py +14 -24
- package/src/clipen/media/probe.py +16 -44
- package/src/clipen/media/service.py +6 -19
- package/src/clipen/media/storage.py +33 -81
- package/src/clipen/music_vocabulary.py +33 -4
- package/src/clipen/power.py +8 -3
- package/src/clipen/projects/__init__.py +1 -1
- package/src/clipen/projects/deletion.py +19 -32
- package/src/clipen/projects/finishing_schema.py +3 -1
- package/src/clipen/projects/models.py +2 -5
- package/src/clipen/projects/picker.py +13 -37
- package/src/clipen/projects/service.py +8 -24
- package/src/clipen/projects/storage.py +226 -246
- package/src/clipen/provider_registry.py +4 -2
- package/src/clipen/providers/account.py +86 -35
- package/src/clipen/providers/claude.py +59 -25
- package/src/clipen/providers/claude_editing.py +14 -7
- package/src/clipen/providers/codex.py +73 -118
- package/src/clipen/providers/codex_editing.py +2 -2
- package/src/clipen/providers/editing_agent.py +19 -17
- package/src/clipen/providers/recovery.py +7 -8
- package/src/clipen/rendering/cover.py +18 -5
- package/src/clipen/rendering/custom_components.py +167 -79
- package/src/clipen/rendering/custom_render.py +62 -41
- package/src/clipen/rendering/production_effects.py +77 -45
- package/src/clipen/rendering/program_components.py +134 -73
- package/src/clipen/rendering/program_creator.py +432 -277
- package/src/clipen/rendering/program_identities.py +277 -182
- package/src/clipen/rendering/program_motion.py +140 -95
- package/src/clipen/rendering/program_studio.py +175 -116
- package/src/clipen/rendering/program_styles.py +231 -145
- package/src/clipen/rendering/program_subtitles.py +71 -34
- package/src/clipen/rendering/renderer.py +150 -121
- package/src/clipen/rendering/storage.py +9 -22
- package/src/clipen/rendering/titles.py +193 -86
- package/src/clipen/skills/__init__.py +1 -0
- package/src/clipen/skills/catalog.py +151 -55
- package/src/clipen/skills/library.py +13 -7
- package/src/clipen/skills/package.py +46 -23
- package/src/clipen/skills/visual_styles.py +29 -18
- package/src/clipen/workspace.py +15 -44
- package/src/clipen/planning/__init__.py +0 -9
|
@@ -34,12 +34,14 @@ class ProviderDescriptor:
|
|
|
34
34
|
|
|
35
35
|
PROVIDERS: dict[str, ProviderDescriptor] = {
|
|
36
36
|
"codex": ProviderDescriptor(
|
|
37
|
-
"codex",
|
|
37
|
+
"codex",
|
|
38
|
+
"Codex",
|
|
38
39
|
"clipen.providers.codex_editing:CodexEditingAgent",
|
|
39
40
|
"clipen.providers.codex:CodexExecAdapter",
|
|
40
41
|
),
|
|
41
42
|
"claude": ProviderDescriptor(
|
|
42
|
-
"claude",
|
|
43
|
+
"claude",
|
|
44
|
+
"Claude",
|
|
43
45
|
"clipen.providers.claude_editing:ClaudeEditingAgent",
|
|
44
46
|
"clipen.providers.claude:ClaudeExecAdapter",
|
|
45
47
|
),
|
|
@@ -4,25 +4,35 @@ Nothing here invokes a model or spends quota. Codex answers live through its
|
|
|
4
4
|
local app server; Claude Code has no such query, so its details come from the
|
|
5
5
|
last Clipen attempt and say so.
|
|
6
6
|
"""
|
|
7
|
+
|
|
7
8
|
from __future__ import annotations
|
|
8
9
|
|
|
9
10
|
import json
|
|
10
11
|
import os
|
|
11
|
-
from pathlib import Path
|
|
12
12
|
import queue
|
|
13
13
|
import subprocess
|
|
14
14
|
import threading
|
|
15
15
|
import time
|
|
16
|
+
from pathlib import Path
|
|
16
17
|
from typing import Mapping
|
|
17
18
|
|
|
18
19
|
_SNAPSHOT = "claude-account.json"
|
|
19
20
|
_WINDOWS = {300: "five_hour", 10080: "weekly"}
|
|
20
21
|
|
|
21
22
|
|
|
22
|
-
def _rpc(
|
|
23
|
+
def _rpc(
|
|
24
|
+
binary: str, environment: Mapping[str, str], requests: list[tuple[str, dict | None]], timeout: float
|
|
25
|
+
) -> dict[int, dict]:
|
|
23
26
|
"""Ask `codex app-server` a few JSON-RPC questions and return the answers by request id."""
|
|
24
|
-
process = subprocess.Popen(
|
|
25
|
-
|
|
27
|
+
process = subprocess.Popen(
|
|
28
|
+
[binary, "app-server"],
|
|
29
|
+
stdin=subprocess.PIPE,
|
|
30
|
+
stdout=subprocess.PIPE,
|
|
31
|
+
stderr=subprocess.DEVNULL,
|
|
32
|
+
env=dict(environment),
|
|
33
|
+
text=True,
|
|
34
|
+
bufsize=1,
|
|
35
|
+
)
|
|
26
36
|
lines: queue.Queue[str | None] = queue.Queue()
|
|
27
37
|
|
|
28
38
|
def read() -> None:
|
|
@@ -35,6 +45,7 @@ def _rpc(binary: str, environment: Mapping[str, str], requests: list[tuple[str,
|
|
|
35
45
|
answers: dict[int, dict] = {}
|
|
36
46
|
deadline = time.monotonic() + timeout
|
|
37
47
|
try:
|
|
48
|
+
|
|
38
49
|
def send(message: dict) -> None:
|
|
39
50
|
assert process.stdin is not None
|
|
40
51
|
process.stdin.write(json.dumps({"jsonrpc": "2.0", **message}) + "\n")
|
|
@@ -79,8 +90,12 @@ def _window(value: object) -> dict | None:
|
|
|
79
90
|
used, minutes, resets = value.get("usedPercent"), value.get("windowDurationMins"), value.get("resetsAt")
|
|
80
91
|
if not isinstance(used, (int, float)) or isinstance(used, bool):
|
|
81
92
|
return None
|
|
82
|
-
return {
|
|
83
|
-
|
|
93
|
+
return {
|
|
94
|
+
"kind": _WINDOWS.get(minutes, "other"),
|
|
95
|
+
"minutes": minutes if isinstance(minutes, int) else None,
|
|
96
|
+
"used_percent": max(0, min(100, round(used))),
|
|
97
|
+
"resets_at": resets if isinstance(resets, int) else None,
|
|
98
|
+
}
|
|
84
99
|
|
|
85
100
|
|
|
86
101
|
_MODELS: dict[str, tuple[float, list[dict]]] = {}
|
|
@@ -90,20 +105,29 @@ _MODELS_LOCK = threading.Lock()
|
|
|
90
105
|
def _models(data: object) -> list[dict]:
|
|
91
106
|
if not isinstance(data, list):
|
|
92
107
|
return []
|
|
93
|
-
return [
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
return [
|
|
109
|
+
{
|
|
110
|
+
"model": m.get("model") or m.get("id"),
|
|
111
|
+
"name": m.get("displayName") or m.get("model"),
|
|
112
|
+
"default": bool(m.get("isDefault")),
|
|
113
|
+
"default_effort": m.get("defaultReasoningEffort"),
|
|
114
|
+
"efforts": [
|
|
115
|
+
e.get("reasoningEffort") for e in m.get("supportedReasoningEfforts") or [] if isinstance(e, dict)
|
|
116
|
+
],
|
|
117
|
+
}
|
|
118
|
+
for m in data
|
|
119
|
+
if isinstance(m, dict) and isinstance(m.get("model") or m.get("id"), str)
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def available_models(binary: str | Path, environment: Mapping[str, str], ttl: float = 600.0) -> list[dict]:
|
|
100
124
|
"""Models this Codex account can run, cached for a few minutes."""
|
|
101
125
|
key = str(binary)
|
|
102
126
|
with _MODELS_LOCK:
|
|
103
127
|
cached = _MODELS.get(key)
|
|
104
128
|
if cached and time.monotonic() - cached[0] < ttl:
|
|
105
129
|
return cached[1]
|
|
106
|
-
models = _models((_rpc(key, environment, [("model/list", {})], 10.).get(1) or {}).get("data"))
|
|
130
|
+
models = _models((_rpc(key, environment, [("model/list", {})], 10.0).get(1) or {}).get("data"))
|
|
107
131
|
with _MODELS_LOCK:
|
|
108
132
|
# An empty answer is kept briefly too, so a slow app server delays one run, not each one.
|
|
109
133
|
_MODELS[key] = (time.monotonic() - (ttl - 60 if not models else 0), models)
|
|
@@ -119,24 +143,36 @@ def resolve_codex_model(preferences: tuple[str | None, str | None], models: list
|
|
|
119
143
|
chosen = next((m for m in models if m["model"] == wanted), None)
|
|
120
144
|
model = chosen or default
|
|
121
145
|
applied_effort = effort if effort and effort in model["efforts"] else None
|
|
122
|
-
return {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
146
|
+
return {
|
|
147
|
+
"id": model["model"],
|
|
148
|
+
"name": model["name"],
|
|
149
|
+
"effort": applied_effort or model["default_effort"],
|
|
150
|
+
"apply_model": chosen is not None,
|
|
151
|
+
"apply_effort": applied_effort is not None,
|
|
152
|
+
"source": "codex_config" if chosen is not None or applied_effort else "default",
|
|
153
|
+
"unavailable": wanted if wanted and chosen is None else None,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def codex_account(binary: str | Path, environment: Mapping[str, str], timeout: float = 10.0) -> dict:
|
|
129
158
|
"""The model Clipen runs (see resolve_codex_model) and live usage limits."""
|
|
130
159
|
from .codex import codex_preferences
|
|
160
|
+
|
|
131
161
|
answers = _rpc(str(binary), environment, [("account/rateLimits/read", None), ("model/list", {})], timeout)
|
|
132
162
|
limits = (answers.get(1) or {}).get("rateLimits")
|
|
133
163
|
resolved = resolve_codex_model(codex_preferences(environment), _models((answers.get(2) or {}).get("data")))
|
|
134
|
-
model =
|
|
164
|
+
model = (
|
|
165
|
+
None if resolved is None else {key: resolved[key] for key in ("id", "name", "effort", "source", "unavailable")}
|
|
166
|
+
)
|
|
135
167
|
quota = None
|
|
136
168
|
if isinstance(limits, dict):
|
|
137
169
|
windows = [w for w in (_window(limits.get("primary")), _window(limits.get("secondary"))) if w]
|
|
138
|
-
quota = {
|
|
139
|
-
|
|
170
|
+
quota = {
|
|
171
|
+
"source": "live",
|
|
172
|
+
"plan": limits.get("planType") if isinstance(limits.get("planType"), str) else None,
|
|
173
|
+
"windows": windows,
|
|
174
|
+
"limited": bool(limits.get("rateLimitReachedType")),
|
|
175
|
+
}
|
|
140
176
|
return {"model": model, "quota": quota}
|
|
141
177
|
|
|
142
178
|
|
|
@@ -149,8 +185,11 @@ def record_claude_account(attempt_root: Path, events: list[dict], requested: str
|
|
|
149
185
|
return
|
|
150
186
|
snapshot = {"model": model, "requested": requested, "observed_at": int(time.time())}
|
|
151
187
|
if isinstance(info, dict):
|
|
152
|
-
snapshot["limit"] = {
|
|
153
|
-
|
|
188
|
+
snapshot["limit"] = {
|
|
189
|
+
key: info.get(key)
|
|
190
|
+
for key in ("status", "resetsAt", "rateLimitType")
|
|
191
|
+
if isinstance(info.get(key), (str, int)) and not isinstance(info.get(key), bool)
|
|
192
|
+
}
|
|
154
193
|
path = attempt_root / _SNAPSHOT
|
|
155
194
|
temporary = path.with_suffix(".tmp")
|
|
156
195
|
temporary.write_text(json.dumps(snapshot), encoding="utf-8")
|
|
@@ -166,6 +205,7 @@ def _claude_name(model: str) -> str:
|
|
|
166
205
|
def claude_account(attempt_root: Path, environment: Mapping[str, str] | None = None) -> dict:
|
|
167
206
|
"""The last run's model and limit status, with the effort and model chosen in Claude Code settings."""
|
|
168
207
|
from .claude import claude_preferences
|
|
208
|
+
|
|
169
209
|
wanted, effort = claude_preferences(environment)
|
|
170
210
|
source = "claude_config" if wanted or effort else "default"
|
|
171
211
|
path = attempt_root / _SNAPSHOT
|
|
@@ -183,12 +223,23 @@ def claude_account(attempt_root: Path, environment: Mapping[str, str] | None = N
|
|
|
183
223
|
model = wanted
|
|
184
224
|
limit = snapshot.get("limit") if isinstance(snapshot.get("limit"), dict) else {}
|
|
185
225
|
observed = snapshot.get("observed_at") if isinstance(snapshot.get("observed_at"), int) else None
|
|
186
|
-
quota =
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
"
|
|
226
|
+
quota = (
|
|
227
|
+
None
|
|
228
|
+
if not limit
|
|
229
|
+
else {
|
|
230
|
+
"source": "last_run",
|
|
231
|
+
"observed_at": observed,
|
|
232
|
+
"plan": None,
|
|
233
|
+
"windows": [],
|
|
234
|
+
"limited": limit.get("status") not in (None, "allowed", "allowed_warning"),
|
|
235
|
+
"warning": limit.get("status") == "allowed_warning",
|
|
236
|
+
"resets_at": limit.get("resetsAt") if isinstance(limit.get("resetsAt"), int) else None,
|
|
237
|
+
"kind": limit.get("rateLimitType") if isinstance(limit.get("rateLimitType"), str) else None,
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
return {
|
|
241
|
+
"model": None
|
|
242
|
+
if not isinstance(model, str)
|
|
243
|
+
else {"id": model, "name": _claude_name(model), "effort": effort, "source": source, "unavailable": None},
|
|
244
|
+
"quota": quota,
|
|
245
|
+
}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import base64
|
|
6
|
-
from dataclasses import dataclass
|
|
7
6
|
import json
|
|
8
7
|
import os
|
|
9
8
|
import re
|
|
10
|
-
from pathlib import Path
|
|
11
9
|
import shutil
|
|
12
10
|
import subprocess
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from pathlib import Path
|
|
13
13
|
from typing import Mapping
|
|
14
14
|
|
|
15
15
|
from jsonschema import Draft202012Validator
|
|
@@ -28,7 +28,6 @@ from .codex import (
|
|
|
28
28
|
_provider_environment,
|
|
29
29
|
_workspace_file,
|
|
30
30
|
)
|
|
31
|
-
from .recovery import ProviderUsage
|
|
32
31
|
from .errors import (
|
|
33
32
|
ProviderAuthenticationError,
|
|
34
33
|
ProviderNetworkError,
|
|
@@ -37,7 +36,7 @@ from .errors import (
|
|
|
37
36
|
ProviderUnavailable,
|
|
38
37
|
ProviderUsageLimitError,
|
|
39
38
|
)
|
|
40
|
-
|
|
39
|
+
from .recovery import ProviderUsage
|
|
41
40
|
|
|
42
41
|
# Flags the bounded editing attempt depends on; an older CLI without them
|
|
43
42
|
# could load user tools or settings, so it is reported as unsupported.
|
|
@@ -81,8 +80,10 @@ def claude_preferences(environment: Mapping[str, str] | None = None) -> tuple[st
|
|
|
81
80
|
if not isinstance(settings, dict):
|
|
82
81
|
return None, None
|
|
83
82
|
model, effort = settings.get("model"), settings.get("effortLevel")
|
|
84
|
-
return (
|
|
85
|
-
|
|
83
|
+
return (
|
|
84
|
+
model if isinstance(model, str) and _CLAUDE_MODEL.fullmatch(model) else None,
|
|
85
|
+
effort if effort in _CLAUDE_EFFORTS else None,
|
|
86
|
+
)
|
|
86
87
|
|
|
87
88
|
|
|
88
89
|
def model_arguments(environment: Mapping[str, str] | None = None) -> tuple[str, ...]:
|
|
@@ -94,27 +95,49 @@ def claude_environment(source: Mapping[str, str] | None = None) -> dict[str, str
|
|
|
94
95
|
inherited = os.environ if source is None else source
|
|
95
96
|
environment = _provider_environment(inherited)
|
|
96
97
|
environment.update({key: value for key, value in inherited.items() if key in _CLAUDE_ENVIRONMENT})
|
|
97
|
-
environment.update(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
environment.update(
|
|
99
|
+
{
|
|
100
|
+
# Match Codex's 600-second MCP tool timeout for bounded music downloads.
|
|
101
|
+
"MCP_TOOL_TIMEOUT": "600000",
|
|
102
|
+
"MCP_TIMEOUT": "60000",
|
|
103
|
+
"DISABLE_AUTOUPDATER": "1",
|
|
104
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
105
|
+
}
|
|
106
|
+
)
|
|
104
107
|
return environment
|
|
105
108
|
|
|
106
109
|
|
|
107
110
|
def raise_for_claude_failure(returncode: int, diagnostic: str, status: object = None) -> None:
|
|
108
111
|
text = diagnostic.lower()
|
|
109
|
-
if status == 401 or any(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
if status == 401 or any(
|
|
113
|
+
marker in text
|
|
114
|
+
for marker in (
|
|
115
|
+
"not logged in",
|
|
116
|
+
"invalid api key",
|
|
117
|
+
"/login",
|
|
118
|
+
"authentication_error",
|
|
119
|
+
"authentication_failed",
|
|
120
|
+
"failed to authenticate",
|
|
121
|
+
"oauth token",
|
|
122
|
+
"oauth session",
|
|
123
|
+
)
|
|
124
|
+
):
|
|
112
125
|
raise ProviderAuthenticationError("Claude login is missing or no longer valid")
|
|
113
|
-
if status == 429 or any(
|
|
114
|
-
|
|
126
|
+
if status == 429 or any(
|
|
127
|
+
marker in text
|
|
128
|
+
for marker in ("usage limit", "rate limit", "rate_limit", "quota", "credit balance", "limit reached")
|
|
129
|
+
):
|
|
115
130
|
raise ProviderUsageLimitError("Claude account usage limit prevented this attempt")
|
|
116
|
-
if any(
|
|
117
|
-
|
|
131
|
+
if any(
|
|
132
|
+
marker in text
|
|
133
|
+
for marker in (
|
|
134
|
+
"connection error",
|
|
135
|
+
"network is unreachable",
|
|
136
|
+
"could not resolve host",
|
|
137
|
+
"econnrefused",
|
|
138
|
+
"enotfound",
|
|
139
|
+
)
|
|
140
|
+
):
|
|
118
141
|
raise ProviderNetworkError("Claude could not reach its service")
|
|
119
142
|
if "permission denied" in text or "operation not permitted" in text:
|
|
120
143
|
raise ProviderPermissionError("Claude permission confinement failed")
|
|
@@ -314,14 +337,23 @@ class ClaudeExecAdapter(CodexExecAdapter):
|
|
|
314
337
|
content: list[dict[str, object]] = [{"type": "text", "text": attempt.prompt}]
|
|
315
338
|
for image in attempt.images:
|
|
316
339
|
path = _workspace_file(image, attempt.workspace.resolve(), "image")
|
|
317
|
-
content.append(
|
|
318
|
-
|
|
319
|
-
|
|
340
|
+
content.append(
|
|
341
|
+
{
|
|
342
|
+
"type": "image",
|
|
343
|
+
"source": {
|
|
344
|
+
"type": "base64",
|
|
345
|
+
"media_type": "image/png",
|
|
346
|
+
"data": base64.b64encode(path.read_bytes()).decode("ascii"),
|
|
347
|
+
},
|
|
348
|
+
}
|
|
349
|
+
)
|
|
320
350
|
message = {"type": "user", "message": {"role": "user", "content": content}}
|
|
321
351
|
return (json.dumps(message, ensure_ascii=False) + "\n").encode("utf-8")
|
|
322
352
|
|
|
323
353
|
@staticmethod
|
|
324
|
-
def _events_and_usage(
|
|
354
|
+
def _events_and_usage(
|
|
355
|
+
stdout: bytes, *, limit: int = _MAX_CAPTURE_BYTES
|
|
356
|
+
) -> tuple[tuple[str, ...], ProviderUsage | None]:
|
|
325
357
|
events = _stream_events(stdout, limit)
|
|
326
358
|
return stream_event_types(events), stream_usage(events)
|
|
327
359
|
|
|
@@ -367,7 +399,9 @@ class ClaudeExecAdapter(CodexExecAdapter):
|
|
|
367
399
|
raise ProviderProtocolError("Claude result was not valid UTF-8 JSON") from error
|
|
368
400
|
if not isinstance(payload, dict):
|
|
369
401
|
raise ProviderProtocolError("Claude result must be a JSON object")
|
|
370
|
-
schema = _load_output_schema(
|
|
402
|
+
schema = _load_output_schema(
|
|
403
|
+
_workspace_file(attempt.output_schema, _isolated_workspace(attempt.workspace), "output_schema")
|
|
404
|
+
)
|
|
371
405
|
try:
|
|
372
406
|
Draft202012Validator(schema).validate(payload)
|
|
373
407
|
except ValidationError as error:
|
|
@@ -21,7 +21,6 @@ from .editing_agent import _MAX_CAPTURE_BYTES, _MCP_TOOLS, BoundedEditingAgent,
|
|
|
21
21
|
from .errors import ProviderProtocolError
|
|
22
22
|
from .recovery import ProviderUsage
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
MCP_SERVER = "clipen"
|
|
26
25
|
|
|
27
26
|
|
|
@@ -46,8 +45,11 @@ class ClaudeEditingAgent(BoundedEditingAgent):
|
|
|
46
45
|
workspace: Path,
|
|
47
46
|
output_path: Path,
|
|
48
47
|
) -> tuple[str, ...]:
|
|
49
|
-
server = {
|
|
50
|
-
|
|
48
|
+
server = {
|
|
49
|
+
"type": "stdio",
|
|
50
|
+
"command": str(self.python),
|
|
51
|
+
"args": mcp_server_arguments(self.projects_root, project_id, run_id, self.local_runtime),
|
|
52
|
+
}
|
|
51
53
|
return (
|
|
52
54
|
str(self.binary),
|
|
53
55
|
"--print",
|
|
@@ -82,15 +84,19 @@ class ClaudeEditingAgent(BoundedEditingAgent):
|
|
|
82
84
|
def record_account(self, stdout: bytes) -> None:
|
|
83
85
|
# Claude Code has no quota query; keep what this attempt reported.
|
|
84
86
|
from .account import record_claude_account
|
|
87
|
+
|
|
85
88
|
try:
|
|
86
|
-
record_claude_account(
|
|
87
|
-
|
|
89
|
+
record_claude_account(
|
|
90
|
+
self.attempt_root, _stream_events(stdout, _MAX_CAPTURE_BYTES), claude_preferences(self.environment)[0]
|
|
91
|
+
)
|
|
88
92
|
except (OSError, ProviderProtocolError):
|
|
89
93
|
pass
|
|
90
94
|
|
|
91
95
|
def closing_message(self, stdout: bytes, final_message: Path) -> str | None:
|
|
92
96
|
# Claude reports its last message in the stream's result event.
|
|
93
|
-
result = next(
|
|
97
|
+
result = next(
|
|
98
|
+
(e for e in reversed(_stream_events(stdout, _MAX_CAPTURE_BYTES)) if e.get("type") == "result"), None
|
|
99
|
+
)
|
|
94
100
|
value = None if result is None else result.get("result")
|
|
95
101
|
return value if isinstance(value, str) else None
|
|
96
102
|
|
|
@@ -103,7 +109,8 @@ class ClaudeEditingAgent(BoundedEditingAgent):
|
|
|
103
109
|
if init is not None:
|
|
104
110
|
servers = init.get("mcp_servers")
|
|
105
111
|
connected = isinstance(servers, list) and any(
|
|
106
|
-
isinstance(s, dict) and s.get("name") == MCP_SERVER and s.get("status") == "connected" for s in servers
|
|
112
|
+
isinstance(s, dict) and s.get("name") == MCP_SERVER and s.get("status") == "connected" for s in servers
|
|
113
|
+
)
|
|
107
114
|
if not connected:
|
|
108
115
|
raise ProviderProtocolError("Claude could not connect to the Clipen MCP server")
|
|
109
116
|
raise_for_failed_result(events, diagnostic)
|