loopx 0.4.8__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 (811) hide show
  1. loopx/__init__.py +5 -0
  2. loopx/agent_onboarding.py +654 -0
  3. loopx/agent_registry.py +112 -0
  4. loopx/ark_managed_agent_host.py +59 -0
  5. loopx/authority.py +805 -0
  6. loopx/benchmark.py +2875 -0
  7. loopx/benchmark_adapters/__init__.py +1 -0
  8. loopx/benchmark_adapters/agentissue.py +2644 -0
  9. loopx/benchmark_adapters/agents_last_exam.py +3998 -0
  10. loopx/benchmark_adapters/edgebench.py +322 -0
  11. loopx/benchmark_adapters/skillsbench.py +5978 -0
  12. loopx/benchmark_adapters/skillsbench_acp_failure_policy.py +143 -0
  13. loopx/benchmark_adapters/skillsbench_acp_process.py +31 -0
  14. loopx/benchmark_adapters/skillsbench_acp_relay.py +4832 -0
  15. loopx/benchmark_adapters/skillsbench_batch.py +124 -0
  16. loopx/benchmark_adapters/skillsbench_bridge_guard.py +209 -0
  17. loopx/benchmark_adapters/skillsbench_bridge_summary.py +203 -0
  18. loopx/benchmark_adapters/skillsbench_codex_goal_recovery.py +271 -0
  19. loopx/benchmark_adapters/skillsbench_codex_goal_trace.py +81 -0
  20. loopx/benchmark_adapters/skillsbench_codex_runtime.py +339 -0
  21. loopx/benchmark_adapters/skillsbench_dockerfile_runtime.py +467 -0
  22. loopx/benchmark_adapters/skillsbench_failure_signals.py +652 -0
  23. loopx/benchmark_adapters/skillsbench_proxy_runtime.py +327 -0
  24. loopx/benchmark_adapters/skillsbench_remote_bridge.py +402 -0
  25. loopx/benchmark_adapters/skillsbench_result_discovery.py +143 -0
  26. loopx/benchmark_adapters/skillsbench_runner_profile.py +436 -0
  27. loopx/benchmark_adapters/skillsbench_runner_source.py +99 -0
  28. loopx/benchmark_adapters/skillsbench_setup_preflight.py +771 -0
  29. loopx/benchmark_adapters/skillsbench_signals.py +15 -0
  30. loopx/benchmark_adapters/skillsbench_task_source.py +141 -0
  31. loopx/benchmark_adapters/skillsbench_turn_route.py +723 -0
  32. loopx/benchmark_adapters/skillsbench_turn_runtime.py +1069 -0
  33. loopx/benchmark_adapters/skillsbench_typed_repair.py +689 -0
  34. loopx/benchmark_adapters/skillsbench_uv_cache.py +111 -0
  35. loopx/benchmark_adapters/skillsbench_verifier_bootstrap.py +227 -0
  36. loopx/benchmark_adapters/skillsbench_verifier_cache.py +138 -0
  37. loopx/benchmark_adapters/terminal_bench.py +10078 -0
  38. loopx/benchmark_case_analysis.py +1276 -0
  39. loopx/benchmark_case_state.py +1079 -0
  40. loopx/benchmark_core/__init__.py +239 -0
  41. loopx/benchmark_core/adapter.py +84 -0
  42. loopx/benchmark_core/artifacts.py +517 -0
  43. loopx/benchmark_core/attempts.py +199 -0
  44. loopx/benchmark_core/container_exec.py +216 -0
  45. loopx/benchmark_core/io.py +68 -0
  46. loopx/benchmark_core/lifecycle.py +211 -0
  47. loopx/benchmark_core/loop_protocol.py +689 -0
  48. loopx/benchmark_core/observable_handles.py +348 -0
  49. loopx/benchmark_core/parity.py +256 -0
  50. loopx/benchmark_core/remote_closeout.py +482 -0
  51. loopx/benchmark_core/rounds.py +215 -0
  52. loopx/benchmark_core/route_profile.py +509 -0
  53. loopx/benchmark_core/run_permissions.py +206 -0
  54. loopx/benchmark_core/split_control.py +925 -0
  55. loopx/benchmark_core/turn_fidelity.py +326 -0
  56. loopx/benchmark_ledger.py +3793 -0
  57. loopx/benchmark_ledger_countability.py +372 -0
  58. loopx/benchmark_ledger_current.py +724 -0
  59. loopx/benchmark_trajectory.py +405 -0
  60. loopx/benchmarks/__init__.py +1 -0
  61. loopx/benchmarks/qualification/__init__.py +1 -0
  62. loopx/benchmarks/qualification/release_outcome_baseline.py +360 -0
  63. loopx/benchmarks/read_models/__init__.py +1 -0
  64. loopx/benchmarks/read_models/benchmark_attempt_accounting.py +53 -0
  65. loopx/benchmarks/read_models/benchmark_comparison.py +414 -0
  66. loopx/benchmarks/read_models/benchmark_event_timeline.py +113 -0
  67. loopx/benchmarks/read_models/benchmark_experiment_report.py +475 -0
  68. loopx/benchmarks/read_models/benchmark_learning_ledger.py +137 -0
  69. loopx/benchmarks/read_models/benchmark_lifecycle_contracts.py +228 -0
  70. loopx/benchmarks/read_models/benchmark_projection.py +723 -0
  71. loopx/benchmarks/read_models/benchmark_result.py +146 -0
  72. loopx/benchmarks/read_models/benchmark_run_execution_contract.py +116 -0
  73. loopx/benchmarks/read_models/benchmark_run_failure.py +157 -0
  74. loopx/benchmarks/read_models/benchmark_run_metrics.py +213 -0
  75. loopx/benchmarks/read_models/benchmark_run_post_execution.py +635 -0
  76. loopx/benchmarks/read_models/benchmark_run_pre_execution.py +541 -0
  77. loopx/benchmarks/read_models/benchmark_status_compaction.py +1255 -0
  78. loopx/benchmarks/read_models/benchmark_status_runner.py +780 -0
  79. loopx/benchmarks/read_models/goal_start_control_score.py +857 -0
  80. loopx/benchmarks/read_models/skillsbench_post_run_debug.py +746 -0
  81. loopx/benchmarks/read_models/skillsbench_verifier_attribution.py +269 -0
  82. loopx/bootstrap.py +1116 -0
  83. loopx/bootstrap_command_pack.py +2167 -0
  84. loopx/boundary_authority.py +199 -0
  85. loopx/canary/__init__.py +1 -0
  86. loopx/canary/maintainability_ratchet.py +800 -0
  87. loopx/canary/planner.py +1984 -0
  88. loopx/canary/premerge.py +1130 -0
  89. loopx/canary/qualification_profiles.py +309 -0
  90. loopx/canary/quality_surface_catalog.py +838 -0
  91. loopx/canary/release_profiles.py +51 -0
  92. loopx/canary/runner.py +1107 -0
  93. loopx/canary/smoke_health.py +581 -0
  94. loopx/canary/smoke_profiles.py +212 -0
  95. loopx/capabilities/__init__.py +0 -0
  96. loopx/capabilities/agent_turn_recall/__init__.py +17 -0
  97. loopx/capabilities/agent_turn_recall/cli.py +369 -0
  98. loopx/capabilities/agent_turn_recall/core.py +296 -0
  99. loopx/capabilities/auto_research/__init__.py +16 -0
  100. loopx/capabilities/auto_research/bootstrap_contract.py +157 -0
  101. loopx/capabilities/auto_research/cli.py +1468 -0
  102. loopx/capabilities/auto_research/core.py +11 -0
  103. loopx/capabilities/auto_research/defaults.py +79 -0
  104. loopx/capabilities/auto_research/demo_e2e.py +1848 -0
  105. loopx/capabilities/auto_research/demo_supervisor.py +186 -0
  106. loopx/capabilities/auto_research/evidence_packet.py +767 -0
  107. loopx/capabilities/auto_research/human_view.py +794 -0
  108. loopx/capabilities/auto_research/kernel.py +191 -0
  109. loopx/capabilities/auto_research/knn_demo_workspace.py +322 -0
  110. loopx/capabilities/auto_research/live_evidence.py +248 -0
  111. loopx/capabilities/auto_research/preset.py +176 -0
  112. loopx/capabilities/auto_research/research_state.py +1085 -0
  113. loopx/capabilities/auto_research/role_profiles.py +394 -0
  114. loopx/capabilities/auto_research/rollout_append.py +97 -0
  115. loopx/capabilities/auto_research/terminal_result_contract.py +422 -0
  116. loopx/capabilities/auto_research/terminal_result_projection.py +171 -0
  117. loopx/capabilities/auto_research/terminal_result_query.py +233 -0
  118. loopx/capabilities/auto_research/terminal_results.py +349 -0
  119. loopx/capabilities/auto_research/user_contract.py +190 -0
  120. loopx/capabilities/auto_research/worker_loop.py +163 -0
  121. loopx/capabilities/auto_research/worker_runtime.py +777 -0
  122. loopx/capabilities/auto_research/worker_skill/SKILL.md +343 -0
  123. loopx/capabilities/benchmark_toolkit/__init__.py +19 -0
  124. loopx/capabilities/benchmark_toolkit/integrity.py +387 -0
  125. loopx/capabilities/catalog.py +1875 -0
  126. loopx/capabilities/change_quality/__init__.py +19 -0
  127. loopx/capabilities/change_quality/cli.py +171 -0
  128. loopx/capabilities/change_quality/context.py +156 -0
  129. loopx/capabilities/change_quality/oracles.py +269 -0
  130. loopx/capabilities/change_quality/policy.py +34 -0
  131. loopx/capabilities/change_quality/receipt.py +482 -0
  132. loopx/capabilities/change_quality/result.py +493 -0
  133. loopx/capabilities/change_quality/scope.py +171 -0
  134. loopx/capabilities/change_quality/shadow.py +680 -0
  135. loopx/capabilities/content_ops/__init__.py +0 -0
  136. loopx/capabilities/content_ops/cli.py +649 -0
  137. loopx/capabilities/content_ops/connector_packets.py +164 -0
  138. loopx/capabilities/content_ops/item_lifecycle.py +1000 -0
  139. loopx/capabilities/content_ops/layout.py +451 -0
  140. loopx/capabilities/content_ops/markdown.py +456 -0
  141. loopx/capabilities/content_ops/schemas.py +51 -0
  142. loopx/capabilities/content_ops/social_browser_x.py +107 -0
  143. loopx/capabilities/content_ops/surface.py +1956 -0
  144. loopx/capabilities/content_ops/templates/layout-catalog-v0.json +72 -0
  145. loopx/capabilities/context_providers/__init__.py +36 -0
  146. loopx/capabilities/context_providers/base.py +189 -0
  147. loopx/capabilities/context_providers/factory.py +32 -0
  148. loopx/capabilities/context_providers/openviking.py +702 -0
  149. loopx/capabilities/context_providers/service_ownership.py +185 -0
  150. loopx/capabilities/decision_context/__init__.py +129 -0
  151. loopx/capabilities/decision_context/architecture.py +83 -0
  152. loopx/capabilities/decision_context/assembler.py +849 -0
  153. loopx/capabilities/decision_context/catalog_entry.py +195 -0
  154. loopx/capabilities/decision_context/cli.py +310 -0
  155. loopx/capabilities/decision_context/cursor_commit.py +535 -0
  156. loopx/capabilities/decision_context/outcome_feedback.py +352 -0
  157. loopx/capabilities/decision_context/packets.py +654 -0
  158. loopx/capabilities/decision_context/private_state.py +189 -0
  159. loopx/capabilities/decision_context/profile.py +453 -0
  160. loopx/capabilities/decision_context/providers.py +228 -0
  161. loopx/capabilities/decision_context/review_settlement.py +136 -0
  162. loopx/capabilities/decision_context/runtime.py +273 -0
  163. loopx/capabilities/decision_context/sources.py +415 -0
  164. loopx/capabilities/explore/__init__.py +1 -0
  165. loopx/capabilities/explore/activation.py +198 -0
  166. loopx/capabilities/explore/adaptive_replay_planner.py +221 -0
  167. loopx/capabilities/explore/child_replay_runtime.py +463 -0
  168. loopx/capabilities/explore/composition_frontier.py +291 -0
  169. loopx/capabilities/explore/counterfactual_runtime.py +578 -0
  170. loopx/capabilities/explore/episode_runtime.py +647 -0
  171. loopx/capabilities/explore/harness_checkpoint.py +171 -0
  172. loopx/capabilities/explore/harness_gate.py +115 -0
  173. loopx/capabilities/explore/harness_runtime.py +1124 -0
  174. loopx/capabilities/explore/replay_metrics.py +206 -0
  175. loopx/capabilities/explore/replay_runtime.py +1271 -0
  176. loopx/capabilities/explore/resource_portfolio.py +173 -0
  177. loopx/capabilities/explore/result_log.py +974 -0
  178. loopx/capabilities/explore/router_state.py +432 -0
  179. loopx/capabilities/explore/source_history_reconcile.py +255 -0
  180. loopx/capabilities/explore/speculative_scheduler.py +498 -0
  181. loopx/capabilities/explore/todo_branch_plan.py +650 -0
  182. loopx/capabilities/explore/todo_evidence.py +141 -0
  183. loopx/capabilities/explore/trace_runtime.py +284 -0
  184. loopx/capabilities/explore/worker_branch_plan.py +1257 -0
  185. loopx/capabilities/integration_branch/__init__.py +13 -0
  186. loopx/capabilities/integration_branch/cli.py +148 -0
  187. loopx/capabilities/integration_branch/core.py +916 -0
  188. loopx/capabilities/issue_fix/__init__.py +19 -0
  189. loopx/capabilities/issue_fix/acceptance_loop.py +1050 -0
  190. loopx/capabilities/issue_fix/candidate_evidence.py +503 -0
  191. loopx/capabilities/issue_fix/candidate_preflight.py +676 -0
  192. loopx/capabilities/issue_fix/cli.py +1822 -0
  193. loopx/capabilities/issue_fix/cli_input.py +87 -0
  194. loopx/capabilities/issue_fix/content_ops_cli.py +148 -0
  195. loopx/capabilities/issue_fix/discovered_issue_promotion.py +947 -0
  196. loopx/capabilities/issue_fix/explore_projection.py +710 -0
  197. loopx/capabilities/issue_fix/feasibility.py +542 -0
  198. loopx/capabilities/issue_fix/github_public.py +661 -0
  199. loopx/capabilities/issue_fix/intake_surface.py +832 -0
  200. loopx/capabilities/issue_fix/metadata_preview.py +218 -0
  201. loopx/capabilities/issue_fix/metrics_projection.py +1340 -0
  202. loopx/capabilities/issue_fix/metrics_supplement.py +634 -0
  203. loopx/capabilities/issue_fix/metrics_supplement_cli.py +127 -0
  204. loopx/capabilities/issue_fix/outcome_projection.py +1235 -0
  205. loopx/capabilities/issue_fix/periodic_report.py +189 -0
  206. loopx/capabilities/issue_fix/pr_description.py +418 -0
  207. loopx/capabilities/issue_fix/pr_gate_reconcile.py +496 -0
  208. loopx/capabilities/issue_fix/pr_gate_reconcile_cli.py +464 -0
  209. loopx/capabilities/issue_fix/pr_lifecycle.py +1327 -0
  210. loopx/capabilities/issue_fix/pr_lifecycle_rollout.py +85 -0
  211. loopx/capabilities/issue_fix/pr_monitor_materialization.py +257 -0
  212. loopx/capabilities/issue_fix/pr_review_ack.py +439 -0
  213. loopx/capabilities/issue_fix/provider_hooks.py +24 -0
  214. loopx/capabilities/issue_fix/repository_commit_evidence.py +186 -0
  215. loopx/capabilities/issue_fix/repository_context.py +457 -0
  216. loopx/capabilities/issue_fix/repository_memory.py +459 -0
  217. loopx/capabilities/issue_fix/repository_memory_provider.py +1454 -0
  218. loopx/capabilities/issue_fix/repository_snapshot.py +454 -0
  219. loopx/capabilities/issue_fix/reviewer_cli.py +917 -0
  220. loopx/capabilities/issue_fix/reviewer_notification.py +882 -0
  221. loopx/capabilities/issue_fix/reviewer_notification_drain.py +942 -0
  222. loopx/capabilities/issue_fix/reviewer_recommendation.py +1057 -0
  223. loopx/capabilities/issue_fix/reviewer_request.py +1282 -0
  224. loopx/capabilities/issue_fix/reward_memory.py +879 -0
  225. loopx/capabilities/issue_fix/workflow_plan.py +1286 -0
  226. loopx/capabilities/material_lifecycle/__init__.py +161 -0
  227. loopx/capabilities/material_lifecycle/_validation.py +183 -0
  228. loopx/capabilities/material_lifecycle/apply.py +672 -0
  229. loopx/capabilities/material_lifecycle/architecture.py +122 -0
  230. loopx/capabilities/material_lifecycle/cli.py +161 -0
  231. loopx/capabilities/material_lifecycle/decision_planning.py +470 -0
  232. loopx/capabilities/material_lifecycle/explore_execution.py +306 -0
  233. loopx/capabilities/material_lifecycle/intake.py +869 -0
  234. loopx/capabilities/material_lifecycle/inventory.py +147 -0
  235. loopx/capabilities/material_lifecycle/lifecycle.py +98 -0
  236. loopx/capabilities/material_lifecycle/preparation.py +147 -0
  237. loopx/capabilities/material_lifecycle/project_skill.py +83 -0
  238. loopx/capabilities/material_lifecycle/ranking.py +267 -0
  239. loopx/capabilities/material_lifecycle/readable_projection.py +500 -0
  240. loopx/capabilities/material_lifecycle/rebuild.py +480 -0
  241. loopx/capabilities/material_lifecycle/settlement.py +238 -0
  242. loopx/capabilities/periodic_report/__init__.py +71 -0
  243. loopx/capabilities/periodic_report/adapters.py +939 -0
  244. loopx/capabilities/periodic_report/archive.py +422 -0
  245. loopx/capabilities/periodic_report/bindings.py +705 -0
  246. loopx/capabilities/periodic_report/cli.py +277 -0
  247. loopx/capabilities/periodic_report/core.py +691 -0
  248. loopx/capabilities/periodic_report/extension_envelope.py +66 -0
  249. loopx/capabilities/periodic_report/presets.py +103 -0
  250. loopx/capabilities/periodic_report/profile.py +235 -0
  251. loopx/capabilities/periodic_report/project_progress.py +179 -0
  252. loopx/capabilities/periodic_report/triggers.py +452 -0
  253. loopx/capabilities/pr_review_queue/__init__.py +17 -0
  254. loopx/capabilities/pr_review_queue/core.py +506 -0
  255. loopx/capabilities/pr_review_queue/review_contract.py +506 -0
  256. loopx/capabilities/registry.py +192 -0
  257. loopx/capabilities/reward_memory/__init__.py +75 -0
  258. loopx/capabilities/reward_memory/application.py +819 -0
  259. loopx/capabilities/reward_memory/architecture.py +572 -0
  260. loopx/capabilities/reward_memory/candidate_review.py +511 -0
  261. loopx/capabilities/reward_memory/cli.py +469 -0
  262. loopx/capabilities/reward_memory/dogfood.py +574 -0
  263. loopx/capabilities/reward_memory/evaluation.py +296 -0
  264. loopx/capabilities/reward_memory/evaluation_fixtures.py +362 -0
  265. loopx/capabilities/reward_memory/experiment.py +567 -0
  266. loopx/capabilities/reward_memory/health.py +222 -0
  267. loopx/capabilities/reward_memory/ingestion.py +519 -0
  268. loopx/capabilities/reward_memory/registry.py +600 -0
  269. loopx/capabilities/reward_memory/runtime_hooks.py +312 -0
  270. loopx/capabilities/reward_memory/scoped_feedback.py +173 -0
  271. loopx/capabilities/semantic_preference/__init__.py +12 -0
  272. loopx/capabilities/semantic_preference/cli.py +189 -0
  273. loopx/capabilities/semantic_preference/contract.py +592 -0
  274. loopx/capabilities/semantic_preference/reward_memory.py +62 -0
  275. loopx/capabilities/value_connectors/__init__.py +1 -0
  276. loopx/capabilities/value_connectors/cli.py +401 -0
  277. loopx/capabilities/value_connectors/finance_extension_migration.py +108 -0
  278. loopx/capabilities/value_connectors/install_check.py +147 -0
  279. loopx/capabilities/value_connectors/planner.py +733 -0
  280. loopx/capabilities/value_connectors/source_map.py +446 -0
  281. loopx/claude_goal_baseline.py +138 -0
  282. loopx/claude_goal_mode/__init__.py +23 -0
  283. loopx/claude_goal_mode/hooks/goal_policy.py +212 -0
  284. loopx/claude_goal_mode/hooks/goal_state.py +139 -0
  285. loopx/claude_goal_mode/mcp/loopx_mcp.py +167 -0
  286. loopx/claude_goal_mode/scripts/connect.py +103 -0
  287. loopx/claude_goal_mode/scripts/goalmode_cmd.py +241 -0
  288. loopx/claude_goal_mode/scripts/install.py +328 -0
  289. loopx/claude_goal_mode/statusline/goal_status.py +97 -0
  290. loopx/cli.py +836 -0
  291. loopx/cli_commands/__init__.py +334 -0
  292. loopx/cli_commands/_host_thread.py +13 -0
  293. loopx/cli_commands/agentissue_runner_flow.py +447 -0
  294. loopx/cli_commands/agents_last_exam.py +160 -0
  295. loopx/cli_commands/agents_last_exam_baked_input.py +302 -0
  296. loopx/cli_commands/agents_last_exam_host_codex.py +374 -0
  297. loopx/cli_commands/agents_last_exam_launch_dry_run.py +372 -0
  298. loopx/cli_commands/agents_last_exam_local_plan.py +322 -0
  299. loopx/cli_commands/agents_last_exam_runner_source.py +352 -0
  300. loopx/cli_commands/agents_last_exam_task_material.py +335 -0
  301. loopx/cli_commands/agents_last_exam_validation_gate.py +236 -0
  302. loopx/cli_commands/benchmark_boundary.py +499 -0
  303. loopx/cli_commands/benchmark_dispatch.py +161 -0
  304. loopx/cli_commands/benchmark_release_outcome.py +123 -0
  305. loopx/cli_commands/benchmark_review_lifecycle.py +1275 -0
  306. loopx/cli_commands/benchmark_run_ledger.py +763 -0
  307. loopx/cli_commands/benchmark_run_ledger_case_analysis.py +249 -0
  308. loopx/cli_commands/benchmark_run_ledger_classification.py +45 -0
  309. loopx/cli_commands/benchmark_run_ledger_maintenance.py +486 -0
  310. loopx/cli_commands/benchmark_run_ledger_maintenance_registration.py +342 -0
  311. loopx/cli_commands/benchmark_run_ledger_maintenance_rendering.py +233 -0
  312. loopx/cli_commands/benchmark_run_ledger_parity.py +92 -0
  313. loopx/cli_commands/bootstrap_connect.py +238 -0
  314. loopx/cli_commands/canary.py +707 -0
  315. loopx/cli_commands/canary_release_qualification.py +79 -0
  316. loopx/cli_commands/capability.py +96 -0
  317. loopx/cli_commands/doctor.py +43 -0
  318. loopx/cli_commands/dreaming.py +143 -0
  319. loopx/cli_commands/edgebench.py +205 -0
  320. loopx/cli_commands/evidence_log.py +275 -0
  321. loopx/cli_commands/explore.py +989 -0
  322. loopx/cli_commands/explore_planning_commands.py +157 -0
  323. loopx/cli_commands/extension.py +271 -0
  324. loopx/cli_commands/first_run_report.py +73 -0
  325. loopx/cli_commands/goal_channel.py +656 -0
  326. loopx/cli_commands/handoff_mode.py +158 -0
  327. loopx/cli_commands/history.py +622 -0
  328. loopx/cli_commands/host_mode_plan.py +113 -0
  329. loopx/cli_commands/lark_inbox.py +431 -0
  330. loopx/cli_commands/lark_kanban.py +629 -0
  331. loopx/cli_commands/ml_experiment.py +321 -0
  332. loopx/cli_commands/multi_agent.py +211 -0
  333. loopx/cli_commands/opencode2_goal_worker.py +217 -0
  334. loopx/cli_commands/pr_review.py +167 -0
  335. loopx/cli_commands/presentation.py +218 -0
  336. loopx/cli_commands/preset.py +96 -0
  337. loopx/cli_commands/project.py +150 -0
  338. loopx/cli_commands/project_lifecycle.py +915 -0
  339. loopx/cli_commands/quota.py +859 -0
  340. loopx/cli_commands/quota_registration.py +241 -0
  341. loopx/cli_commands/quota_request.py +113 -0
  342. loopx/cli_commands/ready_score.py +110 -0
  343. loopx/cli_commands/registry_admin.py +975 -0
  344. loopx/cli_commands/registry_admin_configure.py +344 -0
  345. loopx/cli_commands/registry_admin_peer.py +84 -0
  346. loopx/cli_commands/registry_authority.py +218 -0
  347. loopx/cli_commands/review_batch.py +146 -0
  348. loopx/cli_commands/slash_commands.py +145 -0
  349. loopx/cli_commands/start_goal.py +251 -0
  350. loopx/cli_commands/starter.py +175 -0
  351. loopx/cli_commands/starter_bootstrap.py +179 -0
  352. loopx/cli_commands/starter_bootstrap_registration.py +198 -0
  353. loopx/cli_commands/starter_runtime_idle.py +107 -0
  354. loopx/cli_commands/starter_scheduler.py +207 -0
  355. loopx/cli_commands/starter_session_runtime.py +152 -0
  356. loopx/cli_commands/starter_visible_common.py +54 -0
  357. loopx/cli_commands/starter_visible_driver.py +161 -0
  358. loopx/cli_commands/starter_visible_pilot.py +278 -0
  359. loopx/cli_commands/status.py +867 -0
  360. loopx/cli_commands/status_registration.py +239 -0
  361. loopx/cli_commands/summary_all.py +222 -0
  362. loopx/cli_commands/support_control.py +809 -0
  363. loopx/cli_commands/support_control_registry.py +68 -0
  364. loopx/cli_commands/support_control_supervisor.py +289 -0
  365. loopx/cli_commands/task_lease.py +306 -0
  366. loopx/cli_commands/terminal_bench_adapter.py +717 -0
  367. loopx/cli_commands/terminal_bench_environment_result.py +1246 -0
  368. loopx/cli_commands/todo.py +940 -0
  369. loopx/cli_commands/todo_argument_validation.py +572 -0
  370. loopx/cli_commands/todo_event.py +114 -0
  371. loopx/cli_commands/turn.py +804 -0
  372. loopx/cli_commands/version.py +46 -0
  373. loopx/cli_commands/worker_bridge.py +659 -0
  374. loopx/cli_rollout.py +314 -0
  375. loopx/codex_cli_goal_tui.py +672 -0
  376. loopx/codex_cli_probe.py +1530 -0
  377. loopx/codex_cli_probe_markdown.py +935 -0
  378. loopx/codex_cli_runtime_probe.py +733 -0
  379. loopx/codex_cli_scheduler.py +564 -0
  380. loopx/codex_goal_baseline.py +620 -0
  381. loopx/configuration_catalog.py +617 -0
  382. loopx/configure_goal.py +1375 -0
  383. loopx/contract.py +996 -0
  384. loopx/control_plane/__init__.py +71 -0
  385. loopx/control_plane/agents/__init__.py +1 -0
  386. loopx/control_plane/agents/agent_lane_recommendation.py +516 -0
  387. loopx/control_plane/agents/agent_scope.py +1578 -0
  388. loopx/control_plane/agents/agent_scope_frontier.py +60 -0
  389. loopx/control_plane/agents/capability_gate.py +531 -0
  390. loopx/control_plane/agents/identity.py +140 -0
  391. loopx/control_plane/agents/legacy_migration.py +169 -0
  392. loopx/control_plane/agents/management_projection.py +658 -0
  393. loopx/control_plane/agents/material_frontier.py +608 -0
  394. loopx/control_plane/agents/material_handoff.py +156 -0
  395. loopx/control_plane/agents/multi_agent/__init__.py +1 -0
  396. loopx/control_plane/agents/multi_agent/codex_executable.py +207 -0
  397. loopx/control_plane/agents/multi_agent/collective_round_ledger.py +387 -0
  398. loopx/control_plane/agents/multi_agent/contract.py +474 -0
  399. loopx/control_plane/agents/multi_agent/recipe.py +110 -0
  400. loopx/control_plane/agents/multi_agent/role_successor.py +297 -0
  401. loopx/control_plane/agents/multi_agent/runtime_scripts.py +426 -0
  402. loopx/control_plane/agents/multi_agent/visible_launch_policy.py +149 -0
  403. loopx/control_plane/agents/multi_agent/visible_wake_scheduler.py +392 -0
  404. loopx/control_plane/agents/profile.py +216 -0
  405. loopx/control_plane/agents/runtime_model.py +73 -0
  406. loopx/control_plane/agents/subagent_activity.py +164 -0
  407. loopx/control_plane/agents/supervisor.py +544 -0
  408. loopx/control_plane/agents/supervisor_events.py +462 -0
  409. loopx/control_plane/agents/supervisor_inject.py +204 -0
  410. loopx/control_plane/agents/work_mode.py +56 -0
  411. loopx/control_plane/agents/workspace_guard.py +364 -0
  412. loopx/control_plane/effect_program.py +644 -0
  413. loopx/control_plane/goals/__init__.py +1 -0
  414. loopx/control_plane/goals/active_state_event_projection.py +103 -0
  415. loopx/control_plane/goals/active_state_metadata.py +47 -0
  416. loopx/control_plane/goals/active_state_sections.py +58 -0
  417. loopx/control_plane/goals/configure_goal_service.py +354 -0
  418. loopx/control_plane/goals/contract_health.py +132 -0
  419. loopx/control_plane/goals/dreaming.py +152 -0
  420. loopx/control_plane/goals/global_registry_health.py +199 -0
  421. loopx/control_plane/goals/global_registry_shadow.py +33 -0
  422. loopx/control_plane/goals/goal_channel.py +34 -0
  423. loopx/control_plane/goals/goal_channel_projection.py +560 -0
  424. loopx/control_plane/goals/goal_frontier/__init__.py +1917 -0
  425. loopx/control_plane/goals/goal_frontier/ack_policy.py +149 -0
  426. loopx/control_plane/goals/goal_frontier/outcome_continuity.py +437 -0
  427. loopx/control_plane/goals/goal_frontier/replan_rules.py +210 -0
  428. loopx/control_plane/goals/goal_frontier/semantic_history.py +314 -0
  429. loopx/control_plane/goals/goal_frontier/terminal.py +180 -0
  430. loopx/control_plane/goals/goal_vision.py +443 -0
  431. loopx/control_plane/goals/goal_vision_policy.py +36 -0
  432. loopx/control_plane/goals/goal_vision_state.py +62 -0
  433. loopx/control_plane/goals/goal_vision_wait.py +290 -0
  434. loopx/control_plane/goals/path_resolution.py +20 -0
  435. loopx/control_plane/goals/start_contract.py +206 -0
  436. loopx/control_plane/goals/vision_checkpoint.py +92 -0
  437. loopx/control_plane/handoff/__init__.py +1 -0
  438. loopx/control_plane/handoff/cross_runtime_impl_review.py +311 -0
  439. loopx/control_plane/handoff/delivery_contract.py +161 -0
  440. loopx/control_plane/handoff/handoff_runs.py +71 -0
  441. loopx/control_plane/handoff/project_handoff.py +155 -0
  442. loopx/control_plane/handoff/review_batch.py +463 -0
  443. loopx/control_plane/handoff/review_packet_context.py +216 -0
  444. loopx/control_plane/heartbeat/agent.py +173 -0
  445. loopx/control_plane/heartbeat/budget.py +66 -0
  446. loopx/control_plane/heartbeat/builder.py +501 -0
  447. loopx/control_plane/heartbeat/host.py +64 -0
  448. loopx/control_plane/heartbeat/rules.py +68 -0
  449. loopx/control_plane/heartbeat/task_body.py +759 -0
  450. loopx/control_plane/heartbeat/visible_goal.py +86 -0
  451. loopx/control_plane/projects/__init__.py +1 -0
  452. loopx/control_plane/projects/contract.py +25 -0
  453. loopx/control_plane/projects/registry.py +663 -0
  454. loopx/control_plane/quota/__init__.py +1 -0
  455. loopx/control_plane/quota/cli_projection.py +704 -0
  456. loopx/control_plane/quota/decision_summary.py +431 -0
  457. loopx/control_plane/quota/effect_program.py +152 -0
  458. loopx/control_plane/quota/error_codes.py +19 -0
  459. loopx/control_plane/quota/goal_boundary.py +464 -0
  460. loopx/control_plane/quota/heartbeat_receipt.py +277 -0
  461. loopx/control_plane/quota/heartbeat_recommendation.py +718 -0
  462. loopx/control_plane/quota/host_poll_receipts.py +162 -0
  463. loopx/control_plane/quota/live_decision.py +142 -0
  464. loopx/control_plane/quota/monitor_poll.py +786 -0
  465. loopx/control_plane/quota/policy_constants.py +40 -0
  466. loopx/control_plane/quota/projection_repair.py +262 -0
  467. loopx/control_plane/quota/recent_runs.py +210 -0
  468. loopx/control_plane/quota/scheduler_ack.py +490 -0
  469. loopx/control_plane/quota/selected_todo_projection.py +139 -0
  470. loopx/control_plane/quota/settlement.py +437 -0
  471. loopx/control_plane/quota/settlement_cli.py +246 -0
  472. loopx/control_plane/quota/settlement_validation.py +64 -0
  473. loopx/control_plane/quota/settlement_workspace_causality.py +180 -0
  474. loopx/control_plane/quota/should_run.py +249 -0
  475. loopx/control_plane/quota/should_run_packet.py +1165 -0
  476. loopx/control_plane/quota/should_run_prepare.py +675 -0
  477. loopx/control_plane/quota/slot_accounting.py +1123 -0
  478. loopx/control_plane/quota/spend_sources.py +11 -0
  479. loopx/control_plane/quota/stall_repair.py +397 -0
  480. loopx/control_plane/quota/states.py +29 -0
  481. loopx/control_plane/quota/task_orchestration.py +448 -0
  482. loopx/control_plane/quota/task_orchestration_admission.py +497 -0
  483. loopx/control_plane/quota/turn_envelope.py +889 -0
  484. loopx/control_plane/quota/usage_summary.py +140 -0
  485. loopx/control_plane/reward_memory.py +43 -0
  486. loopx/control_plane/runtime/__init__.py +2 -0
  487. loopx/control_plane/runtime/active_user_assisted_pilot.py +275 -0
  488. loopx/control_plane/runtime/agent_scoped_evidence_log.py +435 -0
  489. loopx/control_plane/runtime/decision_freshness.py +203 -0
  490. loopx/control_plane/runtime/event_ledger.py +197 -0
  491. loopx/control_plane/runtime/event_store_migration_bridge.py +196 -0
  492. loopx/control_plane/runtime/goal_project_route.py +70 -0
  493. loopx/control_plane/runtime/local_state_write_correctness.py +242 -0
  494. loopx/control_plane/runtime/promotion_readiness.py +152 -0
  495. loopx/control_plane/runtime/public_safety.py +120 -0
  496. loopx/control_plane/runtime/run_artifacts.py +78 -0
  497. loopx/control_plane/runtime/run_compaction.py +397 -0
  498. loopx/control_plane/runtime/run_context_retention.py +241 -0
  499. loopx/control_plane/runtime/run_history.py +132 -0
  500. loopx/control_plane/runtime/run_index_duplicates.py +205 -0
  501. loopx/control_plane/runtime/run_index_rebuild.py +263 -0
  502. loopx/control_plane/runtime/run_ingest_health.py +336 -0
  503. loopx/control_plane/runtime/runtime_projection_route.py +624 -0
  504. loopx/control_plane/runtime/runtime_projection_writer.py +98 -0
  505. loopx/control_plane/runtime/session_runtime.py +339 -0
  506. loopx/control_plane/runtime/shared_runtime_material_projection.py +332 -0
  507. loopx/control_plane/runtime/shared_runtime_refresh_projection.py +183 -0
  508. loopx/control_plane/runtime/stale_latest_run.py +90 -0
  509. loopx/control_plane/runtime/status_classifications.py +49 -0
  510. loopx/control_plane/runtime/status_projection_cache.py +235 -0
  511. loopx/control_plane/runtime/stride_observation.py +144 -0
  512. loopx/control_plane/runtime/time.py +39 -0
  513. loopx/control_plane/runtime/trajectory_hygiene.py +149 -0
  514. loopx/control_plane/runtime/validation_command.py +69 -0
  515. loopx/control_plane/scheduler/__init__.py +1 -0
  516. loopx/control_plane/scheduler/ack.py +329 -0
  517. loopx/control_plane/scheduler/arbitration.py +188 -0
  518. loopx/control_plane/scheduler/automation_liveness.py +183 -0
  519. loopx/control_plane/scheduler/execution_context.py +555 -0
  520. loopx/control_plane/scheduler/external_evidence_observation.py +428 -0
  521. loopx/control_plane/scheduler/monitor_display.py +143 -0
  522. loopx/control_plane/scheduler/monitor_poll_policy.py +161 -0
  523. loopx/control_plane/scheduler/monitor_poll_writeback.py +351 -0
  524. loopx/control_plane/scheduler/monitor_target.py +64 -0
  525. loopx/control_plane/scheduler/monitor_todo.py +146 -0
  526. loopx/control_plane/scheduler/monitor_wait.py +237 -0
  527. loopx/control_plane/scheduler/scheduler_hint.py +1284 -0
  528. loopx/control_plane/scheduler/state.py +354 -0
  529. loopx/control_plane/scheduler/state_transition_rules.py +179 -0
  530. loopx/control_plane/scheduler/time.py +10 -0
  531. loopx/control_plane/settlement_driver.py +293 -0
  532. loopx/control_plane/status/__init__.py +6 -0
  533. loopx/control_plane/status/active_state_projection.py +105 -0
  534. loopx/control_plane/status/agent_lane_projection.py +375 -0
  535. loopx/control_plane/status/attention_projection.py +74 -0
  536. loopx/control_plane/status/autonomous_replan_projection.py +103 -0
  537. loopx/control_plane/status/collection.py +140 -0
  538. loopx/control_plane/status/contract_projection.py +31 -0
  539. loopx/control_plane/status/dreaming_projection.py +52 -0
  540. loopx/control_plane/status/goal_attention_projection.py +157 -0
  541. loopx/control_plane/status/lifecycle_projection.py +110 -0
  542. loopx/control_plane/status/monitor_display_projection.py +69 -0
  543. loopx/control_plane/status/registry_health_projection.py +75 -0
  544. loopx/control_plane/status/run_projection.py +70 -0
  545. loopx/control_plane/status/runtime_summaries.py +161 -0
  546. loopx/control_plane/testing/__init__.py +1 -0
  547. loopx/control_plane/testing/actual_default_model_behavior_portfolio.py +1371 -0
  548. loopx/control_plane/testing/canary_harness.py +182 -0
  549. loopx/control_plane/testing/capability_monitor_repair_tool_behavior.py +674 -0
  550. loopx/control_plane/testing/cli_output_budget.py +807 -0
  551. loopx/control_plane/testing/cli_output_differential.py +250 -0
  552. loopx/control_plane/testing/cli_output_semantics.py +87 -0
  553. loopx/control_plane/testing/control_plane_composition_scenarios.py +225 -0
  554. loopx/control_plane/testing/decision_replay.py +268 -0
  555. loopx/control_plane/testing/doubao_model_behavior_actor.py +559 -0
  556. loopx/control_plane/testing/model_behavior_corpus.py +344 -0
  557. loopx/control_plane/testing/model_behavior_qualification.py +769 -0
  558. loopx/control_plane/testing/model_behavior_retained_cases.py +235 -0
  559. loopx/control_plane/testing/model_tool_behavior.py +536 -0
  560. loopx/control_plane/testing/onboarding_model_behavior_qualification.py +642 -0
  561. loopx/control_plane/testing/quota_fixtures.py +208 -0
  562. loopx/control_plane/testing/quota_should_run_parity.py +57 -0
  563. loopx/control_plane/testing/release_commit_qualification.py +671 -0
  564. loopx/control_plane/testing/replan_semantic_action_behavior.py +1302 -0
  565. loopx/control_plane/testing/scoped_gate_successor_tool_behavior.py +527 -0
  566. loopx/control_plane/testing/selected_todo_tool_behavior.py +1002 -0
  567. loopx/control_plane/testing/terminal_settlement_tool_behavior.py +656 -0
  568. loopx/control_plane/todos/__init__.py +1 -0
  569. loopx/control_plane/todos/active_state_editing.py +296 -0
  570. loopx/control_plane/todos/active_state_todo_parser.py +138 -0
  571. loopx/control_plane/todos/active_state_todos.py +175 -0
  572. loopx/control_plane/todos/addition.py +103 -0
  573. loopx/control_plane/todos/claim_visibility.py +253 -0
  574. loopx/control_plane/todos/completed_archive.py +139 -0
  575. loopx/control_plane/todos/completion_fence.py +49 -0
  576. loopx/control_plane/todos/completion_policy.py +153 -0
  577. loopx/control_plane/todos/completion_validation.py +248 -0
  578. loopx/control_plane/todos/completion_validation_accountability.py +27 -0
  579. loopx/control_plane/todos/completion_validation_projection.py +57 -0
  580. loopx/control_plane/todos/contract.py +1476 -0
  581. loopx/control_plane/todos/decision_scope.py +554 -0
  582. loopx/control_plane/todos/deferred_resume.py +546 -0
  583. loopx/control_plane/todos/durable_completion.py +201 -0
  584. loopx/control_plane/todos/event_writeback.py +484 -0
  585. loopx/control_plane/todos/frontier_deadline.py +132 -0
  586. loopx/control_plane/todos/handoff_gate.py +283 -0
  587. loopx/control_plane/todos/handoff_mode.py +444 -0
  588. loopx/control_plane/todos/handoff_note.py +202 -0
  589. loopx/control_plane/todos/line_update.py +361 -0
  590. loopx/control_plane/todos/list_projection.py +205 -0
  591. loopx/control_plane/todos/markdown.py +199 -0
  592. loopx/control_plane/todos/monitor_metadata.py +88 -0
  593. loopx/control_plane/todos/mutation_authority.py +299 -0
  594. loopx/control_plane/todos/projection.py +655 -0
  595. loopx/control_plane/todos/quota_summary.py +1138 -0
  596. loopx/control_plane/todos/route_continuation.py +267 -0
  597. loopx/control_plane/todos/succession_warning.py +174 -0
  598. loopx/control_plane/todos/summary_item.py +223 -0
  599. loopx/control_plane/todos/text.py +30 -0
  600. loopx/control_plane/todos/todo_index.py +226 -0
  601. loopx/control_plane/todos/todo_summary.py +1458 -0
  602. loopx/control_plane/todos/unblock_resume.py +326 -0
  603. loopx/control_plane/todos/user_gate.py +263 -0
  604. loopx/control_plane/todos/write_hint.py +63 -0
  605. loopx/control_plane/todos/write_policy.py +135 -0
  606. loopx/control_plane/turn_driver/__init__.py +85 -0
  607. loopx/control_plane/turn_driver/codex_cli.py +502 -0
  608. loopx/control_plane/turn_driver/driver.py +355 -0
  609. loopx/control_plane/turn_driver/executor.py +1468 -0
  610. loopx/control_plane/turn_driver/loop_controller.py +669 -0
  611. loopx/control_plane/turn_driver/settlement.py +318 -0
  612. loopx/control_plane/turn_driver/transaction.py +375 -0
  613. loopx/control_plane/work_items/__init__.py +1 -0
  614. loopx/control_plane/work_items/attention_fields.py +56 -0
  615. loopx/control_plane/work_items/attention_item.py +77 -0
  616. loopx/control_plane/work_items/attention_queue.py +322 -0
  617. loopx/control_plane/work_items/attention_routing.py +213 -0
  618. loopx/control_plane/work_items/autonomous_candidates.py +135 -0
  619. loopx/control_plane/work_items/autonomous_replan_ack.py +276 -0
  620. loopx/control_plane/work_items/autonomous_replan_obligation.py +786 -0
  621. loopx/control_plane/work_items/backlog_hygiene.py +59 -0
  622. loopx/control_plane/work_items/capability_monitor_fallback.py +221 -0
  623. loopx/control_plane/work_items/delivery_batch_scale.py +66 -0
  624. loopx/control_plane/work_items/delivery_outcome.py +152 -0
  625. loopx/control_plane/work_items/delivery_signals.py +113 -0
  626. loopx/control_plane/work_items/execution_obligation.py +235 -0
  627. loopx/control_plane/work_items/goal_route_hint.py +320 -0
  628. loopx/control_plane/work_items/interaction_contract.py +1540 -0
  629. loopx/control_plane/work_items/issue_meta_surface.py +159 -0
  630. loopx/control_plane/work_items/lifecycle.py +139 -0
  631. loopx/control_plane/work_items/operator_inbox.py +266 -0
  632. loopx/control_plane/work_items/outcome_followthrough.py +69 -0
  633. loopx/control_plane/work_items/primary_action.py +326 -0
  634. loopx/control_plane/work_items/progress_observation.py +630 -0
  635. loopx/control_plane/work_items/project_asset.py +675 -0
  636. loopx/control_plane/work_items/repair_delta.py +693 -0
  637. loopx/control_plane/work_items/runtime_capability_reentry.py +168 -0
  638. loopx/control_plane/work_items/semantic_replan_writeback.py +177 -0
  639. loopx/control_plane/work_items/status_contract.py +49 -0
  640. loopx/control_plane/work_items/task_graph.py +1046 -0
  641. loopx/control_plane/work_items/task_lease.py +1254 -0
  642. loopx/control_plane/work_items/task_lease_settlement.py +422 -0
  643. loopx/control_plane/work_items/work_lane.py +510 -0
  644. loopx/control_plane/work_items/work_lane_context.py +161 -0
  645. loopx/demo.py +247 -0
  646. loopx/diagnose.py +633 -0
  647. loopx/doctor.py +1251 -0
  648. loopx/domain_packs/__init__.py +1 -0
  649. loopx/domain_packs/issue_fix.py +571 -0
  650. loopx/domain_packs/ml_experiment.py +854 -0
  651. loopx/domain_state.py +137 -0
  652. loopx/dreaming.py +706 -0
  653. loopx/entrypoint.py +16 -0
  654. loopx/event_sourced_state.py +981 -0
  655. loopx/execution_profile.py +286 -0
  656. loopx/experiments/__init__.py +1 -0
  657. loopx/experiments/planner_worker/__init__.py +1 -0
  658. loopx/experiments/planner_worker/contract.py +523 -0
  659. loopx/experiments/planner_worker/runtime.py +391 -0
  660. loopx/experiments/planner_worker/traex.py +461 -0
  661. loopx/explore_graph.py +11 -0
  662. loopx/extensions/__init__.py +1 -0
  663. loopx/extensions/bundled.py +28 -0
  664. loopx/extensions/execution_envelope.py +126 -0
  665. loopx/extensions/lark/__init__.py +11 -0
  666. loopx/extensions/lark/event_collector.py +478 -0
  667. loopx/extensions/lark/event_collector_runtime.py +506 -0
  668. loopx/extensions/lark/event_inbox.py +454 -0
  669. loopx/extensions/lark/extension.toml +88 -0
  670. loopx/extensions/lark/goal_channel.py +44 -0
  671. loopx/extensions/lark/goal_channel_contracts.py +388 -0
  672. loopx/extensions/lark/goal_channel_lifecycle.py +218 -0
  673. loopx/extensions/lark/goal_channel_runtime.py +792 -0
  674. loopx/extensions/lark/goal_channel_setup.py +805 -0
  675. loopx/extensions/lark/goal_channel_targets.py +215 -0
  676. loopx/extensions/lark/goal_channel_transport.py +281 -0
  677. loopx/extensions/lark/inbox_reactions.py +650 -0
  678. loopx/extensions/lark/inbox_reply.py +430 -0
  679. loopx/extensions/lark/presentation/__init__.py +11 -0
  680. loopx/extensions/lark/presentation/explore_results.py +2276 -0
  681. loopx/extensions/lark/presentation/explore_singleflight.py +127 -0
  682. loopx/extensions/lark/presentation/explore_source_guard.py +121 -0
  683. loopx/extensions/lark/presentation/explore_stage_document.py +703 -0
  684. loopx/extensions/lark/presentation/explore_visual_integrity.py +122 -0
  685. loopx/extensions/lark/presentation/explore_visual_readback.py +452 -0
  686. loopx/extensions/lark/presentation/explore_visual_styles.py +156 -0
  687. loopx/extensions/lark/presentation/issue_fix_surface.py +612 -0
  688. loopx/extensions/lark/presentation/kanban.py +2791 -0
  689. loopx/extensions/lark/presentation/message_card.py +112 -0
  690. loopx/extensions/lark/presentation/periodic_report.py +261 -0
  691. loopx/extensions/lark/presentation/projection_rows.py +600 -0
  692. loopx/extensions/lark/presentation/record_io.py +95 -0
  693. loopx/extensions/lark/presentation/sync_receipt.py +145 -0
  694. loopx/extensions/lark/private_json.py +40 -0
  695. loopx/extensions/lark/provider.py +86 -0
  696. loopx/extensions/lark/reviewer_notification.py +604 -0
  697. loopx/extensions/manifest.py +385 -0
  698. loopx/extensions/openviking_periodic_report/__init__.py +17 -0
  699. loopx/extensions/openviking_periodic_report/activation.py +173 -0
  700. loopx/extensions/openviking_periodic_report/extension.toml +17 -0
  701. loopx/extensions/openviking_periodic_report/provider.py +355 -0
  702. loopx/extensions/openviking_periodic_report/sink.py +117 -0
  703. loopx/extensions/openviking_semantic_preference/__init__.py +5 -0
  704. loopx/extensions/openviking_semantic_preference/extension.toml +16 -0
  705. loopx/extensions/openviking_semantic_preference/history_export.py +484 -0
  706. loopx/extensions/openviking_semantic_preference/project_peer.py +68 -0
  707. loopx/extensions/openviking_semantic_preference/provider.py +312 -0
  708. loopx/extensions/presentation.py +979 -0
  709. loopx/extensions/process_runtime.py +204 -0
  710. loopx/extensions/readiness.py +168 -0
  711. loopx/extensions/runtime.py +931 -0
  712. loopx/extensions/scaffold.py +335 -0
  713. loopx/feedback.py +581 -0
  714. loopx/file_lock.py +382 -0
  715. loopx/global_registry.py +842 -0
  716. loopx/global_risks.py +970 -0
  717. loopx/global_todos.py +568 -0
  718. loopx/handoff_budget.py +28 -0
  719. loopx/heartbeat_prequota.py +80 -0
  720. loopx/heartbeat_prompt.py +159 -0
  721. loopx/help_surface.py +516 -0
  722. loopx/history.py +1507 -0
  723. loopx/host_loop_activation.py +1311 -0
  724. loopx/host_mode_planner.py +991 -0
  725. loopx/install_contract.py +1 -0
  726. loopx/interface_budget.py +196 -0
  727. loopx/long_task_cadence.py +208 -0
  728. loopx/materials.py +185 -0
  729. loopx/ml_experiment.py +3 -0
  730. loopx/onboarding.py +214 -0
  731. loopx/opencode2_goal_mode/README.md +81 -0
  732. loopx/opencode2_goal_mode/__init__.py +9 -0
  733. loopx/opencode2_goal_mode/opencode2-goal-worker.mjs +1018 -0
  734. loopx/opencode_goal_mode/README.md +99 -0
  735. loopx/opencode_goal_mode/__init__.py +13 -0
  736. loopx/opencode_goal_mode/goal-bridge-runtime.mjs +858 -0
  737. loopx/opencode_goal_mode/loopx-goal.js +8 -0
  738. loopx/operator_gate.py +420 -0
  739. loopx/orchestration.py +127 -0
  740. loopx/paths.py +59 -0
  741. loopx/pi_goal_mode/README.md +67 -0
  742. loopx/pi_goal_mode/__init__.py +13 -0
  743. loopx/pi_goal_mode/loopx-goal.ts +254 -0
  744. loopx/pi_goal_mode/pi-goal-loop-runtime.mjs +574 -0
  745. loopx/pr_review.py +1206 -0
  746. loopx/presentation/__init__.py +1 -0
  747. loopx/presentation/explore_views.py +1334 -0
  748. loopx/presentation/markdown.py +61 -0
  749. loopx/presentation/projection_source_reconcile.py +140 -0
  750. loopx/presentation/public_safety.py +42 -0
  751. loopx/presentation/renderers/__init__.py +17 -0
  752. loopx/presentation/renderers/goal_channel_html.py +269 -0
  753. loopx/presentation/renderers/periodic_report_html.py +786 -0
  754. loopx/presentation/renderers/periodic_report_markdown.py +184 -0
  755. loopx/presentation/renderers/quota_event_markdown.py +116 -0
  756. loopx/presentation/renderers/quota_markdown.py +1112 -0
  757. loopx/presentation/renderers/status_markdown.py +1570 -0
  758. loopx/presentation/renderers/trajectory_hygiene_markdown.py +39 -0
  759. loopx/presentation/renderers/turn_envelope_markdown.py +33 -0
  760. loopx/presentation/sinks/__init__.py +5 -0
  761. loopx/presentation/sinks/openviking_periodic_report.py +7 -0
  762. loopx/presentation/static_site.py +691 -0
  763. loopx/presets.py +369 -0
  764. loopx/project_alias.py +217 -0
  765. loopx/project_map.py +589 -0
  766. loopx/project_prompt.py +1153 -0
  767. loopx/project_skill_cli.py +125 -0
  768. loopx/project_skill_delivery.py +470 -0
  769. loopx/project_uninstall.py +462 -0
  770. loopx/promotion_gate.py +197 -0
  771. loopx/quota.py +1197 -0
  772. loopx/ready_score.py +413 -0
  773. loopx/registry.py +621 -0
  774. loopx/registry_writability.py +64 -0
  775. loopx/release_candidate.py +148 -0
  776. loopx/release_manifest.py +316 -0
  777. loopx/repository_identity.py +100 -0
  778. loopx/review_packet.py +1024 -0
  779. loopx/rollout_event_log.py +505 -0
  780. loopx/runtime.py +112 -0
  781. loopx/self_update.py +750 -0
  782. loopx/session_runtime.py +418 -0
  783. loopx/skill_install_readback.py +500 -0
  784. loopx/slash_command_install.py +1393 -0
  785. loopx/slash_commands.py +264 -0
  786. loopx/state_backup.py +573 -0
  787. loopx/state_migration.py +350 -0
  788. loopx/state_projection.py +809 -0
  789. loopx/state_refresh.py +1416 -0
  790. loopx/status.py +1383 -0
  791. loopx/status_server.py +935 -0
  792. loopx/summary_all.py +725 -0
  793. loopx/terminal_bench_agent.py +2056 -0
  794. loopx/thread_agent_binding.py +408 -0
  795. loopx/todo_followups.py +168 -0
  796. loopx/todo_suggestion_prompt.py +204 -0
  797. loopx/todos.py +2229 -0
  798. loopx/turn_identity.py +17 -0
  799. loopx/upgrade.py +1083 -0
  800. loopx/visible_governance.py +667 -0
  801. loopx/visible_multi_agent_launcher.py +1253 -0
  802. loopx/visible_multi_agent_tmux.py +429 -0
  803. loopx/worker_bridge.py +1574 -0
  804. loopx-0.4.8.dist-info/METADATA +708 -0
  805. loopx-0.4.8.dist-info/RECORD +811 -0
  806. loopx-0.4.8.dist-info/WHEEL +5 -0
  807. loopx-0.4.8.dist-info/entry_points.txt +5 -0
  808. loopx-0.4.8.dist-info/licenses/LICENSE +202 -0
  809. loopx-0.4.8.dist-info/licenses/LICENSE-MIT +21 -0
  810. loopx-0.4.8.dist-info/licenses/NOTICE +6 -0
  811. loopx-0.4.8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1284 @@
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import json
5
+ import re
6
+ from collections.abc import Collection, Mapping
7
+ from dataclasses import dataclass
8
+ from datetime import datetime, timedelta
9
+ from typing import Any
10
+
11
+ from ..runtime.time import now_utc, utc_isoformat
12
+ from ..todos.frontier_deadline import build_frontier_recheck_plan
13
+ from . import ack as scheduler_ack
14
+ from .arbitration import (
15
+ SchedulerArbitration,
16
+ SchedulerDisposition,
17
+ build_scheduler_arbitration,
18
+ )
19
+ from .execution_context import (
20
+ SchedulerExecutionContextResolution,
21
+ SchedulerOwner,
22
+ SchedulerRuntimeProfile,
23
+ apply_scheduler_execution_context,
24
+ resolve_scheduler_execution_context,
25
+ )
26
+ from .monitor_wait import (
27
+ MONITOR_WAIT_HOST_FLOOR_MINUTES,
28
+ MONITOR_WAIT_PHASE_RANK, # noqa: F401 # re-exported for compatibility
29
+ MONITOR_WAIT_PROGRESSION_MINUTES,
30
+ MonitorWaitPhase, # noqa: F401 # re-exported for compatibility
31
+ _parse_monitor_timestamp, # noqa: F401 # re-exported for compatibility
32
+ build_monitor_wait_cadence_plan,
33
+ )
34
+ from .state import (
35
+ CODEX_APP_STATEFUL_BACKOFF_STATE_KEY,
36
+ CODEX_APP_SURFACE,
37
+ normalize_scheduler_host_update_failures,
38
+ normalize_scheduler_rrule,
39
+ retained_scheduler_host_update_failures,
40
+ rrule_for_minutes,
41
+ scheduler_rrule_interval_minutes,
42
+ )
43
+ from .state_transition_rules import (
44
+ decide_scheduler_cadence_transition,
45
+ decide_scheduler_host_transition,
46
+ )
47
+ from .time import parse_scheduler_timestamp
48
+
49
+ SCHEDULER_HINT_SCHEMA_VERSION = "scheduler_hint_v0"
50
+ SCHEDULER_RESET_POLICY_SCHEMA_VERSION = "scheduler_reset_policy_v0"
51
+ SCHEDULER_HINT_DETAIL_SCHEMA_VERSION = "scheduler_hint_detail_v0"
52
+ CODEX_APP_STATEFUL_BACKOFF_SCHEMA_VERSION = "codex_app_stateful_backoff_v0"
53
+ CODEX_APP_SCHEDULER_ACK_HINT_SCHEMA_VERSION = "codex_app_scheduler_ack_hint_v0"
54
+ CODEX_APP_SCHEDULER_FAILURE_HINT_SCHEMA_VERSION = "codex_app_scheduler_failure_hint_v0"
55
+ CODEX_APP_SCHEDULER_FALLBACK_HINT_SCHEMA_VERSION = (
56
+ "codex_app_scheduler_fallback_hint_v0"
57
+ )
58
+ USER_GATE_NOTIFICATION_COOLDOWN_SCHEMA_VERSION = "user_gate_notification_cooldown_v0"
59
+ CODEX_APP_MAX_INTERVAL_MINUTES = 60
60
+ DEFAULT_ACK_CAPABILITIES = {"shell", "filesystem_read", "filesystem_write"}
61
+ FALLBACK_AUTOMATION_ID_PATTERN = re.compile(r"^[A-Za-z0-9._:-]{1,128}$")
62
+ SCHEDULER_BASE_IDENTITY_KEYS = (
63
+ "goal_id",
64
+ "agent_identity.agent_id",
65
+ "effective_action",
66
+ "heartbeat_recommendation.recommended_mode",
67
+ "interaction_contract.mode",
68
+ )
69
+
70
+
71
+ def build_projected_codex_app_automation_id(
72
+ *,
73
+ goal_id: Any,
74
+ agent_id: Any,
75
+ ) -> str:
76
+ """Build a deterministic Codex App automation id when none is installed yet.
77
+
78
+ The fallback bridge needs a stable automation id to create the first
79
+ heartbeat automation for a goal/agent pair. The id is derived from the
80
+ same identity keys used by the scheduler so a later run can resolve it
81
+ back to the installed automation without guessing.
82
+ """
83
+
84
+ safe_goal_id = str(goal_id or "").strip()
85
+ safe_agent_id = str(agent_id or "").strip()
86
+ raw = (
87
+ f"loopx-{safe_goal_id}-{safe_agent_id}"
88
+ if safe_agent_id
89
+ else f"loopx-{safe_goal_id}"
90
+ )
91
+ projected = re.sub(r"[^A-Za-z0-9._:-]", "-", raw)
92
+ projected = re.sub(r"-+", "-", projected).strip("-")
93
+ return projected[:128] or "loopx-fallback"
94
+ SCHEDULER_FRONTIER_IDENTITY_KEYS = (
95
+ "selected_todo.todo_id",
96
+ "selected_todo.action_kind",
97
+ "selected_todo.target_key",
98
+ "selected_todo.claimed_by",
99
+ "selected_todo.capability_binding_ref",
100
+ )
101
+ SCHEDULER_IDENTITY_KEYS = (
102
+ *SCHEDULER_BASE_IDENTITY_KEYS,
103
+ "recommended_action",
104
+ )
105
+ MONITOR_WAIT_IDENTITY_KEYS = SCHEDULER_BASE_IDENTITY_KEYS
106
+ CODEX_APP_SSH_GOAL_RUNTIME_KEY = SchedulerRuntimeProfile.CODEX_APP_SSH_VISIBLE.value
107
+ CODEX_NATIVE_GOAL_BLOCK_ACTION = "update_goal_blocked_keep_loopx_active"
108
+ CODEX_NATIVE_GOAL_RESUME_TRIGGER = "explicit_codex_goal_resume"
109
+
110
+ build_codex_app_scheduler_ack_event = scheduler_ack.build_codex_app_scheduler_ack_event
111
+ build_scheduler_ack_plan = scheduler_ack.build_scheduler_ack_plan
112
+ scheduler_backoff_packet = scheduler_ack.scheduler_backoff_packet
113
+
114
+
115
+ def _stable_digest(value: Any, *, length: int) -> str:
116
+ encoded = json.dumps(
117
+ value,
118
+ ensure_ascii=True,
119
+ sort_keys=True,
120
+ default=str,
121
+ ).encode("utf-8")
122
+ return hashlib.sha256(encoded).hexdigest()[:length]
123
+
124
+
125
+ def _dict_or_empty(value: Any) -> dict[str, Any]:
126
+ return value if isinstance(value, dict) else {}
127
+
128
+
129
+ def _scheduler_identity_keys(
130
+ *,
131
+ cadence_class: str,
132
+ execution_context: SchedulerExecutionContextResolution,
133
+ ) -> tuple[str, ...]:
134
+ base_keys = (
135
+ MONITOR_WAIT_IDENTITY_KEYS
136
+ if cadence_class == "monitor_wait"
137
+ else SCHEDULER_IDENTITY_KEYS
138
+ )
139
+ context = execution_context.context if execution_context.ok else None
140
+ if context is None or context.scheduler_owner is not SchedulerOwner.GOAL_RUNTIME:
141
+ return base_keys
142
+ if cadence_class == "monitor_wait":
143
+ return (*base_keys, *SCHEDULER_FRONTIER_IDENTITY_KEYS)
144
+ return (
145
+ *base_keys[:-1],
146
+ *SCHEDULER_FRONTIER_IDENTITY_KEYS,
147
+ base_keys[-1],
148
+ )
149
+
150
+
151
+ def _build_scheduler_stop_hint(
152
+ *,
153
+ execution_context: SchedulerExecutionContextResolution,
154
+ action: str,
155
+ cadence_class: str,
156
+ reason_code: str,
157
+ reason: str,
158
+ spend_policy: str,
159
+ resume_trigger: str,
160
+ ssh_goal_runtime_action: str,
161
+ unchanged_spend_policy: str,
162
+ ) -> dict[str, Any]:
163
+ return apply_scheduler_execution_context(
164
+ {
165
+ "schema_version": SCHEDULER_HINT_SCHEMA_VERSION,
166
+ "source": "quota.should-run",
167
+ "action": action,
168
+ "cadence_class": cadence_class,
169
+ "reason_code": reason_code,
170
+ "reason": reason,
171
+ "spend_policy": spend_policy,
172
+ "codex_app": {
173
+ "apply": "pause_or_delete_current_heartbeat_if_possible",
174
+ "host_tool": "automation_update",
175
+ "host_action": "pause_or_delete_current_heartbeat",
176
+ "host_action_required": True,
177
+ "attempt_limit": 1,
178
+ "verify_host_result": True,
179
+ "ack_required": False,
180
+ "resume_trigger": resume_trigger,
181
+ "no_spend_for_host_action": True,
182
+ },
183
+ "unchanged_poll": {
184
+ "local_scheduler": "stop",
185
+ "codex_cli_tui": "exit",
186
+ CODEX_APP_SSH_GOAL_RUNTIME_KEY: ssh_goal_runtime_action,
187
+ "claude_code_loop": "stop",
188
+ "final_quota_replan_check_enabled": False,
189
+ "spend_policy": unchanged_spend_policy,
190
+ },
191
+ "unchanged_identity_keys": list(
192
+ _scheduler_identity_keys(
193
+ cadence_class=cadence_class,
194
+ execution_context=execution_context,
195
+ )
196
+ ),
197
+ },
198
+ execution_context,
199
+ )
200
+
201
+
202
+ def _scheduler_progression_interval_elapsed(
203
+ scheduler_state: Mapping[str, Any],
204
+ *,
205
+ current_time: datetime,
206
+ ) -> bool:
207
+ """Advance only after the applied host cadence has had one real interval."""
208
+
209
+ updated_at = parse_scheduler_timestamp(scheduler_state.get("updated_at"))
210
+ applied_interval = scheduler_rrule_interval_minutes(
211
+ scheduler_state.get("last_applied_rrule")
212
+ )
213
+ if updated_at is None or applied_interval is None:
214
+ # Legacy or partial state has no trustworthy settlement clock. Preserve
215
+ # the historical progression behavior instead of pinning it forever.
216
+ return True
217
+ return current_time >= updated_at + timedelta(minutes=applied_interval)
218
+
219
+
220
+ def _user_gate_notification_cooldown(
221
+ *,
222
+ cadence_class: str,
223
+ host_failure_suppressed: bool,
224
+ current_interval_minutes: int,
225
+ effective_host_rrule: str,
226
+ recorded_host_failure: dict[str, Any] | None,
227
+ ) -> dict[str, Any] | None:
228
+ """Bound repeat gate notices when a failed host update leaves a tight poll."""
229
+
230
+ if cadence_class != "human_gate" or not host_failure_suppressed:
231
+ return None
232
+ failed_at = parse_scheduler_timestamp((recorded_host_failure or {}).get("failed_at"))
233
+ host_interval = scheduler_rrule_interval_minutes(effective_host_rrule)
234
+ target_interval = max(1, int(current_interval_minutes))
235
+ if failed_at is None or host_interval is None or host_interval >= target_interval:
236
+ return None
237
+ current_time = now_utc()
238
+ elapsed_seconds = max(0.0, (current_time - failed_at).total_seconds())
239
+ cooldown_seconds = target_interval * 60
240
+ window_seconds = host_interval * 60
241
+ cycle_index = int(elapsed_seconds // cooldown_seconds)
242
+ cycle_position = elapsed_seconds - cycle_index * cooldown_seconds
243
+ notification_due = cycle_index >= 1 and cycle_position < window_seconds
244
+ next_reminder_at = failed_at + timedelta(
245
+ seconds=(cycle_index + 1) * cooldown_seconds
246
+ )
247
+ return {
248
+ "schema_version": USER_GATE_NOTIFICATION_COOLDOWN_SCHEMA_VERSION,
249
+ "active": True,
250
+ "notification_due": notification_due,
251
+ "notification_suppressed": not notification_due,
252
+ "policy": "failed_host_update_bounded_reminder_window",
253
+ "cooldown_minutes": target_interval,
254
+ "reminder_window_minutes": host_interval,
255
+ "failed_at": utc_isoformat(failed_at),
256
+ "next_reminder_at": utc_isoformat(next_reminder_at),
257
+ "reason": (
258
+ "the user gate is still pending, but the failed host cadence update "
259
+ "left a tighter poll; suppress duplicate notices outside the bounded "
260
+ "human-gate reminder window"
261
+ ),
262
+ }
263
+
264
+
265
+ def _monitor_rrule_applied_within_stale_tolerance(
266
+ *,
267
+ cadence_class: str,
268
+ last_applied_rrule: str,
269
+ current_rrule: str,
270
+ ) -> bool:
271
+ if cadence_class != "monitor_wait":
272
+ return False
273
+ applied_minutes = scheduler_rrule_interval_minutes(last_applied_rrule)
274
+ current_minutes = scheduler_rrule_interval_minutes(current_rrule)
275
+ if applied_minutes is None or current_minutes is None:
276
+ return False
277
+ if applied_minutes < current_minutes:
278
+ return False
279
+ return (
280
+ applied_minutes - current_minutes
281
+ <= scheduler_ack.SCHEDULER_ACK_STALE_HINT_TOLERANCE_MINUTES
282
+ )
283
+
284
+
285
+ def build_codex_app_scheduler_ack_hint(
286
+ *,
287
+ goal_id: Any,
288
+ agent_id: Any,
289
+ applied_rrule: Any,
290
+ reset_token: Any,
291
+ identity_signature: Any,
292
+ available_capabilities: Any = None,
293
+ after: str = "automation_update_rrule_success",
294
+ host_match_observed: bool = False,
295
+ surface: str = CODEX_APP_SURFACE,
296
+ state_key: str = CODEX_APP_STATEFUL_BACKOFF_STATE_KEY,
297
+ ) -> dict[str, Any]:
298
+ safe_rrule = normalize_scheduler_rrule(applied_rrule)
299
+ safe_goal_id = str(goal_id or "").strip()
300
+ safe_agent_id = str(agent_id or "").strip()
301
+ safe_surface = str(surface or "").strip()
302
+ safe_state_key = str(state_key or "").strip()
303
+ safe_reset_token = str(reset_token or "").strip()
304
+ safe_identity_signature = str(identity_signature or "").strip()
305
+ safe_available_capabilities: list[str] = []
306
+ if isinstance(available_capabilities, (list, tuple, set)):
307
+ for capability in available_capabilities:
308
+ safe_capability = str(capability or "").strip()
309
+ if (
310
+ safe_capability
311
+ and safe_capability not in DEFAULT_ACK_CAPABILITIES
312
+ and safe_capability not in safe_available_capabilities
313
+ ):
314
+ safe_available_capabilities.append(safe_capability)
315
+ cli_args = [
316
+ "quota",
317
+ "scheduler-ack-current",
318
+ "--goal-id",
319
+ safe_goal_id,
320
+ "--agent-id",
321
+ safe_agent_id,
322
+ "-A",
323
+ ]
324
+ for capability in safe_available_capabilities:
325
+ cli_args.extend(["--available-capability", capability])
326
+ if safe_surface != CODEX_APP_SURFACE:
327
+ cli_args.extend(["--surface", safe_surface])
328
+ if safe_state_key != CODEX_APP_STATEFUL_BACKOFF_STATE_KEY:
329
+ cli_args.extend(["--state-key", safe_state_key])
330
+ cli_args.extend(["--applied-rrule", safe_rrule])
331
+ if host_match_observed:
332
+ cli_args.extend(
333
+ [
334
+ "--host-match-observed",
335
+ "--reset-token",
336
+ safe_reset_token,
337
+ "--identity-signature",
338
+ safe_identity_signature,
339
+ ]
340
+ )
341
+ cli_args.append("--execute")
342
+ args = {
343
+ "goal_id": safe_goal_id,
344
+ "agent_id": safe_agent_id,
345
+ "surface": safe_surface,
346
+ "state_key": safe_state_key,
347
+ "applied_rrule": safe_rrule,
348
+ "reset_token": safe_reset_token,
349
+ "identity_signature": safe_identity_signature,
350
+ }
351
+ if safe_available_capabilities:
352
+ args["available_capabilities"] = safe_available_capabilities
353
+ if host_match_observed:
354
+ args["host_match_observed"] = True
355
+ return {
356
+ "schema_version": CODEX_APP_SCHEDULER_ACK_HINT_SCHEMA_VERSION,
357
+ "after": str(after or "automation_update_rrule_success").strip(),
358
+ "command": "quota scheduler-ack-current",
359
+ "execute": True,
360
+ "cli_args": cli_args,
361
+ "args": args,
362
+ "uses_current_hint": True,
363
+ "no_spend": True,
364
+ }
365
+
366
+
367
+ def build_codex_app_scheduler_failure_hint(
368
+ *,
369
+ goal_id: Any,
370
+ agent_id: Any,
371
+ failed_rrule: Any,
372
+ observed_host_rrule: Any = None,
373
+ available_capabilities: Any = None,
374
+ ) -> dict[str, Any]:
375
+ safe_goal_id = str(goal_id or "").strip()
376
+ safe_agent_id = str(agent_id or "").strip()
377
+ safe_rrule = normalize_scheduler_rrule(failed_rrule)
378
+ safe_observed_rrule = normalize_scheduler_rrule(observed_host_rrule)
379
+ safe_capabilities: list[str] = []
380
+ if isinstance(available_capabilities, (list, tuple, set)):
381
+ for capability in available_capabilities:
382
+ safe_capability = str(capability or "").strip()
383
+ if (
384
+ safe_capability
385
+ and safe_capability not in DEFAULT_ACK_CAPABILITIES
386
+ and safe_capability not in safe_capabilities
387
+ ):
388
+ safe_capabilities.append(safe_capability)
389
+ cli_args = [
390
+ "quota",
391
+ "scheduler-fail-current",
392
+ "--goal-id",
393
+ safe_goal_id,
394
+ "--agent-id",
395
+ safe_agent_id,
396
+ "-A",
397
+ ]
398
+ for capability in safe_capabilities:
399
+ cli_args.extend(["--available-capability", capability])
400
+ cli_args.extend(
401
+ [
402
+ "--failed-rrule",
403
+ safe_rrule,
404
+ ]
405
+ )
406
+ if safe_observed_rrule:
407
+ cli_args.extend(["--codex-app-current-rrule", safe_observed_rrule])
408
+ cli_args.append("--execute")
409
+ return {
410
+ "schema_version": CODEX_APP_SCHEDULER_FAILURE_HINT_SCHEMA_VERSION,
411
+ "cli_args": cli_args,
412
+ }
413
+
414
+
415
+ def build_codex_app_scheduler_fallback_hint(
416
+ *,
417
+ goal_id: Any,
418
+ agent_id: Any,
419
+ automation_id: Any,
420
+ turn_instance_id: Any = "${LOOPX_TURN:?}",
421
+ ) -> dict[str, Any]:
422
+ """Project the bounded SQLite/TOML RRULE fallback for automation_update gaps.
423
+
424
+ The fallback is a standalone host bridge (``loopx-apply-rrule``) that backs
425
+ up ``codex-dev.db``, syncs the automation TOML and SQLite row, and runs the
426
+ bound scheduler ACK. It directly edits the Codex App automation store,
427
+ bypassing the app API, so it is projected only when the host tool is
428
+ unavailable or failed and ``apply_needed=true`` - never as the routine path.
429
+ When no automation is installed yet, a deterministic automation id is
430
+ projected so the fallback bridge can create the first heartbeat automation.
431
+ """
432
+
433
+ safe_goal_id = str(goal_id or "").strip()
434
+ safe_agent_id = str(agent_id or "").strip()
435
+ safe_automation_id = str(automation_id or "").strip()
436
+ safe_turn_instance_id = str(turn_instance_id or "").strip() or "${LOOPX_TURN:?}"
437
+ projected_automation_id = False
438
+ if not FALLBACK_AUTOMATION_ID_PATTERN.match(safe_automation_id):
439
+ safe_automation_id = build_projected_codex_app_automation_id(
440
+ goal_id=safe_goal_id,
441
+ agent_id=safe_agent_id,
442
+ )
443
+ projected_automation_id = True
444
+ cli_args = [
445
+ "loopx-apply-rrule",
446
+ "--goal-id",
447
+ safe_goal_id,
448
+ "--agent-id",
449
+ safe_agent_id,
450
+ "--automation-id",
451
+ safe_automation_id,
452
+ "--turn-instance-id",
453
+ safe_turn_instance_id,
454
+ ]
455
+ return {
456
+ "schema_version": CODEX_APP_SCHEDULER_FALLBACK_HINT_SCHEMA_VERSION,
457
+ "available": True,
458
+ "command": "loopx-apply-rrule",
459
+ "after": "automation_update_unavailable_or_failed",
460
+ "cli_args": cli_args,
461
+ "args": {
462
+ "goal_id": safe_goal_id,
463
+ "agent_id": safe_agent_id,
464
+ "automation_id": safe_automation_id,
465
+ "turn_instance_id": safe_turn_instance_id,
466
+ },
467
+ "no_spend": True,
468
+ "reason": (
469
+ "fallback only when automation_update is unavailable or failed and "
470
+ "apply_needed=true; loopx-apply-rrule directly updates the Codex App "
471
+ "SQLite automation store (codex-dev.db) and TOML, which bypasses the "
472
+ "app API - use only as a bounded fallback, never as the routine path; "
473
+ "run the bound ack_hint after it succeeds"
474
+ + (
475
+ "; automation_id_projected: no installed heartbeat automation "
476
+ "matched this goal/agent, so loopx-apply-rrule will create it "
477
+ "before applying the rrule"
478
+ if projected_automation_id
479
+ else ""
480
+ )
481
+ ),
482
+ **(
483
+ {
484
+ "automation_id_projected": True,
485
+ "action": "create_then_apply_rrule_via_fallback",
486
+ }
487
+ if projected_automation_id
488
+ else {}
489
+ ),
490
+ }
491
+
492
+
493
+ @dataclass(frozen=True)
494
+ class _SchedulerHintBuilder:
495
+ payload: dict[str, Any]
496
+ execution_context: SchedulerExecutionContextResolution
497
+ arbitration: SchedulerArbitration
498
+ spend_policy: Any
499
+ scheduler_ack_capabilities: Any
500
+ codex_app_scheduler_state: dict[str, Any] | None
501
+ codex_app_current_rrule: Any
502
+ codex_app_automation_id: Any
503
+ include_detail: bool
504
+
505
+ def _identity_value(self, path: str) -> Any:
506
+ current: Any = self.payload
507
+ for part in path.split("."):
508
+ if not isinstance(current, dict):
509
+ return None
510
+ current = current.get(part)
511
+ return current
512
+
513
+ def build(
514
+ self,
515
+ *,
516
+ action: str,
517
+ cadence_class: str,
518
+ reason: str,
519
+ codex_interval: int,
520
+ codex_max: int,
521
+ cli_limit: int | None,
522
+ claude_limit: int | None,
523
+ multiplier: int = 2,
524
+ cadence_progression_override: list[int] | None = None,
525
+ reset_profile_snapshot_override: dict[str, Any] | None = None,
526
+ cadence_context_detail: dict[str, Any] | None = None,
527
+ advance_same_identity: bool = True,
528
+ ) -> dict[str, Any]:
529
+ local_cadence_progression = cadence_progression_override or [
530
+ min(codex_interval * (multiplier**step), codex_max) for step in range(3)
531
+ ]
532
+ codex_host_max = min(max(1, codex_max), CODEX_APP_MAX_INTERVAL_MINUTES)
533
+ codex_cadence_progression: list[int] = []
534
+ for interval in local_cadence_progression:
535
+ bounded_interval = min(max(1, int(interval)), codex_host_max)
536
+ if (
537
+ not codex_cadence_progression
538
+ or codex_cadence_progression[-1] != bounded_interval
539
+ ):
540
+ codex_cadence_progression.append(bounded_interval)
541
+ codex_initial_interval = codex_cadence_progression[0]
542
+ local_initial_interval = local_cadence_progression[0]
543
+ final_replan_check = {
544
+ "enabled": cli_limit is not None or claude_limit is not None,
545
+ "trigger": "before_unchanged_poll_after_limit",
546
+ "action": "rerun_quota_should_run_once",
547
+ "if_changed": "follow_new_scheduler_hint",
548
+ "if_run_now": "execute_new_quota_contract",
549
+ "if_unchanged": "apply_after_limit_without_spend",
550
+ "spend_policy": "no quota spend for final replan check or loop stop",
551
+ }
552
+ identity_keys = list(
553
+ _scheduler_identity_keys(
554
+ cadence_class=cadence_class,
555
+ execution_context=self.execution_context,
556
+ )
557
+ )
558
+ identity_snapshot = {key: self._identity_value(key) for key in identity_keys}
559
+ codex_rrule = rrule_for_minutes(codex_initial_interval)
560
+ profile_snapshot = {
561
+ "cadence_class": cadence_class,
562
+ "codex_app_initial_interval_minutes": codex_initial_interval,
563
+ "codex_app_initial_rrule": codex_rrule,
564
+ "codex_app_max_interval_minutes": codex_host_max,
565
+ "codex_app_progression_minutes": codex_cadence_progression,
566
+ "unchanged_poll_backoff_multiplier": multiplier,
567
+ "local_scheduler_unchanged_poll_limit": cli_limit,
568
+ "claude_code_loop_unchanged_poll_limit": claude_limit,
569
+ }
570
+ reset_profile_snapshot = reset_profile_snapshot_override or profile_snapshot
571
+ reset_token = _stable_digest(
572
+ {
573
+ "action": action,
574
+ "identity_snapshot": identity_snapshot,
575
+ "profile_snapshot": reset_profile_snapshot,
576
+ },
577
+ length=16,
578
+ )
579
+ identity_signature = _stable_digest(identity_snapshot, length=12)
580
+ profile_signature = _stable_digest(profile_snapshot, length=12)
581
+ reset_profile_signature = _stable_digest(reset_profile_snapshot, length=12)
582
+ reset_policy_detail = {
583
+ "schema_version": SCHEDULER_RESET_POLICY_SCHEMA_VERSION,
584
+ "source": "quota.should-run",
585
+ "reset_to": "profile_initial_interval",
586
+ "profile_action": action,
587
+ "reset_token": reset_token,
588
+ "host_state_key": "scheduler_hint.reset_policy.reset_token",
589
+ "codex_app_initial_interval_minutes": codex_initial_interval,
590
+ "codex_app_initial_rrule": codex_rrule,
591
+ "local_scheduler_initial_interval_minutes": local_initial_interval,
592
+ "clear_unchanged_poll_state": True,
593
+ "identity_key_count": len(identity_keys),
594
+ "identity_signature": identity_signature,
595
+ "profile_signature": profile_signature,
596
+ "reset_profile_signature": reset_profile_signature,
597
+ "reset_condition_summary": "token_changed|user_feedback|new_or_reassigned_todo|gate_or_material_transition|active_work_projected",
598
+ "after_reset": "apply_initial_interval_before_backoff",
599
+ "codex_app_tool": "automation_update",
600
+ "codex_app_apply": "call_automation_update_to_restore_initial_rrule_on_token_change",
601
+ "no_spend_for_reset": True,
602
+ }
603
+ reset_policy = {
604
+ "reset_token": reset_token,
605
+ "host_state_key": "scheduler_hint.reset_policy.reset_token",
606
+ "codex_app_initial_interval_minutes": codex_initial_interval,
607
+ "codex_app_initial_rrule": codex_rrule,
608
+ "identity_signature": identity_signature,
609
+ }
610
+ local_scheduler = {
611
+ "recommended_interval_minutes": local_initial_interval,
612
+ "max_interval_minutes": codex_max,
613
+ "unchanged_poll_backoff_multiplier": multiplier,
614
+ "example_progression_minutes": local_cadence_progression,
615
+ "unchanged_poll_limit": cli_limit,
616
+ "after_limit": "stop_tick_loop" if cli_limit is not None else "continue",
617
+ "final_quota_replan_check": final_replan_check,
618
+ "no_spend_for_cadence_change": True,
619
+ }
620
+ codex_goal_loop = {
621
+ "unchanged_poll_limit": cli_limit,
622
+ "after_limit": (
623
+ CODEX_NATIVE_GOAL_BLOCK_ACTION
624
+ if cli_limit is not None
625
+ else "continue"
626
+ ),
627
+ "final_quota_replan_check": final_replan_check,
628
+ "loopx_goal_state": "remains_active",
629
+ "resume_trigger": CODEX_NATIVE_GOAL_RESUME_TRIGGER,
630
+ "no_spend_for_block": True,
631
+ }
632
+ codex_cli_tui = {
633
+ **codex_goal_loop,
634
+ "no_spend_for_exit": True,
635
+ }
636
+ codex_app_ssh_goal = dict(codex_goal_loop)
637
+ claude_code_loop = {
638
+ "unchanged_poll_limit": claude_limit,
639
+ "after_limit": "stop_loop" if claude_limit is not None else "continue",
640
+ "final_quota_replan_check": final_replan_check,
641
+ "no_spend_for_stop": True,
642
+ }
643
+ scheduler_state = _dict_or_empty(self.codex_app_scheduler_state)
644
+ scheduler_now = now_utc()
645
+ all_host_update_failures = retained_scheduler_host_update_failures(
646
+ normalize_scheduler_host_update_failures(
647
+ scheduler_state.get("host_update_failures"),
648
+ legacy_failure=scheduler_state.get("host_update_failure"),
649
+ ),
650
+ reference_time=scheduler_now,
651
+ )
652
+ cadence_decision = decide_scheduler_cadence_transition(
653
+ codex_cadence_progression,
654
+ scheduler_state=scheduler_state,
655
+ reset_token=reset_token,
656
+ identity_signature=identity_signature,
657
+ advance_same_identity=advance_same_identity,
658
+ applied_interval_elapsed=_scheduler_progression_interval_elapsed(
659
+ scheduler_state,
660
+ current_time=scheduler_now,
661
+ ),
662
+ has_host_update_failures=bool(all_host_update_failures),
663
+ )
664
+ current_index = cadence_decision.current_index
665
+ state_status = cadence_decision.state_status
666
+ current_interval = codex_cadence_progression[current_index]
667
+ current_rrule = rrule_for_minutes(current_interval)
668
+ last_applied_rrule = str(
669
+ scheduler_state.get("last_applied_rrule") or ""
670
+ ).strip()
671
+ observed_host_rrule = normalize_scheduler_rrule(self.codex_app_current_rrule)
672
+ effective_host_rrule = observed_host_rrule or last_applied_rrule
673
+ host_update_failures = retained_scheduler_host_update_failures(
674
+ all_host_update_failures,
675
+ reference_time=scheduler_now,
676
+ observed_host_rrule=effective_host_rrule,
677
+ )
678
+ recorded_host_failure = next(
679
+ (
680
+ failure
681
+ for failure in reversed(host_update_failures)
682
+ if normalize_scheduler_rrule(failure.get("target_rrule"))
683
+ == current_rrule
684
+ ),
685
+ host_update_failures[-1] if host_update_failures else None,
686
+ )
687
+ current_rrule_already_applied = effective_host_rrule == current_rrule
688
+ if (
689
+ not current_rrule_already_applied
690
+ and not observed_host_rrule
691
+ and state_status == "same_identity"
692
+ ):
693
+ current_rrule_already_applied = (
694
+ _monitor_rrule_applied_within_stale_tolerance(
695
+ cadence_class=cadence_class,
696
+ last_applied_rrule=effective_host_rrule,
697
+ current_rrule=current_rrule,
698
+ )
699
+ )
700
+ host_decision = decide_scheduler_host_transition(
701
+ state_status=state_status,
702
+ observed_host_rrule=observed_host_rrule,
703
+ effective_host_rrule=effective_host_rrule,
704
+ current_rrule=current_rrule,
705
+ current_rrule_already_applied=current_rrule_already_applied,
706
+ scheduler_state_acknowledges_current_rrule=(
707
+ state_status == "same_identity"
708
+ and normalize_scheduler_rrule(last_applied_rrule) == current_rrule
709
+ ),
710
+ all_host_update_failures=all_host_update_failures,
711
+ recorded_host_failure=recorded_host_failure,
712
+ )
713
+ apply_needed = host_decision.apply_needed
714
+ ack_needed = host_decision.ack_needed
715
+ host_match_ack_needed = host_decision.host_match_ack_needed
716
+ host_failure_suppressed = host_decision.host_failure_suppressed
717
+ if host_failure_suppressed:
718
+ state_status = "host_update_failure_suppressed"
719
+ stateful_backoff_detail = {
720
+ "progression_minutes": codex_cadence_progression,
721
+ "current_interval_minutes": current_interval,
722
+ "host_max_interval_minutes": codex_host_max,
723
+ "coarser_wait_fallback": "local_scheduler_only",
724
+ "host_update_failure": "cache_recent_failed_target_and_observed_host_pairs_then_suppress_each_exact_repeat_until_host_changes_ack_or_expiry",
725
+ "ack_required_after_apply": apply_needed,
726
+ "ack_required_from_host_match": host_match_ack_needed,
727
+ "persist": "reset_token|identity_signature|progression_index|last_applied_rrule|host_update_failures|host_update_failure_compat",
728
+ "same_identity_action": (
729
+ "advance_index_after_applied_interval_elapsed"
730
+ if advance_same_identity
731
+ else "keep_initial_interval_while_active_work"
732
+ ),
733
+ "reset_action": "clear_progression_index_apply_initial_rrule",
734
+ "automation_update_scope": "rrule_only_preserve_body_name_status",
735
+ }
736
+ codex_app = {
737
+ "recommended_interval_minutes": current_interval,
738
+ "max_interval_minutes": codex_host_max,
739
+ "unchanged_poll_backoff_multiplier": multiplier,
740
+ "example_progression_minutes": codex_cadence_progression,
741
+ "apply": (
742
+ "update_automation_cadence_if_possible"
743
+ if apply_needed
744
+ else (
745
+ "none_recorded_host_failure"
746
+ if host_failure_suppressed
747
+ else "none_already_applied"
748
+ )
749
+ ),
750
+ "host_tool": "automation_update",
751
+ "host_action": (
752
+ "update_current_heartbeat_rrule"
753
+ if apply_needed
754
+ else (
755
+ "none_recorded_host_failure"
756
+ if host_failure_suppressed
757
+ else "ack_observed_rrule_without_update"
758
+ if host_match_ack_needed
759
+ else "none"
760
+ )
761
+ ),
762
+ "host_action_contract": (
763
+ "automation_update_rrule_then_quota_scheduler_ack"
764
+ if apply_needed
765
+ else (
766
+ "skip_automation_update_for_recorded_host_failure"
767
+ if host_failure_suppressed
768
+ else "quota_scheduler_ack_from_matching_host_observation"
769
+ if host_match_ack_needed
770
+ else "skip_automation_update_when_apply_needed_false"
771
+ )
772
+ ),
773
+ "rrule_source": (
774
+ "scheduler_hint.codex_app.recommended_rrule" if apply_needed else None
775
+ ),
776
+ "stateful_backoff": {
777
+ "schema_version": CODEX_APP_STATEFUL_BACKOFF_SCHEMA_VERSION,
778
+ "state_key": CODEX_APP_STATEFUL_BACKOFF_STATE_KEY,
779
+ "identity_signature": identity_signature,
780
+ "reset_token": reset_token,
781
+ "progression_index": current_index,
782
+ "current_rrule": current_rrule,
783
+ "apply_needed": apply_needed,
784
+ "ack_needed": ack_needed,
785
+ "state_status": state_status,
786
+ },
787
+ "no_spend_for_cadence_change": True,
788
+ }
789
+ stateful_backoff = codex_app["stateful_backoff"]
790
+ if host_update_failures:
791
+ stateful_backoff["host_update_failures"] = [
792
+ dict(failure) for failure in host_update_failures
793
+ ]
794
+ if recorded_host_failure:
795
+ stateful_backoff["host_update_failure"] = dict(recorded_host_failure)
796
+ if observed_host_rrule:
797
+ stateful_backoff["host_observation"] = {
798
+ "source": "quota_should_run_host_observation",
799
+ "current_rrule": observed_host_rrule,
800
+ "status": (
801
+ "matches_recommended"
802
+ if current_rrule_already_applied
803
+ else "drift_detected"
804
+ ),
805
+ }
806
+ goal_id = self.payload.get("goal_id")
807
+ agent_id = self._identity_value("agent_identity.agent_id")
808
+ if apply_needed:
809
+ codex_app["recommended_rrule"] = current_rrule
810
+ if goal_id and agent_id:
811
+ codex_app["failure_hint"] = build_codex_app_scheduler_failure_hint(
812
+ goal_id=goal_id,
813
+ agent_id=agent_id,
814
+ failed_rrule=current_rrule,
815
+ observed_host_rrule=effective_host_rrule,
816
+ available_capabilities=self.scheduler_ack_capabilities,
817
+ )
818
+ codex_app["fallback_hint"] = build_codex_app_scheduler_fallback_hint(
819
+ goal_id=goal_id,
820
+ agent_id=agent_id,
821
+ automation_id=self.codex_app_automation_id,
822
+ )
823
+ if ack_needed and goal_id and agent_id:
824
+ codex_app["ack_hint"] = build_codex_app_scheduler_ack_hint(
825
+ goal_id=goal_id,
826
+ agent_id=agent_id,
827
+ applied_rrule=current_rrule,
828
+ reset_token=reset_token,
829
+ identity_signature=identity_signature,
830
+ available_capabilities=self.scheduler_ack_capabilities,
831
+ after=(
832
+ "automation_update_rrule_success"
833
+ if apply_needed
834
+ else "matching_host_rrule_observed"
835
+ ),
836
+ # Bind the host proof to the originating identity.
837
+ host_match_observed=True,
838
+ )
839
+ unchanged_poll_limits = {
840
+ "local_scheduler": cli_limit,
841
+ "codex_cli_tui": cli_limit,
842
+ "claude_code_loop": claude_limit,
843
+ }
844
+ unchanged_poll_after_limits = {
845
+ "local_scheduler": local_scheduler["after_limit"],
846
+ "codex_cli_tui": codex_cli_tui["after_limit"],
847
+ "claude_code_loop": claude_code_loop["after_limit"],
848
+ }
849
+ detail_contains = [
850
+ "local_scheduler",
851
+ "codex_cli_tui",
852
+ "claude_code_loop",
853
+ "final_quota_replan_check",
854
+ "reset_policy_detail",
855
+ "stateful_backoff_detail",
856
+ ]
857
+ if cli_limit is not None:
858
+ unchanged_poll_limits[CODEX_APP_SSH_GOAL_RUNTIME_KEY] = cli_limit
859
+ unchanged_poll_after_limits[CODEX_APP_SSH_GOAL_RUNTIME_KEY] = (
860
+ codex_app_ssh_goal["after_limit"]
861
+ )
862
+ detail_contains.insert(2, CODEX_APP_SSH_GOAL_RUNTIME_KEY)
863
+ scheduler_hint = {
864
+ "schema_version": SCHEDULER_HINT_SCHEMA_VERSION,
865
+ "source": "quota.should-run",
866
+ "action": action,
867
+ "cadence_class": cadence_class,
868
+ "reason_code": self.arbitration.reason_code,
869
+ "reason": reason,
870
+ "spend_policy": self.spend_policy,
871
+ "codex_app": codex_app,
872
+ "unchanged_poll": {
873
+ "limits": unchanged_poll_limits,
874
+ "after_limits": unchanged_poll_after_limits,
875
+ "final_quota_replan_check_enabled": final_replan_check["enabled"],
876
+ "final_quota_replan_check_action": (
877
+ final_replan_check["action"]
878
+ if final_replan_check["enabled"]
879
+ else None
880
+ ),
881
+ "spend_policy": final_replan_check["spend_policy"],
882
+ },
883
+ "unchanged_identity_keys": identity_keys,
884
+ "reset_policy": reset_policy,
885
+ "detail_ref": {
886
+ "schema_version": SCHEDULER_HINT_DETAIL_SCHEMA_VERSION,
887
+ "omitted_by_default": True,
888
+ "execution_required": False,
889
+ "request": "loopx quota should-run --include-detail scheduler",
890
+ "hot_path_runtime_fields": [
891
+ "codex_app",
892
+ "unchanged_poll",
893
+ "reset_policy",
894
+ ],
895
+ "contains": detail_contains,
896
+ },
897
+ }
898
+ notification_cooldown = _user_gate_notification_cooldown(
899
+ cadence_class=cadence_class,
900
+ host_failure_suppressed=host_failure_suppressed,
901
+ current_interval_minutes=current_interval,
902
+ effective_host_rrule=effective_host_rrule,
903
+ recorded_host_failure=recorded_host_failure,
904
+ )
905
+ if notification_cooldown:
906
+ scheduler_hint["user_gate_notification_cooldown"] = notification_cooldown
907
+ frontier_recheck = build_frontier_recheck_plan(
908
+ self.payload,
909
+ current_time=now_utc(),
910
+ )
911
+ if self.include_detail:
912
+ scheduler_hint["cold_path_detail"] = {
913
+ "schema_version": SCHEDULER_HINT_DETAIL_SCHEMA_VERSION,
914
+ "source": "quota.should-run",
915
+ "local_scheduler": local_scheduler,
916
+ "codex_cli_tui": codex_cli_tui,
917
+ CODEX_APP_SSH_GOAL_RUNTIME_KEY: codex_app_ssh_goal,
918
+ "claude_code_loop": claude_code_loop,
919
+ "final_quota_replan_check": final_replan_check,
920
+ "reset_policy_detail": reset_policy_detail,
921
+ "stateful_backoff_detail": stateful_backoff_detail,
922
+ }
923
+ if cadence_context_detail:
924
+ scheduler_hint["cold_path_detail"]["cadence_context"] = (
925
+ cadence_context_detail
926
+ )
927
+ if frontier_recheck:
928
+ scheduler_hint["cold_path_detail"]["frontier_recheck"] = (
929
+ frontier_recheck
930
+ )
931
+ return apply_scheduler_execution_context(
932
+ scheduler_hint,
933
+ self.execution_context,
934
+ frontier_recheck_after_seconds=(
935
+ frontier_recheck.get("frontier_recheck_after_seconds")
936
+ if frontier_recheck
937
+ else None
938
+ ),
939
+ )
940
+
941
+
942
+ def build_scheduler_hint(
943
+ payload: dict[str, Any],
944
+ *,
945
+ user_action_required: bool = False,
946
+ agent_scope_frontier_actions: Collection[str] = (),
947
+ include_detail: bool = False,
948
+ codex_app_scheduler_state: dict[str, Any] | None = None,
949
+ available_capabilities: Any = None,
950
+ codex_app_current_rrule: Any = None,
951
+ codex_app_automation_id: Any = None,
952
+ scheduler_execution_context: (
953
+ Mapping[str, Any] | SchedulerExecutionContextResolution | None
954
+ ) = None,
955
+ ) -> dict[str, Any]:
956
+ """Project host-runtime cadence/backoff policy from a quota decision.
957
+
958
+ This helper is intentionally pure: callers provide the few quota-local
959
+ classification facts it needs, and it returns the public scheduler contract
960
+ without reading files, mutating state, or depending on the full quota module.
961
+ """
962
+
963
+ execution_context = resolve_scheduler_execution_context(scheduler_execution_context)
964
+ if not execution_context.ok:
965
+ return {
966
+ "schema_version": SCHEDULER_HINT_SCHEMA_VERSION,
967
+ "source": "quota.should-run",
968
+ "action": "repair_scheduler_execution_context",
969
+ "cadence_class": "control_plane_repair",
970
+ "reason_code": "invalid_scheduler_execution_context",
971
+ "reason": (
972
+ "scheduler ownership is missing or contradictory; repair the "
973
+ "typed execution context before applying cadence"
974
+ ),
975
+ "spend_policy": "no quota spend for scheduler context repair",
976
+ "execution_context": execution_context.projection(),
977
+ "execution_phase": {
978
+ "schema_version": "scheduler_execution_phase_v0",
979
+ "disposition": "contract_error",
980
+ "completed": False,
981
+ "apply_needed": False,
982
+ "ack_needed": False,
983
+ "acknowledged": False,
984
+ },
985
+ "codex_app": {
986
+ "applicability": "blocked_invalid_context",
987
+ "apply": "none",
988
+ "host_action": "none",
989
+ "ack_required": False,
990
+ },
991
+ "unchanged_poll": {
992
+ "local_scheduler": "stop_until_context_repaired",
993
+ "codex_cli_tui": "stop_until_context_repaired",
994
+ CODEX_APP_SSH_GOAL_RUNTIME_KEY: "stop_until_context_repaired",
995
+ "claude_code_loop": "stop_until_context_repaired",
996
+ "final_quota_replan_check_enabled": False,
997
+ "spend_policy": "no quota spend for scheduler context repair",
998
+ },
999
+ "consistency_error": {
1000
+ "source": "scheduler_execution_context",
1001
+ "errors": list(execution_context.errors),
1002
+ },
1003
+ }
1004
+
1005
+ heartbeat_recommendation = _dict_or_empty(payload.get("heartbeat_recommendation"))
1006
+ if heartbeat_recommendation.get("recommended_mode") == "quota_paused":
1007
+ return apply_scheduler_execution_context(
1008
+ {
1009
+ "schema_version": SCHEDULER_HINT_SCHEMA_VERSION,
1010
+ "source": "quota.should-run",
1011
+ "action": "stop_until_explicit_resume",
1012
+ "cadence_class": "quota_paused",
1013
+ "reason_code": "quota_paused",
1014
+ "reason": (
1015
+ "Goal-level compute quota is paused; recurring host automation "
1016
+ "must stop until quota.compute is explicitly raised above 0"
1017
+ ),
1018
+ "spend_policy": "no quota spend for paused automation shutdown",
1019
+ "codex_app": {
1020
+ "apply": "pause_or_delete_current_heartbeat_if_possible",
1021
+ "host_tool": "automation_update",
1022
+ "host_action": "pause_or_delete_current_heartbeat",
1023
+ "host_action_required": True,
1024
+ "attempt_limit": 1,
1025
+ "verify_host_result": True,
1026
+ "ack_required": False,
1027
+ "resume_trigger": "explicit quota resume with quota.compute > 0",
1028
+ "no_spend_for_host_action": True,
1029
+ },
1030
+ "unchanged_poll": {
1031
+ "local_scheduler": "stop",
1032
+ "codex_cli_tui": "exit",
1033
+ CODEX_APP_SSH_GOAL_RUNTIME_KEY: "complete_host_goal",
1034
+ "claude_code_loop": "stop",
1035
+ "final_quota_replan_check_enabled": False,
1036
+ "spend_policy": "no quota spend while the Goal is paused",
1037
+ },
1038
+ "unchanged_identity_keys": list(
1039
+ _scheduler_identity_keys(
1040
+ cadence_class="quota_paused",
1041
+ execution_context=execution_context,
1042
+ )
1043
+ ),
1044
+ },
1045
+ execution_context,
1046
+ )
1047
+
1048
+ execution_obligation = _dict_or_empty(payload.get("execution_obligation"))
1049
+ automation_liveness = _dict_or_empty(payload.get("automation_liveness"))
1050
+ spend_policy = (
1051
+ automation_liveness.get("spend_policy")
1052
+ or execution_obligation.get("spend_policy")
1053
+ or heartbeat_recommendation.get("spend_policy")
1054
+ )
1055
+ capability_gate = _dict_or_empty(payload.get("capability_gate"))
1056
+ scheduler_ack_capabilities = (
1057
+ available_capabilities
1058
+ if available_capabilities is not None
1059
+ else capability_gate.get("available")
1060
+ if isinstance(capability_gate.get("available"), list)
1061
+ else []
1062
+ )
1063
+ agent_scope_action_set = {str(value) for value in agent_scope_frontier_actions}
1064
+ arbitration = build_scheduler_arbitration(
1065
+ payload,
1066
+ agent_scope_frontier_actions=agent_scope_action_set,
1067
+ )
1068
+
1069
+ if arbitration.disposition == SchedulerDisposition.TERMINAL_STOP:
1070
+ return _build_scheduler_stop_hint(
1071
+ execution_context=execution_context,
1072
+ action="stop_until_explicit_resume",
1073
+ cadence_class="terminal_no_followup",
1074
+ reason_code=arbitration.reason_code,
1075
+ reason=(
1076
+ "validated closure evidence derives no-follow-up and confirms no "
1077
+ "remaining frontier; recurring polling must stop until resume"
1078
+ ),
1079
+ spend_policy="no quota spend for terminal automation shutdown",
1080
+ resume_trigger="explicit goal resume or newly projected work",
1081
+ ssh_goal_runtime_action="complete_host_goal",
1082
+ unchanged_spend_policy="no quota spend for terminal loop stop",
1083
+ )
1084
+
1085
+ if arbitration.disposition == SchedulerDisposition.PEER_COORDINATION_STOP:
1086
+ cadence_class = "peer_coordination_blocked"
1087
+ return _build_scheduler_stop_hint(
1088
+ execution_context=execution_context,
1089
+ action="return_to_owner_until_material_change",
1090
+ cadence_class=cadence_class,
1091
+ reason_code=arbitration.reason_code,
1092
+ reason=(
1093
+ "explicit peer coordination has no executable peer lane or local "
1094
+ "fallback; recurring polling must stop until its inputs change"
1095
+ ),
1096
+ spend_policy=(
1097
+ "no quota spend while explicit peer coordination is blocked"
1098
+ ),
1099
+ resume_trigger=(
1100
+ "peer activation capability, peer runtime readiness, coordinator "
1101
+ "configuration, or newly projected local work"
1102
+ ),
1103
+ ssh_goal_runtime_action="return_to_owner",
1104
+ unchanged_spend_policy=(
1105
+ "no quota spend for blocked coordination stop"
1106
+ ),
1107
+ )
1108
+
1109
+ builder = _SchedulerHintBuilder(
1110
+ payload=payload,
1111
+ execution_context=execution_context,
1112
+ arbitration=arbitration,
1113
+ spend_policy=spend_policy,
1114
+ scheduler_ack_capabilities=scheduler_ack_capabilities,
1115
+ codex_app_scheduler_state=codex_app_scheduler_state,
1116
+ codex_app_current_rrule=codex_app_current_rrule,
1117
+ codex_app_automation_id=codex_app_automation_id,
1118
+ include_detail=include_detail,
1119
+ )
1120
+ if arbitration.disposition == SchedulerDisposition.AGENT_MONITOR_ONLY_WAIT:
1121
+ return builder.build(
1122
+ action="backoff_agent_monitor_only",
1123
+ cadence_class="agent_monitor_only",
1124
+ reason=(
1125
+ "agent monitor-only mode blocks advancement while a quiet poll keeps "
1126
+ "due monitors and verified direct replies responsive"
1127
+ ),
1128
+ codex_interval=15,
1129
+ codex_max=60,
1130
+ cli_limit=3,
1131
+ claude_limit=3,
1132
+ )
1133
+
1134
+ if arbitration.disposition == SchedulerDisposition.CONSISTENCY_REPAIR:
1135
+ result = builder.build(
1136
+ action="repair_interaction_contract_projection",
1137
+ cadence_class="control_plane_repair",
1138
+ reason=(
1139
+ "scheduler inputs disagree with the final interaction contract; "
1140
+ "repair the projection before applying delivery or wait cadence"
1141
+ ),
1142
+ codex_interval=3,
1143
+ codex_max=10,
1144
+ cli_limit=None,
1145
+ claude_limit=None,
1146
+ advance_same_identity=False,
1147
+ )
1148
+ result["consistency_error"] = arbitration.consistency_error()
1149
+ return result
1150
+
1151
+ if arbitration.disposition == SchedulerDisposition.HUMAN_GATE:
1152
+ return builder.build(
1153
+ action="backoff_waiting_for_user",
1154
+ cadence_class="human_gate",
1155
+ reason=(
1156
+ "user/controller action is the next unlock; surface the concrete "
1157
+ "gate once, then stop repeating the same quiet poll"
1158
+ ),
1159
+ codex_interval=30,
1160
+ codex_max=120,
1161
+ cli_limit=3,
1162
+ claude_limit=3,
1163
+ )
1164
+
1165
+ if arbitration.disposition == SchedulerDisposition.ACTIVE_WORK:
1166
+ interaction_contract = payload.get("interaction_contract")
1167
+ agent_channel = (
1168
+ interaction_contract.get("agent_channel")
1169
+ if isinstance(interaction_contract, Mapping)
1170
+ else None
1171
+ )
1172
+ capability_bridge_wait = (
1173
+ arbitration.mode == "capability_bridge_repair"
1174
+ and isinstance(agent_channel, Mapping)
1175
+ and agent_channel.get("delivery_allowed") is False
1176
+ )
1177
+ return builder.build(
1178
+ action="run_now",
1179
+ cadence_class="active_work",
1180
+ reason=(
1181
+ "the interaction contract requires an agent attempt; keep the active "
1182
+ "scheduler cadence until the turn validates or blocks"
1183
+ ),
1184
+ codex_interval=3,
1185
+ codex_max=10,
1186
+ cli_limit=None,
1187
+ claude_limit=None,
1188
+ advance_same_identity=capability_bridge_wait,
1189
+ )
1190
+
1191
+ if arbitration.disposition == SchedulerDisposition.UNCHANGED_WAIT:
1192
+ return builder.build(
1193
+ action="backoff_until_fresh_evidence",
1194
+ cadence_class="unchanged_noop",
1195
+ reason=(
1196
+ "the current mapped or post-handoff source is unchanged; do not "
1197
+ "keep a tight loop while waiting for fresh evidence or a concrete handoff"
1198
+ ),
1199
+ codex_interval=60,
1200
+ codex_max=240,
1201
+ cli_limit=3,
1202
+ claude_limit=3,
1203
+ )
1204
+
1205
+ if arbitration.disposition == SchedulerDisposition.AGENT_SCOPE_WAIT:
1206
+ return builder.build(
1207
+ action="backoff_until_reassigned",
1208
+ cadence_class="agent_scope_wait",
1209
+ reason=(
1210
+ "this registered agent has no in-scope advancement candidate; "
1211
+ "agent-to-agent handoffs may change quickly, so stay closer to "
1212
+ "the prior scheduler cadence while waiting for handoff owner "
1213
+ "progress, reassignment, or a current-agent todo"
1214
+ ),
1215
+ codex_interval=10,
1216
+ codex_max=60,
1217
+ cli_limit=3,
1218
+ claude_limit=3,
1219
+ cadence_progression_override=[10, 20, 30, 60],
1220
+ )
1221
+
1222
+ if arbitration.disposition == SchedulerDisposition.MONITOR_WAIT:
1223
+ monitor_plan = build_monitor_wait_cadence_plan(
1224
+ payload,
1225
+ current_time=now_utc(),
1226
+ )
1227
+ monitor_progression = (
1228
+ monitor_plan.get("progression_minutes")
1229
+ if isinstance(monitor_plan, dict)
1230
+ else None
1231
+ )
1232
+ monitor_initial_interval = (
1233
+ monitor_progression[0]
1234
+ if isinstance(monitor_progression, list) and monitor_progression
1235
+ else MONITOR_WAIT_HOST_FLOOR_MINUTES
1236
+ )
1237
+ monitor_reset_profile = (
1238
+ {
1239
+ "cadence_class": "monitor_wait",
1240
+ "codex_app_initial_interval_minutes": monitor_initial_interval,
1241
+ "codex_app_initial_rrule": rrule_for_minutes(monitor_initial_interval),
1242
+ "codex_app_max_interval_minutes": 60,
1243
+ "unchanged_poll_backoff_multiplier": 2,
1244
+ "local_scheduler_unchanged_poll_limit": 3,
1245
+ "claude_code_loop_unchanged_poll_limit": 3,
1246
+ **monitor_plan["reset_profile"],
1247
+ }
1248
+ if isinstance(monitor_plan, dict)
1249
+ and isinstance(monitor_plan.get("reset_profile"), dict)
1250
+ else None
1251
+ )
1252
+ return builder.build(
1253
+ action="backoff_until_material_transition",
1254
+ cadence_class="monitor_wait",
1255
+ reason=(
1256
+ "monitor-only quiet polls should remain alive but use a slower "
1257
+ "cadence until material evidence, a blocker, or replan obligation appears"
1258
+ ),
1259
+ codex_interval=monitor_initial_interval,
1260
+ codex_max=60,
1261
+ cli_limit=3,
1262
+ claude_limit=3,
1263
+ cadence_progression_override=(
1264
+ monitor_progression or MONITOR_WAIT_PROGRESSION_MINUTES
1265
+ ),
1266
+ reset_profile_snapshot_override=monitor_reset_profile,
1267
+ cadence_context_detail=monitor_plan,
1268
+ )
1269
+
1270
+ if arbitration.disposition == SchedulerDisposition.QUIET_WAIT:
1271
+ return builder.build(
1272
+ action="backoff_until_state_change",
1273
+ cadence_class="quiet_wait",
1274
+ reason=(
1275
+ "quota blocks delivery and no immediate user/monitor-specific path "
1276
+ "is projected; poll at a slower cadence until the status changes"
1277
+ ),
1278
+ codex_interval=30,
1279
+ codex_max=120,
1280
+ cli_limit=3,
1281
+ claude_limit=3,
1282
+ )
1283
+
1284
+ raise AssertionError(f"unhandled scheduler disposition: {arbitration.disposition}")