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

measurement_retry.pyskills/herdr-foreman/foreman/

"""Retry failed/missing measurements using only the latest existing snapshot.

No cache store or background refresh. Reused readings retain the oldest
observation time; they never acquire the retry's timestamp or effect authority.
"""

import hashlib
import json
import os
import socket
from dataclasses import asdict
from datetime import timedelta

from .chronology import timestamp
from .command_context import HerdrCommandContext
from .errors import UsageError
from .tier_routing import CAPACITY_MAX_AGE


def context_digest(agents, client):
    context = getattr(client, "context", None)
    if not isinstance(context, HerdrCommandContext):
        return None  # An unbound test/custom transport cannot prove reuse.
    facts = {"profiles": [{**agent.as_dict(), "window_group": agent.window_group} for agent in agents],
             "transport": asdict(context), "host": socket.gethostname(), "herdr_env": os.environ.get("HERDR_ENV")}
    return hashlib.sha256(json.dumps(facts, sort_keys=True, separators=(",", ":")).encode()).hexdigest()


def split(agents, previous, digest, at):
    """Keep a successful shared window only when all its profiles still fit."""
    if not digest or not isinstance(previous, dict) or previous.get("measurement_context_sha256") != digest:
        return agents, {}
    try:
        age = timestamp(at, "Measurement retry") - timestamp(previous.get("measured_at"), "Previous measurement")
    except UsageError:
        return agents, {}
    if not timedelta(0) <= age < CAPACITY_MAX_AGE:
        return agents, {}
    records = previous.get("agents", {})
    if not isinstance(records, dict):
        return agents, {}
    groups = {}
    for agent in agents:
        groups.setdefault(("shared", agent.window_group) if agent.window_group else ("worker", agent.name), []).append(agent)
    attempted, reused = [], {}
    for members in groups.values():
        usable = all(isinstance(records.get(agent.name), dict)
                     and "error" not in records[agent.name] and not records[agent.name].get("skipped")
                     and isinstance(records[agent.name].get("headroom_pct"), (int, float))
                     and not isinstance(records[agent.name]["headroom_pct"], bool)
                     and 0 <= records[agent.name]["headroom_pct"] <= 100
                     and records[agent.name].get("kind") == agent.kind
                     and records[agent.name].get("window_group") == agent.window_group
                     for agent in members)
        if usable:
            reused.update({agent.name: records[agent.name] for agent in members})
        else:
            attempted.extend(members)
    return attempted, reused


def combine(snapshot, reused, previous, digest):
    snapshot["measurement_context_sha256"] = digest
    snapshot["reused_agents"] = sorted(reused)
    if reused:
        snapshot["agents"] = {**reused, **snapshot["agents"]}
        # Existing readers use the global time. Keeping the older time makes
        # every freshness check conservative without another per-profile clock.
        snapshot["measured_at"] = previous["measured_at"]
    return snapshot

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