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,1276 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from copy import deepcopy
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+
9
+ BENCHMARK_CASE_ANALYSIS_CANDIDATE_REPORT_SCHEMA_VERSION = (
10
+ "benchmark_case_analysis_candidate_report_v0"
11
+ )
12
+ BENCHMARK_CASE_ANALYSIS_UPSERT_PROPOSAL_SCHEMA_VERSION = (
13
+ "benchmark_case_analysis_upsert_proposal_v0"
14
+ )
15
+ BENCHMARK_CASE_ANALYSIS_ACCEPTANCE_POLICY_SCHEMA_VERSION = (
16
+ "benchmark_case_analysis_acceptance_policy_v0"
17
+ )
18
+
19
+ NO_RUN_DECISIONS = {"", "no_runs_recorded"}
20
+ CASE_ANALYSIS_ACCEPTANCE_POLICIES = {"proposal-only", "generated-safe"}
21
+ GENERATED_SAFE_ACCEPTED_CLASSES = {
22
+ "paired_no_uplift_candidate": "generated_no_uplift_asset",
23
+ "baseline_solved_non_regression_candidate": (
24
+ "generated_baseline_solved_non_regression_asset"
25
+ ),
26
+ "baseline_solved_control_candidate": "generated_baseline_solved_control_asset",
27
+ }
28
+ CASE_ANALYSIS_DETAIL_START_HEADING = "## Treatment Policy Control Set"
29
+ CASE_ANALYSIS_CLASS_LABELS = {
30
+ "baseline_solved_non_regression_asset": (
31
+ "current-protocol baseline-solved / non-regression asset"
32
+ ),
33
+ "generated_baseline_solved_control_asset": (
34
+ "generated baseline-solved control asset"
35
+ ),
36
+ "generated_baseline_solved_non_regression_asset": (
37
+ "generated baseline-solved non-regression asset"
38
+ ),
39
+ "generated_no_uplift_asset": "generated no-uplift asset",
40
+ "no_uplift_asset": "no-uplift asset",
41
+ "positive_uplift_asset": "positive uplift asset",
42
+ "regression_asset": "regression asset",
43
+ "setup_blocker_asset": "setup blocker asset",
44
+ }
45
+ HARNESS_INTERACTION_COUNTER_FIELDS = (
46
+ "loopx_cli_call_count",
47
+ "worker_loopx_cli_call_total",
48
+ "loopx_prompt_driven_case_cli_call_count",
49
+ "loopx_case_scheduler_command_count",
50
+ "controller_action_decisions",
51
+ "followup_prompt_count",
52
+ "private_trajectory_tool_call_count",
53
+ "tool_call_count",
54
+ )
55
+ HARNESS_INTERACTION_BOOL_FIELDS = (
56
+ "loopx_inside_case",
57
+ "loopx_lifecycle_observed",
58
+ "loopx_trace_observed",
59
+ "loopx_prompt_driven_trace_present",
60
+ "loopx_prompt_driven_lifecycle_observed",
61
+ "loopx_controller_trace_present",
62
+ "loopx_controller_trace_public_safe",
63
+ "native_goal_mode_invoked",
64
+ "native_goal_worker_connected",
65
+ "private_trajectory_present",
66
+ )
67
+ HARNESS_INTERACTION_MAP_FIELDS = (
68
+ "loopx_case_rollout_event_counts",
69
+ "loopx_prompt_driven_event_counts",
70
+ "loopx_solution_phase_counters",
71
+ "trajectory_action_category_counts",
72
+ "loopx_cli_state_usage_counts",
73
+ )
74
+ HARNESS_PUBLIC_UNSAFE_FIELDS = (
75
+ "raw_text_copied_to_public",
76
+ "raw_task_text_copied_to_public",
77
+ "raw_verifier_output_copied_to_public",
78
+ "raw_logs_copied",
79
+ "raw_logs_read",
80
+ "raw_task_text_copied",
81
+ "raw_task_text_read",
82
+ "raw_verifier_output_copied",
83
+ "raw_verifier_output_read",
84
+ "raw_trajectory_copied",
85
+ "raw_trajectory_read",
86
+ "raw_agent_trajectory_recorded",
87
+ "raw_commands_recorded",
88
+ "raw_output_recorded",
89
+ "trajectory_copied",
90
+ "trajectory_read",
91
+ "host_path_recorded",
92
+ "local_paths_recorded",
93
+ )
94
+
95
+
96
+ def load_json(path: str | Path) -> dict[str, Any]:
97
+ return json.loads(Path(path).read_text(encoding="utf-8"))
98
+
99
+
100
+ def _compact_text(value: object, *, limit: int = 200) -> str:
101
+ text = str(value or "").strip()
102
+ text = " ".join(text.split())
103
+ if len(text) <= limit:
104
+ return text
105
+ return text[: limit - 1].rstrip() + "..."
106
+
107
+
108
+ def case_analysis_keys(analysis: dict[str, Any]) -> set[tuple[str, str]]:
109
+ keys: set[tuple[str, str]] = set()
110
+ cases = analysis.get("cases")
111
+ if isinstance(cases, list):
112
+ for case in cases:
113
+ if not isinstance(case, dict):
114
+ continue
115
+ benchmark_id = _compact_text(case.get("benchmark_id"), limit=160)
116
+ case_id = _compact_text(case.get("case_id"), limit=200)
117
+ if benchmark_id and case_id:
118
+ keys.add((benchmark_id, case_id))
119
+ coverage = analysis.get("terminal_bench_current_protocol_coverage")
120
+ if isinstance(coverage, dict) and isinstance(coverage.get("rows"), list):
121
+ for row in coverage["rows"]:
122
+ if not isinstance(row, dict):
123
+ continue
124
+ case_id = _compact_text(row.get("case_id"), limit=200)
125
+ if case_id:
126
+ keys.add(("terminal-bench@2.0", case_id))
127
+ return keys
128
+
129
+
130
+ def classify_case_analysis_candidate(
131
+ *,
132
+ latest_decision: str,
133
+ run_count: int,
134
+ ) -> dict[str, str]:
135
+ if latest_decision == "paired_no_score_uplift":
136
+ return {
137
+ "candidate_class": "paired_no_uplift_candidate",
138
+ "promotion_priority": "P1",
139
+ "recommended_handling": (
140
+ "promote when the no-uplift result changes routing, prompt, or "
141
+ "treatment policy"
142
+ ),
143
+ }
144
+ if latest_decision == "paired_baseline_solved_treatment_preserved":
145
+ return {
146
+ "candidate_class": "baseline_solved_non_regression_candidate",
147
+ "promotion_priority": "P2",
148
+ "recommended_handling": (
149
+ "promote selectively as a non-regression guard or keep in "
150
+ "generated coverage"
151
+ ),
152
+ }
153
+ if latest_decision.startswith("paired_treatment_") and (
154
+ "alignment_required" in latest_decision
155
+ or "preflight_required" in latest_decision
156
+ ):
157
+ return {
158
+ "candidate_class": "infrastructure_alignment_candidate",
159
+ "promotion_priority": "P1",
160
+ "recommended_handling": (
161
+ "promote only when the alignment or preflight lesson is reusable "
162
+ "across future runs"
163
+ ),
164
+ }
165
+ if latest_decision == "baseline_failed_treatment_candidate":
166
+ return {
167
+ "candidate_class": "baseline_failure_treatment_candidate",
168
+ "promotion_priority": "P1",
169
+ "recommended_handling": (
170
+ "add failure attribution or a matched treatment before making a "
171
+ "strong case-analysis claim"
172
+ ),
173
+ }
174
+ if "runner_or_setup" in latest_decision or "setup" in latest_decision:
175
+ return {
176
+ "candidate_class": "setup_or_runner_gap_defer",
177
+ "promotion_priority": "P2",
178
+ "recommended_handling": (
179
+ "defer until the compact run reaches scoring or the setup blocker "
180
+ "itself becomes a reusable infrastructure lesson"
181
+ ),
182
+ }
183
+ if latest_decision == "baseline_passed_not_current_treatment_priority":
184
+ return {
185
+ "candidate_class": "baseline_solved_control_candidate",
186
+ "promotion_priority": "P2",
187
+ "recommended_handling": (
188
+ "promote selectively as a baseline-solved control when the case "
189
+ "is needed for routing or coverage"
190
+ ),
191
+ }
192
+ if latest_decision == "single_arm_recorded":
193
+ priority = "P1" if run_count > 1 else "P2"
194
+ return {
195
+ "candidate_class": "single_arm_coverage_or_baseline_candidate",
196
+ "promotion_priority": priority,
197
+ "recommended_handling": (
198
+ "keep as coverage unless the single-arm result teaches a durable "
199
+ "routing or infrastructure lesson"
200
+ ),
201
+ }
202
+ return {
203
+ "candidate_class": "needs_manual_classification",
204
+ "promotion_priority": "P1",
205
+ "recommended_handling": (
206
+ "inspect compact ledger fields only and classify before editing "
207
+ "case-analysis"
208
+ ),
209
+ }
210
+
211
+
212
+ def _case_analysis_id(benchmark_id: str, case_id: str, candidate_class: str) -> str:
213
+ def slug(value: str) -> str:
214
+ text = "".join(ch if ch.isalnum() else "-" for ch in value.lower())
215
+ text = "-".join(part for part in text.split("-") if part)
216
+ return text or "unknown"
217
+
218
+ return f"{slug(benchmark_id)}__{slug(case_id)}__{slug(candidate_class)}"
219
+
220
+
221
+ def _proposal_classification(candidate_class: str) -> str:
222
+ mapping = {
223
+ "paired_no_uplift_candidate": "no_uplift_candidate_proposal",
224
+ "baseline_solved_non_regression_candidate": (
225
+ "baseline_solved_non_regression_candidate_proposal"
226
+ ),
227
+ "infrastructure_alignment_candidate": (
228
+ "infrastructure_alignment_candidate_proposal"
229
+ ),
230
+ "baseline_failure_treatment_candidate": (
231
+ "baseline_failure_treatment_candidate_proposal"
232
+ ),
233
+ "setup_or_runner_gap_defer": "setup_or_runner_gap_defer_proposal",
234
+ "baseline_solved_control_candidate": (
235
+ "baseline_solved_control_candidate_proposal"
236
+ ),
237
+ "single_arm_coverage_or_baseline_candidate": (
238
+ "single_arm_coverage_or_baseline_candidate_proposal"
239
+ ),
240
+ }
241
+ return mapping.get(candidate_class, "manual_classification_required_proposal")
242
+
243
+
244
+ def _normalize_acceptance_policy(acceptance_policy: str | None) -> str:
245
+ policy = _compact_text(acceptance_policy or "proposal-only", limit=80)
246
+ if policy not in CASE_ANALYSIS_ACCEPTANCE_POLICIES:
247
+ allowed = ", ".join(sorted(CASE_ANALYSIS_ACCEPTANCE_POLICIES))
248
+ raise ValueError(
249
+ f"unsupported case-analysis acceptance policy {policy!r}; "
250
+ f"expected one of: {allowed}"
251
+ )
252
+ return policy
253
+
254
+
255
+ def evaluate_case_analysis_acceptance(
256
+ candidate: dict[str, Any],
257
+ *,
258
+ acceptance_policy: str = "proposal-only",
259
+ ) -> dict[str, Any]:
260
+ policy = _normalize_acceptance_policy(acceptance_policy)
261
+ candidate_class = _compact_text(candidate.get("candidate_class"), limit=160)
262
+ latest_decision = _compact_text(candidate.get("latest_decision"), limit=160)
263
+ run_count = int(candidate.get("run_count") or 0)
264
+ accepted_classification = GENERATED_SAFE_ACCEPTED_CLASSES.get(candidate_class)
265
+ reason_codes: list[str] = []
266
+ if policy == "proposal-only":
267
+ return {
268
+ "schema_version": BENCHMARK_CASE_ANALYSIS_ACCEPTANCE_POLICY_SCHEMA_VERSION,
269
+ "policy": policy,
270
+ "accepted": False,
271
+ "status": "proposal_only_not_applied",
272
+ "accepted_classification": None,
273
+ "requires_manual_review": True,
274
+ "reason_codes": ["proposal_only_policy"],
275
+ }
276
+ if not accepted_classification:
277
+ reason_codes.append("candidate_class_requires_manual_review")
278
+ if candidate_class == "paired_no_uplift_candidate":
279
+ if latest_decision != "paired_no_score_uplift":
280
+ reason_codes.append("decision_not_paired_no_score_uplift")
281
+ if run_count < 2:
282
+ reason_codes.append("paired_candidate_needs_two_runs")
283
+ elif candidate_class == "baseline_solved_non_regression_candidate":
284
+ if latest_decision != "paired_baseline_solved_treatment_preserved":
285
+ reason_codes.append("decision_not_baseline_solved_treatment_preserved")
286
+ if run_count < 2:
287
+ reason_codes.append("paired_candidate_needs_two_runs")
288
+ elif candidate_class == "baseline_solved_control_candidate":
289
+ if latest_decision != "baseline_passed_not_current_treatment_priority":
290
+ reason_codes.append("decision_not_baseline_passed_control")
291
+ if run_count < 1:
292
+ reason_codes.append("control_candidate_needs_one_run")
293
+ accepted = bool(accepted_classification) and not reason_codes
294
+ return {
295
+ "schema_version": BENCHMARK_CASE_ANALYSIS_ACCEPTANCE_POLICY_SCHEMA_VERSION,
296
+ "policy": policy,
297
+ "accepted": accepted,
298
+ "status": (
299
+ "accepted_generated_not_applied"
300
+ if accepted
301
+ else "proposal_only_not_applied"
302
+ ),
303
+ "accepted_classification": accepted_classification if accepted else None,
304
+ "requires_manual_review": not accepted,
305
+ "reason_codes": reason_codes or ["generated_safe_policy_matched"],
306
+ }
307
+
308
+
309
+ def _proposal_capability_signal(candidate: dict[str, Any]) -> str:
310
+ candidate_class = _compact_text(candidate.get("candidate_class"), limit=120)
311
+ decision = _compact_text(candidate.get("latest_decision"), limit=120)
312
+ benchmark_id = _compact_text(candidate.get("benchmark_id"), limit=120)
313
+ case_id = _compact_text(candidate.get("case_id"), limit=160)
314
+ run_count = candidate.get("run_count", 0)
315
+ if candidate_class == "baseline_failure_treatment_candidate":
316
+ return (
317
+ f"{benchmark_id}/{case_id} has a compact baseline failure candidate "
318
+ f"({decision}) across {run_count} recorded run(s); promote only after "
319
+ "matched treatment or stronger compact attribution."
320
+ )
321
+ if candidate_class == "infrastructure_alignment_candidate":
322
+ return (
323
+ f"{benchmark_id}/{case_id} carries a compact infrastructure/alignment "
324
+ f"lesson ({decision}); promote if the setup or verifier-alignment "
325
+ "lesson applies beyond this single run."
326
+ )
327
+ if candidate_class == "paired_no_uplift_candidate":
328
+ return (
329
+ f"{benchmark_id}/{case_id} has compact paired no-uplift evidence "
330
+ f"({decision}); use it to adjust routing or treatment policy, not as "
331
+ "a positive uplift claim."
332
+ )
333
+ if candidate_class == "baseline_solved_control_candidate":
334
+ return (
335
+ f"{benchmark_id}/{case_id} is a compact baseline-solved control "
336
+ f"({decision}); promote selectively for coverage or routing balance."
337
+ )
338
+ return (
339
+ f"{benchmark_id}/{case_id} is a compact ledger-only candidate "
340
+ f"({decision}); review proposed classification before editing the case "
341
+ "analysis table."
342
+ )
343
+
344
+
345
+ def _proposal_control_plane_signal(candidate: dict[str, Any]) -> str:
346
+ handling = _compact_text(candidate.get("recommended_handling"), limit=220)
347
+ priority = _compact_text(candidate.get("promotion_priority"), limit=20)
348
+ return (
349
+ f"Generated as a {priority} proposal from compact ledger metadata only. "
350
+ f"Recommended handling: {handling}."
351
+ )
352
+
353
+
354
+ def proposed_case_analysis_record_from_candidate(
355
+ candidate: dict[str, Any],
356
+ *,
357
+ acceptance_policy: str = "proposal-only",
358
+ ) -> dict[str, Any]:
359
+ benchmark_id = _compact_text(candidate.get("benchmark_id"), limit=160)
360
+ case_id = _compact_text(candidate.get("case_id"), limit=200)
361
+ candidate_class = _compact_text(candidate.get("candidate_class"), limit=160)
362
+ recent_run_ids = [
363
+ _compact_text(run_id, limit=120)
364
+ for run_id in candidate.get("recent_run_ids", [])
365
+ if run_id
366
+ ]
367
+ acceptance = evaluate_case_analysis_acceptance(
368
+ candidate,
369
+ acceptance_policy=acceptance_policy,
370
+ )
371
+ accepted = bool(acceptance.get("accepted"))
372
+ record = {
373
+ "schema_version": BENCHMARK_CASE_ANALYSIS_UPSERT_PROPOSAL_SCHEMA_VERSION,
374
+ "proposal_status": _compact_text(acceptance.get("status"), limit=80),
375
+ "analysis_id": _case_analysis_id(benchmark_id, case_id, candidate_class),
376
+ "benchmark_id": benchmark_id,
377
+ "case_id": case_id,
378
+ "classification": (
379
+ _compact_text(acceptance.get("accepted_classification"), limit=160)
380
+ if accepted
381
+ else _proposal_classification(candidate_class)
382
+ ),
383
+ "latest_ledger_decision": _compact_text(
384
+ candidate.get("latest_decision"), limit=160
385
+ ),
386
+ "candidate_class": candidate_class,
387
+ "promotion_priority": _compact_text(
388
+ candidate.get("promotion_priority"), limit=20
389
+ ),
390
+ "source_run_ids": recent_run_ids,
391
+ "source_run_count": int(candidate.get("run_count") or 0),
392
+ "capability_signal": _proposal_capability_signal(candidate),
393
+ "control_plane_signal": _proposal_control_plane_signal(candidate),
394
+ "recommended_next_action": _compact_text(
395
+ candidate.get("recommended_handling"), limit=260
396
+ ),
397
+ "acceptance_policy": acceptance,
398
+ "source_boundary": {
399
+ "inputs": [
400
+ "compact benchmark-run-ledger candidate",
401
+ "benchmark-case-analysis existing keys",
402
+ ],
403
+ "raw_logs_recorded": False,
404
+ "raw_task_text_recorded": False,
405
+ "trajectory_recorded": False,
406
+ "absolute_paths_recorded": False,
407
+ "proposal_only": not accepted,
408
+ "accepted_generated_case_analysis": accepted,
409
+ },
410
+ }
411
+ return record
412
+
413
+
414
+ def build_case_analysis_upsert_proposals(
415
+ *,
416
+ ledger: dict[str, Any],
417
+ analysis: dict[str, Any],
418
+ limit: int | None = None,
419
+ acceptance_policy: str = "proposal-only",
420
+ ) -> list[dict[str, Any]]:
421
+ policy = _normalize_acceptance_policy(acceptance_policy)
422
+ candidates = find_case_analysis_candidates(ledger=ledger, analysis=analysis)
423
+ proposals = [
424
+ proposed_case_analysis_record_from_candidate(
425
+ candidate,
426
+ acceptance_policy=policy,
427
+ )
428
+ for candidate in candidates
429
+ ]
430
+ if limit is not None:
431
+ return proposals[: max(0, limit)]
432
+ return proposals
433
+
434
+
435
+ def case_analysis_record_from_accepted_upsert(
436
+ record: dict[str, Any],
437
+ ) -> dict[str, Any]:
438
+ if record.get("proposal_status") != "accepted_generated_not_applied":
439
+ raise ValueError("only accepted_generated_not_applied records can be applied")
440
+ boundary = (
441
+ record.get("source_boundary")
442
+ if isinstance(record.get("source_boundary"), dict)
443
+ else {}
444
+ )
445
+ return {
446
+ "analysis_id": _compact_text(record.get("analysis_id"), limit=260),
447
+ "benchmark_id": _compact_text(record.get("benchmark_id"), limit=160),
448
+ "case_id": _compact_text(record.get("case_id"), limit=200),
449
+ "classification": _compact_text(record.get("classification"), limit=160),
450
+ "decision": _compact_text(record.get("latest_ledger_decision"), limit=160),
451
+ "evidence_status": "generated_from_compact_benchmark_run_ledger",
452
+ "source_run_ids": [
453
+ _compact_text(run_id, limit=120)
454
+ for run_id in record.get("source_run_ids", [])
455
+ if run_id
456
+ ],
457
+ "source_run_count": int(record.get("source_run_count") or 0),
458
+ "capability_signal": _compact_text(
459
+ record.get("capability_signal"),
460
+ limit=320,
461
+ ),
462
+ "control_plane_signal": _compact_text(
463
+ record.get("control_plane_signal"),
464
+ limit=320,
465
+ ),
466
+ "routing_guidance": {
467
+ "repeat_policy": _compact_text(
468
+ record.get("recommended_next_action"),
469
+ limit=260,
470
+ )
471
+ },
472
+ "acceptance_policy": record.get("acceptance_policy"),
473
+ "source_boundary": {
474
+ "inputs": [
475
+ "compact benchmark-run-ledger candidate",
476
+ "benchmark-case-analysis existing keys",
477
+ ],
478
+ "raw_logs_recorded": bool(boundary.get("raw_logs_recorded", False)),
479
+ "raw_task_text_recorded": bool(
480
+ boundary.get("raw_task_text_recorded", False)
481
+ ),
482
+ "trajectory_recorded": bool(boundary.get("trajectory_recorded", False)),
483
+ "absolute_paths_recorded": bool(
484
+ boundary.get("absolute_paths_recorded", False)
485
+ ),
486
+ "generated_case_analysis": True,
487
+ },
488
+ }
489
+
490
+
491
+ def apply_accepted_case_analysis_records(
492
+ *,
493
+ analysis: dict[str, Any],
494
+ records: list[dict[str, Any]],
495
+ ) -> dict[str, Any]:
496
+ updated = deepcopy(analysis)
497
+ cases = updated.setdefault("cases", [])
498
+ if not isinstance(cases, list):
499
+ raise ValueError("case-analysis payload must contain a cases list")
500
+ existing = case_analysis_keys(updated)
501
+ added_records: list[dict[str, Any]] = []
502
+ skipped_records: list[dict[str, Any]] = []
503
+ for record in records:
504
+ if not isinstance(record, dict):
505
+ continue
506
+ key = (
507
+ _compact_text(record.get("benchmark_id"), limit=160),
508
+ _compact_text(record.get("case_id"), limit=200),
509
+ )
510
+ if record.get("proposal_status") != "accepted_generated_not_applied":
511
+ skipped_records.append(
512
+ {
513
+ "benchmark_id": key[0],
514
+ "case_id": key[1],
515
+ "reason": "not_accepted_by_policy",
516
+ }
517
+ )
518
+ continue
519
+ if not key[0] or not key[1] or key in existing:
520
+ skipped_records.append(
521
+ {
522
+ "benchmark_id": key[0],
523
+ "case_id": key[1],
524
+ "reason": "already_present_or_invalid_key",
525
+ }
526
+ )
527
+ continue
528
+ case_record = case_analysis_record_from_accepted_upsert(record)
529
+ cases.append(case_record)
530
+ existing.add(key)
531
+ added_records.append(case_record)
532
+ return {
533
+ "analysis": updated,
534
+ "added_count": len(added_records),
535
+ "skipped_count": len(skipped_records),
536
+ "added_records": added_records,
537
+ "skipped_records": skipped_records,
538
+ }
539
+
540
+
541
+ def _case_analysis_class_label(case: dict[str, Any]) -> str:
542
+ classification = _compact_text(case.get("classification"), limit=180)
543
+ if not classification:
544
+ return "case-analysis asset"
545
+ if classification in CASE_ANALYSIS_CLASS_LABELS:
546
+ return CASE_ANALYSIS_CLASS_LABELS[classification]
547
+ return classification.replace("_", " ")
548
+
549
+
550
+ def _case_analysis_score_triplet(case: dict[str, Any]) -> tuple[object, object, object]:
551
+ scores = case.get("scores") if isinstance(case.get("scores"), dict) else {}
552
+ baseline = scores.get("baseline_official_score")
553
+ treatment = scores.get("treatment_official_score")
554
+ delta = scores.get("official_score_delta")
555
+ decision = _compact_text(case.get("decision"), limit=180)
556
+ classification = _compact_text(case.get("classification"), limit=180)
557
+ if baseline is None and treatment is None and delta is None:
558
+ if decision == "paired_no_score_uplift":
559
+ return 0.0, 0.0, 0.0
560
+ if decision == "baseline_passed_not_current_treatment_priority":
561
+ return 1.0, None, None
562
+ if "setup" in classification or "runner" in decision:
563
+ return "missing", None, None
564
+ return baseline, treatment, delta
565
+
566
+
567
+ def _markdown_table_value(value: object) -> str:
568
+ if value is None or value == "":
569
+ return "n/a"
570
+ text = _compact_text(value, limit=120)
571
+ return f"`{text}`"
572
+
573
+
574
+ def _markdown_escape_cell(value: object) -> str:
575
+ return _compact_text(value, limit=240).replace("|", "\\|")
576
+
577
+
578
+ def _markdown_escape_scalar(value: object) -> str:
579
+ if value is None:
580
+ return ""
581
+ return _markdown_escape_cell(str(value))
582
+
583
+
584
+ def _render_case_analysis_summary_table(analysis: dict[str, Any]) -> list[str]:
585
+ lines = [
586
+ "| Benchmark | Case | Class | Baseline | Treatment | Delta | Decision |",
587
+ "| --- | --- | --- | --- | --- | --- | --- |",
588
+ ]
589
+ cases = analysis.get("cases")
590
+ if not isinstance(cases, list):
591
+ return lines
592
+ for case in cases:
593
+ if not isinstance(case, dict):
594
+ continue
595
+ baseline, treatment, delta = _case_analysis_score_triplet(case)
596
+ lines.append(
597
+ "| "
598
+ f"`{_markdown_escape_cell(case.get('benchmark_id'))}` | "
599
+ f"`{_markdown_escape_cell(case.get('case_id'))}` | "
600
+ f"{_markdown_escape_cell(_case_analysis_class_label(case))} | "
601
+ f"{_markdown_table_value(baseline)} | "
602
+ f"{_markdown_table_value(treatment)} | "
603
+ f"{_markdown_table_value(delta)} | "
604
+ f"`{_markdown_escape_cell(case.get('decision'))}` |"
605
+ )
606
+ return lines
607
+
608
+
609
+ def _render_terminal_bench_current_protocol_coverage(
610
+ analysis: dict[str, Any],
611
+ ) -> list[str]:
612
+ coverage = analysis.get("terminal_bench_current_protocol_coverage")
613
+ if not isinstance(coverage, dict):
614
+ return []
615
+ rows = coverage.get("rows")
616
+ if not isinstance(rows, list):
617
+ return []
618
+ lines = [
619
+ "## Terminal-Bench Current-Protocol Coverage",
620
+ "",
621
+ "These rows are generated from the latest compact ledger decisions. They are",
622
+ "current-protocol success-preservation guards: both baseline and treatment",
623
+ "score `1.0`, so none of them should be counted as current uplift.",
624
+ "",
625
+ "| Case | Baseline | Treatment | Delta | Role | Case Analysis Status |",
626
+ "| --- | --- | --- | --- | --- | --- |",
627
+ ]
628
+ for row in rows:
629
+ if not isinstance(row, dict):
630
+ continue
631
+ baseline = row.get("baseline_official_score")
632
+ treatment = row.get("treatment_official_score")
633
+ delta = row.get("official_score_delta")
634
+ baseline_run = _compact_text(row.get("baseline_run_id"), limit=40)
635
+ treatment_run = _compact_text(row.get("treatment_run_id"), limit=40)
636
+ lines.append(
637
+ "| "
638
+ f"`{_markdown_escape_cell(row.get('case_id'))}` | "
639
+ f"`{baseline}` (`{baseline_run}`) | "
640
+ f"`{treatment}` (`{treatment_run}`) | "
641
+ f"`{delta}` | "
642
+ f"`{_markdown_escape_cell(row.get('main_table_role'))}` | "
643
+ f"`{_markdown_escape_cell(row.get('case_analysis_status'))}` |"
644
+ )
645
+ return lines
646
+
647
+
648
+ def _iter_public_trajectory_summaries(
649
+ value: object,
650
+ *,
651
+ path: str = "",
652
+ ) -> list[tuple[str, dict[str, Any]]]:
653
+ summaries: list[tuple[str, dict[str, Any]]] = []
654
+ if isinstance(value, dict):
655
+ for key, child in value.items():
656
+ child_path = f"{path}.{key}" if path else str(key)
657
+ if key == "trajectory_public_summary" and isinstance(child, dict):
658
+ summaries.append((child_path, child))
659
+ continue
660
+ summaries.extend(
661
+ _iter_public_trajectory_summaries(child, path=child_path)
662
+ )
663
+ elif isinstance(value, list):
664
+ for index, child in enumerate(value):
665
+ child_path = f"{path}[{index}]" if path else f"[{index}]"
666
+ summaries.extend(
667
+ _iter_public_trajectory_summaries(child, path=child_path)
668
+ )
669
+ return summaries
670
+
671
+
672
+ def _first_int_field(value: dict[str, Any], *keys: str) -> int:
673
+ for key in keys:
674
+ candidate = value.get(key)
675
+ if isinstance(candidate, int) and not isinstance(candidate, bool):
676
+ return candidate
677
+ return 0
678
+
679
+
680
+ def _sum_public_count_map(value: Any) -> int:
681
+ if isinstance(value, dict):
682
+ total = 0
683
+ for child in value.values():
684
+ if isinstance(child, int) and not isinstance(child, bool):
685
+ total += child
686
+ elif isinstance(child, dict):
687
+ total += _sum_public_count_map(child)
688
+ return total
689
+ return 0
690
+
691
+
692
+ def _harness_summary_is_public_safe(summary: dict[str, Any]) -> bool:
693
+ return not any(bool(summary.get(field)) for field in HARNESS_PUBLIC_UNSAFE_FIELDS)
694
+
695
+
696
+ def _harness_summary_kind(path: str, summary: dict[str, Any]) -> str:
697
+ if path.endswith("trajectory_public_summary"):
698
+ return "trajectory_public_summary"
699
+ if "native_goal_route_observations" in path:
700
+ return "native_goal_route_observation"
701
+ if ".arms." in f".{path}.":
702
+ return "case_arm"
703
+ if "product_mode" in path:
704
+ return "product_mode_attribution"
705
+ if summary.get("loopx_case_rollout_event_counts"):
706
+ return "case_rollout_trace"
707
+ if summary.get("loopx_prompt_driven_event_counts"):
708
+ return "prompt_driven_trace"
709
+ return "compact_harness_interaction"
710
+
711
+
712
+ def _contains_harness_interaction_summary(summary: dict[str, Any]) -> bool:
713
+ return any(
714
+ key in summary
715
+ for key in (
716
+ *HARNESS_INTERACTION_COUNTER_FIELDS,
717
+ *HARNESS_INTERACTION_BOOL_FIELDS,
718
+ *HARNESS_INTERACTION_MAP_FIELDS,
719
+ )
720
+ )
721
+
722
+
723
+ def _iter_harness_interaction_summaries(
724
+ value: object,
725
+ *,
726
+ path: str = "",
727
+ ) -> list[tuple[str, dict[str, Any]]]:
728
+ summaries: list[tuple[str, dict[str, Any]]] = []
729
+ if isinstance(value, dict):
730
+ if _contains_harness_interaction_summary(value):
731
+ summaries.append((path or "$", value))
732
+ for key, child in value.items():
733
+ child_path = f"{path}.{key}" if path else str(key)
734
+ summaries.extend(
735
+ _iter_harness_interaction_summaries(child, path=child_path)
736
+ )
737
+ elif isinstance(value, list):
738
+ for index, child in enumerate(value):
739
+ child_path = f"{path}[{index}]" if path else f"[{index}]"
740
+ summaries.extend(
741
+ _iter_harness_interaction_summaries(child, path=child_path)
742
+ )
743
+ return summaries
744
+
745
+
746
+ def _trajectory_summary_is_public_safe(summary: dict[str, Any]) -> bool:
747
+ return not any(
748
+ bool(summary.get(field))
749
+ for field in (
750
+ "raw_text_copied_to_public",
751
+ "raw_task_text_copied_to_public",
752
+ "raw_verifier_output_copied_to_public",
753
+ "host_path_recorded",
754
+ )
755
+ )
756
+
757
+
758
+ def trajectory_public_summary_coverage(analysis: dict[str, Any]) -> dict[str, Any]:
759
+ """Return public-safe coverage rows for backfilled trajectory summaries."""
760
+
761
+ rows: list[dict[str, Any]] = []
762
+ cases = analysis.get("cases")
763
+ if not isinstance(cases, list):
764
+ cases = []
765
+ for case in cases:
766
+ if not isinstance(case, dict):
767
+ continue
768
+ benchmark_id = _compact_text(case.get("benchmark_id"), limit=160)
769
+ case_id = _compact_text(case.get("case_id"), limit=200)
770
+ classification = _compact_text(case.get("classification"), limit=180)
771
+ for summary_path, summary in _iter_public_trajectory_summaries(case):
772
+ rows.append(
773
+ {
774
+ "benchmark_id": benchmark_id,
775
+ "case_id": case_id,
776
+ "classification": classification,
777
+ "summary_path": _compact_text(summary_path, limit=200),
778
+ "schema_version": _compact_text(
779
+ summary.get("schema_version"),
780
+ limit=120,
781
+ ),
782
+ "round_count": summary.get("round_count", 0),
783
+ "tool_call_count": summary.get("tool_call_count", 0),
784
+ "loopx_cli_call_count": summary.get("loopx_cli_call_count", 0),
785
+ "loopx_cli_state_usage_counts": summary.get(
786
+ "loopx_cli_state_usage_counts",
787
+ {},
788
+ ),
789
+ "protected_path_edit_signal_count": summary.get(
790
+ "protected_path_edit_signal_count",
791
+ 0,
792
+ ),
793
+ "attribution_conclusion_present": bool(
794
+ summary.get("attribution_conclusion")
795
+ ),
796
+ "private_trajectory_present": bool(
797
+ summary.get("private_trajectory_present")
798
+ ),
799
+ "public_safe": _trajectory_summary_is_public_safe(summary),
800
+ }
801
+ )
802
+ rows.sort(
803
+ key=lambda row: (
804
+ str(row.get("benchmark_id")),
805
+ str(row.get("case_id")),
806
+ str(row.get("summary_path")),
807
+ )
808
+ )
809
+ public_safe_count = sum(1 for row in rows if row.get("public_safe"))
810
+ attribution_count = sum(
811
+ 1 for row in rows if row.get("attribution_conclusion_present")
812
+ )
813
+ return {
814
+ "schema_version": "trajectory_public_summary_coverage_v0",
815
+ "summary_count": len(rows),
816
+ "public_safe_count": public_safe_count,
817
+ "attribution_conclusion_count": attribution_count,
818
+ "raw_trajectory_recorded": False,
819
+ "rows": rows,
820
+ }
821
+
822
+
823
+ def harness_interaction_public_summary_coverage(
824
+ analysis: dict[str, Any],
825
+ ) -> dict[str, Any]:
826
+ """Return generic public-safe harness interaction coverage rows.
827
+
828
+ This intentionally consumes only compact case-analysis fields. It does not
829
+ read raw trajectories, verifier output, task text, logs, or local paths.
830
+ """
831
+
832
+ rows: list[dict[str, Any]] = []
833
+ cases = analysis.get("cases")
834
+ if not isinstance(cases, list):
835
+ cases = []
836
+ for case in cases:
837
+ if not isinstance(case, dict):
838
+ continue
839
+ benchmark_id = _compact_text(case.get("benchmark_id"), limit=160)
840
+ case_id = _compact_text(case.get("case_id"), limit=200)
841
+ classification = _compact_text(case.get("classification"), limit=180)
842
+ for summary_path, summary in _iter_harness_interaction_summaries(case):
843
+ event_count = sum(
844
+ _sum_public_count_map(summary.get(field))
845
+ for field in HARNESS_INTERACTION_MAP_FIELDS
846
+ )
847
+ rows.append(
848
+ {
849
+ "benchmark_id": benchmark_id,
850
+ "case_id": case_id,
851
+ "classification": classification,
852
+ "summary_path": _compact_text(summary_path, limit=220),
853
+ "source_kind": _harness_summary_kind(summary_path, summary),
854
+ "arm_id": _compact_text(summary.get("arm_id"), limit=160),
855
+ "loopx_cli_call_count": _first_int_field(
856
+ summary,
857
+ "loopx_cli_call_count",
858
+ "worker_loopx_cli_call_total",
859
+ "loopx_prompt_driven_case_cli_call_count",
860
+ ),
861
+ "round_count": _first_int_field(
862
+ summary,
863
+ "round_count",
864
+ "private_trajectory_round_count",
865
+ "max_round_observed",
866
+ ),
867
+ "tool_call_count": _first_int_field(
868
+ summary,
869
+ "tool_call_count",
870
+ "private_trajectory_tool_call_count",
871
+ ),
872
+ "event_count": event_count,
873
+ "controller_trace_present": bool(
874
+ summary.get("loopx_controller_trace_present")
875
+ ),
876
+ "lifecycle_observed": bool(
877
+ summary.get("loopx_lifecycle_observed")
878
+ or summary.get("loopx_prompt_driven_lifecycle_observed")
879
+ ),
880
+ "private_trajectory_present": bool(
881
+ summary.get("private_trajectory_present")
882
+ ),
883
+ "public_safe": _harness_summary_is_public_safe(summary),
884
+ }
885
+ )
886
+ rows.sort(
887
+ key=lambda row: (
888
+ str(row.get("benchmark_id")),
889
+ str(row.get("case_id")),
890
+ str(row.get("summary_path")),
891
+ )
892
+ )
893
+ benchmark_ids = sorted(
894
+ {
895
+ str(row.get("benchmark_id"))
896
+ for row in rows
897
+ if row.get("benchmark_id")
898
+ }
899
+ )
900
+ public_safe_count = sum(1 for row in rows if row.get("public_safe"))
901
+ return {
902
+ "schema_version": "harness_interaction_public_summary_coverage_v0",
903
+ "summary_count": len(rows),
904
+ "public_safe_count": public_safe_count,
905
+ "benchmark_ids": benchmark_ids,
906
+ "raw_trajectory_recorded": False,
907
+ "raw_task_text_recorded": False,
908
+ "raw_verifier_output_recorded": False,
909
+ "raw_logs_recorded": False,
910
+ "rows": rows,
911
+ }
912
+
913
+
914
+ def _render_public_trajectory_summary_coverage(
915
+ analysis: dict[str, Any],
916
+ ) -> list[str]:
917
+ coverage = trajectory_public_summary_coverage(analysis)
918
+ rows = coverage.get("rows")
919
+ if not isinstance(rows, list) or not rows:
920
+ return []
921
+ lines = [
922
+ "## Public Trajectory Summary Coverage",
923
+ "",
924
+ "These rows are generated from `trajectory_public_summary` blocks already",
925
+ "backfilled into `benchmark-case-analysis.json`. They expose only compact",
926
+ "public counters; absence from this table means the durable case record does",
927
+ "not yet contain a public trajectory summary.",
928
+ "",
929
+ "- schema_version: "
930
+ f"`{coverage.get('schema_version')}`",
931
+ "- summary_count: "
932
+ f"`{coverage.get('summary_count', 0)}`",
933
+ "- attribution_conclusion_count: "
934
+ f"`{coverage.get('attribution_conclusion_count', 0)}`",
935
+ "",
936
+ "| Benchmark | Case | Summary | Rounds | Tools | LoopX CLI | Protected Edits | Attribution |",
937
+ "| --- | --- | --- | --- | --- | --- | --- | --- |",
938
+ ]
939
+ for row in rows:
940
+ if not isinstance(row, dict):
941
+ continue
942
+ attribution = "yes" if row.get("attribution_conclusion_present") else "no"
943
+ public_safe = "public-safe" if row.get("public_safe") else "unsafe"
944
+ lines.append(
945
+ "| "
946
+ f"`{_markdown_escape_cell(row.get('benchmark_id'))}` | "
947
+ f"`{_markdown_escape_cell(row.get('case_id'))}` | "
948
+ f"`{_markdown_escape_cell(row.get('summary_path'))}` "
949
+ f"({public_safe}) | "
950
+ f"`{_markdown_escape_scalar(row.get('round_count'))}` | "
951
+ f"`{_markdown_escape_scalar(row.get('tool_call_count'))}` | "
952
+ f"`{_markdown_escape_scalar(row.get('loopx_cli_call_count'))}` | "
953
+ f"`{_markdown_escape_scalar(row.get('protected_path_edit_signal_count'))}` | "
954
+ f"`{attribution}` |"
955
+ )
956
+ return lines
957
+
958
+
959
+ def _render_harness_interaction_public_summary_coverage(
960
+ analysis: dict[str, Any],
961
+ ) -> list[str]:
962
+ coverage = harness_interaction_public_summary_coverage(analysis)
963
+ rows = coverage.get("rows")
964
+ if not isinstance(rows, list) or not rows:
965
+ return []
966
+ lines = [
967
+ "## Public Harness Interaction Coverage",
968
+ "",
969
+ "These rows are generated from compact case-analysis counters across",
970
+ "benchmarks. They combine SkillsBench trajectory summaries, Terminal-Bench",
971
+ "worker/LoopX counters, SWE-Marathon product-path counters, and any future",
972
+ "benchmark case records that expose the same public fields. They do not read",
973
+ "or copy raw trajectories, task text, verifier output, logs, or local paths.",
974
+ "",
975
+ "- schema_version: "
976
+ f"`{coverage.get('schema_version')}`",
977
+ "- summary_count: "
978
+ f"`{coverage.get('summary_count', 0)}`",
979
+ "- benchmark_ids: "
980
+ f"`{', '.join(coverage.get('benchmark_ids') or [])}`",
981
+ "",
982
+ "| Benchmark | Case | Source | Kind | LoopX CLI | Rounds | Tools | Events | Controller Trace | Lifecycle |",
983
+ "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |",
984
+ ]
985
+ for row in rows:
986
+ if not isinstance(row, dict):
987
+ continue
988
+ public_safe = "public-safe" if row.get("public_safe") else "unsafe"
989
+ controller_trace = "yes" if row.get("controller_trace_present") else "no"
990
+ lifecycle = "yes" if row.get("lifecycle_observed") else "no"
991
+ lines.append(
992
+ "| "
993
+ f"`{_markdown_escape_cell(row.get('benchmark_id'))}` | "
994
+ f"`{_markdown_escape_cell(row.get('case_id'))}` | "
995
+ f"`{_markdown_escape_cell(row.get('summary_path'))}` "
996
+ f"({public_safe}) | "
997
+ f"`{_markdown_escape_cell(row.get('source_kind'))}` | "
998
+ f"`{_markdown_escape_scalar(row.get('loopx_cli_call_count'))}` | "
999
+ f"`{_markdown_escape_scalar(row.get('round_count'))}` | "
1000
+ f"`{_markdown_escape_scalar(row.get('tool_call_count'))}` | "
1001
+ f"`{_markdown_escape_scalar(row.get('event_count'))}` | "
1002
+ f"`{controller_trace}` | "
1003
+ f"`{lifecycle}` |"
1004
+ )
1005
+ return lines
1006
+
1007
+
1008
+ def _preserved_case_analysis_detail(existing_markdown: str | None) -> str:
1009
+ if not existing_markdown:
1010
+ return (
1011
+ "## Boundary\n\n"
1012
+ "This file records only compact public-safe evidence. It does not copy "
1013
+ "raw logs, task prompts, trajectories, credentials, hidden tests, "
1014
+ "uploads, or absolute local paths.\n"
1015
+ )
1016
+ marker = f"\n{CASE_ANALYSIS_DETAIL_START_HEADING}"
1017
+ start = existing_markdown.find(marker)
1018
+ if start >= 0:
1019
+ return existing_markdown[start + 1 :].strip() + "\n"
1020
+ if existing_markdown.startswith(CASE_ANALYSIS_DETAIL_START_HEADING):
1021
+ return existing_markdown.strip() + "\n"
1022
+ return (
1023
+ "## Boundary\n\n"
1024
+ "This file records only compact public-safe evidence. It does not copy "
1025
+ "raw logs, task prompts, trajectories, credentials, hidden tests, "
1026
+ "uploads, or absolute local paths.\n"
1027
+ )
1028
+
1029
+
1030
+ def render_case_analysis_markdown(
1031
+ analysis: dict[str, Any],
1032
+ *,
1033
+ existing_markdown: str | None = None,
1034
+ ) -> str:
1035
+ """Render the generated case-analysis summary while preserving deep notes."""
1036
+ cases = analysis.get("cases")
1037
+ case_count = len(cases) if isinstance(cases, list) else 0
1038
+ generated_count = (
1039
+ sum(
1040
+ 1
1041
+ for case in cases
1042
+ if isinstance(case, dict)
1043
+ and _compact_text(case.get("classification"), limit=180).startswith(
1044
+ "generated_"
1045
+ )
1046
+ )
1047
+ if isinstance(cases, list)
1048
+ else 0
1049
+ )
1050
+ lines = [
1051
+ "# Benchmark Case Analysis",
1052
+ "",
1053
+ "This file is the human view of `benchmark_case_analysis_v0`. It records durable",
1054
+ "case lessons that should guide benchmark routing, treatment design, and claims.",
1055
+ "",
1056
+ "It is intentionally separate from `benchmark-run-ledger.md`. The run ledger",
1057
+ "records compact attempts and scores; this file records why a result matters.",
1058
+ "",
1059
+ f"- schema_version: `{analysis.get('schema_version')}`",
1060
+ f"- updated_at: `{analysis.get('updated_at')}`",
1061
+ "- machine_source: `benchmark-case-analysis.json`",
1062
+ "- ledger-only migration audit:",
1063
+ " `benchmark-case-analysis-ledger-only-migration-audit-20260618.md`",
1064
+ "",
1065
+ "## Summary",
1066
+ "",
1067
+ "The table below is generated from compact public case-analysis JSON. It uses",
1068
+ "`n/a` when the compact record does not establish a comparable paired arm,",
1069
+ "and it preserves detailed hand-authored case notes below the generated",
1070
+ "summary sections.",
1071
+ "",
1072
+ f"- case_count: `{case_count}`",
1073
+ f"- generated_compact_record_count: `{generated_count}`",
1074
+ "",
1075
+ ]
1076
+ lines.extend(_render_case_analysis_summary_table(analysis))
1077
+ trajectory_coverage_lines = _render_public_trajectory_summary_coverage(analysis)
1078
+ if trajectory_coverage_lines:
1079
+ lines.extend(["", *trajectory_coverage_lines])
1080
+ harness_coverage_lines = _render_harness_interaction_public_summary_coverage(
1081
+ analysis
1082
+ )
1083
+ if harness_coverage_lines:
1084
+ lines.extend(["", *harness_coverage_lines])
1085
+ coverage_lines = _render_terminal_bench_current_protocol_coverage(analysis)
1086
+ if coverage_lines:
1087
+ lines.extend(["", *coverage_lines])
1088
+ detail = _preserved_case_analysis_detail(existing_markdown)
1089
+ lines.extend(["", detail.strip()])
1090
+ return "\n".join(lines).rstrip() + "\n"
1091
+
1092
+
1093
+ def find_case_analysis_candidates(
1094
+ *,
1095
+ ledger: dict[str, Any],
1096
+ analysis: dict[str, Any],
1097
+ ) -> list[dict[str, Any]]:
1098
+ existing = case_analysis_keys(analysis)
1099
+ candidates: list[dict[str, Any]] = []
1100
+ benchmarks = ledger.get("benchmarks")
1101
+ if not isinstance(benchmarks, dict):
1102
+ return candidates
1103
+ for benchmark_id in sorted(benchmarks):
1104
+ benchmark = benchmarks[benchmark_id]
1105
+ if not isinstance(benchmark, dict):
1106
+ continue
1107
+ cases = benchmark.get("cases")
1108
+ if not isinstance(cases, dict):
1109
+ continue
1110
+ for case_id in sorted(cases):
1111
+ if (benchmark_id, case_id) in existing:
1112
+ continue
1113
+ case = cases[case_id]
1114
+ if not isinstance(case, dict):
1115
+ continue
1116
+ latest = case.get("latest_decision")
1117
+ if not isinstance(latest, dict):
1118
+ continue
1119
+ decision = _compact_text(latest.get("decision"), limit=160)
1120
+ if decision in NO_RUN_DECISIONS:
1121
+ continue
1122
+ runs = [run for run in case.get("runs", []) if isinstance(run, dict)]
1123
+ classified = classify_case_analysis_candidate(
1124
+ latest_decision=decision,
1125
+ run_count=len(runs),
1126
+ )
1127
+ run_ids = [
1128
+ _compact_text(run.get("run_id"), limit=120)
1129
+ for run in runs[-3:]
1130
+ if run.get("run_id")
1131
+ ]
1132
+ candidates.append(
1133
+ {
1134
+ "benchmark_id": benchmark_id,
1135
+ "case_id": case_id,
1136
+ "latest_decision": decision,
1137
+ "run_count": len(runs),
1138
+ "recent_run_ids": run_ids,
1139
+ **classified,
1140
+ "raw_logs_recorded": False,
1141
+ "raw_task_text_recorded": False,
1142
+ "trajectory_recorded": False,
1143
+ }
1144
+ )
1145
+ priority_order = {"P0": 0, "P1": 1, "P2": 2}
1146
+ candidates.sort(
1147
+ key=lambda item: (
1148
+ priority_order.get(str(item.get("promotion_priority")), 99),
1149
+ str(item.get("candidate_class")),
1150
+ str(item.get("benchmark_id")),
1151
+ str(item.get("case_id")),
1152
+ )
1153
+ )
1154
+ return candidates
1155
+
1156
+
1157
+ def build_case_analysis_candidate_report(
1158
+ *,
1159
+ ledger: dict[str, Any],
1160
+ analysis: dict[str, Any],
1161
+ include_proposed_records: bool = False,
1162
+ proposal_limit: int | None = None,
1163
+ acceptance_policy: str = "proposal-only",
1164
+ ) -> dict[str, Any]:
1165
+ policy = _normalize_acceptance_policy(acceptance_policy)
1166
+ candidates = find_case_analysis_candidates(ledger=ledger, analysis=analysis)
1167
+ report: dict[str, Any] = {
1168
+ "schema_version": BENCHMARK_CASE_ANALYSIS_CANDIDATE_REPORT_SCHEMA_VERSION,
1169
+ "candidate_count": len(candidates),
1170
+ "candidates": candidates,
1171
+ "source_boundary": {
1172
+ "inputs": [
1173
+ "compact benchmark-run-ledger",
1174
+ "benchmark-case-analysis case keys",
1175
+ ],
1176
+ "raw_logs_recorded": False,
1177
+ "raw_task_text_recorded": False,
1178
+ "trajectory_recorded": False,
1179
+ "absolute_paths_recorded": False,
1180
+ },
1181
+ }
1182
+ if include_proposed_records:
1183
+ proposed_records = [
1184
+ proposed_case_analysis_record_from_candidate(
1185
+ candidate,
1186
+ acceptance_policy=policy,
1187
+ )
1188
+ for candidate in candidates
1189
+ ]
1190
+ if proposal_limit is not None:
1191
+ proposed_records = proposed_records[: max(0, proposal_limit)]
1192
+ accepted_count = sum(
1193
+ 1
1194
+ for record in proposed_records
1195
+ if isinstance(record, dict)
1196
+ and record.get("proposal_status") == "accepted_generated_not_applied"
1197
+ )
1198
+ report["acceptance_policy"] = {
1199
+ "schema_version": BENCHMARK_CASE_ANALYSIS_ACCEPTANCE_POLICY_SCHEMA_VERSION,
1200
+ "policy": policy,
1201
+ "accepted_record_count": accepted_count,
1202
+ "manual_review_record_count": len(proposed_records) - accepted_count,
1203
+ }
1204
+ report["proposed_record_count"] = len(proposed_records)
1205
+ report["accepted_record_count"] = accepted_count
1206
+ report["proposed_records"] = proposed_records
1207
+ return report
1208
+
1209
+
1210
+ def render_case_analysis_candidate_report_markdown(report: dict[str, Any]) -> str:
1211
+ lines = [
1212
+ "# Benchmark Case-Analysis Candidates",
1213
+ "",
1214
+ "This report is derived only from compact benchmark-run ledger rows and",
1215
+ "existing case-analysis keys. It must not include raw task text, logs,",
1216
+ "trajectories, credentials, uploads, verifier tails, or local paths.",
1217
+ "",
1218
+ f"- schema_version: `{report.get('schema_version')}`",
1219
+ f"- candidate_count: `{report.get('candidate_count', 0)}`",
1220
+ "",
1221
+ "| Priority | Class | Benchmark | Case | Decision | Runs | Recommended Handling |",
1222
+ "| --- | --- | --- | --- | --- | --- | --- |",
1223
+ ]
1224
+ for candidate in report.get("candidates", []):
1225
+ if not isinstance(candidate, dict):
1226
+ continue
1227
+ lines.append(
1228
+ "| "
1229
+ f"`{candidate.get('promotion_priority', '')}` | "
1230
+ f"`{candidate.get('candidate_class', '')}` | "
1231
+ f"`{candidate.get('benchmark_id', '')}` | "
1232
+ f"`{candidate.get('case_id', '')}` | "
1233
+ f"`{candidate.get('latest_decision', '')}` | "
1234
+ f"`{candidate.get('run_count', 0)}` | "
1235
+ f"{candidate.get('recommended_handling', '')} |"
1236
+ )
1237
+ proposed_records = report.get("proposed_records")
1238
+ if isinstance(proposed_records, list):
1239
+ acceptance_policy = report.get("acceptance_policy")
1240
+ lines.extend(
1241
+ [
1242
+ "",
1243
+ "## Proposed Case-Analysis Records",
1244
+ "",
1245
+ "These records are proposal-only. They are safe to review, but the",
1246
+ "case-analysis file should not be edited until the proposed",
1247
+ "classification and handling are accepted.",
1248
+ "",
1249
+ "| Priority | Benchmark | Case | Classification | Status | Source Runs |",
1250
+ "| --- | --- | --- | --- | --- | --- |",
1251
+ ]
1252
+ )
1253
+ if isinstance(acceptance_policy, dict):
1254
+ lines.extend(
1255
+ [
1256
+ "",
1257
+ "- acceptance_policy: "
1258
+ f"`{acceptance_policy.get('policy')}`",
1259
+ "- accepted_record_count: "
1260
+ f"`{acceptance_policy.get('accepted_record_count', 0)}`",
1261
+ "",
1262
+ ]
1263
+ )
1264
+ for record in proposed_records:
1265
+ if not isinstance(record, dict):
1266
+ continue
1267
+ lines.append(
1268
+ "| "
1269
+ f"`{record.get('promotion_priority', '')}` | "
1270
+ f"`{record.get('benchmark_id', '')}` | "
1271
+ f"`{record.get('case_id', '')}` | "
1272
+ f"`{record.get('classification', '')}` | "
1273
+ f"`{record.get('proposal_status', '')}` | "
1274
+ f"`{record.get('source_run_count', 0)}` |"
1275
+ )
1276
+ return "\n".join(lines) + "\n"