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

observer_projection.pyskills/herdr-foreman/foreman/

"""Read-only owner metadata pages for the private observer, never authority.

The owner may read its own complete JSON; the consumer receives only selected
current fields and explicit page coverage. Historical prompts, reports, holds'
evidence and dispatch bodies are never exported. This reader never migrates.
"""

import json
import os
from pathlib import Path
import stat

from . import context_output
from .errors import StateError


MAX_EVENTS = 10_000
SECTIONS = ("binding", "current", "closures")


def _read(path):
    descriptor = os.open(path, os.O_RDONLY | os.O_NOFOLLOW)
    with os.fdopen(descriptor, "rb") as stream:
        if not stat.S_ISREG(os.fstat(stream.fileno()).st_mode):
            raise ValueError("owner evidence must be regular JSON")
        return json.load(stream)


def view(path, section="current", *, offset=0, limit=50):
    """Project supported owner schemas, with bounded printed pages."""
    context_output.validate_page(limit, offset)
    if section not in SECTIONS:
        raise ValueError("select binding, current or closures")
    supervised = _read(str(path) + ".supervision.json")
    if not isinstance(supervised, dict) or supervised.get("schema_version") != 1:
        raise StateError("Restore supported supervision owner evidence before observing this factory; no migration was attempted.", {})
    rows, gaps = [], []
    if section == "binding":
        rows = [{"kind": "binding", "value": supervised.get("binding")}]
    else:
        data = _read(Path(path))
        if (not isinstance(data, dict) or data.get("schema_version") != 11
                or type(data.get("recovery", {}).get("schema_version")) is not int
                or data["recovery"]["schema_version"] not in (19, 20)):
            raise StateError("Restore the supported state/recovery owner before observing this factory; no migration was attempted.", {})
        if section == "current":
            active = [row for row in supervised.get("members", []) if row.get("active")]
            profiles = {row.get("agent"): row for row in data.get("assignments", [])}
            rows = [{"kind": "binding", "value": supervised.get("binding")},
                    {"kind": "context", "value": {"holds": sum(row.get("resumed_at") is None for row in supervised.get("holds", [])),
                                                   "active_assignments": len(active)}}]
            for member in active:
                assignment = member.get("assignment", {})
                refinements = member.get("refinements", [])
                current = refinements[-1] if refinements else assignment
                profile = profiles.get(assignment.get("agent"), {})
                rows.append({"kind": "assignment", "value": {
                    "agent": assignment.get("agent"), "task": assignment.get("task"),
                    "role": profile.get("role", "worker"), "at": profile.get("at") or member.get("at"),
                    "pane_id": current.get("pane_id"), "native_session": current.get("native_session")}})
            snapshots = data.get("snapshots", [])
            snapshot = snapshots[-1] if snapshots else {}
            if snapshot.get("schema_version") in (5, 6):
                for name, row in snapshot.get("agents", {}).items():
                    windows = {key: {field: value.get(field) for field in ("used_pct", "remaining_pct", "resets")}
                               for key, value in row.get("windows", {}).items() if isinstance(value, dict)}
                    rows.append({"kind": "quota", "value": {"profile": name, "measured_at": snapshot.get("measured_at"),
                        "kind": row.get("kind"), "window_group": row.get("window_group"), "windows": windows,
                        "headroom_pct": row.get("headroom_pct"), "skipped": row.get("skipped")}})
            else:
                gaps.append("quota_snapshot_missing_or_unsupported")
        else:
            events = data["recovery"].get("events", [])
            if len(events) > MAX_EVENTS:
                gaps.append("closure_history_truncated")
            for event in reversed(events[-MAX_EVENTS:]):
                if event.get("kind") == "task_closed":
                    rows.append({"kind": "closure", "value": {
                        **{key: event.get(key) for key in ("task", "at", "sequence")},
                        "outcome": (event.get("details") or {}).get("outcome")}})

    def page(effective):
        selected = context_output.page(rows, offset, effective)
        return {"kind": "observer_projection", "section": section, "rows": selected.pop("items"),
                "pagination": selected, "gaps": gaps, "authorizes_dispatch": False,
                "context_complete": selected["omitted"] == 0}
    return context_output.fit_pages(page, limit, offset)

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