|
| 1 | +--- |
| 2 | +weight: 30 |
| 3 | +summary: >- |
| 4 | + The top-level `foreign-regions:` config lists `{start, end}` marker |
| 5 | + pairs whose spanned bytes mdsmith treats as opaque — style rules skip |
| 6 | + diagnostics inside a matched pair and fixers never rewrite it, while |
| 7 | + whole-file rules still count the bytes. Glob-scopable via `overrides:`; |
| 8 | + a start with no matching end reports MDS073. |
| 9 | +--- |
| 10 | +# Foreign regions |
| 11 | + |
| 12 | +A **foreign region** is a span of a Markdown file that another |
| 13 | +generator owns. The top-level `foreign-regions:` key lists the marker |
| 14 | +pairs that bound such spans, so `mdsmith fix` leaves those bytes |
| 15 | +byte-for-byte unchanged and the style rules raise no diagnostics inside |
| 16 | +them. The first case is [APM][apm], whose `managed_section` mode writes |
| 17 | +a block bounded by `<!-- apm:start -->` and `<!-- apm:end -->` and pins |
| 18 | +a SHA-256 of the file; any reflow inside that block trips its drift |
| 19 | +check. |
| 20 | + |
| 21 | +This is the same exclusion the [generated-section engine][gensection] |
| 22 | +applies to `<?include?>` and `<?catalog?>` bodies. The difference is |
| 23 | +ownership: mdsmith regenerates its own directive bodies, but never |
| 24 | +touches a foreign region — the owning tool regenerates it. |
| 25 | + |
| 26 | +## Configuration |
| 27 | + |
| 28 | +Declare each marker pair under `foreign-regions:`. mdsmith matches |
| 29 | +`start` and `end` against whole lines with surrounding whitespace |
| 30 | +trimmed. A marker may be indented, but it must sit on its own line: |
| 31 | + |
| 32 | +```yaml |
| 33 | +foreign-regions: |
| 34 | + - start: "<!-- apm:start -->" |
| 35 | + end: "<!-- apm:end -->" |
| 36 | +``` |
| 37 | +
|
| 38 | +Both markers must be non-empty and must differ from each other; a pair |
| 39 | +that violates either rule is a config error. |
| 40 | +
|
| 41 | +### Scoping to a subtree |
| 42 | +
|
| 43 | +`foreign-regions:` is glob-scopable through |
| 44 | +[`overrides:`](globs.md). An override's `foreign-regions:` list is |
| 45 | +**appended** to the top-level list for every file its glob matches — it |
| 46 | +never replaces the global pairs. Use this to protect an extra marker |
| 47 | +pair that only appears under one path: |
| 48 | + |
| 49 | +```yaml |
| 50 | +foreign-regions: |
| 51 | + - start: "<!-- apm:start -->" |
| 52 | + end: "<!-- apm:end -->" |
| 53 | +overrides: |
| 54 | + - glob: ["AGENTS.md"] |
| 55 | + foreign-regions: |
| 56 | + - start: "<!-- gen:start -->" |
| 57 | + end: "<!-- gen:end -->" |
| 58 | +``` |
| 59 | + |
| 60 | +## What the region protects |
| 61 | + |
| 62 | +mdsmith scans each file for every declared marker pair. It records the |
| 63 | +span from a `start` line through its matching `end` line. The markers |
| 64 | +themselves are part of the span. |
| 65 | + |
| 66 | +| Surface | Behavior inside a matched region | |
| 67 | +| --------------------------------- | ------------------------------------------------------------------------------------------ | |
| 68 | +| `mdsmith fix` | Bytes round-trip unchanged, even otherwise-fixable trailing spaces and table misalignment. | |
| 69 | +| Style and content rules | Emit no diagnostics; the same violation outside the region still fires. | |
| 70 | +| Whole-file rules (MDS022, MDS028) | Still count the region's bytes toward file length and token budget. | |
| 71 | + |
| 72 | +Whole-file rules read the raw source. A large foreign region still |
| 73 | +counts against `max-file-length` and `token-budget`. The region is |
| 74 | +opaque to editing, not invisible to size accounting. |
| 75 | + |
| 76 | +## Malformed regions (MDS073) |
| 77 | + |
| 78 | +APM requires each marker exactly once. mdsmith reports **MDS073** on a |
| 79 | +malformed region and protects no bytes for it: |
| 80 | + |
| 81 | +| Condition | Reported on | |
| 82 | +| ----------------------------------------------- | -------------------------- | |
| 83 | +| A `start` marker with no matching `end` | the `start` line | |
| 84 | +| An `end` marker with no preceding `start` | the `end` line | |
| 85 | +| A second `start` before the first region closes | the duplicate `start` line | |
| 86 | + |
| 87 | +## Non-goals |
| 88 | + |
| 89 | +- **Regenerating the region.** mdsmith treats it as opaque; the owning |
| 90 | + tool regenerates it. |
| 91 | +- **Resolving merge conflicts inside it.** The |
| 92 | + [merge driver](cli/merge-driver.md) stays scoped to mdsmith's own |
| 93 | + directive blocks. |
| 94 | +- **Auto-detecting markers.** Regions are declared in config, never |
| 95 | + inferred. |
| 96 | + |
| 97 | +[apm]: ../research/apm-mdsmith/apm-model.md |
| 98 | +[gensection]: ../background/concepts/generated-section.md |
0 commit comments