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_dispatch.pyskills/herdr-foreman/foreman/

"""Map workflow transport to the existing canonical dispatch/assignment owners.

The workflow record retains only current phase/dispatch references and a live
pending intent. Native results live in recovery.dispatches and assignments,
where existing reconciliation, counters, refusal recovery and metrics find
them. No second dispatch log or Markdown assessment ledger is written here.
"""

from copy import deepcopy

from . import model_unavailability, recovery, supervision
from .errors import UsageError
from .state import add_assignment


def reserve(state, task, generation, round_number, job, template, common, at):
    from .workflow_planning import correction_authority
    confirmed = recovery.confirmed_fix(state["assignments"], task)
    expected = round_number - 1 if job["role"] == "developer" and round_number else round_number
    if confirmed != expected:
        raise UsageError("The task's cumulative correction history changed during preparation; preserve its actual counter and obtain a current task-local decision before dispatch.",
                         {"reason": "task_correction_counter_changed", "confirmed_fixes": confirmed})
    plan, work = correction_authority(state, task, round_number, job["role"])
    paths = {"common": common, job["role"]: job["brief"]}
    identifier, fingerprint = recovery.dispatch_identity(task, job["role"], job["agent"], round_number or None,
        paths, supplied=job["id"].rsplit(":", 1)[0], options={"workflow_schema": 2,
            "generation": generation, "report": job["report"], "model": job["tier"]["model"],
            "effort": job["tier"].get("effort")})
    if identifier != job["id"]:
        raise UsageError("Use the workflow's original role-bound dispatch intent; a different identity cannot reserve this job.", {})
    record = {"id": identifier, "fingerprint": supervision.report_bound_fingerprint(fingerprint, job["report"]),
        "role": job["role"], "agent": job["agent"], "task": task, "fix_round": round_number or None,
        "plan": plan, "work": work, "common": common, "brief": job["brief"],
        "brief_identity": recovery.brief_identity(paths, job["role"], job["report"]),
        "provider": template.kind, "worker_kind": template.name,
        "launch_scope": model_unavailability.launch_scope(template)}
    if job["role"] == "reviewer":
        record["reviewer_scope"] = "verification"
    return recovery.reserve(state["recovery"], record, at)


def sending(state, identifier, observation, at):
    """The input boundary calls this before the actual assignment prompt."""
    return recovery.mark_sending(state["recovery"], identifier, at, deepcopy(observation))


def finish(state, identifier, raw):
    """Associate actual native evidence with the task already owning this intent.

    assign.apply's transport-only call does not own legacy task metadata. The
    canonical reservation supplies task/fix/account identity; model, clear,
    process, pane, send and start evidence come unchanged from the transport.
    """
    store = state["recovery"]
    dispatch = next((row for row in store["dispatches"] if row["id"] == identifier), None)
    if dispatch is None or raw.get("role") != dispatch["role"] or raw.get("agent") != dispatch["agent"]:
        raise UsageError("Native result differs from the reserved workflow role/worker; preserve its uncertain effect.", {})
    if dispatch["status"] == "applied":
        prior = dispatch["result"]
        if prior["pane_id"] != raw.get("pane_id") or prior["tier"] != raw.get("tier"):
            raise UsageError("An existing dispatch already carries different native evidence; reconcile it without another send.", {})
        return prior
    result = {**deepcopy(raw), "task": dispatch["task"], "fix_round": dispatch["fix_round"],
              "dispatch_id": identifier, "assignment_scoped": True, "worker_kind": dispatch["worker_kind"],
              "launch_scope": deepcopy(dispatch["launch_scope"])}
    if dispatch["role"] == "reviewer":
        result["reviewer_scope"] = dispatch["reviewer_scope"]
    else:
        result.pop("reviewer_scope", None)
    add_assignment(state, result["at"], result["role"], result["agent"], status=result["status"],
                   task=dispatch["task"], fix_round=dispatch["fix_round"],
                   reviewer_scope=result.get("reviewer_scope"), cleared=result["cleared"],
                   clear_reason=result["clear_reason"], context_session=result.get("context_session"), tier=result["tier"])
    recovery.finish_dispatch(store, identifier, result, len(state["assignments"]) - 1, result["at"])
    return dispatch["result"]


def current_job(state, supervised, identifier):
    """A derived current view; canonical native facts are not copied into progression."""
    dispatch = next((row for row in state["recovery"]["dispatches"] if row["id"] == identifier), None)
    member = next((row for row in supervised["members"] if row["id"] == identifier), None)
    if dispatch is None or member is None or dispatch["status"] != "applied" or dispatch["result"] is None:
        raise UsageError("Restore this workflow job's canonical applied dispatch and enrollment before observation.", {})
    expected = supervision.expected_assignment(member)
    result = dispatch["result"]
    if expected["task"] != dispatch["task"] or expected["agent"] != dispatch["agent"]:
        raise UsageError("The current native enrollment does not belong to its task dispatch; preserve both owners' evidence.", {})
    return {"schema_version": 1, "id": identifier, "role": dispatch["role"], "agent": dispatch["agent"],
        "worker_kind": dispatch["worker_kind"], "tier": deepcopy(result["tier"]),
        "status": "closed" if not member["active"] else "running", "pane_id": expected["pane_id"],
        "native_session": expected["native_session"], "report": expected["report"],
        "brief": dispatch["brief"], "at": result["at"], "transport": deepcopy(result),
        "report_evidence": None, "claim": None}

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