forgexa-cli 1.97.4__tar.gz → 1.98.1__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.97.4 → forgexa_cli-1.98.1}/PKG-INFO +1 -1
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/__init__.py +1 -1
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/agent_core.py +4 -1
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/component_runtime.py +153 -2
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/daemon.py +1 -1
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/main.py +10 -2
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/ocr_adapter.py +111 -8
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli.egg-info/PKG-INFO +1 -1
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/pyproject.toml +1 -1
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_check_command.py +14 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/README.md +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/_build_config.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/_local_bind.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/autoupgrade.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/aws_evidence.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/aws_logs_evidence.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/observability_contract.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/observability_evidence.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/py.typed +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/runtime_evidence.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli/zcode_protocol.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli.egg-info/SOURCES.txt +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli.egg-info/dependency_links.txt +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli.egg-info/entry_points.txt +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli.egg-info/requires.txt +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/forgexa_cli.egg-info/top_level.txt +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/setup.cfg +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_auth_and_runtime_commands.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_autoupgrade.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_expiry_warnings_and_revoke.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_local_bind_commands.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_publish_script.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_runtime_credentials.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_session_credentials.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_silent_install.py +0 -0
- {forgexa_cli-1.97.4 → forgexa_cli-1.98.1}/tests/test_upgrade_observability.py +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""forgexa-cli — Forgexa command-line client."""
|
|
2
|
-
__version__ = "1.
|
|
2
|
+
__version__ = "1.98.1"
|
|
@@ -5483,6 +5483,8 @@ _UNVERIFIED_AGENT_LIVE_GATE_REASONS = {
|
|
|
5483
5483
|
),
|
|
5484
5484
|
}
|
|
5485
5485
|
|
|
5486
|
+
DESKTOP_LIVE_APPROVAL_AGENTS = frozenset({"gemini"})
|
|
5487
|
+
|
|
5486
5488
|
AGENT_LIVE_VERIFIED_FILE = Path.home() / ".forgexa" / "agent-live-verified"
|
|
5487
5489
|
|
|
5488
5490
|
|
|
@@ -5498,7 +5500,8 @@ def agent_live_gate_approved(agent_id: str, env: dict[str, str] | None = None) -
|
|
|
5498
5500
|
the class-level ``integration_verified`` flag, and returning True
|
|
5499
5501
|
would silently disarm it for any driver marked unverified.
|
|
5500
5502
|
"""
|
|
5501
|
-
|
|
5503
|
+
eligible_agents = set(_UNVERIFIED_AGENT_LIVE_GATE_REASONS) | DESKTOP_LIVE_APPROVAL_AGENTS
|
|
5504
|
+
if agent_id.lower() not in eligible_agents:
|
|
5502
5505
|
return False
|
|
5503
5506
|
source_env = os.environ if env is None else env
|
|
5504
5507
|
verified = {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
+
import ctypes
|
|
5
|
+
import errno
|
|
4
6
|
import hashlib
|
|
5
7
|
import json
|
|
6
8
|
import math
|
|
@@ -547,10 +549,82 @@ def _component_target(root: Path) -> dict[str, Any]:
|
|
|
547
549
|
return target
|
|
548
550
|
|
|
549
551
|
|
|
550
|
-
|
|
552
|
+
class _DarwinProcessInfo(ctypes.Structure):
|
|
553
|
+
_fields_ = [
|
|
554
|
+
("flags", ctypes.c_uint32),
|
|
555
|
+
("status", ctypes.c_uint32),
|
|
556
|
+
("exit_status", ctypes.c_uint32),
|
|
557
|
+
("pid", ctypes.c_uint32),
|
|
558
|
+
("parent_pid", ctypes.c_uint32),
|
|
559
|
+
("uid", ctypes.c_uint32),
|
|
560
|
+
("gid", ctypes.c_uint32),
|
|
561
|
+
("real_uid", ctypes.c_uint32),
|
|
562
|
+
("real_gid", ctypes.c_uint32),
|
|
563
|
+
("saved_uid", ctypes.c_uint32),
|
|
564
|
+
("saved_gid", ctypes.c_uint32),
|
|
565
|
+
("reserved", ctypes.c_uint32),
|
|
566
|
+
("command", ctypes.c_char * 16),
|
|
567
|
+
("name", ctypes.c_char * 32),
|
|
568
|
+
("files", ctypes.c_uint32),
|
|
569
|
+
("group", ctypes.c_uint32),
|
|
570
|
+
("jobs", ctypes.c_uint32),
|
|
571
|
+
("terminal", ctypes.c_uint32),
|
|
572
|
+
("terminal_group", ctypes.c_uint32),
|
|
573
|
+
("nice", ctypes.c_int32),
|
|
574
|
+
("start_seconds", ctypes.c_uint64),
|
|
575
|
+
("start_microseconds", ctypes.c_uint64),
|
|
576
|
+
]
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def _darwin_process_start_identity(process_id: int) -> str:
|
|
580
|
+
library = ctypes.CDLL("/usr/lib/libproc.dylib", use_errno=True)
|
|
581
|
+
function = library.proc_pidinfo
|
|
582
|
+
function.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64, ctypes.c_void_p, ctypes.c_int]
|
|
583
|
+
function.restype = ctypes.c_int
|
|
584
|
+
info = _DarwinProcessInfo()
|
|
585
|
+
ctypes.set_errno(0)
|
|
586
|
+
length = function(process_id, 3, 0, ctypes.byref(info), ctypes.sizeof(info))
|
|
587
|
+
if length != ctypes.sizeof(info) or info.pid != process_id:
|
|
588
|
+
error = ctypes.get_errno()
|
|
589
|
+
if error in {errno.ESRCH, errno.ENOENT}:
|
|
590
|
+
raise ProcessLookupError(error, "process unavailable")
|
|
591
|
+
raise OSError(error or errno.EIO, "process identity unavailable")
|
|
592
|
+
if info.start_seconds == 0 or info.start_microseconds >= 1_000_000:
|
|
593
|
+
raise ValueError("invalid process creation time")
|
|
594
|
+
return f"process-darwin-{process_id}-{info.start_seconds:016x}-{info.start_microseconds:08x}"
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
def _linux_process_start_identity(process_id: int, proc_root: Path = Path("/proc")) -> str:
|
|
598
|
+
boot = (proc_root / "sys/kernel/random/boot_id").read_text(encoding="ascii")
|
|
599
|
+
boot = boot.strip().replace("-", "")
|
|
600
|
+
if not re.fullmatch(r"[a-f0-9]{32}", boot):
|
|
601
|
+
raise ValueError("invalid boot identity")
|
|
602
|
+
stat = (proc_root / str(process_id) / "stat").read_text(encoding="ascii")
|
|
603
|
+
if not stat.startswith(f"{process_id} (") or ") " not in stat:
|
|
604
|
+
raise ValueError("invalid process stat")
|
|
605
|
+
fields = stat.rpartition(") ")[2].split()
|
|
606
|
+
if len(fields) <= 19 or not fields[19].isdigit():
|
|
607
|
+
raise ValueError("invalid process start")
|
|
608
|
+
started = int(fields[19])
|
|
609
|
+
if not 0 < started < 2**64:
|
|
610
|
+
raise ValueError("invalid process start")
|
|
611
|
+
return f"process-linux-{process_id}-{boot}-{started:016x}"
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
def _process_start_identity(process_id: int, *, proc_root: Path = Path("/proc")) -> str:
|
|
551
615
|
try:
|
|
552
616
|
import psutil
|
|
553
617
|
except ImportError as error:
|
|
618
|
+
if sys.platform == "linux":
|
|
619
|
+
try:
|
|
620
|
+
return _linux_process_start_identity(process_id, proc_root)
|
|
621
|
+
except (OSError, ValueError, UnicodeError) as proc_error:
|
|
622
|
+
raise ComponentRuntimeError("component_process_identity_unverified") from proc_error
|
|
623
|
+
if sys.platform == "darwin":
|
|
624
|
+
try:
|
|
625
|
+
return _darwin_process_start_identity(process_id)
|
|
626
|
+
except (OSError, ValueError) as proc_error:
|
|
627
|
+
raise ComponentRuntimeError("component_process_identity_unverified") from proc_error
|
|
554
628
|
raise ComponentRuntimeError("component_process_identity_unverified") from error
|
|
555
629
|
try:
|
|
556
630
|
created = psutil.Process(process_id).create_time()
|
|
@@ -561,9 +635,29 @@ def _process_start_identity(process_id: int) -> str:
|
|
|
561
635
|
return f"process-{process_id}-{struct.pack('!d', created).hex()}"
|
|
562
636
|
|
|
563
637
|
|
|
564
|
-
def _identity_alive(
|
|
638
|
+
def _identity_alive(
|
|
639
|
+
process_id: int, identity: str | None, *, proc_root: Path = Path("/proc"),
|
|
640
|
+
) -> bool | None:
|
|
565
641
|
if identity is None:
|
|
566
642
|
return None
|
|
643
|
+
if identity.startswith("process-darwin-"):
|
|
644
|
+
if sys.platform != "darwin" or not identity.startswith(f"process-darwin-{process_id}-"):
|
|
645
|
+
return None
|
|
646
|
+
try:
|
|
647
|
+
return identity == _darwin_process_start_identity(process_id)
|
|
648
|
+
except ProcessLookupError:
|
|
649
|
+
return False
|
|
650
|
+
except (OSError, ValueError):
|
|
651
|
+
return None
|
|
652
|
+
if identity.startswith("process-linux-"):
|
|
653
|
+
if sys.platform != "linux" or not identity.startswith(f"process-linux-{process_id}-"):
|
|
654
|
+
return None
|
|
655
|
+
try:
|
|
656
|
+
return identity == _linux_process_start_identity(process_id, proc_root)
|
|
657
|
+
except FileNotFoundError as error:
|
|
658
|
+
return False if error.filename == str(proc_root / str(process_id) / "stat") else None
|
|
659
|
+
except (OSError, ValueError, UnicodeError):
|
|
660
|
+
return None
|
|
567
661
|
try:
|
|
568
662
|
import psutil
|
|
569
663
|
except ImportError:
|
|
@@ -981,6 +1075,63 @@ def acquire_component(
|
|
|
981
1075
|
raise ComponentRuntimeError("component_storage_unavailable") from error
|
|
982
1076
|
|
|
983
1077
|
|
|
1078
|
+
def require_external_selection(
|
|
1079
|
+
component_id: str, revision: int, root: Path | None = None, *, allow_disabled: bool = False,
|
|
1080
|
+
) -> str | None:
|
|
1081
|
+
_identifier(component_id)
|
|
1082
|
+
if type(revision) is not int or not 1 <= revision <= 9_007_199_254_740_991:
|
|
1083
|
+
raise ComponentRuntimeError("component_selection_changed")
|
|
1084
|
+
root = default_store_root() if root is None else root
|
|
1085
|
+
if root.is_symlink():
|
|
1086
|
+
raise ComponentRuntimeError("component_storage_invalid")
|
|
1087
|
+
if not root.exists():
|
|
1088
|
+
raise ComponentRuntimeError("component_selection_changed")
|
|
1089
|
+
if os.name != "posix" or os.environ.get("WSL_DISTRO_NAME"):
|
|
1090
|
+
raise ComponentRuntimeError("component_platform_unverified")
|
|
1091
|
+
try:
|
|
1092
|
+
with _ComponentManagerLock(root):
|
|
1093
|
+
target = _component_target(root)
|
|
1094
|
+
selection = _record(
|
|
1095
|
+
root / "selections" / f"{component_id}.json",
|
|
1096
|
+
{
|
|
1097
|
+
"schema_version",
|
|
1098
|
+
"target_id",
|
|
1099
|
+
"component_id",
|
|
1100
|
+
"revision",
|
|
1101
|
+
"installation_id",
|
|
1102
|
+
"enabled",
|
|
1103
|
+
},
|
|
1104
|
+
optional_fields={"external", "external_path"},
|
|
1105
|
+
)
|
|
1106
|
+
if (
|
|
1107
|
+
selection is None
|
|
1108
|
+
or selection["target_id"] != target["target_id"]
|
|
1109
|
+
or selection["component_id"] != component_id
|
|
1110
|
+
or type(selection["revision"]) is not int
|
|
1111
|
+
or selection["revision"] != revision
|
|
1112
|
+
or type(selection["enabled"]) is not bool
|
|
1113
|
+
or selection.get("external") is not True
|
|
1114
|
+
or selection["installation_id"] is not None
|
|
1115
|
+
):
|
|
1116
|
+
raise ComponentRuntimeError("component_selection_changed")
|
|
1117
|
+
if not selection["enabled"] and not allow_disabled:
|
|
1118
|
+
raise ComponentRuntimeError("component_disabled")
|
|
1119
|
+
path = selection.get("external_path")
|
|
1120
|
+
if path is not None and (
|
|
1121
|
+
component_id != "forgexa.ocr" or not isinstance(path, str)
|
|
1122
|
+
or not path.startswith("/") or len(path.encode("utf-8")) > 4096
|
|
1123
|
+
or any(
|
|
1124
|
+
ord(character) < 32 or ord(character) == 127 or character == ":"
|
|
1125
|
+
for character in path
|
|
1126
|
+
)
|
|
1127
|
+
or any(part in {"", ".", ".."} for part in path.split("/")[1:])
|
|
1128
|
+
):
|
|
1129
|
+
raise ComponentRuntimeError("component_selection_changed")
|
|
1130
|
+
return path
|
|
1131
|
+
except OSError as error:
|
|
1132
|
+
raise ComponentRuntimeError("component_storage_unavailable") from error
|
|
1133
|
+
|
|
1134
|
+
|
|
984
1135
|
def validate_external_executable(binary_path: str, root: Path | None = None) -> None:
|
|
985
1136
|
root = default_store_root() if root is None else root
|
|
986
1137
|
try:
|
|
@@ -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.
|
|
1415
|
+
DAEMON_VERSION = "1.98.1"
|
|
1416
1416
|
|
|
1417
1417
|
|
|
1418
1418
|
def _detect_client_type() -> str:
|
|
@@ -3785,7 +3785,10 @@ def cmd_agent_approve_live(args: argparse.Namespace) -> None:
|
|
|
3785
3785
|
print(f"runtime version: {information['version']}; Node: {information['node_version']}")
|
|
3786
3786
|
print("This records your attestation, not an automatic live test. Only approve after start/resume/cancel/isolation acceptance.")
|
|
3787
3787
|
return
|
|
3788
|
-
gated =
|
|
3788
|
+
gated = (
|
|
3789
|
+
set(agent_core._UNVERIFIED_AGENT_LIVE_GATE_REASONS)
|
|
3790
|
+
| agent_core.DESKTOP_LIVE_APPROVAL_AGENTS
|
|
3791
|
+
)
|
|
3789
3792
|
if agent_id not in gated:
|
|
3790
3793
|
print(
|
|
3791
3794
|
f"error: unknown gated agent '{agent_id}'; gated agents: {', '.join(sorted(gated))}",
|
|
@@ -3802,6 +3805,8 @@ def cmd_agent_approve_live(args: argparse.Namespace) -> None:
|
|
|
3802
3805
|
line.split("#", 1)[0].strip().lower()
|
|
3803
3806
|
for line in existing.splitlines() if line.split("#", 1)[0].strip()
|
|
3804
3807
|
}
|
|
3808
|
+
if agent_id == "gemini":
|
|
3809
|
+
print("This approval applies to any Gemini build; repeat acceptance after CLI changes.")
|
|
3805
3810
|
if agent_id in approved:
|
|
3806
3811
|
print(f"already live-verified: {agent_id}")
|
|
3807
3812
|
print(f"allowlist file: {path}")
|
|
@@ -4060,7 +4065,10 @@ def main() -> None:
|
|
|
4060
4065
|
)
|
|
4061
4066
|
agent_approve_live_p.add_argument(
|
|
4062
4067
|
"agent_id", metavar="AGENT_ID",
|
|
4063
|
-
help=
|
|
4068
|
+
help=(
|
|
4069
|
+
"Gated agent id (e.g. gemini, trae, zcode, deepseek, minimax; "
|
|
4070
|
+
"legacy deepseek-harness accepted)"
|
|
4071
|
+
),
|
|
4064
4072
|
)
|
|
4065
4073
|
agent_approve_live_p.add_argument("--binary", default=None, metavar="PATH", help="Installed CLI binary for build-scoped acceptance")
|
|
4066
4074
|
agent_approve_live_p.add_argument("--evidence", default=None, metavar="PATH", help="Required MiniMax build/profile-bound live safety evidence JSON")
|
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
+
import hashlib
|
|
4
5
|
import json
|
|
5
6
|
import math
|
|
6
7
|
import os
|
|
7
8
|
import re
|
|
8
9
|
import shutil
|
|
9
10
|
import signal
|
|
11
|
+
import stat
|
|
10
12
|
import tempfile
|
|
11
13
|
from pathlib import Path, PurePosixPath
|
|
12
14
|
from typing import Any
|
|
13
15
|
|
|
14
16
|
if __package__:
|
|
15
|
-
from .component_runtime import
|
|
17
|
+
from .component_runtime import (
|
|
18
|
+
ComponentRuntimeError,
|
|
19
|
+
ManagedComponentLease,
|
|
20
|
+
observe_owned_process,
|
|
21
|
+
validate_external_executable,
|
|
22
|
+
)
|
|
16
23
|
else:
|
|
17
|
-
from component_runtime import
|
|
24
|
+
from component_runtime import (
|
|
25
|
+
ComponentRuntimeError,
|
|
26
|
+
ManagedComponentLease,
|
|
27
|
+
observe_owned_process,
|
|
28
|
+
validate_external_executable,
|
|
29
|
+
)
|
|
18
30
|
|
|
19
31
|
OCR_COMPONENT_ID = "forgexa.ocr"
|
|
20
32
|
OCR_OUTPUT_LIMIT = 1024 * 1024
|
|
@@ -242,17 +254,30 @@ async def _command_output(
|
|
|
242
254
|
|
|
243
255
|
|
|
244
256
|
async def run_ocr_delegation(
|
|
245
|
-
lease: ManagedComponentLease,
|
|
257
|
+
lease: ManagedComponentLease | None,
|
|
246
258
|
repository: Path,
|
|
247
259
|
action: str,
|
|
248
260
|
paths: list[str] | None = None,
|
|
249
261
|
timeout: float = 30,
|
|
262
|
+
*,
|
|
263
|
+
external_executable: Path | None = None,
|
|
264
|
+
expected_external_instance: str | None = None,
|
|
250
265
|
) -> dict[str, Any]:
|
|
251
266
|
if os.name != "posix" or os.environ.get("WSL_DISTRO_NAME"):
|
|
252
267
|
raise OcrAdapterError("ocr_platform_unverified")
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
268
|
+
if (lease is None) == (external_executable is None):
|
|
269
|
+
raise OcrAdapterError("ocr_instance_unavailable")
|
|
270
|
+
if lease is not None:
|
|
271
|
+
release = lease.receipt["release"]
|
|
272
|
+
if release["component_id"] != OCR_COMPONENT_ID or release["kind"] != "plugin":
|
|
273
|
+
raise OcrAdapterError("ocr_instance_changed")
|
|
274
|
+
else:
|
|
275
|
+
external_identity = _external_identity(external_executable)
|
|
276
|
+
if (
|
|
277
|
+
expected_external_instance is not None
|
|
278
|
+
and _identity_digest(external_identity) != expected_external_instance
|
|
279
|
+
):
|
|
280
|
+
raise OcrAdapterError("ocr_instance_changed")
|
|
256
281
|
if (
|
|
257
282
|
not isinstance(action, str)
|
|
258
283
|
or action not in {"preview", "rule"}
|
|
@@ -285,7 +310,11 @@ async def run_ocr_delegation(
|
|
|
285
310
|
raise OcrAdapterError("ocr_git_unavailable")
|
|
286
311
|
with tempfile.TemporaryDirectory(prefix="forgexa-ocr-delegate-") as temporary:
|
|
287
312
|
directory = Path(temporary)
|
|
288
|
-
environment =
|
|
313
|
+
environment = (
|
|
314
|
+
lease.probe_environment(directory, baseline={})
|
|
315
|
+
if lease is not None
|
|
316
|
+
else _external_environment(external_executable, directory)
|
|
317
|
+
)
|
|
289
318
|
environment.update(
|
|
290
319
|
{
|
|
291
320
|
"PATH": f"{Path(git).parent}{os.pathsep}{environment['PATH']}",
|
|
@@ -299,7 +328,7 @@ async def run_ocr_delegation(
|
|
|
299
328
|
if match is None or tuple(int(part) for part in match.groups()) < (2, 41):
|
|
300
329
|
raise OcrAdapterError("ocr_git_incompatible")
|
|
301
330
|
command = [
|
|
302
|
-
*lease.argv_prefix,
|
|
331
|
+
*(lease.argv_prefix if lease is not None else [str(external_executable)]),
|
|
303
332
|
"delegate",
|
|
304
333
|
action,
|
|
305
334
|
"--format",
|
|
@@ -312,8 +341,82 @@ async def run_ocr_delegation(
|
|
|
312
341
|
if paths:
|
|
313
342
|
command.extend(["--", *paths])
|
|
314
343
|
output = await _command_output(command, repository, environment, timeout, lease)
|
|
344
|
+
if lease is None and _external_identity(external_executable) != external_identity:
|
|
345
|
+
raise OcrAdapterError("ocr_instance_changed")
|
|
315
346
|
return (
|
|
316
347
|
parse_ocr_preview(output, repository)
|
|
317
348
|
if action == "preview"
|
|
318
349
|
else parse_ocr_rules(output, paths)
|
|
319
350
|
)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def _external_environment(executable: Path, directory: Path) -> dict[str, str]:
|
|
354
|
+
paths = [str(executable.parent), os.defpath]
|
|
355
|
+
node = shutil.which("node")
|
|
356
|
+
if node and Path(node).is_absolute():
|
|
357
|
+
try:
|
|
358
|
+
validate_external_executable(node)
|
|
359
|
+
except ComponentRuntimeError:
|
|
360
|
+
pass
|
|
361
|
+
else:
|
|
362
|
+
paths.insert(0, str(Path(node).parent))
|
|
363
|
+
return {
|
|
364
|
+
"PATH": os.pathsep.join(paths),
|
|
365
|
+
"HOME": str(directory),
|
|
366
|
+
"TMPDIR": str(directory),
|
|
367
|
+
"BUN_TMPDIR": str(directory),
|
|
368
|
+
"DISABLE_UPDATES": "1",
|
|
369
|
+
"DISABLE_AUTOUPDATER": "1",
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def _identity_digest(identity: tuple[str, int, int, int, int]) -> str:
|
|
374
|
+
return hashlib.sha256(json.dumps(identity, separators=(",", ":")).encode()).hexdigest()
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
async def probe_external_ocr(executable: Path | None = None) -> dict[str, str] | None:
|
|
378
|
+
found = str(executable) if executable is not None else shutil.which("ocr")
|
|
379
|
+
if not found:
|
|
380
|
+
return None
|
|
381
|
+
executable = Path(found)
|
|
382
|
+
if not executable.is_absolute():
|
|
383
|
+
raise OcrAdapterError("ocr_instance_unavailable")
|
|
384
|
+
identity = _external_identity(executable)
|
|
385
|
+
with tempfile.TemporaryDirectory(prefix="forgexa-ocr-probe-") as temporary:
|
|
386
|
+
directory = Path(temporary)
|
|
387
|
+
output = await _command_output(
|
|
388
|
+
[str(executable), "--version"],
|
|
389
|
+
directory,
|
|
390
|
+
_external_environment(executable, directory),
|
|
391
|
+
10,
|
|
392
|
+
)
|
|
393
|
+
if _external_identity(executable) != identity:
|
|
394
|
+
raise OcrAdapterError("ocr_instance_changed")
|
|
395
|
+
match = re.search(rb"(?<!\d)(\d{1,20}\.\d{1,20}\.\d{1,20})(?!\d)", output)
|
|
396
|
+
if match is None:
|
|
397
|
+
raise OcrAdapterError("ocr_version_unverified")
|
|
398
|
+
return {
|
|
399
|
+
"binary_path": str(executable),
|
|
400
|
+
"version": match.group(1).decode("ascii"),
|
|
401
|
+
"instance_id": _identity_digest(identity),
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def _external_identity(executable: Path | None) -> tuple[str, int, int, int, int]:
|
|
406
|
+
if executable is None or not executable.is_absolute():
|
|
407
|
+
raise OcrAdapterError("ocr_instance_unavailable")
|
|
408
|
+
try:
|
|
409
|
+
validate_external_executable(str(executable))
|
|
410
|
+
resolved = executable.resolve(strict=True)
|
|
411
|
+
metadata = resolved.stat()
|
|
412
|
+
if not stat.S_ISREG(metadata.st_mode) or not os.access(resolved, os.X_OK):
|
|
413
|
+
raise OcrAdapterError("ocr_instance_unavailable")
|
|
414
|
+
return (
|
|
415
|
+
str(resolved),
|
|
416
|
+
metadata.st_dev,
|
|
417
|
+
metadata.st_ino,
|
|
418
|
+
metadata.st_size,
|
|
419
|
+
metadata.st_mtime_ns,
|
|
420
|
+
)
|
|
421
|
+
except (OSError, RuntimeError, ComponentRuntimeError) as error:
|
|
422
|
+
raise OcrAdapterError("ocr_instance_unavailable") from error
|
|
@@ -57,6 +57,20 @@ def test_minimax_agent_only_approval_is_refused(monkeypatch, capsys):
|
|
|
57
57
|
approve.assert_not_called()
|
|
58
58
|
|
|
59
59
|
|
|
60
|
+
def test_gemini_live_approval_requires_explicit_operator_action(tmp_path, monkeypatch, capsys):
|
|
61
|
+
from forgexa_cli import agent_core
|
|
62
|
+
|
|
63
|
+
approval = tmp_path / "agent-live-verified"
|
|
64
|
+
monkeypatch.setattr(agent_core, "AGENT_LIVE_VERIFIED_FILE", approval)
|
|
65
|
+
monkeypatch.delenv("FORGEXA_AGENT_LIVE_VERIFIED", raising=False)
|
|
66
|
+
assert not agent_core.agent_live_gate_approved("gemini")
|
|
67
|
+
main.cmd_agent_approve_live(SimpleNamespace(agent_id="gemini"))
|
|
68
|
+
assert agent_core.agent_live_gate_approved("gemini")
|
|
69
|
+
output = capsys.readouterr().out
|
|
70
|
+
assert "only do this after" in output
|
|
71
|
+
assert "approval applies to any Gemini build" in output
|
|
72
|
+
|
|
73
|
+
|
|
60
74
|
def test_minimax_live_approval_forwards_bound_evidence(tmp_path, monkeypatch, capsys):
|
|
61
75
|
from forgexa_cli import agent_core
|
|
62
76
|
|
|
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
|