forgexa-cli 1.98.3__tar.gz → 1.98.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/PKG-INFO +1 -1
  2. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/__init__.py +1 -1
  3. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/agent_core.py +12 -7
  4. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/component_runtime.py +124 -9
  5. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/daemon.py +1 -1
  6. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/ocr_adapter.py +2 -1
  7. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli.egg-info/PKG-INFO +1 -1
  8. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/pyproject.toml +1 -1
  9. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/README.md +0 -0
  10. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/_build_config.py +0 -0
  11. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/_local_bind.py +0 -0
  12. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/autoupgrade.py +0 -0
  13. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/aws_evidence.py +0 -0
  14. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/aws_logs_evidence.py +0 -0
  15. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/main.py +0 -0
  16. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/observability_contract.py +0 -0
  17. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/observability_evidence.py +0 -0
  18. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/py.typed +0 -0
  19. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/runtime_evidence.py +0 -0
  20. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/workspace_storage.py +0 -0
  21. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli/zcode_protocol.py +0 -0
  22. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli.egg-info/SOURCES.txt +0 -0
  23. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli.egg-info/dependency_links.txt +0 -0
  24. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli.egg-info/entry_points.txt +0 -0
  25. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli.egg-info/requires.txt +0 -0
  26. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/forgexa_cli.egg-info/top_level.txt +0 -0
  27. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/setup.cfg +0 -0
  28. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_auth_and_runtime_commands.py +0 -0
  29. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_autoupgrade.py +0 -0
  30. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_check_command.py +0 -0
  31. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_expiry_warnings_and_revoke.py +0 -0
  32. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_local_bind_commands.py +0 -0
  33. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_publish_script.py +0 -0
  34. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_runtime_credentials.py +0 -0
  35. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_session_credentials.py +0 -0
  36. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_silent_install.py +0 -0
  37. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/tests/test_upgrade_observability.py +0 -0
  38. {forgexa_cli-1.98.3 → forgexa_cli-1.98.5}/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.98.3
3
+ Version: 1.98.5
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.98.3"
2
+ __version__ = "1.98.5"
@@ -2096,13 +2096,14 @@ class AgentDiscovery:
2096
2096
  current_set = set(current.split(os.pathsep))
2097
2097
  additions = [str(d) for d in extra_dirs if d.is_dir() and str(d) not in current_set]
2098
2098
  if additions:
2099
- os.environ["PATH"] = os.pathsep.join(additions) + os.pathsep + current
2099
+ os.environ["PATH"] = os.pathsep.join(filter(None, (current, *additions)))
2100
2100
  logger.debug("Expanded PATH with: %s", ", ".join(additions))
2101
- if not is_win:
2102
- official_trae = home / ".forgexa" / "official" / "trae" / "bin"
2101
+ for component in (*AgentDiscovery.AGENT_REGISTRY, "forgexa.ocr"):
2102
+ official_base = home / ".forgexa" / "official" / component
2103
+ official_bin = official_base if is_win else official_base / "bin"
2103
2104
  current = os.environ.get("PATH", "")
2104
- if official_trae.is_dir() and str(official_trae) not in current.split(os.pathsep):
2105
- os.environ["PATH"] = os.pathsep.join(filter(None, (current, str(official_trae))))
2105
+ if official_bin.is_dir() and str(official_bin) not in current.split(os.pathsep):
2106
+ os.environ["PATH"] = os.pathsep.join(filter(None, (current, str(official_bin))))
2106
2107
 
2107
2108
  @staticmethod
2108
2109
  def _wsl_windows_executable(path: str) -> bool:
@@ -2224,7 +2225,11 @@ class AgentDiscovery:
2224
2225
  async def _discover_instance(
2225
2226
  self, agent_id: str, spec: dict, managed: Any = None
2226
2227
  ) -> DiscoveredAgent | None:
2227
- custom_path = os.environ.get(spec.get("env_path_override", ""))
2228
+ selected_path, selected_revision = (
2229
+ await asyncio.to_thread(component_runtime.selected_external_agent_selection, agent_id)
2230
+ if managed is None else (None, None)
2231
+ )
2232
+ custom_path = selected_path or os.environ.get(spec.get("env_path_override", ""))
2228
2233
  cmd = managed.argv_prefix[-1] if managed is not None else custom_path or spec["commands"][0]
2229
2234
  resolved = shutil.which(cmd)
2230
2235
  if resolved:
@@ -2288,7 +2293,7 @@ class AgentDiscovery:
2288
2293
  min_version_ok=min_version_ok,
2289
2294
  version_warning=version_warning,
2290
2295
  installation_id=managed.receipt["installation_id"] if managed is not None else None,
2291
- selection_revision=managed.selection_revision if managed is not None else None,
2296
+ selection_revision=managed.selection_revision if managed is not None else selected_revision,
2292
2297
  )
2293
2298
  logger.info("Discovered agent: %s v%s (%s)", agent_id, version, resolved)
2294
2299
  if managed is not None:
@@ -917,6 +917,41 @@ def _require_absent_unverified_selection(root: Path, component_id: str) -> None:
917
917
  raise ComponentRuntimeError("component_platform_unverified")
918
918
 
919
919
 
920
+ def _valid_external_selection_path(path: Any) -> bool:
921
+ if not isinstance(path, str) or not path.startswith("/"):
922
+ return False
923
+ try:
924
+ if len(path.encode("utf-8")) > 4096:
925
+ return False
926
+ except UnicodeEncodeError:
927
+ return False
928
+ return (
929
+ not any(ord(character) < 32 or ord(character) == 127 or character == ":" for character in path)
930
+ and all(part not in {"", ".", ".."} for part in path.split("/")[1:])
931
+ )
932
+
933
+
934
+ def _wsl_external_selection(component_id: str) -> dict[str, Any] | None:
935
+ base = Path.home() / ".forgexa" / "wsl-workspace"
936
+ path = base / f"component-{component_id}.json"
937
+ try:
938
+ path.lstat()
939
+ except FileNotFoundError:
940
+ return None
941
+ for directory, private in ((base.parent, False), (base, True)):
942
+ metadata = directory.lstat()
943
+ if (not stat.S_ISDIR(metadata.st_mode) or metadata.st_uid != os.getuid()
944
+ or metadata.st_mode & (0o077 if private else 0o022)):
945
+ raise ComponentRuntimeError("component_storage_invalid")
946
+ selection = _record(path, {"schema_version", "component_id", "revision", "enabled", "external_path"})
947
+ if (selection is None or selection["component_id"] != component_id
948
+ or type(selection["revision"]) is not int or not 1 <= selection["revision"] <= 9_007_199_254_740_991
949
+ or type(selection["enabled"]) is not bool
950
+ or (selection["external_path"] is not None and not _valid_external_selection_path(selection["external_path"]))):
951
+ raise ComponentRuntimeError("component_selection_invalid")
952
+ return selection
953
+
954
+
920
955
  def _acquire_component(
921
956
  component_id: str, root: Path | None = None, override: str | None = None,
922
957
  kind: str = "agent",
@@ -927,9 +962,17 @@ def _acquire_component(
927
962
  root = default_store_root() if root is None else root
928
963
  if root.is_symlink():
929
964
  raise ComponentRuntimeError("component_storage_invalid")
965
+ if os.name == "posix" and os.environ.get("WSL_DISTRO_NAME"):
966
+ if root.exists():
967
+ _require_absent_unverified_selection(root, component_id)
968
+ if kind == "agent":
969
+ selection = _wsl_external_selection(component_id)
970
+ if selection is not None and not selection["enabled"]:
971
+ raise ComponentRuntimeError("component_disabled")
972
+ return None
930
973
  if not root.exists():
931
974
  return None
932
- if os.name != "posix" or os.environ.get("WSL_DISTRO_NAME"):
975
+ if os.name != "posix":
933
976
  _require_absent_unverified_selection(root, component_id)
934
977
  return None
935
978
  import fcntl
@@ -945,7 +988,7 @@ def _acquire_component(
945
988
  "installation_id",
946
989
  "enabled",
947
990
  },
948
- optional_fields={"external"},
991
+ optional_fields={"external", "external_path"},
949
992
  )
950
993
  if selection is None:
951
994
  return None
@@ -964,7 +1007,9 @@ def _acquire_component(
964
1007
  external = selection.get("external")
965
1008
  if (external is not None and external is not True) or (
966
1009
  external is True and (selection["installation_id"] is not None or kind != "agent")
967
- ):
1010
+ ) or ("external_path" in selection and (
1011
+ external is not True or not _valid_external_selection_path(selection["external_path"])
1012
+ )):
968
1013
  raise ComponentRuntimeError("component_selection_invalid")
969
1014
  if not selection["enabled"]:
970
1015
  raise ComponentRuntimeError("component_disabled")
@@ -1096,14 +1141,70 @@ def acquire_component(
1096
1141
  raise ComponentRuntimeError("component_storage_unavailable") from error
1097
1142
 
1098
1143
 
1144
+ def selected_external_agent_selection(component_id: str, root: Path | None = None) -> tuple[str | None, int | None]:
1145
+ _identifier(component_id)
1146
+ root = default_store_root() if root is None else root
1147
+ if root.is_symlink():
1148
+ raise ComponentRuntimeError("component_storage_invalid")
1149
+ try:
1150
+ if os.name == "posix" and os.environ.get("WSL_DISTRO_NAME"):
1151
+ if root.exists():
1152
+ _require_absent_unverified_selection(root, component_id)
1153
+ selection = _wsl_external_selection(component_id)
1154
+ if selection is not None:
1155
+ if not selection["enabled"]:
1156
+ raise ComponentRuntimeError("component_disabled")
1157
+ return selection["external_path"], selection["revision"]
1158
+ return None, None
1159
+ if not root.exists():
1160
+ return None, None
1161
+ if os.name != "posix":
1162
+ _require_absent_unverified_selection(root, component_id)
1163
+ return None, None
1164
+ with _ComponentManagerLock(root):
1165
+ selection = _record(
1166
+ root / "selections" / f"{component_id}.json",
1167
+ {"schema_version", "target_id", "component_id", "revision", "installation_id", "enabled"},
1168
+ optional_fields={"external", "external_path"},
1169
+ )
1170
+ if selection is None:
1171
+ return None, None
1172
+ target = _component_target(root)
1173
+ if (
1174
+ selection["target_id"] != target["target_id"] or selection["component_id"] != component_id
1175
+ or type(selection["revision"]) is not int or not 0 <= selection["revision"] <= 9_007_199_254_740_991
1176
+ or type(selection["enabled"]) is not bool
1177
+ ):
1178
+ raise ComponentRuntimeError("component_selection_invalid")
1179
+ if not selection["enabled"]:
1180
+ raise ComponentRuntimeError("component_disabled")
1181
+ if selection.get("external") is not True or selection["installation_id"] is not None:
1182
+ raise ComponentRuntimeError("component_selection_changed")
1183
+ path = selection.get("external_path")
1184
+ if path is not None and not _valid_external_selection_path(path):
1185
+ raise ComponentRuntimeError("component_selection_invalid")
1186
+ return path, selection["revision"]
1187
+ except OSError as error:
1188
+ raise ComponentRuntimeError("component_storage_unavailable") from error
1189
+
1190
+
1099
1191
  def require_unselected_component(component_id: str, root: Path | None = None) -> None:
1100
1192
  _identifier(component_id)
1101
1193
  root = default_store_root() if root is None else root
1102
1194
  if root.is_symlink():
1103
1195
  raise ComponentRuntimeError("component_storage_invalid")
1196
+ if os.name == "posix" and os.environ.get("WSL_DISTRO_NAME"):
1197
+ try:
1198
+ if root.exists():
1199
+ _require_absent_unverified_selection(root, component_id)
1200
+ if _wsl_external_selection(component_id) is not None:
1201
+ raise ComponentRuntimeError("component_selection_changed")
1202
+ except OSError as error:
1203
+ raise ComponentRuntimeError("component_storage_unavailable") from error
1204
+ return
1104
1205
  if not root.exists():
1105
1206
  return
1106
- if os.name != "posix" or os.environ.get("WSL_DISTRO_NAME"):
1207
+ if os.name != "posix":
1107
1208
  try:
1108
1209
  _require_absent_unverified_selection(root, component_id)
1109
1210
  except OSError as error:
@@ -1134,11 +1235,20 @@ def require_external_selection(
1134
1235
  root = default_store_root() if root is None else root
1135
1236
  if root.is_symlink():
1136
1237
  raise ComponentRuntimeError("component_storage_invalid")
1137
- if not root.exists():
1138
- raise ComponentRuntimeError("component_selection_changed")
1139
- if os.name != "posix" or os.environ.get("WSL_DISTRO_NAME"):
1140
- raise ComponentRuntimeError("component_platform_unverified")
1141
1238
  try:
1239
+ if os.name == "posix" and os.environ.get("WSL_DISTRO_NAME"):
1240
+ if root.exists():
1241
+ _require_absent_unverified_selection(root, component_id)
1242
+ selection = _wsl_external_selection(component_id)
1243
+ if component_id != "forgexa.ocr" or selection is None or selection["revision"] != revision:
1244
+ raise ComponentRuntimeError("component_selection_changed")
1245
+ if not selection["enabled"] and not allow_disabled:
1246
+ raise ComponentRuntimeError("component_disabled")
1247
+ return selection["external_path"]
1248
+ if not root.exists():
1249
+ raise ComponentRuntimeError("component_selection_changed")
1250
+ if os.name != "posix":
1251
+ raise ComponentRuntimeError("component_platform_unverified")
1142
1252
  with _ComponentManagerLock(root):
1143
1253
  target = _component_target(root)
1144
1254
  selection = _record(
@@ -1203,8 +1313,13 @@ def admit_execution(
1203
1313
  ) -> ManagedComponentLease | None:
1204
1314
  lease = acquire_component(component_id, root=root, override=override)
1205
1315
  if lease is None:
1206
- if installation_id is not None or selection_revision is not None:
1316
+ if installation_id is not None:
1207
1317
  raise ComponentRuntimeError("component_instance_missing")
1318
+ selected_path, selected_revision = selected_external_agent_selection(component_id, root)
1319
+ if selected_revision != selection_revision:
1320
+ raise ComponentRuntimeError("component_selection_changed")
1321
+ if selected_path is not None and os.path.realpath(binary_path) != os.path.realpath(selected_path):
1322
+ raise ComponentRuntimeError("component_instance_changed")
1208
1323
  validate_external_executable(binary_path, root)
1209
1324
  return None
1210
1325
  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.98.3"
1415
+ DAEMON_VERSION = "1.98.5"
1416
1416
 
1417
1417
 
1418
1418
  def _detect_client_type() -> str:
@@ -262,8 +262,9 @@ async def run_ocr_delegation(
262
262
  *,
263
263
  external_executable: Path | None = None,
264
264
  expected_external_instance: str | None = None,
265
+ _wsl_guarded: bool = False,
265
266
  ) -> dict[str, Any]:
266
- if os.name != "posix" or os.environ.get("WSL_DISTRO_NAME"):
267
+ if os.name != "posix" or (os.environ.get("WSL_DISTRO_NAME") and not _wsl_guarded):
267
268
  raise OcrAdapterError("ocr_platform_unverified")
268
269
  if (lease is None) == (external_executable is None):
269
270
  raise OcrAdapterError("ocr_instance_unavailable")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: forgexa-cli
3
- Version: 1.98.3
3
+ Version: 1.98.5
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.98.3"
3
+ version = "1.98.5"
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