Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

feat: add a prose-width rule so vaults stop teaching sessions to hard wrap (#312)

Brenno Ferrari490e0dccb4a1
diff --git a/.claude/scripts/lib/frontmatter.ts b/.claude/scripts/lib/frontmatter.ts
index 3006344..a654694 100644
--- a/.claude/scripts/lib/frontmatter.ts
+++ b/.claude/scripts/lib/frontmatter.ts
@@ -5,6 +5,7 @@
import { basename, posix } from "node:path";
import { readFileSync } from "node:fs";
+import { hardWrappedParagraphs } from "./prose-width.ts";
const ROOT_FILES: ReadonlySet<string> = new Set([
"README.md",
@@ -218,6 +219,14 @@ export function validateContent(
);
}
+ // #247: a wrapped note teaches the wrap to every session that reads it.
+ const wrapped = hardWrappedParagraphs(content);
+ if (wrapped.length > 0) {
+ warnings.push(
+ `${wrapped.length} hard-wrapped paragraph line(s), first at line ${wrapped[0]} — write each paragraph as one line; GitHub renders a single newline as a break (raw captures: \`verbatim: true\` in frontmatter)`,
+ );
+ }
+
const ticketLinks = countTicketIdWikilinks(content);
if (ticketLinks > 0) {
warnings.push(
diff --git a/.claude/scripts/lib/prose-width.ts b/.claude/scripts/lib/prose-width.ts
new file mode 100644
index 0000000..effa3cb
--- /dev/null
+++ b/.claude/scripts/lib/prose-width.ts
@@ -0,0 +1,146 @@
+/**
+ * Prose width (#247): a paragraph is one line.
+ *
+ * GitHub, and most renderers outside Obsidian's default, show a single
+ * newline inside a paragraph as a real line break, so prose wrapped at ~70
+ * columns reaches its reader broken mid-sentence. Worse, it propagates: a
+ * session writes the shape it just read, and a vault full of wrapped notes
+ * teaches the wrap to every session that reads them, into the next PR body.
+ * An instruction did not beat the corpus; removing the examples did.
+ *
+ * `hardWrappedParagraphs` finds lines where a prose paragraph continues onto
+ * a further line. STRUCTURE is never counted, because joining it is damage
+ * that no word count notices: frontmatter (CRLF included), fenced code (```
+ * and ~~~), HTML comments and raw HTML blocks, Obsidian `%%` comments, `$$`
+ * math, tables and tab-separated rows, headings, list items and bare list
+ * markers, indented lines (indented code, a list item's continuation),
+ * field lines (`**Label:**` / `**Label**:`, one field per line by design),
+ * embeds, callout and blockquote markers, and a line after an explicit hard
+ * break (two trailing spaces or a backslash) or a lead-in ending in `:`.
+ *
+ * A note that is a raw capture — a pasted research dump, a benchmark log —
+ * keeps its breaks on purpose: `verbatim: true` in its frontmatter opts it
+ * out.
+ */
+
+const FENCE = /^(```|~~~)/;
+const LIST_ITEM = /^(?:[-*+]|\d+[.)])(?:\s|$)/;
+/**
+ * A line led by a closed bold run: field lines (`**Door:** …`,
+ * `**Blast radius**: …`) and `**1. Question?**` items, one per line by design.
+ */
+const BOLD_ITEM = /^\*\*[^*]+\*\*/;
+
+/** True when this (already de-quoted) line is structure, never prose. */
+function isStructure(line: string): boolean {
+ return (
+ line.trim() === "" ||
+ /^\s/.test(line) ||
+ line.startsWith("#") ||
+ line.startsWith("|") ||
+ line.includes("\t") ||
+ LIST_ITEM.test(line) ||
+ BOLD_ITEM.test(line) ||
+ line.startsWith("<") ||
+ line.startsWith("![[") ||
+ line.startsWith("[!") ||
+ /^-{3,}\s*$|^\*{3,}\s*$|^_{3,}\s*$/.test(line)
+ );
+}
+
+/** Whether the note opts out with `verbatim: true` in its frontmatter. */
+export function isVerbatim(content: string): boolean {
+ const text = content.replace(/\r\n/g, "\n");
+ if (!text.startsWith("---\n")) return false;
+ const end = text.indexOf("\n---", 4);
+ if (end === -1) return false;
+ return /^verbatim:\s*true\s*$/m.test(text.slice(4, end));
+}
+
+/**
+ * 1-based line numbers of every line that continues a prose paragraph from
+ * the line above it. Empty for a note at zero, and for a `verbatim` note.
+ */
+export function hardWrappedParagraphs(content: string): number[] {
+ if (isVerbatim(content)) return [];
+ const lines = content.replace(/\r\n/g, "\n").split("\n");
+ const out: number[] = [];
+
+ let i = 0;
+ if (lines[0] === "---") {
+ const close = lines.indexOf("---", 1);
+ i = close === -1 ? 0 : close + 1;
+ }
+
+ let fence: string | null = null;
+ let inComment = false; // <!-- … -->
+ let inObsidianComment = false; // %% … %%
+ let inMath = false; // $$ … $$
+ let previousProse = false;
+ let previousQuoted = false;
+
+ for (; i < lines.length; i++) {
+ const raw = lines[i] ?? "";
+ // A blockquote's content is judged without its marker, so a wrapped
+ // paragraph inside a quote is still one, and a fence, comment or math
+ // block inside a quote is still structure. A callout's `> [!type]`
+ // title line is structure.
+ const quoted = /^>/.test(raw);
+ const line = quoted ? raw.replace(/^(?:>\s?)+/, "") : raw;
+ const notProse = (): void => {
+ previousProse = false;
+ };
+
+ if (fence !== null) {
+ if (line.trimStart().startsWith(fence)) fence = null;
+ notProse();
+ continue;
+ }
+ const fenceOpen = FENCE.exec(line.trimStart());
+ if (fenceOpen && !/^\s{4,}/.test(line)) {
+ fence = fenceOpen[1] ?? null;
+ notProse();
+ continue;
+ }
+ if (inComment) {
+ if (line.includes("-->")) inComment = false;
+ notProse();
+ continue;
+ }
+ if (line.trimStart().startsWith("<!--")) {
+ inComment = !line.includes("-->");
+ notProse();
+ continue;
+ }
+ if (inObsidianComment) {
+ if (line.includes("%%")) inObsidianComment = false;
+ notProse();
+ continue;
+ }
+ if (line.trimStart().startsWith("%%")) {
+ // Opens a comment unless the same line also closes it.
+ inObsidianComment = !line.trimStart().slice(2).includes("%%");
+ notProse();
+ continue;
+ }
+ if (line.trim() === "$$") {
+ inMath = !inMath;
+ notProse();
+ continue;
+ }
+ if (inMath || isStructure(line)) {
+ notProse();
+ continue;
+ }
+
+ // A quote starts or ends a block: prose on either side of the boundary
+ // is two blocks, not one wrapped paragraph.
+ if (previousProse && quoted === previousQuoted) out.push(i + 1);
+ // An explicit hard break (two trailing spaces, or a backslash) ends the
+ // line on purpose, and a line ending in `:` is a lead-in ("Content to
+ // process:" above its placeholder): what follows either is not a wrap.
+ previousProse = !/(?: {2}|\\|:)$/.test(raw);
+ previousQuoted = quoted;
+ }
+ return out;
+}
diff --git a/.claude/scripts/tests/frontmatter.test.ts b/.claude/scripts/tests/frontmatter.test.ts
index fd2caae..490d2f5 100644
--- a/.claude/scripts/tests/frontmatter.test.ts
+++ b/.claude/scripts/tests/frontmatter.test.ts
@@ -242,11 +242,21 @@ describe("validateContent — frontmatter + wikilinks", () => {
test("valid long note with wikilink produces no warnings", () => {
const c =
"---\ndate: 2026-04-05\ndescription: A valid test note\ntags:\n - test\n---\n" +
- "# Note\n\nSome content with [[a wikilink]] and more text.\n" +
+ // Filler is its own paragraph: on the next line it would be a
+ // hard-wrapped one (#247).
+ "# Note\n\nSome content with [[a wikilink]] and more text.\n\n" +
"x".repeat(300);
assert.deepEqual(validateContent(c), []);
});
+ test("a hard-wrapped paragraph is warned about, naming its first line", () => {
+ const c = "---\ndate: 2026-04-05\ndescription: d\ntags: [x]\n---\n# Note\n\nA paragraph that was\nwrapped at a narrow width.\n";
+ const w = validateContent(c).filter((x) => x.includes("hard-wrapped"));
+ assert.equal(w.length, 1);
+ // Line 9 is the continuation: frontmatter is lines 1–5, the heading 6.
+ assert.match(w[0]!, /^1 hard-wrapped paragraph line\(s\), first at line 9 /);
+ });
+
test("tolerates 'tags :' with space (alternate YAML style)", () => {
const c =
"---\ndate : 2026-04-05\ndescription : test\ntags :\n - test\n---\n# Note\n" +
diff --git a/.claude/scripts/tests/prose-width.test.ts b/.claude/scripts/tests/prose-width.test.ts
new file mode 100644
index 0000000..d124519
--- /dev/null
+++ b/.claude/scripts/tests/prose-width.test.ts
@@ -0,0 +1,78 @@
+/**
+ * The hard-wrap detector (#247). Each structure case below was found by
+ * damage when wrapped prose was joined in bulk: joining any of them loses no
+ * word, so only a detector that knows structure can leave them alone.
+ */
+
+import { test, describe } from "node:test";
+import assert from "node:assert/strict";
+import { hardWrappedParagraphs, isVerbatim } from "../lib/prose-width.ts";
+
+const at = (...lines: string[]) => hardWrappedParagraphs(lines.join("\n"));
+
+describe("hardWrappedParagraphs — prose", () => {
+ test("a paragraph continued onto the next line is reported at the continuation", () => {
+ assert.deepEqual(at("# T", "", "A paragraph that was", "wrapped at a narrow width,", "twice."), [4, 5]);
+ });
+ test("one line per paragraph is clean", () => {
+ assert.deepEqual(at("# T", "", "One paragraph on one line.", "", "Another, also on one."), []);
+ });
+ test("a wrapped paragraph inside a blockquote counts; the marker is not prose", () => {
+ assert.deepEqual(at("> A quoted paragraph that", "> was wrapped."), [2]);
+ });
+ test("line numbers are of the file, frontmatter included", () => {
+ assert.deepEqual(at("---", "date: x", "---", "first", "second"), [5]);
+ });
+});
+
+describe("hardWrappedParagraphs — structure is never counted", () => {
+ const clean: [string, string[]][] = [
+ ["LF frontmatter", ["---", "name: a", "description: b", "---", "Body."]],
+ ["fenced code with backticks", ["```", "line one", "line two", "```"]],
+ ["fenced code with tildes", ["~~~", "line one", "line two", "~~~"]],
+ ["an HTML comment", ["<!--", "Terminal and version:", "OS:", "-->"]],
+ ["raw HTML", ["<table>", "<tr><td>a</td></tr>", "</table>"]],
+ ["an Obsidian %% comment", ["%%", "private line", "another", "%%"]],
+ ["$$ math", ["$$", "a = b", "c = d", "$$"]],
+ ["a table", ["| a | b |", "|---|---|", "| 1 | 2 |"]],
+ ["tab-separated rows", ["name\tvalue", "alpha\t1", "beta\t2"]],
+ ["headings", ["# One", "## Two"]],
+ ["list items and bare markers", ["- one", "- two", "1.", "-"]],
+ ["indented lines: code, or a list item's continuation", ["- item", " source: x", " notes: y", " code line", " code line"]],
+ ["field lines, both bold forms", ["**Door:** two-way.", "**Blast radius**: small."]],
+ ["embeds", ["![[Note]]", "![[Other]]"]],
+ ["a callout title above its body", ["> [!warning] Title", "> Body on one line."]],
+ ["an explicit hard break (two spaces)", ["Line one ", "line two"]],
+ ["an explicit hard break (backslash)", ["Line one\\", "line two"]],
+ ["a lead-in ending in a colon", ["Content to process:", "$ARGUMENTS"]],
+ ["a thematic break", ["Text.", "---", "More."]],
+ ["a fence inside a blockquote", ["> Run this:", "> ```sh", "> one", "> two", "> ```"]],
+ ["prose, then a blockquote: two blocks", ["**A question?**", "> An answer on one line.", "Back in prose."]],
+ ["bold-led items, one per line", ["**1. First question?** Detail.", "**2. Second question?** More."]],
+ ];
+ for (const [name, lines] of clean) {
+ test(name, () => assert.deepEqual(at(...lines), []));
+ }
+
+ test("CRLF frontmatter is found as frontmatter, not read as wrapped fields", () => {
+ assert.deepEqual(hardWrappedParagraphs("---\r\nname: a\r\ndescription: b\r\n---\r\nBody.\r\n"), []);
+ });
+ test("CRLF prose is still prose", () => {
+ assert.deepEqual(hardWrappedParagraphs("A paragraph\r\nwrapped.\r\n"), [2]);
+ });
+ test("prose resumes being checked after a fence closes", () => {
+ assert.deepEqual(at("```", "x", "```", "Prose that", "wraps."), [5]);
+ });
+});
+
+describe("verbatim opt-out", () => {
+ test("`verbatim: true` in frontmatter keeps a raw capture's breaks", () => {
+ const note = "---\nverbatim: true\n---\nA pasted log\nwith its own\nline breaks.";
+ assert.equal(isVerbatim(note), true);
+ assert.deepEqual(hardWrappedParagraphs(note), []);
+ });
+ test("verbatim outside frontmatter, or false, does not opt out", () => {
+ assert.equal(isVerbatim("verbatim: true\nA\nB"), false);
+ assert.equal(isVerbatim("---\nverbatim: false\n---\nA\nB"), false);
+ });
+});
diff --git a/.claude/scripts/tests/validate-write.test.ts b/.claude/scripts/tests/validate-write.test.ts
index 6eb7d6d..0a4fb16 100644
--- a/.claude/scripts/tests/validate-write.test.ts
+++ b/.claude/scripts/tests/validate-write.test.ts
@@ -171,7 +171,9 @@ describe("validate-write — valid note produces no warnings", () => {
test("fully-formed note", () => {
const path = makeMd(
"---\ndate: 2026-04-05\ndescription: A valid test note\ntags:\n - test\n---\n" +
- "# Note\n\nSome content with [[a wikilink]] and more text.\n" +
+ // Filler is its own paragraph: on the next line it would be a
+ // hard-wrapped one (#247).
+ "# Note\n\nSome content with [[a wikilink]] and more text.\n\n" +
"x".repeat(300),
"g.md",
);
diff --git a/.claude/scripts/tests/vault-prose-width.test.ts b/.claude/scripts/tests/vault-prose-width.test.ts
new file mode 100644
index 0000000..8ebe545
--- /dev/null
+++ b/.claude/scripts/tests/vault-prose-width.test.ts
@@ -0,0 +1,61 @@
+/**
+ * Prose-width ZERO GATE (#247): no note in this vault has a hard-wrapped
+ * paragraph.
+ *
+ * The write hook warns at write time, but a note edited in Obsidian never
+ * passes through it, and one wrapped note is enough to teach the wrap to the
+ * next session that reads it. So the vault itself is checked, the way
+ * `vault-wikilinks.test.ts` checks links.
+ *
+ * Scope mirrors that gate: machinery and agent config trees are skipped, and
+ * so are session transcripts. Templates are checked: every note made from one
+ * inherits its shape. A note opts out with `verbatim: true`; a folder of raw
+ * captures opts out with a `.verbatim` file.
+ */
+
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { existsSync, readFileSync, readdirSync } from "node:fs";
+import { dirname, join, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+import { hardWrappedParagraphs } from "../lib/prose-width.ts";
+
+const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
+const SKIP = new Set([".git", ".obsidian", ".claude", ".codex", ".gemini", ".github", ".shardmind", "node_modules"]);
+const SKIP_PATHS = new Set(["thinking/session-logs"]);
+
+function notes(): string[] {
+ const out: string[] = [];
+ const walk = (rel: string): void => {
+ if (SKIP_PATHS.has(rel) || (rel !== "" && existsSync(join(repoRoot, rel, ".verbatim")))) return;
+ let entries;
+ try {
+ entries = readdirSync(join(repoRoot, rel), { withFileTypes: true });
+ } catch {
+ return;
+ }
+ for (const e of entries) {
+ if (SKIP.has(e.name)) continue;
+ const r = rel === "" ? e.name : `${rel}/${e.name}`;
+ if (e.isDirectory()) walk(r);
+ else if (e.name.toLowerCase().endsWith(".md")) out.push(r);
+ }
+ };
+ walk("");
+ return out;
+}
+
+test("no note in this vault has a hard-wrapped paragraph", () => {
+ const found = notes();
+ assert.ok(found.length > 0, "the walk found no notes — a gate on an empty walk proves nothing");
+ const offenders = found
+ .map((rel) => ({ rel, lines: hardWrappedParagraphs(readFileSync(join(repoRoot, rel), "utf8")) }))
+ .filter((o) => o.lines.length > 0);
+ assert.deepEqual(
+ offenders.map((o) => `${o.rel}: lines ${o.lines.join(", ")}`),
+ [],
+ "Write each paragraph as one line (GitHub renders a single newline as a break, and a wrapped note teaches the wrap to every session that reads it). " +
+ "A raw capture whose breaks are the evidence opts out with `verbatim: true` in frontmatter. " +
+ "A line split inside a code span (a `\\r` turned into a real newline by a script) shows up here too.",
+ );
+});