#pragma once // serialize.h — minified, escaped XML serialization. Streamed through a 64 KB // buffer (no whole-document string), terse schema, every name/path XML-escaped. #include "infra/emit.h" // rw::formatTo — snprintf's shape kept (stack buffer, snprintf's return) #include "infra/os.h" // rw::os::open_memstream — the est_tokens charge buffers #include // std::format_to_n — the appendf lambdas append through it directly #include "model.h" #include "declwrap.h" // declStartByte — a served body starts at its declaration, wrapper prefix included #include "memguard.h" // #350: memguard::limitSpelling — memory_limit= is spelled as the --max-memory value that raises it #include "extentsuspect.h" // extent honesty: extent_suspect= reason spellings (extent::extentSuspectReasons) #include "nextverb.h" // P3 (L7): next= on the top-ranked row #include "countfloor.h" // count-floor: implementorFloors — the implementors_floor= evidence #include "arch.h" // P3: builtinLayer() — the file-node layer= tag #include "memberowner.h" // QUALNAME-1: MemberOwners — the row folds a member's sc= into n="Owner.name" #include "graph.h" // H6/F2: definitionCountOfName — the ONE resolver behind --lego's defs= single-pick disclosure #include "graphlegend.h" // R-E fix (2026-08-19): rw::rootRelPathsLegend — the ONE root= definition #include "lintrules.h" // §P9.4: langOfPath / dependencyCapable — packDeps' dep_files= denominator #include "langfacts.h" // index-alias-const: LangFacts::aliasTargetDefs picks the C++ alias clause over the Go named-type one #include "resolve.h" // S6-C: canonicalId() — the `id=` canonical symbol string (shared with the resolver) #include "redact.h" // deterministic secret redaction of emitted body content (opt-out --no-redact) #include "docparse.h" // docparse::detail::readWholeFile — --pack-top-n reads each served file through the one whole-file reader #include "infra/sortutil.h" // numeric-key radix helpers for rank/file score order #include "infra/jsonesc.h" // F9: jsonesc::utf8SeqLen — the canonical UTF-8-sequence-length core (was duplicated here) #include "infra/strkern.h" // S5: appendCleanRun — the run-copy skip that replaces escapeXml's per-byte switch #include "notes.h" // L3: field-notes NoteIndex — the retrieval-time surfacing lookup (INERT when null) #include "pageview.h" // §P8: pageWindow / pageDisclosure — the shared --limit/--offset contract (packDeps) #include "sarif.h" // R-E (2026-08-17): rootRelativeUri/rootPrefixOf — the same root= single-root-only // strip --grep's emitGrepReport uses, reused here so the two verbs cannot diverge #include "prconverge.h" // W2-F: RankDisclosure + the pr_iters= / pr_converged= spellings (CLI and MCP share them) #include "historyread.h" // K51: history_unread= on every root that prints churn=/amp= #include "gitmine.h" // F3 (H2H-Graft): RecentFile — the map's rows are the churn-decay miner's own product #include "lexical.h" // MAP-STEM: rw::subtokens — the one subtoken rule (lexLowerByte rides with it) #include "mapinventory.h" // D7: the map scope's tier — computeMapInventory, kMapInventoryLegend #include #include // std::iota — codeFirstKeep #include #include #include // §H7 degrade seam: std::getenv for the non-release fault switch #include #include #include #include // back_inserter (reorderDocsAfterCode) #include #include namespace rw { // XML 1.0 forbids the C0 control set even ESCAPED (0x00-0x08, 0x0B, 0x0C, 0x0E-0x1F — only \t \n \r // are legal Chars): a stray form-feed in an otherwise-legal source file would break the G4 xmllint // gate. Substitute a space — deterministic, applied identically in escapeXml and the CDATA copies. inline char xmlSafeByte( char c ) noexcept { return ( static_cast( c ) < 0x20 && c != '\t' && c != '\n' && c != '\r' ) ? ' ' : c; } // ── §B12.7 + CA4 verifier F-MED-1 — THE C0 DIALECT DIVERGENCE, AND ITS TELL ───────────────────────────── // The XML and JSON dialects do not agree about C0 controls and invalid UTF-8, and they CANNOT: XML 1.0 // forbids the C0 set even escaped (only \t \n \r are legal Chars) so xmlSafeByte must substitute a space, // and an invalid sequence must become '?', while JSON has \u00XX for every control byte. jsonesc.h's own // header records the decision from the other side: the JSON escaper is the FAITHFUL one and stays faithful, // because normalizing there would make the two dialects agree by making BOTH lossy. // // What was wrong was not the divergence — it was that the lossy side said nothing. ``, whose // entire §B1.7 point is being the VERBATIM copy of the user's task, silently was not; and `EmittedBody::text` // is recorded at packBodies' push_back BEFORE appendCdataSafe, so a def holding ESC + Latin-1 reached XML at // 140 B scrubbed and JSON at 148 B raw with nothing anywhere saying so. // // So the lossy side now DISCLOSES: `scrubbed="1"` on the XML surface that lost bytes, and its JSON twin // beside the same field — the JSON is byte-faithful and does not need the warning for itself, but a consumer // diffing the two dialects is owed the fact from either one. THE MARKERS ARE A CLOSED SET, and each XML one // has exactly one JSON counterpart: `task_scrubbed=`/`route_scrubbed=` on the root (ctxRootOpen) twin // `"task_xml_scrubbed"`/`"route_xml_scrubbed"` (ctxRootJsonScrubKeys, right below it — one function, so a // call site cannot emit the field and skip the question), and `` twins `"xml_scrubbed"` on // the JSON body object. test/bodydialectcheck.sh arm (H) sweeps that table in BOTH directions rather than // the one marker that already worked. This predicate is the single decision behind all six: true iff // escapeXml/appendCdataSafe would CHANGE bytes (a C0 other than \t\n\r, or an invalid UTF-8 sequence). // Entity-escaping (& < > " ') is NOT lossy — it round-trips exactly — and must not set the flag, or every // document on earth would wear it. inline bool xmlScrubIsLossy( std::string_view s ) noexcept { const char* d = s.data(); const std::size_t n = s.size(); for( std::size_t i = 0; i < n; ) { const unsigned char c = static_cast( d[i] ); if( c < 0x20 && c != '\t' && c != '\n' && c != '\r' ) { return true; // xmlSafeByte -> ' ' } if( c < 0x80 ) { ++i; continue; } const int len = jsonesc::utf8SeqLen( d, i, n ); if( len == 0 ) { return true; // escapeXml -> '?', appendCdataSafe -> '?' } i += std::size_t( len ); } return false; } // W3FIX M2 — the three LEGAL control chars (\t \n \r) still cannot be written LITERALLY by escapeXml, for two // independent reasons that both bite the §B1.7 verbatim task attribute: // (a) G4 forbids a '\n' anywhere outside CDATA, and `--for=$'a\nb'` put one straight into `` // — a two-line document out of a serializer whose contract is one line; // (b) XML ATTRIBUTE-VALUE NORMALIZATION (XML 1.0 §3.3.3) replaces a literal \t/\n/\r in an attribute with a // SPACE at parse time, so even where the raw byte was tolerated the parser handed back a DIFFERENT // string than the user typed — §B1.7's whole point is that the attribute is the verbatim copy. // A numeric character reference survives normalization exactly (the parser un-escapes it AFTER normalizing), // so ` ` round-trips to '\n' while emitting no literal newline. Emitted for element text too: there a // char reference parses back to the identical character, so one rule serves both seams and no call site has // to know which kind of node it is writing into. Near-golden-neutral, not fully: a plain --whereis over a // .tsv file (bench/recalleval labels) legitimately carries real tabs into t= attributes, where the old code // emitted a literal tab an XML parser silently normalized to a space — the reference there is a FIX, not a // hostile-input path (seam-verifier NIT, 2026-07-29). Everywhere else on this repo the references appear // only on hostile input. inline const char* xmlControlCharRef( char c ) noexcept { switch( c ) { case '\t': return " "; case '\n': return " "; case '\r': return " "; default: return nullptr; } } // F9: utf8SeqLen used to be duplicated here (byte-identical logic to jsonesc.h's copy, just re-commented) — // now forwards to the one canonical core in jsonesc.h (zero project includes, so pulling it in here adds no // cycle risk). Kept as a `using` so every call site below (escapeXml, appendCdataSafe) is unchanged. using jsonesc::utf8SeqLen; // escape & < > " ' (ampersand FIRST) into `out`; returns a view into it. Reused per call. Byte < 0x20 is // scrubbed to a space (xmlSafeByte) or, for the three legal control chars, written as a numeric character // reference (xmlControlCharRef — see M2 above: G4 + attribute-value normalization); an invalid UTF-8 sequence // (A4-F20) is scrubbed to '?' so the emitted name/path/doc-comment/sig text is always well-formed XML AND // valid UTF-8 regardless of source bytes. // SIZE-1 (size-trim): a legend clause is present-only on the FINAL payload, not on a bit decided before the rows were // rendered. A header built ahead of its sections over-approximates on purpose (an undefined attribute costs the meaning); // once the rows are final, the clause whose attribute no emitted row carries is erased here, before the document is priced. // `clause` must be spelled exactly as the legend appended it; a clause that is not there is a no-op (the other dialect). inline void eraseAbsentClause( std::string& legend, std::string_view clause, bool present ) { if( present || clause.empty() ) { return; } if( const std::size_t at = legend.find( clause ); at != std::string::npos ) { legend.erase( at, clause.size() ); } } // The present-only clause of an attribute a late fold added (SIZE-2 folded=, SIZE-3a same_as=): spliced after `anchor` (the // clause it qualifies), or before the first comment's " -->" when the anchor is empty or absent (the other dialect, a dropped clause). inline void spliceClauseAfter( std::string& legend, std::string_view anchor, std::string_view clause ) { std::size_t at = anchor.empty() ? std::string::npos : legend.find( anchor ); at = at == std::string::npos ? legend.find( " -->" ) : at + anchor.size(); if( at != std::string::npos ) { legend.insert( at, clause ); } } // S5 — THE BYTE SET IS THE CONTRACT. Everything below that is NOT in this set is copied through // unchanged by the switch's `default:` arm, so the run loop may memcpy it in bulk without looking at it; // everything that IS in the set still goes through the SAME switch, one byte at a time, unchanged. The // set is therefore derivable from the switch and must be re-derived with it: the five entity bytes, the // whole C0 range (\t \n \r become character references, every other C0 is scrubbed to a space by // xmlSafeByte), and every byte >= 0x80 (utf8SeqLen decides whether the sequence is copied or scrubbed // to '?'). 0x7F is deliberately absent — xmlSafeByte passes DEL through, so it is a clean-run byte. // test/emitescapecheck.sh's MUT arm exists because a set one member short is otherwise silent. inline constexpr strkern::Byteset256 kXmlEscapeByteset = [] { strkern::Byteset256 set; set.addRange( 0x00, 0x1F ); set.add( '&' ); set.add( '<' ); set.add( '>' ); set.add( '"' ); set.add( '\'' ); set.addRange( 0x80, 0xFF ); return set; }(); inline std::string_view escapeXml( std::string_view s, std::vector& out ) { out.clear(); out.reserve( s.size() + 16 ); const auto put = [ & ]( const char* lit ) { while( *lit ) { out.push_back( *lit++ ); } }; const char* d = s.data(); const std::size_t n = s.size(); // Init and increment skip to the next byte the switch actually has an opinion about, copying // everything before it in one insert. On ordinary source text — names, paths, signatures, // doc-comments — that run is the whole string: one scan and one memcpy for the whole call. for( std::size_t i = strkern::appendCleanRun( d, 0, n, kXmlEscapeByteset, out ); i < n; i = strkern::appendCleanRun( d, i, n, kXmlEscapeByteset, out ) ) { const char c = d[i]; switch( c ) { case '&': put( "&" ); ++i; break; case '<': put( "<" ); ++i; break; case '>': put( ">" ); ++i; break; case '"': put( """ ); ++i; break; case '\'': put( "'" ); ++i; break; case '\t': case '\n': case '\r': put( xmlControlCharRef( c ) ); ++i; break; // M2: verbatim round-trip, no literal control byte default: if( static_cast( c ) < 0x80 ) { out.push_back( xmlSafeByte( c ) ); ++i; } else if( const int len = utf8SeqLen( d, i, n ); len == 0 ) { out.push_back( '?' ); ++i; } // scrub invalid UTF-8 else { for( int k = 0; k < len; ++k ) { out.push_back( d[i + k] ); } i += std::size_t( len ); } } } return std::string_view( out.data(), out.size() ); } // The legend clause defining the table above — appended ONLY when it actually rides (multiRoot), the same // presence-matches-emission discipline every other conditional clause in this file follows (and the same // SEPARATE-comment shape kRootRelPathsLegend uses — graphlegend.h — so a caller just concatenates it). inline constexpr const char* kMultiRootTableLegend = ""; inline const char* multiRootTableLegend( bool multiRoot ) noexcept { return multiRoot ? kMultiRootTableLegend : ""; } // ── THE FIXED-BUFFER RULE (CA4 §B14) — the one place it is written down ─────────────────────────────────── // **Never `snprintf` ALREADY-ESCAPED or already-markup text into a fixed `char[]`.** Compose it on // `std::string`. // // The test that separates a breaching site from a safe one is WHICH SIDE OF THE BUFFER THE ESCAPER SITS ON: // escape-then-snprintf → the cut lands in the ESCAPED form: mid-entity (`&am`), mid-attribute-name, // mid-UTF-8 sequence, or before the element's own `/>`. The document is broken and // the process still exits 0 — a G4 breach a caller cannot detect. // snprintf-then-escape → the cut only shortens PROSE, and the escaper then runs over the shortened text. // Ugly, never malformed. `lanes.h:698`/`:723` are safe for exactly this reason. // The escaping is what makes truncation dangerous, not the length: a 512-byte buffer breaks at 228 RAW bytes // once `&` expands 5:1 and `'` 6:1 before the buffer is written. // // A CLAMP IS THE WRONG REMEDY (§H1's recorded reason): it trades a visible breach for a silently wrong path. // Truncation that must happen belongs to the budget layer, which emits a marker; a buffer must never decide it. // // Three occurrences before the rule was swept — `tracelocus.h`'s `char row[640]` (gated, tracelocus only), // `gitmine.h`'s input-side twin (gated, gitmine only), then §B14's six emitters. `test/fixedbufsweep.sh` is // the sweep: it re-derives EVERY `snprintf` call in `src/` that interpolates a `%s`, classifies each against // a committed table, and FAILS on any call the table does not know about — so the next one is a red gate on // the commit that introduces it, not a finding three rounds later. // // W3FIX M3 — THE ONE COMMENT-ECHO SCRUB. Every task-shaped verb echoes the user's own query inside an XML // COMMENT, and each site hand-rolled the SAME '--'-collapse (main.cpp --for, packtask.h, mcpverbs.h, exemplar, // tracelocus.h) while none of them scrubbed the bytes an XML comment cannot carry. So `--for=$'a\001b'` and // `--pack-task=$'a\377b'` both made xmllint reject the whole document (G4), and `$'a\nb'` put a raw newline // outside CDATA — the ATTRIBUTE half of §B1.7 was hardened by escapeXml and the comment half was not. // // The comment is the READABLE echo (the attribute beside it is the verbatim one), so the scrub is lossy on // purpose and states its three rules in one place: // 1. '--' runs collapse to a single '-' — "--" is ill-formed inside a comment and "-->" would close it; // 2. every control byte becomes a space — C0 is illegal XML even escaped (xmlSafeByte), and \t\n\r are // legal XML but forbidden outside CDATA by G4; a character reference is NOT expanded inside a comment, // so ` ` there would be literal text pretending to be an escape — a space is the honest scrub; // 3. an invalid UTF-8 sequence becomes '?' — same rule appendCdataSafe applies to bodies. // Byte-identical to the hand-rolled std::unique collapse for every input that carried no control byte and no // invalid sequence, which is what makes it a drop-in everywhere the old collapse stood. A trailing '-' is // deliberately KEPT: no site ends its comment with user text (fixed legend prose always follows), so "a-" // cannot become "--->" and dropping it would silently lose a character the reader typed. Pure text in, pure // text out. // // CA4 §B4 — THE ENUMERATION, RE-DERIVED FROM SOURCE (this header used to claim "a drop-in at all six echo // sites", and that count had rotted: `main.cpp`'s queryRouteNote was never converted, so the true figure was // never six, and a reader auditing from the comment alone would have stopped one site short — trap #5/#12). // The honest form is a LIST, not a number, and it is machine-checked: `test/fixedbufsweep.sh` re-derives // `git grep -c 'xmlCommentText(' -- src/` (excluding this definition) and FAILS if it disagrees with the // count on the CALL-SITES line below, so the next divergence is a red gate rather than a stale sentence. // // CALL-SITES: 16 // main.cpp --for task echo · --exemplar request note · --query route note // · --run-trace command echo (runTraceLegendComment) (4) // packtask.h task · mention · co-change-boost · doc-mention notes (4) // · path-from upstream-callers note (PATH-FROM-UPSTREAM) (1) // · siblift · expand lift notes (2026-09-10 lift disclosure) (2) // mcpverbs.h for/pack-task task · exemplar request note (2) // tracelocus.h --from-trace src note (1) // serialize.h the / per-symbol name echo inside a comment: packBodies' (2) // over-budget marker and spentTailComment (lane/cutfix-bodies, 2026-09-23) // 2026-08-08 (final-sweep): 14 -> 11. L1 (density audit) dropped the comment-echoed `route note` from THREE // of the fourteen sites — main.cpp's --for route note, packtask.h's route note, and mcpverbs.h's route // reason — because the route= attribute (ctxRootOpen, attribute-escaped) is now the ONE copy of that text // (test/routeoncecheck.sh pins the single-copy contract); the comment echo was a duplicated ~230-260 B per // routed call that a scrub still had to run over. The 14th (`main.cpp`'s queryRouteNote, --query) landed in // the wave-3 merge, and the mechanism worked as designed: this line still read 13, (S4) went red naming the // true figure, and the fix was one line. That is the whole point — the count is now load-bearing rather // than decorative. inline std::string xmlCommentText( std::string_view raw ) { std::string out; out.reserve( raw.size() ); const char* d = raw.data(); const std::size_t n = raw.size(); for( std::size_t i = 0; i < n; ) { const unsigned char c = static_cast( d[i] ); if( c < 0x20 ) // rule 2 — every control byte, \t\n\r included { out += ' '; ++i; continue; } if( c == '-' && !out.empty() && out.back() == '-' ) // rule 1 — collapse the run, don't drop content { ++i; continue; } if( c < 0x80 ) { out += d[i]; ++i; continue; } if( const int len = utf8SeqLen( d, i, n ); len == 0 ) { out += '?'; ++i; } // rule 3 else { out.append( d + i, std::size_t( len ) ); i += std::size_t( len ); } } return out; } // §B1.7 — THE VERBATIM TASK ECHO. Every task-shaped verb prints its header prose inside an XML COMMENT, // where "--" is ill-formed and "-->" would close the comment early, so the echo of the user's own query is // dash-COLLAPSED before it goes in ("--for's default" → "-for's default"). That scrub is correct and stays; // what was wrong is that the collapsed text was the ONLY copy in XML, so the two dialects disagreed about // the string the user typed (--json echoes it raw). An ATTRIBUTE has no such restriction — this renders the // root element's opening tag carrying the VERBATIM task and route note, beside the comment's readable // scrubbed echo. Empty task AND empty route ⇒ a bare "", so every other verb's bytes are untouched. // // W3FIX M2 — the LIMIT of "verbatim", stated because a caller comparing the two dialects will find it: \t \n \r // round-trip EXACTLY (escapeXml writes them as character references, which survive attribute-value // normalization), but the rest of the C0 set becomes a space, because XML 1.0 forbids those bytes in a document // even as a character reference — there is no encoding of them for this format to choose. The --json dialect, // which has no such rule, stays byte-verbatim for all of them. XML scrubs one class of byte; it no longer // silently rewrites the whitespace a user actually typed. inline std::string ctxRootOpen( std::string_view task, std::string_view routeNote, std::string_view rootArg = {} ) { std::vector esc; std::string out = "', whatever follows that '>' } — the second is history_unread's definition comment when the walk was cut, "" // otherwise. The tag ends at its FIRST '>' (every attribute value above is escapeXml'd, so none holds one); splicing at the // string's LAST '>' lands inside that comment. Anything that is not a open tag splits to { "", "" }. inline std::pair ctxRootOpenParts( std::string_view rootOpen ) noexcept { const std::size_t tagEnd = rootOpen.starts_with( "' ) : std::string_view::npos; if( tagEnd == std::string_view::npos ) { return {}; } return { rootOpen.substr( 4, tagEnd - 4 ), rootOpen.substr( tagEnd + 1 ) }; } // ── ctxRootOpen's JSON TWIN, and the reason it is one function rather than a rule ───────────────────────── // The header above promises the scrub fact is legible "from either one" of the two dialects. It was not: the // tree had ONE emitter of the JSON twin (the body writer's "xml_scrubbed") against THREE XML markers, so for // the task echo — the header's own headline example — VT/FF/ESC/invalid-UTF-8 all produced task_scrubbed="1" // in XML and nothing whatsoever in JSON, on --for and --pack-task alike. The machinery was right and the // coverage was one call site short, which is what a promise phrased as a RULE gets you. // // So the JSON side is a function, taking the same two strings ctxRootOpen takes and reading the same single // predicate. A call site that emits the "task" key emits this beside it and cannot answer the question // differently, because it does not answer it at all. The keys are absent on clean input (the // silence-means-nothing-happened convention route=/over_ceiling use), so no ordinary document moves a byte. // Named with the xml_ prefix like the body twin: JSON is the FAITHFUL dialect, and what it is disclosing is // something the OTHER dialect lost. inline std::string ctxRootJsonScrubKeys( std::string_view task, std::string_view routeNote ) { std::string keys; if( !task.empty() && xmlScrubIsLossy( task ) ) { keys += ",\"task_xml_scrubbed\":true"; } if( !routeNote.empty() && xmlScrubIsLossy( routeNote ) ) { keys += ",\"route_xml_scrubbed\":true"; } keys += renderHistoryUnread( DiscloseAs::JsonKeys ); // K51: this is the one JSON root writer every ctx-family document shares (--for, --pack-task, --from-trace) return keys; } // ROOT-SPLICE-SIZE-1: append `attrs` to a ctxRootOpen-built root at its OWN '>' (ctxRootOpenParts), never at the string's last // byte. Under a cut history walk the string ends with history_unread's definition comment, so `insert( size() - 1, … )` put // --pack-task's root extras and --from-trace's notes_degraded=/next= inside that comment (`.-- notes_degraded="1">`: ill-formed). // `rootOpen` is left untouched when it is not a open tag. inline void ctxRootOpenAppendAttrs( std::string& rootOpen, std::string_view attrs ) { const std::size_t tagEnd = 4 + ctxRootOpenParts( rootOpen ).first.size(); // "' ) { rootOpen.insert( tagEnd, attrs ); } } // CDATA-body scrub shared by packSource / packBodies / packOutline: split any "]]>" so the CDATA section // stays valid, scrub forbidden C0 control bytes (xmlSafeByte, G4), AND replace invalid UTF-8 sequences with // '?' (A4-F20 — a stray Latin-1 byte in a source body otherwise makes xmllint reject the whole document). // Single pass, appends into caller-owned `safe`; deterministic + locale-independent. On all-valid input the // output is byte-identical to the prior inline loops (golden-neutral). inline void appendCdataSafe( std::string_view body, std::string& safe ) { const char* d = body.data(); const std::size_t n = body.size(); for( std::size_t i = 0; i < n; ) { if( i + 2 < n && d[i] == ']' && d[i + 1] == ']' && d[i + 2] == '>' ) { safe += "]]]]>"; i += 3; continue; } const unsigned char c = static_cast( d[i] ); if( c < 0x80 ) { safe += xmlSafeByte( d[i] ); ++i; } else if( const int len = utf8SeqLen( d, i, n ); len == 0 ) { safe += '?'; ++i; } // scrub invalid UTF-8 else { safe.append( d + i, std::size_t( len ) ); i += std::size_t( len ); } } } // streamed writer: fwrite on fill + on flush; one syscall per 64 KB, never per token. class XmlWriter { public: explicit XmlWriter( std::FILE* out ) noexcept : m_out( out ) {} ~XmlWriter() { flush(); } XmlWriter( const XmlWriter& ) = delete; XmlWriter& operator=( const XmlWriter& ) = delete; void write( std::string_view s ) noexcept { const char* p = s.data(); std::size_t n = s.size(); while( n ) { const std::size_t room = kCap - m_used; const std::size_t take = n < room ? n : room; std::memcpy( m_buf + m_used, p, take ); m_used += take; p += take; n -= take; if( m_used == kCap ) { flush(); } } } void flush() noexcept { if( m_used ) { // A4-F18: a short fwrite (disk full, broken pipe, quota) previously went UNNOTICED — the map was // silently truncated and ripwire still exited 0. Latch the failure so the caller can turn it into a // nonzero exit + one stderr line (the failed fwrite also sets ferror(m_out), the seam main reads). const std::size_t wrote = std::fwrite( m_buf, 1, m_used, m_out ); if( wrote != m_used ) { m_writeError = true; } m_used = 0; } } // A4-F18: true once any fwrite in this writer's lifetime failed to write every byte. main can also observe // the same condition via ferror(stdout) after the final flush (the failing fwrite sets the stream's error // indicator), which is how the exit-code wiring reaches it without threading a bool through every emitter. bool hadWriteError() const noexcept { return m_writeError; } private: static constexpr std::size_t kCap = 65536; std::FILE* m_out; std::size_t m_used = 0; bool m_writeError = false; char m_buf[ kCap ]; }; // The multi-root label → root path table, canonical order: `` per root, nothing under single-root. §P8 // collision: this prologue spelled its LABEL `l=`, the two characters 22 other sites use for a LINE NUMBER — including the // map's rows. Renamed to label=. inline void writeRootLabelRows( XmlWriter& w, const IngestResult& ing, std::vector& esc ) { if( ing.rootLabels.size() < 2 ) { return; } for( std::size_t r = 0; r < ing.rootLabels.size(); ++r ) { w.write( "" ); } } // M12 (capture-audit-2026-09-04, lane L9): under multi-root, every one of the graph-count verbs // (--callers/--callees/--uses) drops root= (correctly — there IS no single root=) but discloses NOTHING in // its place, so a reader of `ripwire src test --callers=SYM` has no way to learn what the `