forgexa-cli 1.104.2__tar.gz → 1.104.4__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.
Files changed (40) hide show
  1. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/PKG-INFO +1 -1
  2. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/__init__.py +1 -1
  3. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/agent_core.py +110 -3
  4. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/daemon.py +173 -91
  5. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli.egg-info/PKG-INFO +1 -1
  6. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/pyproject.toml +1 -1
  7. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/README.md +0 -0
  8. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/_build_config.py +0 -0
  9. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/_local_bind.py +0 -0
  10. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/autoupgrade.py +0 -0
  11. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/aws_evidence.py +0 -0
  12. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/aws_logs_evidence.py +0 -0
  13. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/code_review_rules.py +0 -0
  14. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/component_runtime.py +0 -0
  15. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/main.py +0 -0
  16. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/observability_contract.py +0 -0
  17. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/observability_evidence.py +0 -0
  18. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/ocr_adapter.py +0 -0
  19. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/py.typed +0 -0
  20. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/runtime_evidence.py +0 -0
  21. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/workspace_storage.py +0 -0
  22. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli/zcode_protocol.py +0 -0
  23. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli.egg-info/SOURCES.txt +0 -0
  24. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli.egg-info/dependency_links.txt +0 -0
  25. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli.egg-info/entry_points.txt +0 -0
  26. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli.egg-info/requires.txt +0 -0
  27. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/forgexa_cli.egg-info/top_level.txt +0 -0
  28. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/setup.cfg +0 -0
  29. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_auth_and_runtime_commands.py +0 -0
  30. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_autoupgrade.py +0 -0
  31. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_check_command.py +0 -0
  32. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_delivery_review_packaged.py +0 -0
  33. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_expiry_warnings_and_revoke.py +0 -0
  34. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_local_bind_commands.py +0 -0
  35. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_publish_script.py +0 -0
  36. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_runtime_credentials.py +0 -0
  37. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_session_credentials.py +0 -0
  38. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_silent_install.py +0 -0
  39. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_upgrade_observability.py +0 -0
  40. {forgexa_cli-1.104.2 → forgexa_cli-1.104.4}/tests/test_workspace_storage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: forgexa-cli
3
- Version: 1.104.2
3
+ Version: 1.104.4
4
4
  Summary: Forgexa CLI — command-line client and AI agent runtime for the Forgexa platform
5
5
  Author-email: Jason Sun <dev.winds@gmail.com>
6
6
  License-Expression: MIT
@@ -1,2 +1,2 @@
1
1
  """forgexa-cli — Forgexa command-line client."""
2
- __version__ = "1.104.2"
2
+ __version__ = "1.104.4"
@@ -1516,9 +1516,11 @@ async def agent_runtime_commit_error(
1516
1516
  )
1517
1517
  commits = await git("rev-list", *revisions, cwd=workspace_path)
1518
1518
  for commit_sha in commits.splitlines():
1519
+ # Other merge parents can lack files inherited unchanged from the baseline.
1519
1520
  output = await git(
1520
1521
  "diff-tree", "--root", "--no-commit-id", "--name-status",
1521
- "--no-renames", "--diff-filter=ACMRTUXB", "-r", "-m", "-z",
1522
+ "--no-renames", "--diff-filter=ACMRTUXB", "-r",
1523
+ "--diff-merges=first-parent", "-z",
1522
1524
  commit_sha, cwd=workspace_path,
1523
1525
  )
1524
1526
  runtime_paths.update(_agent_runtime_paths_from_diff(output))
@@ -1566,6 +1568,24 @@ async def stage_agent_runtime_deletions(
1566
1568
  )
1567
1569
 
1568
1570
 
1571
+ async def untrack_agent_runtime_files(
1572
+ workspace_path: Path, git: Callable[..., Awaitable[str]],
1573
+ ) -> list[str]:
1574
+ """Remove generated state from a managed candidate's index, not its local files."""
1575
+ tracked = await git("ls-files", "--cached", "-z", cwd=workspace_path)
1576
+ paths = sorted({
1577
+ path for path in tracked.split("\0")
1578
+ if path and is_agent_runtime_path(path)
1579
+ })
1580
+ for offset in range(0, len(paths), 100):
1581
+ await git(
1582
+ "rm", "--cached", "--force", "--",
1583
+ *(f":(literal){path}" for path in paths[offset:offset + 100]),
1584
+ cwd=workspace_path,
1585
+ )
1586
+ return paths
1587
+
1588
+
1569
1589
  def _redirect_prompt_through_task_file(
1570
1590
  cwd: Path, prompt: str, task_id: str, agent_label: str,
1571
1591
  *, task_file: Path | None = None, git_exclude: Path | None = None,
@@ -3731,13 +3751,28 @@ DELIVERY_REVIEW_AGENT_IDS = frozenset({
3731
3751
  "claude", "codebuddy", "codex", "copilot", "deepseek", "gemini", "kimi",
3732
3752
  "mimo", "minimax", "opencode", "qoder", "qwen", "trae", "zcode",
3733
3753
  })
3734
- LINUX_DELIVERY_REVIEW_AGENT_IDS = frozenset({"claude", "copilot", "opencode"})
3735
3754
  DELIVERY_REVIEW_SENSITIVE_PATTERNS = (
3736
3755
  r"/[.]env([.][^/]*)?$", r"[.](pem|key|p12|pfx)$", r"/(id_rsa|id_ed25519)([.][^/]*)?$",
3737
3756
  r"/[.]aws/credentials$", r"/[.](npmrc|netrc)$", r"/[.]git(/|$)",
3738
3757
  )
3739
3758
 
3740
3759
 
3760
+ def delivery_review_candidate(input_data: dict | None, workspace_resolution: str = "cloud_worktree") -> dict | None:
3761
+ data = input_data if isinstance(input_data, dict) else {}
3762
+ candidate = data.get("delivery_review_candidate")
3763
+ if (workspace_resolution != "cloud_worktree" or data.get("task") != "delivery_code_review"
3764
+ or not isinstance(candidate, dict) or type(candidate.get("version")) is not int or candidate["version"] != 1
3765
+ or not isinstance(candidate.get("source_delivery_node_id"), str)
3766
+ or candidate["source_delivery_node_id"] != data.get("source_delivery_node_id")
3767
+ or any(not isinstance(candidate.get(key), str) or not candidate[key] for key in ("repo_identity", "branch", "target_branch"))
3768
+ or any(not isinstance(candidate.get(key), str) or not re.fullmatch(r"[a-f0-9]{40}|[a-f0-9]{64}", candidate[key])
3769
+ for key in ("head_sha", "target_sha"))
3770
+ or any(data.get(field) is not None and data[field] != candidate[key]
3771
+ for field, key in (("delivery_review_expected_head", "head_sha"), ("delivery_review_expected_target", "target_sha")))):
3772
+ return None
3773
+ return candidate
3774
+
3775
+
3741
3776
  def delivery_review_sandbox_exec() -> str | None:
3742
3777
  if sys.platform not in {"darwin", "linux"}:
3743
3778
  return None
@@ -3747,7 +3782,7 @@ def delivery_review_sandbox_exec() -> str | None:
3747
3782
  if sys.platform == "linux":
3748
3783
  try:
3749
3784
  probe = subprocess.run(
3750
- [executable, "--unshare-all", "--die-with-parent", "--new-session",
3785
+ [executable, "--unshare-all", "--share-net", "--die-with-parent", "--new-session",
3751
3786
  "--ro-bind", "/", "/", "--proc", "/proc", "--dev", "/dev", "--", "/bin/true"],
3752
3787
  stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=3, check=False,
3753
3788
  )
@@ -3758,6 +3793,66 @@ def delivery_review_sandbox_exec() -> str | None:
3758
3793
  return executable
3759
3794
 
3760
3795
 
3796
+ def delivery_review_linux_command(
3797
+ command: list[str], *, cwd: Path, home: Path, writable: bool = False, network: bool = True,
3798
+ read_paths: list[Path] | None = None, write_paths: list[Path] | None = None,
3799
+ read_only_paths: list[Path] | None = None, deny_paths: list[Path] | None = None,
3800
+ ) -> list[str]:
3801
+ sandbox = delivery_review_sandbox_exec()
3802
+ if sys.platform != "linux" or not sandbox:
3803
+ raise RuntimeError("delivery_review_sandbox_unavailable")
3804
+ user_home, workspace, isolated_home = Path.home().resolve(), cwd.resolve(), home.resolve()
3805
+ roots = {path.resolve() for path in (read_paths or [])}
3806
+ writable_roots = {path.resolve() for path in (write_paths or [])}
3807
+ readonly_roots = {path.resolve() for path in (read_only_paths or [])}
3808
+ if (workspace == isolated_home or workspace in isolated_home.parents or isolated_home in workspace.parents
3809
+ or any(path == user_home or path in user_home.parents for path in {workspace, isolated_home, *roots, *writable_roots, *readonly_roots})
3810
+ or not writable and any(path == workspace or path in workspace.parents or workspace in path.parents for path in writable_roots)):
3811
+ raise RuntimeError("delivery_review_sandbox_scope_invalid")
3812
+ wrapped = [sandbox, "--unshare-all", "--die-with-parent", "--new-session", "--cap-drop", "ALL"]
3813
+ if network:
3814
+ wrapped.append("--share-net")
3815
+ for path in (
3816
+ "/usr", "/bin", "/sbin", "/lib", "/lib64", "/etc/ssl/certs", "/etc/ca-certificates", "/etc/pki",
3817
+ "/etc/resolv.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/gai.conf", "/etc/localtime",
3818
+ "/etc/passwd", "/etc/group", "/etc/ld.so.cache", "/etc/alternatives",
3819
+ ):
3820
+ if Path(path).exists():
3821
+ wrapped += ["--ro-bind", path, path]
3822
+ wrapped += ["--proc", "/proc", "--dev", "/dev", "--tmpfs", "/tmp", "--tmpfs", "/var/tmp"]
3823
+ for path in sorted(roots):
3824
+ if path.exists():
3825
+ if not path.is_dir() and not path.is_file():
3826
+ raise RuntimeError("delivery_review_sandbox_scope_invalid")
3827
+ wrapped += ["--ro-bind", str(path), str(path)]
3828
+ wrapped += ["--bind" if writable else "--ro-bind", str(workspace), str(workspace)]
3829
+ wrapped += ["--bind", str(isolated_home), str(isolated_home)]
3830
+ for path in sorted(writable_roots):
3831
+ if path.exists():
3832
+ wrapped += ["--bind", str(path), str(path)]
3833
+ for path in sorted(readonly_roots):
3834
+ if path.exists():
3835
+ wrapped += ["--ro-bind", str(path), str(path)]
3836
+ protected = {path.resolve() for path in (deny_paths or [])}
3837
+ for root in {workspace, isolated_home, *writable_roots, *readonly_roots, *(path for path in roots if str(path) != "/usr" and not str(path).startswith(("/usr/", "/bin", "/sbin", "/lib")))}:
3838
+ if any(re.search(pattern, str(root)) for pattern in DELIVERY_REVIEW_SENSITIVE_PATTERNS):
3839
+ protected.add(root)
3840
+ continue
3841
+ for directory, directories, files in os.walk(root, followlinks=False):
3842
+ for name in [*directories, *files]:
3843
+ path = Path(directory) / name
3844
+ if any(re.search(pattern, str(path)) for pattern in DELIVERY_REVIEW_SENSITIVE_PATTERNS):
3845
+ protected.add(path)
3846
+ if name in directories:
3847
+ directories.remove(name)
3848
+ for path in sorted(protected):
3849
+ if path.is_dir():
3850
+ wrapped += ["--tmpfs", str(path)]
3851
+ elif path.exists() or path.is_symlink():
3852
+ wrapped += ["--ro-bind", "/dev/null", str(path)]
3853
+ return [*wrapped, "--chdir", str(workspace), "--", *command]
3854
+
3855
+
3761
3856
  _OPENCODE_WORKER_DENIED_TOOLS = (
3762
3857
  "task", "subagent", "delegate_task", "call_omo_agent",
3763
3858
  "background_output", "background_cancel",
@@ -4180,6 +4275,12 @@ def _minimax_sandbox(
4180
4275
  if not sandbox:
4181
4276
  raise RuntimeError("MiniMax delivery review sandbox is unavailable")
4182
4277
  return [sandbox, "-p", "\n".join(profile), *command]
4278
+ if delivery_review:
4279
+ return delivery_review_linux_command(
4280
+ command, cwd=cwd, home=temporary_root, writable=not read_only,
4281
+ read_paths=[root, Path(admission["build"]["package_root"]).parents[1], Path(admission["build"]["node"]).parent.parent],
4282
+ write_paths=[root / "data"], read_only_paths=protected,
4283
+ )
4183
4284
  wrapped = ["bwrap", "--die-with-parent", "--new-session", "--ro-bind", "/", "/",
4184
4285
  "--tmpfs", str(Path.home()), "--dev", "/dev", "--proc", "/proc"]
4185
4286
  for path in (Path(admission["build"]["package_root"]).parents[1],
@@ -5022,6 +5123,12 @@ def deepseek_harness_sandbox_command(
5022
5123
  )
5023
5124
  return [sandbox, "-p", profile, *command]
5024
5125
  if sys.platform == "linux":
5126
+ if delivery_review:
5127
+ return delivery_review_linux_command(
5128
+ command, cwd=cwd, home=home, writable=not read_only,
5129
+ read_paths=[*(read_paths or []), *([credentials_path] if credentials_path else [])],
5130
+ write_paths=[temporary_root], read_only_paths=git_roots,
5131
+ )
5025
5132
  sandbox = shutil.which("bwrap")
5026
5133
  if not sandbox:
5027
5134
  raise RuntimeError("DeepSeek Harness requires a working bubblewrap outer sandbox")
@@ -1428,7 +1428,7 @@ except (ImportError, ModuleNotFoundError):
1428
1428
  # DAEMON_VERSION is the protocol/logic version of the daemon code.
1429
1429
  # Kept in sync with pyproject.toml version via bump-version.sh.
1430
1430
  # CLIENT_TYPE identifies which packaging/distribution this daemon runs in.
1431
- DAEMON_VERSION = "1.104.2"
1431
+ DAEMON_VERSION = "1.104.4"
1432
1432
 
1433
1433
 
1434
1434
  def _detect_client_type() -> str:
@@ -3963,6 +3963,95 @@ class WorkspaceManager:
3963
3963
  if task.workspace_resolution == "local_bind":
3964
3964
  return await self._bind_local_workspace(project, task, runtime_id=runtime_id)
3965
3965
 
3966
+ candidate = agent_core.delivery_review_candidate(task.input_data, task.workspace_resolution)
3967
+ if candidate is not None:
3968
+ self._ensure_dirs()
3969
+ project_key, repo_url, _ = self._configure_project_git_auth(project)
3970
+ if _normalize_repo_identity(repo_url) != candidate["repo_identity"] or task.workspace_branch != candidate["branch"]:
3971
+ raise RuntimeError("delivery_review_candidate_changed: repository or branch identity does not match")
3972
+ parent = self.projects_root / ".delivery-reviews"
3973
+ parent.mkdir(parents=True, exist_ok=True)
3974
+ workspace_path = Path(tempfile.mkdtemp(prefix="candidate-", dir=str(parent)))
3975
+ stage = "validate_refs"
3976
+ try:
3977
+ await self._git("check-ref-format", f"refs/heads/{candidate['branch']}", cwd=workspace_path, timeout=10)
3978
+ await self._git("check-ref-format", f"refs/heads/{candidate['target_branch']}", cwd=workspace_path, timeout=10)
3979
+ cache = None
3980
+ read_env = {"GIT_NO_LAZY_FETCH": "1", "GIT_OPTIONAL_LOCKS": "0", "GIT_TERMINAL_PROMPT": "0"}
3981
+ if not re.fullmatch(r"[a-zA-Z0-9_-]+", project_key):
3982
+ raise ValueError("Invalid project identity")
3983
+ stage = "cache_probe"
3984
+ for existing in (self.projects_root / project_key / self._workspace_key(task), self.projects_root / project_key / "_main"):
3985
+ if not (existing / ".git").exists():
3986
+ continue
3987
+ try:
3988
+ remote = await self._git("config", "--local", "--get", "remote.origin.url", cwd=existing, timeout=10, env_overrides=read_env)
3989
+ if _normalize_repo_identity(remote.strip()) != candidate["repo_identity"]:
3990
+ continue
3991
+ shallow = await self._git("rev-parse", "--is-shallow-repository", cwd=existing, timeout=10, env_overrides=read_env)
3992
+ if shallow.strip() != "false":
3993
+ continue
3994
+ local_config = await self._git("config", "--local", "--null", "--list", cwd=existing, timeout=10, env_overrides=read_env)
3995
+ if any(
3996
+ key == "extensions.partialclone" or key.endswith(".promisor") and value.strip().lower() not in {"false", "no", "0"}
3997
+ for entry in local_config.split("\x00") if entry
3998
+ for key, _, value in [entry.partition("\n")]
3999
+ ):
4000
+ continue
4001
+ except (OSError, RuntimeError, UnicodeError):
4002
+ continue
4003
+ try:
4004
+ for commit in (candidate["head_sha"], candidate["target_sha"]):
4005
+ await self._git("cat-file", "-e", f"{commit}^{{commit}}", cwd=existing, timeout=10, env_overrides=read_env)
4006
+ await self._git("merge-base", candidate["target_sha"], candidate["head_sha"], cwd=existing, timeout=10, env_overrides=read_env)
4007
+ except RuntimeError:
4008
+ continue
4009
+ cache = existing
4010
+ break
4011
+ stage = "initialize"
4012
+ if cache is not None:
4013
+ await self._git("clone", "--shared", "--no-hardlinks", "--no-checkout", "--no-tags", "--template=", "--", str(cache), str(workspace_path),
4014
+ timeout=60, env_overrides=read_env)
4015
+ else:
4016
+ await self._git("init", "--quiet", "--template=", f"--object-format={'sha256' if len(candidate['head_sha']) == 64 else 'sha1'}", cwd=workspace_path, timeout=10)
4017
+ await self._git("config", "core.hooksPath", os.devnull, cwd=workspace_path, timeout=10)
4018
+ await self._git("config", "core.autocrlf", "false", cwd=workspace_path, timeout=10)
4019
+ await self._git("remote", "set-url" if cache else "add", "origin", repo_url, cwd=workspace_path, timeout=10)
4020
+ if cache is None:
4021
+ stage = "fetch"
4022
+ await self._git("fetch", "--depth=1", "--no-tags", "--no-recurse-submodules", "--no-write-fetch-head", "--refmap=",
4023
+ "origin", candidate["head_sha"], candidate["target_sha"],
4024
+ cwd=workspace_path, timeout=settings.GIT_CLONE_TIMEOUT, project_key=project_key)
4025
+ stage = "checkout"
4026
+ await self._git("update-ref", f"refs/remotes/origin/{candidate['target_branch']}", candidate["target_sha"], cwd=workspace_path, timeout=10)
4027
+ await self._git("checkout", "--quiet", "-B", candidate["branch"], candidate["head_sha"], cwd=workspace_path, timeout=60)
4028
+ stage = "predecessor"
4029
+ for commit_sha in task.required_commit_shas:
4030
+ if not isinstance(commit_sha, str) or not re.fullmatch(r"[a-f0-9]{40}|[a-f0-9]{64}", commit_sha):
4031
+ raise ValueError("Invalid predecessor commit")
4032
+ await self._git("merge-base", "--is-ancestor", commit_sha, candidate["head_sha"], cwd=workspace_path, timeout=10)
4033
+ return workspace_path
4034
+ except BaseException as error:
4035
+ shutil.rmtree(workspace_path, ignore_errors=True)
4036
+ if isinstance(error, (OSError, RuntimeError, ValueError, UnicodeError)):
4037
+ detail = str(error).lower()
4038
+ reason = "git_command_failed"
4039
+ for category, pattern in (
4040
+ ("git_timeout", r"timed out|timeout"),
4041
+ ("git_access_denied", r"permission denied|authentication failed|could not read username|publickey|repository not found|(?:http(?:/[\d.]+)?\s+|returned error:\s*)(?:401|403)\b"),
4042
+ ("git_resource_exhausted", r"cannot allocate memory|unable to mmap|out of memory|no space left"),
4043
+ ("git_object_unavailable", r"not our ref|bad object|not a valid|unknown revision|invalid object|unable to read|missing blob|bad tree|corrupt"),
4044
+ ("git_transport_unavailable", r"could not resolve|connection refused|connection reset|network is unreachable|unexpected disconnect|early eof"),
4045
+ ):
4046
+ if re.search(pattern, detail):
4047
+ reason = category
4048
+ break
4049
+ if isinstance(error, UnicodeError):
4050
+ reason = "git_output_encoding"
4051
+ logger.warning("Delivery candidate reconstruction failed (stage=%s, reason=%s, type=%s)", stage, reason, type(error).__name__)
4052
+ raise RuntimeError(f"delivery_review_candidate_unavailable: fixed commits could not be reconstructed (stage={stage}; reason={reason})") from None
4053
+ raise
4054
+
3966
4055
  if (task.input_data or {}).get("task") in ("delivery_code_review", "delivery_review_fix", "delivery_review_retest"):
3967
4056
  project_key = str(project.get("project_key") or "default")
3968
4057
  if not re.fullmatch(r"[a-zA-Z0-9_-]+", project_key):
@@ -6314,11 +6403,11 @@ class WorkspaceManager:
6314
6403
  return ws_path
6315
6404
 
6316
6405
  async def cleanup_workspace(self, workspace_path: Path):
6317
- """Optional cleanup after task. For now, keep workspaces for debugging."""
6318
- pass
6406
+ if workspace_path.parent.resolve() == (self.projects_root / ".delivery-reviews").resolve():
6407
+ shutil.rmtree(workspace_path, ignore_errors=True)
6319
6408
 
6320
6409
  async def _git(self, *args: str, cwd: Path | str | None = None, timeout: int | None = None,
6321
- project_key: str | None = None) -> str:
6410
+ project_key: str | None = None, env_overrides: dict[str, str] | None = None) -> str:
6322
6411
  """Run a git command safely using exec (no shell injection).
6323
6412
 
6324
6413
  If a project SSH key is registered, remote-touching commands
@@ -6489,6 +6578,8 @@ class WorkspaceManager:
6489
6578
  "Git executable not found. Install Git for Windows and ensure "
6490
6579
  "'C:\\Program Files\\Git\\cmd' is accessible to the Forgexa daemon."
6491
6580
  )
6581
+ if env_overrides:
6582
+ env = {**(env or os.environ), **env_overrides}
6492
6583
 
6493
6584
  # start_new_session=True puts git in its own process group.
6494
6585
  # On timeout we send SIGKILL to the entire group, which includes
@@ -6528,7 +6619,7 @@ class WorkspaceManager:
6528
6619
  raise RuntimeError(error_message) from None
6529
6620
  finally:
6530
6621
  # Clean up temp SSH key file if created
6531
- if env and "GIT_SSH_COMMAND" in env:
6622
+ if env and "GIT_SSH_COMMAND" in env and project_key and self._ssh_keys.get(project_key) and args[0] in remote_commands:
6532
6623
  import re as _re
6533
6624
  m = _re.search(r'-i\s+"?([^"\s]+)"?', env["GIT_SSH_COMMAND"])
6534
6625
  if m:
@@ -6624,7 +6715,8 @@ def _delivery_review_capabilities() -> dict:
6624
6715
  return {"delivery_code_review": {
6625
6716
  "protocol_version": 2,
6626
6717
  "ocr_delegation_version": 1,
6627
- "agent_ids": sorted(agent_core.LINUX_DELIVERY_REVIEW_AGENT_IDS if sys.platform == "linux" else agent_core.DELIVERY_REVIEW_AGENT_IDS),
6718
+ "candidate_snapshot_version": 1,
6719
+ "agent_ids": sorted(agent_core.DELIVERY_REVIEW_AGENT_IDS),
6628
6720
  }}
6629
6721
  return {}
6630
6722
 
@@ -6696,45 +6788,10 @@ def _delivery_review_sandbox_command(command: list[str], workspace: Path, home:
6696
6788
  if any(Path(root) == user_home_path or Path(root) in user_home_path.parents for root in read_roots):
6697
6789
  raise RuntimeError("delivery_review_sandbox_scope_invalid")
6698
6790
  if sys.platform == "linux":
6699
- wrapped = [sandbox, "--unshare-all", "--die-with-parent", "--new-session", "--cap-drop", "ALL"]
6700
- if network:
6701
- wrapped.append("--share-net")
6702
- system_paths = (
6703
- "/usr", "/bin", "/sbin", "/lib", "/lib64", "/etc/ssl/certs", "/etc/ca-certificates",
6704
- "/etc/pki", "/etc/resolv.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/gai.conf",
6705
- "/etc/localtime", "/etc/passwd", "/etc/group", "/etc/ld.so.cache", "/etc/alternatives",
6791
+ return agent_core.delivery_review_linux_command(
6792
+ command, cwd=workspace_path, home=home_path, writable=writable, network=network,
6793
+ read_paths=[Path(root) for root in read_roots], deny_paths=deny_paths,
6706
6794
  )
6707
- for path in system_paths:
6708
- if Path(path).exists():
6709
- wrapped += ["--ro-bind", path, path]
6710
- wrapped += ["--proc", "/proc", "--dev", "/dev", "--tmpfs", "/tmp", "--tmpfs", "/var/tmp"]
6711
- for root in sorted(read_roots):
6712
- path = Path(root)
6713
- if not path.exists():
6714
- continue
6715
- if not path.is_dir() and not path.is_file():
6716
- raise RuntimeError("delivery_review_sandbox_scope_invalid")
6717
- wrapped += ["--ro-bind", root, root]
6718
- wrapped += ["--bind" if writable else "--ro-bind", str(workspace_path), str(workspace_path)]
6719
- wrapped += ["--bind", str(home_path), str(home_path)]
6720
- protected = {path.absolute() for path in (deny_paths or [])}
6721
- for root in (workspace_path, home_path, *(Path(path) for path in read_roots if not str(path).startswith(("/usr/", "/bin", "/sbin", "/lib")))):
6722
- if any(re.search(pattern, str(root)) for pattern in agent_core.DELIVERY_REVIEW_SENSITIVE_PATTERNS):
6723
- protected.add(root)
6724
- continue
6725
- for directory, directories, files in os.walk(root, followlinks=False):
6726
- for name in [*directories, *files]:
6727
- path = Path(directory) / name
6728
- if any(re.search(pattern, str(path)) for pattern in agent_core.DELIVERY_REVIEW_SENSITIVE_PATTERNS):
6729
- protected.add(path)
6730
- if name in directories:
6731
- directories.remove(name)
6732
- for path in sorted(protected):
6733
- if path.is_dir():
6734
- wrapped += ["--tmpfs", str(path)]
6735
- elif path.exists() or path.is_symlink():
6736
- wrapped += ["--ro-bind", "/dev/null", str(path)]
6737
- return [*wrapped, "--chdir", str(workspace_path), "--", *command]
6738
6795
  executable_rules = " ".join(f"(subpath {json.dumps(root)})" for root in sorted(read_roots))
6739
6796
  metadata_paths = {
6740
6797
  str(parent) for root in [*read_roots, str(workspace.resolve()), str(home.resolve())]
@@ -14029,6 +14086,7 @@ class RuntimeDaemon:
14029
14086
  workspace_execution_lock: _WorkspaceFileLock | None = None
14030
14087
  local_bind_file_lock = None
14031
14088
  attachment_staging_dir: Path | None = None
14089
+ workspace_path: Path | None = None
14032
14090
  if is_local_bind and task.local_workspace_binding_id:
14033
14091
  # OS-level file lock keyed by binding_id (docs/designs/forgexa-
14034
14092
  # ide-design.md §6.3): the DB lease (orchestrator.py) prevents
@@ -15034,6 +15092,8 @@ class RuntimeDaemon:
15034
15092
  finally:
15035
15093
  if self.managed_policy is not None:
15036
15094
  await self.managed_policy.finish_task()
15095
+ if workspace_path is not None and agent_core.delivery_review_candidate(task.input_data, task.workspace_resolution) is not None:
15096
+ await self.workspace_manager.cleanup_workspace(workspace_path)
15037
15097
  if attachment_staging_dir is not None:
15038
15098
  shutil.rmtree(attachment_staging_dir, ignore_errors=True)
15039
15099
  if workspace_execution_lock is not None:
@@ -15324,7 +15384,7 @@ class RuntimeDaemon:
15324
15384
  dirty = await self.workspace_manager._git(
15325
15385
  "--no-optional-locks", "status", "--porcelain=v1", "-z", "--untracked-files=no", cwd=workspace_path, timeout=10,
15326
15386
  )
15327
- if branch != task.workspace_branch or not re.fullmatch(r"[0-9a-f]{40}", head) or dirty:
15387
+ if branch != task.workspace_branch or not re.fullmatch(r"[0-9a-f]{40}|[0-9a-f]{64}", head) or dirty:
15328
15388
  return failed("delivery_review_candidate_changed", "The candidate branch or workspace changed")
15329
15389
  target_ref = ""
15330
15390
  target = ""
@@ -15338,10 +15398,11 @@ class RuntimeDaemon:
15338
15398
  break
15339
15399
  except RuntimeError:
15340
15400
  continue
15341
- if not target_ref or not re.fullmatch(r"[0-9a-f]{40}", target):
15401
+ if not target_ref or not re.fullmatch(r"[0-9a-f]{40}|[0-9a-f]{64}", target):
15342
15402
  return failed("delivery_review_scope_incomplete", "The target branch cannot be resolved")
15343
- expected_head = (task.input_data or {}).get("delivery_review_expected_head")
15344
- expected_target = (task.input_data or {}).get("delivery_review_expected_target")
15403
+ candidate = agent_core.delivery_review_candidate(task.input_data, task.workspace_resolution) or {}
15404
+ expected_head = (task.input_data or {}).get("delivery_review_expected_head") or candidate.get("head_sha")
15405
+ expected_target = (task.input_data or {}).get("delivery_review_expected_target") or candidate.get("target_sha")
15345
15406
  if (expected_head is not None and expected_head != head) or (expected_target is not None and expected_target != target):
15346
15407
  return failed("delivery_review_candidate_changed", "The local workspace does not match the requested review version")
15347
15408
  preparation_stage = "merge_base"
@@ -17156,6 +17217,7 @@ class RuntimeDaemon:
17156
17217
  timeout_seconds = min(int(input_ctx.get("timeout_seconds", 300)), 300)
17157
17218
  sensitive_patterns = input_ctx.get("sensitive_path_patterns") or []
17158
17219
  candidate_ref = f"refs/heads/merge-candidate/{merge_job_id}"
17220
+ base_ref = base_integration_sha
17159
17221
 
17160
17222
  # Record merge_job_id → project_id so GC can query eligibility later.
17161
17223
  self._record_merge_job(merge_job_id, str(input_ctx.get("project_id") or ""))
@@ -17164,6 +17226,10 @@ class RuntimeDaemon:
17164
17226
  result = dict(result)
17165
17227
  if source_commit_sha and not result.get("source_commit_sha"):
17166
17228
  result["source_commit_sha"] = source_commit_sha
17229
+ if base_ref and not result.get("base_integration_sha"):
17230
+ result["base_integration_sha"] = base_ref
17231
+ if error and not result.get("ai_resolution_notes"):
17232
+ result["ai_resolution_notes"] = error[:2000]
17167
17233
  payload = {"status": status, "output_result": result}
17168
17234
  if error:
17169
17235
  payload["error"] = error[:1000]
@@ -17315,25 +17381,34 @@ class RuntimeDaemon:
17315
17381
  )
17316
17382
  return
17317
17383
 
17318
- # Attempt the merge.
17384
+ merge_message = f"deploy-merge: {source_branch or source_commit_sha[:8]}"
17385
+ merge_error: RuntimeError | None = None
17319
17386
  try:
17320
17387
  await git(
17321
17388
  "-c", f"user.name={_git_name}",
17322
17389
  "-c", f"user.email={_git_email}",
17323
- "merge", "--no-ff", "--no-edit", "-m", f"deploy-merge: {source_branch or source_commit_sha[:8]}",
17390
+ "merge", "--no-ff", "--no-commit", "--no-edit", "-m", merge_message,
17324
17391
  source_commit_sha,
17325
17392
  cwd=workspace_path,
17326
17393
  )
17327
- merge_conflicted = False
17328
- except RuntimeError:
17329
- merge_conflicted = True
17394
+ except RuntimeError as exc:
17395
+ merge_error = exc
17330
17396
 
17331
17397
  # Check for unresolved conflicts.
17332
- try:
17333
- diff_u = await git("diff", "--name-only", "--diff-filter=U", cwd=workspace_path)
17334
- except RuntimeError:
17335
- diff_u = ""
17336
- conflicted_files = [f.strip() for f in diff_u.strip().splitlines() if f.strip()]
17398
+ diff_u = await git(
17399
+ "diff", "--name-only", "--diff-filter=U", "-z", cwd=workspace_path,
17400
+ )
17401
+ conflicted_files = [path for path in diff_u.split("\0") if path]
17402
+ if merge_error and not conflicted_files:
17403
+ raise merge_error
17404
+
17405
+ excluded_runtime_paths = await agent_core.untrack_agent_runtime_files(
17406
+ workspace_path, git,
17407
+ )
17408
+ conflicted_files = [
17409
+ path for path in conflicted_files if not agent_core.is_agent_runtime_path(path)
17410
+ ]
17411
+ merge_conflicted = bool(conflicted_files)
17337
17412
  replayed_artifact_paths: list[str] = []
17338
17413
 
17339
17414
  artifact_prefix = f"docs/requirements/{requirement_key}/"
@@ -17367,12 +17442,6 @@ class RuntimeDaemon:
17367
17442
  cwd=workspace_path,
17368
17443
  )
17369
17444
  await git("add", "--", conflict_path, cwd=workspace_path)
17370
- await git(
17371
- "-c", f"user.name={_git_name}",
17372
- "-c", f"user.email={_git_email}",
17373
- "commit", "--no-edit",
17374
- cwd=workspace_path,
17375
- )
17376
17445
  replayed_artifact_paths = list(conflicted_files)
17377
17446
  conflicted_files = []
17378
17447
  merge_conflicted = False
@@ -17568,10 +17637,10 @@ class RuntimeDaemon:
17568
17637
 
17569
17638
  # Re-check remaining conflicts after this batch.
17570
17639
  try:
17571
- diff_u = await git("diff", "--name-only", "--diff-filter=U", cwd=workspace_path)
17572
- remaining = [
17573
- f.strip() for f in diff_u.strip().splitlines() if f.strip()
17574
- ]
17640
+ diff_u = await git(
17641
+ "diff", "--name-only", "--diff-filter=U", "-z", cwd=workspace_path,
17642
+ )
17643
+ remaining = [path for path in diff_u.split("\0") if path]
17575
17644
  except RuntimeError:
17576
17645
  pass # keep the previous remaining list
17577
17646
 
@@ -17609,15 +17678,6 @@ class RuntimeDaemon:
17609
17678
  )
17610
17679
  if runtime_error:
17611
17680
  raise RuntimeError(runtime_error)
17612
- try:
17613
- await git(
17614
- "-c", f"user.name={_git_name}",
17615
- "-c", f"user.email={_git_email}",
17616
- "commit", "--no-edit",
17617
- cwd=workspace_path,
17618
- )
17619
- except RuntimeError:
17620
- pass # merge may have already committed
17621
17681
  logger.info(
17622
17682
  "deployment_merge: AI resolution succeeded for job %s via %s",
17623
17683
  job_id, resolved_agent_id,
@@ -17626,6 +17686,16 @@ class RuntimeDaemon:
17626
17686
  # AI resolution succeeded — falls through to the shared
17627
17687
  # deterministic precheck + reporting block below.
17628
17688
 
17689
+ merge_head = await git("rev-parse", "--revs-only", "MERGE_HEAD", cwd=workspace_path)
17690
+ staged_paths = await git("diff", "--cached", "--name-only", "-z", cwd=workspace_path)
17691
+ if merge_head.strip() or staged_paths:
17692
+ await git(
17693
+ "-c", f"user.name={_git_name}",
17694
+ "-c", f"user.email={_git_email}",
17695
+ "commit", "-m", merge_message,
17696
+ cwd=workspace_path,
17697
+ )
17698
+
17629
17699
  # Deterministic precheck: scan for residual conflict markers.
17630
17700
  # Applies to both clean merges and AI-resolved merges. Scoped to
17631
17701
  # files actually in conflict — see _scan_conflicted_files_for_markers.
@@ -17643,21 +17713,21 @@ class RuntimeDaemon:
17643
17713
  "merge_outcome": "precheck_failed",
17644
17714
  "conflicted_files": marker_files[:30],
17645
17715
  "candidate_commit_sha": candidate_sha,
17716
+ "ai_resolution_notes": (
17717
+ "Residual Git conflict markers remain in the listed files."
17718
+ ),
17646
17719
  })
17647
17720
  return
17648
17721
 
17649
17722
  # Deterministic precheck: the working tree must be clean (no
17650
17723
  # unstaged/staged leftovers) after merge/commit. Untracked files
17651
17724
  # are ignored — worktrees may contain unrelated artifacts.
17652
- try:
17653
- status_out = await git(
17654
- "status", "--porcelain", "--untracked-files=no", cwd=workspace_path,
17655
- )
17656
- except RuntimeError:
17657
- status_out = ""
17725
+ status_out = await git(
17726
+ "status", "--porcelain", "--untracked-files=no", cwd=workspace_path,
17727
+ )
17658
17728
  dirty_files = [
17659
17729
  (line[3:].strip() if len(line) > 3 else line.strip())
17660
- for line in status_out.strip().splitlines()
17730
+ for line in status_out.splitlines()
17661
17731
  if line.strip()
17662
17732
  ]
17663
17733
  if dirty_files:
@@ -17669,6 +17739,9 @@ class RuntimeDaemon:
17669
17739
  "merge_outcome": "precheck_failed",
17670
17740
  "conflicted_files": dirty_files[:30],
17671
17741
  "candidate_commit_sha": candidate_sha,
17742
+ "ai_resolution_notes": (
17743
+ "The merge working tree has uncommitted changes in the listed files."
17744
+ ),
17672
17745
  })
17673
17746
  return
17674
17747
 
@@ -17677,6 +17750,7 @@ class RuntimeDaemon:
17677
17750
  # because the candidate ref is ephemeral — a re-merge (new train
17678
17751
  # round, baseline resync) produces a different commit history that
17679
17752
  # is NOT a fast-forward of the previous candidate.
17753
+ runtime_error = None
17680
17754
  try:
17681
17755
  runtime_error = await self._agent_runtime_commit_error(workspace_path)
17682
17756
  if runtime_error:
@@ -17687,8 +17761,9 @@ class RuntimeDaemon:
17687
17761
  timeout=settings.GIT_PUSH_TIMEOUT,
17688
17762
  )
17689
17763
  except RuntimeError as exc:
17764
+ error_message = runtime_error or f"candidate push failed: {exc}"
17690
17765
  logger.warning(
17691
- "deployment_merge: job %s candidate push failed: %s", job_id, exc,
17766
+ "deployment_merge: job %s precheck failed: %s", job_id, error_message,
17692
17767
  )
17693
17768
  await _report(
17694
17769
  {
@@ -17697,7 +17772,7 @@ class RuntimeDaemon:
17697
17772
  "candidate_ref": candidate_ref,
17698
17773
  },
17699
17774
  status="failed",
17700
- error=f"candidate push failed: {exc}",
17775
+ error=error_message,
17701
17776
  )
17702
17777
  return
17703
17778
 
@@ -17721,6 +17796,17 @@ class RuntimeDaemon:
17721
17796
  "deployment_merge: job %s %s → %s",
17722
17797
  job_id, outcome, candidate_sha[:12],
17723
17798
  )
17799
+ resolution_notes = []
17800
+ if replayed_artifact_paths:
17801
+ resolution_notes.append(
17802
+ f"Replaced {len(replayed_artifact_paths)} replayed requirement artifacts "
17803
+ f"under {artifact_prefix} from the new source commit."
17804
+ )
17805
+ if excluded_runtime_paths:
17806
+ resolution_notes.append(
17807
+ f"Excluded {len(excluded_runtime_paths)} tracked agent runtime state files "
17808
+ "from the deployment candidate; local files were preserved."
17809
+ )
17724
17810
  await _report({
17725
17811
  "merge_outcome": outcome,
17726
17812
  "resolved_agent": resolved_agent_id,
@@ -17729,11 +17815,7 @@ class RuntimeDaemon:
17729
17815
  "merge_commit_sha": candidate_sha,
17730
17816
  "base_integration_sha": base_ref,
17731
17817
  "source_commit_sha": source_commit_sha,
17732
- "ai_resolution_notes": (
17733
- f"Replaced {len(replayed_artifact_paths)} replayed requirement artifacts "
17734
- f"under {artifact_prefix} from the new source commit."
17735
- if replayed_artifact_paths else None
17736
- ),
17818
+ "ai_resolution_notes": "\n".join(resolution_notes) or None,
17737
17819
  })
17738
17820
 
17739
17821
  except Exception as exc:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: forgexa-cli
3
- Version: 1.104.2
3
+ Version: 1.104.4
4
4
  Summary: Forgexa CLI — command-line client and AI agent runtime for the Forgexa platform
5
5
  Author-email: Jason Sun <dev.winds@gmail.com>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "forgexa-cli"
3
- version = "1.104.2"
3
+ version = "1.104.4"
4
4
  description = "Forgexa CLI — command-line client and AI agent runtime for the Forgexa platform"
5
5
  requires-python = ">=3.9"
6
6
  license = "MIT"
File without changes
File without changes