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.
- loopx/__init__.py +5 -0
- loopx/agent_onboarding.py +654 -0
- loopx/agent_registry.py +112 -0
- loopx/ark_managed_agent_host.py +59 -0
- loopx/authority.py +805 -0
- loopx/benchmark.py +2875 -0
- loopx/benchmark_adapters/__init__.py +1 -0
- loopx/benchmark_adapters/agentissue.py +2644 -0
- loopx/benchmark_adapters/agents_last_exam.py +3998 -0
- loopx/benchmark_adapters/edgebench.py +322 -0
- loopx/benchmark_adapters/skillsbench.py +5978 -0
- loopx/benchmark_adapters/skillsbench_acp_failure_policy.py +143 -0
- loopx/benchmark_adapters/skillsbench_acp_process.py +31 -0
- loopx/benchmark_adapters/skillsbench_acp_relay.py +4832 -0
- loopx/benchmark_adapters/skillsbench_batch.py +124 -0
- loopx/benchmark_adapters/skillsbench_bridge_guard.py +209 -0
- loopx/benchmark_adapters/skillsbench_bridge_summary.py +203 -0
- loopx/benchmark_adapters/skillsbench_codex_goal_recovery.py +271 -0
- loopx/benchmark_adapters/skillsbench_codex_goal_trace.py +81 -0
- loopx/benchmark_adapters/skillsbench_codex_runtime.py +339 -0
- loopx/benchmark_adapters/skillsbench_dockerfile_runtime.py +467 -0
- loopx/benchmark_adapters/skillsbench_failure_signals.py +652 -0
- loopx/benchmark_adapters/skillsbench_proxy_runtime.py +327 -0
- loopx/benchmark_adapters/skillsbench_remote_bridge.py +402 -0
- loopx/benchmark_adapters/skillsbench_result_discovery.py +143 -0
- loopx/benchmark_adapters/skillsbench_runner_profile.py +436 -0
- loopx/benchmark_adapters/skillsbench_runner_source.py +99 -0
- loopx/benchmark_adapters/skillsbench_setup_preflight.py +771 -0
- loopx/benchmark_adapters/skillsbench_signals.py +15 -0
- loopx/benchmark_adapters/skillsbench_task_source.py +141 -0
- loopx/benchmark_adapters/skillsbench_turn_route.py +723 -0
- loopx/benchmark_adapters/skillsbench_turn_runtime.py +1069 -0
- loopx/benchmark_adapters/skillsbench_typed_repair.py +689 -0
- loopx/benchmark_adapters/skillsbench_uv_cache.py +111 -0
- loopx/benchmark_adapters/skillsbench_verifier_bootstrap.py +227 -0
- loopx/benchmark_adapters/skillsbench_verifier_cache.py +138 -0
- loopx/benchmark_adapters/terminal_bench.py +10078 -0
- loopx/benchmark_case_analysis.py +1276 -0
- loopx/benchmark_case_state.py +1079 -0
- loopx/benchmark_core/__init__.py +239 -0
- loopx/benchmark_core/adapter.py +84 -0
- loopx/benchmark_core/artifacts.py +517 -0
- loopx/benchmark_core/attempts.py +199 -0
- loopx/benchmark_core/container_exec.py +216 -0
- loopx/benchmark_core/io.py +68 -0
- loopx/benchmark_core/lifecycle.py +211 -0
- loopx/benchmark_core/loop_protocol.py +689 -0
- loopx/benchmark_core/observable_handles.py +348 -0
- loopx/benchmark_core/parity.py +256 -0
- loopx/benchmark_core/remote_closeout.py +482 -0
- loopx/benchmark_core/rounds.py +215 -0
- loopx/benchmark_core/route_profile.py +509 -0
- loopx/benchmark_core/run_permissions.py +206 -0
- loopx/benchmark_core/split_control.py +925 -0
- loopx/benchmark_core/turn_fidelity.py +326 -0
- loopx/benchmark_ledger.py +3793 -0
- loopx/benchmark_ledger_countability.py +372 -0
- loopx/benchmark_ledger_current.py +724 -0
- loopx/benchmark_trajectory.py +405 -0
- loopx/benchmarks/__init__.py +1 -0
- loopx/benchmarks/qualification/__init__.py +1 -0
- loopx/benchmarks/qualification/release_outcome_baseline.py +360 -0
- loopx/benchmarks/read_models/__init__.py +1 -0
- loopx/benchmarks/read_models/benchmark_attempt_accounting.py +53 -0
- loopx/benchmarks/read_models/benchmark_comparison.py +414 -0
- loopx/benchmarks/read_models/benchmark_event_timeline.py +113 -0
- loopx/benchmarks/read_models/benchmark_experiment_report.py +475 -0
- loopx/benchmarks/read_models/benchmark_learning_ledger.py +137 -0
- loopx/benchmarks/read_models/benchmark_lifecycle_contracts.py +228 -0
- loopx/benchmarks/read_models/benchmark_projection.py +723 -0
- loopx/benchmarks/read_models/benchmark_result.py +146 -0
- loopx/benchmarks/read_models/benchmark_run_execution_contract.py +116 -0
- loopx/benchmarks/read_models/benchmark_run_failure.py +157 -0
- loopx/benchmarks/read_models/benchmark_run_metrics.py +213 -0
- loopx/benchmarks/read_models/benchmark_run_post_execution.py +635 -0
- loopx/benchmarks/read_models/benchmark_run_pre_execution.py +541 -0
- loopx/benchmarks/read_models/benchmark_status_compaction.py +1255 -0
- loopx/benchmarks/read_models/benchmark_status_runner.py +780 -0
- loopx/benchmarks/read_models/goal_start_control_score.py +857 -0
- loopx/benchmarks/read_models/skillsbench_post_run_debug.py +746 -0
- loopx/benchmarks/read_models/skillsbench_verifier_attribution.py +269 -0
- loopx/bootstrap.py +1116 -0
- loopx/bootstrap_command_pack.py +2167 -0
- loopx/boundary_authority.py +199 -0
- loopx/canary/__init__.py +1 -0
- loopx/canary/maintainability_ratchet.py +800 -0
- loopx/canary/planner.py +1984 -0
- loopx/canary/premerge.py +1130 -0
- loopx/canary/qualification_profiles.py +309 -0
- loopx/canary/quality_surface_catalog.py +838 -0
- loopx/canary/release_profiles.py +51 -0
- loopx/canary/runner.py +1107 -0
- loopx/canary/smoke_health.py +581 -0
- loopx/canary/smoke_profiles.py +212 -0
- loopx/capabilities/__init__.py +0 -0
- loopx/capabilities/agent_turn_recall/__init__.py +17 -0
- loopx/capabilities/agent_turn_recall/cli.py +369 -0
- loopx/capabilities/agent_turn_recall/core.py +296 -0
- loopx/capabilities/auto_research/__init__.py +16 -0
- loopx/capabilities/auto_research/bootstrap_contract.py +157 -0
- loopx/capabilities/auto_research/cli.py +1468 -0
- loopx/capabilities/auto_research/core.py +11 -0
- loopx/capabilities/auto_research/defaults.py +79 -0
- loopx/capabilities/auto_research/demo_e2e.py +1848 -0
- loopx/capabilities/auto_research/demo_supervisor.py +186 -0
- loopx/capabilities/auto_research/evidence_packet.py +767 -0
- loopx/capabilities/auto_research/human_view.py +794 -0
- loopx/capabilities/auto_research/kernel.py +191 -0
- loopx/capabilities/auto_research/knn_demo_workspace.py +322 -0
- loopx/capabilities/auto_research/live_evidence.py +248 -0
- loopx/capabilities/auto_research/preset.py +176 -0
- loopx/capabilities/auto_research/research_state.py +1085 -0
- loopx/capabilities/auto_research/role_profiles.py +394 -0
- loopx/capabilities/auto_research/rollout_append.py +97 -0
- loopx/capabilities/auto_research/terminal_result_contract.py +422 -0
- loopx/capabilities/auto_research/terminal_result_projection.py +171 -0
- loopx/capabilities/auto_research/terminal_result_query.py +233 -0
- loopx/capabilities/auto_research/terminal_results.py +349 -0
- loopx/capabilities/auto_research/user_contract.py +190 -0
- loopx/capabilities/auto_research/worker_loop.py +163 -0
- loopx/capabilities/auto_research/worker_runtime.py +777 -0
- loopx/capabilities/auto_research/worker_skill/SKILL.md +343 -0
- loopx/capabilities/benchmark_toolkit/__init__.py +19 -0
- loopx/capabilities/benchmark_toolkit/integrity.py +387 -0
- loopx/capabilities/catalog.py +1875 -0
- loopx/capabilities/change_quality/__init__.py +19 -0
- loopx/capabilities/change_quality/cli.py +171 -0
- loopx/capabilities/change_quality/context.py +156 -0
- loopx/capabilities/change_quality/oracles.py +269 -0
- loopx/capabilities/change_quality/policy.py +34 -0
- loopx/capabilities/change_quality/receipt.py +482 -0
- loopx/capabilities/change_quality/result.py +493 -0
- loopx/capabilities/change_quality/scope.py +171 -0
- loopx/capabilities/change_quality/shadow.py +680 -0
- loopx/capabilities/content_ops/__init__.py +0 -0
- loopx/capabilities/content_ops/cli.py +649 -0
- loopx/capabilities/content_ops/connector_packets.py +164 -0
- loopx/capabilities/content_ops/item_lifecycle.py +1000 -0
- loopx/capabilities/content_ops/layout.py +451 -0
- loopx/capabilities/content_ops/markdown.py +456 -0
- loopx/capabilities/content_ops/schemas.py +51 -0
- loopx/capabilities/content_ops/social_browser_x.py +107 -0
- loopx/capabilities/content_ops/surface.py +1956 -0
- loopx/capabilities/content_ops/templates/layout-catalog-v0.json +72 -0
- loopx/capabilities/context_providers/__init__.py +36 -0
- loopx/capabilities/context_providers/base.py +189 -0
- loopx/capabilities/context_providers/factory.py +32 -0
- loopx/capabilities/context_providers/openviking.py +702 -0
- loopx/capabilities/context_providers/service_ownership.py +185 -0
- loopx/capabilities/decision_context/__init__.py +129 -0
- loopx/capabilities/decision_context/architecture.py +83 -0
- loopx/capabilities/decision_context/assembler.py +849 -0
- loopx/capabilities/decision_context/catalog_entry.py +195 -0
- loopx/capabilities/decision_context/cli.py +310 -0
- loopx/capabilities/decision_context/cursor_commit.py +535 -0
- loopx/capabilities/decision_context/outcome_feedback.py +352 -0
- loopx/capabilities/decision_context/packets.py +654 -0
- loopx/capabilities/decision_context/private_state.py +189 -0
- loopx/capabilities/decision_context/profile.py +453 -0
- loopx/capabilities/decision_context/providers.py +228 -0
- loopx/capabilities/decision_context/review_settlement.py +136 -0
- loopx/capabilities/decision_context/runtime.py +273 -0
- loopx/capabilities/decision_context/sources.py +415 -0
- loopx/capabilities/explore/__init__.py +1 -0
- loopx/capabilities/explore/activation.py +198 -0
- loopx/capabilities/explore/adaptive_replay_planner.py +221 -0
- loopx/capabilities/explore/child_replay_runtime.py +463 -0
- loopx/capabilities/explore/composition_frontier.py +291 -0
- loopx/capabilities/explore/counterfactual_runtime.py +578 -0
- loopx/capabilities/explore/episode_runtime.py +647 -0
- loopx/capabilities/explore/harness_checkpoint.py +171 -0
- loopx/capabilities/explore/harness_gate.py +115 -0
- loopx/capabilities/explore/harness_runtime.py +1124 -0
- loopx/capabilities/explore/replay_metrics.py +206 -0
- loopx/capabilities/explore/replay_runtime.py +1271 -0
- loopx/capabilities/explore/resource_portfolio.py +173 -0
- loopx/capabilities/explore/result_log.py +974 -0
- loopx/capabilities/explore/router_state.py +432 -0
- loopx/capabilities/explore/source_history_reconcile.py +255 -0
- loopx/capabilities/explore/speculative_scheduler.py +498 -0
- loopx/capabilities/explore/todo_branch_plan.py +650 -0
- loopx/capabilities/explore/todo_evidence.py +141 -0
- loopx/capabilities/explore/trace_runtime.py +284 -0
- loopx/capabilities/explore/worker_branch_plan.py +1257 -0
- loopx/capabilities/integration_branch/__init__.py +13 -0
- loopx/capabilities/integration_branch/cli.py +148 -0
- loopx/capabilities/integration_branch/core.py +916 -0
- loopx/capabilities/issue_fix/__init__.py +19 -0
- loopx/capabilities/issue_fix/acceptance_loop.py +1050 -0
- loopx/capabilities/issue_fix/candidate_evidence.py +503 -0
- loopx/capabilities/issue_fix/candidate_preflight.py +676 -0
- loopx/capabilities/issue_fix/cli.py +1822 -0
- loopx/capabilities/issue_fix/cli_input.py +87 -0
- loopx/capabilities/issue_fix/content_ops_cli.py +148 -0
- loopx/capabilities/issue_fix/discovered_issue_promotion.py +947 -0
- loopx/capabilities/issue_fix/explore_projection.py +710 -0
- loopx/capabilities/issue_fix/feasibility.py +542 -0
- loopx/capabilities/issue_fix/github_public.py +661 -0
- loopx/capabilities/issue_fix/intake_surface.py +832 -0
- loopx/capabilities/issue_fix/metadata_preview.py +218 -0
- loopx/capabilities/issue_fix/metrics_projection.py +1340 -0
- loopx/capabilities/issue_fix/metrics_supplement.py +634 -0
- loopx/capabilities/issue_fix/metrics_supplement_cli.py +127 -0
- loopx/capabilities/issue_fix/outcome_projection.py +1235 -0
- loopx/capabilities/issue_fix/periodic_report.py +189 -0
- loopx/capabilities/issue_fix/pr_description.py +418 -0
- loopx/capabilities/issue_fix/pr_gate_reconcile.py +496 -0
- loopx/capabilities/issue_fix/pr_gate_reconcile_cli.py +464 -0
- loopx/capabilities/issue_fix/pr_lifecycle.py +1327 -0
- loopx/capabilities/issue_fix/pr_lifecycle_rollout.py +85 -0
- loopx/capabilities/issue_fix/pr_monitor_materialization.py +257 -0
- loopx/capabilities/issue_fix/pr_review_ack.py +439 -0
- loopx/capabilities/issue_fix/provider_hooks.py +24 -0
- loopx/capabilities/issue_fix/repository_commit_evidence.py +186 -0
- loopx/capabilities/issue_fix/repository_context.py +457 -0
- loopx/capabilities/issue_fix/repository_memory.py +459 -0
- loopx/capabilities/issue_fix/repository_memory_provider.py +1454 -0
- loopx/capabilities/issue_fix/repository_snapshot.py +454 -0
- loopx/capabilities/issue_fix/reviewer_cli.py +917 -0
- loopx/capabilities/issue_fix/reviewer_notification.py +882 -0
- loopx/capabilities/issue_fix/reviewer_notification_drain.py +942 -0
- loopx/capabilities/issue_fix/reviewer_recommendation.py +1057 -0
- loopx/capabilities/issue_fix/reviewer_request.py +1282 -0
- loopx/capabilities/issue_fix/reward_memory.py +879 -0
- loopx/capabilities/issue_fix/workflow_plan.py +1286 -0
- loopx/capabilities/material_lifecycle/__init__.py +161 -0
- loopx/capabilities/material_lifecycle/_validation.py +183 -0
- loopx/capabilities/material_lifecycle/apply.py +672 -0
- loopx/capabilities/material_lifecycle/architecture.py +122 -0
- loopx/capabilities/material_lifecycle/cli.py +161 -0
- loopx/capabilities/material_lifecycle/decision_planning.py +470 -0
- loopx/capabilities/material_lifecycle/explore_execution.py +306 -0
- loopx/capabilities/material_lifecycle/intake.py +869 -0
- loopx/capabilities/material_lifecycle/inventory.py +147 -0
- loopx/capabilities/material_lifecycle/lifecycle.py +98 -0
- loopx/capabilities/material_lifecycle/preparation.py +147 -0
- loopx/capabilities/material_lifecycle/project_skill.py +83 -0
- loopx/capabilities/material_lifecycle/ranking.py +267 -0
- loopx/capabilities/material_lifecycle/readable_projection.py +500 -0
- loopx/capabilities/material_lifecycle/rebuild.py +480 -0
- loopx/capabilities/material_lifecycle/settlement.py +238 -0
- loopx/capabilities/periodic_report/__init__.py +71 -0
- loopx/capabilities/periodic_report/adapters.py +939 -0
- loopx/capabilities/periodic_report/archive.py +422 -0
- loopx/capabilities/periodic_report/bindings.py +705 -0
- loopx/capabilities/periodic_report/cli.py +277 -0
- loopx/capabilities/periodic_report/core.py +691 -0
- loopx/capabilities/periodic_report/extension_envelope.py +66 -0
- loopx/capabilities/periodic_report/presets.py +103 -0
- loopx/capabilities/periodic_report/profile.py +235 -0
- loopx/capabilities/periodic_report/project_progress.py +179 -0
- loopx/capabilities/periodic_report/triggers.py +452 -0
- loopx/capabilities/pr_review_queue/__init__.py +17 -0
- loopx/capabilities/pr_review_queue/core.py +506 -0
- loopx/capabilities/pr_review_queue/review_contract.py +506 -0
- loopx/capabilities/registry.py +192 -0
- loopx/capabilities/reward_memory/__init__.py +75 -0
- loopx/capabilities/reward_memory/application.py +819 -0
- loopx/capabilities/reward_memory/architecture.py +572 -0
- loopx/capabilities/reward_memory/candidate_review.py +511 -0
- loopx/capabilities/reward_memory/cli.py +469 -0
- loopx/capabilities/reward_memory/dogfood.py +574 -0
- loopx/capabilities/reward_memory/evaluation.py +296 -0
- loopx/capabilities/reward_memory/evaluation_fixtures.py +362 -0
- loopx/capabilities/reward_memory/experiment.py +567 -0
- loopx/capabilities/reward_memory/health.py +222 -0
- loopx/capabilities/reward_memory/ingestion.py +519 -0
- loopx/capabilities/reward_memory/registry.py +600 -0
- loopx/capabilities/reward_memory/runtime_hooks.py +312 -0
- loopx/capabilities/reward_memory/scoped_feedback.py +173 -0
- loopx/capabilities/semantic_preference/__init__.py +12 -0
- loopx/capabilities/semantic_preference/cli.py +189 -0
- loopx/capabilities/semantic_preference/contract.py +592 -0
- loopx/capabilities/semantic_preference/reward_memory.py +62 -0
- loopx/capabilities/value_connectors/__init__.py +1 -0
- loopx/capabilities/value_connectors/cli.py +401 -0
- loopx/capabilities/value_connectors/finance_extension_migration.py +108 -0
- loopx/capabilities/value_connectors/install_check.py +147 -0
- loopx/capabilities/value_connectors/planner.py +733 -0
- loopx/capabilities/value_connectors/source_map.py +446 -0
- loopx/claude_goal_baseline.py +138 -0
- loopx/claude_goal_mode/__init__.py +23 -0
- loopx/claude_goal_mode/hooks/goal_policy.py +212 -0
- loopx/claude_goal_mode/hooks/goal_state.py +139 -0
- loopx/claude_goal_mode/mcp/loopx_mcp.py +167 -0
- loopx/claude_goal_mode/scripts/connect.py +103 -0
- loopx/claude_goal_mode/scripts/goalmode_cmd.py +241 -0
- loopx/claude_goal_mode/scripts/install.py +328 -0
- loopx/claude_goal_mode/statusline/goal_status.py +97 -0
- loopx/cli.py +836 -0
- loopx/cli_commands/__init__.py +334 -0
- loopx/cli_commands/_host_thread.py +13 -0
- loopx/cli_commands/agentissue_runner_flow.py +447 -0
- loopx/cli_commands/agents_last_exam.py +160 -0
- loopx/cli_commands/agents_last_exam_baked_input.py +302 -0
- loopx/cli_commands/agents_last_exam_host_codex.py +374 -0
- loopx/cli_commands/agents_last_exam_launch_dry_run.py +372 -0
- loopx/cli_commands/agents_last_exam_local_plan.py +322 -0
- loopx/cli_commands/agents_last_exam_runner_source.py +352 -0
- loopx/cli_commands/agents_last_exam_task_material.py +335 -0
- loopx/cli_commands/agents_last_exam_validation_gate.py +236 -0
- loopx/cli_commands/benchmark_boundary.py +499 -0
- loopx/cli_commands/benchmark_dispatch.py +161 -0
- loopx/cli_commands/benchmark_release_outcome.py +123 -0
- loopx/cli_commands/benchmark_review_lifecycle.py +1275 -0
- loopx/cli_commands/benchmark_run_ledger.py +763 -0
- loopx/cli_commands/benchmark_run_ledger_case_analysis.py +249 -0
- loopx/cli_commands/benchmark_run_ledger_classification.py +45 -0
- loopx/cli_commands/benchmark_run_ledger_maintenance.py +486 -0
- loopx/cli_commands/benchmark_run_ledger_maintenance_registration.py +342 -0
- loopx/cli_commands/benchmark_run_ledger_maintenance_rendering.py +233 -0
- loopx/cli_commands/benchmark_run_ledger_parity.py +92 -0
- loopx/cli_commands/bootstrap_connect.py +238 -0
- loopx/cli_commands/canary.py +707 -0
- loopx/cli_commands/canary_release_qualification.py +79 -0
- loopx/cli_commands/capability.py +96 -0
- loopx/cli_commands/doctor.py +43 -0
- loopx/cli_commands/dreaming.py +143 -0
- loopx/cli_commands/edgebench.py +205 -0
- loopx/cli_commands/evidence_log.py +275 -0
- loopx/cli_commands/explore.py +989 -0
- loopx/cli_commands/explore_planning_commands.py +157 -0
- loopx/cli_commands/extension.py +271 -0
- loopx/cli_commands/first_run_report.py +73 -0
- loopx/cli_commands/goal_channel.py +656 -0
- loopx/cli_commands/handoff_mode.py +158 -0
- loopx/cli_commands/history.py +622 -0
- loopx/cli_commands/host_mode_plan.py +113 -0
- loopx/cli_commands/lark_inbox.py +431 -0
- loopx/cli_commands/lark_kanban.py +629 -0
- loopx/cli_commands/ml_experiment.py +321 -0
- loopx/cli_commands/multi_agent.py +211 -0
- loopx/cli_commands/opencode2_goal_worker.py +217 -0
- loopx/cli_commands/pr_review.py +167 -0
- loopx/cli_commands/presentation.py +218 -0
- loopx/cli_commands/preset.py +96 -0
- loopx/cli_commands/project.py +150 -0
- loopx/cli_commands/project_lifecycle.py +915 -0
- loopx/cli_commands/quota.py +859 -0
- loopx/cli_commands/quota_registration.py +241 -0
- loopx/cli_commands/quota_request.py +113 -0
- loopx/cli_commands/ready_score.py +110 -0
- loopx/cli_commands/registry_admin.py +975 -0
- loopx/cli_commands/registry_admin_configure.py +344 -0
- loopx/cli_commands/registry_admin_peer.py +84 -0
- loopx/cli_commands/registry_authority.py +218 -0
- loopx/cli_commands/review_batch.py +146 -0
- loopx/cli_commands/slash_commands.py +145 -0
- loopx/cli_commands/start_goal.py +251 -0
- loopx/cli_commands/starter.py +175 -0
- loopx/cli_commands/starter_bootstrap.py +179 -0
- loopx/cli_commands/starter_bootstrap_registration.py +198 -0
- loopx/cli_commands/starter_runtime_idle.py +107 -0
- loopx/cli_commands/starter_scheduler.py +207 -0
- loopx/cli_commands/starter_session_runtime.py +152 -0
- loopx/cli_commands/starter_visible_common.py +54 -0
- loopx/cli_commands/starter_visible_driver.py +161 -0
- loopx/cli_commands/starter_visible_pilot.py +278 -0
- loopx/cli_commands/status.py +867 -0
- loopx/cli_commands/status_registration.py +239 -0
- loopx/cli_commands/summary_all.py +222 -0
- loopx/cli_commands/support_control.py +809 -0
- loopx/cli_commands/support_control_registry.py +68 -0
- loopx/cli_commands/support_control_supervisor.py +289 -0
- loopx/cli_commands/task_lease.py +306 -0
- loopx/cli_commands/terminal_bench_adapter.py +717 -0
- loopx/cli_commands/terminal_bench_environment_result.py +1246 -0
- loopx/cli_commands/todo.py +940 -0
- loopx/cli_commands/todo_argument_validation.py +572 -0
- loopx/cli_commands/todo_event.py +114 -0
- loopx/cli_commands/turn.py +804 -0
- loopx/cli_commands/version.py +46 -0
- loopx/cli_commands/worker_bridge.py +659 -0
- loopx/cli_rollout.py +314 -0
- loopx/codex_cli_goal_tui.py +672 -0
- loopx/codex_cli_probe.py +1530 -0
- loopx/codex_cli_probe_markdown.py +935 -0
- loopx/codex_cli_runtime_probe.py +733 -0
- loopx/codex_cli_scheduler.py +564 -0
- loopx/codex_goal_baseline.py +620 -0
- loopx/configuration_catalog.py +617 -0
- loopx/configure_goal.py +1375 -0
- loopx/contract.py +996 -0
- loopx/control_plane/__init__.py +71 -0
- loopx/control_plane/agents/__init__.py +1 -0
- loopx/control_plane/agents/agent_lane_recommendation.py +516 -0
- loopx/control_plane/agents/agent_scope.py +1578 -0
- loopx/control_plane/agents/agent_scope_frontier.py +60 -0
- loopx/control_plane/agents/capability_gate.py +531 -0
- loopx/control_plane/agents/identity.py +140 -0
- loopx/control_plane/agents/legacy_migration.py +169 -0
- loopx/control_plane/agents/management_projection.py +658 -0
- loopx/control_plane/agents/material_frontier.py +608 -0
- loopx/control_plane/agents/material_handoff.py +156 -0
- loopx/control_plane/agents/multi_agent/__init__.py +1 -0
- loopx/control_plane/agents/multi_agent/codex_executable.py +207 -0
- loopx/control_plane/agents/multi_agent/collective_round_ledger.py +387 -0
- loopx/control_plane/agents/multi_agent/contract.py +474 -0
- loopx/control_plane/agents/multi_agent/recipe.py +110 -0
- loopx/control_plane/agents/multi_agent/role_successor.py +297 -0
- loopx/control_plane/agents/multi_agent/runtime_scripts.py +426 -0
- loopx/control_plane/agents/multi_agent/visible_launch_policy.py +149 -0
- loopx/control_plane/agents/multi_agent/visible_wake_scheduler.py +392 -0
- loopx/control_plane/agents/profile.py +216 -0
- loopx/control_plane/agents/runtime_model.py +73 -0
- loopx/control_plane/agents/subagent_activity.py +164 -0
- loopx/control_plane/agents/supervisor.py +544 -0
- loopx/control_plane/agents/supervisor_events.py +462 -0
- loopx/control_plane/agents/supervisor_inject.py +204 -0
- loopx/control_plane/agents/work_mode.py +56 -0
- loopx/control_plane/agents/workspace_guard.py +364 -0
- loopx/control_plane/effect_program.py +644 -0
- loopx/control_plane/goals/__init__.py +1 -0
- loopx/control_plane/goals/active_state_event_projection.py +103 -0
- loopx/control_plane/goals/active_state_metadata.py +47 -0
- loopx/control_plane/goals/active_state_sections.py +58 -0
- loopx/control_plane/goals/configure_goal_service.py +354 -0
- loopx/control_plane/goals/contract_health.py +132 -0
- loopx/control_plane/goals/dreaming.py +152 -0
- loopx/control_plane/goals/global_registry_health.py +199 -0
- loopx/control_plane/goals/global_registry_shadow.py +33 -0
- loopx/control_plane/goals/goal_channel.py +34 -0
- loopx/control_plane/goals/goal_channel_projection.py +560 -0
- loopx/control_plane/goals/goal_frontier/__init__.py +1917 -0
- loopx/control_plane/goals/goal_frontier/ack_policy.py +149 -0
- loopx/control_plane/goals/goal_frontier/outcome_continuity.py +437 -0
- loopx/control_plane/goals/goal_frontier/replan_rules.py +210 -0
- loopx/control_plane/goals/goal_frontier/semantic_history.py +314 -0
- loopx/control_plane/goals/goal_frontier/terminal.py +180 -0
- loopx/control_plane/goals/goal_vision.py +443 -0
- loopx/control_plane/goals/goal_vision_policy.py +36 -0
- loopx/control_plane/goals/goal_vision_state.py +62 -0
- loopx/control_plane/goals/goal_vision_wait.py +290 -0
- loopx/control_plane/goals/path_resolution.py +20 -0
- loopx/control_plane/goals/start_contract.py +206 -0
- loopx/control_plane/goals/vision_checkpoint.py +92 -0
- loopx/control_plane/handoff/__init__.py +1 -0
- loopx/control_plane/handoff/cross_runtime_impl_review.py +311 -0
- loopx/control_plane/handoff/delivery_contract.py +161 -0
- loopx/control_plane/handoff/handoff_runs.py +71 -0
- loopx/control_plane/handoff/project_handoff.py +155 -0
- loopx/control_plane/handoff/review_batch.py +463 -0
- loopx/control_plane/handoff/review_packet_context.py +216 -0
- loopx/control_plane/heartbeat/agent.py +173 -0
- loopx/control_plane/heartbeat/budget.py +66 -0
- loopx/control_plane/heartbeat/builder.py +501 -0
- loopx/control_plane/heartbeat/host.py +64 -0
- loopx/control_plane/heartbeat/rules.py +68 -0
- loopx/control_plane/heartbeat/task_body.py +759 -0
- loopx/control_plane/heartbeat/visible_goal.py +86 -0
- loopx/control_plane/projects/__init__.py +1 -0
- loopx/control_plane/projects/contract.py +25 -0
- loopx/control_plane/projects/registry.py +663 -0
- loopx/control_plane/quota/__init__.py +1 -0
- loopx/control_plane/quota/cli_projection.py +704 -0
- loopx/control_plane/quota/decision_summary.py +431 -0
- loopx/control_plane/quota/effect_program.py +152 -0
- loopx/control_plane/quota/error_codes.py +19 -0
- loopx/control_plane/quota/goal_boundary.py +464 -0
- loopx/control_plane/quota/heartbeat_receipt.py +277 -0
- loopx/control_plane/quota/heartbeat_recommendation.py +718 -0
- loopx/control_plane/quota/host_poll_receipts.py +162 -0
- loopx/control_plane/quota/live_decision.py +142 -0
- loopx/control_plane/quota/monitor_poll.py +786 -0
- loopx/control_plane/quota/policy_constants.py +40 -0
- loopx/control_plane/quota/projection_repair.py +262 -0
- loopx/control_plane/quota/recent_runs.py +210 -0
- loopx/control_plane/quota/scheduler_ack.py +490 -0
- loopx/control_plane/quota/selected_todo_projection.py +139 -0
- loopx/control_plane/quota/settlement.py +437 -0
- loopx/control_plane/quota/settlement_cli.py +246 -0
- loopx/control_plane/quota/settlement_validation.py +64 -0
- loopx/control_plane/quota/settlement_workspace_causality.py +180 -0
- loopx/control_plane/quota/should_run.py +249 -0
- loopx/control_plane/quota/should_run_packet.py +1165 -0
- loopx/control_plane/quota/should_run_prepare.py +675 -0
- loopx/control_plane/quota/slot_accounting.py +1123 -0
- loopx/control_plane/quota/spend_sources.py +11 -0
- loopx/control_plane/quota/stall_repair.py +397 -0
- loopx/control_plane/quota/states.py +29 -0
- loopx/control_plane/quota/task_orchestration.py +448 -0
- loopx/control_plane/quota/task_orchestration_admission.py +497 -0
- loopx/control_plane/quota/turn_envelope.py +889 -0
- loopx/control_plane/quota/usage_summary.py +140 -0
- loopx/control_plane/reward_memory.py +43 -0
- loopx/control_plane/runtime/__init__.py +2 -0
- loopx/control_plane/runtime/active_user_assisted_pilot.py +275 -0
- loopx/control_plane/runtime/agent_scoped_evidence_log.py +435 -0
- loopx/control_plane/runtime/decision_freshness.py +203 -0
- loopx/control_plane/runtime/event_ledger.py +197 -0
- loopx/control_plane/runtime/event_store_migration_bridge.py +196 -0
- loopx/control_plane/runtime/goal_project_route.py +70 -0
- loopx/control_plane/runtime/local_state_write_correctness.py +242 -0
- loopx/control_plane/runtime/promotion_readiness.py +152 -0
- loopx/control_plane/runtime/public_safety.py +120 -0
- loopx/control_plane/runtime/run_artifacts.py +78 -0
- loopx/control_plane/runtime/run_compaction.py +397 -0
- loopx/control_plane/runtime/run_context_retention.py +241 -0
- loopx/control_plane/runtime/run_history.py +132 -0
- loopx/control_plane/runtime/run_index_duplicates.py +205 -0
- loopx/control_plane/runtime/run_index_rebuild.py +263 -0
- loopx/control_plane/runtime/run_ingest_health.py +336 -0
- loopx/control_plane/runtime/runtime_projection_route.py +624 -0
- loopx/control_plane/runtime/runtime_projection_writer.py +98 -0
- loopx/control_plane/runtime/session_runtime.py +339 -0
- loopx/control_plane/runtime/shared_runtime_material_projection.py +332 -0
- loopx/control_plane/runtime/shared_runtime_refresh_projection.py +183 -0
- loopx/control_plane/runtime/stale_latest_run.py +90 -0
- loopx/control_plane/runtime/status_classifications.py +49 -0
- loopx/control_plane/runtime/status_projection_cache.py +235 -0
- loopx/control_plane/runtime/stride_observation.py +144 -0
- loopx/control_plane/runtime/time.py +39 -0
- loopx/control_plane/runtime/trajectory_hygiene.py +149 -0
- loopx/control_plane/runtime/validation_command.py +69 -0
- loopx/control_plane/scheduler/__init__.py +1 -0
- loopx/control_plane/scheduler/ack.py +329 -0
- loopx/control_plane/scheduler/arbitration.py +188 -0
- loopx/control_plane/scheduler/automation_liveness.py +183 -0
- loopx/control_plane/scheduler/execution_context.py +555 -0
- loopx/control_plane/scheduler/external_evidence_observation.py +428 -0
- loopx/control_plane/scheduler/monitor_display.py +143 -0
- loopx/control_plane/scheduler/monitor_poll_policy.py +161 -0
- loopx/control_plane/scheduler/monitor_poll_writeback.py +351 -0
- loopx/control_plane/scheduler/monitor_target.py +64 -0
- loopx/control_plane/scheduler/monitor_todo.py +146 -0
- loopx/control_plane/scheduler/monitor_wait.py +237 -0
- loopx/control_plane/scheduler/scheduler_hint.py +1284 -0
- loopx/control_plane/scheduler/state.py +354 -0
- loopx/control_plane/scheduler/state_transition_rules.py +179 -0
- loopx/control_plane/scheduler/time.py +10 -0
- loopx/control_plane/settlement_driver.py +293 -0
- loopx/control_plane/status/__init__.py +6 -0
- loopx/control_plane/status/active_state_projection.py +105 -0
- loopx/control_plane/status/agent_lane_projection.py +375 -0
- loopx/control_plane/status/attention_projection.py +74 -0
- loopx/control_plane/status/autonomous_replan_projection.py +103 -0
- loopx/control_plane/status/collection.py +140 -0
- loopx/control_plane/status/contract_projection.py +31 -0
- loopx/control_plane/status/dreaming_projection.py +52 -0
- loopx/control_plane/status/goal_attention_projection.py +157 -0
- loopx/control_plane/status/lifecycle_projection.py +110 -0
- loopx/control_plane/status/monitor_display_projection.py +69 -0
- loopx/control_plane/status/registry_health_projection.py +75 -0
- loopx/control_plane/status/run_projection.py +70 -0
- loopx/control_plane/status/runtime_summaries.py +161 -0
- loopx/control_plane/testing/__init__.py +1 -0
- loopx/control_plane/testing/actual_default_model_behavior_portfolio.py +1371 -0
- loopx/control_plane/testing/canary_harness.py +182 -0
- loopx/control_plane/testing/capability_monitor_repair_tool_behavior.py +674 -0
- loopx/control_plane/testing/cli_output_budget.py +807 -0
- loopx/control_plane/testing/cli_output_differential.py +250 -0
- loopx/control_plane/testing/cli_output_semantics.py +87 -0
- loopx/control_plane/testing/control_plane_composition_scenarios.py +225 -0
- loopx/control_plane/testing/decision_replay.py +268 -0
- loopx/control_plane/testing/doubao_model_behavior_actor.py +559 -0
- loopx/control_plane/testing/model_behavior_corpus.py +344 -0
- loopx/control_plane/testing/model_behavior_qualification.py +769 -0
- loopx/control_plane/testing/model_behavior_retained_cases.py +235 -0
- loopx/control_plane/testing/model_tool_behavior.py +536 -0
- loopx/control_plane/testing/onboarding_model_behavior_qualification.py +642 -0
- loopx/control_plane/testing/quota_fixtures.py +208 -0
- loopx/control_plane/testing/quota_should_run_parity.py +57 -0
- loopx/control_plane/testing/release_commit_qualification.py +671 -0
- loopx/control_plane/testing/replan_semantic_action_behavior.py +1302 -0
- loopx/control_plane/testing/scoped_gate_successor_tool_behavior.py +527 -0
- loopx/control_plane/testing/selected_todo_tool_behavior.py +1002 -0
- loopx/control_plane/testing/terminal_settlement_tool_behavior.py +656 -0
- loopx/control_plane/todos/__init__.py +1 -0
- loopx/control_plane/todos/active_state_editing.py +296 -0
- loopx/control_plane/todos/active_state_todo_parser.py +138 -0
- loopx/control_plane/todos/active_state_todos.py +175 -0
- loopx/control_plane/todos/addition.py +103 -0
- loopx/control_plane/todos/claim_visibility.py +253 -0
- loopx/control_plane/todos/completed_archive.py +139 -0
- loopx/control_plane/todos/completion_fence.py +49 -0
- loopx/control_plane/todos/completion_policy.py +153 -0
- loopx/control_plane/todos/completion_validation.py +248 -0
- loopx/control_plane/todos/completion_validation_accountability.py +27 -0
- loopx/control_plane/todos/completion_validation_projection.py +57 -0
- loopx/control_plane/todos/contract.py +1476 -0
- loopx/control_plane/todos/decision_scope.py +554 -0
- loopx/control_plane/todos/deferred_resume.py +546 -0
- loopx/control_plane/todos/durable_completion.py +201 -0
- loopx/control_plane/todos/event_writeback.py +484 -0
- loopx/control_plane/todos/frontier_deadline.py +132 -0
- loopx/control_plane/todos/handoff_gate.py +283 -0
- loopx/control_plane/todos/handoff_mode.py +444 -0
- loopx/control_plane/todos/handoff_note.py +202 -0
- loopx/control_plane/todos/line_update.py +361 -0
- loopx/control_plane/todos/list_projection.py +205 -0
- loopx/control_plane/todos/markdown.py +199 -0
- loopx/control_plane/todos/monitor_metadata.py +88 -0
- loopx/control_plane/todos/mutation_authority.py +299 -0
- loopx/control_plane/todos/projection.py +655 -0
- loopx/control_plane/todos/quota_summary.py +1138 -0
- loopx/control_plane/todos/route_continuation.py +267 -0
- loopx/control_plane/todos/succession_warning.py +174 -0
- loopx/control_plane/todos/summary_item.py +223 -0
- loopx/control_plane/todos/text.py +30 -0
- loopx/control_plane/todos/todo_index.py +226 -0
- loopx/control_plane/todos/todo_summary.py +1458 -0
- loopx/control_plane/todos/unblock_resume.py +326 -0
- loopx/control_plane/todos/user_gate.py +263 -0
- loopx/control_plane/todos/write_hint.py +63 -0
- loopx/control_plane/todos/write_policy.py +135 -0
- loopx/control_plane/turn_driver/__init__.py +85 -0
- loopx/control_plane/turn_driver/codex_cli.py +502 -0
- loopx/control_plane/turn_driver/driver.py +355 -0
- loopx/control_plane/turn_driver/executor.py +1468 -0
- loopx/control_plane/turn_driver/loop_controller.py +669 -0
- loopx/control_plane/turn_driver/settlement.py +318 -0
- loopx/control_plane/turn_driver/transaction.py +375 -0
- loopx/control_plane/work_items/__init__.py +1 -0
- loopx/control_plane/work_items/attention_fields.py +56 -0
- loopx/control_plane/work_items/attention_item.py +77 -0
- loopx/control_plane/work_items/attention_queue.py +322 -0
- loopx/control_plane/work_items/attention_routing.py +213 -0
- loopx/control_plane/work_items/autonomous_candidates.py +135 -0
- loopx/control_plane/work_items/autonomous_replan_ack.py +276 -0
- loopx/control_plane/work_items/autonomous_replan_obligation.py +786 -0
- loopx/control_plane/work_items/backlog_hygiene.py +59 -0
- loopx/control_plane/work_items/capability_monitor_fallback.py +221 -0
- loopx/control_plane/work_items/delivery_batch_scale.py +66 -0
- loopx/control_plane/work_items/delivery_outcome.py +152 -0
- loopx/control_plane/work_items/delivery_signals.py +113 -0
- loopx/control_plane/work_items/execution_obligation.py +235 -0
- loopx/control_plane/work_items/goal_route_hint.py +320 -0
- loopx/control_plane/work_items/interaction_contract.py +1540 -0
- loopx/control_plane/work_items/issue_meta_surface.py +159 -0
- loopx/control_plane/work_items/lifecycle.py +139 -0
- loopx/control_plane/work_items/operator_inbox.py +266 -0
- loopx/control_plane/work_items/outcome_followthrough.py +69 -0
- loopx/control_plane/work_items/primary_action.py +326 -0
- loopx/control_plane/work_items/progress_observation.py +630 -0
- loopx/control_plane/work_items/project_asset.py +675 -0
- loopx/control_plane/work_items/repair_delta.py +693 -0
- loopx/control_plane/work_items/runtime_capability_reentry.py +168 -0
- loopx/control_plane/work_items/semantic_replan_writeback.py +177 -0
- loopx/control_plane/work_items/status_contract.py +49 -0
- loopx/control_plane/work_items/task_graph.py +1046 -0
- loopx/control_plane/work_items/task_lease.py +1254 -0
- loopx/control_plane/work_items/task_lease_settlement.py +422 -0
- loopx/control_plane/work_items/work_lane.py +510 -0
- loopx/control_plane/work_items/work_lane_context.py +161 -0
- loopx/demo.py +247 -0
- loopx/diagnose.py +633 -0
- loopx/doctor.py +1251 -0
- loopx/domain_packs/__init__.py +1 -0
- loopx/domain_packs/issue_fix.py +571 -0
- loopx/domain_packs/ml_experiment.py +854 -0
- loopx/domain_state.py +137 -0
- loopx/dreaming.py +706 -0
- loopx/entrypoint.py +16 -0
- loopx/event_sourced_state.py +981 -0
- loopx/execution_profile.py +286 -0
- loopx/experiments/__init__.py +1 -0
- loopx/experiments/planner_worker/__init__.py +1 -0
- loopx/experiments/planner_worker/contract.py +523 -0
- loopx/experiments/planner_worker/runtime.py +391 -0
- loopx/experiments/planner_worker/traex.py +461 -0
- loopx/explore_graph.py +11 -0
- loopx/extensions/__init__.py +1 -0
- loopx/extensions/bundled.py +28 -0
- loopx/extensions/execution_envelope.py +126 -0
- loopx/extensions/lark/__init__.py +11 -0
- loopx/extensions/lark/event_collector.py +478 -0
- loopx/extensions/lark/event_collector_runtime.py +506 -0
- loopx/extensions/lark/event_inbox.py +454 -0
- loopx/extensions/lark/extension.toml +88 -0
- loopx/extensions/lark/goal_channel.py +44 -0
- loopx/extensions/lark/goal_channel_contracts.py +388 -0
- loopx/extensions/lark/goal_channel_lifecycle.py +218 -0
- loopx/extensions/lark/goal_channel_runtime.py +792 -0
- loopx/extensions/lark/goal_channel_setup.py +805 -0
- loopx/extensions/lark/goal_channel_targets.py +215 -0
- loopx/extensions/lark/goal_channel_transport.py +281 -0
- loopx/extensions/lark/inbox_reactions.py +650 -0
- loopx/extensions/lark/inbox_reply.py +430 -0
- loopx/extensions/lark/presentation/__init__.py +11 -0
- loopx/extensions/lark/presentation/explore_results.py +2276 -0
- loopx/extensions/lark/presentation/explore_singleflight.py +127 -0
- loopx/extensions/lark/presentation/explore_source_guard.py +121 -0
- loopx/extensions/lark/presentation/explore_stage_document.py +703 -0
- loopx/extensions/lark/presentation/explore_visual_integrity.py +122 -0
- loopx/extensions/lark/presentation/explore_visual_readback.py +452 -0
- loopx/extensions/lark/presentation/explore_visual_styles.py +156 -0
- loopx/extensions/lark/presentation/issue_fix_surface.py +612 -0
- loopx/extensions/lark/presentation/kanban.py +2791 -0
- loopx/extensions/lark/presentation/message_card.py +112 -0
- loopx/extensions/lark/presentation/periodic_report.py +261 -0
- loopx/extensions/lark/presentation/projection_rows.py +600 -0
- loopx/extensions/lark/presentation/record_io.py +95 -0
- loopx/extensions/lark/presentation/sync_receipt.py +145 -0
- loopx/extensions/lark/private_json.py +40 -0
- loopx/extensions/lark/provider.py +86 -0
- loopx/extensions/lark/reviewer_notification.py +604 -0
- loopx/extensions/manifest.py +385 -0
- loopx/extensions/openviking_periodic_report/__init__.py +17 -0
- loopx/extensions/openviking_periodic_report/activation.py +173 -0
- loopx/extensions/openviking_periodic_report/extension.toml +17 -0
- loopx/extensions/openviking_periodic_report/provider.py +355 -0
- loopx/extensions/openviking_periodic_report/sink.py +117 -0
- loopx/extensions/openviking_semantic_preference/__init__.py +5 -0
- loopx/extensions/openviking_semantic_preference/extension.toml +16 -0
- loopx/extensions/openviking_semantic_preference/history_export.py +484 -0
- loopx/extensions/openviking_semantic_preference/project_peer.py +68 -0
- loopx/extensions/openviking_semantic_preference/provider.py +312 -0
- loopx/extensions/presentation.py +979 -0
- loopx/extensions/process_runtime.py +204 -0
- loopx/extensions/readiness.py +168 -0
- loopx/extensions/runtime.py +931 -0
- loopx/extensions/scaffold.py +335 -0
- loopx/feedback.py +581 -0
- loopx/file_lock.py +382 -0
- loopx/global_registry.py +842 -0
- loopx/global_risks.py +970 -0
- loopx/global_todos.py +568 -0
- loopx/handoff_budget.py +28 -0
- loopx/heartbeat_prequota.py +80 -0
- loopx/heartbeat_prompt.py +159 -0
- loopx/help_surface.py +516 -0
- loopx/history.py +1507 -0
- loopx/host_loop_activation.py +1311 -0
- loopx/host_mode_planner.py +991 -0
- loopx/install_contract.py +1 -0
- loopx/interface_budget.py +196 -0
- loopx/long_task_cadence.py +208 -0
- loopx/materials.py +185 -0
- loopx/ml_experiment.py +3 -0
- loopx/onboarding.py +214 -0
- loopx/opencode2_goal_mode/README.md +81 -0
- loopx/opencode2_goal_mode/__init__.py +9 -0
- loopx/opencode2_goal_mode/opencode2-goal-worker.mjs +1018 -0
- loopx/opencode_goal_mode/README.md +99 -0
- loopx/opencode_goal_mode/__init__.py +13 -0
- loopx/opencode_goal_mode/goal-bridge-runtime.mjs +858 -0
- loopx/opencode_goal_mode/loopx-goal.js +8 -0
- loopx/operator_gate.py +420 -0
- loopx/orchestration.py +127 -0
- loopx/paths.py +59 -0
- loopx/pi_goal_mode/README.md +67 -0
- loopx/pi_goal_mode/__init__.py +13 -0
- loopx/pi_goal_mode/loopx-goal.ts +254 -0
- loopx/pi_goal_mode/pi-goal-loop-runtime.mjs +574 -0
- loopx/pr_review.py +1206 -0
- loopx/presentation/__init__.py +1 -0
- loopx/presentation/explore_views.py +1334 -0
- loopx/presentation/markdown.py +61 -0
- loopx/presentation/projection_source_reconcile.py +140 -0
- loopx/presentation/public_safety.py +42 -0
- loopx/presentation/renderers/__init__.py +17 -0
- loopx/presentation/renderers/goal_channel_html.py +269 -0
- loopx/presentation/renderers/periodic_report_html.py +786 -0
- loopx/presentation/renderers/periodic_report_markdown.py +184 -0
- loopx/presentation/renderers/quota_event_markdown.py +116 -0
- loopx/presentation/renderers/quota_markdown.py +1112 -0
- loopx/presentation/renderers/status_markdown.py +1570 -0
- loopx/presentation/renderers/trajectory_hygiene_markdown.py +39 -0
- loopx/presentation/renderers/turn_envelope_markdown.py +33 -0
- loopx/presentation/sinks/__init__.py +5 -0
- loopx/presentation/sinks/openviking_periodic_report.py +7 -0
- loopx/presentation/static_site.py +691 -0
- loopx/presets.py +369 -0
- loopx/project_alias.py +217 -0
- loopx/project_map.py +589 -0
- loopx/project_prompt.py +1153 -0
- loopx/project_skill_cli.py +125 -0
- loopx/project_skill_delivery.py +470 -0
- loopx/project_uninstall.py +462 -0
- loopx/promotion_gate.py +197 -0
- loopx/quota.py +1197 -0
- loopx/ready_score.py +413 -0
- loopx/registry.py +621 -0
- loopx/registry_writability.py +64 -0
- loopx/release_candidate.py +148 -0
- loopx/release_manifest.py +316 -0
- loopx/repository_identity.py +100 -0
- loopx/review_packet.py +1024 -0
- loopx/rollout_event_log.py +505 -0
- loopx/runtime.py +112 -0
- loopx/self_update.py +750 -0
- loopx/session_runtime.py +418 -0
- loopx/skill_install_readback.py +500 -0
- loopx/slash_command_install.py +1393 -0
- loopx/slash_commands.py +264 -0
- loopx/state_backup.py +573 -0
- loopx/state_migration.py +350 -0
- loopx/state_projection.py +809 -0
- loopx/state_refresh.py +1416 -0
- loopx/status.py +1383 -0
- loopx/status_server.py +935 -0
- loopx/summary_all.py +725 -0
- loopx/terminal_bench_agent.py +2056 -0
- loopx/thread_agent_binding.py +408 -0
- loopx/todo_followups.py +168 -0
- loopx/todo_suggestion_prompt.py +204 -0
- loopx/todos.py +2229 -0
- loopx/turn_identity.py +17 -0
- loopx/upgrade.py +1083 -0
- loopx/visible_governance.py +667 -0
- loopx/visible_multi_agent_launcher.py +1253 -0
- loopx/visible_multi_agent_tmux.py +429 -0
- loopx/worker_bridge.py +1574 -0
- loopx-0.4.8.dist-info/METADATA +708 -0
- loopx-0.4.8.dist-info/RECORD +811 -0
- loopx-0.4.8.dist-info/WHEEL +5 -0
- loopx-0.4.8.dist-info/entry_points.txt +5 -0
- loopx-0.4.8.dist-info/licenses/LICENSE +202 -0
- loopx-0.4.8.dist-info/licenses/LICENSE-MIT +21 -0
- loopx-0.4.8.dist-info/licenses/NOTICE +6 -0
- loopx-0.4.8.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,981 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Iterable
|
|
9
|
+
|
|
10
|
+
from .control_plane.runtime.time import now_utc_iso as runtime_now_utc_iso
|
|
11
|
+
from .file_lock import exclusive_file_lock
|
|
12
|
+
from .control_plane.todos.contract import (
|
|
13
|
+
TODO_MONITOR_METADATA_FIELDS,
|
|
14
|
+
TODO_STATUS_DONE,
|
|
15
|
+
TODO_STATUS_BLOCKED,
|
|
16
|
+
TODO_STATUS_DEFERRED,
|
|
17
|
+
TODO_STATUS_OPEN,
|
|
18
|
+
TODO_TASK_PATTERN,
|
|
19
|
+
build_todo_id,
|
|
20
|
+
format_todo_metadata_line,
|
|
21
|
+
normalize_explicit_todo_task_class,
|
|
22
|
+
normalize_required_capabilities,
|
|
23
|
+
normalize_required_write_scopes,
|
|
24
|
+
normalize_removed_todo_continuation_policy,
|
|
25
|
+
normalize_todo_action_kind,
|
|
26
|
+
normalize_todo_blocks_agent,
|
|
27
|
+
normalize_todo_bound_agent,
|
|
28
|
+
normalize_todo_capability_binding_ref,
|
|
29
|
+
normalize_todo_claimed_by,
|
|
30
|
+
normalize_todo_continuation_policy,
|
|
31
|
+
normalize_todo_excluded_agents,
|
|
32
|
+
normalize_todo_global_gate,
|
|
33
|
+
normalize_todo_goal_bound,
|
|
34
|
+
normalize_todo_id,
|
|
35
|
+
normalize_todo_id_list,
|
|
36
|
+
normalize_todo_status,
|
|
37
|
+
normalize_todo_task_domain,
|
|
38
|
+
normalize_todo_task_repository,
|
|
39
|
+
parse_todo_metadata_line,
|
|
40
|
+
todo_done_for_status,
|
|
41
|
+
todo_marker_for_status,
|
|
42
|
+
todo_status_from_marker,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
STATE_EVENT_SCHEMA_VERSION = "loopx_state_event_v0"
|
|
47
|
+
STATE_PROJECTION_SCHEMA_VERSION = "event_sourced_state_projection_v0"
|
|
48
|
+
STATE_PROJECTION_VERSION = "event_sourced_state_contract_v0"
|
|
49
|
+
|
|
50
|
+
PUBLIC_PRIVACY = "public_safe"
|
|
51
|
+
LOCAL_PRIVATE_PRIVACY = "local_private"
|
|
52
|
+
PRIVATE_POINTER_PRIVACY = "private_pointer"
|
|
53
|
+
PRIVACY_VALUES = {PUBLIC_PRIVACY, LOCAL_PRIVATE_PRIVACY, PRIVATE_POINTER_PRIVACY}
|
|
54
|
+
|
|
55
|
+
TODO_ADDED = "todo_added"
|
|
56
|
+
TODO_CLAIMED = "todo_claimed"
|
|
57
|
+
TODO_UPDATED = "todo_updated"
|
|
58
|
+
TODO_BLOCKED = "todo_blocked"
|
|
59
|
+
TODO_DEFERRED = "todo_deferred"
|
|
60
|
+
TODO_COMPLETED = "todo_completed"
|
|
61
|
+
REFRESH_RECORDED = "refresh_recorded"
|
|
62
|
+
RUN_RECORDED = "run_recorded"
|
|
63
|
+
QUOTA_SPENT = "quota_spent"
|
|
64
|
+
EVIDENCE_ATTACHED = "evidence_attached"
|
|
65
|
+
SUPERVISOR_PROPOSED = "supervisor_proposed"
|
|
66
|
+
SUPERVISOR_RECEIPT_RECORDED = "supervisor_receipt_recorded"
|
|
67
|
+
|
|
68
|
+
MARKDOWN_BACKFILL_PRODUCER = "loopx.backfill"
|
|
69
|
+
MARKDOWN_HEADING_PATTERN = re.compile(r"^##\s+(.+?)\s*$")
|
|
70
|
+
TODO_PRIORITY_PREFIX_PATTERN = re.compile(r"^\[(P[0-4])\]\s+(.+)$", re.IGNORECASE)
|
|
71
|
+
PUBLIC_BACKFILL_REDACTION = "[redacted-private-state]"
|
|
72
|
+
PUBLIC_BACKFILL_UNSAFE_PATTERNS = (
|
|
73
|
+
re.compile(r"(?i)(?:^|[\s`'\"])(?:/Users/|/private/|/var/folders/)"),
|
|
74
|
+
re.compile(r"(?i)\b(?:secret|password|credential|token)\b"),
|
|
75
|
+
re.compile(r"https?://"),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
SUPPORTED_EVENT_TYPES = {
|
|
79
|
+
TODO_ADDED,
|
|
80
|
+
TODO_CLAIMED,
|
|
81
|
+
TODO_UPDATED,
|
|
82
|
+
TODO_BLOCKED,
|
|
83
|
+
TODO_DEFERRED,
|
|
84
|
+
TODO_COMPLETED,
|
|
85
|
+
REFRESH_RECORDED,
|
|
86
|
+
RUN_RECORDED,
|
|
87
|
+
QUOTA_SPENT,
|
|
88
|
+
EVIDENCE_ATTACHED,
|
|
89
|
+
SUPERVISOR_PROPOSED,
|
|
90
|
+
SUPERVISOR_RECEIPT_RECORDED,
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
TODO_EVENT_TYPES = {
|
|
94
|
+
TODO_ADDED,
|
|
95
|
+
TODO_CLAIMED,
|
|
96
|
+
TODO_UPDATED,
|
|
97
|
+
TODO_BLOCKED,
|
|
98
|
+
TODO_DEFERRED,
|
|
99
|
+
TODO_COMPLETED,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class StateEventError(ValueError):
|
|
104
|
+
"""Raised when a state event cannot be accepted or replayed."""
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class StateEventConflictError(StateEventError):
|
|
108
|
+
"""Raised when a duplicate event id carries different event content."""
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def now_utc_iso() -> str:
|
|
112
|
+
return runtime_now_utc_iso()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def compact_text(value: Any) -> str:
|
|
116
|
+
return " ".join(str(value or "").strip().split())
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _redact_public_backfill_text(value: Any, *, privacy: str) -> str:
|
|
120
|
+
text = compact_text(value)
|
|
121
|
+
if privacy != PUBLIC_PRIVACY:
|
|
122
|
+
return text
|
|
123
|
+
if any(pattern.search(text) for pattern in PUBLIC_BACKFILL_UNSAFE_PATTERNS):
|
|
124
|
+
return PUBLIC_BACKFILL_REDACTION
|
|
125
|
+
return text
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _redact_public_backfill_source_ref(value: Any, *, privacy: str) -> str:
|
|
129
|
+
text = compact_text(value) or "ACTIVE_GOAL_STATE.md"
|
|
130
|
+
if privacy != PUBLIC_PRIVACY:
|
|
131
|
+
return text
|
|
132
|
+
if any(pattern.search(text) for pattern in PUBLIC_BACKFILL_UNSAFE_PATTERNS):
|
|
133
|
+
return "ACTIVE_GOAL_STATE.md"
|
|
134
|
+
return text
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _role_for_markdown_heading(heading: str) -> str | None:
|
|
138
|
+
normalized = compact_text(heading).lower()
|
|
139
|
+
if normalized.startswith("user todo") or "owner review" in normalized:
|
|
140
|
+
return "user"
|
|
141
|
+
if normalized.startswith("agent todo"):
|
|
142
|
+
return "agent"
|
|
143
|
+
return None
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _todo_priority_and_title(text: Any, *, privacy: str) -> tuple[str, str]:
|
|
147
|
+
compact = compact_text(text)
|
|
148
|
+
match = TODO_PRIORITY_PREFIX_PATTERN.match(compact)
|
|
149
|
+
if match:
|
|
150
|
+
return match.group(1).upper(), _redact_public_backfill_text(match.group(2), privacy=privacy)
|
|
151
|
+
return "P2", _redact_public_backfill_text(compact, privacy=privacy)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _backfill_event_id(*, goal_id: str, todo_id: str, suffix: str) -> str:
|
|
155
|
+
digest = hashlib.sha1(f"{goal_id}|{todo_id}|{suffix}".encode("utf-8")).hexdigest()[:16]
|
|
156
|
+
return f"backfill-{suffix}-{digest}"
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _backfill_source_refs(
|
|
160
|
+
*,
|
|
161
|
+
source_ref: str,
|
|
162
|
+
source_section: str,
|
|
163
|
+
source_line: int | None,
|
|
164
|
+
privacy: str,
|
|
165
|
+
) -> dict[str, Any]:
|
|
166
|
+
refs: dict[str, Any] = {
|
|
167
|
+
"source_ref": _redact_public_backfill_source_ref(source_ref, privacy=privacy),
|
|
168
|
+
"source_section": compact_text(source_section),
|
|
169
|
+
}
|
|
170
|
+
if source_line is not None:
|
|
171
|
+
refs["source_line"] = source_line
|
|
172
|
+
return refs
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _markdown_todo_records(state_text: str) -> list[dict[str, Any]]:
|
|
176
|
+
role: str | None = None
|
|
177
|
+
source_section: str | None = None
|
|
178
|
+
current: dict[str, Any] | None = None
|
|
179
|
+
records: list[dict[str, Any]] = []
|
|
180
|
+
role_indexes = {"user": 0, "agent": 0}
|
|
181
|
+
|
|
182
|
+
for line_number, line in enumerate(state_text.splitlines(), start=1):
|
|
183
|
+
heading_match = MARKDOWN_HEADING_PATTERN.match(line)
|
|
184
|
+
if heading_match:
|
|
185
|
+
source_section = compact_text(heading_match.group(1))
|
|
186
|
+
role = _role_for_markdown_heading(source_section)
|
|
187
|
+
current = None
|
|
188
|
+
continue
|
|
189
|
+
if role is None or source_section is None:
|
|
190
|
+
continue
|
|
191
|
+
todo_match = TODO_TASK_PATTERN.match(line)
|
|
192
|
+
if todo_match:
|
|
193
|
+
marker, text = todo_match.groups()
|
|
194
|
+
role_indexes[role] += 1
|
|
195
|
+
current = {
|
|
196
|
+
"role": role,
|
|
197
|
+
"source_section": source_section,
|
|
198
|
+
"source_line": line_number,
|
|
199
|
+
"planner_order": role_indexes[role],
|
|
200
|
+
"status": todo_status_from_marker(marker),
|
|
201
|
+
"text": compact_text(text),
|
|
202
|
+
}
|
|
203
|
+
records.append(current)
|
|
204
|
+
continue
|
|
205
|
+
if current is None or not line.startswith((" ", "\t")):
|
|
206
|
+
continue
|
|
207
|
+
metadata = parse_todo_metadata_line(line)
|
|
208
|
+
if metadata:
|
|
209
|
+
current.update(metadata)
|
|
210
|
+
continue
|
|
211
|
+
continuation = compact_text(line)
|
|
212
|
+
if continuation:
|
|
213
|
+
current["text"] = compact_text(f"{current.get('text', '')} {continuation}")
|
|
214
|
+
for record in records:
|
|
215
|
+
role = str(record.get("role") or "agent")
|
|
216
|
+
source_section = str(record.get("source_section") or "")
|
|
217
|
+
title_text = compact_text(record.get("text"))
|
|
218
|
+
if not normalize_todo_id(record.get("todo_id")):
|
|
219
|
+
record["todo_id"] = build_todo_id(
|
|
220
|
+
role=role,
|
|
221
|
+
source_section=source_section,
|
|
222
|
+
index=record.get("planner_order"),
|
|
223
|
+
text=title_text,
|
|
224
|
+
)
|
|
225
|
+
record["status"] = normalize_todo_status(record.get("status")) or TODO_STATUS_OPEN
|
|
226
|
+
return records
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def backfill_todo_events_from_markdown(
|
|
230
|
+
state_text: str,
|
|
231
|
+
*,
|
|
232
|
+
goal_id: str,
|
|
233
|
+
source_ref: str = "ACTIVE_GOAL_STATE.md",
|
|
234
|
+
recorded_at: str | None = None,
|
|
235
|
+
producer: str = MARKDOWN_BACKFILL_PRODUCER,
|
|
236
|
+
privacy: str = LOCAL_PRIVATE_PRIVACY,
|
|
237
|
+
) -> list[dict[str, Any]]:
|
|
238
|
+
"""Convert Markdown workbench todos into idempotent append-only events.
|
|
239
|
+
|
|
240
|
+
The helper does not mutate the Markdown source. When writing a public-safe
|
|
241
|
+
stream, compact todo titles/evidence/reasons that look like private state
|
|
242
|
+
are redacted; local-private streams preserve the workbench text.
|
|
243
|
+
"""
|
|
244
|
+
normalized_goal_id = compact_text(goal_id)
|
|
245
|
+
if not normalized_goal_id:
|
|
246
|
+
raise StateEventError("goal_id is required")
|
|
247
|
+
if privacy not in PRIVACY_VALUES:
|
|
248
|
+
raise StateEventError(f"privacy must be one of: {', '.join(sorted(PRIVACY_VALUES))}")
|
|
249
|
+
|
|
250
|
+
events: list[dict[str, Any]] = []
|
|
251
|
+
for record in _markdown_todo_records(state_text):
|
|
252
|
+
role = str(record.get("role") or "agent")
|
|
253
|
+
todo_id = normalize_todo_id(record.get("todo_id")) or build_todo_id(
|
|
254
|
+
role=role,
|
|
255
|
+
source_section=record.get("source_section"),
|
|
256
|
+
index=record.get("planner_order"),
|
|
257
|
+
text=record.get("text"),
|
|
258
|
+
)
|
|
259
|
+
priority, title = _todo_priority_and_title(record.get("text"), privacy=privacy)
|
|
260
|
+
refs = {
|
|
261
|
+
"todo_id": todo_id,
|
|
262
|
+
**_backfill_source_refs(
|
|
263
|
+
source_ref=source_ref,
|
|
264
|
+
source_section=str(record.get("source_section") or ""),
|
|
265
|
+
source_line=record.get("source_line"),
|
|
266
|
+
privacy=privacy,
|
|
267
|
+
),
|
|
268
|
+
}
|
|
269
|
+
payload: dict[str, Any] = {
|
|
270
|
+
"role": role,
|
|
271
|
+
"priority": priority,
|
|
272
|
+
"title": title,
|
|
273
|
+
"planner_order": record.get("planner_order"),
|
|
274
|
+
}
|
|
275
|
+
task_class = normalize_explicit_todo_task_class(record.get("task_class"))
|
|
276
|
+
action_kind = normalize_todo_action_kind(record.get("action_kind"))
|
|
277
|
+
task_domain = normalize_todo_task_domain(record.get("task_domain"))
|
|
278
|
+
capability_binding_ref = normalize_todo_capability_binding_ref(
|
|
279
|
+
record.get("capability_binding_ref")
|
|
280
|
+
)
|
|
281
|
+
task_repository = normalize_todo_task_repository(
|
|
282
|
+
record.get("task_repository")
|
|
283
|
+
)
|
|
284
|
+
continuation_policy = normalize_todo_continuation_policy(
|
|
285
|
+
record.get("continuation_policy")
|
|
286
|
+
)
|
|
287
|
+
removed_continuation_policy = normalize_removed_todo_continuation_policy(
|
|
288
|
+
record.get("removed_continuation_policy")
|
|
289
|
+
)
|
|
290
|
+
required_write_scopes = normalize_required_write_scopes(
|
|
291
|
+
record.get("required_write_scopes")
|
|
292
|
+
)
|
|
293
|
+
required_capabilities = normalize_required_capabilities(
|
|
294
|
+
record.get("required_capabilities")
|
|
295
|
+
)
|
|
296
|
+
blocks_agent = normalize_todo_blocks_agent(record.get("blocks_agent"))
|
|
297
|
+
bound_agent = normalize_todo_bound_agent(record.get("bound_agent"))
|
|
298
|
+
goal_bound = normalize_todo_goal_bound(record.get("goal_bound"))
|
|
299
|
+
global_gate = normalize_todo_global_gate(record.get("global_gate"))
|
|
300
|
+
excluded_agents = normalize_todo_excluded_agents(record.get("excluded_agents"))
|
|
301
|
+
if task_class:
|
|
302
|
+
payload["task_class"] = task_class
|
|
303
|
+
if action_kind:
|
|
304
|
+
payload["action_kind"] = action_kind
|
|
305
|
+
if task_domain:
|
|
306
|
+
payload["task_domain"] = task_domain
|
|
307
|
+
if capability_binding_ref:
|
|
308
|
+
payload["capability_binding_ref"] = capability_binding_ref
|
|
309
|
+
if task_repository:
|
|
310
|
+
payload["task_repository"] = task_repository
|
|
311
|
+
if continuation_policy:
|
|
312
|
+
payload["continuation_policy"] = continuation_policy
|
|
313
|
+
if removed_continuation_policy:
|
|
314
|
+
payload["removed_continuation_policy"] = removed_continuation_policy
|
|
315
|
+
if required_write_scopes:
|
|
316
|
+
payload["required_write_scopes"] = required_write_scopes
|
|
317
|
+
if required_capabilities:
|
|
318
|
+
payload["required_capabilities"] = required_capabilities
|
|
319
|
+
if blocks_agent:
|
|
320
|
+
payload["blocks_agent"] = blocks_agent
|
|
321
|
+
if bound_agent:
|
|
322
|
+
payload["bound_agent"] = bound_agent
|
|
323
|
+
if goal_bound is not None:
|
|
324
|
+
payload["goal_bound"] = goal_bound
|
|
325
|
+
if global_gate is not None:
|
|
326
|
+
payload["global_gate"] = global_gate
|
|
327
|
+
if excluded_agents:
|
|
328
|
+
payload["excluded_agents"] = excluded_agents
|
|
329
|
+
events.append(
|
|
330
|
+
make_state_event(
|
|
331
|
+
event_id=_backfill_event_id(goal_id=normalized_goal_id, todo_id=todo_id, suffix="add"),
|
|
332
|
+
goal_id=normalized_goal_id,
|
|
333
|
+
event_type=TODO_ADDED,
|
|
334
|
+
refs=refs,
|
|
335
|
+
payload=payload,
|
|
336
|
+
recorded_at=recorded_at,
|
|
337
|
+
producer=producer,
|
|
338
|
+
privacy=privacy,
|
|
339
|
+
)
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
claimed_by = normalize_todo_claimed_by(record.get("claimed_by"))
|
|
343
|
+
if claimed_by:
|
|
344
|
+
events.append(
|
|
345
|
+
make_state_event(
|
|
346
|
+
event_id=_backfill_event_id(goal_id=normalized_goal_id, todo_id=todo_id, suffix="claim"),
|
|
347
|
+
goal_id=normalized_goal_id,
|
|
348
|
+
event_type=TODO_CLAIMED,
|
|
349
|
+
refs=refs,
|
|
350
|
+
payload={"claimed_by": claimed_by},
|
|
351
|
+
recorded_at=recorded_at,
|
|
352
|
+
producer=producer,
|
|
353
|
+
privacy=privacy,
|
|
354
|
+
)
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
status = normalize_todo_status(record.get("status")) or TODO_STATUS_OPEN
|
|
358
|
+
if status == TODO_STATUS_DONE:
|
|
359
|
+
completion_payload: dict[str, Any] = {}
|
|
360
|
+
for key in ("evidence", "reason"):
|
|
361
|
+
if record.get(key):
|
|
362
|
+
completion_payload[key] = _redact_public_backfill_text(record[key], privacy=privacy)
|
|
363
|
+
events.append(
|
|
364
|
+
make_state_event(
|
|
365
|
+
event_id=_backfill_event_id(goal_id=normalized_goal_id, todo_id=todo_id, suffix="complete"),
|
|
366
|
+
goal_id=normalized_goal_id,
|
|
367
|
+
event_type=TODO_COMPLETED,
|
|
368
|
+
refs=refs,
|
|
369
|
+
payload=completion_payload,
|
|
370
|
+
recorded_at=recorded_at,
|
|
371
|
+
producer=producer,
|
|
372
|
+
privacy=privacy,
|
|
373
|
+
)
|
|
374
|
+
)
|
|
375
|
+
elif status == TODO_STATUS_DEFERRED:
|
|
376
|
+
deferred_payload = {}
|
|
377
|
+
for key in ("reason", "resume_when"):
|
|
378
|
+
if record.get(key):
|
|
379
|
+
deferred_payload[key] = _redact_public_backfill_text(record[key], privacy=privacy)
|
|
380
|
+
events.append(
|
|
381
|
+
make_state_event(
|
|
382
|
+
event_id=_backfill_event_id(goal_id=normalized_goal_id, todo_id=todo_id, suffix="defer"),
|
|
383
|
+
goal_id=normalized_goal_id,
|
|
384
|
+
event_type=TODO_DEFERRED,
|
|
385
|
+
refs=refs,
|
|
386
|
+
payload=deferred_payload,
|
|
387
|
+
recorded_at=recorded_at,
|
|
388
|
+
producer=producer,
|
|
389
|
+
privacy=privacy,
|
|
390
|
+
)
|
|
391
|
+
)
|
|
392
|
+
elif status == TODO_STATUS_BLOCKED:
|
|
393
|
+
blocked_payload = {}
|
|
394
|
+
if record.get("reason"):
|
|
395
|
+
blocked_payload["reason"] = _redact_public_backfill_text(record["reason"], privacy=privacy)
|
|
396
|
+
events.append(
|
|
397
|
+
make_state_event(
|
|
398
|
+
event_id=_backfill_event_id(goal_id=normalized_goal_id, todo_id=todo_id, suffix="block"),
|
|
399
|
+
goal_id=normalized_goal_id,
|
|
400
|
+
event_type=TODO_BLOCKED,
|
|
401
|
+
refs=refs,
|
|
402
|
+
payload=blocked_payload,
|
|
403
|
+
recorded_at=recorded_at,
|
|
404
|
+
producer=producer,
|
|
405
|
+
privacy=privacy,
|
|
406
|
+
)
|
|
407
|
+
)
|
|
408
|
+
return events
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def _sorted_dict(value: dict[str, Any]) -> dict[str, Any]:
|
|
412
|
+
return {key: value[key] for key in sorted(value)}
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def event_fingerprint(event: dict[str, Any]) -> str:
|
|
416
|
+
comparable = {key: value for key, value in event.items() if key != "append_sequence"}
|
|
417
|
+
return json.dumps(comparable, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def event_stream_checksum(events: Iterable[dict[str, Any]]) -> str:
|
|
421
|
+
body = "\n".join(
|
|
422
|
+
json.dumps(event, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
|
|
423
|
+
for event in events
|
|
424
|
+
)
|
|
425
|
+
return "sha256:" + hashlib.sha256(body.encode("utf-8")).hexdigest()
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def _require_dict(value: Any, *, field_name: str) -> dict[str, Any]:
|
|
429
|
+
if value is None:
|
|
430
|
+
return {}
|
|
431
|
+
if not isinstance(value, dict):
|
|
432
|
+
raise StateEventError(f"{field_name} must be an object")
|
|
433
|
+
return dict(value)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def normalize_state_event(event: dict[str, Any], *, append_sequence: int | None = None) -> dict[str, Any]:
|
|
437
|
+
if not isinstance(event, dict):
|
|
438
|
+
raise StateEventError("event must be an object")
|
|
439
|
+
|
|
440
|
+
event_id = compact_text(event.get("event_id"))
|
|
441
|
+
goal_id = compact_text(event.get("goal_id"))
|
|
442
|
+
event_type = compact_text(event.get("event_type"))
|
|
443
|
+
if not event_id:
|
|
444
|
+
raise StateEventError("event_id is required")
|
|
445
|
+
if not goal_id:
|
|
446
|
+
raise StateEventError("goal_id is required")
|
|
447
|
+
if event_type not in SUPPORTED_EVENT_TYPES:
|
|
448
|
+
raise StateEventError(f"unsupported event_type: {event_type}")
|
|
449
|
+
|
|
450
|
+
refs = _require_dict(event.get("refs"), field_name="refs")
|
|
451
|
+
if refs.get("mutates_prior_event_id"):
|
|
452
|
+
raise StateEventError("events must not mutate prior events")
|
|
453
|
+
payload = _require_dict(event.get("payload"), field_name="payload")
|
|
454
|
+
|
|
455
|
+
if event_type in TODO_EVENT_TYPES:
|
|
456
|
+
todo_id = normalize_todo_id(refs.get("todo_id"))
|
|
457
|
+
if not todo_id:
|
|
458
|
+
raise StateEventError(f"{event_type} requires refs.todo_id")
|
|
459
|
+
refs["todo_id"] = todo_id
|
|
460
|
+
if payload.get("capability_binding_ref") is not None:
|
|
461
|
+
capability_binding_ref = normalize_todo_capability_binding_ref(
|
|
462
|
+
payload.get("capability_binding_ref")
|
|
463
|
+
)
|
|
464
|
+
if not capability_binding_ref:
|
|
465
|
+
raise StateEventError(
|
|
466
|
+
"capability_binding_ref must be a public-safe namespaced token"
|
|
467
|
+
)
|
|
468
|
+
payload["capability_binding_ref"] = capability_binding_ref
|
|
469
|
+
if payload.get("task_domain") is not None:
|
|
470
|
+
task_domain = normalize_todo_task_domain(payload.get("task_domain"))
|
|
471
|
+
if not task_domain:
|
|
472
|
+
raise StateEventError(
|
|
473
|
+
"task_domain must be a public-safe lowercase token"
|
|
474
|
+
)
|
|
475
|
+
payload["task_domain"] = task_domain
|
|
476
|
+
|
|
477
|
+
privacy = compact_text(event.get("privacy") or PUBLIC_PRIVACY)
|
|
478
|
+
if privacy not in PRIVACY_VALUES:
|
|
479
|
+
raise StateEventError(f"privacy must be one of: {', '.join(sorted(PRIVACY_VALUES))}")
|
|
480
|
+
|
|
481
|
+
sequence = append_sequence if append_sequence is not None else event.get("append_sequence")
|
|
482
|
+
if sequence is not None:
|
|
483
|
+
try:
|
|
484
|
+
sequence = int(sequence)
|
|
485
|
+
except (TypeError, ValueError) as exc:
|
|
486
|
+
raise StateEventError("append_sequence must be an integer") from exc
|
|
487
|
+
if sequence < 1:
|
|
488
|
+
raise StateEventError("append_sequence must be positive")
|
|
489
|
+
|
|
490
|
+
normalized = {
|
|
491
|
+
"schema_version": compact_text(event.get("schema_version") or STATE_EVENT_SCHEMA_VERSION),
|
|
492
|
+
"event_id": event_id,
|
|
493
|
+
"goal_id": goal_id,
|
|
494
|
+
"event_type": event_type,
|
|
495
|
+
"recorded_at": compact_text(event.get("recorded_at") or now_utc_iso()),
|
|
496
|
+
"producer": compact_text(event.get("producer") or "loopx.event_sourced_state"),
|
|
497
|
+
"privacy": privacy,
|
|
498
|
+
"projection_version": compact_text(event.get("projection_version") or STATE_PROJECTION_VERSION),
|
|
499
|
+
"refs": _sorted_dict(refs),
|
|
500
|
+
"payload": _sorted_dict(payload),
|
|
501
|
+
}
|
|
502
|
+
actor_agent_id = normalize_todo_claimed_by(event.get("actor_agent_id"))
|
|
503
|
+
if actor_agent_id:
|
|
504
|
+
normalized["actor_agent_id"] = actor_agent_id
|
|
505
|
+
if normalized["schema_version"] != STATE_EVENT_SCHEMA_VERSION:
|
|
506
|
+
raise StateEventError(f"schema_version must be {STATE_EVENT_SCHEMA_VERSION}")
|
|
507
|
+
if sequence is not None:
|
|
508
|
+
normalized["append_sequence"] = sequence
|
|
509
|
+
return normalized
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def make_state_event(
|
|
513
|
+
*,
|
|
514
|
+
event_id: str,
|
|
515
|
+
goal_id: str,
|
|
516
|
+
event_type: str,
|
|
517
|
+
refs: dict[str, Any] | None = None,
|
|
518
|
+
payload: dict[str, Any] | None = None,
|
|
519
|
+
recorded_at: str | None = None,
|
|
520
|
+
producer: str | None = None,
|
|
521
|
+
privacy: str = PUBLIC_PRIVACY,
|
|
522
|
+
projection_version: str = STATE_PROJECTION_VERSION,
|
|
523
|
+
actor_agent_id: str | None = None,
|
|
524
|
+
) -> dict[str, Any]:
|
|
525
|
+
return normalize_state_event(
|
|
526
|
+
{
|
|
527
|
+
"schema_version": STATE_EVENT_SCHEMA_VERSION,
|
|
528
|
+
"event_id": event_id,
|
|
529
|
+
"goal_id": goal_id,
|
|
530
|
+
"event_type": event_type,
|
|
531
|
+
"recorded_at": recorded_at or now_utc_iso(),
|
|
532
|
+
"producer": producer or "loopx.event_sourced_state",
|
|
533
|
+
"privacy": privacy,
|
|
534
|
+
"projection_version": projection_version,
|
|
535
|
+
"refs": refs or {},
|
|
536
|
+
"payload": payload or {},
|
|
537
|
+
"actor_agent_id": actor_agent_id,
|
|
538
|
+
}
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
@dataclass
|
|
543
|
+
class AppendOnlyStateEventStore:
|
|
544
|
+
path: Path
|
|
545
|
+
_events: list[dict[str, Any]] = field(default_factory=list)
|
|
546
|
+
_loaded: bool = False
|
|
547
|
+
|
|
548
|
+
def load(self) -> list[dict[str, Any]]:
|
|
549
|
+
if self._loaded:
|
|
550
|
+
return list(self._events)
|
|
551
|
+
events: list[dict[str, Any]] = []
|
|
552
|
+
if self.path.exists():
|
|
553
|
+
for line_number, line in enumerate(self.path.read_text(encoding="utf-8").splitlines(), start=1):
|
|
554
|
+
if not line.strip():
|
|
555
|
+
continue
|
|
556
|
+
try:
|
|
557
|
+
raw = json.loads(line)
|
|
558
|
+
except json.JSONDecodeError as exc:
|
|
559
|
+
raise StateEventError(f"invalid JSONL at line {line_number}: {exc}") from exc
|
|
560
|
+
events.append(normalize_state_event(raw))
|
|
561
|
+
self._events = _dedupe_events(events)
|
|
562
|
+
self._loaded = True
|
|
563
|
+
return list(self._events)
|
|
564
|
+
|
|
565
|
+
def append(self, event: dict[str, Any]) -> dict[str, Any]:
|
|
566
|
+
with exclusive_file_lock(self.path):
|
|
567
|
+
self._loaded = False
|
|
568
|
+
events = self.load()
|
|
569
|
+
existing = {item["event_id"]: item for item in events}
|
|
570
|
+
next_sequence = max((int(item["append_sequence"]) for item in events), default=0) + 1
|
|
571
|
+
normalized = normalize_state_event(event, append_sequence=next_sequence)
|
|
572
|
+
prior = existing.get(normalized["event_id"])
|
|
573
|
+
if prior is not None:
|
|
574
|
+
if event_fingerprint(prior) != event_fingerprint(normalized):
|
|
575
|
+
raise StateEventConflictError(f"conflicting event_id: {normalized['event_id']}")
|
|
576
|
+
return prior
|
|
577
|
+
|
|
578
|
+
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
579
|
+
with self.path.open("a", encoding="utf-8") as stream:
|
|
580
|
+
stream.write(json.dumps(normalized, sort_keys=True, ensure_ascii=False) + "\n")
|
|
581
|
+
self._events.append(normalized)
|
|
582
|
+
return normalized
|
|
583
|
+
|
|
584
|
+
def append_many(self, events: Iterable[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
585
|
+
return [self.append(event) for event in events]
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
def _dedupe_events(events: Iterable[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
589
|
+
by_id: dict[str, dict[str, Any]] = {}
|
|
590
|
+
ordered: list[dict[str, Any]] = []
|
|
591
|
+
for event in events:
|
|
592
|
+
prior = by_id.get(event["event_id"])
|
|
593
|
+
if prior is not None:
|
|
594
|
+
if event_fingerprint(prior) != event_fingerprint(event):
|
|
595
|
+
raise StateEventConflictError(f"conflicting event_id: {event['event_id']}")
|
|
596
|
+
continue
|
|
597
|
+
by_id[event["event_id"]] = event
|
|
598
|
+
ordered.append(event)
|
|
599
|
+
return ordered
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
def event_sort_key(event: dict[str, Any]) -> tuple[int, str, str]:
|
|
603
|
+
return (
|
|
604
|
+
int(event.get("append_sequence") or 0),
|
|
605
|
+
str(event.get("recorded_at") or ""),
|
|
606
|
+
str(event.get("event_id") or ""),
|
|
607
|
+
)
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
def _todo_from_added_event(event: dict[str, Any]) -> dict[str, Any]:
|
|
611
|
+
payload = event.get("payload") or {}
|
|
612
|
+
refs = event.get("refs") or {}
|
|
613
|
+
text = compact_text(payload.get("text") or payload.get("title"))
|
|
614
|
+
role = compact_text(payload.get("role") or "agent")
|
|
615
|
+
source_section = (
|
|
616
|
+
"User Todo / Owner Review Reading Queue" if role == "user" else "Agent Todo"
|
|
617
|
+
)
|
|
618
|
+
todo_id = normalize_todo_id(refs.get("todo_id")) or build_todo_id(
|
|
619
|
+
role=role,
|
|
620
|
+
source_section=source_section,
|
|
621
|
+
index=event.get("append_sequence"),
|
|
622
|
+
text=text,
|
|
623
|
+
)
|
|
624
|
+
task_class = normalize_explicit_todo_task_class(payload.get("task_class"))
|
|
625
|
+
action_kind = normalize_todo_action_kind(payload.get("action_kind"))
|
|
626
|
+
task_domain = normalize_todo_task_domain(payload.get("task_domain"))
|
|
627
|
+
capability_binding_ref = normalize_todo_capability_binding_ref(
|
|
628
|
+
payload.get("capability_binding_ref")
|
|
629
|
+
)
|
|
630
|
+
task_repository = normalize_todo_task_repository(payload.get("task_repository"))
|
|
631
|
+
continuation_policy = normalize_todo_continuation_policy(
|
|
632
|
+
payload.get("continuation_policy")
|
|
633
|
+
)
|
|
634
|
+
removed_continuation_policy = normalize_removed_todo_continuation_policy(
|
|
635
|
+
payload.get("removed_continuation_policy")
|
|
636
|
+
or payload.get("continuation_policy")
|
|
637
|
+
)
|
|
638
|
+
required_write_scopes = normalize_required_write_scopes(
|
|
639
|
+
payload.get("required_write_scopes")
|
|
640
|
+
)
|
|
641
|
+
required_capabilities = normalize_required_capabilities(
|
|
642
|
+
payload.get("required_capabilities")
|
|
643
|
+
)
|
|
644
|
+
blocks_agent = normalize_todo_blocks_agent(payload.get("blocks_agent"))
|
|
645
|
+
bound_agent = normalize_todo_bound_agent(payload.get("bound_agent"))
|
|
646
|
+
goal_bound = normalize_todo_goal_bound(payload.get("goal_bound"))
|
|
647
|
+
global_gate = normalize_todo_global_gate(payload.get("global_gate"))
|
|
648
|
+
excluded_agents = normalize_todo_excluded_agents(payload.get("excluded_agents"))
|
|
649
|
+
claimed_by = normalize_todo_claimed_by(payload.get("claimed_by"))
|
|
650
|
+
actor_agent_id = normalize_todo_claimed_by(event.get("actor_agent_id"))
|
|
651
|
+
todo: dict[str, Any] = {
|
|
652
|
+
"schema_version": "todo_item_v0",
|
|
653
|
+
"todo_id": todo_id,
|
|
654
|
+
"role": role,
|
|
655
|
+
"status": TODO_STATUS_OPEN,
|
|
656
|
+
"done": False,
|
|
657
|
+
"priority": compact_text(payload.get("priority") or "P2"),
|
|
658
|
+
"title": text,
|
|
659
|
+
"text": text if not payload.get("priority") else f"[{compact_text(payload.get('priority'))}] {text}",
|
|
660
|
+
"source_section": source_section,
|
|
661
|
+
"planner_order": payload.get("planner_order"),
|
|
662
|
+
"append_sequence": event.get("append_sequence"),
|
|
663
|
+
"last_event_id": event.get("event_id"),
|
|
664
|
+
}
|
|
665
|
+
if task_class:
|
|
666
|
+
todo["task_class"] = task_class
|
|
667
|
+
if action_kind:
|
|
668
|
+
todo["action_kind"] = action_kind
|
|
669
|
+
if task_domain:
|
|
670
|
+
todo["task_domain"] = task_domain
|
|
671
|
+
if capability_binding_ref:
|
|
672
|
+
todo["capability_binding_ref"] = capability_binding_ref
|
|
673
|
+
if task_repository:
|
|
674
|
+
todo["task_repository"] = task_repository
|
|
675
|
+
if removed_continuation_policy:
|
|
676
|
+
todo["removed_continuation_policy"] = removed_continuation_policy
|
|
677
|
+
elif continuation_policy:
|
|
678
|
+
todo["continuation_policy"] = continuation_policy
|
|
679
|
+
if required_write_scopes:
|
|
680
|
+
todo["required_write_scopes"] = required_write_scopes
|
|
681
|
+
if required_capabilities:
|
|
682
|
+
todo["required_capabilities"] = required_capabilities
|
|
683
|
+
if blocks_agent:
|
|
684
|
+
todo["blocks_agent"] = blocks_agent
|
|
685
|
+
if bound_agent:
|
|
686
|
+
todo["bound_agent"] = bound_agent
|
|
687
|
+
if goal_bound is not None:
|
|
688
|
+
todo["goal_bound"] = goal_bound
|
|
689
|
+
if global_gate is not None:
|
|
690
|
+
todo["global_gate"] = global_gate
|
|
691
|
+
if excluded_agents:
|
|
692
|
+
todo["excluded_agents"] = excluded_agents
|
|
693
|
+
unblocks_todo_id = normalize_todo_id(payload.get("unblocks_todo_id"))
|
|
694
|
+
if unblocks_todo_id:
|
|
695
|
+
todo["unblocks_todo_id"] = unblocks_todo_id
|
|
696
|
+
for key in TODO_MONITOR_METADATA_FIELDS:
|
|
697
|
+
if payload.get(key):
|
|
698
|
+
todo[key] = compact_text(payload[key])
|
|
699
|
+
if claimed_by:
|
|
700
|
+
todo["claimed_by"] = claimed_by
|
|
701
|
+
if actor_agent_id:
|
|
702
|
+
todo["created_by"] = actor_agent_id
|
|
703
|
+
return todo
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
def _update_todo_from_event(todo: dict[str, Any], event: dict[str, Any]) -> None:
|
|
707
|
+
payload = event.get("payload") or {}
|
|
708
|
+
event_type = event.get("event_type")
|
|
709
|
+
actor_agent_id = normalize_todo_claimed_by(event.get("actor_agent_id"))
|
|
710
|
+
if actor_agent_id:
|
|
711
|
+
todo["last_actor_agent_id"] = actor_agent_id
|
|
712
|
+
elif event_type not in (REFRESH_RECORDED, RUN_RECORDED, QUOTA_SPENT, EVIDENCE_ATTACHED):
|
|
713
|
+
todo.pop("last_actor_agent_id", None)
|
|
714
|
+
if event_type == TODO_CLAIMED:
|
|
715
|
+
claimed_by = normalize_todo_claimed_by(payload.get("claimed_by"))
|
|
716
|
+
if claimed_by:
|
|
717
|
+
todo["claimed_by"] = claimed_by
|
|
718
|
+
elif event_type == TODO_UPDATED:
|
|
719
|
+
for key in (
|
|
720
|
+
"priority",
|
|
721
|
+
"role",
|
|
722
|
+
"title",
|
|
723
|
+
"task_class",
|
|
724
|
+
"action_kind",
|
|
725
|
+
):
|
|
726
|
+
if payload.get(key):
|
|
727
|
+
todo[key] = compact_text(payload[key])
|
|
728
|
+
task_domain = normalize_todo_task_domain(payload.get("task_domain"))
|
|
729
|
+
if task_domain:
|
|
730
|
+
todo["task_domain"] = task_domain
|
|
731
|
+
capability_binding_ref = normalize_todo_capability_binding_ref(
|
|
732
|
+
payload.get("capability_binding_ref")
|
|
733
|
+
)
|
|
734
|
+
if capability_binding_ref:
|
|
735
|
+
existing_binding_ref = todo.get("capability_binding_ref")
|
|
736
|
+
if existing_binding_ref and existing_binding_ref != capability_binding_ref:
|
|
737
|
+
raise StateEventError("capability_binding_ref is immutable once set")
|
|
738
|
+
todo["capability_binding_ref"] = capability_binding_ref
|
|
739
|
+
continuation_policy = normalize_todo_continuation_policy(
|
|
740
|
+
payload.get("continuation_policy")
|
|
741
|
+
)
|
|
742
|
+
removed_continuation_policy = normalize_removed_todo_continuation_policy(
|
|
743
|
+
payload.get("removed_continuation_policy")
|
|
744
|
+
or payload.get("continuation_policy")
|
|
745
|
+
)
|
|
746
|
+
update_excluded_agents = normalize_todo_excluded_agents(
|
|
747
|
+
payload.get("excluded_agents")
|
|
748
|
+
)
|
|
749
|
+
if removed_continuation_policy:
|
|
750
|
+
todo.pop("continuation_policy", None)
|
|
751
|
+
todo["removed_continuation_policy"] = removed_continuation_policy
|
|
752
|
+
elif continuation_policy:
|
|
753
|
+
explicit_repair = (
|
|
754
|
+
todo.get("removed_continuation_policy")
|
|
755
|
+
and continuation_policy == "independent_handoff"
|
|
756
|
+
and bool(update_excluded_agents)
|
|
757
|
+
)
|
|
758
|
+
if not todo.get("removed_continuation_policy") or explicit_repair:
|
|
759
|
+
todo["continuation_policy"] = continuation_policy
|
|
760
|
+
if explicit_repair:
|
|
761
|
+
todo.pop("removed_continuation_policy", None)
|
|
762
|
+
required_write_scopes = normalize_required_write_scopes(
|
|
763
|
+
payload.get("required_write_scopes")
|
|
764
|
+
)
|
|
765
|
+
if required_write_scopes:
|
|
766
|
+
todo["required_write_scopes"] = required_write_scopes
|
|
767
|
+
task_repository = normalize_todo_task_repository(
|
|
768
|
+
payload.get("task_repository")
|
|
769
|
+
)
|
|
770
|
+
if task_repository:
|
|
771
|
+
todo["task_repository"] = task_repository
|
|
772
|
+
required_capabilities = normalize_required_capabilities(
|
|
773
|
+
payload.get("required_capabilities")
|
|
774
|
+
)
|
|
775
|
+
if required_capabilities:
|
|
776
|
+
todo["required_capabilities"] = required_capabilities
|
|
777
|
+
blocks_agent = normalize_todo_blocks_agent(payload.get("blocks_agent"))
|
|
778
|
+
if blocks_agent:
|
|
779
|
+
todo["blocks_agent"] = blocks_agent
|
|
780
|
+
bound_agent = normalize_todo_bound_agent(payload.get("bound_agent"))
|
|
781
|
+
if bound_agent:
|
|
782
|
+
todo["bound_agent"] = bound_agent
|
|
783
|
+
todo.pop("goal_bound", None)
|
|
784
|
+
goal_bound = normalize_todo_goal_bound(payload.get("goal_bound"))
|
|
785
|
+
if goal_bound is not None:
|
|
786
|
+
todo["goal_bound"] = goal_bound
|
|
787
|
+
if goal_bound:
|
|
788
|
+
todo.pop("bound_agent", None)
|
|
789
|
+
global_gate = normalize_todo_global_gate(payload.get("global_gate"))
|
|
790
|
+
if global_gate is not None:
|
|
791
|
+
todo["global_gate"] = global_gate
|
|
792
|
+
if update_excluded_agents:
|
|
793
|
+
todo["excluded_agents"] = update_excluded_agents
|
|
794
|
+
for key in TODO_MONITOR_METADATA_FIELDS:
|
|
795
|
+
if payload.get(key):
|
|
796
|
+
todo[key] = compact_text(payload[key])
|
|
797
|
+
if payload.get("text") or payload.get("title"):
|
|
798
|
+
title = compact_text(payload.get("text") or payload.get("title"))
|
|
799
|
+
todo["title"] = title
|
|
800
|
+
priority = compact_text(todo.get("priority") or "")
|
|
801
|
+
todo["text"] = f"[{priority}] {title}" if priority else title
|
|
802
|
+
elif event_type == TODO_BLOCKED:
|
|
803
|
+
todo["status"] = "blocked"
|
|
804
|
+
todo["done"] = False
|
|
805
|
+
if payload.get("reason"):
|
|
806
|
+
todo["reason"] = compact_text(payload["reason"])
|
|
807
|
+
elif event_type == TODO_DEFERRED:
|
|
808
|
+
todo["status"] = "deferred"
|
|
809
|
+
todo["done"] = False
|
|
810
|
+
if payload.get("reason"):
|
|
811
|
+
todo["reason"] = compact_text(payload["reason"])
|
|
812
|
+
if payload.get("resume_when"):
|
|
813
|
+
todo["resume_when"] = compact_text(payload["resume_when"])
|
|
814
|
+
elif event_type == TODO_COMPLETED:
|
|
815
|
+
todo["status"] = TODO_STATUS_DONE
|
|
816
|
+
todo["done"] = True
|
|
817
|
+
for key in (
|
|
818
|
+
"evidence",
|
|
819
|
+
"reason",
|
|
820
|
+
"note",
|
|
821
|
+
"completed_at",
|
|
822
|
+
"updated_at",
|
|
823
|
+
"no_followup",
|
|
824
|
+
):
|
|
825
|
+
if payload.get(key) is not None:
|
|
826
|
+
todo[key] = compact_text(payload[key])
|
|
827
|
+
successor_todo_ids = normalize_todo_id_list(payload.get("successor_todo_ids"))
|
|
828
|
+
if successor_todo_ids:
|
|
829
|
+
todo["successor_todo_ids"] = successor_todo_ids
|
|
830
|
+
todo["last_event_id"] = event.get("event_id")
|
|
831
|
+
todo["last_append_sequence"] = event.get("append_sequence")
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
def build_state_projection(
|
|
835
|
+
events: Iterable[dict[str, Any]],
|
|
836
|
+
*,
|
|
837
|
+
goal_id: str | None = None,
|
|
838
|
+
generated_at: str | None = None,
|
|
839
|
+
) -> dict[str, Any]:
|
|
840
|
+
normalized = _dedupe_events(normalize_state_event(event) for event in events)
|
|
841
|
+
ordered = sorted(normalized, key=event_sort_key)
|
|
842
|
+
inferred_goal_id = goal_id or (ordered[0]["goal_id"] if ordered else "")
|
|
843
|
+
todos: dict[str, dict[str, Any]] = {}
|
|
844
|
+
timeline: list[dict[str, Any]] = []
|
|
845
|
+
|
|
846
|
+
for event in ordered:
|
|
847
|
+
if inferred_goal_id and event["goal_id"] != inferred_goal_id:
|
|
848
|
+
raise StateEventError("all events in a projection must share one goal_id")
|
|
849
|
+
event_type = event["event_type"]
|
|
850
|
+
todo_id = (event.get("refs") or {}).get("todo_id")
|
|
851
|
+
if event_type == TODO_ADDED:
|
|
852
|
+
todo = _todo_from_added_event(event)
|
|
853
|
+
todos[todo["todo_id"]] = todo
|
|
854
|
+
elif event_type in TODO_EVENT_TYPES and todo_id:
|
|
855
|
+
todo = todos.get(todo_id)
|
|
856
|
+
if todo is None:
|
|
857
|
+
raise StateEventError(f"{event_type} references unknown todo_id: {todo_id}")
|
|
858
|
+
_update_todo_from_event(todo, event)
|
|
859
|
+
elif event_type in {REFRESH_RECORDED, RUN_RECORDED, QUOTA_SPENT, EVIDENCE_ATTACHED}:
|
|
860
|
+
timeline_entry: dict[str, Any] = {
|
|
861
|
+
"event_id": event["event_id"],
|
|
862
|
+
"event_type": event_type,
|
|
863
|
+
"append_sequence": event.get("append_sequence"),
|
|
864
|
+
"recorded_at": event.get("recorded_at"),
|
|
865
|
+
"summary": compact_text((event.get("payload") or {}).get("summary")),
|
|
866
|
+
"refs": event.get("refs") or {},
|
|
867
|
+
}
|
|
868
|
+
if event.get("actor_agent_id"):
|
|
869
|
+
timeline_entry["actor_agent_id"] = event["actor_agent_id"]
|
|
870
|
+
timeline.append(timeline_entry)
|
|
871
|
+
|
|
872
|
+
todo_items = sorted(
|
|
873
|
+
todos.values(),
|
|
874
|
+
key=lambda item: (
|
|
875
|
+
item.get("role") != "user",
|
|
876
|
+
str(item.get("priority") or "P9"),
|
|
877
|
+
int(item.get("planner_order") or 9999),
|
|
878
|
+
int(item.get("append_sequence") or 0),
|
|
879
|
+
),
|
|
880
|
+
)
|
|
881
|
+
user_todos = [item for item in todo_items if item.get("role") == "user"]
|
|
882
|
+
agent_todos = [item for item in todo_items if item.get("role") != "user"]
|
|
883
|
+
last_event = ordered[-1] if ordered else {}
|
|
884
|
+
return {
|
|
885
|
+
"schema_version": STATE_PROJECTION_SCHEMA_VERSION,
|
|
886
|
+
"goal_id": inferred_goal_id,
|
|
887
|
+
"generated_at": generated_at or now_utc_iso(),
|
|
888
|
+
"source_event_count": len(ordered),
|
|
889
|
+
"source_checksum": event_stream_checksum(ordered),
|
|
890
|
+
"last_event_id": last_event.get("event_id"),
|
|
891
|
+
"last_append_sequence": last_event.get("append_sequence"),
|
|
892
|
+
"projection_version": STATE_PROJECTION_VERSION,
|
|
893
|
+
"user_todos": _todo_summary(user_todos, role="user"),
|
|
894
|
+
"agent_todos": _todo_summary(agent_todos, role="agent"),
|
|
895
|
+
"timeline": timeline,
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
def _todo_summary(items: list[dict[str, Any]], *, role: str) -> dict[str, Any]:
|
|
900
|
+
open_items = [item for item in items if not todo_done_for_status(item.get("status"))]
|
|
901
|
+
done_items = [item for item in items if todo_done_for_status(item.get("status"))]
|
|
902
|
+
return {
|
|
903
|
+
"schema_version": "todo_summary_v0",
|
|
904
|
+
"role": role,
|
|
905
|
+
"total_count": len(items),
|
|
906
|
+
"open_count": len(open_items),
|
|
907
|
+
"done_count": len(done_items),
|
|
908
|
+
"items": items,
|
|
909
|
+
"first_open_items": open_items[:5],
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
def render_todo_markdown(item: dict[str, Any]) -> list[str]:
|
|
914
|
+
status = normalize_todo_status(item.get("status")) or TODO_STATUS_OPEN
|
|
915
|
+
marker = todo_marker_for_status(status)
|
|
916
|
+
text = compact_text(item.get("text") or item.get("title"))
|
|
917
|
+
if not text.startswith("[") and item.get("priority"):
|
|
918
|
+
text = f"[{compact_text(item.get('priority'))}] {text}"
|
|
919
|
+
lines = [f"- [{marker}] {text}"]
|
|
920
|
+
monitor_metadata = {
|
|
921
|
+
key: item.get(key)
|
|
922
|
+
for key in TODO_MONITOR_METADATA_FIELDS
|
|
923
|
+
}
|
|
924
|
+
metadata = format_todo_metadata_line(
|
|
925
|
+
todo_id=item.get("todo_id"),
|
|
926
|
+
status=status,
|
|
927
|
+
task_class=item.get("task_class"),
|
|
928
|
+
action_kind=item.get("action_kind"),
|
|
929
|
+
task_domain=item.get("task_domain"),
|
|
930
|
+
capability_binding_ref=item.get("capability_binding_ref"),
|
|
931
|
+
task_repository=item.get("task_repository"),
|
|
932
|
+
continuation_policy=item.get("continuation_policy"),
|
|
933
|
+
removed_continuation_policy=item.get("removed_continuation_policy"),
|
|
934
|
+
required_write_scopes=item.get("required_write_scopes"),
|
|
935
|
+
required_capabilities=item.get("required_capabilities"),
|
|
936
|
+
claimed_by=item.get("claimed_by"),
|
|
937
|
+
bound_agent=item.get("bound_agent"),
|
|
938
|
+
goal_bound=item.get("goal_bound"),
|
|
939
|
+
blocks_agent=item.get("blocks_agent"),
|
|
940
|
+
excluded_agents=item.get("excluded_agents"),
|
|
941
|
+
global_gate=item.get("global_gate"),
|
|
942
|
+
unblocks_todo_id=item.get("unblocks_todo_id"),
|
|
943
|
+
successor_todo_ids=item.get("successor_todo_ids"),
|
|
944
|
+
no_followup=True if item.get("no_followup") == "true" else None,
|
|
945
|
+
**monitor_metadata,
|
|
946
|
+
note=item.get("note"),
|
|
947
|
+
evidence=item.get("evidence"),
|
|
948
|
+
reason=item.get("reason"),
|
|
949
|
+
completed_at=item.get("completed_at"),
|
|
950
|
+
updated_at=item.get("updated_at"),
|
|
951
|
+
)
|
|
952
|
+
if metadata:
|
|
953
|
+
lines.append(metadata)
|
|
954
|
+
return lines
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
def render_active_state_sections(projection: dict[str, Any]) -> str:
|
|
958
|
+
lines: list[str] = []
|
|
959
|
+
for heading, summary_key in (
|
|
960
|
+
("User Todo / Owner Review Reading Queue", "user_todos"),
|
|
961
|
+
("Agent Todo", "agent_todos"),
|
|
962
|
+
):
|
|
963
|
+
items = ((projection.get(summary_key) or {}).get("items") or [])
|
|
964
|
+
if not items:
|
|
965
|
+
continue
|
|
966
|
+
if lines:
|
|
967
|
+
lines.append("")
|
|
968
|
+
lines.extend([f"## {heading}", ""])
|
|
969
|
+
for item in items:
|
|
970
|
+
lines.extend(render_todo_markdown(item))
|
|
971
|
+
|
|
972
|
+
timeline = projection.get("timeline") or []
|
|
973
|
+
if timeline:
|
|
974
|
+
if lines:
|
|
975
|
+
lines.append("")
|
|
976
|
+
lines.extend(["## Progress Ledger", ""])
|
|
977
|
+
for event in timeline:
|
|
978
|
+
event_type = compact_text(event.get("event_type"))
|
|
979
|
+
summary = compact_text(event.get("summary")) or "event recorded"
|
|
980
|
+
lines.append(f"- {event_type}: {summary}")
|
|
981
|
+
return "\n".join(lines).rstrip() + "\n"
|