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,263 @@
1
+ """`agent-env config` — inspect the config surface without touching it."""
2
+
3
+ import datetime
4
+ import json
5
+ from typing import Optional
6
+
7
+ import click
8
+
9
+ from agent_env.config import loader as config_loader
10
+ from agent_env.config.describe import (
11
+ SOURCE_ENV,
12
+ SOURCE_NONE,
13
+ SOURCE_WALK_UP,
14
+ ConfigReport,
15
+ Explained,
16
+ PluginOwner,
17
+ PluginsReport,
18
+ SectionsReport,
19
+ as_dict,
20
+ describe_config,
21
+ explain_path,
22
+ search_path,
23
+ sources,
24
+ )
25
+ from agent_env.config.provenance import KIND_DEFAULT, headline, lines as section_lines
26
+
27
+
28
+
29
+ def _json(payload: dict) -> str:
30
+ """The group's one serializer. TOML has first-class date/time types, so a perfectly
31
+ valid config file reaches here holding values `json` refuses; anything else unexpected
32
+ still raises, because silently stringifying it would hide a real bug."""
33
+ def encode(value):
34
+ if isinstance(value, (datetime.datetime, datetime.date, datetime.time)):
35
+ return value.isoformat()
36
+ raise TypeError(f"cannot serialize {type(value).__name__} in a config report")
37
+ return json.dumps(payload, indent=2, default=encode)
38
+
39
+
40
+ def _source_prose(report: ConfigReport) -> str:
41
+ """The report says *how* the file was found; the sentence saying so belongs here."""
42
+ if report.config_source == SOURCE_ENV:
43
+ return f"via ${config_loader.ENV_CONFIG_PATH}"
44
+ if report.config_source == SOURCE_WALK_UP:
45
+ return "discovered by walking up from the working directory"
46
+ if report.config_source == SOURCE_NONE:
47
+ root = report.search_root
48
+ return f"none found — walked up from {root} to {root.anchor or '/'}"
49
+ return "discovery failed"
50
+
51
+
52
+ def _plugin_lines(plugins: PluginsReport) -> list[str]:
53
+ """Each ``[plugins.<name>]`` table under the distribution it belongs to."""
54
+ if plugins.error:
55
+ return [f"(unresolved) {plugins.error}", "from [plugins]"]
56
+ if not plugins.tables:
57
+ return ["(none)"]
58
+ out = []
59
+ for table in plugins.tables:
60
+ body = [f"(unresolved) {table.error}"] if table.error else [
61
+ line for line in section_lines(table.value, seam=False) if line] or ["(empty)"]
62
+ out += [table.owner.label, *(f" {line}" for line in body), f" from {table.where}"]
63
+ return out
64
+
65
+
66
+ def render(report: ConfigReport) -> str:
67
+ """Render a `ConfigReport` as the operator-facing block. Kept separate from the command
68
+ so the format is assertable without a CliRunner."""
69
+ labels = ["config:", "plugins:"] + [f"{s.name}:" for s in report.sections]
70
+ width = max(len(label) for label in labels) + 1
71
+ lines = []
72
+ where = report.config_path if report.config_path is not None else "(none)"
73
+ lines.append(f"{'config:':<{width}} {where}")
74
+ lines.append(f"{'':<{width}} {_source_prose(report)}")
75
+ if report.error:
76
+ lines.append(f"{'':<{width}} (error) {report.error}")
77
+ for warning in report.warnings:
78
+ lines.append(f"{'':<{width}} (warning) {warning}")
79
+ lines.append("")
80
+ for section in report.sections:
81
+ label = f"{section.name}:"
82
+ body = [f"(unresolved) {section.error}"] if section.error else section_lines(section.value)
83
+ head, rest = (body[0] or ("(unset)" if len(body) == 1 else "")), body[1:]
84
+ lines.append(f"{label:<{width}} {head}".rstrip())
85
+ lines += [f"{'':<{width}} {extra}" for extra in rest]
86
+ lines.append(f"{'':<{width}} from {section.winner.where}")
87
+ for beaten in section.shadowed:
88
+ if beaten.error is not None:
89
+ lines.append(f"{'':<{width}} ; {beaten.where} unreadable: {beaten.error}")
90
+ elif beaten.kind != KIND_DEFAULT:
91
+ lines.append(f"{'':<{width}} ; {beaten.summary()} in {beaten.where}, shadowed")
92
+ if report.sections:
93
+ head, *rest = _plugin_lines(report.plugins)
94
+ lines.append(f"{'plugins:':<{width}} {head}")
95
+ lines += [f"{'':<{width}} {extra}" for extra in rest]
96
+ return "\n".join(lines)
97
+
98
+
99
+ def _owner_line(owner: PluginOwner) -> str:
100
+ return f" ; {owner.note}"
101
+
102
+
103
+ def _plugin_json(owner: Optional[PluginOwner]) -> Optional[dict]:
104
+ if owner is None:
105
+ return None
106
+ return {"name": owner.name, "installed": owner.installed is not None, "version": owner.version,
107
+ "plugin": owner.plugin}
108
+
109
+
110
+ @click.group()
111
+ def config():
112
+ """Inspect the resolved agent-env configuration."""
113
+
114
+
115
+ @config.command()
116
+ @click.option("--json", "as_json", is_flag=True, help="Machine-readable, provenance included.")
117
+ def show(as_json: bool):
118
+ """Print the config file that won and what each section resolves to.
119
+
120
+ Read-only: no store is constructed, no network call is made, and no directory is
121
+ created. Secret values are never printed — `env:` / `secret:` references are shown as
122
+ references, and a literal under a secret-shaped key is masked.
123
+ """
124
+ report = describe_config()
125
+ click.echo(_json(as_dict(report)) if as_json else render(report))
126
+
127
+
128
+ @config.command()
129
+ @click.option("--json", "as_json", is_flag=True, help="Machine-readable.")
130
+ def debug(as_json: bool):
131
+ """Print every path discovery considers, in order, and whether it is there."""
132
+ candidates = [{"path": str(c.path), "why": c.why, "exists": c.exists} for c in search_path()]
133
+ if as_json:
134
+ click.echo(_json({"search_path": candidates}))
135
+ return
136
+ for c in candidates:
137
+ mark = "->" if c["exists"] else " "
138
+ click.echo(f"{mark} {c['path']} ({c['why']}, exists: {'yes' if c['exists'] else 'no'})")
139
+
140
+
141
+ def _render_children(report: SectionsReport) -> list[str]:
142
+ what = "plugin tables" if all(c.plugin is not None for c in report.children) else "sections"
143
+ out = [f" covers {len(report.children)} {what}, each resolving on its own:"]
144
+ width = max(len(c.path) for c in report.children) + 2
145
+ for child in report.children:
146
+ where = child.winner.where if child.winner is not None else "(none)"
147
+ summary = (f"(unresolved) {child.error}" if child.error
148
+ else headline(child.value, seam=child.plugin is None))
149
+ owner = f" ({child.plugin.label})" if child.plugin is not None else ""
150
+ out.append(f" {child.path:<{width}}{summary} from {where}{owner}")
151
+ return out
152
+
153
+
154
+ def render_explain(report: Explained) -> str:
155
+ """One path's resolution, in the same vocabulary `show` uses for a whole section."""
156
+ lines = [f"{report.path}"]
157
+ if isinstance(report, SectionsReport):
158
+ return "\n".join(lines + _render_children(report))
159
+ if report.error:
160
+ lines.append(f" (unresolved) {report.error}")
161
+ if report.winner is None and not report.error:
162
+ lines.append(" (unset) — no layer supplies this path")
163
+ if report.plugin is not None:
164
+ lines.append(_owner_line(report.plugin))
165
+ return "\n".join(lines)
166
+ if not report.error:
167
+ body = section_lines(report.value, seam=report.plugin is None)
168
+ # `(unset)` only when there is nothing else to say: substituting it whenever the
169
+ # first line is blank prints it directly above the table it is denying.
170
+ head = body[0] or ("(unset)" if len(body) == 1 else "")
171
+ lines.append(f" {head}".rstrip())
172
+ lines += [f" {extra}" for extra in body[1:]]
173
+ if report.winner is not None:
174
+ lines.append(f" from {report.winner.where}")
175
+ for beaten in report.shadowed:
176
+ if beaten.error is not None:
177
+ lines.append(f" ; {beaten.where} unreadable: {beaten.error}")
178
+ elif beaten.kind != KIND_DEFAULT:
179
+ lines.append(f" ; {beaten.summary()} in {beaten.where}, shadowed")
180
+ if report.file_only and report.winner is not None:
181
+ lines.append(" ; read from the file only — no resolver owns this path")
182
+ if report.plugin is not None:
183
+ lines.append(_owner_line(report.plugin))
184
+ return "\n".join(lines)
185
+
186
+
187
+ @config.command()
188
+ @click.argument("path")
189
+ @click.option("--json", "as_json", is_flag=True, help="Machine-readable, provenance included.")
190
+ def explain(path: str, as_json: bool):
191
+ """Print where one dotted PATH's value came from.
192
+
193
+ PATH is a section name or a TOML path — `document` and `stores.document` both work.
194
+ Read-only, on the same terms as `show`.
195
+ """
196
+ report = explain_path(path)
197
+ if as_json and isinstance(report, SectionsReport):
198
+ # The wire shape stays flat even though the types split: an ancestor answered with
199
+ # a different set of keys would break a reader that just indexes them, and the type
200
+ # split was for this module's clarity, not the caller's.
201
+ click.echo(_json({
202
+ "path": report.path,
203
+ "section": None,
204
+ "value": None,
205
+ "winner": None,
206
+ "shadowed": [],
207
+ "error": None,
208
+ "file_only": False,
209
+ "plugin": None,
210
+ "children": [
211
+ {"path": c.path, "section": c.section,
212
+ "winner": None if c.winner is None else c.winner.where,
213
+ "value": c.value, "error": c.error, "plugin": _plugin_json(c.plugin)}
214
+ for c in report.children
215
+ ],
216
+ }))
217
+ return
218
+ if as_json:
219
+ click.echo(_json({
220
+ "path": report.path,
221
+ "section": report.section,
222
+ "value": report.value,
223
+ "winner": None if report.winner is None else {
224
+ "kind": report.winner.kind, "where": report.winner.where,
225
+ "value": report.winner.summary(),
226
+ },
227
+ "shadowed": [{"kind": b.kind, "where": b.where, "value": b.summary(), "error": b.error}
228
+ for b in report.shadowed],
229
+ "error": report.error,
230
+ "file_only": report.file_only,
231
+ "plugin": _plugin_json(report.plugin),
232
+ "children": [],
233
+ }))
234
+ return
235
+ click.echo(render_explain(report))
236
+
237
+
238
+ @config.command(name="sources")
239
+ @click.option("--json", "as_json", is_flag=True, help="Machine-readable.")
240
+ def sources_command(as_json: bool):
241
+ """Print every layer the resolver consults, lowest precedence first.
242
+
243
+ `debug` answers which *file*; this answers which *layers* — including the ones
244
+ contributing nothing, because "the file I edited is not being read" is the thing worth
245
+ seeing.
246
+ """
247
+ layers = sources()
248
+ if as_json:
249
+ # Array order *is* the precedence order; no numeric layer id is published,
250
+ # because the target chain's numbering is not settled and would renumber.
251
+ click.echo(_json({"sources": [
252
+ {"kind": s.kind, "where": s.where, "present": s.present,
253
+ "detail": s.detail, "shadows": s.shadows}
254
+ for s in layers
255
+ ]}))
256
+ return
257
+ # Deliberately not column-aligned on `where`: one entry is a filesystem path, and
258
+ # padding every other row to its width pushes the detail off the edge of a terminal.
259
+ for s in layers:
260
+ mark = "->" if s.present else " "
261
+ shadows = f" -> [{s.shadows}]" if s.shadows else ""
262
+ detail = f" ({s.detail})" if s.detail else ""
263
+ click.echo(f"{mark} {s.kind:<8} {s.where}{shadows}{detail}")
@@ -0,0 +1,31 @@
1
+ import click
2
+
3
+ from .deploy import deploy
4
+ from .gateway import gateway
5
+ from .get_instance import get_instance
6
+ from .mcp_server import mcp_server
7
+ from .multi import multi
8
+ from .service_db import service_db
9
+ from .snapshot import snapshot
10
+ from .state import init_env_state, teardown_env_state
11
+ from .website import website
12
+ from .website_browser import website_browser
13
+
14
+
15
+ @click.group()
16
+ def env():
17
+ """Environment commands."""
18
+ pass
19
+
20
+
21
+ env.add_command(deploy)
22
+ env.add_command(gateway)
23
+ env.add_command(get_instance)
24
+ env.add_command(init_env_state)
25
+ env.add_command(mcp_server)
26
+ env.add_command(multi)
27
+ env.add_command(service_db)
28
+ env.add_command(snapshot)
29
+ env.add_command(teardown_env_state)
30
+ env.add_command(website)
31
+ env.add_command(website_browser)
@@ -0,0 +1,112 @@
1
+ import asyncio
2
+
3
+ import click
4
+
5
+ from agent_env.env import DeployedGatewayEnv, Env
6
+ from agent_env.env.gateway import GatewayMode
7
+ from agent_env.store.routing import run_scope
8
+
9
+ MIN_TTL_SECONDS = 60 # 1 minute
10
+ MAX_TTL_SECONDS = 1209600 # 2 weeks
11
+ DEFAULT_TTL_SECONDS = 10800 # 3 hours
12
+
13
+
14
+ @click.command()
15
+ @click.option("--id", "env_id", required=True, help="Env id")
16
+ @click.option("--version", "env_version", default=None, type=int, help="Env version (defaults to latest)")
17
+ @click.option("--ttl-seconds", type=click.IntRange(min=MIN_TTL_SECONDS, max=MAX_TTL_SECONDS), default=DEFAULT_TTL_SECONDS,
18
+ help=f"VM lifetime in seconds (min {MIN_TTL_SECONDS}, max {MAX_TTL_SECONDS}, default {DEFAULT_TTL_SECONDS})")
19
+ @click.option("--gateway-mode", type=click.Choice([m.value for m in GatewayMode], case_sensitive=False),
20
+ default=GatewayMode.PERFORMANCE.value, help="Gateway mode (performance or consistent)")
21
+ @click.option("--sandbox", default=None,
22
+ help="Sandbox backend(s): a built-in (modal, modal_vm, e2b, local) "
23
+ "or a name from [sandbox.providers] in .agentenv/config.toml; comma-separated for a "
24
+ "fallback chain. Defaults to [sandbox].default (else local) when omitted.")
25
+ @click.option("--service-db", "service_db_env_id", default=None,
26
+ help="Override default_service_db_env_id (on Modal its images must be in the configured image store)")
27
+ @click.option("--gateway", "gateway_env_id", default=None,
28
+ help="Override default_gateway_env_id")
29
+ @click.option("--priority", type=int, default=0, show_default=True,
30
+ help="Sandbox priority: 0=interactive, 1=non_interactive (honoured by backends with priority tiers)")
31
+ @click.option("--disk-size-gb", type=float, default=10.0, show_default=True,
32
+ help="Sandbox VM disk size in GB. Large universes (e.g. github/gdrive "
33
+ "root file trees) need more than the 10GB default.")
34
+ @click.option("--cpu", type=float, default=None,
35
+ help="Sandbox VM vCPUs. Defaults to the provider value of 1.0, "
36
+ "which is one whole core after rounding. A universe loads its "
37
+ "components concurrently onto that one VM, and the loaders are "
38
+ "CPU-bound (JSON decode, row shaping, COPY), so a large "
39
+ "multi-component universe is competing with itself for a single "
40
+ "core.")
41
+ @click.option("--memory-mb", type=int, default=None,
42
+ help="Sandbox VM memory in MB (default provider value, ~8192). "
43
+ "Stopgap for memory-heavy parallel loads; prefer sizing "
44
+ "--disk-size-gb since artifact staging is disk-backed.")
45
+ @click.option("--env-state-type", default=None,
46
+ help="Env state type when creating a fresh store: 'local_postgres' (the built-in "
47
+ "default) or any backend registered under [state.providers] in config.toml.")
48
+ @click.option("--env-state-instance-id", default=None,
49
+ help="Attach against an EXISTING env state instance instead of creating a fresh store "
50
+ "(its own type selects the provider).")
51
+ def deploy(env_id: str, env_version: int | None, ttl_seconds: int, gateway_mode: str, sandbox: str, service_db_env_id: str | None, gateway_env_id: str | None, priority: int, disk_size_gb: float, cpu: float | None, memory_mb: int | None, env_state_type: str | None, env_state_instance_id: str | None):
52
+ """Deploy an MCP server environment."""
53
+ from agent_env.providers import build_sandbox_provider
54
+ from agent_env.config import get_config
55
+
56
+ if sandbox:
57
+ try:
58
+ build_sandbox_provider(sandbox)
59
+ except ValueError as e:
60
+ raise click.BadParameter(str(e), param_hint="'--sandbox'")
61
+ click.echo(f"Sandbox backend: {sandbox or 'config default'}")
62
+
63
+ if service_db_env_id:
64
+ get_config().default_service_db_env_id = service_db_env_id
65
+ click.echo(f"Override default_service_db_env_id: {service_db_env_id}")
66
+ if gateway_env_id:
67
+ get_config().default_gateway_env_id = gateway_env_id
68
+ click.echo(f"Override default_gateway_env_id: {gateway_env_id}")
69
+
70
+ click.echo(f"Fetching env: id={env_id} version={env_version or 'latest'}...")
71
+ env = Env.get(env_id, version=env_version)
72
+ click.echo(f"Found env: id={env.id} version={env.version} type={env.type}")
73
+
74
+ mode = GatewayMode(gateway_mode)
75
+ cpu_note = f", cpu={cpu}" if cpu else ""
76
+ mem_note = f", memory={memory_mb}MB" if memory_mb else ""
77
+ click.echo(f"Deploying (ttl={ttl_seconds}s, gateway_mode={mode.value}, disk={disk_size_gb}GB{cpu_note}{mem_note})...")
78
+ deploy_kwargs = dict(ttl_seconds=ttl_seconds, gateway_mode=mode, sandbox_type=sandbox, priority=priority, disk_size_gb=disk_size_gb)
79
+ if cpu is not None:
80
+ deploy_kwargs["cpu"] = cpu
81
+ if memory_mb is not None:
82
+ deploy_kwargs["memory_mb"] = memory_mb
83
+ if env_state_type is not None:
84
+ deploy_kwargs["env_state_type"] = env_state_type
85
+ click.echo(f"Env state type: {env_state_type}")
86
+ if env_state_instance_id:
87
+ deploy_kwargs["env_state_instance_id"] = env_state_instance_id
88
+ click.echo(f"Env state instance id: {env_state_instance_id}")
89
+ try:
90
+ with run_scope(env.id):
91
+ deployed_env = asyncio.run(env.deploy(**deploy_kwargs))
92
+ except NotImplementedError as e:
93
+ click.echo(f"Error: {e}", err=True)
94
+ raise SystemExit(1)
95
+
96
+ click.echo(f"Deployed!")
97
+ if deployed_env.instance_id:
98
+ click.echo("Instance ID: " + click.style(deployed_env.instance_id, fg="green"))
99
+ click.echo("Env MCP Url: " + click.style(deployed_env.mcp_url, fg="blue"))
100
+ # A record without a gateway has none of the gateway's URLs.
101
+ if isinstance(deployed_env, DeployedGatewayEnv):
102
+ click.echo("Env Gateway Url: " + click.style(deployed_env.gateway_url, fg="yellow"))
103
+ if deployed_env.db_web_url:
104
+ click.echo("Env DB Web Url: " + click.style(deployed_env.db_web_url, fg="yellow"))
105
+ if deployed_env.db_mcp_url:
106
+ click.echo("Env DB MCP Url: " + click.style(deployed_env.db_mcp_url, fg="yellow"))
107
+ if deployed_env.vnc_url:
108
+ click.echo("VNC Url: " + click.style(deployed_env.vnc_url, fg="yellow"))
109
+ for svc_name, url in (deployed_env.website_frontend_urls or {}).items():
110
+ click.echo(f"Website Frontend ({svc_name}): " + click.style(url, fg="yellow"))
111
+ if deployed_env.expires_at_utc:
112
+ click.echo(f"Expires At (UTC): {deployed_env.expires_at_utc}")
@@ -0,0 +1,57 @@
1
+ import sys
2
+ from pathlib import Path
3
+
4
+ import click
5
+
6
+ from agent_env.artifact import DockerImageArtifact
7
+ from agent_env.cli.utils import build_platform_option, detect_env_metadata
8
+ from agent_env.env import GatewayEnv
9
+ from agent_env.utils.docker_build import build_image
10
+
11
+ _PACKAGE_ROOT = Path(__file__).parent.parent.parent
12
+ GATEWAY_DOCKERFILE = _PACKAGE_ROOT / "env" / "gateway" / "Dockerfile"
13
+ GATEWAY_CONTEXT = _PACKAGE_ROOT / "env"
14
+ GATEWAY_IMAGE_TAG = "env-gateway"
15
+
16
+
17
+ @click.group()
18
+ def gateway():
19
+ """Gateway environment commands."""
20
+ pass
21
+
22
+
23
+ @gateway.command()
24
+ @click.option("--id", "env_id", required=True, help="Env id")
25
+ @click.option("--metadata", "metadata_pairs", multiple=True, help="Metadata key=value pair (repeatable)")
26
+ @build_platform_option
27
+ def put(env_id: str, metadata_pairs: tuple[str, ...], build_platform: str):
28
+ """Build and upload a gateway environment."""
29
+
30
+ click.echo(f"Building gateway Docker image...")
31
+ build_image(GATEWAY_DOCKERFILE, GATEWAY_CONTEXT, GATEWAY_IMAGE_TAG, platform=build_platform)
32
+
33
+ click.echo(f"Creating DockerImageArtifact...")
34
+ artifact = DockerImageArtifact.put(
35
+ id=f"gateway-{env_id}",
36
+ description="Created from agent-env CLI",
37
+ image_name=GATEWAY_IMAGE_TAG,
38
+ )
39
+ click.echo(f"Created artifact: id={artifact.id} version={artifact.version}")
40
+
41
+ user_metadata = {}
42
+ for pair in metadata_pairs:
43
+ if "=" not in pair:
44
+ click.echo(f"Invalid metadata format '{pair}', expected key=value", err=True)
45
+ sys.exit(1)
46
+ key, value = pair.split("=", 1)
47
+ user_metadata[key] = value
48
+ metadata = detect_env_metadata(GATEWAY_DOCKERFILE, GATEWAY_CONTEXT)
49
+ metadata.update(user_metadata)
50
+
51
+ click.echo(f"Creating GatewayEnv...")
52
+ env = GatewayEnv.put(
53
+ id=env_id,
54
+ docker_image_artifact=artifact,
55
+ metadata=metadata if metadata else None,
56
+ )
57
+ click.echo(f"Created GatewayEnv: id={env.id} version={env.version}")
@@ -0,0 +1,40 @@
1
+ """Get a deployed environment instance by ID."""
2
+
3
+ import click
4
+
5
+
6
+ @click.command("get-instance")
7
+ @click.option("--id", "instance_id", required=True, help="Instance ID")
8
+ def get_instance(instance_id: str):
9
+ """Look up a deployed environment instance."""
10
+ from agent_env.store.base import NotFoundError
11
+
12
+ from agent_env.env.env import DeployedGatewayEnv, DeployedSandboxEnv
13
+ from agent_env.env.store import get_env_instance_store
14
+
15
+ try:
16
+ deployed_env = get_env_instance_store().get(instance_id)
17
+ except NotFoundError:
18
+ click.echo(f"Error: Instance '{instance_id}' not found", err=True)
19
+ raise SystemExit(1)
20
+
21
+ click.echo(f"Instance ID: {deployed_env.instance_id}")
22
+ click.echo(f"Env ID: {deployed_env.env_id}")
23
+ click.echo(f"Env Version: {deployed_env.env_version}")
24
+ # A record without a gateway has none of the gateway's URLs.
25
+ gateway = deployed_env if isinstance(deployed_env, DeployedGatewayEnv) else None
26
+ if gateway:
27
+ click.echo(f"Env Base Url: {gateway.gateway_url}")
28
+ click.echo(f"Env MCP Url: {deployed_env.mcp_url}")
29
+ if gateway and gateway.db_web_url:
30
+ click.echo(f"Env DB Web Url: {gateway.db_web_url}")
31
+ if gateway and gateway.db_mcp_url:
32
+ click.echo(f"Env DB MCP Url: {gateway.db_mcp_url}")
33
+ for svc_name, url in ((gateway.website_frontend_urls if gateway else None) or {}).items():
34
+ click.echo(f"Website Frontend ({svc_name}): {url}")
35
+ if isinstance(deployed_env, DeployedSandboxEnv):
36
+ click.echo(f"Sandbox ID: {deployed_env.sandbox_id}")
37
+ if deployed_env.created_at_utc:
38
+ click.echo(f"Created At (UTC): {deployed_env.created_at_utc}")
39
+ if deployed_env.expires_at_utc:
40
+ click.echo(f"Expires At (UTC): {deployed_env.expires_at_utc}")