This is called in the main pipeline at line 130-131:
python
# 6. Finalize
if not items:
items += _empty_queue_fallback(plan)
The injection logic:
python
def _empty_queue_fallback(plan: dict | None) -> list[WorkQueueItem]:
"""Return a 'run scan' nudge when an active plan cycle has cleared."""
if not plan:
return []
plan_scores = plan.get("plan_start_scores", {})
if plan_scores.get("strict") is None:
return []
return [{
"id": "workflow::run-scan",
"kind": "workflow_action",
"summary": "Queue cleared — run scan to finalize and reveal your updated score.",
"primary_command": "desloppify scan",
"file": "",
"detector": "workflow",
"confidence": "high",
}]
Conditions for injection:
Items list is empty (after all filtering and sorting)
Plan exists
Plan has plan_start_scores["strict"] set (i.e., an active plan cycle)
4. Where the Emptiness Check Happens
In cmd_plan_queue() (queue_render.py, lines 175-263):
Line 229-231: checks if not items: after building queue and collapsing clusters
Prints "Queue is empty." message
In cmd_next() (next/cmd.py, lines 112-335):
Line 307-313: calls _show_empty_queue() helper which shows the frozen score and plan-start context
This happens after full queue is built and items are truncated to count
In scan preflight (scan/preflight.py, lines 23-89):
Line 68-76: uses plan_aware_queue_breakdown() to count remaining items
Line 75: checks if mode is not ScoreDisplayMode.FROZEN: return (i.e., if queue is clear of objective work, allow scan)
Otherwise gates with CommandError
5. How Cluster Focus is Resolved and Applied
In cmd_next() (lines 130-141):
python
def _resolve_cluster_focus(
plan_data: dict | None,
*,
cluster_arg: str | None,
scope: str | None,
) -> str | None:
effective_cluster = cluster_arg
if plan_data and not cluster_arg and not scope:
active_cluster = plan_data.get("active_cluster")
if active_cluster:
effective_cluster = active_cluster
return effective_cluster
Resolution order:
If --cluster arg provided, use it
Else if plan exists AND no --cluster AND no --scope:
Use plan's active_cluster if set
Else None
Then passed to build_work_queue() (lines 245-258):
Replaces cluster member items with single meta-items for compact display only (not filtering).
Only collapses clusters with 2+ members (line 226-233)
Manual (triage) clusters inserted at front in plan order
Auto-clusters collapse in-place where first member is found
Individual member items are removed
This is called in display contexts:
cmd_plan_queue() line 209: collapse for plan queue display
_show_empty_queue() line 118 in queue_progress.py: for breakdown counting
cmd_next() line 262-263: collapse unless cluster focus is active
9. Key Control Parameters Summary
Parameter
Function
Location
Effect
QueueBuildOptions.scan_path
Narrows scope to paths under this root
core.py:159-163
Passed to build_issue_items()
QueueBuildOptions.scope
Pattern filtering on item ID, path, detector, dimension
core.py:113, 198
Applied in _gather_subjective_items()
QueueBuildOptions.cluster
Focus to cluster members
core.py:256
Applied in filter_cluster_focus()
QueueBuildOptions.plan
Living plan for reordering, skipping, clustering
core.py:106
Threaded through presort/postsort
plan["active_cluster"]
User's current focus cluster
plan_order.py:108
Used if no explicit --cluster arg
plan["queue_order"]
Prioritized issue list
plan_order.py:66-72
Drives sort via _plan_position
plan["skipped"]
Issues to hide by default
plan_order.py:81-99, 119-133
Removed, optionally re-appended
plan["plan_start_scores"]["strict"]
Frozen score from cycle start
core.py:332
Triggers workflow::run-scan injection
This architecture ensures filtering (cluster/scope) is decoupled from reordering (plan order), and the workflow::run-scan injection only occurs when an active plan cycle completes all objective work.
Perfect! Now I have a comprehensive picture. Let me create a detailed summary report:
I've thoroughly explored all the places that interact with queue emptiness and the workflow::run-scan injection mechanism. Here's the complete landscape: