CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

jbaruch/herdr-policy

Herdr team coordination policy for AI coding agents

Quality

93%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files

workflow_planning.pyskills/herdr-foreman/foreman/

"""Select fresh workflow workers through the existing budget/tier planner.

The schema-2 owner supplies the real task, counter and canonical history.
Legacy correction-plan metadata is not fabricated to satisfy another loop.
No native worker is contacted and no source or owner record is written here.
"""

from . import capabilities, composition, lifecycle, planner, selection, recovery
from . import cli
from .chronology import timestamp
from .errors import PlanError, UsageError
from .state import latest_snapshot, role_counts


MEASUREMENT_MAX_AGE = 900


def quota(state, worker_kind, at):
    """Observed roster headroom, never a guarantee that a provider will accept input."""
    snapshot = latest_snapshot(state)
    if snapshot is None:
        return None
    age = (timestamp(at, "Quota checkpoint") - timestamp(snapshot["measured_at"], "Roster measurement")).total_seconds()
    if not 0 <= age <= MEASUREMENT_MAX_AGE:
        return None
    remaining = cli._snapshot_headroom(snapshot)
    value = remaining.get(worker_kind)
    groups = planner._window_groups(snapshot.get("agents", {}))
    group = groups.get(worker_kind)
    if group is not None:
        shared = [reading for name, reading in remaining.items() if groups.get(name) == group and reading is not None]
        if shared:
            value = min(shared)
    return value


def require_headroom(state, worker_kind, at):
    """Preserve a known exhausted account at preparation and native launch."""
    remaining = quota(state, worker_kind, at)
    if remaining is not None and remaining <= 0:
        raise UsageError("This workflow worker has no measured headroom; preserve its current account evidence before launching it.",
                         {"reason": "quota_exhausted", "worker_kind": worker_kind})


def correction_authority(state, task, round_number, role):
    """Use the actual cumulative allowance and its existing bounded work owner."""
    store = state["recovery"]
    progress = store["tasks"][task].get("progression", {})
    plan = None
    work = None
    if round_number and round_number > recovery.ceiling_at(store, task, round_number):
        plans = [row for row in recovery.active_plans(store) if row["task"] == task
                 and row["first_fix"] <= round_number <= row["last_fix"]]
        if len(plans) != 1:
            raise UsageError("Restore the unique existing correction authorization for this cumulative attempt.", {})
        plan = plans[0]["id"]
        from . import report_contract, workflow_workspace
        findings = []
        for expected in progress.get("blockers", []):
            receipt, body = workflow_workspace.capture(expected["path"])
            if receipt != expected:
                raise UsageError("Restore the exact blocking report before spending its approved correction allowance.", {})
            claim = report_contract.workflow_claim(body.decode("utf-8"))
            findings.extend(item["id"] for item in claim["findings"] if item["severity"] == "blocking" and item["status"] != "resolved")
        # Verifiers and release preserve the actual implementation plan/work
        # already recorded on the current developer dispatch.
        if role != "developer":
            source = next((row for row in store["dispatches"] if row["id"] == progress.get("jobs", {}).get("developer")), None)
            if source is None:
                raise UsageError("Restore the current developer's actual correction-work authorization before verification.", {})
            plan, work = source["plan"], source["work"]
        else:
            head = progress.get("head")
            work = {"base_revision": store["tasks"][task]["base_revision"], "scope": plans[0]["scope"],
                    "paths": head["paths"] if head is not None else [], "findings": sorted(set(findings))}
    recovery.validate_work(store, state["assignments"], task, round_number or None, plan, work,
                           implementation=role == "developer")
    return plan, work


def plan(state, state_path, document, progress, roles, agents, at):
    snapshot = latest_snapshot(state)
    if snapshot is None:
        raise UsageError("Measure the admitted worker roster before selecting workflow assignments.", {})
    if not agents or any(not agent.assignment_scoped or not agent.tiers for agent in agents):
        raise UsageError("Configure fresh assignment-scoped workers with verified tier tables before admitting background work.", {})
    constraints = composition.selection_constraints(roles, agents, {}, state["assignments"], document["task"],
        dispatches=state["recovery"]["dispatches"], assessments=state["specialist_assessments"],
        candidate_names=snapshot.get("agents", {}).keys())
    holds = cli._seat_holds(roles, document["task"], state, state_path)
    # This planner selects configured worker kinds, not existing native aliases.
    # Assignment/session independence is still checked by the native job owner.
    roster = {agent.name for agent in agents}
    excluded = {role: sorted((set(constraints["exclude"].get(role, [])) | set(holds["exclude"].get(role, []))) & roster)
                for role in roles}
    exhausted = {agent.name for agent in agents if (remaining := quota(state, agent.name, at)) is not None and remaining <= 0}
    for role in roles:
        eligible = roster - set(excluded[role])
        if eligible and eligible <= exhausted:
            raise PlanError("The eligible workflow workers have no measured headroom; preserve their current account evidence before selecting another assignment.",
                            {"reason": "quota_exhausted", "responsibility": role})
        excluded[role] = sorted(set(excluded[role]) | exhausted)
    table = capabilities.load(state_path)
    refusals = []
    rounds = {}
    candidates = cli._candidate_tiers(roles, agents, rounds, progress["round"] or None,
        excludes=excluded, headroom=cli._snapshot_headroom(snapshot), table=table,
        refusals=refusals, reusable_agents=True, measured_at=snapshot.get("measured_at"),
        at=at, capacity_groups=cli._snapshot_groups(snapshot), unavailable_store=state["recovery"])
    result = cli._build_plan_with_refusals(planner.plan, refusals, roles, snapshot,
        role_counts(state, cli._worker_kind_provenance(state)), exclude=excluded,
        operator_exclude={},
        role_costs=cli.load_role_costs(document["config"]["path"]),
        snapshot_ref={"source": str(state_path), "measured_at": snapshot.get("measured_at")},
        tier_candidates=candidates, rounds=rounds, familiarity=constraints["familiarity"],
        selection_rationale=constraints["rationale"] + holds["rationale"],
        roster=[agent.name for agent in agents], reusable_agents=True)
    result["selection"] = selection.records(result["assignments"], result.get("tiers"),
        {agent.name: agent for agent in agents}, {}, rounds, progress["round"] or None, table)
    result.update(schema_version=planner.ASSIGNMENT_PLAN_SCHEMA_VERSION,
                  worker_kinds=dict(result["assignments"]))
    result["assignments"] = lifecycle.identities(result["assignments"])
    return result

skills

herdr-foreman

foreman

__init__.py

__main__.py

antigravity_native.py

assign.py

attention_view.py

attention.py

billing.py

bootstrap_recovery.py

brief_inputs.py

capabilities.py

chronology.py

churn.py

claude_native.py

cli.py

codex_goals.py

command_context.py

composer.py

composition.py

config.py

context_evidence.py

context_output.py

coordination_metrics.py

cost_report.py

delivery_collection.py

diagnostics.py

engagement.py

errors.py

foreman_queue.py

foreman_reset.py

github_context.py

herdr.py

historical.py

home.py

host_goals.py

launch.py

lifecycle.py

load_set.py

measure.py

measurement_capture.py

measurement_retry.py

members.py

memory.py

model_unavailability.py

native_permissions.py

native_policy.py

no_work_recovery.py

observer_projection.py

observer_role.py

oracle.py

parsers.py

partition.py

plan_explanation.py

planner.py

policy_paths.py

probe_recovery.py

probe.py

process_lease.py

progression_owner.py

progression_runtime.py

progression_service.py

provision.py

recovery.py

release_activation.py

release_checkout.py

release_flight.py

release_rebind.py

remote_owner.py

remote_service.py

renderable.py

report_contract.py

report_delivery.py

report_gates.py

reset_input_hook.py

restoration.py

retrospective_runtime.py

retrospective.py

role_clear.py

role_context.py

runnable.py

selection.py

session_start_hook.py

state.py

successors.py

supervision_gate.py

supervision_hook.py

supervision_runtime.py

supervision.py

task_evidence.py

tier_routing.py

tiers.py

triggers.py

workflow_adoption.py

workflow_artifacts.py

workflow_batch.py

workflow_capacity.py

workflow_contract.py

workflow_dispatch.py

workflow_native.py

workflow_planning.py

workflow_profiles.py

workflow_readiness.py

workflow_recovery.py

workflow_release.py

workflow_rename.py

workflow_review.py

workflow_service.py

workflow_upgrade.py

workflow_workspace.py

antigravity.example.json

bootstrap-repository.py

compose-briefs.sh

config.example.json

foreman-tier-check.py

foreman.sh

label-workspaces.sh

measurements.py

native-hook.sh

observer-view.py

policy-paths.py

prepare-briefs.py

provision-worktree.sh

prune-report-caches.py

resolve-gates.sh

resolve-policy-paths.sh

review-package.sh

roster.sh

round-preflight.sh

SKILL.md

start-judge-worker.sh

state-schema.md

sweep-worktrees.sh

verify-authority.sh

wait-report.sh

workflow-review.py

README.md

tile.json