encodeNodePathKey function

String encodeNodePathKey(
  1. String nodePath
)

Encodes nodePath for use inside a bd metadata KEY (tg-6e4j).

bd's server-side atomic metadata merge — the --set-metadata path EVERY chokepoint write rides since the mergeMetadata migration — validates keys against [a-zA-Z_][a-zA-Z0-9_.]*. A raw node path (pow-1rn.3/spec_review/intake) carries / and -, so any write embedding one was refused WHOLESALE (BdUpdatePartialFailure), which silently froze every circuit advance on the first live arm of the rc.3 foundation. (The retired --metadata JSON-replace path never validated keys, which is why the shape survived until the merge migration.)

Reversible per-character escape into the accepted charset, _ as the escape lead: __u, /_s, -_h. decodeNodePathKey reverses it; any other character passes through unchanged. Today's id vocabulary (bead/circuit/step ids: [a-z0-9._-] + the / separator) is covered exactly; a new special character in ids must extend BOTH halves.

_ is escaped FIRST so the _s/_h sequences the later rules introduce are never re-escaped.

Implementation

String encodeNodePathKey(String nodePath) =>
    nodePath.replaceAll('_', '_u').replaceAll('/', '_s').replaceAll('-', '_h');