forgexa-cli 1.96.4__tar.gz → 1.96.5__tar.gz
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.
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/PKG-INFO +1 -1
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/__init__.py +1 -1
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/component_runtime.py +19 -9
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/daemon.py +1 -1
- forgexa_cli-1.96.5/forgexa_cli/ocr_adapter.py +319 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli.egg-info/PKG-INFO +1 -1
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli.egg-info/SOURCES.txt +1 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/pyproject.toml +1 -1
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/README.md +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/_build_config.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/_local_bind.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/agent_core.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/autoupgrade.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/aws_evidence.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/aws_logs_evidence.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/main.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/observability_contract.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/observability_evidence.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/py.typed +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/runtime_evidence.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli/zcode_protocol.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli.egg-info/dependency_links.txt +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli.egg-info/entry_points.txt +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli.egg-info/requires.txt +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/forgexa_cli.egg-info/top_level.txt +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/setup.cfg +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_auth_and_runtime_commands.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_autoupgrade.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_check_command.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_expiry_warnings_and_revoke.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_local_bind_commands.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_publish_script.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_runtime_credentials.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_session_credentials.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_silent_install.py +0 -0
- {forgexa_cli-1.96.4 → forgexa_cli-1.96.5}/tests/test_upgrade_observability.py +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""forgexa-cli — Forgexa command-line client."""
|
|
2
|
-
__version__ = "1.96.
|
|
2
|
+
__version__ = "1.96.5"
|
|
@@ -695,10 +695,7 @@ def inspect_usage(lease_id: str, root: Path | None = None) -> dict[str, Any]:
|
|
|
695
695
|
return result
|
|
696
696
|
|
|
697
697
|
|
|
698
|
-
def
|
|
699
|
-
runtime_instance_id: str, root: Path | None = None
|
|
700
|
-
) -> dict[str, Any] | None:
|
|
701
|
-
_identifier(runtime_instance_id)
|
|
698
|
+
def inspect_target(root: Path | None = None) -> dict[str, Any] | None:
|
|
702
699
|
root = default_store_root() if root is None else root
|
|
703
700
|
if root.is_symlink():
|
|
704
701
|
raise ComponentRuntimeError("component_storage_invalid")
|
|
@@ -707,7 +704,16 @@ def runtime_capabilities(
|
|
|
707
704
|
if os.name != "posix" or os.environ.get("WSL_DISTRO_NAME"):
|
|
708
705
|
raise ComponentRuntimeError("component_platform_unverified")
|
|
709
706
|
with _ComponentManagerLock(root):
|
|
710
|
-
|
|
707
|
+
return _component_target(root)
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
def runtime_capabilities(
|
|
711
|
+
runtime_instance_id: str, root: Path | None = None
|
|
712
|
+
) -> dict[str, Any] | None:
|
|
713
|
+
_identifier(runtime_instance_id)
|
|
714
|
+
target = inspect_target(root)
|
|
715
|
+
if target is None:
|
|
716
|
+
return None
|
|
711
717
|
process_id = os.getpid()
|
|
712
718
|
return {
|
|
713
719
|
"schema_version": 1,
|
|
@@ -722,9 +728,12 @@ def runtime_capabilities(
|
|
|
722
728
|
|
|
723
729
|
|
|
724
730
|
def _acquire_component(
|
|
725
|
-
component_id: str, root: Path | None = None, override: str | None = None
|
|
731
|
+
component_id: str, root: Path | None = None, override: str | None = None,
|
|
732
|
+
kind: str = "agent",
|
|
726
733
|
) -> ManagedComponentLease | None:
|
|
727
734
|
_identifier(component_id)
|
|
735
|
+
if kind not in {"agent", "plugin"}:
|
|
736
|
+
raise ComponentRuntimeError("component_receipt_invalid")
|
|
728
737
|
root = default_store_root() if root is None else root
|
|
729
738
|
if root.is_symlink():
|
|
730
739
|
raise ComponentRuntimeError("component_storage_invalid")
|
|
@@ -813,7 +822,7 @@ def _acquire_component(
|
|
|
813
822
|
if (
|
|
814
823
|
type(release["schema_version"]) is not int
|
|
815
824
|
or release["schema_version"] != 1
|
|
816
|
-
or release["kind"] !=
|
|
825
|
+
or release["kind"] != kind
|
|
817
826
|
):
|
|
818
827
|
raise ComponentRuntimeError("component_receipt_invalid")
|
|
819
828
|
for name in ("component_id", "release_id", "protocol_generation"):
|
|
@@ -879,10 +888,11 @@ def _acquire_component(
|
|
|
879
888
|
|
|
880
889
|
|
|
881
890
|
def acquire_component(
|
|
882
|
-
component_id: str, root: Path | None = None, override: str | None = None
|
|
891
|
+
component_id: str, root: Path | None = None, override: str | None = None,
|
|
892
|
+
kind: str = "agent",
|
|
883
893
|
) -> ManagedComponentLease | None:
|
|
884
894
|
try:
|
|
885
|
-
return _acquire_component(component_id, root, override)
|
|
895
|
+
return _acquire_component(component_id, root, override, kind)
|
|
886
896
|
except OSError as error:
|
|
887
897
|
raise ComponentRuntimeError("component_storage_unavailable") from error
|
|
888
898
|
|
|
@@ -1412,7 +1412,7 @@ except (ImportError, ModuleNotFoundError):
|
|
|
1412
1412
|
# DAEMON_VERSION is the protocol/logic version of the daemon code.
|
|
1413
1413
|
# Kept in sync with pyproject.toml version via bump-version.sh.
|
|
1414
1414
|
# CLIENT_TYPE identifies which packaging/distribution this daemon runs in.
|
|
1415
|
-
DAEMON_VERSION = "1.96.
|
|
1415
|
+
DAEMON_VERSION = "1.96.5"
|
|
1416
1416
|
|
|
1417
1417
|
|
|
1418
1418
|
def _detect_client_type() -> str:
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import json
|
|
5
|
+
import math
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import shutil
|
|
9
|
+
import signal
|
|
10
|
+
import tempfile
|
|
11
|
+
from pathlib import Path, PurePosixPath
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
if __package__:
|
|
15
|
+
from .component_runtime import ManagedComponentLease, observe_owned_process
|
|
16
|
+
else:
|
|
17
|
+
from component_runtime import ManagedComponentLease, observe_owned_process
|
|
18
|
+
|
|
19
|
+
OCR_COMPONENT_ID = "forgexa.ocr"
|
|
20
|
+
OCR_OUTPUT_LIMIT = 1024 * 1024
|
|
21
|
+
OCR_FILE_LIMIT = 5000
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class OcrAdapterError(RuntimeError):
|
|
25
|
+
def __init__(self, code: str) -> None:
|
|
26
|
+
self.code = code
|
|
27
|
+
super().__init__(code)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _object(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
|
|
31
|
+
result: dict[str, Any] = {}
|
|
32
|
+
for key, value in pairs:
|
|
33
|
+
if key in result:
|
|
34
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
35
|
+
result[key] = value
|
|
36
|
+
return result
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _decode(payload: bytes | str) -> dict[str, Any]:
|
|
40
|
+
if len(payload if isinstance(payload, bytes) else payload.encode()) > OCR_OUTPUT_LIMIT:
|
|
41
|
+
raise OcrAdapterError("ocr_output_limit")
|
|
42
|
+
try:
|
|
43
|
+
value = json.loads(payload, object_pairs_hook=_object)
|
|
44
|
+
except (ValueError, UnicodeError) as exc:
|
|
45
|
+
raise OcrAdapterError("ocr_output_invalid") from exc
|
|
46
|
+
if not isinstance(value, dict) or value.get("schema_version") != "1":
|
|
47
|
+
raise OcrAdapterError("ocr_schema_unsupported")
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _count(value: Any) -> int:
|
|
52
|
+
if type(value) is not int or value < 0 or value > 9_007_199_254_740_991:
|
|
53
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
54
|
+
return value
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _text(value: Any, limit: int) -> str:
|
|
58
|
+
if not isinstance(value, str) or len(value) > limit or "\x00" in value:
|
|
59
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
60
|
+
return value
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _path(value: Any) -> str:
|
|
64
|
+
try:
|
|
65
|
+
value = _text(value, 4096)
|
|
66
|
+
except OcrAdapterError as exc:
|
|
67
|
+
raise OcrAdapterError("ocr_path_invalid") from exc
|
|
68
|
+
path = PurePosixPath(value)
|
|
69
|
+
if not value or path.is_absolute() or "\\" in value or ":" in value:
|
|
70
|
+
raise OcrAdapterError("ocr_path_invalid")
|
|
71
|
+
if any(part in {"", ".", ".."} for part in value.split("/")):
|
|
72
|
+
raise OcrAdapterError("ocr_path_invalid")
|
|
73
|
+
if any(ord(character) < 32 for character in value):
|
|
74
|
+
raise OcrAdapterError("ocr_path_invalid")
|
|
75
|
+
return value
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def parse_ocr_preview(payload: bytes | str, repository: Path) -> dict[str, Any]:
|
|
79
|
+
value = _decode(payload)
|
|
80
|
+
if value.get("mode") != "workspace" or any(value.get(key) for key in ("from", "to", "commit")):
|
|
81
|
+
raise OcrAdapterError("ocr_mode_unsupported")
|
|
82
|
+
returned = Path(_text(value.get("repository"), 4096))
|
|
83
|
+
if not returned.is_absolute() or returned.resolve() != repository.resolve():
|
|
84
|
+
raise OcrAdapterError("ocr_repository_changed")
|
|
85
|
+
paths: set[str] = set()
|
|
86
|
+
for key, count_key in (
|
|
87
|
+
("reviewable_files", "reviewable_count"),
|
|
88
|
+
("excluded_files", "excluded_count"),
|
|
89
|
+
):
|
|
90
|
+
files = value.get(key)
|
|
91
|
+
if (
|
|
92
|
+
not isinstance(files, list)
|
|
93
|
+
or len(files) > OCR_FILE_LIMIT
|
|
94
|
+
or len(files) != _count(value.get(count_key))
|
|
95
|
+
):
|
|
96
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
97
|
+
for entry in files:
|
|
98
|
+
if not isinstance(entry, dict):
|
|
99
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
100
|
+
path = _path(entry.get("path"))
|
|
101
|
+
if path in paths:
|
|
102
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
103
|
+
paths.add(path)
|
|
104
|
+
if not _text(entry.get("status"), 128):
|
|
105
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
106
|
+
_count(entry.get("insertions"))
|
|
107
|
+
_count(entry.get("deletions"))
|
|
108
|
+
if "exclude_reason" in entry:
|
|
109
|
+
_text(entry["exclude_reason"], 2048)
|
|
110
|
+
if _count(value.get("total_files")) != len(paths) or len(paths) > OCR_FILE_LIMIT:
|
|
111
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
112
|
+
_count(value.get("total_insertions"))
|
|
113
|
+
_count(value.get("total_deletions"))
|
|
114
|
+
return value
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def parse_ocr_rules(payload: bytes | str, requested_paths: list[str]) -> dict[str, Any]:
|
|
118
|
+
requested = {_path(path) for path in requested_paths}
|
|
119
|
+
if not requested or len(requested_paths) != len(requested) or len(requested) > OCR_FILE_LIMIT:
|
|
120
|
+
raise OcrAdapterError("ocr_path_invalid")
|
|
121
|
+
value = _decode(payload)
|
|
122
|
+
groups = value.get("groups")
|
|
123
|
+
if not isinstance(groups, list) or len(groups) > OCR_FILE_LIMIT:
|
|
124
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
125
|
+
group_ids: set[int] = set()
|
|
126
|
+
covered: set[str] = set()
|
|
127
|
+
for group in groups:
|
|
128
|
+
if not isinstance(group, dict):
|
|
129
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
130
|
+
group_id = _count(group.get("group_id"))
|
|
131
|
+
if group_id < 1 or group_id in group_ids:
|
|
132
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
133
|
+
group_ids.add(group_id)
|
|
134
|
+
_text(group.get("source"), 4096)
|
|
135
|
+
_text(group.get("pattern"), 4096)
|
|
136
|
+
_text(group.get("rule"), 64 * 1024)
|
|
137
|
+
files = group.get("files")
|
|
138
|
+
if not isinstance(files, list) or len(files) > OCR_FILE_LIMIT:
|
|
139
|
+
raise OcrAdapterError("ocr_output_invalid")
|
|
140
|
+
for entry in files:
|
|
141
|
+
path = _path(entry)
|
|
142
|
+
if path not in requested:
|
|
143
|
+
raise OcrAdapterError("ocr_rule_scope_invalid")
|
|
144
|
+
covered.add(path)
|
|
145
|
+
if covered != requested:
|
|
146
|
+
raise OcrAdapterError("ocr_rule_scope_invalid")
|
|
147
|
+
return value
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
async def _read_output(stream: asyncio.StreamReader, limit: int) -> bytes:
|
|
151
|
+
output = bytearray()
|
|
152
|
+
while True:
|
|
153
|
+
chunk = await stream.read(16 * 1024)
|
|
154
|
+
if not chunk:
|
|
155
|
+
return bytes(output)
|
|
156
|
+
output.extend(chunk)
|
|
157
|
+
if len(output) > limit:
|
|
158
|
+
raise OcrAdapterError("ocr_output_limit")
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
async def _stop_process(process: asyncio.subprocess.Process) -> None:
|
|
162
|
+
if process.returncode is not None:
|
|
163
|
+
return
|
|
164
|
+
try:
|
|
165
|
+
os.killpg(process.pid, signal.SIGTERM)
|
|
166
|
+
await asyncio.wait_for(process.wait(), 1)
|
|
167
|
+
except asyncio.TimeoutError:
|
|
168
|
+
try:
|
|
169
|
+
os.killpg(process.pid, signal.SIGKILL)
|
|
170
|
+
await asyncio.wait_for(process.wait(), 5)
|
|
171
|
+
except (asyncio.TimeoutError, OSError) as exc:
|
|
172
|
+
raise OcrAdapterError("ocr_cleanup_unconfirmed") from exc
|
|
173
|
+
except ProcessLookupError:
|
|
174
|
+
try:
|
|
175
|
+
await asyncio.wait_for(process.wait(), 5)
|
|
176
|
+
except asyncio.TimeoutError as exc:
|
|
177
|
+
raise OcrAdapterError("ocr_cleanup_unconfirmed") from exc
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
async def _command_output(
|
|
181
|
+
command: list[str],
|
|
182
|
+
directory: Path,
|
|
183
|
+
environment: dict[str, str],
|
|
184
|
+
timeout: float,
|
|
185
|
+
lease: ManagedComponentLease | None = None,
|
|
186
|
+
) -> bytes:
|
|
187
|
+
process = None
|
|
188
|
+
observer = None
|
|
189
|
+
readers: list[asyncio.Task] = []
|
|
190
|
+
deadline = asyncio.get_running_loop().time() + timeout
|
|
191
|
+
try:
|
|
192
|
+
if lease is not None:
|
|
193
|
+
lease.verify()
|
|
194
|
+
lease.begin_spawn()
|
|
195
|
+
spawn = asyncio.create_task(
|
|
196
|
+
asyncio.create_subprocess_exec(
|
|
197
|
+
*command,
|
|
198
|
+
cwd=str(directory),
|
|
199
|
+
env=environment,
|
|
200
|
+
stdin=asyncio.subprocess.DEVNULL,
|
|
201
|
+
stdout=asyncio.subprocess.PIPE,
|
|
202
|
+
stderr=asyncio.subprocess.PIPE,
|
|
203
|
+
start_new_session=True,
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
try:
|
|
207
|
+
process = await asyncio.shield(spawn)
|
|
208
|
+
except asyncio.CancelledError:
|
|
209
|
+
process = await spawn
|
|
210
|
+
raise
|
|
211
|
+
if lease is not None:
|
|
212
|
+
lease.record_process(process.pid)
|
|
213
|
+
observer = asyncio.create_task(observe_owned_process(lease, process))
|
|
214
|
+
readers = [
|
|
215
|
+
asyncio.create_task(_read_output(process.stdout, OCR_OUTPUT_LIMIT)),
|
|
216
|
+
asyncio.create_task(_read_output(process.stderr, 64 * 1024)),
|
|
217
|
+
]
|
|
218
|
+
output, _stderr = await asyncio.wait_for(
|
|
219
|
+
asyncio.gather(*readers),
|
|
220
|
+
max(0, deadline - asyncio.get_running_loop().time()),
|
|
221
|
+
)
|
|
222
|
+
await asyncio.wait_for(process.wait(), max(0, deadline - asyncio.get_running_loop().time()))
|
|
223
|
+
if process.returncode != 0:
|
|
224
|
+
raise OcrAdapterError("ocr_execution_failed")
|
|
225
|
+
if lease is not None:
|
|
226
|
+
lease.verify()
|
|
227
|
+
return output
|
|
228
|
+
except asyncio.TimeoutError as exc:
|
|
229
|
+
raise OcrAdapterError("ocr_timeout") from exc
|
|
230
|
+
finally:
|
|
231
|
+
if observer is not None:
|
|
232
|
+
observer.cancel()
|
|
233
|
+
await asyncio.gather(observer, return_exceptions=True)
|
|
234
|
+
try:
|
|
235
|
+
if process is not None:
|
|
236
|
+
await _stop_process(process)
|
|
237
|
+
finally:
|
|
238
|
+
for reader in readers:
|
|
239
|
+
reader.cancel()
|
|
240
|
+
if readers:
|
|
241
|
+
await asyncio.gather(*readers, return_exceptions=True)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
async def run_ocr_delegation(
|
|
245
|
+
lease: ManagedComponentLease,
|
|
246
|
+
repository: Path,
|
|
247
|
+
action: str,
|
|
248
|
+
paths: list[str] | None = None,
|
|
249
|
+
timeout: float = 30,
|
|
250
|
+
) -> dict[str, Any]:
|
|
251
|
+
if os.name != "posix" or os.environ.get("WSL_DISTRO_NAME"):
|
|
252
|
+
raise OcrAdapterError("ocr_platform_unverified")
|
|
253
|
+
release = lease.receipt["release"]
|
|
254
|
+
if release["component_id"] != OCR_COMPONENT_ID or release["kind"] != "plugin":
|
|
255
|
+
raise OcrAdapterError("ocr_instance_changed")
|
|
256
|
+
if (
|
|
257
|
+
not isinstance(action, str)
|
|
258
|
+
or action not in {"preview", "rule"}
|
|
259
|
+
or type(timeout) not in {int, float}
|
|
260
|
+
or not math.isfinite(timeout)
|
|
261
|
+
or timeout <= 0
|
|
262
|
+
or timeout > 60
|
|
263
|
+
):
|
|
264
|
+
raise OcrAdapterError("ocr_request_invalid")
|
|
265
|
+
paths = [] if paths is None else paths
|
|
266
|
+
if (
|
|
267
|
+
not isinstance(paths, list)
|
|
268
|
+
or (action == "preview" and paths)
|
|
269
|
+
or (action == "rule" and not paths)
|
|
270
|
+
or len(paths) > OCR_FILE_LIMIT
|
|
271
|
+
):
|
|
272
|
+
raise OcrAdapterError("ocr_request_invalid")
|
|
273
|
+
for path in paths:
|
|
274
|
+
_path(path)
|
|
275
|
+
if len(set(paths)) != len(paths):
|
|
276
|
+
raise OcrAdapterError("ocr_path_invalid")
|
|
277
|
+
repository = repository.resolve(strict=True)
|
|
278
|
+
if not repository.is_dir():
|
|
279
|
+
raise OcrAdapterError("ocr_repository_changed")
|
|
280
|
+
for path in paths:
|
|
281
|
+
if not (repository / path).resolve().is_relative_to(repository):
|
|
282
|
+
raise OcrAdapterError("ocr_path_invalid")
|
|
283
|
+
git = shutil.which("git")
|
|
284
|
+
if not git:
|
|
285
|
+
raise OcrAdapterError("ocr_git_unavailable")
|
|
286
|
+
with tempfile.TemporaryDirectory(prefix="forgexa-ocr-delegate-") as temporary:
|
|
287
|
+
directory = Path(temporary)
|
|
288
|
+
environment = lease.probe_environment(directory, baseline={})
|
|
289
|
+
environment.update(
|
|
290
|
+
{
|
|
291
|
+
"PATH": f"{Path(git).parent}{os.pathsep}{environment['PATH']}",
|
|
292
|
+
"GIT_CONFIG_NOSYSTEM": "1",
|
|
293
|
+
"GIT_CONFIG_GLOBAL": os.devnull,
|
|
294
|
+
"GIT_TERMINAL_PROMPT": "0",
|
|
295
|
+
}
|
|
296
|
+
)
|
|
297
|
+
version = await _command_output([git, "--version"], directory, environment, 5)
|
|
298
|
+
match = re.match(rb"git version (\d+)\.(\d+)", version)
|
|
299
|
+
if match is None or tuple(int(part) for part in match.groups()) < (2, 41):
|
|
300
|
+
raise OcrAdapterError("ocr_git_incompatible")
|
|
301
|
+
command = [
|
|
302
|
+
*lease.argv_prefix,
|
|
303
|
+
"delegate",
|
|
304
|
+
action,
|
|
305
|
+
"--format",
|
|
306
|
+
"json",
|
|
307
|
+
"--repo",
|
|
308
|
+
str(repository),
|
|
309
|
+
"--max-git-procs",
|
|
310
|
+
"2",
|
|
311
|
+
]
|
|
312
|
+
if paths:
|
|
313
|
+
command.extend(["--", *paths])
|
|
314
|
+
output = await _command_output(command, repository, environment, timeout, lease)
|
|
315
|
+
return (
|
|
316
|
+
parse_ocr_preview(output, repository)
|
|
317
|
+
if action == "preview"
|
|
318
|
+
else parse_ocr_rules(output, paths)
|
|
319
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|