agentenv-framework 0.9.1254__py3-none-any.whl

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 (312) hide show
  1. agent_env/__init__.py +0 -0
  2. agent_env/a2a_agent/__init__.py +23 -0
  3. agent_env/a2a_agent/a2a_agent.py +600 -0
  4. agent_env/a2a_agent/conversation_store.py +356 -0
  5. agent_env/a2a_agent/object_transfer.py +609 -0
  6. agent_env/a2a_agent/protocol.py +238 -0
  7. agent_env/a2a_agent/store.py +201 -0
  8. agent_env/a2a_agent/validator.py +901 -0
  9. agent_env/artifact/__init__.py +48 -0
  10. agent_env/artifact/artifact.py +74 -0
  11. agent_env/artifact/artifacts/__init__.py +0 -0
  12. agent_env/artifact/artifacts/cli.py +83 -0
  13. agent_env/artifact/artifacts/docker_image.py +457 -0
  14. agent_env/artifact/artifacts/environment.py +89 -0
  15. agent_env/artifact/artifacts/environment_universe.py +156 -0
  16. agent_env/artifact/artifacts/file.py +214 -0
  17. agent_env/artifact/artifacts/file_artifact_universe.py +206 -0
  18. agent_env/artifact/artifacts/skill.py +206 -0
  19. agent_env/artifact/artifacts/vm_image.py +95 -0
  20. agent_env/artifact/ref.py +15 -0
  21. agent_env/artifact/registry.py +251 -0
  22. agent_env/artifact/store.py +295 -0
  23. agent_env/artifact/universe.py +38 -0
  24. agent_env/attribution.py +41 -0
  25. agent_env/bundle/__init__.py +4 -0
  26. agent_env/bundle/_fs.py +128 -0
  27. agent_env/bundle/authoring.py +239 -0
  28. agent_env/bundle/installed.py +175 -0
  29. agent_env/bundle/ledger.py +269 -0
  30. agent_env/bundle/materialize.py +204 -0
  31. agent_env/bundle/parse.py +594 -0
  32. agent_env/bundle/plan.py +414 -0
  33. agent_env/bundle/resolve.py +404 -0
  34. agent_env/bundle/run.py +361 -0
  35. agent_env/cli/__init__.py +69 -0
  36. agent_env/cli/__main__.py +10 -0
  37. agent_env/cli/_installers.py +576 -0
  38. agent_env/cli/_plugin_changes.py +947 -0
  39. agent_env/cli/a2a_agent/__init__.py +22 -0
  40. agent_env/cli/a2a_agent/add_skill.py +97 -0
  41. agent_env/cli/a2a_agent/deploy.py +60 -0
  42. agent_env/cli/a2a_agent/get.py +15 -0
  43. agent_env/cli/a2a_agent/get_instance.py +26 -0
  44. agent_env/cli/a2a_agent/put.py +78 -0
  45. agent_env/cli/a2a_agent/validate.py +56 -0
  46. agent_env/cli/artifact/__init__.py +20 -0
  47. agent_env/cli/artifact/cli.py +83 -0
  48. agent_env/cli/artifact/environment.py +44 -0
  49. agent_env/cli/artifact/environment_universe.py +163 -0
  50. agent_env/cli/artifact/file_artifact_universe.py +281 -0
  51. agent_env/cli/artifact/skill.py +128 -0
  52. agent_env/cli/banner.py +25 -0
  53. agent_env/cli/config.py +263 -0
  54. agent_env/cli/env/__init__.py +31 -0
  55. agent_env/cli/env/deploy.py +112 -0
  56. agent_env/cli/env/gateway.py +57 -0
  57. agent_env/cli/env/get_instance.py +40 -0
  58. agent_env/cli/env/mcp_server.py +410 -0
  59. agent_env/cli/env/multi.py +282 -0
  60. agent_env/cli/env/service_db.py +99 -0
  61. agent_env/cli/env/snapshot.py +35 -0
  62. agent_env/cli/env/state/__init__.py +6 -0
  63. agent_env/cli/env/state/init.py +108 -0
  64. agent_env/cli/env/state/teardown.py +44 -0
  65. agent_env/cli/env/website.py +216 -0
  66. agent_env/cli/env/website_browser.py +67 -0
  67. agent_env/cli/eval/__init__.py +16 -0
  68. agent_env/cli/eval/add_tasks.py +63 -0
  69. agent_env/cli/eval/create.py +49 -0
  70. agent_env/cli/eval/run.py +194 -0
  71. agent_env/cli/identity/__init__.py +5 -0
  72. agent_env/cli/identity/client_identity.py +37 -0
  73. agent_env/cli/plugin.py +438 -0
  74. agent_env/cli/run.py +285 -0
  75. agent_env/cli/task/__init__.py +21 -0
  76. agent_env/cli/task/create.py +109 -0
  77. agent_env/cli/task/get.py +17 -0
  78. agent_env/cli/task/get_instance.py +34 -0
  79. agent_env/cli/task/run.py +615 -0
  80. agent_env/cli/task/validate.py +31 -0
  81. agent_env/cli/up.py +123 -0
  82. agent_env/cli/utils.py +183 -0
  83. agent_env/config/__init__.py +50 -0
  84. agent_env/config/describe.py +1067 -0
  85. agent_env/config/errors.py +13 -0
  86. agent_env/config/loader.py +245 -0
  87. agent_env/config/model.py +154 -0
  88. agent_env/config/paths.py +25 -0
  89. agent_env/config/plugin_tables.py +101 -0
  90. agent_env/config/provenance.py +134 -0
  91. agent_env/config/runtime.py +1064 -0
  92. agent_env/config/snapshot.py +81 -0
  93. agent_env/entity_refs.py +186 -0
  94. agent_env/env/__init__.py +49 -0
  95. agent_env/env/env.py +433 -0
  96. agent_env/env/env_artifact_store.py +87 -0
  97. agent_env/env/envs/__init__.py +7 -0
  98. agent_env/env/envs/_deployment.py +281 -0
  99. agent_env/env/envs/gateway_server.py +32 -0
  100. agent_env/env/envs/mcp_server.py +387 -0
  101. agent_env/env/envs/multi_env.py +780 -0
  102. agent_env/env/envs/service_db/Dockerfile +20 -0
  103. agent_env/env/envs/service_db/Dockerfile.db-mcp +42 -0
  104. agent_env/env/envs/service_db/Dockerfile.db-web +8 -0
  105. agent_env/env/envs/service_db.py +92 -0
  106. agent_env/env/envs/website.py +294 -0
  107. agent_env/env/envs/website_browser/Dockerfile +40 -0
  108. agent_env/env/envs/website_browser/__init__.py +17 -0
  109. agent_env/env/envs/website_browser/entrypoint.sh +13 -0
  110. agent_env/env/gateway/Dockerfile +14 -0
  111. agent_env/env/gateway/__init__.py +37 -0
  112. agent_env/env/gateway/clock.py +184 -0
  113. agent_env/env/gateway/constants.py +190 -0
  114. agent_env/env/gateway/entrypoint.py +156 -0
  115. agent_env/env/gateway/gateway.py +1095 -0
  116. agent_env/env/gateway/get_time.py +60 -0
  117. agent_env/env/gateway/requirements.txt +4 -0
  118. agent_env/env/gateway/triggers.py +1193 -0
  119. agent_env/env/legacy_protocol.py +146 -0
  120. agent_env/env/registry.py +93 -0
  121. agent_env/env/snapshot_store.py +372 -0
  122. agent_env/env/store.py +411 -0
  123. agent_env/eval/__init__.py +14 -0
  124. agent_env/eval/eval.py +68 -0
  125. agent_env/eval/store.py +116 -0
  126. agent_env/examples/hello/README.md +9 -0
  127. agent_env/examples/hello/artifacts/greeting/check.sh +1 -0
  128. agent_env/examples/hello/artifacts/greeting/hello.txt +1 -0
  129. agent_env/examples/hello/tasks/hello.json +10 -0
  130. agent_env/explorer/__init__.py +12 -0
  131. agent_env/explorer/app.py +277 -0
  132. agent_env/explorer/openapi_docs.py +242 -0
  133. agent_env/explorer/plugin.py +95 -0
  134. agent_env/explorer/routers/__init__.py +1 -0
  135. agent_env/explorer/routers/common.py +174 -0
  136. agent_env/explorer/routers/conversations.py +25 -0
  137. agent_env/explorer/routers/objects.py +112 -0
  138. agent_env/explorer/routers/runs.py +475 -0
  139. agent_env/plugins/__init__.py +59 -0
  140. agent_env/plugins/_cli.py +244 -0
  141. agent_env/plugins/_discovery.py +97 -0
  142. agent_env/plugins/_inventory.py +262 -0
  143. agent_env/plugins/_registration.py +268 -0
  144. agent_env/plugins/_report.py +47 -0
  145. agent_env/plugins/_requirements.py +55 -0
  146. agent_env/providers/__init__.py +37 -0
  147. agent_env/providers/env_providers/__init__.py +12 -0
  148. agent_env/providers/env_providers/constants.py +13 -0
  149. agent_env/providers/env_providers/env_gateway_provider.py +1354 -0
  150. agent_env/providers/env_providers/env_provider.py +237 -0
  151. agent_env/providers/env_providers/env_server_provider.py +133 -0
  152. agent_env/providers/env_state/__init__.py +49 -0
  153. agent_env/providers/env_state/env_state_provider.py +554 -0
  154. agent_env/providers/env_state/local_postgres.py +390 -0
  155. agent_env/providers/env_state/store.py +112 -0
  156. agent_env/providers/sandbox_providers/__init__.py +29 -0
  157. agent_env/providers/sandbox_providers/chained_sandbox_provider.py +93 -0
  158. agent_env/providers/sandbox_providers/e2b/__init__.py +6 -0
  159. agent_env/providers/sandbox_providers/e2b/provider.py +376 -0
  160. agent_env/providers/sandbox_providers/e2b/sandbox.py +342 -0
  161. agent_env/providers/sandbox_providers/e2b/template.py +158 -0
  162. agent_env/providers/sandbox_providers/local_sandbox.py +408 -0
  163. agent_env/providers/sandbox_providers/modal_sandbox.py +500 -0
  164. agent_env/providers/sandbox_providers/modal_vm_sandbox.py +466 -0
  165. agent_env/providers/sandbox_providers/sandbox.py +387 -0
  166. agent_env/providers/sandbox_providers/sandbox_provider.py +614 -0
  167. agent_env/py.typed +0 -0
  168. agent_env/runner/__init__.py +16 -0
  169. agent_env/runner/local_runner.py +190 -0
  170. agent_env/runner/runner.py +127 -0
  171. agent_env/runner/store.py +94 -0
  172. agent_env/store/__init__.py +126 -0
  173. agent_env/store/_google.py +68 -0
  174. agent_env/store/base.py +33 -0
  175. agent_env/store/document_store/__init__.py +60 -0
  176. agent_env/store/document_store/document_store.py +519 -0
  177. agent_env/store/document_store/dynamodb_document_store.py +306 -0
  178. agent_env/store/document_store/evaluation.py +199 -0
  179. agent_env/store/document_store/firestore_mongo_document_store.py +242 -0
  180. agent_env/store/document_store/mongo_document_store.py +259 -0
  181. agent_env/store/document_store/sqlite_document_store.py +314 -0
  182. agent_env/store/ids.py +123 -0
  183. agent_env/store/image_store/__init__.py +34 -0
  184. agent_env/store/image_store/ecr_image_store.py +131 -0
  185. agent_env/store/image_store/google_credentials.py +113 -0
  186. agent_env/store/image_store/image_store.py +113 -0
  187. agent_env/store/image_store/local_registry_image_store.py +106 -0
  188. agent_env/store/image_store/oci_registry_credentials.py +196 -0
  189. agent_env/store/local_state.py +27 -0
  190. agent_env/store/object_store/__init__.py +24 -0
  191. agent_env/store/object_store/gcs_object_store.py +415 -0
  192. agent_env/store/object_store/local_object_store.py +143 -0
  193. agent_env/store/object_store/object_store.py +198 -0
  194. agent_env/store/object_store/s3_object_store.py +354 -0
  195. agent_env/store/query.py +112 -0
  196. agent_env/store/routing.py +609 -0
  197. agent_env/store/secret_store/__init__.py +19 -0
  198. agent_env/store/secret_store/aws_secrets_manager_secret_store.py +293 -0
  199. agent_env/store/secret_store/gcp_secret_manager_secret_store.py +319 -0
  200. agent_env/store/secret_store/local_secret_store.py +47 -0
  201. agent_env/store/secret_store/secret_store.py +19 -0
  202. agent_env/task/__init__.py +27 -0
  203. agent_env/task/interrupts.py +109 -0
  204. agent_env/task/registry.py +27 -0
  205. agent_env/task/step_journal.py +99 -0
  206. agent_env/task/store.py +940 -0
  207. agent_env/task/task.py +815 -0
  208. agent_env/task/teardown.py +142 -0
  209. agent_env/task_step/__init__.py +47 -0
  210. agent_env/task_step/context.py +195 -0
  211. agent_env/task_step/context_ops.py +224 -0
  212. agent_env/task_step/registry.py +182 -0
  213. agent_env/task_step/review_store.py +118 -0
  214. agent_env/task_step/snapshot_utils/__init__.py +2 -0
  215. agent_env/task_step/snapshot_utils/agent_state_capture.py +261 -0
  216. agent_env/task_step/snapshot_utils/snapshot_series.py +631 -0
  217. agent_env/task_step/store.py +129 -0
  218. agent_env/task_step/task_step.py +173 -0
  219. agent_env/task_step/task_steps/__init__.py +27 -0
  220. agent_env/task_step/task_steps/a2a_agent_validator/__init__.py +31 -0
  221. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/README.md +158 -0
  222. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.m4a +0 -0
  223. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.mp3 +0 -0
  224. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.mp4 +0 -0
  225. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.ogg +0 -0
  226. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.wav +0 -0
  227. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/document.pdf +0 -0
  228. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.gif +0 -0
  229. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.jpg +0 -0
  230. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.png +0 -0
  231. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_card.py +103 -0
  232. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_config_identity.py +69 -0
  233. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_mcp.py +178 -0
  234. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_core_protocol.py +67 -0
  235. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_install.py +115 -0
  236. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_litellm_attribution.py +124 -0
  237. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_litellm_attribution_runtime.py +173 -0
  238. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_modalities.py +270 -0
  239. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_peer_agents.py +102 -0
  240. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_role.py +151 -0
  241. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_skill_config.py +194 -0
  242. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_snapshot.py +111 -0
  243. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_system_prompt.py +215 -0
  244. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_trajectory.py +164 -0
  245. agent_env/task_step/task_steps/add_skills.py +240 -0
  246. agent_env/task_step/task_steps/apply_server_config.py +288 -0
  247. agent_env/task_step/task_steps/collect_artifacts.py +940 -0
  248. agent_env/task_step/task_steps/deploy_agent.py +626 -0
  249. agent_env/task_step/task_steps/deploy_env.py +197 -0
  250. agent_env/task_step/task_steps/deploy_human_agent.py +100 -0
  251. agent_env/task_step/task_steps/deploy_sandbox.py +170 -0
  252. agent_env/task_step/task_steps/env_card_validator/__init__.py +4 -0
  253. agent_env/task_step/task_steps/env_card_validator/verify_env_card.py +109 -0
  254. agent_env/task_step/task_steps/env_card_validator/verify_env_core_protocol.py +108 -0
  255. agent_env/task_step/task_steps/install_agent.py +376 -0
  256. agent_env/task_step/task_steps/load_artifact.py +775 -0
  257. agent_env/task_step/task_steps/mcp_cli_builder/__init__.py +4 -0
  258. agent_env/task_step/task_steps/mcp_cli_builder/build_mcp_cli.py +201 -0
  259. agent_env/task_step/task_steps/mcp_cli_builder/codegen.py +627 -0
  260. agent_env/task_step/task_steps/mcp_env_validator/__init__.py +44 -0
  261. agent_env/task_step/task_steps/mcp_env_validator/validation_gate_aggregator.py +102 -0
  262. agent_env/task_step/task_steps/mcp_env_validator/verify_mcp_env_assessment.py +78 -0
  263. agent_env/task_step/task_steps/mcp_env_validator/verify_mcp_tool_schema.py +152 -0
  264. agent_env/task_step/task_steps/mcp_env_validator/verify_spec_conformance.py +486 -0
  265. agent_env/task_step/task_steps/modify_env_tool_access.py +80 -0
  266. agent_env/task_step/task_steps/multienv_validator/__init__.py +3 -0
  267. agent_env/task_step/task_steps/multienv_validator/combine_universe_verdicts.py +107 -0
  268. agent_env/task_step/task_steps/multienv_validator/universe_comparison.py +253 -0
  269. agent_env/task_step/task_steps/multienv_validator/verify_universe_agent_judge.py +180 -0
  270. agent_env/task_step/task_steps/multienv_validator/verify_universe_roundtrip.py +241 -0
  271. agent_env/task_step/task_steps/peer_agents.py +92 -0
  272. agent_env/task_step/task_steps/prompt_agent.py +900 -0
  273. agent_env/task_step/task_steps/register_agent_triggers.py +113 -0
  274. agent_env/task_step/task_steps/register_env_triggers.py +97 -0
  275. agent_env/task_step/task_steps/reset_env.py +71 -0
  276. agent_env/task_step/task_steps/review.py +152 -0
  277. agent_env/task_step/task_steps/run_code.py +461 -0
  278. agent_env/task_step/task_steps/run_code_runner.py +52 -0
  279. agent_env/task_step/task_steps/run_docker_container.py +380 -0
  280. agent_env/task_step/task_steps/sandbox_utils/__init__.py +0 -0
  281. agent_env/task_step/task_steps/sandbox_utils/sandbox_utils.py +79 -0
  282. agent_env/task_step/task_steps/snapshot_agent_state.py +205 -0
  283. agent_env/task_step/task_steps/snapshot_env.py +637 -0
  284. agent_env/task_step/task_steps/sync_env_clock.py +132 -0
  285. agent_env/task_step/task_steps/teardown_sandboxes.py +170 -0
  286. agent_env/task_step/task_steps/verifiers/__init__.py +23 -0
  287. agent_env/task_step/task_steps/verifiers/agent_prompt_response_verifier.py +166 -0
  288. agent_env/task_step/task_steps/verifiers/aggregate_verifiers.py +90 -0
  289. agent_env/task_step/task_steps/verifiers/env_outcome_verifier.py +127 -0
  290. agent_env/task_step/task_steps/verifiers/judge_utils/__init__.py +2 -0
  291. agent_env/task_step/task_steps/verifiers/judge_utils/frame_selection.py +377 -0
  292. agent_env/task_step/task_steps/verifiers/judge_utils/judge_output_format.py +1293 -0
  293. agent_env/task_step/task_steps/verifiers/judge_utils/trajectory_filter.py +514 -0
  294. agent_env/task_step/task_steps/verifiers/rubrics_verifier.py +1318 -0
  295. agent_env/task_step/task_steps/verifiers/run_container_unit_tests_verifier.py +434 -0
  296. agent_env/task_step/task_steps/verifiers/scoring.py +40 -0
  297. agent_env/task_step/task_steps/verifiers/verify_sandbox.py +308 -0
  298. agent_env/task_step/thread_work.py +61 -0
  299. agent_env/utils/__init__.py +0 -0
  300. agent_env/utils/card_naming.py +108 -0
  301. agent_env/utils/deprecation.py +109 -0
  302. agent_env/utils/docker_build.py +29 -0
  303. agent_env/utils/exec_retry.py +77 -0
  304. agent_env/utils/litellm_attribution.py +59 -0
  305. agent_env/utils/paths.py +20 -0
  306. agentenv_framework-0.9.1254.dist-info/METADATA +394 -0
  307. agentenv_framework-0.9.1254.dist-info/RECORD +312 -0
  308. agentenv_framework-0.9.1254.dist-info/WHEEL +4 -0
  309. agentenv_framework-0.9.1254.dist-info/entry_points.txt +5 -0
  310. agentenv_framework-0.9.1254.dist-info/licenses/LICENSE +202 -0
  311. agentenv_framework-0.9.1254.dist-info/licenses/NOTICE +4 -0
  312. agentenv_framework-0.9.1254.dist-info/licenses/THIRD_PARTY_NOTICES.md +7665 -0
@@ -0,0 +1,404 @@
1
+ """Rewrite each reference in a parsed bundle to the id it names, before anything is built or written.
2
+
3
+ References are the fields step types declare in ``entity_refs`` and the toml keys entity types declare
4
+ in ``toml_refs``. The name of one of this bundle's entities becomes that entity's id, a name an output
5
+ of the same task writes becomes the output's id, and anything else is a store id, left as written;
6
+ whether store ids exist is checked later, with the other checks that read a store.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import copy
12
+ import unicodedata
13
+ from collections.abc import Iterator
14
+ from dataclasses import dataclass
15
+ from pathlib import Path
16
+ from typing import Any
17
+
18
+ from agent_env.a2a_agent import A2AAgent
19
+ from agent_env.artifact.registry import canonical_type, get_artifact_registry
20
+ from agent_env.entity_refs import EntityKind, EntityRef, RefRole, RefSite, parse_toml_ref, ref_sites
21
+ from agent_env.env.registry import get_env_registry
22
+ from agent_env.eval.eval import Eval
23
+ from agent_env.plugins import _registration
24
+ from agent_env.store.ids import LOCAL_PREFIX, validate_local_id
25
+ from agent_env.task_step.registry import get_task_step_registry
26
+ from agent_env.task_step.task_step import TaskStep, attach_retry_config
27
+
28
+ from ._fs import fold, relative, show
29
+ from .parse import NAMED_BY, Bundle, BundleEntry, BundleError, BundleKind
30
+
31
+ # Step keys that hold step ids, never entity ids.
32
+ _STEP_ID_KEYS = ("id", "type", "depends_on")
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class BuiltImage:
37
+ """The image built from an env or agent folder for one of its image keys."""
38
+
39
+ id: str
40
+ entry: BundleEntry
41
+ dockerfile: str # relative to the entry's folder
42
+
43
+
44
+ @dataclass(frozen=True)
45
+ class Reference:
46
+ """A resolved reference: to ``local``, this bundle's entity or built image, or, when ``local`` is
47
+ None, to a store id at ``version`` (None for its latest)."""
48
+
49
+ kind: EntityKind
50
+ id: str
51
+ version: int | None
52
+ local: BundleEntry | BuiltImage | None
53
+ where: str # the referencing field, as problems name it
54
+ artifact_type: str | None # the type the field takes, when it names one
55
+
56
+
57
+ @dataclass(frozen=True)
58
+ class Output:
59
+ """An id a task's step writes, named under the task."""
60
+
61
+ kind: EntityKind
62
+ id: str
63
+ step: int # the writing step's index in the task
64
+ step_id: Any
65
+ artifact_type: str | None
66
+
67
+
68
+ @dataclass(frozen=True)
69
+ class ResolvedEntry:
70
+ """An entry's config as a copy with every declared reference rewritten, what it references, and
71
+ for a task what its steps write."""
72
+
73
+ entry: BundleEntry
74
+ config: Any
75
+ references: tuple[Reference, ...]
76
+ outputs: tuple[Output, ...]
77
+
78
+
79
+ @dataclass(frozen=True)
80
+ class ResolvedBundle:
81
+ bundle: Bundle
82
+ entries: tuple[ResolvedEntry, ...]
83
+ built_images: tuple[BuiltImage, ...]
84
+
85
+
86
+ def resolve_bundle(bundle: Bundle) -> ResolvedBundle:
87
+ """Resolve every entry's references. Raises BundleError listing every problem found."""
88
+ return _Resolver(bundle).resolve()
89
+
90
+
91
+ class _Skip(Exception):
92
+ """An entry that can't be resolved; its problem is already recorded."""
93
+
94
+
95
+ class _Resolver:
96
+ def __init__(self, bundle: Bundle):
97
+ self.bundle = bundle
98
+ self.problems: list[str] = []
99
+ self.built: list[BuiltImage] = []
100
+ # By kind and exact name or id, by kind and folded name, and by folded name across the kinds a
101
+ # step can name (steps never name tasks or evals).
102
+ self.named: dict[tuple[EntityKind, str], BundleEntry] = {}
103
+ self.folded: dict[tuple[EntityKind, str], BundleEntry] = {}
104
+ stepped = {bundle_kind for kind in (EntityKind.ENV, EntityKind.AGENT, EntityKind.ARTIFACT)
105
+ for bundle_kind in NAMED_BY[kind]}
106
+ self.step_named = {fold(entry.name): entry for entry in bundle.entries if entry.kind in stepped}
107
+ self.ignored: dict[tuple[EntityKind, str], Path] = {}
108
+ for kind, bundle_kinds in NAMED_BY.items():
109
+ for entry in bundle.entries:
110
+ if entry.kind in bundle_kinds:
111
+ self.named[kind, _nfc(entry.name)] = self.named[kind, _nfc(entry.id)] = entry
112
+ self.folded[kind, fold(entry.name)] = self.folded[kind, fold(entry.id)] = entry
113
+ folders = {bundle_kind.value for bundle_kind in bundle_kinds}
114
+ for path in bundle.ignored:
115
+ if len(path.parts) == 2 and path.parts[0] in folders:
116
+ for name in (path.name, path.stem):
117
+ self.ignored[kind, fold(name)] = path
118
+
119
+ def resolve(self) -> ResolvedBundle:
120
+ resolved = []
121
+ for entry in self.bundle.entries:
122
+ try:
123
+ resolved.append(self._task(entry) if entry.kind is BundleKind.TASK else self._toml(entry))
124
+ except _Skip:
125
+ pass
126
+ if self.problems:
127
+ raise BundleError(self.problems)
128
+ return ResolvedBundle(self.bundle, tuple(resolved), tuple(self.built))
129
+
130
+ # One method per kind of config
131
+
132
+ def _toml(self, entry: BundleEntry) -> ResolvedEntry:
133
+ config = copy.deepcopy(entry.config)
134
+ if not isinstance(config, dict):
135
+ return ResolvedEntry(entry, config, (), ())
136
+ references: list[Reference] = []
137
+ refs = []
138
+ for ref in getattr(self._toml_class(entry), "toml_refs", ()):
139
+ if not self._image(entry, config, ref, references):
140
+ refs.append(ref)
141
+ for site in ref_sites(refs, config, inline_pins=True):
142
+ try:
143
+ name, version = parse_toml_ref(site.ref.kind, site.owner if site.version_key else site.value)
144
+ except ValueError as e:
145
+ self._problem(entry, f"{site.path}: {e}")
146
+ continue
147
+ self._resolve(entry, site, site.path, name, version, {}, set(), references)
148
+ if entry.kind is BundleKind.EVAL:
149
+ self._refuse_repeated_tasks(entry, references)
150
+ return ResolvedEntry(entry, config, tuple(references), ())
151
+
152
+ def _refuse_repeated_tasks(self, entry: BundleEntry, references: list[Reference]) -> None:
153
+ first: dict[str, str] = {}
154
+ for ref in references:
155
+ where = ref.where.partition(".")[0]
156
+ if ref.id in first:
157
+ task = f"this bundle's task {ref.local.name!r}" if ref.local is not None else repr(ref.id)
158
+ self._problem(entry, f"{where}: {task} is also {first[ref.id]}; an eval lists each task once "
159
+ "(for repeat runs, use agent-env eval run --k)")
160
+ else:
161
+ first[ref.id] = where
162
+
163
+ def _task(self, entry: BundleEntry) -> ResolvedEntry:
164
+ steps = copy.deepcopy(entry.config)
165
+ registry = get_task_step_registry()
166
+ declared = []
167
+ for index, step in enumerate(steps):
168
+ step_type = step.get("type")
169
+ cls = registry.get(step_type) if isinstance(step_type, str) else None
170
+ if cls is None:
171
+ note = _registration.failure_note(_registration.TASK_STEPS, step_type) if isinstance(step_type, str) else ""
172
+ self._problem(entry, f"step {step.get('id')!r}: {step_type!r} is not a known step type{note}")
173
+ elif self._derived_outputs(entry, step, cls):
174
+ declared.append((index, step, cls))
175
+ outputs = self._outputs(entry, declared)
176
+ upstream = _upstream(steps)
177
+ references: list[Reference] = []
178
+ for index, step, cls in declared:
179
+ where = f"step {step.get('id')!r}: "
180
+ if cls.entity_refs is None:
181
+ self._undeclared(entry, step, cls, outputs, where)
182
+ continue
183
+ for site in ref_sites(cls.entity_refs, step):
184
+ if site.ref.role is RefRole.OUTPUT:
185
+ continue
186
+ if not (isinstance(site.value, str) and site.value):
187
+ self._problem(entry, f"{where}{site.path} must be an id, not {site.value!r}")
188
+ continue
189
+ self._resolve(entry, site, f"{where}{site.path}", site.value, site.version, outputs, upstream[index],
190
+ references)
191
+ return ResolvedEntry(entry, steps, tuple(references), tuple(outputs.values()))
192
+
193
+ # Parts of a config
194
+
195
+ def _toml_class(self, entry: BundleEntry) -> type:
196
+ group = None
197
+ if entry.kind is BundleKind.ENV:
198
+ cls, group = get_env_registry().get(entry.type), _registration.ENVS
199
+ elif entry.kind is BundleKind.AGENT:
200
+ cls = A2AAgent if entry.type == A2AAgent.type else None
201
+ elif entry.kind is BundleKind.EVAL:
202
+ cls = Eval if entry.type == Eval.type else None
203
+ else:
204
+ cls, group = get_artifact_registry().get(canonical_type(entry.type)), _registration.ARTIFACTS
205
+ if cls is None:
206
+ name = canonical_type(entry.type) if group == _registration.ARTIFACTS else entry.type
207
+ note = _registration.failure_note(group, name) if group else ""
208
+ self._problem(entry, f"{entry.type!r} is not a known {entry.kind.store} type{note}")
209
+ raise _Skip
210
+ return cls
211
+
212
+ def _image(self, entry: BundleEntry, config: dict, ref: EntityRef, references: list[Reference]) -> bool:
213
+ """Record the image an image key builds: the folder's Dockerfile when ``image`` is left out, or
214
+ ``{ dockerfile = "<path>" }``. False when the key names an image artifact instead."""
215
+ if ref.artifact_type != "docker_image" or ref.path != ref.field:
216
+ return False
217
+ value = config.get(ref.path)
218
+ if isinstance(value, dict) and "ref" in value:
219
+ self._problem(entry, f"{ref.path}: an external image ({{ ref = ... }}) isn't supported yet")
220
+ return True
221
+ if value is None and ref.path == "image":
222
+ dockerfile = "Dockerfile"
223
+ elif isinstance(value, dict) and value.keys() == {"dockerfile"}:
224
+ dockerfile = value["dockerfile"]
225
+ else:
226
+ return False
227
+ path = entry.path / dockerfile if isinstance(dockerfile, str) and dockerfile else None
228
+ inside = path is not None and not Path(dockerfile).is_absolute() and path.resolve().is_relative_to(entry.path.resolve())
229
+ if not (inside and path.is_file()):
230
+ self._problem(entry, f"{ref.path}: there is no {dockerfile!r} in this folder to build")
231
+ return True
232
+ role = f"{entry.kind.store}_image" if ref.path == "image" else ref.path
233
+ image = BuiltImage(f"{entry.id}__{role}", entry, dockerfile)
234
+ config[ref.path] = image.id
235
+ self.built.append(image)
236
+ references.append(Reference(EntityKind.ARTIFACT, image.id, None, image, ref.path, ref.artifact_type))
237
+ return True
238
+
239
+ def _derived_outputs(self, entry: BundleEntry, step: dict, cls: type) -> bool:
240
+ """Write in any output id the step's type derives when the field is left out (build_mcp_cli's
241
+ ``cli-<env_id>``), so it's named like one written out. False when its type can't read the step."""
242
+ absent = [ref for ref in cls.entity_refs or ()
243
+ if ref.role is RefRole.OUTPUT and ref.path == ref.field and step.get(ref.field) is None]
244
+ if not absent:
245
+ return True
246
+ try:
247
+ read = build_step(step).to_dict()
248
+ except Exception as e:
249
+ self._problem(entry, f"step {step.get('id')!r}: {cls.type} can't read it ({type(e).__name__}: {e})")
250
+ return False
251
+ for ref in absent:
252
+ if read.get(ref.field) is not None:
253
+ step[ref.field] = read[ref.field]
254
+ return True
255
+
256
+ def _outputs(self, entry: BundleEntry, declared: list[tuple[int, dict, type]]) -> dict[tuple[EntityKind, str], Output]:
257
+ """Name each id a step writes under its task, keyed by kind and the name as written."""
258
+ outputs: dict[tuple[EntityKind, str], Output] = {}
259
+ for index, step, cls in declared:
260
+ refs = [ref for ref in cls.entity_refs or () if ref.role is RefRole.OUTPUT]
261
+ for site in ref_sites(refs, step):
262
+ where, name, kind = f"step {step.get('id')!r}: {site.path}", site.value, site.ref.kind
263
+ if not (isinstance(name, str) and name):
264
+ self._problem(entry, f"{where} must be an id, not {name!r}")
265
+ continue
266
+ name = _nfc(name)
267
+ clash = self.named.get((kind, name)) or self.folded.get((kind, fold(name)))
268
+ if clash is not None:
269
+ self._problem(entry, f"{where}: {name!r} is written by this step and is also this bundle's "
270
+ f"{kind.value} {clash.name!r}; rename one")
271
+ continue
272
+ if (kind, name) in outputs:
273
+ self._problem(entry, f"{where}: {name!r} is also written by step "
274
+ f"{outputs[kind, name].step_id!r}; give each output its own name")
275
+ continue
276
+ output_id = name if name.startswith(LOCAL_PREFIX) else f"{entry.id}/{name}"
277
+ try:
278
+ validate_local_id(output_id)
279
+ except ValueError as e:
280
+ self._problem(entry, f"{where}: {e}")
281
+ continue
282
+ site.rewrite(output_id)
283
+ outputs[kind, name] = Output(kind, output_id, index, step.get("id"), site.ref.artifact_type)
284
+ return outputs
285
+
286
+ def _resolve(self, entry: BundleEntry, site: RefSite, where: str, name: str, version: int | None,
287
+ outputs: dict[tuple[EntityKind, str], Output], upstream: set[int],
288
+ references: list[Reference]) -> None:
289
+ kind, expected, key = site.ref.kind, site.ref.artifact_type, _nfc(name)
290
+ output = outputs.get((kind, key))
291
+ if output is not None:
292
+ if output.step not in upstream:
293
+ self._problem(entry, f"{where}: {name!r} is written by step {output.step_id!r}, which this step "
294
+ "doesn't depend on")
295
+ elif version is not None:
296
+ self._problem(entry, f"{where}: {name!r} is written by this task, so it has no fixed version; "
297
+ "drop the pin")
298
+ elif expected and output.artifact_type and not _same_type(output.artifact_type, expected):
299
+ self._problem(entry, f"{where}: this task writes {name!r} as {output.artifact_type}, but this field "
300
+ f"takes {expected}")
301
+ else:
302
+ site.rewrite(output.id)
303
+ return
304
+ local = self.named.get((kind, key))
305
+ if local is not None:
306
+ if version is not None:
307
+ self._problem(entry, f"{where}: {name!r} is defined in this bundle, so it has no fixed version; "
308
+ "drop the pin")
309
+ elif expected and not _same_type(local.type, expected):
310
+ self._problem(entry, f"{where}: {name!r} is this bundle's {local.type}, but this field takes {expected}")
311
+ else:
312
+ site.rewrite(local.id)
313
+ references.append(Reference(kind, local.id, None, local, where, expected))
314
+ return
315
+ near = self.folded.get((kind, fold(name)))
316
+ if near is not None:
317
+ near_name = near.id if fold(name) == fold(near.id) else near.name
318
+ else:
319
+ near_name = next((n for k, n in outputs if k is kind and fold(n) == fold(name)), None)
320
+ ignored = self.ignored.get((kind, fold(name)))
321
+ if near_name is not None:
322
+ self._problem(entry, f"{where}: {name!r} isn't in this bundle, but {near_name!r} is; names are "
323
+ "case-sensitive")
324
+ elif ignored is not None:
325
+ self._problem(entry, f"{where}: {name!r} names {show(ignored)}, which this bundle ignores")
326
+ else:
327
+ references.append(Reference(kind, name, version, None, where, expected))
328
+
329
+ def _undeclared(self, entry: BundleEntry, step: dict, cls: type, outputs: dict[tuple[EntityKind, str], Output],
330
+ where: str) -> None:
331
+ """A step type that declares no references passes through, unless it repeats a bundle name that
332
+ it can't have rewritten."""
333
+ written = {fold(name) for _, name in outputs}
334
+ for path, value in _strings(step):
335
+ match = self.step_named.get(fold(value))
336
+ if match is not None:
337
+ named = f"this bundle's {match.kind.store} {match.name!r}"
338
+ elif fold(value) in written:
339
+ named = "an output of this task"
340
+ else:
341
+ continue
342
+ self._problem(entry, f"{where}{path} = {value!r} names {named}, but {cls.type} doesn't declare its "
343
+ "entity_refs, so it can't be rewritten")
344
+
345
+ def _problem(self, entry: BundleEntry, message: str) -> None:
346
+ self.problems.append(f"{relative(self.bundle.root, entry.path)}: {message}")
347
+
348
+
349
+ def build_step(step: dict) -> TaskStep:
350
+ """The step a task's write puts, built from a copy of ``step``, so the resolved config the ledger hashes
351
+ never changes."""
352
+ step = copy.deepcopy(step)
353
+ return attach_retry_config(get_task_step_registry()[step["type"]].from_dict(step), step)
354
+
355
+
356
+ def _nfc(name: str) -> str:
357
+ """The form names are compared in: the parser's entity names are NFC, as authored text may not be."""
358
+ return unicodedata.normalize("NFC", name)
359
+
360
+
361
+ def _upstream(steps: list[dict]) -> list[set[int]]:
362
+ """The indexes of the steps each step runs after: its ``depends_on`` or, when it has none, every
363
+ step before it, followed transitively; the rule the task scheduler runs steps by."""
364
+ index_of: dict[str, int] = {}
365
+ for index, step in enumerate(steps):
366
+ if isinstance(step.get("id"), str):
367
+ index_of.setdefault(step["id"], index)
368
+ direct = []
369
+ for index, step in enumerate(steps):
370
+ raw = step.get("depends_on")
371
+ if raw is None:
372
+ direct.append(set(range(index)))
373
+ continue
374
+ ids = [dep.get("task_step_id") for dep in raw if isinstance(dep, dict)] if isinstance(raw, list) else []
375
+ direct.append({index_of[dep_id] for dep_id in ids if dep_id in index_of})
376
+ upstream = []
377
+ for index in range(len(steps)):
378
+ seen: set[int] = set()
379
+ frontier = list(direct[index])
380
+ while frontier:
381
+ current = frontier.pop()
382
+ if current not in seen:
383
+ seen.add(current)
384
+ frontier.extend(direct[current])
385
+ upstream.append(seen)
386
+ return upstream
387
+
388
+
389
+ def _same_type(artifact_type: str, expected: str) -> bool:
390
+ return canonical_type(artifact_type) == canonical_type(expected)
391
+
392
+
393
+ def _strings(value: Any, path: str = "") -> Iterator[tuple[str, str]]:
394
+ """Every string in a step with its path, except under the keys that hold step ids."""
395
+ if isinstance(value, str):
396
+ yield path, value
397
+ elif isinstance(value, dict):
398
+ for key, item in value.items():
399
+ if (not path and key in _STEP_ID_KEYS) or str(key).endswith(("_step_id", "_step_ids")):
400
+ continue
401
+ yield from _strings(item, f"{path}.{key}" if path else str(key))
402
+ elif isinstance(value, list):
403
+ for i, item in enumerate(value):
404
+ yield from _strings(item, f"{path}[{i}]")