PLUGIN DETAIL FLAVOR: SPACES CLASS FLAVOR

hook-dsh-normalize-spaces

Hook @ DSH @ Normalize @ Spaces • _The DeepSeek Harness Plugin Family for PlayForm._ The space normalizer for model output - a DeepSeek Harness plugin that hooks the llm/stream waterfall (the interceptable wrapper around EVERY streaming model call, bound to the LlmRuntime) and normalizes the unicode space family in model output, live in the transcript: every visible non-terminator space that is not the ASCII space becomes the plain ASCII space - U+00A0 to ' ', quads and quirs alike. A CLASS flavor of the normalize family: the core's Spaces class plus a configurable replacement string (default " ", the plain ASCII space). The family's raw-write tool (registered by hook-dsh-normalize-dash) bypasses this flavor's transforms too - the exemption is family-wide.

CLI INSTALL COPIED
$ pnpm add @playform/hook-dsh-normalize-spaces
Namespace: @playform/hook-dsh-normalize-spaces Release: v0.0.1
Archetype: Hook Event: llm/stream Table: core Spaces class

The profile wiring for this plugin - the bundles list, the patch entry and the restart - is on the setup page.

Where It Fits

FAMILY POSITION: 4TH OF 6 STREAM NORMALIZERS

Family position (the @-sentence Hook @ DSH @ Normalize @ Spaces): a hook child of the plugin-dsh-factory service and the hook-dsh-core machinery; the fourth of the six stream normalizer siblings:

FlavorTableSubstitution
hook-dsh-normalize-dashcore Dashes class→ replacement (default -)
hook-dsh-normalize-quotescore Quotes MAPcurly → straight
hook-dsh-normalize-ellipsiscore Ellipsis classU+2026 → ...
hook-dsh-normalize-spaces (this bundle)core Spaces classunicode spaces → " "
hook-dsh-normalize-invisiblecore Invisible classremoved (default "")
hook-dsh-normalize-fullwidthcore Fullwidth MAPfull-width → half-width

A non-manifest factory consumer: it injects ["pluginFactory"] and uses only State (cell unwrap + shared Ledger/Enabled mappings + its own fields) and Append; the config is composed by the factory's standalone Schema helper with shared: false - the minimal block, no fs/observed dead fields. It touches no files, so fs/write-intent and fs/observed never see it; it wraps the downstream result and always calls next(), so it composes with other llm/stream listeners regardless of registration order.

In the DeepSeek Harness

WHERE THE FLAVOR OPERATES
SeamWhat the plugin does thereWhat you can observe
llm/stream - the model stream waterfallThe plugin's listener wraps the interceptable waterfall around EVERY streaming model call (bound to the LlmRuntime): next() is called first, options are never touched, one chunk in - one chunk out, upstream throws propagate.Plain ASCII spaces reach the live UI and the durable transcript as the stream is born.
The model stream vocabulary (dsh-llm)The chunk/block shapes it rewrites come from the harness's stream vocabulary (@deepseek-ai/dsh-llm, type-only): text deltas, reasoning deltas and assembled blocks must agree.No inconsistencies between deltas and blocks for downstream consumers.
The factory serviceA non-manifest factory consumer: State for the config (the replacement is a hot-editable volatile cell - no remount) and Append for every ledger line; it touches no files.Composes with other llm/stream listeners regardless of registration order.
The raw-write exemption (family-wide)The family's raw-write tool (registered by hook-dsh-normalize-dash) passes through this flavor's stream transforms by identity - the tool's explicit normalize parameter is the only normalization it applies.Per-call control stays with the agent, even with every stream flavor armed.
The ledger / sessionTwo lines through the factory's Append: the activation proof from apply() and the per-stream count line on a normal completion with N > 0.A thrown-away stream writes no ledger line.

The Problem

WHY THE SPACES FLAVOR EXISTS

Model output picks up exotic spaces - the no-break space from copy-pasted prose, the thin space from typographic text, the ideographic space from CJK input. Markdown renderers and shell quoting do not treat them as spaces; a command with a U+00A0 in it fails for no visible reason. This flavor makes the plain ASCII space the one that reaches the transcript.

How It Works

THE STREAM PIPELINE
llm/stream waterfall (options, next) the interceptable wrapper around │ EVERY streaming model call ▼ next() called FIRST, always - options never touched Normalize(upstream, state) the async generator │ for await (chunk of upstream) ▼ CoreChunk(chunk, transform, reasoning, toolArgs, raw) the core's per-chunk dispatch │ ├─ text-delta ────────► Replace(text, Spaces, " ") rewrite the text field ├─ reasoning-delta ───► same, when normalizeReasoning (default ON) ├─ block-end ─────────► the assembled block's text fields - │ TextBlock.text / ReasoningBlock.text (plus a │ runtime `thinking` string field) - the deltas │ AND the block must agree, or consumers see │ inconsistencies ├─ tool-call-delta ───► Replace(argumentsDelta, Spaces, " ") when │ normalizeToolArguments (IMPLEMENTED, default │ OFF - execution-critical raw JSON, the user's │ accepted risk; the example patch turns it │ on) - the assembled ToolCallBlock.arguments │ follows the same flag via block-end │ The gate is THREE-WAY with the flag on: a │ delta/block whose `name` is "edit" passes │ through BY IDENTITY (the edit tool's │ `old_string` must match the real file bytes), │ and a call whose arguments open with the │ `{"__normalize":false` marker (FIRST key, │ tracked per call id) passes through │ UNNORMALIZED with the marker entry stripped, │ so the executed call carries no unknown key └─ block-start / usage / finish ──► PASSTHROUGH BY IDENTITY, ALWAYS (usage/finish ordering is the adapter contract) │ count === 0 → original chunk BY IDENTITY; rewritten → shallow copy ▼ yield ──► downstream consumers = the live UI + the durable transcript │ (order preserved, no buffering; upstream throws propagate) ▼ normal loop completion, Count > 0 Factory.Append ──► `hook-dsh-normalize-spaces: normalized N space char(s) in one stream`

The transform - exactly the core's Spaces class (@playform/hook-dsh-core's Normalize/Spaces), applied per text segment through the core's generic class-to-string Replace:

[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000] → replacement

Exactly Unicode's Zs category minus the ASCII space - becomes the config replacement (default " ", the plain ASCII space U+0020):

Code pointsCharacters
U+00A0no-break space
U+1680ogham space mark
U+2000-U+200Aen quad, em quad, en space, three-per-em, four-per-em, six-per-em, figure space, punctuation space, thin space, hair space
U+202Fnarrow no-break space
U+205Fmedium mathematical space
U+3000ideographic space

No context rules - hermes-style whole-chunk replacement, no lookahead; chunk-boundary-safe. The replacement is applied with a function replacer, so a custom replacement containing $ patterns is inserted literally. Replaced characters are counted per stream for the ledger line.

The Config

SCHEMA + DEFAULTS AT LOAD
FieldTypeDefaultVolatileMeaning
logbooleantrueyeswrite the durable ledger file
logFilestring~/.dsh/hook-dsh-normalize-spaces.logyesthe spaces ledger (separate from the family's logs)
replacementstring" "yesthe transform's only knob - hot-editable, the next stream picks it up with no remount
normalizeReasoningbooleantruenonormalize reasoning deltas and the assembled reasoning block too
normalizeToolArgumentsbooleanfalsenoIMPLEMENTED (default OFF): rewrite the tool-call argumentsDelta and the assembled ToolCallBlock.arguments when on (with the edit name exemption and the {"__normalize":false raw-marker pass-through) - execution-critical raw JSON, the user's accepted risk; the example patch turns it on

Volatile cells commit without remounting the plugin; the factory's State builder unwraps them defensively. Example cordis.patch.yml row:

- insert: - id: hook-dsh-normalize-spaces name: "@playform/hook-dsh-normalize-spaces" config: log: true logFile: ~/.dsh/hook-dsh-normalize-spaces.log replacement: " "

In Action

ONE STREAM, ONE TRANSFORMATION

One stream, one transformation. The model emits copy-pasted typographic spacing; the live UI and the transcript receive plain ASCII spaces. In the incoming line below the three gaps are the no-break space U+00A0, the em quad U+2003 and the ideographic space U+3000, in that order:

Before → after - the model stream, then what reaches the transcript

text-delta in (what the model wrote; each marked gap is a non-ASCII space): deploy the agent to the ring buffer text-delta out (what reaches the transcript): "deploy the agent to the ring buffer"

Each non-ASCII space in the Zs-minus-ASCII class - U+00A0 between deploy and the, U+2003 between agent and to, U+3000 between ring and buffer in the sample above - becomes exactly one ASCII space (U+0020); ASCII spaces that were already there are untouched. This is what makes a pasted command executable again: echo a - b with a hidden no-break space between the arguments runs after the pass, where before the pass the shell saw one mangled word. When a stream finishes normally with replacements made, the ledger gets the count line shown below (note the replacement= field renders the default as a bare space). The replacement is hot-editable (say to _ for debugging), and the same pass runs over reasoning deltas when normalizeReasoning is on and over tool-call arguments when the example patch enables normalizeToolArguments - with the edit name exempt and raw-marker calls passing through unnormalized.

The Ledger

TWO LINES VIA FACTORY APPEND

Two lines, both written through the factory's Append (the hook-dsh-normalize-spaces: prefix is the logger's <State.Module>:; the durable file line is [<ISO>] <message>). In the activation line, replacement= is followed by the ASCII space itself - the default renders as a trailing blank:

hook-dsh-normalize-spaces: activated (replacement= , reasoning=on, toolArgs=off, logFile=~/.dsh/hook-dsh-normalize-spaces.log) hook-dsh-normalize-spaces: normalized 3 space char(s) in one stream

The activation line is written by apply(); the count line only follows a normal stream completion and only when N > 0 (a thrown-away stream writes no ledger line).

Related plugins

12 TOTAL
hook-dsh-core DSH FAMILY

Supplies the Spaces class, the Replace replacer and the generic Chunk/Block dispatch this flavor is a thin closure over.

plugin-dsh-factory PARENT SERVICE

The parent service: State, Append - plus the named Schema helper (shared: false) for the config.

License: MIT.