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

policy_paths.pyskills/herdr-foreman/foreman/

"""Locate the single coding-policy release bundle used by Herdr helpers.

Tessl keeps a package tree intact. ACR realizes each skill as a complete,
namespaced directory. Resolve the release skill as a unit; never assemble
its helpers from different installations or execute code during discovery.
"""

import argparse
import json
import os
import sys
from pathlib import Path

from .errors import ForemanError, UsageError


NATIVE_FOREMAN = "acr__jbaruch__herdr-policy__herdr-foreman"
NATIVE_RELEASE = "acr__jbaruch__coding-policy__release"
RELEASE_FILES = (
    "SKILL.md",
    "origin-repo.py",
    "lib/bounded-run.sh",
    "lib/prune-worktrees.sh",
    "lib/prune-remote-branches.sh",
    "lib/prune_result.py",
)
WORKFLOW_RELEASE_FILES = ("review-lanes.sh", "poll-pr-reviews.sh", "watch-pr-reviews.sh")


def require_workflow_release(release):
    """Require the independent-review ABI for a schema-2 task workflow."""
    missing = [name for name in WORKFLOW_RELEASE_FILES if not (release / name).is_file()]
    if missing:
        raise UsageError("Install coding-policy 0.5.0 or later in the selected release bundle before admitting or resuming this task workflow; preserve existing owners and holds.",
                         {"release_skill": str(release), "missing": missing})
    return release


def refuse_combined_policy(skill_dir, shared, global_tessl):
    """An unregistered source helper is distinct from installed legacy hooks."""
    roots = {shared / ".tessl/plugins/jbaruch/coding-policy",
             global_tessl / "plugins/jbaruch/coding-policy"}
    package = skill_dir.parent.parent
    if (package.name == "herdr-policy" and package.parent.name == "jbaruch"
            and package.parent.parent.name == "plugins" and package.parent.parent.parent.name == ".tessl"):
        roots.add(package.parent / "coding-policy")
    conflicts = []
    for root in sorted(roots):
        for name in ("herdr-foreman", "herdr-standup"):
            try:
                (root / "skills" / name).lstat()
            except FileNotFoundError:
                continue
            except OSError:
                raise UsageError("Cannot verify installed policy ownership — restore access to local/global plugin trees before Herdr work") from None
            conflicts.append(str(root))
            break
    if conflicts:
        raise UsageError(
            "A combined coding-policy team runtime is still installed — keep teams stopped, reconcile active work, "
            "then upgrade to reduced coding-policy before using herdr-policy; preserve owner records and unknown deliveries",
            {"legacy_packages": conflicts},
        )


def coding_release(skill_dir, shared, global_tessl, explicit_root=None):
    """Return one complete release skill, preferring the executing installation.

    An explicit package root is exclusive. Otherwise use the same ACR native
    skill host, the peer Tessl package, project-local Tessl, then global Tessl.
    An existing but incomplete selection is an installation error, not a
    license to silently combine it with another version.
    """
    skill_dir = Path(skill_dir).resolve()
    shared = Path(shared).resolve()
    global_tessl = Path(global_tessl).resolve()
    refuse_combined_policy(skill_dir, shared, global_tessl)
    if explicit_root is not None:
        candidates = [Path(explicit_root).resolve() / "skills/release"]
    else:
        candidates = []
        if skill_dir.name == NATIVE_FOREMAN:
            candidates.append(skill_dir.parent / NATIVE_RELEASE)
        else:
            package = skill_dir.parent.parent
            candidates.append(package.parent / "coding-policy/skills/release")
        candidates.extend((
            shared / ".tessl/plugins/jbaruch/coding-policy/skills/release",
            global_tessl / "plugins/jbaruch/coding-policy/skills/release",
        ))

    visited = set()
    for candidate in candidates:
        candidate = candidate.resolve()
        if candidate in visited:
            continue
        visited.add(candidate)
        if not candidate.exists():
            continue
        missing = [name for name in RELEASE_FILES if not (candidate / name).is_file()]
        if missing:
            raise UsageError(
                "coding-policy release helpers are incomplete at {} — install the "
                "compatible coding-policy package before running Herdr cleanup".format(candidate),
                {"release_skill": str(candidate), "missing": missing},
            )
        return candidate
    raise UsageError(
        "coding-policy release helpers were not found — install the compatible "
        "coding-policy package alongside herdr-policy, or pass its package root",
        {"searched": [str(path) for path in candidates]},
    )


def brief_inputs(skill_dir, shared, global_tessl, explicit_root=None, *, workflow=False):
    """Resolve the scoped worker contract and the selected general policy."""
    skill_dir, shared = Path(skill_dir).resolve(), Path(shared).resolve()
    release = coding_release(skill_dir, shared, global_tessl, explicit_root)
    if workflow:
        require_workflow_release(release)
    indexes = [shared / ".tessl/RULES.md", Path(global_tessl) / "RULES.md"]
    if release.name == NATIVE_RELEASE:
        # Native adapters may host rules in CLAUDE.md, an imported instruction
        # file, or scoped Cursor rules. A pre-existing AGENTS.md proves none of
        # those. Use the selected general package's authored native router.
        indexes = [release / "POLICY.md"]
    policy = next((path.resolve() for path in indexes if path.is_file() and path.stat().st_size), None)
    team = skill_dir / "references/worker-context.md"
    if policy is None or not team.is_file() or not team.stat().st_size:
        raise UsageError("Policy inputs are missing — repair the selected coding-policy and herdr-policy "
                         "installations before composing briefs", {"indexes": [str(p) for p in indexes],
                                                                   "team_operation": str(team)})
    return {"POLICY_INDEX": str(policy), "RELEASE_SKILL": str(release / "SKILL.md"),
            "TEAM_OPERATION": str(team)}


def main(argv=None):
    """Read paths or current installation identity; never execute team work."""
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("operation", choices=("release", "brief-inputs", "identity"))
    parser.add_argument("--shared", type=Path, default=Path.cwd())
    parser.add_argument("--global-tessl", type=Path, default=Path.home() / ".tessl")
    parser.add_argument("--coding-policy-root", type=Path,
                        default=os.environ.get("HERDR_CODING_POLICY_ROOT") or None)
    args = parser.parse_args(argv)
    if not args.coding_policy_root:
        args.coding_policy_root = None
    skill = Path(__file__).resolve().parents[1]
    try:
        if not args.shared.is_absolute() or not args.shared.is_dir() or not args.global_tessl.is_absolute():
            raise UsageError("Pass an existing absolute shared checkout and an absolute global Tessl root")
        if args.coding_policy_root is not None and not Path(args.coding_policy_root).is_absolute():
            raise UsageError("HERDR_CODING_POLICY_ROOT must be an absolute package root")
        if args.operation == "identity":
            from .native_policy import executing_policy_root
            from .remote_owner import loaded_policy
            root = executing_policy_root()
            version, digest = loaded_policy(root)
            result = {"schema_version": 1, "policy_root": str(root), "version": version, "digest": digest,
                      "authorizes_dispatch": False}
        elif args.operation == "release":
            result = {"release_skill": str(coding_release(skill, args.shared, args.global_tessl,
                                                         args.coding_policy_root))}
        else:
            result = brief_inputs(skill, args.shared, args.global_tessl, args.coding_policy_root)
    except (OSError, ForemanError) as exc:
        print("policy-paths: {} — repair the selected installation before retrying".format(exc), file=sys.stderr)
        if isinstance(exc, ForemanError) and exc.details:
            print(json.dumps(exc.details), file=sys.stderr)
        return 2
    print(json.dumps(result))
    return 0

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