forgexa-cli 1.100.0__tar.gz → 1.101.0__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.0 → forgexa_cli-1.101.0}/PKG-INFO +1 -1
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/__init__.py +1 -1
- forgexa_cli-1.101.0/forgexa_cli/code_review_rules.py +118 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/daemon.py +129 -17
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli.egg-info/PKG-INFO +1 -1
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli.egg-info/SOURCES.txt +1 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/pyproject.toml +1 -1
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/README.md +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/_build_config.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/_local_bind.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/agent_core.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/autoupgrade.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/aws_evidence.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/aws_logs_evidence.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/component_runtime.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/main.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/observability_contract.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/observability_evidence.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/ocr_adapter.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/py.typed +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/runtime_evidence.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/workspace_storage.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli/zcode_protocol.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli.egg-info/dependency_links.txt +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli.egg-info/entry_points.txt +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli.egg-info/requires.txt +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/forgexa_cli.egg-info/top_level.txt +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/setup.cfg +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_auth_and_runtime_commands.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_autoupgrade.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_check_command.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_expiry_warnings_and_revoke.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_local_bind_commands.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_publish_script.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_runtime_credentials.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_session_credentials.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_silent_install.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/tests/test_upgrade_observability.py +0 -0
- {forgexa_cli-1.100.0 → forgexa_cli-1.101.0}/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.0"
|
|
@@ -0,0 +1,118 @@
|
|
|
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 validate_rule_package(template, rule_sections):
|
|
42
|
+
if not isinstance(template, str) or not template.strip() or not isinstance(rule_sections, list):
|
|
43
|
+
raise ValueError("A core rule and a list of rule sections are required")
|
|
44
|
+
seen = set()
|
|
45
|
+
for section in rule_sections:
|
|
46
|
+
if not isinstance(section, dict) or set(section) != {
|
|
47
|
+
"id",
|
|
48
|
+
"title",
|
|
49
|
+
"instructions",
|
|
50
|
+
"applicability",
|
|
51
|
+
}:
|
|
52
|
+
raise ValueError("Invalid rule section")
|
|
53
|
+
section_id = section["id"]
|
|
54
|
+
if (
|
|
55
|
+
not isinstance(section_id, str)
|
|
56
|
+
or not _SECTION_ID.fullmatch(section_id)
|
|
57
|
+
or section_id in seen
|
|
58
|
+
):
|
|
59
|
+
raise ValueError("Rule section IDs must be unique and valid")
|
|
60
|
+
seen.add(section_id)
|
|
61
|
+
if any(
|
|
62
|
+
not isinstance(section[key], str) or not section[key].strip()
|
|
63
|
+
for key in ("title", "instructions")
|
|
64
|
+
):
|
|
65
|
+
raise ValueError("Rule section title and instructions are required")
|
|
66
|
+
applicability = section["applicability"]
|
|
67
|
+
if not isinstance(applicability, dict) or type(applicability.get("always")) is not bool:
|
|
68
|
+
raise ValueError("Invalid rule section applicability")
|
|
69
|
+
if applicability["always"]:
|
|
70
|
+
if set(applicability) != {"always"}:
|
|
71
|
+
raise ValueError("Always-applicable rules cannot specify paths")
|
|
72
|
+
else:
|
|
73
|
+
patterns = applicability.get("path_patterns")
|
|
74
|
+
if (
|
|
75
|
+
set(applicability) != {"always", "path_patterns"}
|
|
76
|
+
or not isinstance(patterns, list)
|
|
77
|
+
or not patterns
|
|
78
|
+
or any(not _valid_path(item, pattern=True) for item in patterns)
|
|
79
|
+
):
|
|
80
|
+
raise ValueError("Path-specific rules require valid repository patterns")
|
|
81
|
+
package = {"template": template, "rule_sections": deepcopy(rule_sections)}
|
|
82
|
+
if len(_canonical_json(package)) > MAX_RULE_PACKAGE_BYTES:
|
|
83
|
+
raise ValueError("Review rule package exceeds 64 KiB")
|
|
84
|
+
return package
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _matches(path, pattern):
|
|
88
|
+
return fnmatch.fnmatchcase(path, pattern) or (
|
|
89
|
+
pattern.startswith("**/") and fnmatch.fnmatchcase(path, pattern[3:])
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def select_rule_sections(rule_sections, changed_paths, recheck_paths):
|
|
94
|
+
paths = list(changed_paths) + list(recheck_paths)
|
|
95
|
+
if any(not _valid_path(path) for path in paths):
|
|
96
|
+
return list(rule_sections)
|
|
97
|
+
return [
|
|
98
|
+
section
|
|
99
|
+
for section in rule_sections
|
|
100
|
+
if section["applicability"]["always"]
|
|
101
|
+
or any(
|
|
102
|
+
_matches(path, pattern)
|
|
103
|
+
for path in paths
|
|
104
|
+
for pattern in section["applicability"]["path_patterns"]
|
|
105
|
+
)
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def assign_recheck_issues(batch_paths, issues):
|
|
110
|
+
if not batch_paths:
|
|
111
|
+
if issues:
|
|
112
|
+
raise ValueError("Recheck issues require a review batch")
|
|
113
|
+
return []
|
|
114
|
+
assignments = [[] for _ in batch_paths]
|
|
115
|
+
batches_by_path = {path: index for index, paths in enumerate(batch_paths) for path in paths}
|
|
116
|
+
for issue in issues:
|
|
117
|
+
assignments[batches_by_path.get(issue.get("file"), 0)].append(issue)
|
|
118
|
+
return assignments
|
|
@@ -83,6 +83,14 @@ 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
|
+
|
|
86
94
|
try:
|
|
87
95
|
from app.zcode_protocol import (
|
|
88
96
|
ZCodeProtocolError,
|
|
@@ -1412,7 +1420,7 @@ except (ImportError, ModuleNotFoundError):
|
|
|
1412
1420
|
# DAEMON_VERSION is the protocol/logic version of the daemon code.
|
|
1413
1421
|
# Kept in sync with pyproject.toml version via bump-version.sh.
|
|
1414
1422
|
# CLIENT_TYPE identifies which packaging/distribution this daemon runs in.
|
|
1415
|
-
DAEMON_VERSION = "1.
|
|
1423
|
+
DAEMON_VERSION = "1.101.0"
|
|
1416
1424
|
|
|
1417
1425
|
|
|
1418
1426
|
def _detect_client_type() -> str:
|
|
@@ -1840,6 +1848,7 @@ class TaskResult:
|
|
|
1840
1848
|
_RUNTIME_CRITIC_TIMEOUT_SECONDS = 300
|
|
1841
1849
|
_RUNTIME_CRITIC_DIFF_MAX_CHARS = 30_000
|
|
1842
1850
|
_RUNTIME_CRITIC_OUTPUT_MAX_CHARS = 20_000
|
|
1851
|
+
_DELIVERY_REVIEW_PROMPT_MAX_BYTES = 256 * 1024
|
|
1843
1852
|
_RUNTIME_CRITIC_SOURCE_MAX_BYTES = 1_000_000
|
|
1844
1853
|
_RUNTIME_CRITIC_SOURCE_MAX_FILES = 128
|
|
1845
1854
|
_RUNTIME_CRITIC_SOURCE_TIMEOUT_SECONDS = 200
|
|
@@ -6594,7 +6603,7 @@ def _workspace_has_recent_activity(
|
|
|
6594
6603
|
|
|
6595
6604
|
def _delivery_review_capabilities() -> dict:
|
|
6596
6605
|
if sys.platform == "darwin" and shutil.which("sandbox-exec"):
|
|
6597
|
-
return {"delivery_code_review": {"protocol_version":
|
|
6606
|
+
return {"delivery_code_review": {"protocol_version": 2}}
|
|
6598
6607
|
return {}
|
|
6599
6608
|
|
|
6600
6609
|
|
|
@@ -14691,6 +14700,13 @@ class RuntimeDaemon:
|
|
|
14691
14700
|
await git("clone", "--quiet", "--no-hardlinks", "--no-checkout", "--", str(workspace_path), str(sandbox), timeout=120)
|
|
14692
14701
|
await git("checkout", "--quiet", "--detach", expected, cwd=sandbox, timeout=120)
|
|
14693
14702
|
await git("remote", "remove", "origin", cwd=sandbox, timeout=10)
|
|
14703
|
+
if data.get("delivery_code_review_version") == 2:
|
|
14704
|
+
existing = await git(
|
|
14705
|
+
"--literal-pathspecs", "ls-tree", "-r", "--name-only", "-z", expected,
|
|
14706
|
+
"--", *sorted(allowed_paths), cwd=sandbox, timeout=30,
|
|
14707
|
+
)
|
|
14708
|
+
if {path for path in existing.split("\x00") if path} != allowed_paths:
|
|
14709
|
+
return failed("delivery_review_fix_requires_existing_files", "Selected repair files must exist in the reviewed commit")
|
|
14694
14710
|
issues = (data.get("fix_context") or {}).get("issues") or []
|
|
14695
14711
|
prompt = (
|
|
14696
14712
|
"Fix only the selected issues in this isolated copy. Do not edit other files, commit, push, "
|
|
@@ -14709,6 +14725,8 @@ class RuntimeDaemon:
|
|
|
14709
14725
|
status = await git("--no-optional-locks", "status", "--porcelain=v1", "-z", "--untracked-files=all", "--no-renames", cwd=sandbox, timeout=30)
|
|
14710
14726
|
entries = _git_status_entries(status)
|
|
14711
14727
|
new_paths = [path for entry_status, path in entries if entry_status == "??"]
|
|
14728
|
+
if data.get("delivery_code_review_version") == 2 and new_paths:
|
|
14729
|
+
return failed("delivery_review_fix_scope_violation", "The repair created an unapproved file")
|
|
14712
14730
|
if any(path not in allowed_paths for path in new_paths):
|
|
14713
14731
|
return failed("delivery_review_fix_scope_violation", "The repair created an unapproved file")
|
|
14714
14732
|
if new_paths:
|
|
@@ -14729,7 +14747,12 @@ class RuntimeDaemon:
|
|
|
14729
14747
|
remote_lines = [line.split() for line in remote.splitlines() if line.strip()]
|
|
14730
14748
|
if remote_lines != [[expected, f"refs/heads/{branch}"]]:
|
|
14731
14749
|
return failed("delivery_review_candidate_changed", "The remote candidate changed during repair")
|
|
14732
|
-
|
|
14750
|
+
if data.get("delivery_code_review_version") == 2:
|
|
14751
|
+
default_branch = data.get("reviewed_target_branch")
|
|
14752
|
+
if not isinstance(default_branch, str) or not default_branch or default_branch.startswith("-"):
|
|
14753
|
+
return failed("delivery_review_candidate_changed", "The frozen target branch is unavailable")
|
|
14754
|
+
else:
|
|
14755
|
+
default_branch = str((task.project or {}).get("default_branch") or "main")
|
|
14733
14756
|
target = await git("ls-remote", "--refs", "origin", f"refs/heads/{default_branch}", cwd=workspace_path, timeout=60, project_key=project_key)
|
|
14734
14757
|
target_lines = [line.split() for line in target.splitlines() if line.strip()]
|
|
14735
14758
|
if target_lines != [[expected_target, f"refs/heads/{default_branch}"]]:
|
|
@@ -14791,7 +14814,32 @@ class RuntimeDaemon:
|
|
|
14791
14814
|
return failed("delivery_review_agent_unsupported", "This agent has no verified read-only delivery review mode")
|
|
14792
14815
|
if task.workspace_resolution == "local_bind" and not task.local_evidence_upload:
|
|
14793
14816
|
return failed("delivery_review_local_privacy_required", "Local review results cannot be shared under this project policy")
|
|
14794
|
-
|
|
14817
|
+
data = task.input_data or {}
|
|
14818
|
+
protocol = data.get("delivery_code_review_version", 1)
|
|
14819
|
+
if type(protocol) is not int or protocol not in (1, 2):
|
|
14820
|
+
return failed("delivery_review_scope_incomplete", "The review protocol is unsupported")
|
|
14821
|
+
snapshot = None
|
|
14822
|
+
generation_id = None
|
|
14823
|
+
if protocol == 2:
|
|
14824
|
+
snapshot = data.get("delivery_review_snapshot")
|
|
14825
|
+
try:
|
|
14826
|
+
config = snapshot["config"]
|
|
14827
|
+
if (config["version"] != 2 or config["engine"] != "agent"
|
|
14828
|
+
or code_review_rules.review_config_sha256(config) != snapshot["review_config_sha256"]):
|
|
14829
|
+
raise ValueError("Invalid review identity")
|
|
14830
|
+
if not isinstance(config["context"], dict) or not isinstance(config["additional_instructions"], str):
|
|
14831
|
+
raise ValueError("Invalid review input")
|
|
14832
|
+
code_review_rules.validate_rule_package(
|
|
14833
|
+
config["rule_package"]["template"], config["rule_package"]["rule_sections"]
|
|
14834
|
+
)
|
|
14835
|
+
generation_id = str(UUID(data["review_generation_id"]))
|
|
14836
|
+
default_branch = config["target_branch"]
|
|
14837
|
+
if not isinstance(default_branch, str):
|
|
14838
|
+
raise ValueError("Invalid target branch")
|
|
14839
|
+
except (KeyError, TypeError, ValueError):
|
|
14840
|
+
return failed("delivery_review_scope_incomplete", "The frozen review configuration is invalid")
|
|
14841
|
+
else:
|
|
14842
|
+
default_branch = str((task.project or {}).get("default_branch") or "main").strip()
|
|
14795
14843
|
if not task.workspace_branch or not default_branch or default_branch.startswith("-"):
|
|
14796
14844
|
return failed("delivery_review_scope_incomplete", "The candidate or target branch is unavailable")
|
|
14797
14845
|
|
|
@@ -14858,8 +14906,11 @@ class RuntimeDaemon:
|
|
|
14858
14906
|
logger.warning("Cannot prepare delivery review scope: %s", type(error).__name__)
|
|
14859
14907
|
return failed("delivery_review_scope_incomplete", "The complete candidate diff is unavailable")
|
|
14860
14908
|
|
|
14861
|
-
metadata = {"version":
|
|
14909
|
+
metadata = {"version": protocol, "base_sha": base, "target_sha": target, "head_sha": head,
|
|
14862
14910
|
"changed_files": paths, "reviewed_batches": [batch_paths for batch_paths, _ in batches] if paths else []}
|
|
14911
|
+
if snapshot is not None:
|
|
14912
|
+
metadata.update({"review_config_sha256": snapshot["review_config_sha256"],
|
|
14913
|
+
"review_generation_id": generation_id})
|
|
14863
14914
|
git = {"branch": branch, "before_sha": head, "commit_sha": head, "files_changed": []}
|
|
14864
14915
|
recheck = (task.input_data or {}).get("delivery_review_recheck")
|
|
14865
14916
|
if recheck is not None and (
|
|
@@ -14879,9 +14930,9 @@ class RuntimeDaemon:
|
|
|
14879
14930
|
or any("file" in issue and not isinstance(issue["file"], str) for issue in selected_issues)
|
|
14880
14931
|
or {issue["id"] for issue in selected_issues} != set(selected_ids)):
|
|
14881
14932
|
return failed("delivery_review_scope_incomplete", "The selected recheck issues are invalid")
|
|
14882
|
-
|
|
14883
|
-
|
|
14884
|
-
|
|
14933
|
+
recheck_by_batch = code_review_rules.assign_recheck_issues(
|
|
14934
|
+
[batch_paths for batch_paths, _ in batches], selected_issues,
|
|
14935
|
+
)
|
|
14885
14936
|
if not paths and not recheck:
|
|
14886
14937
|
return TaskResult(status="success", exit_code=0, stdout="", stderr="", git=git,
|
|
14887
14938
|
metrics={"delivery_code_review": metadata}, has_verified_completion=True,
|
|
@@ -14890,7 +14941,7 @@ class RuntimeDaemon:
|
|
|
14890
14941
|
if paths and not diff:
|
|
14891
14942
|
return failed("delivery_review_scope_incomplete", "Changed files have no reviewable diff")
|
|
14892
14943
|
|
|
14893
|
-
context =
|
|
14944
|
+
context = snapshot["config"]["context"] if snapshot is not None else data.get("context") or {}
|
|
14894
14945
|
requirements = context.get("requirement_description") if isinstance(context, dict) else None
|
|
14895
14946
|
if not isinstance(requirements, str) or not requirements.strip():
|
|
14896
14947
|
return failed("delivery_review_scope_incomplete", "The approved requirement context is unavailable")
|
|
@@ -14925,15 +14976,28 @@ class RuntimeDaemon:
|
|
|
14925
14976
|
value[key] = entry
|
|
14926
14977
|
return value
|
|
14927
14978
|
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
|
|
14934
|
-
|
|
14979
|
+
def assemble_prompt(index, batch_paths, batch_diff, batch_recheck):
|
|
14980
|
+
rules = ""
|
|
14981
|
+
section_ids = []
|
|
14982
|
+
if snapshot is not None:
|
|
14983
|
+
config = snapshot["config"]
|
|
14984
|
+
selected_sections = code_review_rules.select_rule_sections(
|
|
14985
|
+
config["rule_package"]["rule_sections"], batch_paths,
|
|
14986
|
+
[issue.get("file") for issue in batch_recheck],
|
|
14987
|
+
)
|
|
14988
|
+
section_ids = [section["id"] for section in selected_sections
|
|
14989
|
+
if not section["applicability"]["always"]]
|
|
14990
|
+
rules = (
|
|
14991
|
+
"\nApproved review rules are subordinate to the platform's fixed scope, "
|
|
14992
|
+
"read-only permissions, output contract and human decisions. "
|
|
14993
|
+
"Report conflicts instead of changing those requirements.\n\nCore rules:\n"
|
|
14994
|
+
+ config["rule_package"]["template"]
|
|
14995
|
+
+ "\n\nProject additions:\n" + config["additional_instructions"]
|
|
14996
|
+
)
|
|
14997
|
+
for section in selected_sections:
|
|
14998
|
+
rules += f"\n\nRule {section['id']}: {section['title']}\n{section['instructions']}"
|
|
14999
|
+
prompt = (prompt_prefix + rules + f"\nReview batch {index + 1} of {len(batches)}; cover these files only:\n"
|
|
14935
15000
|
+ 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
15001
|
if batch_recheck:
|
|
14938
15002
|
prompt += (
|
|
14939
15003
|
"\n\nRecheck every selected original issue against the repair commit. "
|
|
@@ -14943,6 +15007,54 @@ class RuntimeDaemon:
|
|
|
14943
15007
|
"Also report new defects in issues. Selected original issues:\n"
|
|
14944
15008
|
+ json.dumps(batch_recheck, ensure_ascii=False)
|
|
14945
15009
|
)
|
|
15010
|
+
return prompt, section_ids
|
|
15011
|
+
|
|
15012
|
+
while True:
|
|
15013
|
+
batch_prompts = [assemble_prompt(index, batch_paths, batch_diff, recheck_by_batch[index])
|
|
15014
|
+
for index, (batch_paths, batch_diff) in enumerate(batches)]
|
|
15015
|
+
oversized = next((index for index, (prompt, _) in enumerate(batch_prompts)
|
|
15016
|
+
if snapshot is not None and len(prompt.encode("utf-8")) > _DELIVERY_REVIEW_PROMPT_MAX_BYTES), None)
|
|
15017
|
+
if oversized is None:
|
|
15018
|
+
break
|
|
15019
|
+
oversized_paths = batches[oversized][0]
|
|
15020
|
+
if len(oversized_paths) < 2 or len(batches) >= 8:
|
|
15021
|
+
return failed("delivery_review_scope_incomplete", "A complete review prompt exceeds the input budget")
|
|
15022
|
+
file_diffs = []
|
|
15023
|
+
try:
|
|
15024
|
+
for path in oversized_paths:
|
|
15025
|
+
file_diff = await self.workspace_manager._git(
|
|
15026
|
+
"--literal-pathspecs", "diff", "--no-ext-diff", "--no-textconv", "--no-renames", "--unified=3",
|
|
15027
|
+
base, head, "--", path, cwd=workspace_path, timeout=60,
|
|
15028
|
+
)
|
|
15029
|
+
if not file_diff or len(file_diff.encode("utf-8")) > _RUNTIME_CRITIC_DIFF_MAX_CHARS:
|
|
15030
|
+
raise ValueError("Invalid file diff")
|
|
15031
|
+
file_diffs.append(file_diff)
|
|
15032
|
+
except (OSError, RuntimeError, ValueError, UnicodeError):
|
|
15033
|
+
return failed("delivery_review_scope_incomplete", "The complete diff cannot be split safely")
|
|
15034
|
+
midpoint = len(oversized_paths) // 2
|
|
15035
|
+
batches[oversized:oversized + 1] = [
|
|
15036
|
+
(oversized_paths[:midpoint], "".join(file_diffs[:midpoint])),
|
|
15037
|
+
(oversized_paths[midpoint:], "".join(file_diffs[midpoint:])),
|
|
15038
|
+
]
|
|
15039
|
+
recheck_by_batch = code_review_rules.assign_recheck_issues(
|
|
15040
|
+
[batch_paths for batch_paths, _ in batches], selected_issues if recheck else [],
|
|
15041
|
+
)
|
|
15042
|
+
if snapshot is not None:
|
|
15043
|
+
metadata["reviewed_batches"] = [
|
|
15044
|
+
{"paths": batch_paths, "rule_section_ids": batch_prompts[index][1],
|
|
15045
|
+
"recheck_issue_ids": [issue["id"] for issue in recheck_by_batch[index]]}
|
|
15046
|
+
for index, (batch_paths, _) in enumerate(batches)
|
|
15047
|
+
]
|
|
15048
|
+
metadata["prompt_bytes"] = [len(prompt.encode("utf-8")) for prompt, _ in batch_prompts]
|
|
15049
|
+
|
|
15050
|
+
summaries, issues, combined_metrics, rechecked = [], [], {}, []
|
|
15051
|
+
deadline = time.monotonic() + (task.timeout_seconds or settings.AGENT_TIMEOUT)
|
|
15052
|
+
for index, (batch_paths, batch_diff) in enumerate(batches):
|
|
15053
|
+
remaining = int(deadline - time.monotonic())
|
|
15054
|
+
if remaining <= 0:
|
|
15055
|
+
return failed("delivery_review_agent_failed", "Delivery review exceeded its time budget")
|
|
15056
|
+
prompt = batch_prompts[index][0]
|
|
15057
|
+
batch_recheck = recheck_by_batch[index]
|
|
14946
15058
|
review_task = TaskInfo(
|
|
14947
15059
|
task_id=f"{task.task_id}-delivery-review-{index + 1}", graph_id=task.graph_id,
|
|
14948
15060
|
node_type="delivery_code_review", agent_type="claude", input_prompt=prompt,
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|