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

context_output.pyskills/herdr-foreman/foreman/

"""Printed-byte budgets for current-context views; never task authority.

Owners supply a pure page builder. Shrinking its page retains its ordering,
totals and continuation instead of truncating a record or hiding obligations.
An indivisible oversized record refuses. Persisted owner schemas are unchanged.
"""

import json

from .errors import UsageError

OUTPUT_BYTES = 16_384
VIEW_SCHEMA_VERSION = 2
DEFAULT_LIMIT = 10
MAX_LIMIT = 50
WARNING_BYTES = 4_096

# Foreman-facing knowledge views. Native Stop/executor owners use their own
# observation APIs; this exposure gate never changes their effect authority.
READ_COMMANDS = frozenset({
    "state", "status", "foreman-queue", "workflow-readiness", "cost-report", "explain-plan",
    "memory-list", "memory-show", "attention-list", "attention-show", "catch-up",
    "supervision-gate", "supervision-status", "supervision-drain", "supervision-watch",
    "retro-check", "retro-list", "retro-show", "capability-check", "capability-show",
    "report-gate-status", "github-context", "foreman-reset-status",
})


def printed_json(value):
    return json.dumps(value, indent=2) + "\n"


def utf8_size(value: str, label: str):
    """Measure semantic context text without exposing malformed input bytes."""
    try:
        return len(value.encode("utf-8"))
    except UnicodeError:
        raise UsageError("Use valid UTF-8 for {} before requesting context. Preserve the original owner and unread evidence while correcting the text.".format(label),
                         {"context_complete": False}) from None


def error_text(error, diagnostics=""):
    """Retain complete JSON errors; never cut an oversized diagnostic in half."""
    result = diagnostics + printed_json(error.to_dict())
    if len(result.encode("utf-8")) <= OUTPUT_BYTES:
        return result
    return printed_json(UsageError(
        "The requested operation failed and its diagnostic exceeds the context budget. Preserve the original owner records, holds and unknown outcomes; narrow the evidence question or repair the source diagnostic before retrying. No omitted evidence is accepted.",
        {"reason": "context_diagnostic_budget_exceeded", "context_complete": False,
         "operation_failed": True}).to_dict())


def validate_page(limit, offset):
    if type(limit) is not int or not 1 <= limit <= MAX_LIMIT or type(offset) is not int or offset < 0:
        raise UsageError("Use --limit 1–{} and a nonnegative --offset; follow next_offset for another page.".format(MAX_LIMIT), {})


def page(rows, offset, limit):
    selected = rows[offset:offset + limit]
    return {"total": len(rows), "offset": offset, "limit": limit, "returned": len(selected),
            "omitted": len(rows) - len(selected),
            "next_offset": offset + len(selected) if offset + len(selected) < len(rows) else None,
            "items": selected}


def section_page(rows, offset, limit, *, selected):
    """Retain counts and a start cursor for a section outside the selected view."""
    result = page(rows, offset if selected else 0, limit if selected else 0)
    result["selected"] = selected
    return result


def validate_sequence(through, after):
    if type(after) is not int or not 0 <= after <= through:
        raise UsageError("Use a nonnegative --after sequence within the selected through snapshot.", {})


def sequence_page(rows, through, after, limit, key):
    """A stable event cursor even when earlier returned events are acknowledged."""
    validate_sequence(through, after)
    later = [row for row in rows if key(row) > after]
    selected = later[:limit]
    return {"through": through, "after": after, "limit": limit, "total": len(rows),
            "earlier_pending": len(rows) - len(later), "returned": len(selected),
            "omitted": len(rows) - len(selected),
            "next_after": (key(selected[-1]) if selected else after) if len(later) > len(selected) else None,
            "items": selected}


def enforce_budget(result, recovery, *, diagnostic_text=""):
    """Check exact stdout bytes without changing an existing document schema."""
    if len((json.dumps(result, indent=2) + "\n" + diagnostic_text).encode("utf-8")) > OUTPUT_BYTES:
        raise UsageError(
            recovery,
            {"reason": "context_budget_exceeded", "budget_bytes": OUTPUT_BYTES, "context_complete": False})
    return result


def bounded(result):
    result["schema_version"] = VIEW_SCHEMA_VERSION
    result["authorizes_progression"] = False
    result["budget"] = {"output_bytes": OUTPUT_BYTES}
    return enforce_budget(result,
                          "Current context exceeds its printed output budget. Keep unexamined obligations unresolved; select a narrower task, --section where available, or evidence question instead of dumping history.")


def fit_pages(builder, limit, offset):
    validate_page(limit, offset)
    for effective in range(limit, 0, -1):
        result = builder(effective)
        try:
            return bounded(result)
        except UsageError:
            if effective == 1:
                raise
    raise AssertionError("A validated page always has a positive limit.")

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