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,664 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# ruff: noqa: F403,F405
|
|
4
|
+
|
|
5
|
+
from agentic_project_kit.cli_commands.transfer_shared import *
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@transfer_app.command("repo-status")
|
|
9
|
+
def repo_status_command(
|
|
10
|
+
short: bool = typer.Option(True, "--short/--full", help="Use short git status by default."),
|
|
11
|
+
json_output: bool = typer.Option(False, "--json", help="Print JSON instead of text."),
|
|
12
|
+
) -> None:
|
|
13
|
+
result = repo_status(short=short)
|
|
14
|
+
_echo_repo_result(result, json_output)
|
|
15
|
+
if result.returncode != 0:
|
|
16
|
+
raise typer.Exit(code=result.returncode)
|
|
17
|
+
|
|
18
|
+
@transfer_app.command("patch-cycle-status")
|
|
19
|
+
def patch_cycle_status_command(
|
|
20
|
+
pr_number: int | None = typer.Option(
|
|
21
|
+
None,
|
|
22
|
+
"--pr",
|
|
23
|
+
help="Optional pull request number to include in the patch-cycle state.",
|
|
24
|
+
),
|
|
25
|
+
include_ci: bool = typer.Option(False, "--include-ci", help="Include PR statusCheckRollup summary when --pr is provided."),
|
|
26
|
+
root: Path = typer.Option(Path("."), "--root", help="Project root."),
|
|
27
|
+
json_output: bool = typer.Option(False, "--json", help="Print JSON instead of text."),
|
|
28
|
+
) -> None:
|
|
29
|
+
"""Render the current four-slice patch/handoff workflow state."""
|
|
30
|
+
result = build_patch_cycle_status(root.resolve(), pr_number=pr_number, include_ci=include_ci)
|
|
31
|
+
if json_output:
|
|
32
|
+
typer.echo(json.dumps(result.as_dict(), indent=2, sort_keys=True))
|
|
33
|
+
else:
|
|
34
|
+
typer.echo(render_patch_cycle_status(result), nl=False)
|
|
35
|
+
if result.blockers:
|
|
36
|
+
raise typer.Exit(code=2)
|
|
37
|
+
|
|
38
|
+
@transfer_app.command("repo-log")
|
|
39
|
+
def repo_log_command(
|
|
40
|
+
limit: int = typer.Option(5, "--limit", "-n", min=1, help="Number of commits to show."),
|
|
41
|
+
json_output: bool = typer.Option(False, "--json", help="Print JSON instead of text."),
|
|
42
|
+
) -> None:
|
|
43
|
+
result = repo_log(limit=limit)
|
|
44
|
+
_echo_repo_result(result, json_output)
|
|
45
|
+
if result.returncode != 0:
|
|
46
|
+
raise typer.Exit(code=result.returncode)
|
|
47
|
+
|
|
48
|
+
@transfer_app.command("head-sha")
|
|
49
|
+
def head_sha_command(
|
|
50
|
+
full: bool = typer.Option(
|
|
51
|
+
False, "--full", help="Print the full HEAD SHA instead of the short SHA."
|
|
52
|
+
),
|
|
53
|
+
json_output: bool = typer.Option(False, "--json", help="Print JSON instead of text."),
|
|
54
|
+
) -> None:
|
|
55
|
+
result = head_sha(full=full)
|
|
56
|
+
_echo_repo_result(result, json_output)
|
|
57
|
+
if result.returncode != 0:
|
|
58
|
+
raise typer.Exit(code=result.returncode)
|
|
59
|
+
|
|
60
|
+
@transfer_app.command("rebase-on-upstream")
|
|
61
|
+
def rebase_on_upstream_command(
|
|
62
|
+
upstream: str = typer.Option("", "--upstream", help="Upstream ref. Defaults to origin/<current-branch>."),
|
|
63
|
+
expected_branch: str = typer.Option("", "--branch", help="Expected current branch before rebasing."),
|
|
64
|
+
json_output: bool = typer.Option(False, "--json", help="Print machine-readable JSON only."),
|
|
65
|
+
) -> None:
|
|
66
|
+
"""Rebase the current branch on its upstream with bounded conflict reporting."""
|
|
67
|
+
import subprocess
|
|
68
|
+
from typing import Any
|
|
69
|
+
|
|
70
|
+
steps: list[dict[str, Any]] = []
|
|
71
|
+
blockers: list[str] = []
|
|
72
|
+
|
|
73
|
+
def run_step(name: str, argv: list[str]) -> dict[str, Any]:
|
|
74
|
+
completed = subprocess.run(argv, text=True, capture_output=True)
|
|
75
|
+
item = {
|
|
76
|
+
"name": name,
|
|
77
|
+
"argv": argv,
|
|
78
|
+
"returncode": completed.returncode,
|
|
79
|
+
"stdout": completed.stdout,
|
|
80
|
+
"stderr": completed.stderr,
|
|
81
|
+
"ok": completed.returncode == 0,
|
|
82
|
+
}
|
|
83
|
+
steps.append(item)
|
|
84
|
+
return item
|
|
85
|
+
|
|
86
|
+
branch_result = run_step("current-branch", ["git", "branch", "--show-current"])
|
|
87
|
+
current_branch = str(branch_result["stdout"]).strip()
|
|
88
|
+
|
|
89
|
+
if branch_result["returncode"] != 0 or not current_branch:
|
|
90
|
+
blockers.append("current_branch_missing")
|
|
91
|
+
if current_branch in {"main", "master"}:
|
|
92
|
+
blockers.append("refuse_main_branch")
|
|
93
|
+
if expected_branch and current_branch != expected_branch:
|
|
94
|
+
blockers.append(f"branch_mismatch_expected_{expected_branch}_actual_{current_branch}")
|
|
95
|
+
|
|
96
|
+
target_upstream = upstream.strip() or (f"origin/{current_branch}" if current_branch else "")
|
|
97
|
+
|
|
98
|
+
if not blockers:
|
|
99
|
+
fetch_result = run_step("fetch-origin", ["git", "fetch", "origin", current_branch])
|
|
100
|
+
if fetch_result["returncode"] != 0:
|
|
101
|
+
# Fallback for new branches whose upstream is main or a custom ref.
|
|
102
|
+
fetch_result = run_step("fetch-origin-main", ["git", "fetch", "origin", "main"])
|
|
103
|
+
if fetch_result["returncode"] != 0:
|
|
104
|
+
blockers.append("fetch_failed")
|
|
105
|
+
|
|
106
|
+
rebase_returncode = 0
|
|
107
|
+
if not blockers:
|
|
108
|
+
rebase_result = run_step("rebase", ["git", "rebase", target_upstream])
|
|
109
|
+
rebase_returncode = int(rebase_result["returncode"])
|
|
110
|
+
if rebase_returncode != 0:
|
|
111
|
+
blockers.append("rebase_failed")
|
|
112
|
+
|
|
113
|
+
conflict_status_result = run_step(
|
|
114
|
+
"conflict-status",
|
|
115
|
+
["./.venv/bin/agentic-kit", "transfer", "conflict-status", "--json"],
|
|
116
|
+
)
|
|
117
|
+
conflict_payload: dict[str, Any] = {}
|
|
118
|
+
try:
|
|
119
|
+
conflict_payload = json.loads(str(conflict_status_result["stdout"]) or "{}")
|
|
120
|
+
except json.JSONDecodeError:
|
|
121
|
+
conflict_payload = {"parse_error": "conflict-status output was not valid JSON"}
|
|
122
|
+
|
|
123
|
+
conflict_present = bool(conflict_payload.get("conflict_present"))
|
|
124
|
+
if conflict_present and "conflict_detected" not in blockers:
|
|
125
|
+
blockers.append("conflict_detected")
|
|
126
|
+
|
|
127
|
+
result_status = "PASS" if not blockers else "BLOCKED"
|
|
128
|
+
final_signal = "d" if result_status == "PASS" else "f"
|
|
129
|
+
next_action = (
|
|
130
|
+
"Rebase completed and no merge/rebase conflict is present."
|
|
131
|
+
if result_status == "PASS"
|
|
132
|
+
else "Inspect rebase/conflict state before continuing: " + ", ".join(blockers)
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
payload = {
|
|
136
|
+
"schema_version": 1,
|
|
137
|
+
"kind": "transfer_rebase_on_upstream_result",
|
|
138
|
+
"action": "rebase-on-upstream",
|
|
139
|
+
"result_status": result_status,
|
|
140
|
+
"final_signal": final_signal,
|
|
141
|
+
"branch": current_branch,
|
|
142
|
+
"upstream": target_upstream,
|
|
143
|
+
"blockers": blockers,
|
|
144
|
+
"conflict_present": conflict_present,
|
|
145
|
+
"conflict_status": conflict_payload,
|
|
146
|
+
"steps": steps,
|
|
147
|
+
"next_action": next_action,
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if json_output:
|
|
151
|
+
typer.echo(json.dumps(payload, indent=2, ensure_ascii=False))
|
|
152
|
+
else:
|
|
153
|
+
_echo_transfer_payload_summary(
|
|
154
|
+
title="TRANSFER_REBASE_ON_UPSTREAM",
|
|
155
|
+
result_status=result_status,
|
|
156
|
+
final_signal=final_signal,
|
|
157
|
+
next_action=next_action,
|
|
158
|
+
fields={
|
|
159
|
+
"BRANCH": current_branch,
|
|
160
|
+
"UPSTREAM": target_upstream,
|
|
161
|
+
"CONFLICT": "yes" if conflict_present else "no",
|
|
162
|
+
"BLOCKERS": len(blockers),
|
|
163
|
+
},
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
if blockers:
|
|
167
|
+
raise typer.Exit(code=2)
|
|
168
|
+
|
|
169
|
+
@transfer_app.command("repo-diff")
|
|
170
|
+
def repo_diff_command(
|
|
171
|
+
cached: bool = typer.Option(False, "--cached", help="Show staged diff."),
|
|
172
|
+
name_only: bool = typer.Option(False, "--name-only", help="Show only changed path names."),
|
|
173
|
+
json_output: bool = typer.Option(False, "--json", help="Print JSON instead of text."),
|
|
174
|
+
) -> None:
|
|
175
|
+
result = repo_diff(cached=cached, name_only=name_only)
|
|
176
|
+
_echo_repo_result(result, json_output)
|
|
177
|
+
if result.returncode != 0:
|
|
178
|
+
raise typer.Exit(code=result.returncode)
|
|
179
|
+
|
|
180
|
+
@transfer_app.command("work-order-patch")
|
|
181
|
+
def work_order_patch_command(
|
|
182
|
+
path: Path = typer.Option(DEFAULT_PATCH_ORDER, "--path", help="JSON/YAML patch work-order path."),
|
|
183
|
+
dry_run: bool = typer.Option(False, "--dry-run", help="Validate without writing files."),
|
|
184
|
+
json_output: bool = typer.Option(False, "--json", help="Print machine-readable JSON only."),
|
|
185
|
+
) -> None:
|
|
186
|
+
"""Apply a guarded JSON/YAML text-replacement patch work order."""
|
|
187
|
+
try:
|
|
188
|
+
patch = load_work_order_patch(path)
|
|
189
|
+
result = apply_work_order_patch(patch, patch_path=path, project_root=Path("."), dry_run=dry_run)
|
|
190
|
+
except (FileNotFoundError, ValueError) as exc:
|
|
191
|
+
result = WorkOrderPatchResult(
|
|
192
|
+
result_status="FAIL",
|
|
193
|
+
returncode=2,
|
|
194
|
+
patch_path=str(path),
|
|
195
|
+
expected_branch="",
|
|
196
|
+
actual_branch="",
|
|
197
|
+
findings=(str(exc),),
|
|
198
|
+
message="Work-order patch could not be loaded.",
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
if json_output:
|
|
202
|
+
typer.echo(json.dumps(work_order_patch_result_as_json_data(result), indent=2, ensure_ascii=False))
|
|
203
|
+
else:
|
|
204
|
+
typer.echo(render_work_order_patch_result(result))
|
|
205
|
+
|
|
206
|
+
if result.returncode != 0:
|
|
207
|
+
raise typer.Exit(code=result.returncode)
|
|
208
|
+
|
|
209
|
+
@transfer_app.command("protected-diff-plan")
|
|
210
|
+
def protected_diff_plan_command(
|
|
211
|
+
label: str = typer.Option("protected-change-plan", "--label", help="Stable label for the temporary diff file."),
|
|
212
|
+
cached: bool = typer.Option(False, "--cached", help="Use staged diff."),
|
|
213
|
+
json_output: bool = typer.Option(False, "--json", help="Print machine-readable JSON only."),
|
|
214
|
+
) -> None:
|
|
215
|
+
"""Write the current diff to /tmp and run the Python protected change planner on it."""
|
|
216
|
+
import json
|
|
217
|
+
import re
|
|
218
|
+
import subprocess
|
|
219
|
+
import sys
|
|
220
|
+
from pathlib import Path
|
|
221
|
+
|
|
222
|
+
safe_label = re.sub(r"[^A-Za-z0-9_.-]+", "-", label).strip("-") or "protected-change-plan"
|
|
223
|
+
diff_path = Path("/tmp") / f"{safe_label}.diff"
|
|
224
|
+
|
|
225
|
+
diff_command = ["git", "diff"]
|
|
226
|
+
if cached:
|
|
227
|
+
diff_command.append("--cached")
|
|
228
|
+
diff_command.extend(["--output", str(diff_path)])
|
|
229
|
+
|
|
230
|
+
diff_result = subprocess.run(diff_command, text=True, capture_output=True)
|
|
231
|
+
plan_result = None
|
|
232
|
+
plan_command = [
|
|
233
|
+
sys.executable,
|
|
234
|
+
"-m",
|
|
235
|
+
"agentic_project_kit.protected_change_planner",
|
|
236
|
+
"--diff-file",
|
|
237
|
+
str(diff_path),
|
|
238
|
+
]
|
|
239
|
+
if diff_result.returncode == 0:
|
|
240
|
+
plan_result = subprocess.run(
|
|
241
|
+
plan_command,
|
|
242
|
+
text=True,
|
|
243
|
+
capture_output=True,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
plan_ok = plan_result is not None and plan_result.returncode == 0
|
|
247
|
+
result_status = "PASS" if diff_result.returncode == 0 and plan_ok else "FAIL"
|
|
248
|
+
final_signal = "d" if result_status == "PASS" else "f"
|
|
249
|
+
next_action = (
|
|
250
|
+
"Protected change plan passed; proceed with explicit add/commit paths."
|
|
251
|
+
if result_status == "PASS"
|
|
252
|
+
else "Inspect protected-diff-plan output before committing."
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
payload = {
|
|
256
|
+
"schema_version": 1,
|
|
257
|
+
"kind": "transfer_protected_diff_plan_result",
|
|
258
|
+
"action": "protected-diff-plan",
|
|
259
|
+
"result_status": result_status,
|
|
260
|
+
"final_signal": final_signal,
|
|
261
|
+
"next_action": next_action,
|
|
262
|
+
"diff_path": str(diff_path),
|
|
263
|
+
"cached": cached,
|
|
264
|
+
"commands": {
|
|
265
|
+
"diff": {
|
|
266
|
+
"argv": diff_command,
|
|
267
|
+
"returncode": diff_result.returncode,
|
|
268
|
+
"stdout": diff_result.stdout,
|
|
269
|
+
"stderr": diff_result.stderr,
|
|
270
|
+
"ok": diff_result.returncode == 0,
|
|
271
|
+
},
|
|
272
|
+
"protected_change_plan": None
|
|
273
|
+
if plan_result is None
|
|
274
|
+
else {
|
|
275
|
+
"argv": plan_command,
|
|
276
|
+
"returncode": plan_result.returncode,
|
|
277
|
+
"stdout": plan_result.stdout,
|
|
278
|
+
"stderr": plan_result.stderr,
|
|
279
|
+
"ok": plan_result.returncode == 0,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if json_output:
|
|
285
|
+
typer.echo(json.dumps(payload, indent=2, ensure_ascii=False))
|
|
286
|
+
else:
|
|
287
|
+
_echo_transfer_payload_summary(
|
|
288
|
+
title="TRANSFER_PROTECTED_DIFF_PLAN",
|
|
289
|
+
result_status=result_status,
|
|
290
|
+
final_signal=final_signal,
|
|
291
|
+
next_action=next_action,
|
|
292
|
+
fields={
|
|
293
|
+
"DIFF": str(diff_path),
|
|
294
|
+
"CACHED": "yes" if cached else "no",
|
|
295
|
+
"PLAN": "PASS" if plan_ok else "FAIL",
|
|
296
|
+
},
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
if result_status != "PASS":
|
|
300
|
+
raise typer.Exit(code=1)
|
|
301
|
+
|
|
302
|
+
@transfer_app.command("conflict-resolve-file")
|
|
303
|
+
def conflict_resolve_file_command(
|
|
304
|
+
path: Path = typer.Argument(..., help="Repository-relative conflicted file to resolve."),
|
|
305
|
+
source: Path = typer.Option(..., "--source", help="File whose content should replace the conflicted target."),
|
|
306
|
+
expected_branch: str = typer.Option("", "--branch", help="Expected current branch."),
|
|
307
|
+
json_output: bool = typer.Option(False, "--json", help="Print machine-readable JSON only."),
|
|
308
|
+
) -> None:
|
|
309
|
+
"""Resolve one conflicted file by replacing it from an explicit source and staging it."""
|
|
310
|
+
import subprocess
|
|
311
|
+
from typing import Any
|
|
312
|
+
|
|
313
|
+
steps: list[dict[str, Any]] = []
|
|
314
|
+
blockers: list[str] = []
|
|
315
|
+
|
|
316
|
+
def run_step(name: str, argv: list[str]) -> dict[str, Any]:
|
|
317
|
+
completed = subprocess.run(argv, text=True, capture_output=True)
|
|
318
|
+
item = {
|
|
319
|
+
"name": name,
|
|
320
|
+
"argv": argv,
|
|
321
|
+
"returncode": completed.returncode,
|
|
322
|
+
"stdout": completed.stdout,
|
|
323
|
+
"stderr": completed.stderr,
|
|
324
|
+
"ok": completed.returncode == 0,
|
|
325
|
+
}
|
|
326
|
+
steps.append(item)
|
|
327
|
+
return item
|
|
328
|
+
|
|
329
|
+
target = Path(path)
|
|
330
|
+
source_path = Path(source)
|
|
331
|
+
current_branch = ""
|
|
332
|
+
unmerged_files: list[str] = []
|
|
333
|
+
|
|
334
|
+
if target.is_absolute() or ".." in target.parts:
|
|
335
|
+
blockers.append("unsafe_target_path")
|
|
336
|
+
if source_path.is_dir():
|
|
337
|
+
blockers.append("source_is_directory")
|
|
338
|
+
if not source_path.exists():
|
|
339
|
+
blockers.append("source_missing")
|
|
340
|
+
|
|
341
|
+
branch_result = run_step("current-branch", ["git", "branch", "--show-current"])
|
|
342
|
+
current_branch = str(branch_result["stdout"]).strip()
|
|
343
|
+
if branch_result["returncode"] != 0 or not current_branch:
|
|
344
|
+
blockers.append("current_branch_missing")
|
|
345
|
+
if current_branch in {"main", "master"}:
|
|
346
|
+
blockers.append("refuse_main_branch")
|
|
347
|
+
if expected_branch and current_branch != expected_branch:
|
|
348
|
+
blockers.append(f"branch_mismatch_expected_{expected_branch}_actual_{current_branch}")
|
|
349
|
+
|
|
350
|
+
unmerged_result = run_step("unmerged-files", ["git", "diff", "--name-only", "--diff-filter=U"])
|
|
351
|
+
unmerged_files = [line.strip() for line in str(unmerged_result["stdout"]).splitlines() if line.strip()]
|
|
352
|
+
target_text = target.as_posix()
|
|
353
|
+
if unmerged_result["returncode"] != 0:
|
|
354
|
+
blockers.append("unmerged_files_check_failed")
|
|
355
|
+
elif target_text not in unmerged_files:
|
|
356
|
+
blockers.append("target_not_unmerged")
|
|
357
|
+
|
|
358
|
+
if not blockers:
|
|
359
|
+
try:
|
|
360
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
361
|
+
target.write_text(source_path.read_text(encoding="utf-8"), encoding="utf-8")
|
|
362
|
+
except OSError as exc:
|
|
363
|
+
blockers.append(f"write_failed:{exc}")
|
|
364
|
+
else:
|
|
365
|
+
add_result = run_step("git-add-target", ["git", "add", target_text])
|
|
366
|
+
if add_result["returncode"] != 0:
|
|
367
|
+
blockers.append("git_add_failed")
|
|
368
|
+
|
|
369
|
+
result_status = "PASS" if not blockers else "BLOCKED"
|
|
370
|
+
final_signal = "d" if result_status == "PASS" else "f"
|
|
371
|
+
next_action = (
|
|
372
|
+
"Conflict file resolved and staged; run conflict-status or continue the rebase/merge."
|
|
373
|
+
if result_status == "PASS"
|
|
374
|
+
else "Inspect conflict-resolve-file blockers before continuing: " + ", ".join(blockers)
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
payload = {
|
|
378
|
+
"schema_version": 1,
|
|
379
|
+
"kind": "transfer_conflict_resolve_file_result",
|
|
380
|
+
"action": "conflict-resolve-file",
|
|
381
|
+
"result_status": result_status,
|
|
382
|
+
"final_signal": final_signal,
|
|
383
|
+
"branch": current_branch,
|
|
384
|
+
"path": target_text,
|
|
385
|
+
"source": str(source_path),
|
|
386
|
+
"blockers": blockers,
|
|
387
|
+
"unmerged_files": unmerged_files,
|
|
388
|
+
"steps": steps,
|
|
389
|
+
"next_action": next_action,
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if json_output:
|
|
393
|
+
typer.echo(json.dumps(payload, indent=2, ensure_ascii=False))
|
|
394
|
+
else:
|
|
395
|
+
_echo_transfer_payload_summary(
|
|
396
|
+
title="TRANSFER_CONFLICT_RESOLVE_FILE",
|
|
397
|
+
result_status=result_status,
|
|
398
|
+
final_signal=final_signal,
|
|
399
|
+
next_action=next_action,
|
|
400
|
+
fields={
|
|
401
|
+
"BRANCH": current_branch,
|
|
402
|
+
"PATH": target_text,
|
|
403
|
+
"SOURCE": str(source_path),
|
|
404
|
+
"BLOCKERS": len(blockers),
|
|
405
|
+
},
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
if blockers:
|
|
409
|
+
raise typer.Exit(code=2)
|
|
410
|
+
|
|
411
|
+
@transfer_app.command("conflict-status")
|
|
412
|
+
def conflict_status_command(
|
|
413
|
+
json_output: bool = typer.Option(False, "--json", help="Print machine-readable JSON only."),
|
|
414
|
+
) -> None:
|
|
415
|
+
"""Report merge/rebase conflict state without resolving anything."""
|
|
416
|
+
import json
|
|
417
|
+
import subprocess
|
|
418
|
+
from pathlib import Path
|
|
419
|
+
|
|
420
|
+
def run(argv: list[str]) -> dict[str, object]:
|
|
421
|
+
completed = subprocess.run(argv, text=True, capture_output=True)
|
|
422
|
+
return {
|
|
423
|
+
"argv": argv,
|
|
424
|
+
"returncode": completed.returncode,
|
|
425
|
+
"stdout": completed.stdout,
|
|
426
|
+
"stderr": completed.stderr,
|
|
427
|
+
"ok": completed.returncode == 0,
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
branch = run(["git", "branch", "--show-current"])
|
|
431
|
+
status = run(["git", "status", "--short"])
|
|
432
|
+
unmerged = run(["git", "diff", "--name-only", "--diff-filter=U"])
|
|
433
|
+
|
|
434
|
+
rebase_apply = Path(".git/rebase-apply").exists()
|
|
435
|
+
rebase_merge = Path(".git/rebase-merge").exists()
|
|
436
|
+
merge_head = Path(".git/MERGE_HEAD").exists()
|
|
437
|
+
|
|
438
|
+
unmerged_files = [
|
|
439
|
+
line.strip()
|
|
440
|
+
for line in str(unmerged["stdout"]).splitlines()
|
|
441
|
+
if line.strip()
|
|
442
|
+
]
|
|
443
|
+
conflict_present = bool(unmerged_files or rebase_apply or rebase_merge or merge_head)
|
|
444
|
+
|
|
445
|
+
result_status = "CONFLICT" if conflict_present else "PASS"
|
|
446
|
+
final_signal = "f" if conflict_present else "d"
|
|
447
|
+
next_action = (
|
|
448
|
+
"Resolve or abort the active merge/rebase before continuing."
|
|
449
|
+
if conflict_present
|
|
450
|
+
else "No merge/rebase conflict detected."
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
payload = {
|
|
454
|
+
"schema_version": 1,
|
|
455
|
+
"kind": "transfer_conflict_status_result",
|
|
456
|
+
"action": "conflict-status",
|
|
457
|
+
"result_status": result_status,
|
|
458
|
+
"final_signal": final_signal,
|
|
459
|
+
"next_action": next_action,
|
|
460
|
+
"repo": {
|
|
461
|
+
"branch": str(branch["stdout"]).strip(),
|
|
462
|
+
"status_short": status["stdout"],
|
|
463
|
+
"conflict_present": conflict_present,
|
|
464
|
+
"unmerged_files": unmerged_files,
|
|
465
|
+
"rebase_apply": rebase_apply,
|
|
466
|
+
"rebase_merge": rebase_merge,
|
|
467
|
+
"merge_head": merge_head,
|
|
468
|
+
},
|
|
469
|
+
"commands": {
|
|
470
|
+
"branch": branch,
|
|
471
|
+
"status": status,
|
|
472
|
+
"unmerged": unmerged,
|
|
473
|
+
},
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if json_output:
|
|
477
|
+
typer.echo(json.dumps(payload, indent=2, ensure_ascii=False))
|
|
478
|
+
else:
|
|
479
|
+
_echo_transfer_payload_summary(
|
|
480
|
+
title="TRANSFER_CONFLICT_STATUS",
|
|
481
|
+
result_status=result_status,
|
|
482
|
+
final_signal=final_signal,
|
|
483
|
+
next_action=next_action,
|
|
484
|
+
fields={
|
|
485
|
+
"BRANCH": str(branch["stdout"]).strip(),
|
|
486
|
+
"CONFLICT": "yes" if conflict_present else "no",
|
|
487
|
+
"UNMERGED": len(unmerged_files),
|
|
488
|
+
},
|
|
489
|
+
)
|
|
490
|
+
if unmerged_files:
|
|
491
|
+
typer.echo("")
|
|
492
|
+
typer.echo("UNMERGED_FILES")
|
|
493
|
+
for item in unmerged_files:
|
|
494
|
+
typer.echo(f"- {item}")
|
|
495
|
+
|
|
496
|
+
if conflict_present:
|
|
497
|
+
raise typer.Exit(code=2)
|
|
498
|
+
|
|
499
|
+
@transfer_app.command("fetch-origin")
|
|
500
|
+
def fetch_origin_command(
|
|
501
|
+
branch: str = typer.Option("main", "--branch", help="Remote branch to fetch from origin."),
|
|
502
|
+
json_output: bool = typer.Option(False, "--json", help="Print JSON instead of text."),
|
|
503
|
+
) -> None:
|
|
504
|
+
result = fetch_origin(branch)
|
|
505
|
+
_echo_repo_result(result, json_output)
|
|
506
|
+
if result.returncode != 0:
|
|
507
|
+
raise typer.Exit(code=result.returncode)
|
|
508
|
+
|
|
509
|
+
@transfer_app.command("pull-current")
|
|
510
|
+
def pull_current_command(
|
|
511
|
+
json_output: bool = typer.Option(False, "--json", help="Print JSON instead of text."),
|
|
512
|
+
) -> None:
|
|
513
|
+
result = pull_current()
|
|
514
|
+
_echo_repo_result(result, json_output)
|
|
515
|
+
if result.returncode != 0:
|
|
516
|
+
raise typer.Exit(code=result.returncode)
|
|
517
|
+
|
|
518
|
+
@transfer_app.command("delete-merged-work-branch")
|
|
519
|
+
def delete_merged_work_branch_command(
|
|
520
|
+
branch: str = typer.Argument(..., help="Merged feature/docs/fix/chore/evidence branch to delete."),
|
|
521
|
+
remote: bool = typer.Option(True, "--remote/--no-remote", help="Delete the branch on origin."),
|
|
522
|
+
local: bool = typer.Option(True, "--local/--no-local", help="Delete the local branch."),
|
|
523
|
+
force_local: bool = typer.Option(False, "--force-local", help="Force local deletion with git branch -D."),
|
|
524
|
+
json_output: bool = typer.Option(False, "--json", help="Print machine-readable JSON only."),
|
|
525
|
+
) -> None:
|
|
526
|
+
"""Delete a merged non-main work branch after PR merge-state verification."""
|
|
527
|
+
import subprocess
|
|
528
|
+
from typing import Any
|
|
529
|
+
|
|
530
|
+
steps: list[dict[str, Any]] = []
|
|
531
|
+
blockers: list[str] = []
|
|
532
|
+
|
|
533
|
+
def run_step(name: str, argv: list[str]) -> dict[str, Any]:
|
|
534
|
+
completed = subprocess.run(argv, text=True, capture_output=True)
|
|
535
|
+
item = {
|
|
536
|
+
"name": name,
|
|
537
|
+
"argv": argv,
|
|
538
|
+
"returncode": completed.returncode,
|
|
539
|
+
"stdout": completed.stdout,
|
|
540
|
+
"stderr": completed.stderr,
|
|
541
|
+
"ok": completed.returncode == 0,
|
|
542
|
+
}
|
|
543
|
+
steps.append(item)
|
|
544
|
+
return item
|
|
545
|
+
|
|
546
|
+
allowed_prefixes = ("feature/", "fix/", "docs/", "chore/", "evidence/")
|
|
547
|
+
current_branch = ""
|
|
548
|
+
pr_number = ""
|
|
549
|
+
|
|
550
|
+
if branch in {"main", "master"}:
|
|
551
|
+
blockers.append("refuse_main_branch")
|
|
552
|
+
if branch.startswith("/") or branch.endswith("/") or ".." in branch or " " in branch:
|
|
553
|
+
blockers.append("unsafe_branch_name")
|
|
554
|
+
if not branch.startswith(allowed_prefixes):
|
|
555
|
+
blockers.append("branch_prefix_not_allowed")
|
|
556
|
+
if not (local or remote):
|
|
557
|
+
blockers.append("nothing_to_delete")
|
|
558
|
+
|
|
559
|
+
current_result = run_step("current-branch", ["git", "branch", "--show-current"])
|
|
560
|
+
current_branch = str(current_result["stdout"]).strip()
|
|
561
|
+
if current_result["returncode"] != 0:
|
|
562
|
+
blockers.append("current_branch_check_failed")
|
|
563
|
+
if current_branch == branch:
|
|
564
|
+
blockers.append("refuse_delete_current_branch")
|
|
565
|
+
|
|
566
|
+
pr_view = run_step(
|
|
567
|
+
"pr-view-state",
|
|
568
|
+
[
|
|
569
|
+
"gh",
|
|
570
|
+
"pr",
|
|
571
|
+
"view",
|
|
572
|
+
branch,
|
|
573
|
+
"--json",
|
|
574
|
+
"state,mergedAt,number,headRefName",
|
|
575
|
+
"--jq",
|
|
576
|
+
".state + \"\\t\" + (.mergedAt // \"\") + \"\\t\" + (.number|tostring) + \"\\t\" + .headRefName",
|
|
577
|
+
],
|
|
578
|
+
)
|
|
579
|
+
pr_info = str(pr_view["stdout"]).strip()
|
|
580
|
+
if pr_view["returncode"] != 0 or not pr_info:
|
|
581
|
+
blockers.append("pr_state_not_verified")
|
|
582
|
+
else:
|
|
583
|
+
parts = pr_info.split("\t")
|
|
584
|
+
state = parts[0] if len(parts) > 0 else ""
|
|
585
|
+
merged_at = parts[1] if len(parts) > 1 else ""
|
|
586
|
+
pr_number = parts[2] if len(parts) > 2 else ""
|
|
587
|
+
head_ref = parts[3] if len(parts) > 3 else ""
|
|
588
|
+
if state != "MERGED" or not merged_at:
|
|
589
|
+
blockers.append("pr_not_merged")
|
|
590
|
+
if head_ref and head_ref != branch:
|
|
591
|
+
blockers.append("pr_head_branch_mismatch")
|
|
592
|
+
|
|
593
|
+
if not blockers and local:
|
|
594
|
+
delete_args = ["git", "branch", "-D" if force_local else "-d", branch]
|
|
595
|
+
local_delete = run_step("delete-local-branch", delete_args)
|
|
596
|
+
if local_delete["returncode"] != 0:
|
|
597
|
+
blockers.append("local_delete_failed")
|
|
598
|
+
|
|
599
|
+
if not blockers and remote:
|
|
600
|
+
remote_delete = run_step("delete-remote-branch", ["git", "push", "origin", "--delete", branch])
|
|
601
|
+
if remote_delete["returncode"] != 0:
|
|
602
|
+
blockers.append("remote_delete_failed")
|
|
603
|
+
|
|
604
|
+
result_status = "PASS" if not blockers else "BLOCKED"
|
|
605
|
+
final_signal = "d" if result_status == "PASS" else "f"
|
|
606
|
+
next_action = (
|
|
607
|
+
"Merged work branch deletion completed."
|
|
608
|
+
if result_status == "PASS"
|
|
609
|
+
else "Inspect delete-merged-work-branch blockers before continuing: " + ", ".join(blockers)
|
|
610
|
+
)
|
|
611
|
+
|
|
612
|
+
payload = {
|
|
613
|
+
"schema_version": 1,
|
|
614
|
+
"kind": "transfer_delete_merged_work_branch_result",
|
|
615
|
+
"action": "delete-merged-work-branch",
|
|
616
|
+
"result_status": result_status,
|
|
617
|
+
"final_signal": final_signal,
|
|
618
|
+
"branch": branch,
|
|
619
|
+
"current_branch": current_branch,
|
|
620
|
+
"pr_number": pr_number,
|
|
621
|
+
"local_requested": local,
|
|
622
|
+
"remote_requested": remote,
|
|
623
|
+
"blockers": blockers,
|
|
624
|
+
"steps": steps,
|
|
625
|
+
"next_action": next_action,
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
if json_output:
|
|
629
|
+
typer.echo(json.dumps(payload, indent=2, ensure_ascii=False))
|
|
630
|
+
else:
|
|
631
|
+
_echo_transfer_payload_summary(
|
|
632
|
+
title="TRANSFER_DELETE_MERGED_WORK_BRANCH",
|
|
633
|
+
result_status=result_status,
|
|
634
|
+
final_signal=final_signal,
|
|
635
|
+
next_action=next_action,
|
|
636
|
+
fields={
|
|
637
|
+
"BRANCH": branch,
|
|
638
|
+
"CURRENT": current_branch,
|
|
639
|
+
"PR": pr_number or "none",
|
|
640
|
+
"BLOCKERS": len(blockers),
|
|
641
|
+
},
|
|
642
|
+
)
|
|
643
|
+
|
|
644
|
+
if blockers:
|
|
645
|
+
raise typer.Exit(code=2)
|
|
646
|
+
|
|
647
|
+
@transfer_app.command("branch-delete")
|
|
648
|
+
def branch_delete_command(
|
|
649
|
+
branch: str = typer.Argument(..., help="Branch name to delete."),
|
|
650
|
+
remote: bool = typer.Option(
|
|
651
|
+
False, "--remote", help="Delete branch on origin instead of locally."
|
|
652
|
+
),
|
|
653
|
+
force: bool = typer.Option(False, "--force", help="Force local branch deletion with -D."),
|
|
654
|
+
json_output: bool = typer.Option(False, "--json", help="Print JSON instead of text."),
|
|
655
|
+
) -> None:
|
|
656
|
+
require_capability = _public_transfer_attr("_require_transfer_capability", _require_transfer_capability)
|
|
657
|
+
require_capability("rules_confirmed")
|
|
658
|
+
result = branch_delete(branch, remote=remote, force=force)
|
|
659
|
+
_echo_repo_result(result, json_output)
|
|
660
|
+
if result.returncode != 0:
|
|
661
|
+
raise typer.Exit(code=result.returncode)
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
__all__ = [name for name in globals() if not name.startswith("__")]
|