Skip to content

JordanGunn/nunchuck / skills/task/task-select

task-select

Verified

Select a task by writing its ID to `.tasks/.active`. Prints the selected task path and any suspicion flags (stale, hash mismatch) to encourage skepticism.

scripts/include/task_hash.py

View on GitHub
"""Deterministic hashing for task canonical intent."""

import hashlib
import re


CANONICAL_SECTIONS = ["Goal", "Acceptance", "Constraints", "Dependencies"]
EXCLUDED_SECTIONS = ["Evidence"]


def normalize_content(content: str) -> str:
    """
    Normalize markdown content for hashing.
    
    - Normalize line endings to \n
    - Trim trailing whitespace from each line
    - Collapse multiple blank lines to single blank line
    """
    lines = content.replace("\r\n", "\n").replace("\r", "\n").split("\n")
    lines = [line.rstrip() for line in lines]
    
    normalized = []
    prev_blank = False
    for line in lines:
        is_blank = line == ""
        if is_blank and prev_blank:
            continue
        normalized.append(line)
        prev_blank = is_blank
    
    return "\n".join(normalized).strip()


def extract_section(content: str, heading: str) -> str:
    """Extract content under a specific H2 heading."""
    pattern = rf"^## {re.escape(heading)}\s*\n(.*?)(?=^## |\Z)"
    match = re.search(pattern, content, re.MULTILINE | re.DOTALL)
    if match:
        return match.group(1).strip()
    return ""


def extract_canonical_intent(content: str) -> str:
    """
    Extract canonical intent sections from task markdown.
    
    Includes: Goal, Acceptance, Constraints, Dependencies
    Excludes: Evidence
    """
    sections = []
    for heading in CANONICAL_SECTIONS:
        section_content = extract_section(content, heading)
        if section_content:
            sections.append(f"## {heading}\n\n{section_content}")
    
    return "\n\n".join(sections)


def compute_intent_hash(content: str) -> str:
    """
    Compute SHA256 hash of canonical intent sections.
    
    Returns lowercase hex string.
    """
    intent = extract_canonical_intent(content)
    normalized = normalize_content(intent)
    return hashlib.sha256(normalized.encode("utf-8")).hexdigest()


def verify_intent_hash(content: str, stored_hash: str | None) -> tuple[bool, str]:
    """
    Verify stored hash matches computed hash.
    
    Returns (matches, computed_hash).
    """
    computed = compute_intent_hash(content)
    if stored_hash is None:
        return False, computed
    return stored_hash == computed, computed
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 197kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall