agentic-project-kit 1.0.1__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.
- agentic_project_kit/__init__.py +1 -0
- agentic_project_kit/absolute_path_portability_audit.py +241 -0
- agentic_project_kit/access_level_policy.py +14 -0
- agentic_project_kit/access_levels.py +22 -0
- agentic_project_kit/action_registry.py +195 -0
- agentic_project_kit/action_specs.py +286 -0
- agentic_project_kit/agent_command_runner.py +516 -0
- agentic_project_kit/audit_test_matrix.py +36 -0
- agentic_project_kit/audit_test_matrix_cli.py +43 -0
- agentic_project_kit/chat_bootloader.py +257 -0
- agentic_project_kit/chat_entrypoint_contract.py +297 -0
- agentic_project_kit/checks.py +511 -0
- agentic_project_kit/ci_readiness.py +211 -0
- agentic_project_kit/cli.py +147 -0
- agentic_project_kit/cli_commands/__init__.py +1 -0
- agentic_project_kit/cli_commands/absolute_path_audit.py +25 -0
- agentic_project_kit/cli_commands/actions.py +21 -0
- agentic_project_kit/cli_commands/artifact_gc.py +240 -0
- agentic_project_kit/cli_commands/boot.py +55 -0
- agentic_project_kit/cli_commands/chat.py +34 -0
- agentic_project_kit/cli_commands/checks.py +305 -0
- agentic_project_kit/cli_commands/cockpit.py +103 -0
- agentic_project_kit/cli_commands/command_taxonomy.py +25 -0
- agentic_project_kit/cli_commands/commands.py +129 -0
- agentic_project_kit/cli_commands/dev.py +23 -0
- agentic_project_kit/cli_commands/direction.py +92 -0
- agentic_project_kit/cli_commands/doc_currency_audit.py +25 -0
- agentic_project_kit/cli_commands/doc_registry.py +126 -0
- agentic_project_kit/cli_commands/docs.py +223 -0
- agentic_project_kit/cli_commands/dpa.py +1338 -0
- agentic_project_kit/cli_commands/evidence.py +251 -0
- agentic_project_kit/cli_commands/github.py +34 -0
- agentic_project_kit/cli_commands/governance.py +14 -0
- agentic_project_kit/cli_commands/gui.py +23 -0
- agentic_project_kit/cli_commands/gui_readiness_gate.py +27 -0
- agentic_project_kit/cli_commands/handoff.py +183 -0
- agentic_project_kit/cli_commands/human_workflows.py +430 -0
- agentic_project_kit/cli_commands/init.py +132 -0
- agentic_project_kit/cli_commands/instruction.py +75 -0
- agentic_project_kit/cli_commands/mutation_lock_audit.py +24 -0
- agentic_project_kit/cli_commands/ns_legacy_audit.py +25 -0
- agentic_project_kit/cli_commands/pass_already_done.py +66 -0
- agentic_project_kit/cli_commands/patch_failure_discipline_audit.py +26 -0
- agentic_project_kit/cli_commands/patch_preflight.py +37 -0
- agentic_project_kit/cli_commands/path_literal_audit.py +39 -0
- agentic_project_kit/cli_commands/patterns.py +40 -0
- agentic_project_kit/cli_commands/planning_docs_audit.py +25 -0
- agentic_project_kit/cli_commands/pr.py +133 -0
- agentic_project_kit/cli_commands/pr_hygiene.py +27 -0
- agentic_project_kit/cli_commands/profiles.py +26 -0
- agentic_project_kit/cli_commands/program_redundancy_audit.py +25 -0
- agentic_project_kit/cli_commands/project_direction.py +25 -0
- agentic_project_kit/cli_commands/release.py +392 -0
- agentic_project_kit/cli_commands/release_publish_orchestration.py +36 -0
- agentic_project_kit/cli_commands/remote_branch_hygiene.py +152 -0
- agentic_project_kit/cli_commands/remote_next.py +57 -0
- agentic_project_kit/cli_commands/removed_ns_commands.py +65 -0
- agentic_project_kit/cli_commands/rule_registry.py +129 -0
- agentic_project_kit/cli_commands/rules.py +222 -0
- agentic_project_kit/cli_commands/scaffold.py +46 -0
- agentic_project_kit/cli_commands/slice.py +21 -0
- agentic_project_kit/cli_commands/standard_gates_audit_suite.py +27 -0
- agentic_project_kit/cli_commands/state.py +51 -0
- agentic_project_kit/cli_commands/status_current_state_audit.py +30 -0
- agentic_project_kit/cli_commands/todo.py +53 -0
- agentic_project_kit/cli_commands/transfer.py +19 -0
- agentic_project_kit/cli_commands/transfer_context_flow.py +398 -0
- agentic_project_kit/cli_commands/transfer_context_helpers.py +398 -0
- agentic_project_kit/cli_commands/transfer_diagnostics.py +767 -0
- agentic_project_kit/cli_commands/transfer_evidence_flow.py +368 -0
- agentic_project_kit/cli_commands/transfer_handoff_flow.py +594 -0
- agentic_project_kit/cli_commands/transfer_order_contract.py +74 -0
- agentic_project_kit/cli_commands/transfer_post_merge_complete.py +442 -0
- agentic_project_kit/cli_commands/transfer_post_merge_settle.py +171 -0
- agentic_project_kit/cli_commands/transfer_pr_closeout_complete.py +124 -0
- agentic_project_kit/cli_commands/transfer_pr_create_flow.py +743 -0
- agentic_project_kit/cli_commands/transfer_pr_merge_flow.py +547 -0
- agentic_project_kit/cli_commands/transfer_repo_after_pr.py +160 -0
- agentic_project_kit/cli_commands/transfer_repo_pre_pr.py +664 -0
- agentic_project_kit/cli_commands/transfer_runner_flow.py +131 -0
- agentic_project_kit/cli_commands/transfer_runtime_initial.py +194 -0
- agentic_project_kit/cli_commands/transfer_shared.py +274 -0
- agentic_project_kit/cli_commands/validation.py +200 -0
- agentic_project_kit/cli_commands/version.py +27 -0
- agentic_project_kit/cli_commands/work_orders.py +219 -0
- agentic_project_kit/cli_commands/workflow.py +471 -0
- agentic_project_kit/cli_commands/workflow_guard.py +26 -0
- agentic_project_kit/cli_commands/workspace.py +252 -0
- agentic_project_kit/cockpit.py +608 -0
- agentic_project_kit/cockpit_readiness.py +67 -0
- agentic_project_kit/command_authority_audit.py +192 -0
- agentic_project_kit/command_inbox_check.py +103 -0
- agentic_project_kit/command_manifest.py +591 -0
- agentic_project_kit/command_queue_contract.py +161 -0
- agentic_project_kit/command_selector.py +245 -0
- agentic_project_kit/command_taxonomy.py +264 -0
- agentic_project_kit/commit_guard.py +67 -0
- agentic_project_kit/communication_artifact_gc.py +495 -0
- agentic_project_kit/communication_rule_context.py +437 -0
- agentic_project_kit/communication_state.py +115 -0
- agentic_project_kit/composed_wrapper_invariants.py +97 -0
- agentic_project_kit/composite_short_circuit.py +140 -0
- agentic_project_kit/contract.py +251 -0
- agentic_project_kit/control_state.py +83 -0
- agentic_project_kit/doc_currency_audit.py +536 -0
- agentic_project_kit/doc_lifecycle.py +1179 -0
- agentic_project_kit/doc_lifecycle_signals.py +446 -0
- agentic_project_kit/doc_lifecycle_sweep.py +639 -0
- agentic_project_kit/doc_mesh.py +491 -0
- agentic_project_kit/doctor.py +379 -0
- agentic_project_kit/documentation_registry.py +1122 -0
- agentic_project_kit/documentation_system_audit.py +310 -0
- agentic_project_kit/dpa_current_handoff_lifecycle.py +549 -0
- agentic_project_kit/dpa_dp2_decision_readiness.py +362 -0
- agentic_project_kit/dpa_dp3_dp4_adjudication.py +604 -0
- agentic_project_kit/dpa_dp5_block_new_gate.py +294 -0
- agentic_project_kit/dpa_dp5_stage_adoption.py +615 -0
- agentic_project_kit/dpa_dp5_strict_gate.py +187 -0
- agentic_project_kit/dpa_final_closeout.py +627 -0
- agentic_project_kit/dpa_fixture_evidence.py +680 -0
- agentic_project_kit/dpa_maintainer_record_check.py +711 -0
- agentic_project_kit/dpa_post_dp2_scope_assessment.py +734 -0
- agentic_project_kit/dpa_probe_002_readiness.py +509 -0
- agentic_project_kit/dpa_probe_003_readiness.py +417 -0
- agentic_project_kit/dpa_probe_004_readiness.py +437 -0
- agentic_project_kit/dpa_readiness.py +505 -0
- agentic_project_kit/dpa_readonly_probe_execution.py +500 -0
- agentic_project_kit/dpa_registry_contracts.py +312 -0
- agentic_project_kit/dpa_renderer_readiness.py +407 -0
- agentic_project_kit/dpa_repo_adoption_assessment.py +574 -0
- agentic_project_kit/dpa_stable_readiness.py +743 -0
- agentic_project_kit/dpa_successor_projection.py +168 -0
- agentic_project_kit/dpa_workspace_init_projection.py +93 -0
- agentic_project_kit/dpa_wrt_ch001_evidence.py +327 -0
- agentic_project_kit/entrypoint_slice_runner.py +153 -0
- agentic_project_kit/evidence_clean.py +152 -0
- agentic_project_kit/evidence_commit_paths.py +214 -0
- agentic_project_kit/evidence_finalize_log.py +204 -0
- agentic_project_kit/evidence_guard.py +114 -0
- agentic_project_kit/evidence_inspector.py +507 -0
- agentic_project_kit/evidence_state_contract.py +99 -0
- agentic_project_kit/execution_mode_state.py +148 -0
- agentic_project_kit/final_summary_contract.py +85 -0
- agentic_project_kit/finalize_guard.py +139 -0
- agentic_project_kit/gatekeeper_core.py +232 -0
- agentic_project_kit/github.py +25 -0
- agentic_project_kit/governance.py +59 -0
- agentic_project_kit/gui_action_execution.py +105 -0
- agentic_project_kit/gui_action_renderer.py +81 -0
- agentic_project_kit/gui_action_run_intent.py +98 -0
- agentic_project_kit/gui_action_views.py +195 -0
- agentic_project_kit/gui_activity_log.py +76 -0
- agentic_project_kit/gui_button_catalog.py +605 -0
- agentic_project_kit/gui_cockpit.py +365 -0
- agentic_project_kit/gui_cockpit_actions.py +695 -0
- agentic_project_kit/gui_cockpit_common.py +172 -0
- agentic_project_kit/gui_cockpit_header.py +501 -0
- agentic_project_kit/gui_cockpit_sidebar.py +387 -0
- agentic_project_kit/gui_cockpit_task.py +748 -0
- agentic_project_kit/gui_command_projection.py +355 -0
- agentic_project_kit/gui_communication_modes.py +130 -0
- agentic_project_kit/gui_dry_run.py +219 -0
- agentic_project_kit/gui_gatekeeper_status.py +259 -0
- agentic_project_kit/gui_layout_plan.py +148 -0
- agentic_project_kit/gui_open_folder.py +18 -0
- agentic_project_kit/gui_output_status_panel.py +61 -0
- agentic_project_kit/gui_panel_state.py +47 -0
- agentic_project_kit/gui_presenter.py +62 -0
- agentic_project_kit/gui_readiness_gate.py +206 -0
- agentic_project_kit/gui_release_flow.py +59 -0
- agentic_project_kit/gui_task_editor.py +1077 -0
- agentic_project_kit/gui_tk_widgets.py +177 -0
- agentic_project_kit/gui_tkinter_renderer.py +87 -0
- agentic_project_kit/gui_tkinter_shell.py +1176 -0
- agentic_project_kit/gui_transfer_contract.py +28 -0
- agentic_project_kit/gui_viewmodel.py +698 -0
- agentic_project_kit/gui_window_guard.py +46 -0
- agentic_project_kit/handoff_freshness.py +390 -0
- agentic_project_kit/handoff_prompt.py +180 -0
- agentic_project_kit/handoff_state.py +254 -0
- agentic_project_kit/instruction_lint.py +455 -0
- agentic_project_kit/llm_context_carriers.py +66 -0
- agentic_project_kit/llm_execution_context.py +285 -0
- agentic_project_kit/local_command_stack.py +133 -0
- agentic_project_kit/local_feature_gate.py +82 -0
- agentic_project_kit/local_garbage_collector.py +269 -0
- agentic_project_kit/models.py +18 -0
- agentic_project_kit/mutation_lock_audit.py +421 -0
- agentic_project_kit/next_turn_evidence.py +253 -0
- agentic_project_kit/next_turn_merge_if_green.py +459 -0
- agentic_project_kit/next_turn_pr_status.py +255 -0
- agentic_project_kit/next_turn_result.py +183 -0
- agentic_project_kit/next_turn_runner.py +159 -0
- agentic_project_kit/next_turn_slot.py +107 -0
- agentic_project_kit/next_turn_status.py +274 -0
- agentic_project_kit/ns_legacy_reference_audit.py +258 -0
- agentic_project_kit/ns_slice_runner.py +16 -0
- agentic_project_kit/operational_handoff_projection.py +124 -0
- agentic_project_kit/output_contract.py +80 -0
- agentic_project_kit/output_repair.py +61 -0
- agentic_project_kit/pass_already_done.py +216 -0
- agentic_project_kit/patch_artifact_preflight.py +147 -0
- agentic_project_kit/patch_cycle_workflow.py +440 -0
- agentic_project_kit/patch_failure_discipline_audit.py +223 -0
- agentic_project_kit/patch_preflight.py +215 -0
- agentic_project_kit/path_literal_audit.py +612 -0
- agentic_project_kit/patterns.py +99 -0
- agentic_project_kit/planning_docs_consolidation_audit.py +313 -0
- agentic_project_kit/portability_shell_gate.py +40 -0
- agentic_project_kit/post_merge_handoff_refresh.py +56 -0
- agentic_project_kit/post_release.py +252 -0
- agentic_project_kit/post_release_closeout.py +616 -0
- agentic_project_kit/pr_cleanup.py +172 -0
- agentic_project_kit/pr_closeout.py +50 -0
- agentic_project_kit/pr_closeout_complete.py +344 -0
- agentic_project_kit/pr_create_or_skip.py +71 -0
- agentic_project_kit/pr_hygiene.py +210 -0
- agentic_project_kit/program_redundancy_audit.py +251 -0
- agentic_project_kit/project_direction.py +840 -0
- agentic_project_kit/protected_change_planner.py +194 -0
- agentic_project_kit/release.py +401 -0
- agentic_project_kit/release_doi_safety.py +24 -0
- agentic_project_kit/release_gate_core.py +174 -0
- agentic_project_kit/release_metadata_authority_gate.py +328 -0
- agentic_project_kit/release_metadata_prep.py +43 -0
- agentic_project_kit/release_notes.py +823 -0
- agentic_project_kit/release_prep_core.py +204 -0
- agentic_project_kit/release_prepare.py +369 -0
- agentic_project_kit/release_process_guardrails.py +247 -0
- agentic_project_kit/release_publish_core.py +114 -0
- agentic_project_kit/release_publish_orchestration.py +469 -0
- agentic_project_kit/release_state.py +552 -0
- agentic_project_kit/release_verify_core.py +175 -0
- agentic_project_kit/remote_branch_hygiene.py +223 -0
- agentic_project_kit/remote_next.py +89 -0
- agentic_project_kit/remote_next_closeout.py +101 -0
- agentic_project_kit/remote_next_order_contract.py +391 -0
- agentic_project_kit/removed_ns_commands.py +458 -0
- agentic_project_kit/removed_source_audit.py +225 -0
- agentic_project_kit/rendering.py +13 -0
- agentic_project_kit/repair_report.py +79 -0
- agentic_project_kit/repo_identity.py +59 -0
- agentic_project_kit/result_report_classifier.py +57 -0
- agentic_project_kit/rule_ack.py +105 -0
- agentic_project_kit/rule_preservation.py +58 -0
- agentic_project_kit/rule_refresh.py +174 -0
- agentic_project_kit/rule_registry_registration.py +322 -0
- agentic_project_kit/rule_registry_report.py +206 -0
- agentic_project_kit/rule_registry_validator.py +704 -0
- agentic_project_kit/rule_snapshot.py +98 -0
- agentic_project_kit/rule_source_validator.py +133 -0
- agentic_project_kit/run_summary.py +68 -0
- agentic_project_kit/run_summary_renderer.py +238 -0
- agentic_project_kit/runtime_validator.py +68 -0
- agentic_project_kit/safe_file_replace.py +35 -0
- agentic_project_kit/safe_patch.py +47 -0
- agentic_project_kit/safe_push.py +218 -0
- agentic_project_kit/safe_remove_diagnostic.py +51 -0
- agentic_project_kit/scaffold.py +69 -0
- agentic_project_kit/site_claims.py +444 -0
- agentic_project_kit/site_generator.py +1140 -0
- agentic_project_kit/slice_gate.py +225 -0
- agentic_project_kit/slice_runner.py +75 -0
- agentic_project_kit/standard_gates_audit_suite.py +167 -0
- agentic_project_kit/state_freshness.py +135 -0
- agentic_project_kit/status_current_state_audit.py +762 -0
- agentic_project_kit/successor_handoff_package.py +1763 -0
- agentic_project_kit/templates.py +292 -0
- agentic_project_kit/terminal_block_guard.py +166 -0
- agentic_project_kit/terminal_logging.py +275 -0
- agentic_project_kit/todo.py +97 -0
- agentic_project_kit/transfer_closeout.py +136 -0
- agentic_project_kit/transfer_continue.py +215 -0
- agentic_project_kit/transfer_local_runner.py +101 -0
- agentic_project_kit/transfer_operation_monitor.py +236 -0
- agentic_project_kit/transfer_post_merge_lifecycle.py +356 -0
- agentic_project_kit/transfer_post_merge_settle.py +383 -0
- agentic_project_kit/transfer_pr_actions.py +164 -0
- agentic_project_kit/transfer_remote_next.py +959 -0
- agentic_project_kit/transfer_repo_actions.py +2253 -0
- agentic_project_kit/transfer_runner.py +347 -0
- agentic_project_kit/transfer_safety_context.py +291 -0
- agentic_project_kit/transfer_state.py +483 -0
- agentic_project_kit/transfer_uplink.py +471 -0
- agentic_project_kit/transfer_workflow_next.py +148 -0
- agentic_project_kit/typed_work_order_evidence.py +58 -0
- agentic_project_kit/typed_work_order_queue.py +166 -0
- agentic_project_kit/typed_work_order_runner.py +168 -0
- agentic_project_kit/work_cycle.py +317 -0
- agentic_project_kit/work_discard_changes.py +129 -0
- agentic_project_kit/work_order_patch.py +199 -0
- agentic_project_kit/work_order_runner.py +120 -0
- agentic_project_kit/work_order_uploader.py +220 -0
- agentic_project_kit/work_order_validator.py +185 -0
- agentic_project_kit/work_orders.py +246 -0
- agentic_project_kit/workflow_guard.py +262 -0
- agentic_project_kit/workflow_summary_runner.py +124 -0
- agentic_project_kit/workspace.py +665 -0
- agentic_project_kit/workspace_adopt.py +471 -0
- agentic_project_kit/workspace_dpa_intake.py +406 -0
- agentic_project_kit/workspace_init.py +487 -0
- agentic_project_kit/workspace_lock.py +129 -0
- agentic_project_kit/workspace_remove.py +381 -0
- agentic_project_kit/workspace_upgrade.py +324 -0
- agentic_project_kit/wrapper_live_status.py +104 -0
- agentic_project_kit-1.0.1.dist-info/METADATA +724 -0
- agentic_project_kit-1.0.1.dist-info/RECORD +310 -0
- agentic_project_kit-1.0.1.dist-info/WHEEL +4 -0
- agentic_project_kit-1.0.1.dist-info/entry_points.txt +3 -0
- agentic_project_kit-1.0.1.dist-info/licenses/LICENSE +10 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Sequence
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import re
|
|
8
|
+
|
|
9
|
+
from agentic_project_kit.release import CommandResult, run_command
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
PatchCycleRunner = Callable[[Path, Sequence[str]], CommandResult]
|
|
13
|
+
|
|
14
|
+
PATCH_CYCLE_STEPS: tuple[str, ...] = (
|
|
15
|
+
"PATCH_SLICE",
|
|
16
|
+
"PATCH_PR",
|
|
17
|
+
"HANDOFF_REFRESH_SLICE",
|
|
18
|
+
"HANDOFF_REFRESH_PR",
|
|
19
|
+
"POST_MERGE_CLEAN_STATE",
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True)
|
|
24
|
+
class PatchCycleStep:
|
|
25
|
+
id: str
|
|
26
|
+
status: str
|
|
27
|
+
allowed_next_actions: tuple[str, ...]
|
|
28
|
+
blockers: tuple[str, ...] = ()
|
|
29
|
+
evidence: tuple[str, ...] = ()
|
|
30
|
+
|
|
31
|
+
def as_dict(self) -> dict[str, object]:
|
|
32
|
+
return {
|
|
33
|
+
"id": self.id,
|
|
34
|
+
"status": self.status,
|
|
35
|
+
"allowed_next_actions": list(self.allowed_next_actions),
|
|
36
|
+
"blockers": list(self.blockers),
|
|
37
|
+
"evidence": list(self.evidence),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True)
|
|
42
|
+
class PatchCycleStatus:
|
|
43
|
+
schema_version: int
|
|
44
|
+
kind: str
|
|
45
|
+
current_stage: str
|
|
46
|
+
result_status: str
|
|
47
|
+
branch: str
|
|
48
|
+
head_sha: str
|
|
49
|
+
origin_main_sha: str
|
|
50
|
+
worktree_clean: bool
|
|
51
|
+
dirty_paths: tuple[str, ...]
|
|
52
|
+
pr_number: int | None
|
|
53
|
+
pr: dict[str, object] | None
|
|
54
|
+
handoff_generated_head: str
|
|
55
|
+
handoff_validation_status: str
|
|
56
|
+
handoff_fresh_for_head: bool
|
|
57
|
+
steps: tuple[PatchCycleStep, ...]
|
|
58
|
+
next_action: str
|
|
59
|
+
recommended_next_action: str
|
|
60
|
+
disabled_actions: tuple[dict[str, object], ...]
|
|
61
|
+
traffic_lights: dict[str, str]
|
|
62
|
+
blockers: tuple[str, ...]
|
|
63
|
+
|
|
64
|
+
def as_dict(self) -> dict[str, object]:
|
|
65
|
+
return {
|
|
66
|
+
"schema_version": self.schema_version,
|
|
67
|
+
"kind": self.kind,
|
|
68
|
+
"current_stage": self.current_stage,
|
|
69
|
+
"result_status": self.result_status,
|
|
70
|
+
"branch": self.branch,
|
|
71
|
+
"head_sha": self.head_sha,
|
|
72
|
+
"origin_main_sha": self.origin_main_sha,
|
|
73
|
+
"worktree_clean": self.worktree_clean,
|
|
74
|
+
"dirty_paths": list(self.dirty_paths),
|
|
75
|
+
"pr_number": self.pr_number,
|
|
76
|
+
"pr": self.pr,
|
|
77
|
+
"handoff_generated_head": self.handoff_generated_head,
|
|
78
|
+
"handoff_validation_status": self.handoff_validation_status,
|
|
79
|
+
"handoff_fresh_for_head": self.handoff_fresh_for_head,
|
|
80
|
+
"steps": [step.as_dict() for step in self.steps],
|
|
81
|
+
"next_action": self.next_action,
|
|
82
|
+
"recommended_next_action": self.recommended_next_action,
|
|
83
|
+
"disabled_actions": list(self.disabled_actions),
|
|
84
|
+
"traffic_lights": self.traffic_lights,
|
|
85
|
+
"blockers": list(self.blockers),
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def build_patch_cycle_status(
|
|
90
|
+
project_root: Path,
|
|
91
|
+
*,
|
|
92
|
+
pr_number: int | None = None,
|
|
93
|
+
include_ci: bool = False,
|
|
94
|
+
command_runner: PatchCycleRunner | None = None,
|
|
95
|
+
) -> PatchCycleStatus:
|
|
96
|
+
runner = command_runner or run_command
|
|
97
|
+
branch = _stdout(runner(project_root, ["git", "branch", "--show-current"]))
|
|
98
|
+
head_sha = _stdout(runner(project_root, ["git", "rev-parse", "HEAD"]))
|
|
99
|
+
origin_main_sha = _stdout(runner(project_root, ["git", "rev-parse", "origin/main"]))
|
|
100
|
+
status_result = runner(project_root, ["git", "status", "--short", "--untracked-files=all"])
|
|
101
|
+
dirty_paths = tuple(line.strip() for line in status_result.stdout.splitlines() if line.strip())
|
|
102
|
+
worktree_clean = status_result.returncode == 0 and not dirty_paths
|
|
103
|
+
handoff_validation = _read_handoff_validation(project_root)
|
|
104
|
+
handoff_generated_head = str(handoff_validation.get("generated_head") or "")
|
|
105
|
+
handoff_validation_status = str(handoff_validation.get("status") or "MISSING")
|
|
106
|
+
handoff_fresh_for_head = bool(head_sha and handoff_generated_head == head_sha)
|
|
107
|
+
pr = _read_pr(project_root, pr_number, include_ci, runner) if pr_number is not None else None
|
|
108
|
+
current_stage = _current_stage(
|
|
109
|
+
branch=branch,
|
|
110
|
+
worktree_clean=worktree_clean,
|
|
111
|
+
handoff_fresh_for_head=handoff_fresh_for_head,
|
|
112
|
+
)
|
|
113
|
+
blockers = _global_blockers(
|
|
114
|
+
branch=branch,
|
|
115
|
+
head_sha=head_sha,
|
|
116
|
+
origin_main_sha=origin_main_sha,
|
|
117
|
+
dirty_paths=dirty_paths,
|
|
118
|
+
pr=pr,
|
|
119
|
+
)
|
|
120
|
+
steps = _steps_for(
|
|
121
|
+
current_stage=current_stage,
|
|
122
|
+
branch=branch,
|
|
123
|
+
worktree_clean=worktree_clean,
|
|
124
|
+
dirty_paths=dirty_paths,
|
|
125
|
+
pr_number=pr_number,
|
|
126
|
+
pr=pr,
|
|
127
|
+
handoff_fresh_for_head=handoff_fresh_for_head,
|
|
128
|
+
head_sha=head_sha,
|
|
129
|
+
origin_main_sha=origin_main_sha,
|
|
130
|
+
)
|
|
131
|
+
next_action = _next_action(current_stage, blockers, steps)
|
|
132
|
+
disabled_actions = _disabled_actions(steps, blockers)
|
|
133
|
+
traffic_lights = _traffic_lights(steps, blockers)
|
|
134
|
+
result_status = "BLOCKED" if blockers else ("PASS" if current_stage == "POST_MERGE_CLEAN_STATE" else "READY")
|
|
135
|
+
return PatchCycleStatus(
|
|
136
|
+
schema_version=1,
|
|
137
|
+
kind="patch_cycle_workflow_status",
|
|
138
|
+
current_stage=current_stage,
|
|
139
|
+
result_status=result_status,
|
|
140
|
+
branch=branch,
|
|
141
|
+
head_sha=head_sha,
|
|
142
|
+
origin_main_sha=origin_main_sha,
|
|
143
|
+
worktree_clean=worktree_clean,
|
|
144
|
+
dirty_paths=dirty_paths,
|
|
145
|
+
pr_number=pr_number,
|
|
146
|
+
pr=pr,
|
|
147
|
+
handoff_generated_head=handoff_generated_head,
|
|
148
|
+
handoff_validation_status=handoff_validation_status,
|
|
149
|
+
handoff_fresh_for_head=handoff_fresh_for_head,
|
|
150
|
+
steps=steps,
|
|
151
|
+
next_action=next_action,
|
|
152
|
+
recommended_next_action=next_action,
|
|
153
|
+
disabled_actions=disabled_actions,
|
|
154
|
+
traffic_lights=traffic_lights,
|
|
155
|
+
blockers=blockers,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def render_patch_cycle_status(status: PatchCycleStatus) -> str:
|
|
160
|
+
lines = [
|
|
161
|
+
"PATCH_CYCLE_WORKFLOW_STATUS",
|
|
162
|
+
f"RESULT_STATUS={status.result_status}",
|
|
163
|
+
f"CURRENT_STAGE={status.current_stage}",
|
|
164
|
+
f"BRANCH={status.branch or '<unknown>'}",
|
|
165
|
+
f"HEAD={status.head_sha or '<unknown>'}",
|
|
166
|
+
f"ORIGIN_MAIN={status.origin_main_sha or '<unknown>'}",
|
|
167
|
+
f"WORKTREE_CLEAN={str(status.worktree_clean).lower()}",
|
|
168
|
+
f"HANDOFF_VALIDATION_STATUS={status.handoff_validation_status}",
|
|
169
|
+
f"HANDOFF_FRESH_FOR_HEAD={str(status.handoff_fresh_for_head).lower()}",
|
|
170
|
+
]
|
|
171
|
+
if status.pr_number is not None:
|
|
172
|
+
lines.append(f"PR={status.pr_number}")
|
|
173
|
+
for step in status.steps:
|
|
174
|
+
lines.append(
|
|
175
|
+
"STEP="
|
|
176
|
+
+ "|".join(
|
|
177
|
+
[
|
|
178
|
+
step.id,
|
|
179
|
+
step.status,
|
|
180
|
+
",".join(step.allowed_next_actions) or "<none>",
|
|
181
|
+
",".join(step.blockers) or "<none>",
|
|
182
|
+
]
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
for blocker in status.blockers:
|
|
186
|
+
lines.append(f"BLOCKER={blocker}")
|
|
187
|
+
lines.append(f"NEXT={status.next_action}")
|
|
188
|
+
lines.append(f"FINAL_SIGNAL={'f' if status.blockers else 'd'}")
|
|
189
|
+
return "\n".join(lines) + "\n"
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _stdout(result: CommandResult) -> str:
|
|
193
|
+
return (result.stdout or "").strip() if result.returncode == 0 else ""
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _read_handoff_validation(project_root: Path) -> dict[str, object]:
|
|
197
|
+
path = project_root / "docs/reports/handoff-packages/latest/validation_report.json"
|
|
198
|
+
if not path.exists():
|
|
199
|
+
return {}
|
|
200
|
+
try:
|
|
201
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
202
|
+
except json.JSONDecodeError:
|
|
203
|
+
return {"status": "INVALID"}
|
|
204
|
+
return payload
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _read_pr(project_root: Path, pr_number: int, include_ci: bool, runner: PatchCycleRunner) -> dict[str, object]:
|
|
208
|
+
fields = "number,state,mergeStateStatus,headRefName,headRefOid,isDraft,url"
|
|
209
|
+
if include_ci:
|
|
210
|
+
fields += ",statusCheckRollup"
|
|
211
|
+
result = runner(
|
|
212
|
+
project_root,
|
|
213
|
+
[
|
|
214
|
+
"gh",
|
|
215
|
+
"pr",
|
|
216
|
+
"view",
|
|
217
|
+
str(pr_number),
|
|
218
|
+
"--json",
|
|
219
|
+
fields,
|
|
220
|
+
],
|
|
221
|
+
)
|
|
222
|
+
if result.returncode != 0:
|
|
223
|
+
return {
|
|
224
|
+
"number": pr_number,
|
|
225
|
+
"available": False,
|
|
226
|
+
"error": (result.stderr or result.stdout).strip(),
|
|
227
|
+
}
|
|
228
|
+
try:
|
|
229
|
+
payload = json.loads(result.stdout)
|
|
230
|
+
except json.JSONDecodeError as exc:
|
|
231
|
+
return {"number": pr_number, "available": False, "error": f"invalid_pr_json:{exc}"}
|
|
232
|
+
payload["available"] = True
|
|
233
|
+
if include_ci:
|
|
234
|
+
payload["checks"] = _summarize_checks(payload.get("statusCheckRollup"))
|
|
235
|
+
payload["checks_status"] = _checks_status(payload["checks"])
|
|
236
|
+
return payload
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def _summarize_checks(raw_checks: object) -> list[dict[str, object]]:
|
|
240
|
+
if not isinstance(raw_checks, list):
|
|
241
|
+
return []
|
|
242
|
+
checks: list[dict[str, object]] = []
|
|
243
|
+
for item in raw_checks:
|
|
244
|
+
if not isinstance(item, dict):
|
|
245
|
+
continue
|
|
246
|
+
checks.append(
|
|
247
|
+
{
|
|
248
|
+
"name": item.get("name") or item.get("workflowName") or item.get("context") or "<unknown>",
|
|
249
|
+
"status": item.get("status"),
|
|
250
|
+
"conclusion": item.get("conclusion"),
|
|
251
|
+
"state": item.get("state"),
|
|
252
|
+
}
|
|
253
|
+
)
|
|
254
|
+
return checks
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _checks_status(checks: object) -> str:
|
|
258
|
+
if not isinstance(checks, list) or not checks:
|
|
259
|
+
return "UNKNOWN"
|
|
260
|
+
conclusions = {str(item.get("conclusion") or item.get("state") or item.get("status") or "").upper() for item in checks if isinstance(item, dict)}
|
|
261
|
+
if any(value in {"FAILURE", "FAILED", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED"} for value in conclusions):
|
|
262
|
+
return "FAIL"
|
|
263
|
+
if any(value in {"PENDING", "IN_PROGRESS", "QUEUED", "REQUESTED", "WAITING"} for value in conclusions):
|
|
264
|
+
return "PENDING"
|
|
265
|
+
if conclusions and all(value in {"SUCCESS", "COMPLETED", "NEUTRAL", "SKIPPED"} for value in conclusions):
|
|
266
|
+
return "PASS"
|
|
267
|
+
return "UNKNOWN"
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def _current_stage(*, branch: str, worktree_clean: bool, handoff_fresh_for_head: bool) -> str:
|
|
271
|
+
if branch == "main":
|
|
272
|
+
return "POST_MERGE_CLEAN_STATE" if worktree_clean and handoff_fresh_for_head else "HANDOFF_REFRESH_SLICE"
|
|
273
|
+
if _is_handoff_refresh_branch(branch):
|
|
274
|
+
return "HANDOFF_REFRESH_PR" if worktree_clean else "HANDOFF_REFRESH_SLICE"
|
|
275
|
+
return "PATCH_PR" if worktree_clean else "PATCH_SLICE"
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _global_blockers(
|
|
279
|
+
*,
|
|
280
|
+
branch: str,
|
|
281
|
+
head_sha: str,
|
|
282
|
+
origin_main_sha: str,
|
|
283
|
+
dirty_paths: tuple[str, ...],
|
|
284
|
+
pr: dict[str, object] | None,
|
|
285
|
+
) -> tuple[str, ...]:
|
|
286
|
+
blockers: list[str] = []
|
|
287
|
+
if not branch:
|
|
288
|
+
blockers.append("branch_unknown")
|
|
289
|
+
if not head_sha:
|
|
290
|
+
blockers.append("head_unknown")
|
|
291
|
+
if branch == "main" and dirty_paths:
|
|
292
|
+
blockers.append("main_dirty")
|
|
293
|
+
if branch == "main" and origin_main_sha and head_sha and head_sha != origin_main_sha:
|
|
294
|
+
blockers.append("main_not_synced_with_origin_main")
|
|
295
|
+
if pr is not None and pr.get("available") is False:
|
|
296
|
+
blockers.append("pr_metadata_unavailable")
|
|
297
|
+
if pr is not None and pr.get("checks_status") == "FAIL":
|
|
298
|
+
blockers.append("pr_checks_failing")
|
|
299
|
+
return tuple(blockers)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _steps_for(
|
|
303
|
+
*,
|
|
304
|
+
current_stage: str,
|
|
305
|
+
branch: str,
|
|
306
|
+
worktree_clean: bool,
|
|
307
|
+
dirty_paths: tuple[str, ...],
|
|
308
|
+
pr_number: int | None,
|
|
309
|
+
pr: dict[str, object] | None,
|
|
310
|
+
handoff_fresh_for_head: bool,
|
|
311
|
+
head_sha: str,
|
|
312
|
+
origin_main_sha: str,
|
|
313
|
+
) -> tuple[PatchCycleStep, ...]:
|
|
314
|
+
patch_pr_state = _pr_state(pr)
|
|
315
|
+
return (
|
|
316
|
+
PatchCycleStep(
|
|
317
|
+
"PATCH_SLICE",
|
|
318
|
+
"ACTIVE" if current_stage == "PATCH_SLICE" else ("DONE" if current_stage in {"PATCH_PR", "HANDOFF_REFRESH_SLICE", "HANDOFF_REFRESH_PR", "POST_MERGE_CLEAN_STATE"} else "PENDING"),
|
|
319
|
+
_actions("protected_diff_plan", "commit", "push_current") if current_stage == "PATCH_SLICE" else (),
|
|
320
|
+
("worktree_dirty",) if current_stage == "PATCH_SLICE" and dirty_paths else (),
|
|
321
|
+
dirty_paths[:20],
|
|
322
|
+
),
|
|
323
|
+
PatchCycleStep(
|
|
324
|
+
"PATCH_PR",
|
|
325
|
+
"ACTIVE" if current_stage == "PATCH_PR" else ("DONE" if current_stage in {"HANDOFF_REFRESH_SLICE", "HANDOFF_REFRESH_PR", "POST_MERGE_CLEAN_STATE"} else "PENDING"),
|
|
326
|
+
_actions("pr_create_complete", "pr_status") if current_stage == "PATCH_PR" else (),
|
|
327
|
+
_pr_blockers(pr_number, pr),
|
|
328
|
+
_pr_evidence(pr_number, patch_pr_state),
|
|
329
|
+
),
|
|
330
|
+
PatchCycleStep(
|
|
331
|
+
"HANDOFF_REFRESH_SLICE",
|
|
332
|
+
"ACTIVE" if current_stage == "HANDOFF_REFRESH_SLICE" else ("DONE" if current_stage in {"HANDOFF_REFRESH_PR", "POST_MERGE_CLEAN_STATE"} and handoff_fresh_for_head else "PENDING"),
|
|
333
|
+
_actions("admin_refresh_pr", "prepare_successor_handoff", "publish_last_report") if current_stage == "HANDOFF_REFRESH_SLICE" else (),
|
|
334
|
+
() if branch != "main" or not worktree_clean or handoff_fresh_for_head else ("handoff_generated_head_mismatch",),
|
|
335
|
+
(f"handoff_fresh_for_head={handoff_fresh_for_head}",),
|
|
336
|
+
),
|
|
337
|
+
PatchCycleStep(
|
|
338
|
+
"HANDOFF_REFRESH_PR",
|
|
339
|
+
"ACTIVE" if current_stage == "HANDOFF_REFRESH_PR" else ("DONE" if current_stage == "POST_MERGE_CLEAN_STATE" else "PENDING"),
|
|
340
|
+
_actions("pr_create_complete", "pr_status") if current_stage == "HANDOFF_REFRESH_PR" else (),
|
|
341
|
+
(),
|
|
342
|
+
(f"branch={branch}",) if _is_handoff_refresh_branch(branch) else (),
|
|
343
|
+
),
|
|
344
|
+
PatchCycleStep(
|
|
345
|
+
"POST_MERGE_CLEAN_STATE",
|
|
346
|
+
"DONE" if current_stage == "POST_MERGE_CLEAN_STATE" else "PENDING",
|
|
347
|
+
_actions("sync_main", "post_merge_check", "repo_status") if current_stage == "POST_MERGE_CLEAN_STATE" else (),
|
|
348
|
+
() if branch != "main" or (worktree_clean and head_sha == origin_main_sha) else ("main_not_clean_or_not_synced",),
|
|
349
|
+
(f"origin_main={origin_main_sha}",) if origin_main_sha else (),
|
|
350
|
+
),
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def _actions(*names: str) -> tuple[str, ...]:
|
|
355
|
+
mapping = {
|
|
356
|
+
"protected_diff_plan": "agentic-kit transfer protected-diff-plan --label <slice-label>",
|
|
357
|
+
"commit": "agentic-kit transfer commit --message <message> --path <explicit-path>",
|
|
358
|
+
"push_current": "agentic-kit transfer push-current",
|
|
359
|
+
"pr_create_complete": "agentic-kit transfer pr-create-complete --title <title> --body <body>",
|
|
360
|
+
"pr_status": "agentic-kit transfer pr-status " + "<" + "pr-number" + ">" + " --json",
|
|
361
|
+
"admin_refresh_pr": "agentic-kit transfer admin-refresh-pr --after-pr " + "<" + "pr-number" + ">" + " --json",
|
|
362
|
+
"prepare_successor_handoff": "agentic-kit transfer prepare-successor-handoff --render-prompt",
|
|
363
|
+
"publish_last_report": "agentic-kit transfer publish-last-report",
|
|
364
|
+
"sync_main": "agentic-kit transfer sync-main",
|
|
365
|
+
"post_merge_check": "agentic-kit transfer post-merge-check",
|
|
366
|
+
"repo_status": "agentic-kit transfer repo-status",
|
|
367
|
+
}
|
|
368
|
+
return tuple(mapping[name] for name in names)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def _next_action(
|
|
372
|
+
current_stage: str,
|
|
373
|
+
blockers: tuple[str, ...],
|
|
374
|
+
steps: tuple[PatchCycleStep, ...],
|
|
375
|
+
) -> str:
|
|
376
|
+
if blockers:
|
|
377
|
+
return "Diagnose blockers before continuing: " + ", ".join(blockers)
|
|
378
|
+
active = next((step for step in steps if step.id == current_stage), None)
|
|
379
|
+
if active and active.allowed_next_actions:
|
|
380
|
+
return active.allowed_next_actions[0]
|
|
381
|
+
if current_stage == "POST_MERGE_CLEAN_STATE":
|
|
382
|
+
return "Patch cycle is clean; start the next planned slice when ready."
|
|
383
|
+
return "Inspect patch-cycle status and choose the next wrapper-backed action."
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def _pr_state(pr: dict[str, object] | None) -> str:
|
|
387
|
+
if not pr:
|
|
388
|
+
return "unknown"
|
|
389
|
+
if pr.get("available") is False:
|
|
390
|
+
return "unavailable"
|
|
391
|
+
return str(pr.get("state") or "unknown").lower()
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
def _pr_blockers(pr_number: int | None, pr: dict[str, object] | None) -> tuple[str, ...]:
|
|
395
|
+
if pr_number is None:
|
|
396
|
+
return ()
|
|
397
|
+
if pr and pr.get("available") is False:
|
|
398
|
+
return ("pr_metadata_unavailable",)
|
|
399
|
+
if pr and pr.get("checks_status") == "FAIL":
|
|
400
|
+
return ("pr_checks_failing",)
|
|
401
|
+
return ()
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def _pr_evidence(pr_number: int | None, pr_state: str) -> tuple[str, ...]:
|
|
405
|
+
if pr_number is None:
|
|
406
|
+
return ()
|
|
407
|
+
return (f"pr={pr_number}", f"pr_state={pr_state}")
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def _disabled_actions(steps: tuple[PatchCycleStep, ...], blockers: tuple[str, ...]) -> tuple[dict[str, object], ...]:
|
|
411
|
+
disabled: list[dict[str, object]] = []
|
|
412
|
+
for step in steps:
|
|
413
|
+
if step.status == "ACTIVE":
|
|
414
|
+
continue
|
|
415
|
+
disabled.append({"step": step.id, "reason": f"step_status_{step.status.lower()}"})
|
|
416
|
+
for blocker in blockers:
|
|
417
|
+
disabled.append({"step": "GLOBAL", "reason": blocker})
|
|
418
|
+
return tuple(disabled)
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def _traffic_lights(steps: tuple[PatchCycleStep, ...], blockers: tuple[str, ...]) -> dict[str, str]:
|
|
422
|
+
lights: dict[str, str] = {}
|
|
423
|
+
for step in steps:
|
|
424
|
+
if step.blockers:
|
|
425
|
+
lights[step.id] = "red"
|
|
426
|
+
elif step.status == "DONE":
|
|
427
|
+
lights[step.id] = "green"
|
|
428
|
+
elif step.status == "ACTIVE":
|
|
429
|
+
lights[step.id] = "yellow"
|
|
430
|
+
else:
|
|
431
|
+
lights[step.id] = "gray"
|
|
432
|
+
if blockers:
|
|
433
|
+
lights["GLOBAL"] = "red"
|
|
434
|
+
return lights
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def _is_handoff_refresh_branch(branch: str) -> bool:
|
|
438
|
+
return bool(re.match(r"^(docs|codex)/post-pr\\d+-handoff-refresh$", branch)) or (
|
|
439
|
+
"handoff" in branch and "refresh" in branch
|
|
440
|
+
)
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import asdict, dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
PATCH_FAILURE_PATTERNS: tuple[str, ...] = (
|
|
9
|
+
"block not found",
|
|
10
|
+
"expected block not found",
|
|
11
|
+
"assertion block not found",
|
|
12
|
+
"function not found",
|
|
13
|
+
"not found or not uniquely",
|
|
14
|
+
"not uniquely replaced",
|
|
15
|
+
"patch failed",
|
|
16
|
+
"patch guard",
|
|
17
|
+
"old assertion still",
|
|
18
|
+
"old log assertion still",
|
|
19
|
+
"expected current",
|
|
20
|
+
"anchor not found",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
DIAGNOSIS_PATTERNS: tuple[re.Pattern[str], ...] = (
|
|
24
|
+
re.compile(r"RESULT=.*DIAGNOS.*DONE", re.IGNORECASE),
|
|
25
|
+
re.compile(r"RESULT=.*PATCH_FAILURE.*DONE", re.IGNORECASE),
|
|
26
|
+
re.compile(r"PATCH_FAILURE_DIAGNOSIS_DONE", re.IGNORECASE),
|
|
27
|
+
re.compile(r"actual file state", re.IGNORECASE),
|
|
28
|
+
re.compile(r"exact .*test functions", re.IGNORECASE),
|
|
29
|
+
re.compile(r"exact .*diff", re.IGNORECASE),
|
|
30
|
+
re.compile(r"diagnose .*file.*state", re.IGNORECASE),
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
DEFAULT_SCAN_GLOBS: tuple[str, ...] = (
|
|
34
|
+
"docs/reports/command_runs/**/*.md",
|
|
35
|
+
"docs/reports/command_runs/**/*.txt",
|
|
36
|
+
"docs/reports/command_runs/**/*.json",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
TMP_SCAN_GLOBS: tuple[str, ...] = (
|
|
40
|
+
"tmp/*.log",
|
|
41
|
+
"tmp/*.txt",
|
|
42
|
+
"tmp/*.json",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class PatchFailureSignal:
|
|
48
|
+
path: str
|
|
49
|
+
group: str
|
|
50
|
+
kind: str
|
|
51
|
+
detail: str
|
|
52
|
+
mtime_ns: int
|
|
53
|
+
|
|
54
|
+
def as_dict(self) -> dict[str, object]:
|
|
55
|
+
return asdict(self)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass(frozen=True)
|
|
59
|
+
class PatchFailureDisciplineResult:
|
|
60
|
+
root: str
|
|
61
|
+
signals: tuple[PatchFailureSignal, ...]
|
|
62
|
+
violations: tuple[PatchFailureSignal, ...]
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def ok(self) -> bool:
|
|
66
|
+
return not self.violations
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def status(self) -> str:
|
|
70
|
+
return "PASS" if self.ok else "FAIL"
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def returncode(self) -> int:
|
|
74
|
+
return 0 if self.ok else 1
|
|
75
|
+
|
|
76
|
+
def as_dict(self) -> dict[str, object]:
|
|
77
|
+
return {
|
|
78
|
+
"schema_version": 1,
|
|
79
|
+
"kind": "patch_failure_discipline_audit",
|
|
80
|
+
"root": self.root,
|
|
81
|
+
"status": self.status,
|
|
82
|
+
"signal_count": len(self.signals),
|
|
83
|
+
"violation_count": len(self.violations),
|
|
84
|
+
"signals": [signal.as_dict() for signal in self.signals],
|
|
85
|
+
"violations": [signal.as_dict() for signal in self.violations],
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _safe_read(path: Path) -> str:
|
|
90
|
+
try:
|
|
91
|
+
return path.read_text(encoding="utf-8", errors="replace")
|
|
92
|
+
except OSError:
|
|
93
|
+
return ""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _group_for_path(path: Path, root: Path) -> str:
|
|
97
|
+
relative = path.relative_to(root).as_posix()
|
|
98
|
+
name = path.name
|
|
99
|
+
match = re.match(r"(slice\d+)", name)
|
|
100
|
+
if match:
|
|
101
|
+
return match.group(1)
|
|
102
|
+
match = re.match(r"([a-z0-9]+(?:-[a-z0-9]+){0,3})-\d{8}-\d{6}", name)
|
|
103
|
+
if match:
|
|
104
|
+
return match.group(1)
|
|
105
|
+
if relative.startswith("docs/reports/"):
|
|
106
|
+
return relative.rsplit("/", 1)[0]
|
|
107
|
+
return path.stem
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _discover_logs(root: Path, *, include_tmp: bool) -> tuple[Path, ...]:
|
|
111
|
+
globs = list(DEFAULT_SCAN_GLOBS)
|
|
112
|
+
if include_tmp:
|
|
113
|
+
globs.extend(TMP_SCAN_GLOBS)
|
|
114
|
+
paths: list[Path] = []
|
|
115
|
+
for pattern in globs:
|
|
116
|
+
for path in root.glob(pattern):
|
|
117
|
+
if path.is_file() and path not in paths:
|
|
118
|
+
paths.append(path)
|
|
119
|
+
return tuple(sorted(paths))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _signals_for_file(path: Path, root: Path) -> tuple[PatchFailureSignal, ...]:
|
|
123
|
+
text = _safe_read(path)
|
|
124
|
+
lowered = text.lower()
|
|
125
|
+
group = _group_for_path(path, root)
|
|
126
|
+
try:
|
|
127
|
+
mtime_ns = path.stat().st_mtime_ns
|
|
128
|
+
except OSError:
|
|
129
|
+
mtime_ns = 0
|
|
130
|
+
|
|
131
|
+
signals: list[PatchFailureSignal] = []
|
|
132
|
+
matched = [pattern for pattern in PATCH_FAILURE_PATTERNS if pattern in lowered]
|
|
133
|
+
if matched:
|
|
134
|
+
signals.append(
|
|
135
|
+
PatchFailureSignal(
|
|
136
|
+
path=path.relative_to(root).as_posix(),
|
|
137
|
+
group=group,
|
|
138
|
+
kind="patch_failure",
|
|
139
|
+
detail=", ".join(sorted(matched))[:500],
|
|
140
|
+
mtime_ns=mtime_ns,
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
if any(pattern.search(text) for pattern in DIAGNOSIS_PATTERNS):
|
|
145
|
+
signals.append(
|
|
146
|
+
PatchFailureSignal(
|
|
147
|
+
path=path.relative_to(root).as_posix(),
|
|
148
|
+
group=group,
|
|
149
|
+
kind="diagnosis",
|
|
150
|
+
detail="diagnosis marker found",
|
|
151
|
+
mtime_ns=mtime_ns,
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
return tuple(signals)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _violations(signals: tuple[PatchFailureSignal, ...]) -> tuple[PatchFailureSignal, ...]:
|
|
159
|
+
by_group: dict[str, list[PatchFailureSignal]] = {}
|
|
160
|
+
for signal in signals:
|
|
161
|
+
by_group.setdefault(signal.group, []).append(signal)
|
|
162
|
+
|
|
163
|
+
violations: list[PatchFailureSignal] = []
|
|
164
|
+
for group, group_signals in by_group.items():
|
|
165
|
+
ordered = sorted(group_signals, key=lambda item: (item.mtime_ns, item.path, item.kind))
|
|
166
|
+
failures_since_diagnosis = 0
|
|
167
|
+
last_failure: PatchFailureSignal | None = None
|
|
168
|
+
for signal in ordered:
|
|
169
|
+
if signal.kind == "diagnosis":
|
|
170
|
+
failures_since_diagnosis = 0
|
|
171
|
+
last_failure = None
|
|
172
|
+
continue
|
|
173
|
+
if signal.kind == "patch_failure":
|
|
174
|
+
failures_since_diagnosis += 1
|
|
175
|
+
last_failure = signal
|
|
176
|
+
|
|
177
|
+
if failures_since_diagnosis >= 2 and last_failure is not None:
|
|
178
|
+
violations.append(
|
|
179
|
+
PatchFailureSignal(
|
|
180
|
+
path=last_failure.path,
|
|
181
|
+
group=group,
|
|
182
|
+
kind="missing_diagnosis_after_repeated_patch_failure",
|
|
183
|
+
detail=(
|
|
184
|
+
"two or more patch-failure signals occurred without a later "
|
|
185
|
+
"diagnosis marker in the same group"
|
|
186
|
+
),
|
|
187
|
+
mtime_ns=last_failure.mtime_ns,
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
return tuple(violations)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def audit_patch_failure_discipline(
|
|
195
|
+
root: Path = Path("."),
|
|
196
|
+
*,
|
|
197
|
+
include_tmp: bool = False,
|
|
198
|
+
) -> PatchFailureDisciplineResult:
|
|
199
|
+
root = root.resolve()
|
|
200
|
+
signals: list[PatchFailureSignal] = []
|
|
201
|
+
for path in _discover_logs(root, include_tmp=include_tmp):
|
|
202
|
+
signals.extend(_signals_for_file(path, root))
|
|
203
|
+
|
|
204
|
+
signal_tuple = tuple(sorted(signals, key=lambda item: (item.group, item.mtime_ns, item.path, item.kind)))
|
|
205
|
+
return PatchFailureDisciplineResult(
|
|
206
|
+
root=root.as_posix(),
|
|
207
|
+
signals=signal_tuple,
|
|
208
|
+
violations=_violations(signal_tuple),
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def render_patch_failure_discipline(result: PatchFailureDisciplineResult) -> str:
|
|
213
|
+
lines = [
|
|
214
|
+
"PATCH_FAILURE_DISCIPLINE_AUDIT",
|
|
215
|
+
f"STATUS={result.status}",
|
|
216
|
+
f"SIGNAL_COUNT={len(result.signals)}",
|
|
217
|
+
f"VIOLATION_COUNT={len(result.violations)}",
|
|
218
|
+
]
|
|
219
|
+
for violation in result.violations:
|
|
220
|
+
lines.append(f"VIOLATION={violation.group}|{violation.path}|{violation.detail}")
|
|
221
|
+
for signal in result.signals:
|
|
222
|
+
lines.append(f"SIGNAL={signal.kind}|{signal.group}|{signal.path}|{signal.detail}")
|
|
223
|
+
return "\n".join(lines) + "\n"
|