agentleFS
GCarin1GCarin1/Doctrina/.claude/skills/check-the-line-ending-before-patching/SKILL.md

check-the-line-ending-before-patching

Skill1 starsChanged 3 days agoMITView on GitHub

Patch a file under .doctrina/ with a script without assuming its line ending, so a regex cannot silently match nothing and report success. Use when: The task edits, patches, or generates any file under .doctrina/ with a script, sed, or a regex replacement rather than by hand.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer writing the file whole: Read it, build the full new content in memory, write it back.

    line 53
  2. Very specific:

    When you must pattern-match, use \r?\n everywhere: Never a bare \n, never a bare $ in multiline mode.

    line 57
  3. Distinctive:

    Verify by reading the content, not the exit code: After a bulk edit, look at one file, and run the gate that inspects bodies:

    line 84

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- doctrina:skill-export — generated from .doctrina/skills/check-the-line-ending-before-patching.md by `doctrina index rebuild`; edit that file, not this one. -->

Skill — check-the-line-ending-before-patching

When to use this skill

  • Writing a script that fills in proposals, tasks, deltas, or specs.
  • Using sed, a Node one-liner, or any regex replacement against a file under .doctrina/.
  • Generating artifact content in bulk (a backlog, a migration, a bilingual docs pass).

The failure this prevents

A file under .doctrina/ may end its lines with LF or with CRLF, and which one is not a property of Doctrina: it is the checkout's. This repository is LF everywhere — .gitattributes says * text=auto eol=lf — but it was not always (a Windows checkout with core.autocrlf turned the templates and everything scaffolded from them into CRLF), and a project that uses Doctrina has whatever its own git settings give it. Look:

file .doctrina/changes/<id>/proposal.md
#   "... with CRLF line terminators", or no mention of terminators (LF)

A pattern anchored on \n\n, ^## What$, or $ matches nothing in a CRLF file, and a replacement that matches nothing is not an error — sed exits 0, String.replace returns the original string, and the script reports success. The file is unchanged and every downstream gate sees a file that is structurally valid, because the scaffold it still holds is valid.

This is not hypothetical: it is how six proposals reached the archive with ## Why holding nothing but its scaffold comment, past every gate, in one session.

Inside the CLI there is nothing to do

Since change 0250 the CLI's own read (src/lib/fs-ops.js) returns every file with LF, and write gives an existing file back the ending it had. New code under packages/doctrina-cli/src/ writes its patterns for LF and calls read/write — never readFileSync on an artifact, and no eolOf/withEol bookkeeping. The procedure below is for a script OUTSIDE the CLI (a one-off Python or sed pass), which sees the bytes as they are on disk.

Procedure

  1. Prefer writing the file whole. Read it, build the full new content in memory, write it back. A whole-file write cannot silently half-apply.
  2. When you must pattern-match, use \r?\n everywhere. Never a bare \n, never a bare $ in multiline mode.

    // wrong — silently no-ops on a CRLF file
    text.replace(/(## Why\n\n)<!--[\s\S]*?-->\n/, `$1${why}\n`);
    
    // right
    text.replace(/(## Why\r?\n\r?\n)<!--[\s\S]*?-->[ \t]*\r?\n?/, `$1${why}\n`);

    Inside the CLI, eolOf(text) reads the ending a file already has and withEol(text, eol) writes it back (packages/doctrina-cli/src/lib/fs-ops.js); commands/work.js does that when it injects the prompt under ## Why.

  3. Assert the replacement happened. The whole defect is a silent no-op, so make it loud:

    const next = text.replace(pattern, replacement);
    if (next === text) throw new Error(`${file}: pattern matched nothing`);
  4. Write back the ending the file had. Mixing terminators inside one file is tolerated by the parsers but makes the next diff unreadable: split on /\r?\n/, and rejoin with whichever the file used.
  5. Verify by reading the content, not the exit code. After a bulk edit, look at one file, and run the gate that inspects bodies:

    cat -A .doctrina/changes/<id>/proposal.md | head -20
    doctrina change check <id>   # fails on a section that is still scaffold

Anti-patterns

  • Trusting a zero exit code from sed -i as proof the edit landed.
  • Writing one ending into a file that holds the other — the next pattern then fails in the other direction.
  • Assuming either ending. "It is Linux, so it is LF" was false in this repository for months, and ".doctrina/ is CRLF" is false in it now.
  • "It worked when I tested it by hand" — a hand edit in an editor normalises terminators; the script does not.

Related material

  • packages/doctrina-cli/src/commands/work.js — the injection under ## Why that keeps the file's own ending.
  • packages/doctrina-cli/src/commands/analyze.js — the hollow-section check that exists because this defect shipped.
  • [[stage-a-change-backlog]] — the bulk-authoring case where this bites hardest.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.