Skip to content

API Reference parrot.flows.dev_loop.webhook

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.flows.dev_loop.webhook

View source

GitHub pull_request.closed webhook for worktree cleanup.

Implements Module 11 of the dev-loop spec. Worktree cleanup is external to the flow itself (spec G8). Two paths trigger it:

  1. A human running /sdd-done manually after a merge.
  2. This module: a webhook listener registered on the existing :class:parrot.autonomous.AutonomousOrchestrator.WebhookListener via orchestrator.register_webhook(...). The listener handles HMAC validation — this module only adds the GitHub-specific transform and cleanup helper.

Class RevisionWebhookHandler

React to github.pr_comment / github.pr_review events.

Filters reviewer feedback by DEV_LOOP_REVISION_TRIGGER, drops bot-authored comments, dedups by head_sha (mirroring GitHubReviewer), builds a :class:RevisionBrief, and calls DevLoopRunner.run_revision(...). A single handler instance keeps the seen-head_sha set so a chatty PR cannot spawn a revision storm (R3).

Parameter Type Default Description
runner Any A DevLoopRunner constructed with the revision deps.
trigger Optional[str] None Override for conf.DEV_LOOP_REVISION_TRIGGER — "changes_requested" (default), "any_comment" or "command" (/revise prefix).
bot_login Optional[str] None GitHub login of the flow-bot; comments authored by it are ignored. When None, no author is treated as a bot.
repo_base_path Optional[str] None Base dir under which the existing clone lives; the revision reuses <repo_base_path>/<branch>. Defaults to conf.WORKTREE_BASE_PATH.

Method RevisionWebhookHandler.handle_event

Maybe trigger a revision run. Returns the FlowResult or None.

None is returned (no run) when the comment is bot-authored, fails the trigger filter, is a duplicate head_sha delivery, or lacks the fields needed to build a :class:RevisionBrief.

handle_event(event_type: str, payload: Dict[str, Any]) -> Optional[Any]

Parameter Type Default Description
event_type str
payload Dict[str, Any]

Returns: Optional[Any]

Function cleanup_worktree

Run git worktree remove then git worktree prune.

Best-effort: a missing worktree (already cleaned) is not an error. All subprocess failures are logged and swallowed.

cleanup_worktree(branch: str) -> None

Parameter Type Default Description
branch str

Function register_pull_request_webhook

Register the GitHub pull_request.closed webhook handler.

register_pull_request_webhook(orchestrator: Any, *, secret: str, path: str = '/github/dev-loop', target_id: str = 'dev-loop-cleanup') -> None

Parameter Type Default Description
orchestrator Any A :class:parrot.autonomous.AutonomousOrchestrator.
secret str HMAC secret configured on the GitHub webhook.
path str '/github/dev-loop' HTTP path for the listener (default /github/dev-loop).
target_id str 'dev-loop-cleanup' Logical target id used by the orchestrator's WebhookListener to dispatch to the cleanup helper.

Function sweep_finished_worktrees

Remove dev-loop worktrees whose PR is merged/closed. Best effort.

The webhook-less fallback for worktree cleanup. Lists every live dev-loop worktree and decides per branch:

  • PR merged or closed → remove the worktree.
  • PR open → keep (a reviewer revision may still reuse it).
  • No PR (orphan) → kept by default; removed only when remove_orphans=True (e.g. a run that failed before opening a PR).

sweep_finished_worktrees(*, pr_state_fn: Optional[Callable[[str], Awaitable[Optional[str]]]] = None, remove_orphans: bool = False, dry_run: bool = False, cwd: Optional[str] = None) -> Dict[str, Any]

Parameter Type Default Description
pr_state_fn Optional[Callable[[str], Awaitable[Optional[str]]]] None Async branch -> state resolver returning one of "merged"/"closed"/"open"/None. Defaults to the gh CLI (:func:_gh_pr_state). Injectable for tests.
remove_orphans bool False Also remove worktrees with no PR.
dry_run bool False Report what would be removed without touching anything.
cwd Optional[str] None Working directory for the git/gh subprocesses (defaults to the current process dir; pass the repo root when calling out-of-tree).

Returns: Dict[str, Any] — A report dict {"removed": [...], "kept": [{"branch", "reason"}], "errors": [...], "dry_run": bool}.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally