Claude Skill

todo-archive

Archive checked `.ai/TODO.md` tasks into `.ai/todos/YYYY-MM/DD.md`, leaving unchecked tasks.

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Virus-scanned Reviewed automatically before listing.

Full trust report

Download paulrberg-agent-skills-skills_todo-archive-913232a.zip · 5 KB
Part of paulrberg/agent-skills — 42 skills

Install

skills CLI npx skills add https://github.com/PaulRBerg/agent-skills/tree/main/skills/todo-archive
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install paulrberg-agent-skills@llmmart
Git git clone https://github.com/PaulRBerg/agent-skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole paulrberg/agent-skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

TODO Archive

If these instructions are already present in the conversation from a slash or dollar invocation, follow them directly; do not invoke this skill again through a skill tool.

Arguments

  • path (optional): Repository root or any path inside the repository. Default to the current directory.
  • --hint TEXT (optional): Archive only the section whose heading contains TEXT (case-insensitive substring), including its subsections. Without it, archive checked tasks from the whole file. Checked tasks outside the matched section stay in .ai/TODO.md.
  • --date YYYY-MM-DD|YYYY_MM_DD (optional): Archive date. Default to today's local date.
  • --dry-run (optional): Preview target paths and rendered content without writing.

Workflow

  1. Resolve the supplied path, or the current directory when omitted. For an existing file, use its containing directory; for a directory, use that directory. Store the absolute directory as start_dir, then resolve its Git root:

    git -C "$start_dir" rev-parse --show-toplevel
    

    Store the result as repo_root. When start_dir is outside a Git repository, use it as repo_root. Stop on a missing input path or another resolution error.

  2. Verify .ai/TODO.md exists under the root. If it is missing, stop and report the path checked.

  3. Resolve the skill directory and run its helper:

    uv run python "<skill-dir>/scripts/archive_todo.py" --root "$repo_root"
    

    Pass through --hint, --date, or --dry-run when the user requested them.

  4. Report the rewritten .ai/TODO.md, the created or merged archive path, the matched section (when --hint was given), and the archived/remaining task counts. If an archive for the date already exists, the helper appends the new batch to it, retaining one matching top-level heading. If the helper reports no checked tasks, treat it as a no-op. If --hint matches no heading, the helper exits non-zero and lists the available sections; relay them.

  5. If useful, inspect only <repo_root>/.ai/TODO.md and the exact archive path returned by the helper. Verify their contents directly; when Git ignores them, compare filesystem snapshots rather than relying on git diff.

Helper Behavior

scripts/archive_todo.py reads only <root>/.ai/TODO.md, writes archived tasks to <root>/.ai/todos/YYYY-MM/DD.md, and rewrites <root>/.ai/TODO.md with the remaining tasks. It preserves task-free sections and prose verbatim (a minimal stub with the source's first heading, or # TODO, only if everything was archived). With --hint, it restricts archiving to the matched heading's subtree and exits non-zero listing available headings when nothing matches. A same-day re-run appends its batch to that day's file, removing the new leading H1 only when it exactly matches the existing archive's leading H1.

Completion

Completion evidence is the helper's archive path plus archived and remaining task counts; a no-checked-task result is a successful no-op. Dry-run completion requires rendered paths/content with no filesystem changes, but the final message still follows the one-line formats below. Report the result as a single line (append a (scope: "<hint>") segment only when --hint was given), with the archive path relative to the repository root:

  • Success: 📦 Archived <n> → <archive path> (created|merged) · <remaining> remaining
  • No-op: ✅ Nothing to archive · <remaining> remaining
  • Dry run: 🔎 Would archive <n> → <archive path> (would create|would merge) · <remaining> would remain

Do not repeat full dry-run document content in the final message or add decoration to TODO/archive files, paths, commands, or helper diagnostics.

Files (agent-skills)
  • agents
    • openai.yaml 43 B
      policy:
        allow_implicit_invocation: false
      
  • scripts
    • archive_todo.py 12 KB
      #!/usr/bin/env python3
      from __future__ import annotations
      
      import argparse
      import datetime as dt
      import pathlib
      import re
      import subprocess
      import sys
      from dataclasses import dataclass, field
      from typing import Iterable, Optional
      
      
      TASK_RE = re.compile(r"^(\s*)([-*+])\s+\[([ xX])\]\s+(.*?)(\r?\n)?$")
      HEADING_RE = re.compile(r"^(#{1,6})\s+\S.*$")
      BLANK_RE = re.compile(r"^\s*$")
      
      
      @dataclass
      class Node:
          kind: str
          line: str = ""
          level: int = 0
          indent: int = -1
          checked: Optional[bool] = None
          archive: Optional[bool] = None
          marker: str = "-"
          text: str = ""
          children: list["Node"] = field(default_factory=list)
      
      
      def main() -> int:
          parser = argparse.ArgumentParser(
              description="Archive checked Markdown tasks from .ai/TODO.md into .ai/todos/."
          )
          parser.add_argument("--root", default=None, help="repository root; defaults to git root or cwd")
          parser.add_argument("--date", default=None, help="YYYY-MM-DD or YYYY_MM_DD; defaults to today")
          parser.add_argument("--dry-run", action="store_true", help="print rendered outputs without writing")
          parser.add_argument(
              "--hint",
              default=None,
              help="archive only the section whose heading contains this text (case-insensitive)",
          )
          args = parser.parse_args()
      
          root = resolve_root(args.root)
          todo_path = root / ".ai" / "TODO.md"
          if not todo_path.exists():
              print(f"TODO.md not found: {todo_path}", file=sys.stderr)
              return 1
      
          archive_date = normalize_date(args.date)
          archive_path = root / ".ai" / "todos" / archive_date[:7] / f"{archive_date[-2:]}.md"
      
          source = todo_path.read_text(encoding="utf-8")
          tree = parse_document(source.splitlines(keepends=True))
      
          matched = collect_matching_headings(tree, args.hint)
          if args.hint is not None and not matched:
              print(f"No heading matched hint {args.hint!r} in {todo_path}", file=sys.stderr)
              headings = [heading_text(node) for node in iter_headings(tree)]
              if headings:
                  print("Available sections:", file=sys.stderr)
                  for heading in headings:
                      print(f"  - {heading}", file=sys.stderr)
              return 1
      
          mark_tasks(tree, args.hint, in_section=args.hint is None)
          archive_count = count_tasks(tree, True)
          remaining_count = count_tasks(tree, False)
      
          if archive_count == 0:
              scope = f" in section matching {args.hint!r}" if args.hint else ""
              print(f"No checked tasks found{scope} in {todo_path}; no archive written.")
              print(f"Tasks remaining: {remaining_count}")
              return 0
      
          new_archive_text = finalize(render(tree, True), fallback_heading="# TODO\n")
          existing_archive_text = archive_path.read_text(encoding="utf-8") if archive_path.exists() else None
          archive_text = (
              merge_archive_text(existing_archive_text, new_archive_text)
              if existing_archive_text is not None
              else new_archive_text
          )
          remaining_text = finalize(render(tree, False), fallback_heading=first_heading(source) or "# TODO\n")
      
          if args.dry_run:
              print(f"TODO: {todo_path}")
              print(f"ARCHIVE: {archive_path}")
              if matched:
                  print(f"Section(s): {', '.join(matched)}")
              if existing_archive_text is not None:
                  print(f"NOTE: {archive_path.name} exists; this batch will be merged into it.")
              print(f"Checked tasks to archive: {archive_count}")
              print(f"Tasks remaining: {remaining_count}")
              print("\n--- .ai/TODO.md ---")
              print(remaining_text, end="")
              print("\n--- archive ---")
              print(archive_text, end="")
              return 0
      
          archive_path.parent.mkdir(parents=True, exist_ok=True)
          archive_path.write_text(archive_text, encoding="utf-8")
          todo_path.write_text(remaining_text, encoding="utf-8")
      
          print(f"Archived checked tasks: {archive_count}")
          if matched:
              print(f"Section(s): {', '.join(matched)}")
          print(f"Tasks remaining: {remaining_count}")
          print(f"Rewrote: {todo_path}")
          if existing_archive_text is not None:
              print(f"Merged: {archive_path}")
          else:
              print(f"Created: {archive_path}")
          return 0
      
      
      def resolve_root(root_arg: Optional[str]) -> pathlib.Path:
          if root_arg:
              return pathlib.Path(root_arg).expanduser().resolve()
      
          try:
              result = subprocess.run(
                  ["git", "rev-parse", "--show-toplevel"],
                  check=True,
                  capture_output=True,
                  text=True,
              )
          except (OSError, subprocess.CalledProcessError):
              return pathlib.Path.cwd().resolve()
      
          return pathlib.Path(result.stdout.strip()).resolve()
      
      
      def normalize_date(value: Optional[str]) -> str:
          if value is None:
              return dt.date.today().isoformat()
      
          normalized = value.replace("_", "-")
          try:
              dt.date.fromisoformat(normalized)
          except ValueError:
              raise SystemExit("--date must be YYYY-MM-DD or YYYY_MM_DD")
          return normalized
      
      
      def merge_archive_text(existing_text: str, new_text: str) -> str:
          """Append a newly archived batch, omitting an identical leading H1.
      
          Daily archives normally begin with the same top-level heading as the source
          TODO. Keeping it once makes repeated same-day archives read as one document.
          Other content is intentionally left untouched and batches remain ordered by
          archive time.
          """
          existing_heading = leading_h1(existing_text)
          new_heading = leading_h1(new_text)
          if existing_heading is not None and new_heading is not None:
              existing_line, _ = existing_heading
              new_line, new_end = new_heading
              if existing_line == new_line:
                  new_text = new_text[new_end:].lstrip("\r\n")
      
          return existing_text.rstrip("\r\n") + "\n\n" + new_text.lstrip("\r\n")
      
      
      def leading_h1(text: str) -> Optional[tuple[str, int]]:
          """Return the first non-blank H1 line and its end offset, if present."""
          offset = 0
          for line in text.splitlines(keepends=True):
              end = offset + len(line)
              if BLANK_RE.match(line):
                  offset = end
                  continue
              if re.match(r"^#\s+\S.*(?:\r?\n)?$", line):
                  return line.rstrip("\r\n"), end
              return None
          return None
      
      
      def parse_document(lines: Iterable[str]) -> Node:
          root = Node("root")
          stack: list[Node] = [root]
      
          for line in lines:
              heading_match = HEADING_RE.match(line)
              if heading_match:
                  level = len(heading_match.group(1))
                  while len(stack) > 1 and (
                      stack[-1].kind == "task"
                      or (stack[-1].kind == "heading" and stack[-1].level >= level)
                  ):
                      stack.pop()
                  node = Node("heading", line=line, level=level)
                  stack[-1].children.append(node)
                  stack.append(node)
                  continue
      
              task_match = TASK_RE.match(line)
              if task_match:
                  indent_text, marker, box, text, _newline = task_match.groups()
                  indent = len(indent_text.expandtabs(4))
                  while stack[-1].kind == "task" and stack[-1].indent >= indent:
                      stack.pop()
                  node = Node(
                      "task",
                      line=line,
                      indent=indent,
                      checked=box.lower() == "x",
                      marker=marker,
                      text=text,
                  )
                  stack[-1].children.append(node)
                  stack.append(node)
                  continue
      
              if stack[-1].kind == "task" and not is_task_continuation(line, stack[-1].indent):
                  while stack[-1].kind == "task":
                      stack.pop()
      
              stack[-1].children.append(Node("raw", line=line))
      
          return root
      
      
      def is_task_continuation(line: str, task_indent: int) -> bool:
          if BLANK_RE.match(line):
              return True
          return leading_spaces(line) > task_indent
      
      
      def leading_spaces(line: str) -> int:
          return len(line.expandtabs(4)) - len(line.expandtabs(4).lstrip(" "))
      
      
      def heading_text(node: Node) -> str:
          return re.sub(r"^#{1,6}\s+", "", node.line).strip()
      
      
      def iter_headings(node: Node) -> Iterable[Node]:
          for child in node.children:
              if child.kind == "heading":
                  yield child
              yield from iter_headings(child)
      
      
      def heading_matches(node: Node, hint: str) -> bool:
          return hint.lower() in heading_text(node).lower()
      
      
      def collect_matching_headings(node: Node, hint: Optional[str]) -> list[str]:
          if hint is None:
              return []
          return [heading_text(h) for h in iter_headings(node) if heading_matches(h, hint)]
      
      
      def mark_tasks(node: Node, hint: Optional[str], in_section: bool) -> None:
          """Mark every task with whether it belongs in the archive output.
      
          A task is archived when it is checked and within scope. Scope is the whole
          document when no hint is given, or the subtree of any heading matching the
          hint otherwise. Once inside a matched section, all descendants stay in scope.
          """
          if node.kind == "task":
              node.archive = bool(node.checked) and in_section
      
          child_in_section = in_section
          if node.kind == "heading" and hint is not None and heading_matches(node, hint):
              child_in_section = True
      
          for child in node.children:
              mark_tasks(child, hint, child_in_section)
      
      
      def count_tasks(node: Node, archive: bool) -> int:
          total = 1 if node.kind == "task" and node.archive is archive else 0
          return total + sum(count_tasks(child, archive) for child in node.children)
      
      
      def has_task(node: Node, archive: bool) -> bool:
          return count_tasks(node, archive) > 0
      
      
      def render(node: Node, archive: bool) -> str:
          if node.kind == "root":
              if not archive:
                  return "".join(render(child, archive) for child in node.children)
              return "".join(render(child, archive) for child in node.children if has_task(child, archive))
      
          if node.kind == "heading":
              if not archive:
                  children = "".join(
                      render_child(child, archive, parent_is_rendered=True) for child in node.children
                  )
                  return node.line + children if children.strip() else ""
              if not has_task(node, archive):
                  return ""
              return node.line + "".join(render_child(child, archive, parent_is_rendered=True) for child in node.children)
      
          if node.kind == "task":
              if not has_task(node, archive):
                  return ""
              if node.archive is archive:
                  first_line = node.line
              else:
                  first_line = context_line(node)
              return first_line + "".join(render_child(child, archive, parent_is_rendered=True) for child in node.children)
      
          if node.kind == "raw":
              return node.line
      
          raise AssertionError(f"unknown node kind: {node.kind}")
      
      
      def render_child(node: Node, archive: bool, parent_is_rendered: bool) -> str:
          if node.kind == "raw":
              return node.line if parent_is_rendered else ""
          return render(node, archive)
      
      
      def context_line(node: Node) -> str:
          newline = "\n" if node.line.endswith("\n") else ""
          return f"{' ' * node.indent}{node.marker} {node.text}{newline}"
      
      
      def finalize(text: str, fallback_heading: str) -> str:
          lines = text.splitlines(keepends=True)
      
          while lines and BLANK_RE.match(lines[0]):
              lines.pop(0)
          while lines and BLANK_RE.match(lines[-1]):
              lines.pop()
      
          cleaned: list[str] = []
          blank_count = 0
          for line in lines:
              if BLANK_RE.match(line):
                  blank_count += 1
                  if blank_count <= 2:
                      cleaned.append(line)
              else:
                  blank_count = 0
                  cleaned.append(line)
      
          spaced: list[str] = []
          for line in cleaned:
              if HEADING_RE.match(line) and spaced and not BLANK_RE.match(spaced[-1]):
                  spaced.append("\n")
              spaced.append(line)
      
          text = "".join(spaced)
          if not text.strip():
              text = fallback_heading
          if not text.endswith("\n"):
              text += "\n"
          return text
      
      
      def first_heading(source: str) -> Optional[str]:
          for line in source.splitlines(keepends=True):
              if HEADING_RE.match(line):
                  return line if line.endswith("\n") else line + "\n"
          return None
      
      
      if __name__ == "__main__":
          raise SystemExit(main())
      
  • SKILL.md 3.9 KB
    ---
    argument-hint: "[path] [--hint TEXT] [--date YYYY-MM-DD|YYYY_MM_DD] [--dry-run]"
    disable-model-invocation: true
    effort: low
    model: sonnet
    name: todo-archive
    description: Archive checked `.ai/TODO.md` tasks into `.ai/todos/YYYY-MM/DD.md`, leaving unchecked tasks.
    ---
    
    # TODO Archive
    
    If these instructions are already present in the conversation from a slash or dollar invocation, follow them directly;
    do not invoke this skill again through a skill tool.
    
    ## Arguments
    
    - `path` (optional): Repository root or any path inside the repository. Default to the current directory.
    - `--hint TEXT` (optional): Archive only the section whose heading contains `TEXT` (case-insensitive substring),
      including its subsections. Without it, archive checked tasks from the whole file. Checked tasks outside the matched
      section stay in `.ai/TODO.md`.
    - `--date YYYY-MM-DD|YYYY_MM_DD` (optional): Archive date. Default to today's local date.
    - `--dry-run` (optional): Preview target paths and rendered content without writing.
    
    ## Workflow
    
    1. Resolve the supplied `path`, or the current directory when omitted. For an existing file, use its containing
       directory; for a directory, use that directory. Store the absolute directory as `start_dir`, then resolve its Git
       root:
    
       ```sh
       git -C "$start_dir" rev-parse --show-toplevel
       ```
    
       Store the result as `repo_root`. When `start_dir` is outside a Git repository, use it as `repo_root`. Stop on a
       missing input path or another resolution error.
    
    2. Verify `.ai/TODO.md` exists under the root. If it is missing, stop and report the path checked.
    
    3. Resolve the skill directory and run its helper:
    
       ```sh
       uv run python "<skill-dir>/scripts/archive_todo.py" --root "$repo_root"
       ```
    
       Pass through `--hint`, `--date`, or `--dry-run` when the user requested them.
    
    4. Report the rewritten `.ai/TODO.md`, the created or merged archive path, the matched section (when `--hint` was
       given), and the archived/remaining task counts. If an archive for the date already exists, the helper appends the new
       batch to it, retaining one matching top-level heading. If the helper reports no checked tasks, treat it as a no-op.
       If `--hint` matches no heading, the helper exits non-zero and lists the available sections; relay them.
    
    5. If useful, inspect only `<repo_root>/.ai/TODO.md` and the exact archive path returned by the helper. Verify their
       contents directly; when Git ignores them, compare filesystem snapshots rather than relying on `git diff`.
    
    ## Helper Behavior
    
    `scripts/archive_todo.py` reads only `<root>/.ai/TODO.md`, writes archived tasks to `<root>/.ai/todos/YYYY-MM/DD.md`,
    and rewrites `<root>/.ai/TODO.md` with the remaining tasks. It preserves task-free sections and prose verbatim (a
    minimal stub with the source's first heading, or `# TODO`, only if everything was archived). With `--hint`, it restricts
    archiving to the matched heading's subtree and exits non-zero listing available headings when nothing matches. A
    same-day re-run appends its batch to that day's file, removing the new leading H1 only when it exactly matches the
    existing archive's leading H1.
    
    ## Completion
    
    Completion evidence is the helper's archive path plus archived and remaining task counts; a no-checked-task result is a
    successful no-op. Dry-run completion requires rendered paths/content with no filesystem changes, but the final message
    still follows the one-line formats below. Report the result as a single line (append a `(scope: "<hint>")` segment only
    when `--hint` was given), with the archive path relative to the repository root:
    
    - Success: `📦 Archived <n> → <archive path> (created|merged) · <remaining> remaining`
    - No-op: `✅ Nothing to archive · <remaining> remaining`
    - Dry run: `🔎 Would archive <n> → <archive path> (would create|would merge) · <remaining> would remain`
    
    Do not repeat full dry-run document content in the final message or add decoration to TODO/archive files, paths,
    commands, or helper diagnostics.
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.

Related