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

attention_view.pyskills/herdr-foreman/foreman/

"""Bounded offline catch-up, with obligations ahead of saved progress."""

import copy

from . import attention, context_output, foreman_reset
from .chronology import timestamp
from .errors import UsageError


def _short(value, limit=600):
    text = " ".join(str(value).split())
    return text if len(text) <= limit else text[:limit - 1] + "…"


def _source_link(source):
    ref = source["ref"]
    label = source["kind"].replace("_", " ")
    if ref.startswith(("https://", "http://", "/")) and not any(char in ref for char in "\n\r"):
        target = ref.replace("<", "%3C").replace(">", "%3E")
        return "[{}](<{}>)".format(label, target)
    return "{}: {}".format(label, _short(ref, 2000))


def _useful_links(sources):
    rank = {"artifact": 0, "task_ledger": 1, "retrospective": 2, "other": 3, "user_message": 4}
    links = []
    for source in sorted(sources, key=lambda row: rank[row["kind"]]):
        ref = source["ref"]
        if ref.startswith(("https://", "http://", "/")) and not any(char in ref for char in "\n\r"):
            link = _source_link(source)
            if link not in links:
                links.append(link)
    return " · ".join(links[:3])


def _pagination(page, label):
    if not page["omitted"]:
        return []
    selector = "--section {} ".format(page["section"])
    next_page = "Continue with {}--offset {}.".format(selector, page["next_offset"]) if page["next_offset"] is not None else "Read earlier pages with {}--offset 0.".format(selector)
    return ["", "**{} {} are outside this page.** {}".format(page["omitted"], label, next_page)]


def _render(result):
    lines = ["# Needs your attention", ""]
    for reset in result["foreman_resets"]:
        lines.extend(["## Foreman reset {} needs you".format(reset["status"]), "",
                      _short(reset["needed"]), "", "Record: {}".format(reset["record"]), ""])
    lines.extend(_pagination(result["foreman_reset_page"], "foreman resets"))
    queue = result["attention"]
    needs_you = bool(queue["total"] or result["foreman_reset_page"]["total"])
    if not needs_you:
        lines.append("Nothing currently needs your attention in the saved queue.")
    for row in queue["items"]:
        lines.extend(["## {}".format(_short(row["title"], 300)), "",
                      _short(row["context"]), "", _short(row["consequence"]), ""])
        if row["options"]:
            lines.extend(["Choices: {}".format("; ".join(_short(value, 200) for value in row["options"])), ""])
        if row["recommendation"]:
            lines.extend(["Recommendation: {}".format(_short(row["recommendation"])), ""])
        lines.extend(["**Needed:** {}".format(_short(row["resolution_condition"])), ""])
        links = _useful_links(row["sources"])
        if links:
            lines.extend([links, ""])
        if row["resurfaced"]:
            lines.extend(["_Back for attention after {}._".format(row["deferred_until"]), ""])
        elif row["last_presented_at"]:
            cue = {"question": "Still awaiting your answer.", "decision": "Still awaiting your decision.",
                   "review": "Still awaiting your review."}.get(row["kind"], "Still open from the earlier update.")
            lines.extend(["_{}_".format(cue), ""])
    lines.extend(_pagination(queue, "actionable obligations"))
    result["attention_markdown"] = "\n".join(lines).rstrip() + "\n" if needs_you else ""
    deferred = result["deferred"]
    if deferred["total"]:
        lines.extend(["", "## Coming back later", ""])
        for row in deferred["items"]:
            lines.append("- {} — {}.".format(_short(row["title"], 300), row["deferred_until"]))
        lines.extend(_pagination(deferred, "deferred items"))
    lines.extend(["", "## Known progress", ""])
    assessments = {"verified": "Verified when recorded", "reported": "Reported; acceptance unverified", "unknown": "Acceptance unknown"}
    for row in result["progress"]["items"]:
        lines.extend(["**{}:** {}".format(_short(row["task"]), _short(row["summary"])), "",
                      "{} · {}".format(assessments[row["assessment"]], row["at"]), ""])
        links = _useful_links(row["sources"])
        if links:
            lines.extend([links, ""])
    if not result["progress"]["total"]:
        lines.append("No saved progress matches this view; completion is unknown.")
    lines.extend(_pagination(result["progress"], "progress records"))
    if result["closed"] is not None and result["closed"]["total"]:
        lines.extend(["", "## Resolved", ""])
        for row in result["closed"]["items"]:
            outcome = row["resolution"]["summary"] if row["resolution"] is not None else "Replaced by a later obligation."
            lines.append("- **{}:** {} ({})".format(_short(row["title"], 300), _short(outcome), row["updated_at"]))
        lines.extend(_pagination(result["closed"], "closed items"))
    return "\n".join(lines).rstrip() + "\n"


def catch_up(path, at, *, task=None, limit=context_output.DEFAULT_LIMIT, offset=0, since=None,
             include_closed=False, compact=False, section=None):
    context_output.validate_page(limit, offset)
    if section not in (None, "attention", "deferred", "progress", "closed", "resets"):
        raise UsageError("Select --section attention, deferred, progress, closed or resets.", {})
    include_closed = include_closed or section is not None
    now = timestamp(at, "Catch-up checkpoint")
    cutoff = timestamp(since, "Catch-up since") if since is not None else None
    document, entries, progress = attention.load(path)
    if document["events"] and timestamp(document["events"][-1]["at"], "Latest attention event") > now:
        raise UsageError("Catch-up checkpoint precedes saved events; use the current UTC checkpoint without rewriting history.", {})
    actionable, deferred, closed = [], [], []
    for value in entries.values():
        if task is not None and value["task"] != task:
            continue
        row = copy.deepcopy(value)
        row["resurfaced"] = row["status"] == "deferred" and timestamp(row["deferred_until"], "Resurface time") <= now
        row["effective_status"] = "open" if row["resurfaced"] else row["status"]
        if row["effective_status"] == "open":
            actionable.append(row)
        elif row["effective_status"] == "deferred":
            deferred.append(row)
        elif cutoff is None or timestamp(row["updated_at"], "Resolution time") >= cutoff:
            closed.append(row)
    actionable.sort(key=lambda row: (-row["priority"], row["created_at"], row["id"]))
    deferred.sort(key=lambda row: (row["deferred_until"], -row["priority"], row["id"]))
    closed.sort(key=lambda row: (row["updated_at"], row["id"]), reverse=True)
    progress = [row for row in progress if (task is None or row["task"] == task)
                and (cutoff is None or timestamp(row["at"], "Progress time") >= cutoff)]
    progress.sort(key=lambda row: (row["at"], row["id"]), reverse=True)
    # Reset obligations remain globally counted even in a task/section-specific view.
    resets = foreman_reset.outstanding(path)

    def build(effective):
        def selected(rows, name):
            page = context_output.section_page(rows, offset, effective, selected=section in (None, name))
            page["section"] = name
            return page

        reset_page = selected(resets, "resets")
        result = {"schema_version": attention.SCHEMA_VERSION, "state_path": str(attention.canonical_state(path)),
                  "attention_path": str(attention.storage_path(path)), "checked_at": attention._utc(at),
                  "task": task, "since": since, "section": section, "attention": selected(actionable, "attention"),
                  "deferred": selected(deferred, "deferred"),
                  "progress": selected(progress, "progress"),
                  "closed": selected(closed, "closed") if include_closed else None,
                  "retrospective_index": str(attention.canonical_state(path)) + ".retrospectives/index.json",
                  "foreman_resets": reset_page.pop("items"), "foreman_reset_page": reset_page,
                  "presentation_included": not compact}
        sections = [result[name] for name in ("attention", "deferred", "progress", "closed")
                    if result[name] is not None]
        result["context_complete"] = reset_page["omitted"] == 0 and all(page["omitted"] == 0 for page in sections)
        if not compact:
            sources = []
            for page in sections:
                for row in page["items"]:
                    for source in row["sources"]:
                        if source not in sources:
                            sources.append(copy.deepcopy(source))
            result["sources"] = sources
            result["markdown"] = _render(result)
        return result

    return context_output.fit_pages(build, 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