Skip to content

Commit 3d55f02

Browse files
committed
docs: add foreign-regions reference and mark plan complete
Document the foreign-regions: config key, its override scoping, the opacity contract, and the MDS073 malformed-region diagnostic. Regenerate the CLAUDE.md, reference-index, AGENTS.md, and copilot-instructions catalogs/includes, and mark plan 2607082049 done. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EwKxDxhjkTQPPkBrNhsrNG
1 parent 754bb11 commit 3d55f02

7 files changed

Lines changed: 112 additions & 10 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ row: "- [{summary}](../{filename})"
141141
- [Print the mdsmith build version and exit.](../docs/reference/cli/version.md)
142142
- [Each file under `.mdsmith/conventions/` declares one user convention. The basename is the convention name; the file body carries a `flavor:` plus a `rules:` map. Sits alongside inline `conventions.<name>:` in `.mdsmith.yml`.](../docs/reference/convention-files.md)
143143
- [Built-in Markdown conventions, the rule presets each one applies, and how user config layers on top via deep-merge.](../docs/reference/conventions.md)
144+
- [The top-level `foreign-regions:` config lists `{start, end}` marker pairs whose spanned bytes mdsmith treats as opaque — style rules skip diagnostics inside a matched pair and fixers never rewrite it, while whole-file rules still count the bytes. Glob-scopable via `overrides:`; a start with no matching end reports MDS073.](../docs/reference/foreign-regions.md)
144145
- [Glob pattern syntax across mdsmith config, directives, and CLI argument expansion, with the supported exclusion semantics for each surface.](../docs/reference/globs.md)
145146
- [Look up exact CLI commands, config glob and schema syntax, the built-in conventions, and the section-schema grammar.](../docs/reference/index.md)
146147
- [Each file under `.mdsmith/kinds/` declares one kind. The basename is the kind name; the file body carries the full `KindBody` — schema, rules, `path-pattern:`, `extends:`. Sits alongside inline `kinds.<name>:` in `.mdsmith.yml`.](../docs/reference/kind-files.md)

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ row: "- [{summary}]({filename})"
147147
- [Print the mdsmith build version and exit.](docs/reference/cli/version.md)
148148
- [Each file under `.mdsmith/conventions/` declares one user convention. The basename is the convention name; the file body carries a `flavor:` plus a `rules:` map. Sits alongside inline `conventions.<name>:` in `.mdsmith.yml`.](docs/reference/convention-files.md)
149149
- [Built-in Markdown conventions, the rule presets each one applies, and how user config layers on top via deep-merge.](docs/reference/conventions.md)
150+
- [The top-level `foreign-regions:` config lists `{start, end}` marker pairs whose spanned bytes mdsmith treats as opaque — style rules skip diagnostics inside a matched pair and fixers never rewrite it, while whole-file rules still count the bytes. Glob-scopable via `overrides:`; a start with no matching end reports MDS073.](docs/reference/foreign-regions.md)
150151
- [Glob pattern syntax across mdsmith config, directives, and CLI argument expansion, with the supported exclusion semantics for each surface.](docs/reference/globs.md)
151152
- [Look up exact CLI commands, config glob and schema syntax, the built-in conventions, and the section-schema grammar.](docs/reference/index.md)
152153
- [Each file under `.mdsmith/kinds/` declares one kind. The basename is the kind name; the file body carries the full `KindBody` — schema, rules, `path-pattern:`, `extends:`. Sits alongside inline `kinds.<name>:` in `.mdsmith.yml`.](docs/reference/kind-files.md)

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ row: "- [{summary}]({filename})"
133133
- [Print the mdsmith build version and exit.](docs/reference/cli/version.md)
134134
- [Each file under `.mdsmith/conventions/` declares one user convention. The basename is the convention name; the file body carries a `flavor:` plus a `rules:` map. Sits alongside inline `conventions.<name>:` in `.mdsmith.yml`.](docs/reference/convention-files.md)
135135
- [Built-in Markdown conventions, the rule presets each one applies, and how user config layers on top via deep-merge.](docs/reference/conventions.md)
136+
- [The top-level `foreign-regions:` config lists `{start, end}` marker pairs whose spanned bytes mdsmith treats as opaque — style rules skip diagnostics inside a matched pair and fixers never rewrite it, while whole-file rules still count the bytes. Glob-scopable via `overrides:`; a start with no matching end reports MDS073.](docs/reference/foreign-regions.md)
136137
- [Glob pattern syntax across mdsmith config, directives, and CLI argument expansion, with the supported exclusion semantics for each surface.](docs/reference/globs.md)
137138
- [Look up exact CLI commands, config glob and schema syntax, the built-in conventions, and the section-schema grammar.](docs/reference/index.md)
138139
- [Each file under `.mdsmith/kinds/` declares one kind. The basename is the kind name; the file body carries the full `KindBody` — schema, rules, `path-pattern:`, `extends:`. Sits alongside inline `kinds.<name>:` in `.mdsmith.yml`.](docs/reference/kind-files.md)

PLAN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ footer: |
247247
| 2607051920 || sonnet | [Consolidate duplicated leading-space/blank-line rule helpers into internal/rules/astutil](plan/2607051920_arch-fix-rule-whitespace-helpers-astutil.md) |
248248
| 2607071642 || sonnet | [Single-file metric extraction via `mdsmith metrics get` (readability first)](plan/2607071642_extractable-file-metrics.md) |
249249
| 2607082048 || sonnet | [Placeholder token for APM `${input:name}` prompt parameters](plan/2607082048_apm-input-placeholder-token.md) |
250-
| 2607082049 | 🔲 | opus | [Foreign managed-region protection for `mdsmith fix`](plan/2607082049_foreign-managed-regions.md) |
250+
| 2607082049 | | opus | [Foreign managed-region protection for `mdsmith fix`](plan/2607082049_foreign-managed-regions.md) |
251251
| 2607082050 | 🔲 | sonnet | [APM coexistence: `mdsmith init --apm`, guide, and kind pack](plan/2607082050_apm-coexist-guide-and-kind-pack.md) |
252252
| 2607082051 | 🔲 | opus | [Schema extensions: closed frontmatter and filename agreement](plan/2607082051_apm-schema-extensions.md) |
253253
| 2607082052 || sonnet | [SARIF output format for `mdsmith check`](plan/2607082052_check-sarif-output.md) |

docs/reference/foreign-regions.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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

docs/reference/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ row: "- [{summary}]({filename})"
3737
- [Print the mdsmith build version and exit.](cli/version.md)
3838
- [Each file under `.mdsmith/conventions/` declares one user convention. The basename is the convention name; the file body carries a `flavor:` plus a `rules:` map. Sits alongside inline `conventions.<name>:` in `.mdsmith.yml`.](convention-files.md)
3939
- [Built-in Markdown conventions, the rule presets each one applies, and how user config layers on top via deep-merge.](conventions.md)
40+
- [The top-level `foreign-regions:` config lists `{start, end}` marker pairs whose spanned bytes mdsmith treats as opaque — style rules skip diagnostics inside a matched pair and fixers never rewrite it, while whole-file rules still count the bytes. Glob-scopable via `overrides:`; a start with no matching end reports MDS073.](foreign-regions.md)
4041
- [Glob pattern syntax across mdsmith config, directives, and CLI argument expansion, with the supported exclusion semantics for each surface.](globs.md)
4142
- [Each file under `.mdsmith/kinds/` declares one kind. The basename is the kind name; the file body carries the full `KindBody` — schema, rules, `path-pattern:`, `extends:`. Sits alongside inline `kinds.<name>:` in `.mdsmith.yml`.](kind-files.md)
4243
- [Every markdownlint rule and the mdsmith rule that covers it, generated from the rule README front matter — the same data `mdsmith init --from-markdownlint` reads.](markdownlint-mapping.md)

plan/2607082049_foreign-managed-regions.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
id: 2607082049
33
title: "Foreign managed-region protection for `mdsmith fix`"
4-
status: "🔳"
4+
status: ""
55
model: opus
66
summary: >-
77
Add a `foreign-regions:` config listing `{start, end}` marker
@@ -87,20 +87,20 @@ metrics still count those bytes.
8787

8888
## Acceptance Criteria
8989

90-
- [ ] `mdsmith fix` leaves bytes between a declared
90+
- [x] `mdsmith fix` leaves bytes between a declared
9191
`{start, end}` pair unchanged, including
9292
otherwise-fixable trailing spaces and table
9393
misalignment.
94-
- [ ] A style-rule violation inside the region emits
94+
- [x] A style-rule violation inside the region emits
9595
no diagnostic; the same violation outside it
9696
still does.
97-
- [ ] MDS022 and MDS028 still count the region's
97+
- [x] MDS022 and MDS028 still count the region's
9898
bytes toward file length and token budget.
99-
- [ ] A start marker with no matching end marker
99+
- [x] A start marker with no matching end marker
100100
produces a diagnostic.
101-
- [ ] The region config is glob-scopable via
101+
- [x] The region config is glob-scopable via
102102
`overrides:`.
103-
- [ ] All tests pass: `go test ./...`
104-
- [ ] `go tool -modfile=tools/go.mod golangci-lint
103+
- [x] All tests pass: `go test ./...`
104+
- [x] `go tool -modfile=tools/go.mod golangci-lint
105105
run` reports no issues.
106-
- [ ] `mdsmith check .` — 0 failures.
106+
- [x] `mdsmith check .` — 0 failures.

0 commit comments

Comments
 (0)