forgexa-cli 1.100.1__tar.gz → 1.101.2__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.100.1 → forgexa_cli-1.101.2}/PKG-INFO +1 -1
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/__init__.py +1 -1
- forgexa_cli-1.101.2/forgexa_cli/code_review_rules.py +122 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/daemon.py +174 -20
- forgexa_cli-1.101.2/forgexa_cli/ocr_adapter.py +1066 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli.egg-info/PKG-INFO +1 -1
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli.egg-info/SOURCES.txt +2 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/pyproject.toml +1 -1
- forgexa_cli-1.101.2/tests/test_delivery_review_packaged.py +73 -0
- forgexa_cli-1.100.1/forgexa_cli/ocr_adapter.py +0 -423
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/README.md +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/_build_config.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/_local_bind.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/agent_core.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/autoupgrade.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/aws_evidence.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/aws_logs_evidence.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/component_runtime.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/main.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/observability_contract.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/observability_evidence.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/py.typed +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/runtime_evidence.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/workspace_storage.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli/zcode_protocol.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli.egg-info/dependency_links.txt +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli.egg-info/entry_points.txt +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli.egg-info/requires.txt +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/forgexa_cli.egg-info/top_level.txt +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/setup.cfg +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_auth_and_runtime_commands.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_autoupgrade.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_check_command.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_expiry_warnings_and_revoke.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_local_bind_commands.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_publish_script.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_runtime_credentials.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_session_credentials.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_silent_install.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_upgrade_observability.py +0 -0
- {forgexa_cli-1.100.1 → forgexa_cli-1.101.2}/tests/test_workspace_storage.py +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""forgexa-cli — Forgexa command-line client."""
|
|
2
|
-
__version__ = "1.
|
|
2
|
+
__version__ = "1.101.2"
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Portable validation and selection for delivery code review rules."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import fnmatch
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
import re
|
|
9
|
+
from copy import deepcopy
|
|
10
|
+
from pathlib import PurePosixPath
|
|
11
|
+
|
|
12
|
+
MAX_RULE_PACKAGE_BYTES = 64 * 1024
|
|
13
|
+
_SECTION_ID = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _canonical_json(value):
|
|
17
|
+
try:
|
|
18
|
+
return json.dumps(
|
|
19
|
+
value, ensure_ascii=False, sort_keys=True, separators=(",", ":"), allow_nan=False
|
|
20
|
+
).encode("utf-8")
|
|
21
|
+
except (TypeError, ValueError, UnicodeError) as error:
|
|
22
|
+
raise ValueError("Invalid review configuration") from error
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def review_config_sha256(config):
|
|
26
|
+
return hashlib.sha256(_canonical_json(config)).hexdigest()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _valid_path(value, *, pattern=False):
|
|
30
|
+
if not isinstance(value, str) or not value or "\\" in value or "\x00" in value:
|
|
31
|
+
return False
|
|
32
|
+
if value.startswith("/") or re.match(r"^[A-Za-z]:", value):
|
|
33
|
+
return False
|
|
34
|
+
if pattern and (value.startswith("!") or any(char in value for char in "{}\n\r")):
|
|
35
|
+
return False
|
|
36
|
+
if any(part in {"", ".", ".."} for part in value.split("/")):
|
|
37
|
+
return False
|
|
38
|
+
return str(PurePosixPath(value)) == value
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def is_valid_review_path(value):
|
|
42
|
+
return _valid_path(value)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def validate_rule_package(template, rule_sections):
|
|
46
|
+
if not isinstance(template, str) or not template.strip() or not isinstance(rule_sections, list):
|
|
47
|
+
raise ValueError("A core rule and a list of rule sections are required")
|
|
48
|
+
seen = set()
|
|
49
|
+
for section in rule_sections:
|
|
50
|
+
if not isinstance(section, dict) or set(section) != {
|
|
51
|
+
"id",
|
|
52
|
+
"title",
|
|
53
|
+
"instructions",
|
|
54
|
+
"applicability",
|
|
55
|
+
}:
|
|
56
|
+
raise ValueError("Invalid rule section")
|
|
57
|
+
section_id = section["id"]
|
|
58
|
+
if (
|
|
59
|
+
not isinstance(section_id, str)
|
|
60
|
+
or not _SECTION_ID.fullmatch(section_id)
|
|
61
|
+
or section_id in seen
|
|
62
|
+
):
|
|
63
|
+
raise ValueError("Rule section IDs must be unique and valid")
|
|
64
|
+
seen.add(section_id)
|
|
65
|
+
if any(
|
|
66
|
+
not isinstance(section[key], str) or not section[key].strip()
|
|
67
|
+
for key in ("title", "instructions")
|
|
68
|
+
):
|
|
69
|
+
raise ValueError("Rule section title and instructions are required")
|
|
70
|
+
applicability = section["applicability"]
|
|
71
|
+
if not isinstance(applicability, dict) or type(applicability.get("always")) is not bool:
|
|
72
|
+
raise ValueError("Invalid rule section applicability")
|
|
73
|
+
if applicability["always"]:
|
|
74
|
+
if set(applicability) != {"always"}:
|
|
75
|
+
raise ValueError("Always-applicable rules cannot specify paths")
|
|
76
|
+
else:
|
|
77
|
+
patterns = applicability.get("path_patterns")
|
|
78
|
+
if (
|
|
79
|
+
set(applicability) != {"always", "path_patterns"}
|
|
80
|
+
or not isinstance(patterns, list)
|
|
81
|
+
or not patterns
|
|
82
|
+
or any(not _valid_path(item, pattern=True) for item in patterns)
|
|
83
|
+
):
|
|
84
|
+
raise ValueError("Path-specific rules require valid repository patterns")
|
|
85
|
+
package = {"template": template, "rule_sections": deepcopy(rule_sections)}
|
|
86
|
+
if len(_canonical_json(package)) > MAX_RULE_PACKAGE_BYTES:
|
|
87
|
+
raise ValueError("Review rule package exceeds 64 KiB")
|
|
88
|
+
return package
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _matches(path, pattern):
|
|
92
|
+
return fnmatch.fnmatchcase(path, pattern) or (
|
|
93
|
+
pattern.startswith("**/") and fnmatch.fnmatchcase(path, pattern[3:])
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def select_rule_sections(rule_sections, changed_paths, recheck_paths):
|
|
98
|
+
paths = list(changed_paths) + list(recheck_paths)
|
|
99
|
+
if any(not _valid_path(path) for path in paths):
|
|
100
|
+
return list(rule_sections)
|
|
101
|
+
return [
|
|
102
|
+
section
|
|
103
|
+
for section in rule_sections
|
|
104
|
+
if section["applicability"]["always"]
|
|
105
|
+
or any(
|
|
106
|
+
_matches(path, pattern)
|
|
107
|
+
for path in paths
|
|
108
|
+
for pattern in section["applicability"]["path_patterns"]
|
|
109
|
+
)
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def assign_recheck_issues(batch_paths, issues):
|
|
114
|
+
if not batch_paths:
|
|
115
|
+
if issues:
|
|
116
|
+
raise ValueError("Recheck issues require a review batch")
|
|
117
|
+
return []
|
|
118
|
+
assignments = [[] for _ in batch_paths]
|
|
119
|
+
batches_by_path = {path: index for index, paths in enumerate(batch_paths) for path in paths}
|
|
120
|
+
for issue in issues:
|
|
121
|
+
assignments[batches_by_path.get(issue.get("file"), 0)].append(issue)
|
|
122
|
+
return assignments
|
|
@@ -83,6 +83,22 @@ except ImportError:
|
|
|
83
83
|
except ImportError:
|
|
84
84
|
import runtime_evidence # type: ignore[no-redef] # flat script layout (desktop resources)
|
|
85
85
|
|
|
86
|
+
try:
|
|
87
|
+
from app import code_review_rules
|
|
88
|
+
except ImportError:
|
|
89
|
+
try:
|
|
90
|
+
from . import code_review_rules # type: ignore[no-redef]
|
|
91
|
+
except ImportError:
|
|
92
|
+
import code_review_rules # type: ignore[no-redef]
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
from app import ocr_adapter
|
|
96
|
+
except ImportError:
|
|
97
|
+
try:
|
|
98
|
+
from . import ocr_adapter # type: ignore[no-redef]
|
|
99
|
+
except ImportError:
|
|
100
|
+
import ocr_adapter # type: ignore[no-redef]
|
|
101
|
+
|
|
86
102
|
try:
|
|
87
103
|
from app.zcode_protocol import (
|
|
88
104
|
ZCodeProtocolError,
|
|
@@ -1412,7 +1428,7 @@ except (ImportError, ModuleNotFoundError):
|
|
|
1412
1428
|
# DAEMON_VERSION is the protocol/logic version of the daemon code.
|
|
1413
1429
|
# Kept in sync with pyproject.toml version via bump-version.sh.
|
|
1414
1430
|
# CLIENT_TYPE identifies which packaging/distribution this daemon runs in.
|
|
1415
|
-
DAEMON_VERSION = "1.
|
|
1431
|
+
DAEMON_VERSION = "1.101.2"
|
|
1416
1432
|
|
|
1417
1433
|
|
|
1418
1434
|
def _detect_client_type() -> str:
|
|
@@ -1840,6 +1856,7 @@ class TaskResult:
|
|
|
1840
1856
|
_RUNTIME_CRITIC_TIMEOUT_SECONDS = 300
|
|
1841
1857
|
_RUNTIME_CRITIC_DIFF_MAX_CHARS = 30_000
|
|
1842
1858
|
_RUNTIME_CRITIC_OUTPUT_MAX_CHARS = 20_000
|
|
1859
|
+
_DELIVERY_REVIEW_PROMPT_MAX_BYTES = 256 * 1024
|
|
1843
1860
|
_RUNTIME_CRITIC_SOURCE_MAX_BYTES = 1_000_000
|
|
1844
1861
|
_RUNTIME_CRITIC_SOURCE_MAX_FILES = 128
|
|
1845
1862
|
_RUNTIME_CRITIC_SOURCE_TIMEOUT_SECONDS = 200
|
|
@@ -6594,7 +6611,7 @@ def _workspace_has_recent_activity(
|
|
|
6594
6611
|
|
|
6595
6612
|
def _delivery_review_capabilities() -> dict:
|
|
6596
6613
|
if sys.platform == "darwin" and shutil.which("sandbox-exec"):
|
|
6597
|
-
return {"delivery_code_review": {"protocol_version": 1}}
|
|
6614
|
+
return {"delivery_code_review": {"protocol_version": 2, "ocr_delegation_version": 1}}
|
|
6598
6615
|
return {}
|
|
6599
6616
|
|
|
6600
6617
|
|
|
@@ -14691,6 +14708,13 @@ class RuntimeDaemon:
|
|
|
14691
14708
|
await git("clone", "--quiet", "--no-hardlinks", "--no-checkout", "--", str(workspace_path), str(sandbox), timeout=120)
|
|
14692
14709
|
await git("checkout", "--quiet", "--detach", expected, cwd=sandbox, timeout=120)
|
|
14693
14710
|
await git("remote", "remove", "origin", cwd=sandbox, timeout=10)
|
|
14711
|
+
if data.get("delivery_code_review_version") == 2:
|
|
14712
|
+
existing = await git(
|
|
14713
|
+
"--literal-pathspecs", "ls-tree", "-r", "--name-only", "-z", expected,
|
|
14714
|
+
"--", *sorted(allowed_paths), cwd=sandbox, timeout=30,
|
|
14715
|
+
)
|
|
14716
|
+
if {path for path in existing.split("\x00") if path} != allowed_paths:
|
|
14717
|
+
return failed("delivery_review_fix_requires_existing_files", "Selected repair files must exist in the reviewed commit")
|
|
14694
14718
|
issues = (data.get("fix_context") or {}).get("issues") or []
|
|
14695
14719
|
prompt = (
|
|
14696
14720
|
"Fix only the selected issues in this isolated copy. Do not edit other files, commit, push, "
|
|
@@ -14709,6 +14733,8 @@ class RuntimeDaemon:
|
|
|
14709
14733
|
status = await git("--no-optional-locks", "status", "--porcelain=v1", "-z", "--untracked-files=all", "--no-renames", cwd=sandbox, timeout=30)
|
|
14710
14734
|
entries = _git_status_entries(status)
|
|
14711
14735
|
new_paths = [path for entry_status, path in entries if entry_status == "??"]
|
|
14736
|
+
if data.get("delivery_code_review_version") == 2 and new_paths:
|
|
14737
|
+
return failed("delivery_review_fix_scope_violation", "The repair created an unapproved file")
|
|
14712
14738
|
if any(path not in allowed_paths for path in new_paths):
|
|
14713
14739
|
return failed("delivery_review_fix_scope_violation", "The repair created an unapproved file")
|
|
14714
14740
|
if new_paths:
|
|
@@ -14729,7 +14755,12 @@ class RuntimeDaemon:
|
|
|
14729
14755
|
remote_lines = [line.split() for line in remote.splitlines() if line.strip()]
|
|
14730
14756
|
if remote_lines != [[expected, f"refs/heads/{branch}"]]:
|
|
14731
14757
|
return failed("delivery_review_candidate_changed", "The remote candidate changed during repair")
|
|
14732
|
-
|
|
14758
|
+
if data.get("delivery_code_review_version") == 2:
|
|
14759
|
+
default_branch = data.get("reviewed_target_branch")
|
|
14760
|
+
if not isinstance(default_branch, str) or not default_branch or default_branch.startswith("-"):
|
|
14761
|
+
return failed("delivery_review_candidate_changed", "The frozen target branch is unavailable")
|
|
14762
|
+
else:
|
|
14763
|
+
default_branch = str((task.project or {}).get("default_branch") or "main")
|
|
14733
14764
|
target = await git("ls-remote", "--refs", "origin", f"refs/heads/{default_branch}", cwd=workspace_path, timeout=60, project_key=project_key)
|
|
14734
14765
|
target_lines = [line.split() for line in target.splitlines() if line.strip()]
|
|
14735
14766
|
if target_lines != [[expected_target, f"refs/heads/{default_branch}"]]:
|
|
@@ -14783,15 +14814,47 @@ class RuntimeDaemon:
|
|
|
14783
14814
|
return failed("delivery_review_fix_failed", "The selected repair could not be applied or pushed")
|
|
14784
14815
|
|
|
14785
14816
|
async def _execute_delivery_code_review(self, task, agent, workspace_path) -> TaskResult:
|
|
14817
|
+
engine_identity = None
|
|
14818
|
+
|
|
14786
14819
|
def failed(code: str, message: str) -> TaskResult:
|
|
14787
14820
|
return TaskResult(status="failed", exit_code=-1, stdout="", stderr="", failure_code=code,
|
|
14788
|
-
error=message, execution_attempt_id=task.execution_attempt_id
|
|
14821
|
+
error=message, execution_attempt_id=task.execution_attempt_id,
|
|
14822
|
+
metrics={"delivery_review_engine_identity": engine_identity} if engine_identity else {})
|
|
14823
|
+
|
|
14824
|
+
def remember_identity(identity):
|
|
14825
|
+
nonlocal engine_identity
|
|
14826
|
+
engine_identity = identity
|
|
14789
14827
|
|
|
14790
14828
|
if str(getattr(agent, "agent_id", "")).lower() != "claude":
|
|
14791
14829
|
return failed("delivery_review_agent_unsupported", "This agent has no verified read-only delivery review mode")
|
|
14792
14830
|
if task.workspace_resolution == "local_bind" and not task.local_evidence_upload:
|
|
14793
14831
|
return failed("delivery_review_local_privacy_required", "Local review results cannot be shared under this project policy")
|
|
14794
|
-
|
|
14832
|
+
data = task.input_data or {}
|
|
14833
|
+
protocol = data.get("delivery_code_review_version", 1)
|
|
14834
|
+
if type(protocol) is not int or protocol not in (1, 2):
|
|
14835
|
+
return failed("delivery_review_scope_incomplete", "The review protocol is unsupported")
|
|
14836
|
+
snapshot = None
|
|
14837
|
+
generation_id = None
|
|
14838
|
+
if protocol == 2:
|
|
14839
|
+
snapshot = data.get("delivery_review_snapshot")
|
|
14840
|
+
try:
|
|
14841
|
+
config = snapshot["config"]
|
|
14842
|
+
if (config["version"] != 2 or config["engine"] not in {"agent", "ocr_delegate"}
|
|
14843
|
+
or code_review_rules.review_config_sha256(config) != snapshot["review_config_sha256"]):
|
|
14844
|
+
raise ValueError("Invalid review identity")
|
|
14845
|
+
if not isinstance(config["context"], dict) or not isinstance(config["additional_instructions"], str):
|
|
14846
|
+
raise ValueError("Invalid review input")
|
|
14847
|
+
code_review_rules.validate_rule_package(
|
|
14848
|
+
config["rule_package"]["template"], config["rule_package"]["rule_sections"]
|
|
14849
|
+
)
|
|
14850
|
+
generation_id = str(UUID(data["review_generation_id"]))
|
|
14851
|
+
default_branch = config["target_branch"]
|
|
14852
|
+
if not isinstance(default_branch, str):
|
|
14853
|
+
raise ValueError("Invalid target branch")
|
|
14854
|
+
except (KeyError, TypeError, ValueError):
|
|
14855
|
+
return failed("delivery_review_scope_incomplete", "The frozen review configuration is invalid")
|
|
14856
|
+
else:
|
|
14857
|
+
default_branch = str((task.project or {}).get("default_branch") or "main").strip()
|
|
14795
14858
|
if not task.workspace_branch or not default_branch or default_branch.startswith("-"):
|
|
14796
14859
|
return failed("delivery_review_scope_incomplete", "The candidate or target branch is unavailable")
|
|
14797
14860
|
|
|
@@ -14858,8 +14921,11 @@ class RuntimeDaemon:
|
|
|
14858
14921
|
logger.warning("Cannot prepare delivery review scope: %s", type(error).__name__)
|
|
14859
14922
|
return failed("delivery_review_scope_incomplete", "The complete candidate diff is unavailable")
|
|
14860
14923
|
|
|
14861
|
-
metadata = {"version":
|
|
14924
|
+
metadata = {"version": protocol, "base_sha": base, "target_sha": target, "head_sha": head,
|
|
14862
14925
|
"changed_files": paths, "reviewed_batches": [batch_paths for batch_paths, _ in batches] if paths else []}
|
|
14926
|
+
if snapshot is not None:
|
|
14927
|
+
metadata.update({"review_config_sha256": snapshot["review_config_sha256"],
|
|
14928
|
+
"review_generation_id": generation_id})
|
|
14863
14929
|
git = {"branch": branch, "before_sha": head, "commit_sha": head, "files_changed": []}
|
|
14864
14930
|
recheck = (task.input_data or {}).get("delivery_review_recheck")
|
|
14865
14931
|
if recheck is not None and (
|
|
@@ -14879,18 +14945,36 @@ class RuntimeDaemon:
|
|
|
14879
14945
|
or any("file" in issue and not isinstance(issue["file"], str) for issue in selected_issues)
|
|
14880
14946
|
or {issue["id"] for issue in selected_issues} != set(selected_ids)):
|
|
14881
14947
|
return failed("delivery_review_scope_incomplete", "The selected recheck issues are invalid")
|
|
14882
|
-
|
|
14883
|
-
|
|
14884
|
-
|
|
14948
|
+
recheck_by_batch = code_review_rules.assign_recheck_issues(
|
|
14949
|
+
[batch_paths for batch_paths, _ in batches], selected_issues,
|
|
14950
|
+
)
|
|
14951
|
+
engine_evidence = None
|
|
14952
|
+
if snapshot is not None and snapshot["config"]["engine"] == "ocr_delegate":
|
|
14953
|
+
try:
|
|
14954
|
+
engine_evidence = await ocr_adapter.run_selected_ocr_range_preview(
|
|
14955
|
+
workspace_path, target, head, base, paths,
|
|
14956
|
+
expected_identity=data.get("delivery_review_engine_identity"),
|
|
14957
|
+
timeout=min(float(task.timeout_seconds or 30), 60), on_identity=remember_identity,
|
|
14958
|
+
)
|
|
14959
|
+
except ocr_adapter.OcrAdapterError as error:
|
|
14960
|
+
return failed(error.code, "Open Code Review could not safely cover the fixed review range")
|
|
14885
14961
|
if not paths and not recheck:
|
|
14962
|
+
if engine_identity:
|
|
14963
|
+
try:
|
|
14964
|
+
await ocr_adapter.verify_selected_ocr_identity(engine_identity)
|
|
14965
|
+
except ocr_adapter.OcrAdapterError as error:
|
|
14966
|
+
return failed(error.code, "The selected Open Code Review instance changed during review")
|
|
14886
14967
|
return TaskResult(status="success", exit_code=0, stdout="", stderr="", git=git,
|
|
14887
|
-
metrics={"delivery_code_review": metadata
|
|
14968
|
+
metrics={"delivery_code_review": metadata,
|
|
14969
|
+
**({"delivery_review_engine_identity": engine_identity,
|
|
14970
|
+
"delivery_review_engine_evidence": engine_evidence} if engine_evidence else {})},
|
|
14971
|
+
has_verified_completion=True,
|
|
14888
14972
|
critic_review={"collection_status": "not_applicable"},
|
|
14889
14973
|
execution_attempt_id=task.execution_attempt_id)
|
|
14890
14974
|
if paths and not diff:
|
|
14891
14975
|
return failed("delivery_review_scope_incomplete", "Changed files have no reviewable diff")
|
|
14892
14976
|
|
|
14893
|
-
context =
|
|
14977
|
+
context = snapshot["config"]["context"] if snapshot is not None else data.get("context") or {}
|
|
14894
14978
|
requirements = context.get("requirement_description") if isinstance(context, dict) else None
|
|
14895
14979
|
if not isinstance(requirements, str) or not requirements.strip():
|
|
14896
14980
|
return failed("delivery_review_scope_incomplete", "The approved requirement context is unavailable")
|
|
@@ -14925,15 +15009,29 @@ class RuntimeDaemon:
|
|
|
14925
15009
|
value[key] = entry
|
|
14926
15010
|
return value
|
|
14927
15011
|
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
|
|
14934
|
-
|
|
15012
|
+
def assemble_prompt(index, batch_paths, batch_diff, batch_recheck):
|
|
15013
|
+
rules = ""
|
|
15014
|
+
section_ids = []
|
|
15015
|
+
if snapshot is not None:
|
|
15016
|
+
config = snapshot["config"]
|
|
15017
|
+
selected_sections = code_review_rules.select_rule_sections(
|
|
15018
|
+
config["rule_package"]["rule_sections"], batch_paths,
|
|
15019
|
+
[issue.get("file") for issue in batch_recheck],
|
|
15020
|
+
)
|
|
15021
|
+
section_ids = [section["id"] for section in selected_sections
|
|
15022
|
+
if not section["applicability"]["always"]]
|
|
15023
|
+
rules = (
|
|
15024
|
+
"\nApproved review rules are subordinate to the platform's fixed scope, "
|
|
15025
|
+
"read-only permissions, output contract and human decisions. "
|
|
15026
|
+
"Report conflicts instead of changing those requirements. "
|
|
15027
|
+
"An issue may include confidence as an integer from 1 to 10; it is a self-assessment, not a gate.\n\nCore rules:\n"
|
|
15028
|
+
+ config["rule_package"]["template"]
|
|
15029
|
+
+ "\n\nProject additions:\n" + config["additional_instructions"]
|
|
15030
|
+
)
|
|
15031
|
+
for section in selected_sections:
|
|
15032
|
+
rules += f"\n\nRule {section['id']}: {section['title']}\n{section['instructions']}"
|
|
15033
|
+
prompt = (prompt_prefix + rules + f"\nReview batch {index + 1} of {len(batches)}; cover these files only:\n"
|
|
14935
15034
|
+ json.dumps(batch_paths, ensure_ascii=True) + f"\n\nComplete batch diff ({base}..{head}):\n{batch_diff}")
|
|
14936
|
-
batch_recheck = recheck_by_batch[index]
|
|
14937
15035
|
if batch_recheck:
|
|
14938
15036
|
prompt += (
|
|
14939
15037
|
"\n\nRecheck every selected original issue against the repair commit. "
|
|
@@ -14943,6 +15041,54 @@ class RuntimeDaemon:
|
|
|
14943
15041
|
"Also report new defects in issues. Selected original issues:\n"
|
|
14944
15042
|
+ json.dumps(batch_recheck, ensure_ascii=False)
|
|
14945
15043
|
)
|
|
15044
|
+
return prompt, section_ids
|
|
15045
|
+
|
|
15046
|
+
while True:
|
|
15047
|
+
batch_prompts = [assemble_prompt(index, batch_paths, batch_diff, recheck_by_batch[index])
|
|
15048
|
+
for index, (batch_paths, batch_diff) in enumerate(batches)]
|
|
15049
|
+
oversized = next((index for index, (prompt, _) in enumerate(batch_prompts)
|
|
15050
|
+
if snapshot is not None and len(prompt.encode("utf-8")) > _DELIVERY_REVIEW_PROMPT_MAX_BYTES), None)
|
|
15051
|
+
if oversized is None:
|
|
15052
|
+
break
|
|
15053
|
+
oversized_paths = batches[oversized][0]
|
|
15054
|
+
if len(oversized_paths) < 2 or len(batches) >= 8:
|
|
15055
|
+
return failed("delivery_review_scope_incomplete", "A complete review prompt exceeds the input budget")
|
|
15056
|
+
file_diffs = []
|
|
15057
|
+
try:
|
|
15058
|
+
for path in oversized_paths:
|
|
15059
|
+
file_diff = await self.workspace_manager._git(
|
|
15060
|
+
"--literal-pathspecs", "diff", "--no-ext-diff", "--no-textconv", "--no-renames", "--unified=3",
|
|
15061
|
+
base, head, "--", path, cwd=workspace_path, timeout=60,
|
|
15062
|
+
)
|
|
15063
|
+
if not file_diff or len(file_diff.encode("utf-8")) > _RUNTIME_CRITIC_DIFF_MAX_CHARS:
|
|
15064
|
+
raise ValueError("Invalid file diff")
|
|
15065
|
+
file_diffs.append(file_diff)
|
|
15066
|
+
except (OSError, RuntimeError, ValueError, UnicodeError):
|
|
15067
|
+
return failed("delivery_review_scope_incomplete", "The complete diff cannot be split safely")
|
|
15068
|
+
midpoint = len(oversized_paths) // 2
|
|
15069
|
+
batches[oversized:oversized + 1] = [
|
|
15070
|
+
(oversized_paths[:midpoint], "".join(file_diffs[:midpoint])),
|
|
15071
|
+
(oversized_paths[midpoint:], "".join(file_diffs[midpoint:])),
|
|
15072
|
+
]
|
|
15073
|
+
recheck_by_batch = code_review_rules.assign_recheck_issues(
|
|
15074
|
+
[batch_paths for batch_paths, _ in batches], selected_issues if recheck else [],
|
|
15075
|
+
)
|
|
15076
|
+
if snapshot is not None:
|
|
15077
|
+
metadata["reviewed_batches"] = [
|
|
15078
|
+
{"paths": batch_paths, "rule_section_ids": batch_prompts[index][1],
|
|
15079
|
+
"recheck_issue_ids": [issue["id"] for issue in recheck_by_batch[index]]}
|
|
15080
|
+
for index, (batch_paths, _) in enumerate(batches)
|
|
15081
|
+
]
|
|
15082
|
+
metadata["prompt_bytes"] = [len(prompt.encode("utf-8")) for prompt, _ in batch_prompts]
|
|
15083
|
+
|
|
15084
|
+
summaries, issues, combined_metrics, rechecked = [], [], {}, []
|
|
15085
|
+
deadline = time.monotonic() + (task.timeout_seconds or settings.AGENT_TIMEOUT)
|
|
15086
|
+
for index, (batch_paths, batch_diff) in enumerate(batches):
|
|
15087
|
+
remaining = int(deadline - time.monotonic())
|
|
15088
|
+
if remaining <= 0:
|
|
15089
|
+
return failed("delivery_review_agent_failed", "Delivery review exceeded its time budget")
|
|
15090
|
+
prompt = batch_prompts[index][0]
|
|
15091
|
+
batch_recheck = recheck_by_batch[index]
|
|
14946
15092
|
review_task = TaskInfo(
|
|
14947
15093
|
task_id=f"{task.task_id}-delivery-review-{index + 1}", graph_id=task.graph_id,
|
|
14948
15094
|
node_type="delivery_code_review", agent_type="claude", input_prompt=prompt,
|
|
@@ -14991,8 +15137,16 @@ class RuntimeDaemon:
|
|
|
14991
15137
|
report["rechecked_issues"] = rechecked
|
|
14992
15138
|
if len(issues) > 100 or len(json.dumps(report, ensure_ascii=False).encode("utf-8")) > 100_000:
|
|
14993
15139
|
return failed("delivery_review_output_invalid", "The complete review result exceeds the available output scope")
|
|
15140
|
+
if engine_identity:
|
|
15141
|
+
try:
|
|
15142
|
+
await ocr_adapter.verify_selected_ocr_identity(engine_identity)
|
|
15143
|
+
except ocr_adapter.OcrAdapterError as error:
|
|
15144
|
+
return failed(error.code, "The selected Open Code Review instance changed during review")
|
|
14994
15145
|
return TaskResult(status="success", exit_code=0, stdout="", stderr="", git=git,
|
|
14995
|
-
metrics={**combined_metrics, "delivery_code_review": metadata
|
|
15146
|
+
metrics={**combined_metrics, "delivery_code_review": metadata,
|
|
15147
|
+
**({"delivery_review_engine_identity": engine_identity,
|
|
15148
|
+
"delivery_review_engine_evidence": engine_evidence} if engine_evidence else {})},
|
|
15149
|
+
has_verified_completion=True,
|
|
14996
15150
|
critic_review={"collection_status": "completed", "result": report, "agent_used": "claude"},
|
|
14997
15151
|
execution_attempt_id=task.execution_attempt_id)
|
|
14998
15152
|
|