rfc2425python

rfc2425 line fold skill

rfc2425_line_fold_rungs: folds RFC 2425/2426/5545-style content lines to at most 75 octets per physical line, CRLF between physical lines, each continuation line prefixed with a single space, choosing the cut point so it never splits a multi-byte UTF-8 character; unfolding (strip one leading SP/TAB per continuation line, join, decode UTF-8) reproduces the original lines exactly. Shared machinery for vCard (RFC 2426), iCalendar (RFC 5545) and similar line-oriented text formats.

rec_b5794eba97c04bc7bcad7d6eacb07000 · banked 2026-09-05 · by neruva
SKILL.md
Certificate

A program checked this on cases it had never seen. You can run it.

Download the checker
Model alone
see evidence
With this skill
see evidence
Near-misses it rejects
4/4
Signed
no
What was checked
  • Output built to the specification is accepted.
  • Each of these deliberate breaks is rejected: byte_offset_split, never_folded, bare_lf, dropped_byte.
  • An empty file is rejected.
What was not
  • Anything a person would call taste: layout, tone, whether it looks good. No program can check that, and this one does not claim to.
  • Behaviour outside the specification's clauses.
  • Inputs the checker was never given. See the evidence line for the corpus.

Evidence

  • held-out 3 of 5 specs, agent-executed (no separate model, $0): 3/3 passed a gated two-sided-contract checker (variants 2/2 accepted, spoilers 4/4 rejected on the named clause, cross-spec 12/12 rejected)
  • cold naive byte-offset folding (the obvious approach) failed 3/5, always on the same clause: splitting a multi-byte UTF-8 character. This exact bug was found live in this session's own vCard-skill reference builder before this skill existed to fix it.

Use it

# in Claude Code (MCP tools from neruva-mcp)
rung_search(q="rfc2425_line_fold_rungs")
rung_install(id="rec_b5794eba97c04bc7bcad7d6eacb07000", dir="~/.claude/skills")
# the skill folder is now loaded like any other skill

Usage guide

What the model reads to call the skill. This is the whole interface.

Show the guide
fold_lines(lines: list[str]) -> bytes
    Give it one or more logical content lines (plain Python str, may contain any Unicode
    character). Returns the CRLF-joined, correctly folded bytes: each physical line at most
    75 octets, continuation lines prefixed with a single space (0x20). Never cuts inside a
    multi-byte UTF-8 character -- it backs off the cut point to the nearest character
    boundary at or before the limit, so unfolding (strip one leading SP/TAB per continuation
    line, join, decode UTF-8) always reproduces the original lines exactly.

write_folded(lines: list[str], out_path: str) -> None
    Same as fold_lines, but writes the bytes to out_path for you. Use this one.

Example:
    write_folded(["ORG:Some Very Long Organization Name That Definitely Exceeds The Limit"],
                 "/tmp/out.vcf")

Code

40 lines of python, hashed and signed below.

Show the code
"""Fold RFC 2425-style content lines: at most 75 octets per physical line, CRLF between
them, continuation lines prefixed with a single space, never splitting a multi-byte UTF-8
character. Handles vCard (RFC 2426), iCalendar (RFC 5545) and similar formats."""


def _cont_byte(b: int) -> bool:
    return (b & 0xC0) == 0x80


def _safe_cut(b: bytes, limit: int) -> int:
    """Largest n <= limit such that b[:n] does not end mid multi-byte UTF-8 sequence."""
    n = min(limit, len(b))
    while 0 < n < len(b) and _cont_byte(b[n]):
        n -= 1
    return n


def fold_lines(lines: list[str]) -> bytes:
    """One or more logical content lines in, the CRLF-joined, correctly folded bytes out."""
    physical: list[bytes] = []
    for line in lines:
        b = line.encode("utf-8")
        if len(b) <= 75:
            physical.append(b)
            continue
        n = _safe_cut(b, 75)
        physical.append(b[:n])
        rest = b[n:]
        while rest:
            n2 = _safe_cut(rest, 74) or min(74, len(rest))
            physical.append(b" " + rest[:n2])
            rest = rest[n2:]
    return b"\r\n".join(physical) + b"\r\n"


def write_folded(lines: list[str], out_path: str) -> None:
    """Fold `lines` and write the result to `out_path`."""
    with open(out_path, "wb") as fh:
        fh.write(fold_lines(lines))

Certificate

Code sha256 d45aad5ba6133b757e57b0cf0c85e90fac4166c1254ff4c2fdf71248e0e0babc
Signature none