Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions planfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,48 @@ def admit_comparative_findings(
dry_run=dry_run,
)

def reconcile_in_progress(
self,
*,
apply: bool = False,
sprint: str = "active",
workspace_root: str | Path | None = None,
now: datetime | None = None,
actor: str = "planfile.reconcile",
) -> dict:
"""Reconcile ``in_progress`` tickets against live leases, worktrees, and merge receipts."""
from planfile.reconcile import reconcile_in_progress

return reconcile_in_progress(
self,
apply=apply,
sprint=sprint,
workspace_root=workspace_root,
now=now,
actor=actor,
)

reconcile = reconcile_in_progress

def executable_queue(
self,
*,
sprint: str = "active",
workspace_root: str | Path | None = None,
queue: str | None = None,
now: datetime | None = None,
) -> dict:
"""Return the canonical ``planfile.executable-queue/v1`` summary for this repository."""
from planfile.executable_queue import executable_queue

return executable_queue(
self,
sprint=sprint,
workspace_root=workspace_root,
queue=queue,
now=now,
)


def quick_ticket(name: str, tool: str = "unknown", **kwargs) -> Ticket:
"""One-liner ticket creation for tools."""
Expand All @@ -934,6 +976,12 @@ def quick_ticket(name: str, tool: str = "unknown", **kwargs) -> Ticket:
"ComparativeFindingProposal", "ExecutorOwnershipSpec",
"ObsoleteTargetHeadError", "admit_comparative_findings",
"compute_comparative_dedupe_key", "compute_requirement_fingerprint",
# Reconciliation & Executable Queue
"EXECUTABLE_QUEUE_SCHEMA", "RECONCILE_REPORT_SCHEMA",
"CandidateEvaluation", "evaluate_executable_candidate",
"executable_queue", "executable_skip_reason",
"fleet_executable_queue", "is_executable_candidate",
"reconcile", "reconcile_fleet_in_progress", "reconcile_in_progress",
# Store & API
"PlanfileStore", "Planfile", "quick_ticket",
# Executors (lazy loaded)
Expand Down Expand Up @@ -962,6 +1010,23 @@ def quick_ticket(name: str, tool: str = "unknown", **kwargs) -> Ticket:
"compute_requirement_fingerprint",
})

_RECONCILE_EXPORTS = frozenset({
"RECONCILE_REPORT_SCHEMA",
"reconcile",
"reconcile_fleet_in_progress",
"reconcile_in_progress",
})

_EXECUTABLE_QUEUE_EXPORTS = frozenset({
"EXECUTABLE_QUEUE_SCHEMA",
"CandidateEvaluation",
"evaluate_executable_candidate",
"executable_queue",
"executable_skip_reason",
"fleet_executable_queue",
"is_executable_candidate",
})

_TESTQL_EXPORTS = frozenset({
"run_testql_validation",
"build_testql_tickets",
Expand All @@ -984,6 +1049,24 @@ def __getattr__(name):
value = getattr(comparative_findings, name)
globals()[name] = value
return value
if name in _RECONCILE_EXPORTS:
import importlib

reconcile_mod = importlib.import_module("planfile.reconcile")
if name == "reconcile":
return reconcile_mod
value = getattr(reconcile_mod, name)
globals()[name] = value
return value
if name in _EXECUTABLE_QUEUE_EXPORTS:
import importlib

executable_queue_mod = importlib.import_module("planfile.executable_queue")
if name == "executable_queue":
return executable_queue_mod
value = getattr(executable_queue_mod, name)
globals()[name] = value
return value
if name in _TESTQL_EXPORTS:
from planfile import testql_integration

Expand Down
14 changes: 12 additions & 2 deletions planfile/cli/extra_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
Commands are organized into separate modules for better maintainability.
"""

import typer

from planfile.cli.groups.examples import create_examples_app
from planfile.cli.groups.health import create_health_app
from planfile.cli.groups.ticket.reconcile import (
ticket_executable_queue,
ticket_reconcile,
)


def add_extra_commands(app):
"""Add health and examples command groups to the CLI app."""
def add_extra_commands(app: typer.Typer) -> None:
"""Add health, examples, reconciliation, and executable-queue commands to the CLI app."""
# Add health commands
health_app = create_health_app()
app.add_typer(health_app, name="health")

# Add examples commands
examples_app = create_examples_app()
app.add_typer(examples_app, name="examples")

# Top-level reconciliation and canonical executable queue commands
app.command("reconcile")(ticket_reconcile)
app.command("executable-queue")(ticket_executable_queue)
6 changes: 6 additions & 0 deletions planfile/cli/groups/ticket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
ticket_validate,
ticket_waves,
)
from planfile.cli.groups.ticket.reconcile import (
ticket_executable_queue,
ticket_reconcile,
)


def register_ticket_commands(app: typer.Typer) -> None:
Expand Down Expand Up @@ -81,5 +85,7 @@ def ticket_callback(ctx: typer.Context) -> None:
ticket_app.command("decompose")(ticket_decompose)
ticket_app.command("coverage")(ticket_coverage)
ticket_app.command("prune-deps")(ticket_prune_deps)
ticket_app.command("reconcile")(ticket_reconcile)
ticket_app.command("executable-queue")(ticket_executable_queue)

app.add_typer(ticket_app, name="ticket")
220 changes: 220 additions & 0 deletions planfile/cli/groups/ticket/reconcile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
"""CLI commands for ``in_progress`` reconciliation and canonical executable queue reporting."""

from __future__ import annotations

import json
import sys
from typing import Any

import typer
import yaml
from rich.table import Table

from planfile.cli.core import console


def _emit_structured(payload: dict[str, Any], fmt: str) -> bool:
normalized = fmt.strip().lower()
if normalized == "json":
sys.stdout.write(json.dumps(payload, indent=2, sort_keys=False) + "\n")
return True
if normalized == "yaml":
sys.stdout.write(yaml.safe_dump(payload, sort_keys=False, allow_unicode=True))
return True
return False


def _render_reconcile_table(report: dict[str, Any]) -> None:
counts = report["counts"]
mode_label = "APPLIED" if report["mode"] == "apply" else "DRY-RUN"
console.print(
f"[bold]in_progress reconciliation ({mode_label})[/bold] — "
f"scanned={counts['scanned_in_progress']} "
f"merged->done={counts['merged_to_done']} "
f"abandoned->open={counts['abandoned_to_open']} "
f"active={counts['active_retained']} "
f"unobserved={counts['unobserved_preserved']}"
)
decisions = report.get("decisions") or []
if not decisions:
console.print("[dim]No in_progress tickets found in scope.[/dim]")
return

table = Table(show_header=True)
table.add_column("Ticket", style="cyan", no_wrap=True)
table.add_column("Sprint")
table.add_column("Class")
table.add_column("Transition", no_wrap=True)
table.add_column("Applied")
table.add_column("Reason / Evidence")

for item in decisions:
evidence = str(item.get("reason") or "")
if item.get("terminalSha"):
evidence = f"{evidence} ({str(item['terminalSha'])[:12]})"
elif item.get("leaseId"):
evidence = f"{evidence}"
table.add_row(
str(item.get("id") or ""),
str(item.get("sprint") or ""),
str(item.get("classification") or ""),
f"{item.get('previous_status')} -> {item.get('proposed_status')}",
"yes" if item.get("applied") else "no",
evidence,
)
console.print(table)


def _render_executable_queue_table(report: dict[str, Any]) -> None:
counts = report["counts"]
console.print(
f"[bold]Executable Pending Queue ({report['schema']})[/bold] — "
f"executable={counts['executable']} "
f"open={counts['open']} "
f"in_progress={counts['in_progress']} "
f"excluded={counts['excluded']} "
f"scanned={counts['total_scanned']}"
)
candidates = report.get("candidates") or []
if not candidates:
console.print("[dim]No executable candidates in scope.[/dim]")
return

table = Table(show_header=True)
table.add_column("ID", style="cyan", no_wrap=True)
table.add_column("Priority", no_wrap=True)
table.add_column("Sprint", no_wrap=True)
table.add_column("Repository")
table.add_column("Name")

for cand in candidates:
table.add_row(
str(cand.get("id") or ""),
str(cand.get("priority") or "normal"),
str(cand.get("sprint") or "current"),
str(cand.get("repository") or cand.get("repo_path") or ""),
str(cand.get("name") or ""),
)
console.print(table)


def ticket_reconcile(
project: str = typer.Option(".", "--project", "-p", help="Project directory"),
sprint: str = typer.Option(
"active",
"--sprint",
"-s",
help="Sprint scope ('active', 'current', 'backlog', 'all', or sprint ID)",
),
workspace_root: str | None = typer.Option(
None,
"--workspace-root",
"-w",
help="Workspace directory for resolving external target repositories",
),
fleet: bool = typer.Option(
False,
"--fleet",
help="Reconcile all .planfile repositories discovered under workspace root",
),
apply: bool = typer.Option(
False,
"--apply",
help="Atomically apply status transitions (default is dry-run report)",
),
actor: str = typer.Option(
"planfile.reconcile",
"--actor",
help="Audit actor recorded when --apply mutates tickets",
),
fmt: str = typer.Option(
"table",
"--format",
"-f",
help="Output format: table, json, or yaml",
),
) -> None:
"""Reconcile in_progress tickets with live leases, worktrees, and merge receipts."""
if fmt.strip().lower() not in {"table", "json", "yaml"}:
console.print(f"[red]Unsupported format: {fmt} (choose table, json, or yaml)[/red]")
raise typer.Exit(2)

from planfile.reconcile import reconcile_fleet_in_progress, reconcile_in_progress

if fleet:
root_dir = workspace_root or project
report = reconcile_fleet_in_progress(
root_dir,
apply=apply,
sprint=sprint,
actor=actor,
)
else:
report = reconcile_in_progress(
project,
apply=apply,
sprint=sprint,
workspace_root=workspace_root,
actor=actor,
)

if not _emit_structured(report, fmt):
_render_reconcile_table(report)


def ticket_executable_queue(
project: str = typer.Option(".", "--project", "-p", help="Project directory"),
sprint: str = typer.Option(
"active",
"--sprint",
"-s",
help="Sprint scope ('active', 'current', 'backlog', 'all', or sprint ID)",
),
workspace_root: str | None = typer.Option(
None,
"--workspace-root",
"-w",
help="Workspace directory for resolving external target repositories",
),
fleet: bool = typer.Option(
False,
"--fleet",
help="Aggregate canonical executable queue across all fleet repositories",
),
queue: str | None = typer.Option(
None,
"--queue",
"-q",
help="Filter candidates by execution queue name",
),
fmt: str = typer.Option(
"table",
"--format",
"-f",
help="Output format: table, json, or yaml",
),
) -> None:
"""Evaluate and report the canonical planfile.executable-queue/v1 pending queue."""
if fmt.strip().lower() not in {"table", "json", "yaml"}:
console.print(f"[red]Unsupported format: {fmt} (choose table, json, or yaml)[/red]")
raise typer.Exit(2)

from planfile.executable_queue import executable_queue, fleet_executable_queue

if fleet:
root_dir = workspace_root or project
report = fleet_executable_queue(
root_dir,
sprint=sprint,
queue=queue,
)
else:
report = executable_queue(
project,
sprint=sprint,
workspace_root=workspace_root,
queue=queue,
)

if not _emit_structured(report, fmt):
_render_executable_queue_table(report)
Loading
Loading