Check rich text against the writing style before sending it
Context
Operators set writing instructions for everything agents post to Basecamp (basecamp config set instructions <url> --global), and agents are told to run basecamp instructions before writing. On the operator's machine about one session in five reads them; the rest post without them, and what goes wrong is structural: one flat paragraph of 150+ words, raw URLs in the text instead of links on words, two people mentioned at the head of a hand-back when one should decide. Every writer there (factory tools, connector subagents, report scripts, ad-hoc Claude and Codex sessions) posts through this CLI, and every rich-text write goes through richTextToHTML. So this proposes a deterministic check at that one door.
Proposed on the Kitchen card
Change
richtext.CheckStyle(html)reads the HTML a write is about to send and reports three findings, each with a one-line message in the rule's plain words:- raw URL: an
http(s)://URL in prose. Link hrefs and link text, code, and a URL that is the whole of its block (how an embed is written) are allowed. - flat body: more than 120 words with no second block (
<p>,<div>,<li>, heading,<blockquote>,<pre>,<tr>) and no<br>. - lead mentions: more than one distinct person in the first non-empty block, counting mention attachments,
mention:/person:links,@sgid:and the@Nametext the CLI resolves into mentions.
- raw URL: an
richTextToHTMLruns the check after Markdown conversion (or on the HTML as given with--format html), only when instructions apply to this write: the baseline or the active profile's (instructionsLayers). It now returns(string, error), and each of the 23 callers returns the error before sending anything.- Inside an agent session (
harness.InAgentSession:CLAUDECODE,CLAUDE_CODE_SESSION_ID, or anyCODEX_*butCODEX_HOME) a finding refuses the write with a usage error listing the findings, with a hint namingbasecamp instructionsand--as-written. Outside one the findings go to stderr as a warning and the write goes ahead. --as-writtenis added inaddRichTextFormatFlag, so every command with--formathas it (81 surface entries).skills/basecamp/SKILL.mdmentions the check and the flag where--formatis documented. The skill sits at its 16 KiB cap, so the Mermaid paragraph next to it was tightened to make room ("Use one where a picture beats prose" and the line about who sees the diagram are gone).
Chat lines and title fields are not checked; they don't pass through richTextToHTML.
Verification
bin/ci passes locally: gofmt, vet, golangci-lint, unit tests, 546 e2e tests, surface snapshot, skill drift, provenance, tidy.
internal/richtext/style_test.go: each finding and non-finding. That includes a URL alone in a block, a URL as a link's href and text, URLs in code, two paragraphs, the Markdown spacer paragraph,<br>, lists, headings, one mention, the same person twice, a second mention in a later block,@Name,@sgid:, an email address, and a mention in code.internal/commands/richtext_format_test.go: throughcomments createandupdate. It covers refusal in an agent session with nothing sent, a warning outside one,--as-written, no instructions set, profile instructions,--format htmlchecked as given, and a URL alone in an HTML block. A separate test checks that the error lists the findings and that the hint names the way out.internal/harness/session_test.go: the environment detection, including thatCODEX_HOMEalone doesn't count.
Alternatives
- Refuse inside an agent session (chosen). An agent can rewrite and resend in the same turn, and the refusal is what reaches agents that skipped the instructions. The cost: a script run from an agent's shell that posts a long single paragraph, or a raw URL, on purpose now fails until it passes
--as-written. - Warn only, everywhere. This never breaks a caller, but a stderr line is easy to miss: agents often discard stderr or don't act on it, and that is how the instructions themselves get skipped today.
- People posting outside an agent session get the warning, not the refusal, because nobody is there to rewrite for them and they may mean it.
Open questions for review:
- The check runs on the instructions that apply to this write (baseline or active profile), not
anyInstructionsConfigured, which also counts other profiles. That would check a post going out under a profile with no instructions. - The 120-word threshold.
@Nametext counts as a mention attempt even if it later fails to resolve.