Skip to content

Flatten Markdown/HTML for human-readable paste + PowerShell/prompt cleanup, --agent preset, MCP server & hook#1

Merged
sameer-zahir merged 2 commits into
mainfrom
claude/strip-code-blocks-email-EcaDQ
Jun 4, 2026
Merged

Flatten Markdown/HTML for human-readable paste + PowerShell/prompt cleanup, --agent preset, MCP server & hook#1
sameer-zahir merged 2 commits into
mainfrom
claude/strip-code-blocks-email-EcaDQ

Conversation

@sameer-zahir

@sameer-zahir sameer-zahir commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Grows the original fence/underline strip into a comprehensive make-it-paste-ready feature set, plus agent integration.

Phase 1 — engine

  • Markdown flattening (-m/--markdown; on in --email/--plain): headings, **bold**/*italic*/~~strike~~, inline `code`, list markers, [text](url)text (url), autolinks/images. Fenced and inline code are kept verbatim — shielded from both inline stripping and typography via a NUL-sentinel pass. Opt-in, so a bare socb never mangles raw terminal output.
  • HTML → text (--html): strip tags/script/style, decode entities.
  • PowerShell cleanup (--powershell/--ps): drop ~~~~ underlines and the + continuation gutter, block-anchored so diffs are safe.
  • Shell-prompt stripping (--prompts) and paragraph reflow (--reflow, conservative).
  • UTF-16 / BOM input decoding so Windows files/clipboard don't mojibake.
  • --agent preset: denoise for feeding output into a model — strip ANSI/box/glyph noise but keep Markdown structure + Unicode.
  • Markdown pipe-table alignment (| :--: |) recognized by the table engine.

Phase 2 — distribution

  • MCP server (socb-mcp): stdio server exposing sanitize_text(text, preset?, options?) for Claude Desktop/Code and Codex. @modelcontextprotocol/sdk is an optional dependency, so the plain CLI path stays dependency-free.
  • Experimental PreToolUse hook (hooks/socb-clean.mjs): rewrites noisy Bash commands through socb --agent before output hits the model's context, preserving the original exit code. (PostToolUse can't rewrite output — verified against the hooks docs — so PreToolUse updatedInput is the mechanism.)

Tests

186 passing: unit tests for every new transform (incl. false-positive guards for my_var_name, ls *.py, code-span protection, idempotence) + decode; CLI preset/override integration; MCP server driven over stdio via the SDK client; hook decision logic. Typecheck clean.

🤖 Generated with Claude Code

claude and others added 2 commits June 4, 2026 15:57
Add a stripFences transform that removes code-block delimiter lines so
output pastes into email/Slack as plain text with no fences:

- Markdown fences (>=3 backticks or tildes, optional indent + info string),
  opening and closing, leaving the wrapped content intact.
- PowerShell error underlines (the "+ ~~~~~" run under a bad token).

On by default; --no-fences / keep-fences to disable. Wired through the
pipeline, CLI flags, config validation, and library exports, with unit
tests and README/CHANGELOG updates.

https://claude.ai/code/session_01MmJKvYLG7wM3kyNGBv5Ydp
…ent, MCP server + hook

Phase 1 (engine):
- flattenMarkdown: headings, **bold**/*italic*/~~strike~~, inline `code`, list
  markers, [text](url) -> text (url); fenced + inline code kept VERBATIM via NUL
  sentinels (shielded from inline strip + typography). Opt-in (-m / --markdown).
- htmlToText (--html), cleanPowerShell (--powershell/--ps: ~ underlines + "+ "
  gutter), stripPrompts (--prompts), reflowParagraphs (--reflow).
- decodeInput: UTF-16 LE/BE + BOM detection so Windows input doesn't mojibake.
- --agent preset: denoise for feeding output INTO a model (keep Markdown/Unicode).
- Markdown/HTML/reflow/prompts/PowerShell enabled in --email / --plain presets.
- Markdown pipe-table alignment rows (| :--: |) recognized by the table engine.

Phase 2 (distribution):
- socb-mcp: stdio MCP server exposing sanitize_text(text, preset?, options?) for
  Claude Desktop/Code and Codex. @modelcontextprotocol/sdk as an optional dep so
  the plain CLI path stays dependency-free.
- Experimental Claude Code PreToolUse hook (hooks/socb-clean.mjs) that rewrites
  noisy Bash commands through `socb --agent`, preserving the original exit code.

Tests: 186 pass (markdown/html/powershell/prompts/reflow/decode units; colon
table alignment; CLI preset/override integration; MCP server over stdio; hook
decision logic). Typecheck clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sameer-zahir sameer-zahir changed the title Strip Markdown code fences and PowerShell tilde underlines Flatten Markdown/HTML for human-readable paste + PowerShell/prompt cleanup, --agent preset, MCP server & hook Jun 4, 2026
@sameer-zahir sameer-zahir merged commit 0b9704f into main Jun 4, 2026
6 checks passed
@sameer-zahir sameer-zahir deleted the claude/strip-code-blocks-email-EcaDQ branch June 4, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants