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,1000 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import copy
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from collections.abc import Mapping, Sequence
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from typing import Any
|
|
10
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
11
|
+
|
|
12
|
+
from .schemas import (
|
|
13
|
+
CONTENT_OPS_ITEM_PACKET_SCHEMA_VERSION,
|
|
14
|
+
CONTENT_OPS_ITEM_PROJECTION_SCHEMA_VERSION,
|
|
15
|
+
CONTENT_OPS_ITEM_SCHEMA_VERSION,
|
|
16
|
+
CONTENT_OPS_ITEM_TRANSITION_PACKET_SCHEMA_VERSION,
|
|
17
|
+
CONTENT_OPS_ITEM_TRANSITION_RECEIPT_SCHEMA_VERSION,
|
|
18
|
+
CONTENT_OPS_QUEUE_PROJECTION_SCHEMA_VERSION,
|
|
19
|
+
CONTENT_OPS_QUEUE_STATUS_PACKET_SCHEMA_VERSION,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
ALLOWED_ITEM_KINDS = {"article", "post", "profile_update", "reply", "repost"}
|
|
23
|
+
ALLOWED_ITEM_STATES = {
|
|
24
|
+
"captured",
|
|
25
|
+
"draft",
|
|
26
|
+
"review_ready",
|
|
27
|
+
"approved",
|
|
28
|
+
"delivery_ready",
|
|
29
|
+
"published",
|
|
30
|
+
"readback_verified",
|
|
31
|
+
"skipped",
|
|
32
|
+
"superseded",
|
|
33
|
+
}
|
|
34
|
+
ALLOWED_EFFECT_KINDS = {"profile_update", "publish", "reply", "repost"}
|
|
35
|
+
TERMINAL_STATES = {"readback_verified", "skipped", "superseded"}
|
|
36
|
+
|
|
37
|
+
_TOKEN_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$")
|
|
38
|
+
_DIGEST_RE = re.compile(r"^sha256:[0-9a-f]{64}$")
|
|
39
|
+
_ITEM_KEYS = {
|
|
40
|
+
"schema_version",
|
|
41
|
+
"item_id",
|
|
42
|
+
"item_kind",
|
|
43
|
+
"channel",
|
|
44
|
+
"state",
|
|
45
|
+
"revision",
|
|
46
|
+
"content_digest",
|
|
47
|
+
"content_ref",
|
|
48
|
+
"source_refs",
|
|
49
|
+
"approval",
|
|
50
|
+
"delivery_intent",
|
|
51
|
+
"delivery_receipt",
|
|
52
|
+
"readback_receipt",
|
|
53
|
+
"superseded_by",
|
|
54
|
+
"terminal_reason",
|
|
55
|
+
"last_event",
|
|
56
|
+
"created_at",
|
|
57
|
+
"updated_at",
|
|
58
|
+
"autopublish_allowed",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _token(value: Any, label: str) -> str:
|
|
63
|
+
text = str(value or "").strip()
|
|
64
|
+
if not _TOKEN_RE.fullmatch(text):
|
|
65
|
+
raise ValueError(f"{label} must be an opaque token")
|
|
66
|
+
return text
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _digest(value: Any, label: str) -> str:
|
|
70
|
+
text = str(value or "").strip()
|
|
71
|
+
if not _DIGEST_RE.fullmatch(text):
|
|
72
|
+
raise ValueError(f"{label} must use sha256:<64 lowercase hex chars>")
|
|
73
|
+
return text
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _timestamp(value: Any, label: str) -> str:
|
|
77
|
+
text = str(value or "").strip()
|
|
78
|
+
try:
|
|
79
|
+
parsed = datetime.fromisoformat(text)
|
|
80
|
+
except ValueError as exc:
|
|
81
|
+
raise ValueError(f"{label} must be an ISO-8601 timestamp") from exc
|
|
82
|
+
if parsed.tzinfo is None:
|
|
83
|
+
raise ValueError(f"{label} must include a timezone")
|
|
84
|
+
return text
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _timestamp_value(value: Any, label: str) -> datetime:
|
|
88
|
+
return datetime.fromisoformat(_timestamp(value, label))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _public_url(value: Any, label: str) -> str:
|
|
92
|
+
text = str(value or "").strip()
|
|
93
|
+
parsed = urlsplit(text)
|
|
94
|
+
if parsed.scheme != "https" or not parsed.hostname:
|
|
95
|
+
raise ValueError(f"{label} must be a public https URL")
|
|
96
|
+
if parsed.username or parsed.password or parsed.query or parsed.fragment:
|
|
97
|
+
raise ValueError(f"{label} must not contain credentials, query, or fragment")
|
|
98
|
+
host = parsed.hostname.lower().rstrip(".")
|
|
99
|
+
if host == "localhost" or host.endswith((".localhost", ".local")):
|
|
100
|
+
raise ValueError(f"{label} must not target a local host")
|
|
101
|
+
return urlunsplit(("https", parsed.netloc, parsed.path or "/", "", ""))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _short_reason(value: Any, label: str) -> str:
|
|
105
|
+
text = " ".join(str(value or "").split())
|
|
106
|
+
if not text or len(text) > 180:
|
|
107
|
+
raise ValueError(f"{label} must contain 1-180 public-safe characters")
|
|
108
|
+
lowered = text.lower()
|
|
109
|
+
if any(
|
|
110
|
+
marker in lowered for marker in ("/users/", "/private/", "bearer ", "secret")
|
|
111
|
+
):
|
|
112
|
+
raise ValueError(f"{label} must not contain private paths or credentials")
|
|
113
|
+
return text
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _source_refs(values: Sequence[Any] | None) -> list[str]:
|
|
117
|
+
refs = [_token(value, "source_ref") for value in values or []]
|
|
118
|
+
if len(refs) != len(set(refs)):
|
|
119
|
+
raise ValueError("source_refs must be unique")
|
|
120
|
+
return refs
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _event_digest(event: Mapping[str, Any]) -> str:
|
|
124
|
+
encoded = json.dumps(
|
|
125
|
+
event, ensure_ascii=True, sort_keys=True, separators=(",", ":")
|
|
126
|
+
)
|
|
127
|
+
return "sha256:" + hashlib.sha256(encoded.encode("utf-8")).hexdigest()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _record(
|
|
131
|
+
value: Any,
|
|
132
|
+
label: str,
|
|
133
|
+
*,
|
|
134
|
+
required: set[str],
|
|
135
|
+
optional: set[str] | None = None,
|
|
136
|
+
) -> dict[str, Any] | None:
|
|
137
|
+
if value is None:
|
|
138
|
+
return None
|
|
139
|
+
if not isinstance(value, Mapping):
|
|
140
|
+
raise TypeError(f"{label} must be an object or null")
|
|
141
|
+
record = dict(value)
|
|
142
|
+
optional = optional or set()
|
|
143
|
+
missing = sorted(required - set(record))
|
|
144
|
+
extra = sorted(set(record) - required - optional)
|
|
145
|
+
if missing or extra:
|
|
146
|
+
raise ValueError(
|
|
147
|
+
f"{label} fields invalid: missing={missing}, unsupported={extra}"
|
|
148
|
+
)
|
|
149
|
+
return record
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _validate_effect_records(item: Mapping[str, Any]) -> None:
|
|
153
|
+
approval = _record(
|
|
154
|
+
item.get("approval"),
|
|
155
|
+
"approval",
|
|
156
|
+
required={
|
|
157
|
+
"approval_ref",
|
|
158
|
+
"revision",
|
|
159
|
+
"content_digest",
|
|
160
|
+
"effect_kind",
|
|
161
|
+
"account_ref",
|
|
162
|
+
"valid_from",
|
|
163
|
+
"valid_until",
|
|
164
|
+
},
|
|
165
|
+
)
|
|
166
|
+
intent = _record(
|
|
167
|
+
item.get("delivery_intent"),
|
|
168
|
+
"delivery_intent",
|
|
169
|
+
required={
|
|
170
|
+
"provider_id",
|
|
171
|
+
"effect_kind",
|
|
172
|
+
"account_ref",
|
|
173
|
+
"not_before",
|
|
174
|
+
"not_after",
|
|
175
|
+
},
|
|
176
|
+
)
|
|
177
|
+
delivery = _record(
|
|
178
|
+
item.get("delivery_receipt"),
|
|
179
|
+
"delivery_receipt",
|
|
180
|
+
required={
|
|
181
|
+
"provider_id",
|
|
182
|
+
"effect_kind",
|
|
183
|
+
"account_ref",
|
|
184
|
+
"content_digest",
|
|
185
|
+
"public_url",
|
|
186
|
+
"receipt_ref",
|
|
187
|
+
"recorded_at",
|
|
188
|
+
},
|
|
189
|
+
)
|
|
190
|
+
readback = _record(
|
|
191
|
+
item.get("readback_receipt"),
|
|
192
|
+
"readback_receipt",
|
|
193
|
+
required={"public_url", "content_digest", "readback_ref", "verified_at"},
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
state = str(item["state"])
|
|
197
|
+
if state in {"approved", "delivery_ready", "published", "readback_verified"}:
|
|
198
|
+
if approval is None:
|
|
199
|
+
raise ValueError(f"{state} item requires approval")
|
|
200
|
+
elif approval is not None:
|
|
201
|
+
raise ValueError(f"{state} item must not retain approval")
|
|
202
|
+
if state == "delivery_ready" and intent is None:
|
|
203
|
+
raise ValueError("delivery_ready item requires delivery_intent")
|
|
204
|
+
if intent is not None and state not in {
|
|
205
|
+
"delivery_ready",
|
|
206
|
+
"published",
|
|
207
|
+
"readback_verified",
|
|
208
|
+
}:
|
|
209
|
+
raise ValueError(f"{state} item must not retain delivery_intent")
|
|
210
|
+
if state in {"published", "readback_verified"} and delivery is None:
|
|
211
|
+
raise ValueError(f"{state} item requires delivery_receipt")
|
|
212
|
+
if delivery is not None and state not in {"published", "readback_verified"}:
|
|
213
|
+
raise ValueError(f"{state} item must not retain delivery_receipt")
|
|
214
|
+
if state == "readback_verified" and readback is None:
|
|
215
|
+
raise ValueError("readback_verified item requires readback_receipt")
|
|
216
|
+
if readback is not None and state != "readback_verified":
|
|
217
|
+
raise ValueError(f"{state} item must not retain readback_receipt")
|
|
218
|
+
|
|
219
|
+
if approval is not None:
|
|
220
|
+
_token(approval["approval_ref"], "approval.approval_ref")
|
|
221
|
+
if approval["revision"] != item["revision"]:
|
|
222
|
+
raise ValueError("approval revision does not match item revision")
|
|
223
|
+
if (
|
|
224
|
+
_digest(approval["content_digest"], "approval.content_digest")
|
|
225
|
+
!= item["content_digest"]
|
|
226
|
+
):
|
|
227
|
+
raise ValueError("approval content_digest does not match item")
|
|
228
|
+
if approval["effect_kind"] not in ALLOWED_EFFECT_KINDS:
|
|
229
|
+
raise ValueError("approval effect_kind is invalid")
|
|
230
|
+
if approval["account_ref"] is not None:
|
|
231
|
+
_token(approval["account_ref"], "approval.account_ref")
|
|
232
|
+
for field in ("valid_from", "valid_until"):
|
|
233
|
+
if approval[field] is not None:
|
|
234
|
+
_timestamp(approval[field], f"approval.{field}")
|
|
235
|
+
if intent is not None:
|
|
236
|
+
_token(intent["provider_id"], "delivery_intent.provider_id")
|
|
237
|
+
if intent["effect_kind"] != approval["effect_kind"]:
|
|
238
|
+
raise ValueError("delivery_intent effect_kind does not match approval")
|
|
239
|
+
if intent["account_ref"] is not None:
|
|
240
|
+
_token(intent["account_ref"], "delivery_intent.account_ref")
|
|
241
|
+
if (
|
|
242
|
+
approval.get("account_ref")
|
|
243
|
+
and intent["account_ref"] != approval["account_ref"]
|
|
244
|
+
):
|
|
245
|
+
raise ValueError("delivery_intent account_ref does not match approval")
|
|
246
|
+
for field in ("not_before", "not_after"):
|
|
247
|
+
if intent[field] is not None:
|
|
248
|
+
_timestamp(intent[field], f"delivery_intent.{field}")
|
|
249
|
+
if delivery is not None:
|
|
250
|
+
_token(delivery["provider_id"], "delivery_receipt.provider_id")
|
|
251
|
+
_token(delivery["receipt_ref"], "delivery_receipt.receipt_ref")
|
|
252
|
+
_timestamp(delivery["recorded_at"], "delivery_receipt.recorded_at")
|
|
253
|
+
_public_url(delivery["public_url"], "delivery_receipt.public_url")
|
|
254
|
+
if delivery["effect_kind"] != approval["effect_kind"]:
|
|
255
|
+
raise ValueError("delivery_receipt effect_kind does not match approval")
|
|
256
|
+
if (
|
|
257
|
+
_digest(delivery["content_digest"], "delivery_receipt.content_digest")
|
|
258
|
+
!= item["content_digest"]
|
|
259
|
+
):
|
|
260
|
+
raise ValueError("delivery_receipt content_digest does not match item")
|
|
261
|
+
expected_provider = intent.get("provider_id") if intent else None
|
|
262
|
+
if expected_provider and delivery["provider_id"] != expected_provider:
|
|
263
|
+
raise ValueError("delivery_receipt provider_id does not match intent")
|
|
264
|
+
expected_account = (
|
|
265
|
+
intent.get("account_ref") if intent else approval.get("account_ref")
|
|
266
|
+
)
|
|
267
|
+
if delivery["account_ref"] is not None:
|
|
268
|
+
_token(delivery["account_ref"], "delivery_receipt.account_ref")
|
|
269
|
+
if expected_account and delivery["account_ref"] != expected_account:
|
|
270
|
+
raise ValueError("delivery_receipt account_ref does not match approval")
|
|
271
|
+
if readback is not None:
|
|
272
|
+
_token(readback["readback_ref"], "readback_receipt.readback_ref")
|
|
273
|
+
_timestamp(readback["verified_at"], "readback_receipt.verified_at")
|
|
274
|
+
if (
|
|
275
|
+
_public_url(readback["public_url"], "readback_receipt.public_url")
|
|
276
|
+
!= delivery["public_url"]
|
|
277
|
+
):
|
|
278
|
+
raise ValueError("readback_receipt public_url does not match delivery")
|
|
279
|
+
if (
|
|
280
|
+
_digest(readback["content_digest"], "readback_receipt.content_digest")
|
|
281
|
+
!= item["content_digest"]
|
|
282
|
+
):
|
|
283
|
+
raise ValueError("readback_receipt content_digest does not match item")
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _require_item(item: Mapping[str, Any]) -> dict[str, Any]:
|
|
287
|
+
candidate = copy.deepcopy(dict(item))
|
|
288
|
+
extra = sorted(set(candidate) - _ITEM_KEYS)
|
|
289
|
+
if extra:
|
|
290
|
+
raise ValueError(f"content item contains unsupported fields: {extra}")
|
|
291
|
+
if candidate.get("schema_version") != CONTENT_OPS_ITEM_SCHEMA_VERSION:
|
|
292
|
+
raise ValueError("content item schema_version is invalid")
|
|
293
|
+
_token(candidate.get("item_id"), "item_id")
|
|
294
|
+
if candidate.get("item_kind") not in ALLOWED_ITEM_KINDS:
|
|
295
|
+
raise ValueError(f"item_kind must be one of {sorted(ALLOWED_ITEM_KINDS)}")
|
|
296
|
+
_token(candidate.get("channel"), "channel")
|
|
297
|
+
if candidate.get("state") not in ALLOWED_ITEM_STATES:
|
|
298
|
+
raise ValueError(f"state must be one of {sorted(ALLOWED_ITEM_STATES)}")
|
|
299
|
+
revision = candidate.get("revision")
|
|
300
|
+
if isinstance(revision, bool) or not isinstance(revision, int) or revision < 1:
|
|
301
|
+
raise ValueError("revision must be a positive integer")
|
|
302
|
+
_digest(candidate.get("content_digest"), "content_digest")
|
|
303
|
+
_token(candidate.get("content_ref"), "content_ref")
|
|
304
|
+
_source_refs(candidate.get("source_refs"))
|
|
305
|
+
_timestamp(candidate.get("created_at"), "created_at")
|
|
306
|
+
_timestamp(candidate.get("updated_at"), "updated_at")
|
|
307
|
+
if candidate.get("autopublish_allowed") is not False:
|
|
308
|
+
raise ValueError("autopublish_allowed must be false")
|
|
309
|
+
last_event = _record(
|
|
310
|
+
candidate.get("last_event"),
|
|
311
|
+
"last_event",
|
|
312
|
+
required={"event_id", "event_digest", "action"},
|
|
313
|
+
)
|
|
314
|
+
if last_event is not None:
|
|
315
|
+
_token(last_event["event_id"], "last_event.event_id")
|
|
316
|
+
_digest(last_event["event_digest"], "last_event.event_digest")
|
|
317
|
+
_token(last_event["action"], "last_event.action")
|
|
318
|
+
if candidate.get("superseded_by") is not None:
|
|
319
|
+
_token(candidate["superseded_by"], "superseded_by")
|
|
320
|
+
if candidate.get("terminal_reason") is not None:
|
|
321
|
+
_short_reason(candidate["terminal_reason"], "terminal_reason")
|
|
322
|
+
if candidate["state"] == "superseded" and not candidate.get("superseded_by"):
|
|
323
|
+
raise ValueError("superseded item requires superseded_by")
|
|
324
|
+
if candidate.get("superseded_by") and candidate["state"] != "superseded":
|
|
325
|
+
raise ValueError("only a superseded item may set superseded_by")
|
|
326
|
+
if candidate["state"] in {"skipped", "superseded"}:
|
|
327
|
+
if not candidate.get("terminal_reason"):
|
|
328
|
+
raise ValueError(f"{candidate['state']} item requires terminal_reason")
|
|
329
|
+
elif candidate.get("terminal_reason") is not None:
|
|
330
|
+
raise ValueError("non-terminal item must not set terminal_reason")
|
|
331
|
+
_validate_effect_records(candidate)
|
|
332
|
+
return candidate
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def build_content_ops_item(
|
|
336
|
+
*,
|
|
337
|
+
item_id: str,
|
|
338
|
+
item_kind: str,
|
|
339
|
+
channel: str,
|
|
340
|
+
content_digest: str,
|
|
341
|
+
content_ref: str,
|
|
342
|
+
source_refs: Sequence[str] | None = None,
|
|
343
|
+
created_at: str,
|
|
344
|
+
) -> dict[str, Any]:
|
|
345
|
+
"""Create a compact content item without copying draft content into LoopX."""
|
|
346
|
+
|
|
347
|
+
if item_kind not in ALLOWED_ITEM_KINDS:
|
|
348
|
+
raise ValueError(f"item_kind must be one of {sorted(ALLOWED_ITEM_KINDS)}")
|
|
349
|
+
timestamp = _timestamp(created_at, "created_at")
|
|
350
|
+
item = {
|
|
351
|
+
"schema_version": CONTENT_OPS_ITEM_SCHEMA_VERSION,
|
|
352
|
+
"item_id": _token(item_id, "item_id"),
|
|
353
|
+
"item_kind": item_kind,
|
|
354
|
+
"channel": _token(channel, "channel"),
|
|
355
|
+
"state": "captured",
|
|
356
|
+
"revision": 1,
|
|
357
|
+
"content_digest": _digest(content_digest, "content_digest"),
|
|
358
|
+
"content_ref": _token(content_ref, "content_ref"),
|
|
359
|
+
"source_refs": _source_refs(source_refs),
|
|
360
|
+
"approval": None,
|
|
361
|
+
"delivery_intent": None,
|
|
362
|
+
"delivery_receipt": None,
|
|
363
|
+
"readback_receipt": None,
|
|
364
|
+
"superseded_by": None,
|
|
365
|
+
"terminal_reason": None,
|
|
366
|
+
"last_event": None,
|
|
367
|
+
"created_at": timestamp,
|
|
368
|
+
"updated_at": timestamp,
|
|
369
|
+
"autopublish_allowed": False,
|
|
370
|
+
}
|
|
371
|
+
return _require_item(item)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def validate_content_ops_item(item: Mapping[str, Any]) -> dict[str, Any]:
|
|
375
|
+
errors: list[str] = []
|
|
376
|
+
try:
|
|
377
|
+
_require_item(item)
|
|
378
|
+
except ValueError as exc:
|
|
379
|
+
errors.append(str(exc))
|
|
380
|
+
return {
|
|
381
|
+
"ok": not errors,
|
|
382
|
+
"schema_version": CONTENT_OPS_ITEM_SCHEMA_VERSION,
|
|
383
|
+
"errors": errors,
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def _require_event(event: Mapping[str, Any]) -> tuple[dict[str, Any], str]:
|
|
388
|
+
candidate = copy.deepcopy(dict(event))
|
|
389
|
+
required = {
|
|
390
|
+
"event_id",
|
|
391
|
+
"action",
|
|
392
|
+
"expected_state",
|
|
393
|
+
"expected_revision",
|
|
394
|
+
"occurred_at",
|
|
395
|
+
}
|
|
396
|
+
missing = sorted(key for key in required if key not in candidate)
|
|
397
|
+
extra = sorted(set(candidate) - required - {"payload"})
|
|
398
|
+
if missing or extra:
|
|
399
|
+
raise ValueError(
|
|
400
|
+
f"event fields invalid: missing={missing}, unsupported={extra}"
|
|
401
|
+
)
|
|
402
|
+
candidate["event_id"] = _token(candidate["event_id"], "event_id")
|
|
403
|
+
candidate["occurred_at"] = _timestamp(candidate["occurred_at"], "occurred_at")
|
|
404
|
+
revision = candidate["expected_revision"]
|
|
405
|
+
if isinstance(revision, bool) or not isinstance(revision, int) or revision < 1:
|
|
406
|
+
raise ValueError("expected_revision must be a positive integer")
|
|
407
|
+
if candidate["expected_state"] not in ALLOWED_ITEM_STATES:
|
|
408
|
+
raise ValueError("expected_state is invalid")
|
|
409
|
+
if not isinstance(candidate.get("payload", {}), Mapping):
|
|
410
|
+
raise TypeError("event payload must be an object")
|
|
411
|
+
candidate["payload"] = dict(candidate.get("payload") or {})
|
|
412
|
+
return candidate, _event_digest(candidate)
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def _payload(
|
|
416
|
+
payload: Mapping[str, Any],
|
|
417
|
+
*,
|
|
418
|
+
required: set[str],
|
|
419
|
+
optional: set[str] | None = None,
|
|
420
|
+
) -> dict[str, Any]:
|
|
421
|
+
optional = optional or set()
|
|
422
|
+
missing = sorted(required - set(payload))
|
|
423
|
+
extra = sorted(set(payload) - required - optional)
|
|
424
|
+
if missing or extra:
|
|
425
|
+
raise ValueError(
|
|
426
|
+
f"event payload fields invalid: missing={missing}, unsupported={extra}"
|
|
427
|
+
)
|
|
428
|
+
return dict(payload)
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def _clear_effect_state(item: dict[str, Any]) -> None:
|
|
432
|
+
item["approval"] = None
|
|
433
|
+
item["delivery_intent"] = None
|
|
434
|
+
item["delivery_receipt"] = None
|
|
435
|
+
item["readback_receipt"] = None
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def _assert_delivery_window(item: Mapping[str, Any], occurred_at: str) -> None:
|
|
439
|
+
observed = _timestamp_value(occurred_at, "occurred_at")
|
|
440
|
+
approval = item.get("approval") if isinstance(item.get("approval"), Mapping) else {}
|
|
441
|
+
intent = (
|
|
442
|
+
item.get("delivery_intent")
|
|
443
|
+
if isinstance(item.get("delivery_intent"), Mapping)
|
|
444
|
+
else {}
|
|
445
|
+
)
|
|
446
|
+
for field, is_lower in (
|
|
447
|
+
("valid_from", True),
|
|
448
|
+
("valid_until", False),
|
|
449
|
+
("not_before", True),
|
|
450
|
+
("not_after", False),
|
|
451
|
+
):
|
|
452
|
+
raw = approval.get(field) if field.startswith("valid_") else intent.get(field)
|
|
453
|
+
if raw is None:
|
|
454
|
+
continue
|
|
455
|
+
boundary = _timestamp_value(raw, field)
|
|
456
|
+
if (is_lower and observed < boundary) or (not is_lower and observed > boundary):
|
|
457
|
+
raise ValueError(f"delivery occurred outside {field}")
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def _transition(item: dict[str, Any], event: Mapping[str, Any]) -> None:
|
|
461
|
+
action = str(event["action"])
|
|
462
|
+
state = str(item["state"])
|
|
463
|
+
payload = dict(event["payload"])
|
|
464
|
+
|
|
465
|
+
if action == "revise":
|
|
466
|
+
if state not in {
|
|
467
|
+
"captured",
|
|
468
|
+
"draft",
|
|
469
|
+
"review_ready",
|
|
470
|
+
"approved",
|
|
471
|
+
"delivery_ready",
|
|
472
|
+
}:
|
|
473
|
+
raise ValueError(f"revise is not allowed from {state}")
|
|
474
|
+
values = _payload(
|
|
475
|
+
payload,
|
|
476
|
+
required={"content_digest", "content_ref"},
|
|
477
|
+
optional={"source_refs"},
|
|
478
|
+
)
|
|
479
|
+
item["revision"] += 1
|
|
480
|
+
item["content_digest"] = _digest(values["content_digest"], "content_digest")
|
|
481
|
+
item["content_ref"] = _token(values["content_ref"], "content_ref")
|
|
482
|
+
if "source_refs" in values:
|
|
483
|
+
if not isinstance(values["source_refs"], list):
|
|
484
|
+
raise ValueError("source_refs must be a list")
|
|
485
|
+
item["source_refs"] = _source_refs(values["source_refs"])
|
|
486
|
+
_clear_effect_state(item)
|
|
487
|
+
item["state"] = "draft"
|
|
488
|
+
return
|
|
489
|
+
|
|
490
|
+
if action == "submit_review":
|
|
491
|
+
if state not in {"captured", "draft"}:
|
|
492
|
+
raise ValueError(f"submit_review is not allowed from {state}")
|
|
493
|
+
_payload(payload, required=set())
|
|
494
|
+
item["state"] = "review_ready"
|
|
495
|
+
return
|
|
496
|
+
|
|
497
|
+
if action == "approve":
|
|
498
|
+
if state != "review_ready":
|
|
499
|
+
raise ValueError(f"approve is not allowed from {state}")
|
|
500
|
+
values = _payload(
|
|
501
|
+
payload,
|
|
502
|
+
required={"approval_ref", "revision", "content_digest", "effect_kind"},
|
|
503
|
+
optional={"account_ref", "valid_from", "valid_until"},
|
|
504
|
+
)
|
|
505
|
+
if values["revision"] != item["revision"]:
|
|
506
|
+
raise ValueError("approval revision does not match current item revision")
|
|
507
|
+
if (
|
|
508
|
+
_digest(values["content_digest"], "content_digest")
|
|
509
|
+
!= item["content_digest"]
|
|
510
|
+
):
|
|
511
|
+
raise ValueError("approval content_digest does not match current item")
|
|
512
|
+
effect_kind = str(values["effect_kind"])
|
|
513
|
+
if effect_kind not in ALLOWED_EFFECT_KINDS:
|
|
514
|
+
raise ValueError(
|
|
515
|
+
f"effect_kind must be one of {sorted(ALLOWED_EFFECT_KINDS)}"
|
|
516
|
+
)
|
|
517
|
+
approval = {
|
|
518
|
+
"approval_ref": _token(values["approval_ref"], "approval_ref"),
|
|
519
|
+
"revision": item["revision"],
|
|
520
|
+
"content_digest": item["content_digest"],
|
|
521
|
+
"effect_kind": effect_kind,
|
|
522
|
+
"account_ref": _token(values["account_ref"], "account_ref")
|
|
523
|
+
if values.get("account_ref")
|
|
524
|
+
else None,
|
|
525
|
+
"valid_from": _timestamp(values["valid_from"], "valid_from")
|
|
526
|
+
if values.get("valid_from")
|
|
527
|
+
else None,
|
|
528
|
+
"valid_until": _timestamp(values["valid_until"], "valid_until")
|
|
529
|
+
if values.get("valid_until")
|
|
530
|
+
else None,
|
|
531
|
+
}
|
|
532
|
+
if (
|
|
533
|
+
approval["valid_from"]
|
|
534
|
+
and approval["valid_until"]
|
|
535
|
+
and _timestamp_value(approval["valid_from"], "valid_from")
|
|
536
|
+
> _timestamp_value(approval["valid_until"], "valid_until")
|
|
537
|
+
):
|
|
538
|
+
raise ValueError("valid_from must not be after valid_until")
|
|
539
|
+
item["approval"] = approval
|
|
540
|
+
item["state"] = "approved"
|
|
541
|
+
return
|
|
542
|
+
|
|
543
|
+
if action == "set_delivery_intent":
|
|
544
|
+
if state != "approved":
|
|
545
|
+
raise ValueError(f"set_delivery_intent is not allowed from {state}")
|
|
546
|
+
values = _payload(
|
|
547
|
+
payload,
|
|
548
|
+
required={"provider_id", "effect_kind"},
|
|
549
|
+
optional={"account_ref", "not_before", "not_after"},
|
|
550
|
+
)
|
|
551
|
+
approval = dict(item["approval"])
|
|
552
|
+
if values["effect_kind"] != approval["effect_kind"]:
|
|
553
|
+
raise ValueError("delivery intent effect_kind does not match approval")
|
|
554
|
+
account_ref = (
|
|
555
|
+
_token(values["account_ref"], "account_ref")
|
|
556
|
+
if values.get("account_ref")
|
|
557
|
+
else approval.get("account_ref")
|
|
558
|
+
)
|
|
559
|
+
if approval.get("account_ref") and account_ref != approval["account_ref"]:
|
|
560
|
+
raise ValueError("delivery intent account_ref does not match approval")
|
|
561
|
+
intent = {
|
|
562
|
+
"provider_id": _token(values["provider_id"], "provider_id"),
|
|
563
|
+
"effect_kind": values["effect_kind"],
|
|
564
|
+
"account_ref": account_ref,
|
|
565
|
+
"not_before": _timestamp(values["not_before"], "not_before")
|
|
566
|
+
if values.get("not_before")
|
|
567
|
+
else None,
|
|
568
|
+
"not_after": _timestamp(values["not_after"], "not_after")
|
|
569
|
+
if values.get("not_after")
|
|
570
|
+
else None,
|
|
571
|
+
}
|
|
572
|
+
if (
|
|
573
|
+
intent["not_before"]
|
|
574
|
+
and intent["not_after"]
|
|
575
|
+
and _timestamp_value(intent["not_before"], "not_before")
|
|
576
|
+
> _timestamp_value(intent["not_after"], "not_after")
|
|
577
|
+
):
|
|
578
|
+
raise ValueError("not_before must not be after not_after")
|
|
579
|
+
item["delivery_intent"] = intent
|
|
580
|
+
item["state"] = "delivery_ready"
|
|
581
|
+
return
|
|
582
|
+
|
|
583
|
+
if action == "record_delivery":
|
|
584
|
+
if state not in {"approved", "delivery_ready"}:
|
|
585
|
+
raise ValueError(f"record_delivery is not allowed from {state}")
|
|
586
|
+
values = _payload(
|
|
587
|
+
payload,
|
|
588
|
+
required={
|
|
589
|
+
"provider_id",
|
|
590
|
+
"effect_kind",
|
|
591
|
+
"content_digest",
|
|
592
|
+
"public_url",
|
|
593
|
+
"receipt_ref",
|
|
594
|
+
},
|
|
595
|
+
optional={"account_ref"},
|
|
596
|
+
)
|
|
597
|
+
approval = dict(item["approval"])
|
|
598
|
+
if values["effect_kind"] != approval["effect_kind"]:
|
|
599
|
+
raise ValueError("delivery effect_kind does not match approval")
|
|
600
|
+
if (
|
|
601
|
+
_digest(values["content_digest"], "content_digest")
|
|
602
|
+
!= approval["content_digest"]
|
|
603
|
+
):
|
|
604
|
+
raise ValueError("delivery content_digest does not match approval")
|
|
605
|
+
intent = dict(item["delivery_intent"] or {})
|
|
606
|
+
provider_id = _token(values["provider_id"], "provider_id")
|
|
607
|
+
if intent and provider_id != intent["provider_id"]:
|
|
608
|
+
raise ValueError("delivery provider_id does not match intent")
|
|
609
|
+
account_ref = (
|
|
610
|
+
_token(values["account_ref"], "account_ref")
|
|
611
|
+
if values.get("account_ref")
|
|
612
|
+
else intent.get("account_ref") or approval.get("account_ref")
|
|
613
|
+
)
|
|
614
|
+
expected_account = intent.get("account_ref") or approval.get("account_ref")
|
|
615
|
+
if expected_account and account_ref != expected_account:
|
|
616
|
+
raise ValueError("delivery account_ref does not match approval or intent")
|
|
617
|
+
_assert_delivery_window(item, str(event["occurred_at"]))
|
|
618
|
+
item["delivery_receipt"] = {
|
|
619
|
+
"provider_id": provider_id,
|
|
620
|
+
"effect_kind": values["effect_kind"],
|
|
621
|
+
"account_ref": account_ref,
|
|
622
|
+
"content_digest": item["content_digest"],
|
|
623
|
+
"public_url": _public_url(values["public_url"], "public_url"),
|
|
624
|
+
"receipt_ref": _token(values["receipt_ref"], "receipt_ref"),
|
|
625
|
+
"recorded_at": event["occurred_at"],
|
|
626
|
+
}
|
|
627
|
+
item["state"] = "published"
|
|
628
|
+
return
|
|
629
|
+
|
|
630
|
+
if action == "verify_readback":
|
|
631
|
+
if state != "published":
|
|
632
|
+
raise ValueError(f"verify_readback is not allowed from {state}")
|
|
633
|
+
values = _payload(
|
|
634
|
+
payload,
|
|
635
|
+
required={"public_url", "content_digest", "readback_ref"},
|
|
636
|
+
)
|
|
637
|
+
delivery = dict(item["delivery_receipt"])
|
|
638
|
+
public_url = _public_url(values["public_url"], "public_url")
|
|
639
|
+
if public_url != delivery["public_url"]:
|
|
640
|
+
raise ValueError("readback public_url does not match delivery receipt")
|
|
641
|
+
if (
|
|
642
|
+
_digest(values["content_digest"], "content_digest")
|
|
643
|
+
!= delivery["content_digest"]
|
|
644
|
+
):
|
|
645
|
+
raise ValueError("readback content_digest does not match delivery receipt")
|
|
646
|
+
item["readback_receipt"] = {
|
|
647
|
+
"public_url": public_url,
|
|
648
|
+
"content_digest": item["content_digest"],
|
|
649
|
+
"readback_ref": _token(values["readback_ref"], "readback_ref"),
|
|
650
|
+
"verified_at": event["occurred_at"],
|
|
651
|
+
}
|
|
652
|
+
item["state"] = "readback_verified"
|
|
653
|
+
return
|
|
654
|
+
|
|
655
|
+
if action == "revoke_approval":
|
|
656
|
+
if state not in {"approved", "delivery_ready"}:
|
|
657
|
+
raise ValueError(f"revoke_approval is not allowed from {state}")
|
|
658
|
+
values = _payload(payload, required={"reason"})
|
|
659
|
+
_clear_effect_state(item)
|
|
660
|
+
_short_reason(values["reason"], "reason")
|
|
661
|
+
item["state"] = "review_ready"
|
|
662
|
+
return
|
|
663
|
+
|
|
664
|
+
if action == "skip":
|
|
665
|
+
if state in {"published", *TERMINAL_STATES}:
|
|
666
|
+
raise ValueError(f"skip is not allowed from {state}")
|
|
667
|
+
values = _payload(payload, required={"reason"})
|
|
668
|
+
_clear_effect_state(item)
|
|
669
|
+
item["terminal_reason"] = _short_reason(values["reason"], "reason")
|
|
670
|
+
item["state"] = "skipped"
|
|
671
|
+
return
|
|
672
|
+
|
|
673
|
+
if action == "supersede":
|
|
674
|
+
if state in {"published", *TERMINAL_STATES}:
|
|
675
|
+
raise ValueError(f"supersede is not allowed from {state}")
|
|
676
|
+
values = _payload(payload, required={"successor_item_id", "reason"})
|
|
677
|
+
successor = _token(values["successor_item_id"], "successor_item_id")
|
|
678
|
+
if successor == item["item_id"]:
|
|
679
|
+
raise ValueError("successor_item_id must differ from item_id")
|
|
680
|
+
_clear_effect_state(item)
|
|
681
|
+
item["superseded_by"] = successor
|
|
682
|
+
item["terminal_reason"] = _short_reason(values["reason"], "reason")
|
|
683
|
+
item["state"] = "superseded"
|
|
684
|
+
return
|
|
685
|
+
|
|
686
|
+
raise ValueError(f"unsupported content item action {action!r}")
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def project_content_ops_item(item: Mapping[str, Any]) -> dict[str, Any]:
|
|
690
|
+
current = _require_item(item)
|
|
691
|
+
state = str(current["state"])
|
|
692
|
+
next_actions = {
|
|
693
|
+
"captured": ["revise", "submit_review", "skip", "supersede"],
|
|
694
|
+
"draft": ["revise", "submit_review", "skip", "supersede"],
|
|
695
|
+
"review_ready": ["revise", "approve", "skip", "supersede"],
|
|
696
|
+
"approved": [
|
|
697
|
+
"revise",
|
|
698
|
+
"set_delivery_intent",
|
|
699
|
+
"record_delivery",
|
|
700
|
+
"revoke_approval",
|
|
701
|
+
"skip",
|
|
702
|
+
"supersede",
|
|
703
|
+
],
|
|
704
|
+
"delivery_ready": [
|
|
705
|
+
"revise",
|
|
706
|
+
"record_delivery",
|
|
707
|
+
"revoke_approval",
|
|
708
|
+
"skip",
|
|
709
|
+
"supersede",
|
|
710
|
+
],
|
|
711
|
+
"published": ["verify_readback"],
|
|
712
|
+
"readback_verified": [],
|
|
713
|
+
"skipped": [],
|
|
714
|
+
"superseded": [],
|
|
715
|
+
}[state]
|
|
716
|
+
delivery = current.get("delivery_receipt") or {}
|
|
717
|
+
return {
|
|
718
|
+
"schema_version": CONTENT_OPS_ITEM_PROJECTION_SCHEMA_VERSION,
|
|
719
|
+
"item_id": current["item_id"],
|
|
720
|
+
"item_kind": current["item_kind"],
|
|
721
|
+
"channel": current["channel"],
|
|
722
|
+
"state": state,
|
|
723
|
+
"revision": current["revision"],
|
|
724
|
+
"approval_present": current.get("approval") is not None,
|
|
725
|
+
"delivery_intent_present": current.get("delivery_intent") is not None,
|
|
726
|
+
"published_url": delivery.get("public_url"),
|
|
727
|
+
"readback_verified": current.get("readback_receipt") is not None,
|
|
728
|
+
"terminal": state in TERMINAL_STATES,
|
|
729
|
+
"superseded_by": current.get("superseded_by"),
|
|
730
|
+
"next_actions": next_actions,
|
|
731
|
+
"truth_contract": {
|
|
732
|
+
"projection_is_writable": False,
|
|
733
|
+
"external_effect_authority": "none",
|
|
734
|
+
"autopublish_allowed": False,
|
|
735
|
+
},
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
def build_content_ops_queue_projection(
|
|
740
|
+
*,
|
|
741
|
+
items: Sequence[Mapping[str, Any]],
|
|
742
|
+
queue_id: str = "content_ops_managed_queue",
|
|
743
|
+
generated_at: str = "2026-08-10T00:00:00Z",
|
|
744
|
+
) -> dict[str, Any]:
|
|
745
|
+
"""Project caller-owned content items into one managed queue surface."""
|
|
746
|
+
|
|
747
|
+
queue_token = _token(queue_id, "queue_id")
|
|
748
|
+
timestamp = _timestamp(generated_at, "generated_at")
|
|
749
|
+
if not items:
|
|
750
|
+
raise ValueError("content queue requires at least one item")
|
|
751
|
+
normalized = [_require_item(item) for item in items]
|
|
752
|
+
item_projections = [project_content_ops_item(item) for item in normalized]
|
|
753
|
+
|
|
754
|
+
counts: dict[str, int] = {}
|
|
755
|
+
terminal_count = 0
|
|
756
|
+
for projection in item_projections:
|
|
757
|
+
state = str(projection["state"])
|
|
758
|
+
counts[state] = counts.get(state, 0) + 1
|
|
759
|
+
if projection["terminal"]:
|
|
760
|
+
terminal_count += 1
|
|
761
|
+
|
|
762
|
+
actionable = [
|
|
763
|
+
{
|
|
764
|
+
"priority_index": index,
|
|
765
|
+
"item_id": projection["item_id"],
|
|
766
|
+
"item_kind": projection["item_kind"],
|
|
767
|
+
"channel": projection["channel"],
|
|
768
|
+
"state": projection["state"],
|
|
769
|
+
"revision": projection["revision"],
|
|
770
|
+
"next_actions": projection["next_actions"],
|
|
771
|
+
}
|
|
772
|
+
for index, projection in enumerate(item_projections, start=1)
|
|
773
|
+
if not projection["terminal"]
|
|
774
|
+
]
|
|
775
|
+
next_action = None
|
|
776
|
+
if actionable:
|
|
777
|
+
first = actionable[0]
|
|
778
|
+
next_action = {
|
|
779
|
+
"item_id": first["item_id"],
|
|
780
|
+
"state": first["state"],
|
|
781
|
+
"priority_index": first["priority_index"],
|
|
782
|
+
"next_actions": first["next_actions"],
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
return {
|
|
786
|
+
"schema_version": CONTENT_OPS_QUEUE_PROJECTION_SCHEMA_VERSION,
|
|
787
|
+
"queue_id": queue_token,
|
|
788
|
+
"generated_at": timestamp,
|
|
789
|
+
"item_count": len(item_projections),
|
|
790
|
+
"counts": counts,
|
|
791
|
+
"terminal_count": terminal_count,
|
|
792
|
+
"items": [
|
|
793
|
+
{
|
|
794
|
+
"priority_index": index,
|
|
795
|
+
"item_id": projection["item_id"],
|
|
796
|
+
"item_kind": projection["item_kind"],
|
|
797
|
+
"channel": projection["channel"],
|
|
798
|
+
"state": projection["state"],
|
|
799
|
+
"revision": projection["revision"],
|
|
800
|
+
"content_ref": normalized[index - 1]["content_ref"],
|
|
801
|
+
"terminal": projection["terminal"],
|
|
802
|
+
"published_url": projection["published_url"],
|
|
803
|
+
"next_actions": projection["next_actions"],
|
|
804
|
+
}
|
|
805
|
+
for index, projection in enumerate(item_projections, start=1)
|
|
806
|
+
],
|
|
807
|
+
"next_action": next_action,
|
|
808
|
+
"truth_contract": {
|
|
809
|
+
"projection_is_writable": False,
|
|
810
|
+
"external_effect_authority": "none",
|
|
811
|
+
"autopublish_allowed": False,
|
|
812
|
+
},
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
def build_content_ops_queue_status_packet(
|
|
817
|
+
*,
|
|
818
|
+
items: Sequence[Mapping[str, Any]],
|
|
819
|
+
queue_id: str = "content_ops_managed_queue",
|
|
820
|
+
generated_at: str = "2026-08-10T00:00:00Z",
|
|
821
|
+
) -> dict[str, Any]:
|
|
822
|
+
"""Build a read-only queue status packet without draft bodies."""
|
|
823
|
+
|
|
824
|
+
projection = build_content_ops_queue_projection(
|
|
825
|
+
items=items,
|
|
826
|
+
queue_id=queue_id,
|
|
827
|
+
generated_at=generated_at,
|
|
828
|
+
)
|
|
829
|
+
return {
|
|
830
|
+
"ok": True,
|
|
831
|
+
"schema_version": CONTENT_OPS_QUEUE_STATUS_PACKET_SCHEMA_VERSION,
|
|
832
|
+
"queue_id": projection["queue_id"],
|
|
833
|
+
"generated_at": projection["generated_at"],
|
|
834
|
+
"item_count": projection["item_count"],
|
|
835
|
+
"projection": projection,
|
|
836
|
+
"external_reads_performed": False,
|
|
837
|
+
"external_writes_performed": False,
|
|
838
|
+
"private_source_bodies_read": False,
|
|
839
|
+
"autopublish_allowed": False,
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
def build_content_ops_item_packet(**kwargs: Any) -> dict[str, Any]:
|
|
844
|
+
item = build_content_ops_item(**kwargs)
|
|
845
|
+
return {
|
|
846
|
+
"ok": True,
|
|
847
|
+
"schema_version": CONTENT_OPS_ITEM_PACKET_SCHEMA_VERSION,
|
|
848
|
+
"item": item,
|
|
849
|
+
"projection": project_content_ops_item(item),
|
|
850
|
+
"external_reads_performed": False,
|
|
851
|
+
"external_writes_performed": False,
|
|
852
|
+
"autopublish_allowed": False,
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
def apply_content_ops_item_event(
|
|
857
|
+
item: Mapping[str, Any], event: Mapping[str, Any]
|
|
858
|
+
) -> dict[str, Any]:
|
|
859
|
+
current = _require_item(item)
|
|
860
|
+
normalized_event, event_digest = _require_event(event)
|
|
861
|
+
last_event = current.get("last_event")
|
|
862
|
+
if (
|
|
863
|
+
isinstance(last_event, Mapping)
|
|
864
|
+
and last_event.get("event_id") == normalized_event["event_id"]
|
|
865
|
+
):
|
|
866
|
+
if last_event.get("event_digest") != event_digest:
|
|
867
|
+
raise ValueError("event_id was already used with different content")
|
|
868
|
+
return {
|
|
869
|
+
"ok": True,
|
|
870
|
+
"schema_version": CONTENT_OPS_ITEM_TRANSITION_PACKET_SCHEMA_VERSION,
|
|
871
|
+
"item": current,
|
|
872
|
+
"projection": project_content_ops_item(current),
|
|
873
|
+
"receipt": {
|
|
874
|
+
"schema_version": CONTENT_OPS_ITEM_TRANSITION_RECEIPT_SCHEMA_VERSION,
|
|
875
|
+
"status": "already_applied",
|
|
876
|
+
"event_id": normalized_event["event_id"],
|
|
877
|
+
"event_digest": event_digest,
|
|
878
|
+
"from_state": current["state"],
|
|
879
|
+
"to_state": current["state"],
|
|
880
|
+
"revision": current["revision"],
|
|
881
|
+
},
|
|
882
|
+
"external_reads_performed": False,
|
|
883
|
+
"external_writes_performed": False,
|
|
884
|
+
"autopublish_allowed": False,
|
|
885
|
+
}
|
|
886
|
+
if normalized_event["expected_state"] != current["state"]:
|
|
887
|
+
raise ValueError("event expected_state does not match current item state")
|
|
888
|
+
if normalized_event["expected_revision"] != current["revision"]:
|
|
889
|
+
raise ValueError("event expected_revision does not match current item revision")
|
|
890
|
+
|
|
891
|
+
before_state = str(current["state"])
|
|
892
|
+
updated = copy.deepcopy(current)
|
|
893
|
+
_transition(updated, normalized_event)
|
|
894
|
+
updated["updated_at"] = normalized_event["occurred_at"]
|
|
895
|
+
updated["last_event"] = {
|
|
896
|
+
"event_id": normalized_event["event_id"],
|
|
897
|
+
"event_digest": event_digest,
|
|
898
|
+
"action": normalized_event["action"],
|
|
899
|
+
}
|
|
900
|
+
_require_item(updated)
|
|
901
|
+
return {
|
|
902
|
+
"ok": True,
|
|
903
|
+
"schema_version": CONTENT_OPS_ITEM_TRANSITION_PACKET_SCHEMA_VERSION,
|
|
904
|
+
"item": updated,
|
|
905
|
+
"projection": project_content_ops_item(updated),
|
|
906
|
+
"receipt": {
|
|
907
|
+
"schema_version": CONTENT_OPS_ITEM_TRANSITION_RECEIPT_SCHEMA_VERSION,
|
|
908
|
+
"status": "applied",
|
|
909
|
+
"event_id": normalized_event["event_id"],
|
|
910
|
+
"event_digest": event_digest,
|
|
911
|
+
"from_state": before_state,
|
|
912
|
+
"to_state": updated["state"],
|
|
913
|
+
"revision": updated["revision"],
|
|
914
|
+
},
|
|
915
|
+
"external_reads_performed": False,
|
|
916
|
+
"external_writes_performed": False,
|
|
917
|
+
"autopublish_allowed": False,
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
def render_content_ops_item_packet_markdown(packet: Mapping[str, Any]) -> str:
|
|
922
|
+
if not packet.get("ok"):
|
|
923
|
+
return f"# LoopX Content Item\n\n- error: `{packet.get('error')}`\n"
|
|
924
|
+
projection = (
|
|
925
|
+
packet.get("projection")
|
|
926
|
+
if isinstance(packet.get("projection"), Mapping)
|
|
927
|
+
else {}
|
|
928
|
+
)
|
|
929
|
+
receipt = (
|
|
930
|
+
packet.get("receipt") if isinstance(packet.get("receipt"), Mapping) else {}
|
|
931
|
+
)
|
|
932
|
+
lines = [
|
|
933
|
+
"# LoopX Content Item",
|
|
934
|
+
"",
|
|
935
|
+
f"- item_id: `{projection.get('item_id')}`",
|
|
936
|
+
f"- state: `{projection.get('state')}`",
|
|
937
|
+
f"- revision: `{projection.get('revision')}`",
|
|
938
|
+
f"- approval_present: `{projection.get('approval_present')}`",
|
|
939
|
+
f"- readback_verified: `{projection.get('readback_verified')}`",
|
|
940
|
+
f"- external_writes_performed: `{packet.get('external_writes_performed')}`",
|
|
941
|
+
]
|
|
942
|
+
if receipt:
|
|
943
|
+
lines.extend(
|
|
944
|
+
[
|
|
945
|
+
f"- transition_status: `{receipt.get('status')}`",
|
|
946
|
+
f"- transition: `{receipt.get('from_state')} -> {receipt.get('to_state')}`",
|
|
947
|
+
]
|
|
948
|
+
)
|
|
949
|
+
return "\n".join(lines) + "\n"
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
def render_content_ops_queue_status_markdown(packet: Mapping[str, Any]) -> str:
|
|
953
|
+
if not packet.get("ok"):
|
|
954
|
+
return f"# LoopX Content-Ops Queue\n\n- error: `{packet.get('error')}`\n"
|
|
955
|
+
projection = (
|
|
956
|
+
packet.get("projection")
|
|
957
|
+
if isinstance(packet.get("projection"), Mapping)
|
|
958
|
+
else {}
|
|
959
|
+
)
|
|
960
|
+
counts = projection.get("counts") if isinstance(projection.get("counts"), Mapping) else {}
|
|
961
|
+
next_action = (
|
|
962
|
+
projection.get("next_action")
|
|
963
|
+
if isinstance(projection.get("next_action"), Mapping)
|
|
964
|
+
else None
|
|
965
|
+
)
|
|
966
|
+
lines = [
|
|
967
|
+
"# LoopX Content-Ops Queue",
|
|
968
|
+
"",
|
|
969
|
+
f"- queue_id: `{projection.get('queue_id')}`",
|
|
970
|
+
f"- item_count: `{projection.get('item_count')}`",
|
|
971
|
+
f"- terminal_count: `{projection.get('terminal_count')}`",
|
|
972
|
+
f"- counts: `{counts}`",
|
|
973
|
+
f"- external_writes_performed: `{packet.get('external_writes_performed')}`",
|
|
974
|
+
]
|
|
975
|
+
if next_action:
|
|
976
|
+
lines.extend(
|
|
977
|
+
[
|
|
978
|
+
"",
|
|
979
|
+
"## Next Action",
|
|
980
|
+
"",
|
|
981
|
+
f"- item_id: `{next_action.get('item_id')}`",
|
|
982
|
+
f"- state: `{next_action.get('state')}`",
|
|
983
|
+
f"- priority_index: `{next_action.get('priority_index')}`",
|
|
984
|
+
f"- next_actions: `{next_action.get('next_actions')}`",
|
|
985
|
+
]
|
|
986
|
+
)
|
|
987
|
+
items = projection.get("items")
|
|
988
|
+
if isinstance(items, Sequence) and not isinstance(items, (str, bytes)):
|
|
989
|
+
lines.extend(["", "## Queue Items", ""])
|
|
990
|
+
for item in items:
|
|
991
|
+
if not isinstance(item, Mapping):
|
|
992
|
+
continue
|
|
993
|
+
lines.append(
|
|
994
|
+
f"- `{item.get('priority_index')}` "
|
|
995
|
+
f"`{item.get('item_id')}` "
|
|
996
|
+
f"state=`{item.get('state')}` "
|
|
997
|
+
f"kind=`{item.get('item_kind')}` "
|
|
998
|
+
f"rev=`{item.get('revision')}`"
|
|
999
|
+
)
|
|
1000
|
+
return "\n".join(lines) + "\n"
|