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

"""Bind a release worker's reading to all current review and inline bodies.

This digest is an identity, never proof that a person or worker read anything
and never a readiness predicate. The independently delivered release claim
attests the reading; the canonical watcher still supplies merge readiness.
"""

import hashlib
import json
import re

from .errors import UsageError


REVIEW_STATES = frozenset({"APPROVED", "CHANGES_REQUESTED", "COMMENTED", "DISMISSED", "PENDING"})


def premerge_evidence(snapshot):
    """Validate a stored canonical watch receipt, never resolve live readiness.

    Only the watcher supplies `ready`. These checks reject incomplete receipts
    or fields contradicting that result; the file receipt binds every byte.
    """
    binding = identity(snapshot)
    error = UsageError("Restore the complete unchanged pre-merge watch-pr-reviews.sh output, including its actual CI, current reviewer, merge and watcher receipt fields; a self-labelled ready object is not release evidence.", {})
    ci, reviews = snapshot.get("ci"), snapshot.get("reviews")
    merge, watch = snapshot.get("merge_state"), snapshot.get("watch")
    counts = snapshot.get("inline_comments")
    if (not isinstance(ci, dict) or ci.get("status") not in ("success", "none")
            or not isinstance(ci.get("checks"), list)
            or not isinstance(reviews, dict) or not {"codex", "claude"}.issubset(reviews)
            or not isinstance(merge, dict) or not isinstance(merge.get("status"), str)
            or not merge["status"] or merge["status"] == "DIRTY" or merge.get("mergeable") != "MERGEABLE"
            or not isinstance(watch, dict) or watch.get("result") != "ready"
            or type(watch.get("attempts")) is not int or watch["attempts"] < 1
            or type(watch.get("elapsed_seconds")) is not int or watch["elapsed_seconds"] < 0
            or not isinstance(counts, dict)
            or any(type(counts.get(bot)) is not int or counts[bot] < 0 for bot in ("codex", "copilot"))):
        raise error
    for check in ci["checks"]:
        if (not isinstance(check, dict) or not isinstance(check.get("name"), str) or not check["name"]
                or not isinstance(check.get("bucket"), str) or not check["bucket"]):
            raise error
    fields = {"state", "submitted_at", "body", "commit_id", "stale", "requested"}
    for bot, states in (("codex", {"APPROVED", "COMMENTED", "RULED"}),
                        ("claude", {"APPROVED", "COMMENTED"})):
        row = reviews[bot]
        if (not isinstance(row, dict) or not fields.issubset(row)
                or not isinstance(row["state"], str) or row["state"] not in states
                or row["stale"] is not False or row["requested"] is not False
                or row["commit_id"] != binding["head_sha"]
                or not isinstance(row["submitted_at"], str) or not row["submitted_at"]
                or row["body"] is not None and not isinstance(row["body"], str)):
            raise error
    for field, required in (("review_bodies", {"submitted_at", "commit_id", "html_url"}),
                            ("inline_comment_bodies", {"in_reply_to_id", "path", "line", "html_url"})):
        if any(not required.issubset(row) for row in snapshot[field]):
            raise error
    return binding


def identity(snapshot):
    if (not isinstance(snapshot, dict) or type(snapshot.get("pr_number")) is not int
            or snapshot["pr_number"] < 1 or not isinstance(snapshot.get("head_sha"), str)
            or re.fullmatch(r"[a-f0-9]{40}(?:[a-f0-9]{24})?", snapshot["head_sha"]) is None
            or not isinstance(snapshot.get("review_bodies"), list)
            or not isinstance(snapshot.get("inline_comment_bodies"), list)):
        raise UsageError("Capture the canonical complete PR review snapshot before binding the release reading.", {})
    bodies = {}
    for field in ("review_bodies", "inline_comment_bodies"):
        rows, seen = [], set()
        for row in snapshot[field]:
            if (not isinstance(row, dict) or type(row.get("id")) is not int
                    or row["id"] < 1 or not isinstance(row.get("body"), str) or row["id"] in seen
                    or not isinstance(row.get("author"), str) or not row["author"].strip()
                    or len(row["author"].encode("utf-8")) > 256
                    or any(ord(char) < 32 for char in row["author"])
                    or field == "review_bodies" and (not isinstance(row.get("state"), str) or row["state"] not in REVIEW_STATES)):
                raise UsageError("Retain each complete review/inline body with its unique ID and author, plus canonical state for review rows; missing or unsupported evidence cannot bind a release reading.", {})
            seen.add(row["id"])
            rows.append(row)
        bodies[field] = sorted(rows, key=lambda row: row["id"])
    value = {"schema_version": 1, "pr_number": snapshot["pr_number"], "head_sha": snapshot["head_sha"], **bodies}
    raw = json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
    if len(raw) > 2_097_152:
        raise UsageError("The current review exceeds the bounded workflow input; retain its source and request a task-local reading decision.", {})
    return {"schema_version": 1, "pr_number": value["pr_number"], "head_sha": value["head_sha"],
            "sha256": hashlib.sha256(raw).hexdigest(),
            "reviews": len(bodies["review_bodies"]), "inline_comments": len(bodies["inline_comment_bodies"])}

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