Skip to content

mvschwarz/openrig / packages/daemon/assets/plugins/openrig-core/skills/refocusing

refocusing

Verified

Use when a long-running agent may have lost the product outcome, when context was compacted, when work has crossed a major boundary, or when a fresh path-based trace is needed before the next consequential action. Not for fresh-session orientation, waking an idle seat, or checkpoints.

FileKindSize
SKILL.mdskill md3.8 KB
references/refocus.mdmarkdown1.1 KB
scripts/trace-to-root.pyexecutablescript30.0 KB

scripts/trace-to-root.py

View on GitHub
#!/usr/bin/env python3
"""Render topology and work context by ascending directory paths only."""

import argparse
import datetime
import json
import os
import re
import subprocess
import sys
from pathlib import Path

SHELVES = {"rigs", "pods", "seats", "missions", "slices"}
# The daemon's exact current-work refusal meaning "this seat holds no in-progress typed baton"
# (daemon domain/current-work.js, NO_TYPED_IN_PROGRESS). Only this exact text earns the work-root
# fallback. Compare by equality, not prefix: the sibling refusal "no typed in-progress work
# resolved to a work node" is a resolution failure and must stay a named gap. If the daemon's
# wording changes, equality fails toward a named gap that shows the new text, never a silent fallback.
NO_CURRENT_BATON_BASIS = (
    "no typed in-progress work (only in-progress rows are considered; a typed row that is "
    "pending or blocked is not current work)"
)
# The daemon's session-name character set and human-class refs (domain/session-name.ts:
# validateSessionName, isHumanSeatSessionRef).
SESSION_CHARS = re.compile(r"[A-Za-z0-9\-_.@]+")
HUMAN_CLASS_SESSION = re.compile(r"human(?:-[A-Za-z0-9._-]+)?@(?:kernel|host)|[A-Za-z0-9._:-]+@external")


def rig_output(*args):
    try:
        result = subprocess.run(
            ["rig", *args], capture_output=True, text=True, timeout=10, check=False
        )
    except (OSError, subprocess.SubprocessError):
        return None
    value = (result.stdout or "").strip()
    return value if result.returncode == 0 and value else None


def configured_root(key, env_key):
    value = os.environ.get(env_key) or rig_output("config", "get", key)
    return Path(value).expanduser().resolve() if value else None


def extra_work_roots(cli_roots):
    """Roots beyond workspace.root that the work trace may ascend to: a catalogued project
    can live outside workspace.root (#2693). Refocus-only, unlike OPENRIG_WORKSPACE_ROOT,
    which the CLI config store also reads as workspace.root."""
    values = list(cli_roots or [])
    values += [part for part in (os.environ.get("OPENRIG_REFOCUS_WORK_ROOT") or "").split(os.pathsep) if part]
    return [Path(value).expanduser().resolve() for value in values]


def work_root_for(start, root, extra_roots):
    """The deepest known root that contains start; workspace.root when none does, so a node
    outside every known root still reports the same gap."""
    if start is None or not extra_roots:
        return root
    start = Path(start).expanduser().resolve()
    containing = [candidate for candidate in (root, *extra_roots) if under_root(start, candidate)]
    return max(containing, key=lambda candidate: len(candidate.parts)) if containing else root


def under_root(path, root):
    try:
        path.relative_to(root)
        return True
    except ValueError:
        return False


def ascent(start, root):
    start = start.expanduser().resolve()
    if not under_root(start, root):
        return None, f"start is outside configured root: {start}"
    nodes = []
    current = start
    while True:
        if current.name not in SHELVES:
            nodes.append(current)
        if current == root:
            break
        parent = current.parent
        if parent == current:
            return None, f"could not reach configured root: {root}"
        current = parent
    return list(reversed(nodes)), None


def read(path):
    try:
        return path.read_text(encoding="utf8", errors="replace")
    except OSError:
        return None


# Contract twin of CLI scope-fs.ts and daemon scope/node-file.ts; parity is tested.
NOTES_FILE_PRECEDENCE = ("NOTES.md", "MISSION_NOTES.md")


def resolve_notes(node):
    for name in NOTES_FILE_PRECEDENCE:
        candidate = node / name
        try:
            if candidate.is_file() and os.access(candidate, os.R_OK):
                return (candidate, name), None
        except OSError:
            pass
    return None, None


def intent(text):
    if not text or not text.startswith("---"):
        return None
    match = re.match(r"^---\s*\n(.*?)\n---(?:\s*\n|$)", text, re.S)
    if not match:
        return None
    lines = match.group(1).splitlines()
    for index, line in enumerate(lines):
        found = re.match(r"^intent:\s*(.*)$", line)
        if not found:
            continue
        value = found.group(1).strip()
        if value in {"|", ">", "|-", ">-", "|+", ">+"}:
            block = []
            for later in lines[index + 1:]:
                if later and not later[0].isspace():
                    break
                block.append(later.strip())
            return " ".join(part for part in block if part)
        if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"'}:
            if value[0] == '"':
                try:
                    return json.loads(value)
                except json.JSONDecodeError:
                    pass
            return value[1:-1]
        return value or None
    return None


def light_learned(text):
    if not text:
        return ""
    body = re.sub(r"^---\s*\n.*?\n---\s*\n", "", text, count=1, flags=re.S).strip()
    if len(body) <= 800:
        return body
    boundary = body.rfind("\n", 0, 800)
    return body[:boundary if boundary > 0 else 800].rstrip() + "\n[… use --depth full for the rest]"


# OPR.0.7.0.12 — the refocus packet (--packet). Duties and notes are carried as text by
# conventional section, with an honest "not found" and a bounded excerpt otherwise; nobody is
# asked to add headings. Old files are named with their measured age as a cue, not a verdict.
DUTY_HEADINGS = ("my job here", "standing duties")
NOTES_STATE_HEADINGS = ("current state",)
HEADING = re.compile(r"^(#{1,6})\s+(.*?)\s*#*\s*$")
DEFAULT_NOTES_MAX_AGE_DAYS = 14
# Each packet field is bounded on its own; there is no total cap. A row's summary and continuation are one line each,
# the held and next lists show their newest rows with the full count, and a matched section's body is cut at a line.
FIELD_CHARS = 160
HELD_SHOWN = 20
NEXT_SHOWN = 10
SECTION_CHARS = 1500


def one_line(text):
    """(text as one line, cut to FIELD_CHARS, whether it was shortened)."""
    flat = " ".join(str(text).split())
    if len(flat) <= FIELD_CHARS:
        return flat, flat != str(text).strip()
    return flat[:FIELD_CHARS - 1].rstrip() + "…", True


def bounded_section(body):
    if len(body) <= SECTION_CHARS:
        return body
    boundary = body.rfind("\n", 0, SECTION_CHARS)
    return body[:boundary if boundary > 0 else SECTION_CHARS].rstrip() + "\n[… use --depth full for the rest]"


def heading_sections(text, wanted):
    """[(title, body)] for each Markdown heading whose title starts with a wanted phrase."""
    lines = re.sub(r"^---\s*\n.*?\n---\s*\n", "", text or "", count=1, flags=re.S).splitlines()
    found = []
    for index, line in enumerate(lines):
        match = HEADING.match(line)
        if not match or not match.group(2).strip().lower().startswith(wanted):
            continue
        level = len(match.group(1))
        body = []
        for later in lines[index + 1:]:
            heading = HEADING.match(later)
            if heading and len(heading.group(1)) <= level:
                break
            body.append(later)
        found.append((match.group(2).strip(), "\n".join(body).strip()))
    return found


def by_section(text, wanted, path):
    found = heading_sections(text, wanted)
    shown = "\n\n".join(f"{title}\n{bounded_section(body)}" if body else title for title, body in found)
    missing = [phrase for phrase in wanted if not any(title.lower().startswith(phrase) for title, _ in found)]
    if not missing:
        return shown
    if not found:
        names = " or ".join(f'"{phrase.upper()}"' for phrase in wanted)
        return f"SECTION NOT FOUND — no {names} heading in {path}; bounded excerpt follows\n{light_learned(text)}"
    # Some sections matched: name each one that did not, with the same bounded excerpt, so text
    # kept under another heading is not silently dropped.
    names = ", ".join(f'"{phrase.upper()}"' for phrase in missing)
    return f"{shown}\n\nSECTION NOT FOUND — no {names} heading in {path}; bounded excerpt follows\n{light_learned(text)}"


def notes_max_age_days():
    try:
        value = float(os.environ.get("OPENRIG_REFOCUS_NOTES_MAX_AGE_DAYS", DEFAULT_NOTES_MAX_AGE_DAYS))
    except ValueError:
        return DEFAULT_NOTES_MAX_AGE_DAYS
    return value if value > 0 else DEFAULT_NOTES_MAX_AGE_DAYS


def age_cue(path, text):
    """An OLD NOTES line when the file is past the threshold, measured from `updated:` or mtime."""
    threshold = notes_max_age_days()
    updated, source = None, "mtime"
    match = re.match(r"^---\s*\n(.*?)\n---", text or "", re.S)
    if match:
        found = re.search(r"^updated:\s*[\"']?(\d{4}-\d{2}-\d{2})", match.group(1), re.M)
        if found:
            try:
                updated = datetime.datetime.strptime(found.group(1), "%Y-%m-%d").replace(tzinfo=datetime.timezone.utc)
                source = "updated"
            except ValueError:
                updated = None
    if updated is None:
        try:
            updated = datetime.datetime.fromtimestamp(path.stat().st_mtime, datetime.timezone.utc)
        except OSError:
            return None
    age = (datetime.datetime.now(datetime.timezone.utc) - updated).total_seconds() / 86400
    if age <= threshold:
        return None
    return f"OLD NOTES — {path}, {age:.0f} days old, source {source}, threshold {threshold:g} days"


def render_topology(start, root, depth, failures, packet=False):
    output = ["## TOPOLOGY TRACE", f"root: {root}", f"start: {start}"]
    nodes, error = ascent(start, root)
    if error:
        failures.append(error)
        return "\n".join(output + [f"TRACE GAP — {error}"])
    for node in nodes:
        chain_file = node / "LEARNED.md"
        text = read(chain_file)
        label = node.relative_to(root) or Path(".")
        if text is None:
            output.append(f"\n### {label}\nMISSING LINK — {chain_file}")
            continue
        if depth == "full":
            body = text.strip()
        elif packet and node == nodes[-1]:
            # The seat's own file: its job and standing duties as text.
            body = by_section(text, DUTY_HEADINGS, chain_file)
        else:
            body = light_learned(text)
        output.append(f"\n### {label} · LEARNED.md\n{body}")
        cue = age_cue(chain_file, text) if packet else None
        if cue:
            output.append(cue)
    return "\n".join(output)


def render_work(start, root, depth, failures, fallback=None, packet=False):
    output = ["## WORK TRACE", f"root: {root}", f"start: {start}"]
    if fallback:
        output.append(f"FALLBACK — {fallback}")
    nodes, error = ascent(start, root)
    if error:
        failures.append(error)
        return "\n".join(output + [f"TRACE GAP — {error}"])
    for node in nodes:
        label = node.relative_to(root) or Path(".")
        spec = next((candidate for candidate in (node / "SPEC.md", node / "README.md") if candidate.is_file()), None)
        if spec is None:
            output.append(f"\n### {label}\nMISSING LINK — no SPEC.md or README.md at {node}")
        else:
            text = read(spec) or ""
            if depth == "full":
                body = text.strip()
            else:
                value = intent(text)
                body = f"intent: {value}" if value else "MISSING INTENT — no readable intent: field"
            output.append(f"\n### {label} · {spec.name}\n{body}")

        notes, resolution_error = resolve_notes(node)
        if resolution_error:
            failures.append(resolution_error)
            output.append(f"NOTES RESOLUTION GAP — {resolution_error} at {node}")
        elif notes:
            notes_path, notes_name = notes
            if depth == "full":
                notes_text = read(notes_path)
                if notes_text is None:
                    failures.append(f"unreadable notes: {notes_path}")
                    output.append(f"NOTES RESOLUTION GAP — resolved {notes_name} became unreadable at {notes_path}")
                else:
                    output.append(f"\nNOTES · {notes_name}\n{notes_text.strip()}")
                    cue = age_cue(notes_path, notes_text) if packet else None
                    if cue:
                        output.append(cue)
            elif packet:
                notes_text = read(notes_path)
                if notes_text is None:
                    failures.append(f"unreadable notes: {notes_path}")
                    output.append(f"NOTES RESOLUTION GAP — resolved {notes_name} became unreadable at {notes_path}")
                else:
                    output.append(f"\nNOTES · {notes_name}\n{by_section(notes_text, NOTES_STATE_HEADINGS, notes_path)}")
                    cue = age_cue(notes_path, notes_text)
                    if cue:
                        output.append(cue)
            else:
                try:
                    size = notes_path.stat().st_size
                except OSError:
                    failures.append(f"unreadable notes: {notes_path}")
                    output.append(f"NOTES RESOLUTION GAP — resolved {notes_name} became unreadable at {notes_path}")
                else:
                    output.append(f"NOTES · {notes_name} · {size} bytes · {notes_path}")
        else:
            output.append(f"NOTES GAP — no readable mission notes at {node}")

        # The SDLC convention keeps a node's current delivery state in PROGRESS.md; carry it
        # as text when present. Its absence is not a gap: many nodes have no PROGRESS.md.
        progress_path = node / "PROGRESS.md"
        progress_text = read(progress_path) if packet else None
        if progress_text is not None:
            progress_body = progress_text.strip() if depth == "full" else by_section(progress_text, NOTES_STATE_HEADINGS, progress_path)
            output.append(f"\nPROGRESS · PROGRESS.md\n{progress_body}")
            cue = age_cue(progress_path, progress_text)
            if cue:
                output.append(cue)
    return "\n".join(output)


def candidate_line(candidate):
    name = candidate.get("mission") or "?"
    if candidate.get("slice"):
        name += f" / {candidate['slice']}"
    intent_text = candidate.get("intent") or "no readable intent"
    line = f"- {name} — {intent_text} — source: {candidate.get('source') or 'unknown'}"
    if candidate.get("unresolved"):
        line += f" — UNRESOLVED ON THIS HOST: {candidate['unresolved']}"
    return line


def row_fields(row, *fields):
    """Each named field as one bounded line, and a pointer to the whole row when any was shortened."""
    values, cut = [], False
    for field, missing in fields:
        value, shortened = one_line(row.get(field) or missing)
        values.append(value)
        cut = cut or shortened
    pointer = f" — full row: rig queue show {row['qitemId']}" if cut and row.get("qitemId") else ""
    return values, pointer


def cut_notice(name, state, rows, shown, daemon_cut):
    """The list's notice when it was cut here or by the daemon: how many are shown, of how many."""
    if not daemon_cut and len(rows) <= shown:
        return None
    total = f"more than {len(rows)}" if daemon_cut else str(len(rows))
    return (f"(the {name} list was cut: {min(len(rows), shown)} of {total} shown; "
            f"`rig queue list --owned --state {state}` has the rest)")


def render_held_and_next(evidence):
    output = []
    per_list = "heldTruncated" in evidence or "nextTruncated" in evidence
    held = evidence.get("held") or []
    if held:
        output.append("HELD WORK (blocked; this is not next):")
        for row in held[:HELD_SHOWN]:
            (summary, blocked_on, continuation), pointer = row_fields(
                row, ("summary", "no summary"), ("blockedOn", "unknown"), ("continuation", "none recorded"))
            output.append(f"- {row.get('qitemId') or 'a row'} — {summary} — blocked on {blocked_on} — "
                          f"continuation: {continuation}{pointer}")
    following = evidence.get("next") or []
    if following:
        output.append("POSSIBLE NEXT WORK (pending; no order implied):")
        for row in following[:NEXT_SHOWN]:
            missions = ", ".join(row.get("missions") or [])
            (summary,), pointer = row_fields(row, ("summary", "no summary"))
            output.append(f"- {row.get('qitemId') or 'a row'} — {summary}"
                          + (f" [mission: {missions}]" if missions else "") + pointer)
    notices = [
        cut_notice("held", "blocked", held, HELD_SHOWN, per_list and bool(evidence.get("heldTruncated"))),
        cut_notice("next", "pending", following, NEXT_SHOWN, per_list and bool(evidence.get("nextTruncated"))),
    ]
    output.extend(notice for notice in notices if notice)
    if not per_list and evidence.get("heldAndNextTruncated"):
        output.append("(held and next lists were cut; `rig queue list` has the rest)")
    return "\n".join(output)


def render_candidates(evidence, root, depth, failures, extra_roots=(), project=None, project_unknown=None):
    """The work section from labelled queue evidence. One direct, resolved tag is shown as the
    work with its source; anything less certain lists every candidate and asks the agent."""
    candidates = evidence.get("candidates") or []
    unknown = evidence.get("unknown") or []
    if (len(candidates) == 1 and not unknown and candidates[0].get("kind") == "tag"
            and candidates[0].get("workNodePath") and not candidates[0].get("unresolved")):
        only = candidates[0]
        notes = [f"WORK FROM QUEUE EVIDENCE — {only.get('source')}. If this is stale, say what you are actually doing."]
        if not only.get("slice"):
            notes.append("no slice named")
        start = Path(only["workNodePath"])
        traced = render_work(start, work_root_for(start, root, extra_roots), depth, failures, packet=True)
        head, _, rest = traced.partition("\n")
        return "\n".join([head, *notes, rest])

    missions_root = evidence.get("missionsRoot") or str(root / "missions")
    output = ["## WORK — name it"]
    if not candidates and not unknown:
        output.append("No in-progress queue row names your work. If you are working from messages, "
                      "name the mission they belong to; if you have no current work, say so.")
    elif len(candidates) > 1:
        output.append(f"{len(candidates)} candidates are in flight. Say which mission you are actually working on.")
    else:
        output.append("The queue evidence does not settle your work. Confirm a candidate or name your mission.")
    if candidates:
        output.append("Candidates (evidence, not a verdict; none is adopted for you):")
        output.extend(candidate_line(candidate) for candidate in candidates)
    if unknown:
        output.append("In-progress rows the queue cannot place:")
        for row in unknown:
            (summary,), pointer = row_fields(row, ("summary", "no summary"))
            output.append(f"- {row.get('qitemId') or 'a row'} — {summary}: {row.get('reason')}{pointer}")
    if not candidates:
        names = evidence.get("missionsOnHost") or []
        if names:
            listing = ", ".join(names) + (", …" if evidence.get("missionsOnHostTruncated") else "")
            output.append(f"Missions on this host: {listing}")
    output.append("Then read that mission's current intent as text:")
    output.append(f"  python3 {Path(__file__).resolve()} --trees work --packet --work-start {missions_root}/<mission>")
    # Nothing in progress: orient from the seat's selected project, which may live outside
    # workspace.root (#3320), or say why none was selected. Held and next work stay evidence only.
    orient_root = root
    if not candidates and not unknown and project:
        orient_root = Path(project).expanduser().resolve()
    elif not candidates and not unknown and project_unknown:
        output.append(f"PROJECT UNSELECTED — {project_unknown}; showing the work root instead")
    orientation = render_work(orient_root, orient_root, "light", failures, packet=True)
    _, _, rest = orientation.partition("\n")
    heading = ("the selected project's chain, not your work" if orient_root is not root
               else "the project-level chain, not your work")
    output.append(f"\n## ORIENTATION — {heading}\n" + rest.lstrip("\n"))
    return "\n".join(output)


def read_candidates(source):
    try:
        raw = sys.stdin.read() if source == "-" else Path(source).read_text(encoding="utf8")
        evidence = json.loads(raw)
    except (OSError, json.JSONDecodeError) as error:
        return None, f"work candidates unreadable: {error}"
    if not isinstance(evidence, dict) or not isinstance(evidence.get("candidates", []), list):
        return None, "work candidates have an invalid shape"
    return evidence, None


def canonical_seat(session):
    """(member, rig) for a canonical session name, else None so the caller asks `rig whoami`.

    Mirrors the daemon's parse contract (domain/session-name.ts, parseSessionName): the member is
    everything before the FIRST "@" and the rig is everything after it, which may itself contain
    "@". Human-class refs are not seats, and a name outside the session character set
    (validateSessionName) is uncertain, so both keep the lookup."""
    if not session or not SESSION_CHARS.fullmatch(session) or HUMAN_CLASS_SESSION.fullmatch(session):
        return None
    member, at, rig = session.partition("@")
    return (member, rig) if at and member and rig else None


def derive_topology_start(root):
    explicit = os.environ.get("OPENRIG_REFOCUS_TOPOLOGY_NODE")
    if explicit:
        return Path(explicit)
    # A stale session name (one left over from a seat swap) can name a seat that has no folder;
    # only an existing seat directory is trusted, otherwise `rig whoami` decides.
    seat = canonical_seat(os.environ.get("OPENRIG_SESSION_NAME"))
    if seat:
        member, rig = seat
        candidate = root / "rigs" / rig / "seats" / member
        if candidate.is_dir():
            return candidate
    raw = rig_output("whoami", "--json")
    if not raw:
        return None
    try:
        identity = json.loads(raw).get("identity", {})
    except json.JSONDecodeError:
        return None
    rig = identity.get("rigName")
    session = identity.get("sessionName")
    if not rig or not session:
        return None
    seat = str(session).split("@", 1)[0]
    return root / "rigs" / str(rig) / "seats" / seat


def derive_work_start(root):
    explicit = os.environ.get("OPENRIG_REFOCUS_WORK_NODE")
    if explicit:
        return Path(explicit)
    current = Path.cwd().resolve()
    if not under_root(current, root):
        return None
    while under_root(current, root):
        if (current / "SPEC.md").is_file() or (current / "README.md").is_file():
            return current
        if current == root:
            break
        current = current.parent
    return None


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--trees", choices=("topology", "work", "both"), default=os.environ.get("OPENRIG_REFOCUS_TREES", "both"))
    parser.add_argument("--depth", choices=("light", "full"), default=os.environ.get("OPENRIG_REFOCUS_DEPTH", "light"))
    parser.add_argument("--topology-start")
    parser.add_argument("--work-start")
    parser.add_argument("--work-root", action="append", default=[], help="an extra root the work trace may ascend to, for a catalogued project outside workspace.root; repeatable (also OPENRIG_REFOCUS_WORK_ROOT, separated by the OS path separator)")
    parser.add_argument("--work-project", help="the root of the project selected for this seat (as work-install selects it); the broad orientation when there is no current typed baton")
    parser.add_argument("--work-project-unknown", help="why no single project was selected for this seat")
    parser.add_argument("--work-basis", help="the daemon's reason no current work node was named")
    parser.add_argument("--work-unknown", help="why the current work node could not be read")
    parser.add_argument("--unresolved-work-advisory", action="store_true", help="show unresolved typed work as an advisory with broad orientation")
    parser.add_argument("--work-unknown-timed-out", action="store_true", help="the --work-unknown lookup timed out (a slow daemon); with --unresolved-work-advisory it is an advisory, not a failure")
    parser.add_argument("--check", action="store_true", help="exit nonzero on trace or notes resolution failure; rendered text is unchanged")
    parser.add_argument("--packet", action="store_true", help="carry duties and notes as text by section, with old-notes cues")
    parser.add_argument("--work-candidates", help="labelled work evidence as JSON (a path, or - for stdin), from `rig queue whoami --work-candidates`")
    args = parser.parse_args()

    sections = []
    failures = []

    def gap(text):
        failures.append(text)
        return text
    if args.trees in {"topology", "both"}:
        root = configured_root("topology.root", "OPENRIG_TOPOLOGY_ROOT")
        if root is None:
            sections.append(gap("## TOPOLOGY TRACE\nTRACE GAP — topology.root is unresolved"))
        else:
            start = Path(args.topology_start) if args.topology_start else derive_topology_start(root)
            sections.append(render_topology(start, root, args.depth, failures, packet=args.packet) if start else
                            gap("## TOPOLOGY TRACE\nTRACE GAP — current topology node is unresolved; pass --topology-start with a literal absolute path (or configure OPENRIG_REFOCUS_TOPOLOGY_NODE separately)"))

    if args.trees in {"work", "both"}:
        root = configured_root("workspace.root", "OPENRIG_WORKSPACE_ROOT")
        if root is None:
            sections.append(gap("## WORK TRACE\nTRACE GAP — workspace.root is unresolved"))
        else:
            # Precedence: an explicit start wins; then the hook's daemon answer (basis or unknown);
            # only a standalone run with neither falls back to inferring from the working directory.
            extra_roots = extra_work_roots(args.work_root)
            explicit = args.work_start or os.environ.get("OPENRIG_REFOCUS_WORK_NODE")
            evidence = None
            if args.work_candidates:
                evidence, error = read_candidates(args.work_candidates)
                if error:
                    sections.append(gap(f"## WORK TRACE\nTRACE GAP — {error}"))
            if explicit:
                sections.append(render_work(Path(explicit), work_root_for(explicit, root, extra_roots), args.depth, failures, packet=args.packet))
            elif evidence is not None:
                sections.append(render_candidates(evidence, root, args.depth, failures, extra_roots,
                                                  project=args.work_project, project_unknown=args.work_project_unknown))
            elif args.work_candidates:
                pass  # the unreadable-evidence gap above is the answer; never fall back to the root
            elif args.work_basis == NO_CURRENT_BATON_BASIS and args.work_project:
                # The seat's selected project, which may live outside workspace.root (#3320).
                project = Path(args.work_project).expanduser().resolve()
                sections.append(render_work(project, project, args.depth, failures, packet=args.packet, fallback=(
                    f"no current typed baton ({args.work_basis}). Showing the selected project's chain from its root: "
                    "a broad orientation, not evidence of a current mission")))
            elif args.work_basis == NO_CURRENT_BATON_BASIS:
                unselected = (f"\nPROJECT UNSELECTED — {args.work_project_unknown}; showing the work root instead"
                              if args.work_project_unknown else "")
                sections.append(render_work(root, root, args.depth, failures, packet=args.packet, fallback=(
                    f"no current typed baton ({args.work_basis}). Showing the project-level chain from the work root: "
                    "a broad orientation, not evidence of a current mission" + unselected)))
            elif args.unresolved_work_advisory and args.work_basis and args.work_basis.startswith("typed work did not resolve: "):
                sections.append(f"## WORK TRACE\nTRACE GAP — no single current work node: {args.work_basis}")
                sections.append(render_work(root, root, args.depth, failures, packet=args.packet, fallback=(
                    "typed work could not be resolved. Showing the project-level chain from the work root: "
                    "a broad orientation, not evidence of a current mission")))
            elif args.work_basis:
                sections.append(gap(f"## WORK TRACE\nTRACE GAP — no single current work node: {args.work_basis}"))
            elif args.unresolved_work_advisory and args.work_unknown and args.work_unknown_timed_out:
                # A lookup that timed out says nothing about this seat's work: name it, orient broadly, and don't fail --check.
                sections.append(f"## WORK TRACE\nTRACE GAP — current work node UNKNOWN: {args.work_unknown}")
                sections.append(render_work(root, root, args.depth, failures, packet=args.packet, fallback=(
                    "the work lookup timed out, which says nothing about this seat's work. Showing the project-level chain "
                    "from the work root: a broad orientation, not evidence of a current mission")))
            elif args.work_unknown:
                sections.append(gap(f"## WORK TRACE\nTRACE GAP — current work node UNKNOWN: {args.work_unknown}"))
            else:
                start = derive_work_start(root)
                sections.append(render_work(start, root, args.depth, failures, packet=args.packet) if start else
                                gap("## WORK TRACE\nTRACE GAP — current work node is unresolved; pass --work-start with a literal absolute path (or configure OPENRIG_REFOCUS_WORK_NODE separately)"))
            held_and_next = render_held_and_next(evidence) if evidence else ""
            if held_and_next:
                sections.append(held_and_next)

    print("\n\n".join(sections))
    return 1 if args.check and failures else 0


if __name__ == "__main__":
    raise SystemExit(main())
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 463kUpdated Claude CodeCodexVerifiedInstall
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 463kUpdated Claude CodeCodexVerifiedInstall
discernment-nudgeanthropics/skillsAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.Stars: 195kUpdated Claude CodeCodexVerifiedInstall
internal-commsanthropics/skillsA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).Stars: 195kUpdated Claude CodeCodexVerifiedInstall