@kensnzk/koyu 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.ja.md +4 -2
  2. package/README.md +5 -3
  3. package/dist/cli.js +156 -81
  4. package/dist/cli.js.map +1 -1
  5. package/dist/core/derive.d.ts +259 -0
  6. package/dist/core/derive.d.ts.map +1 -0
  7. package/dist/core/derive.js +570 -0
  8. package/dist/core/derive.js.map +1 -0
  9. package/dist/{check.d.ts → core/diagnose.d.ts} +11 -12
  10. package/dist/core/diagnose.d.ts.map +1 -0
  11. package/dist/{check.js → core/diagnose.js} +232 -221
  12. package/dist/core/diagnose.js.map +1 -0
  13. package/dist/core/diff.d.ts.map +1 -0
  14. package/dist/{diff.js → core/diff.js} +84 -41
  15. package/dist/core/diff.js.map +1 -0
  16. package/dist/{fabric.d.ts → core/fabric.d.ts} +4 -0
  17. package/dist/core/fabric.d.ts.map +1 -0
  18. package/dist/{fabric.js → core/fabric.js} +4 -3
  19. package/dist/core/fabric.js.map +1 -0
  20. package/dist/{graph.d.ts → core/graph.d.ts} +1 -3
  21. package/dist/core/graph.d.ts.map +1 -0
  22. package/dist/{graph.js → core/graph.js} +43 -51
  23. package/dist/core/graph.js.map +1 -0
  24. package/dist/core/light.d.ts +24 -0
  25. package/dist/core/light.d.ts.map +1 -0
  26. package/dist/{light.js → core/light.js} +15 -10
  27. package/dist/core/light.js.map +1 -0
  28. package/dist/{model.d.ts → core/model.d.ts} +124 -13
  29. package/dist/core/model.d.ts.map +1 -0
  30. package/dist/{model.js → core/model.js} +193 -50
  31. package/dist/core/model.js.map +1 -0
  32. package/dist/core/parse.d.ts.map +1 -0
  33. package/dist/{parse.js → core/parse.js} +528 -116
  34. package/dist/core/parse.js.map +1 -0
  35. package/dist/{poly.d.ts → core/poly.d.ts} +3 -2
  36. package/dist/core/poly.d.ts.map +1 -0
  37. package/dist/{poly.js → core/poly.js} +8 -9
  38. package/dist/core/poly.js.map +1 -0
  39. package/dist/core/site.d.ts.map +1 -0
  40. package/dist/core/site.js.map +1 -0
  41. package/dist/core/tolerance.d.ts +26 -0
  42. package/dist/core/tolerance.d.ts.map +1 -0
  43. package/dist/core/tolerance.js +48 -0
  44. package/dist/core/tolerance.js.map +1 -0
  45. package/dist/{vertical.d.ts → core/vertical.d.ts} +41 -12
  46. package/dist/core/vertical.d.ts.map +1 -0
  47. package/dist/{vertical.js → core/vertical.js} +45 -104
  48. package/dist/core/vertical.js.map +1 -0
  49. package/dist/core/vocabulary.d.ts +40 -0
  50. package/dist/core/vocabulary.d.ts.map +1 -0
  51. package/dist/core/vocabulary.js +164 -0
  52. package/dist/core/vocabulary.js.map +1 -0
  53. package/dist/{axo.d.ts → draw/axo.d.ts} +1 -1
  54. package/dist/draw/axo.d.ts.map +1 -0
  55. package/dist/{axo.js → draw/axo.js} +53 -81
  56. package/dist/draw/axo.js.map +1 -0
  57. package/dist/draw/index.d.ts +3 -0
  58. package/dist/draw/index.d.ts.map +1 -0
  59. package/dist/draw/index.js +11 -0
  60. package/dist/draw/index.js.map +1 -0
  61. package/dist/draw/plan.d.ts +10 -0
  62. package/dist/draw/plan.d.ts.map +1 -0
  63. package/dist/draw/plan.js +284 -0
  64. package/dist/draw/plan.js.map +1 -0
  65. package/dist/index.d.ts +15 -11
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +49 -12
  68. package/dist/index.js.map +1 -1
  69. package/dist/mcp.js +71 -40
  70. package/dist/mcp.js.map +1 -1
  71. package/dist/parse-file.d.ts +1 -1
  72. package/dist/parse-file.d.ts.map +1 -1
  73. package/dist/parse-file.js +1 -1
  74. package/dist/parse-file.js.map +1 -1
  75. package/dist/validate/access.d.ts +6 -0
  76. package/dist/validate/access.d.ts.map +1 -0
  77. package/dist/validate/access.js +238 -0
  78. package/dist/validate/access.js.map +1 -0
  79. package/dist/validate/envelope.d.ts +4 -0
  80. package/dist/validate/envelope.d.ts.map +1 -0
  81. package/dist/validate/envelope.js +55 -0
  82. package/dist/validate/envelope.js.map +1 -0
  83. package/dist/validate/index.d.ts +60 -0
  84. package/dist/validate/index.d.ts.map +1 -0
  85. package/dist/validate/index.js +77 -0
  86. package/dist/validate/index.js.map +1 -0
  87. package/dist/validate/light.d.ts +6 -0
  88. package/dist/validate/light.d.ts.map +1 -0
  89. package/dist/validate/light.js +28 -0
  90. package/dist/validate/light.js.map +1 -0
  91. package/dist/validate/runs.d.ts +16 -0
  92. package/dist/validate/runs.d.ts.map +1 -0
  93. package/dist/validate/runs.js +60 -0
  94. package/dist/validate/runs.js.map +1 -0
  95. package/dist/validate/site.d.ts +6 -0
  96. package/dist/validate/site.d.ts.map +1 -0
  97. package/dist/validate/site.js +63 -0
  98. package/dist/validate/site.js.map +1 -0
  99. package/editors/vscode/.vscodeignore +2 -0
  100. package/editors/vscode/README.md +28 -0
  101. package/editors/vscode/extension.js +150 -0
  102. package/editors/vscode/language-configuration.json +19 -0
  103. package/editors/vscode/package.json +57 -0
  104. package/editors/vscode/syntaxes/koyu.tmLanguage.json +226 -0
  105. package/examples/basement/main.muro +1 -1
  106. package/examples/complex/main.muro +1 -1
  107. package/examples/house/main.muro +2 -2
  108. package/examples/house.muro +2 -2
  109. package/examples/mansion.muro +2 -2
  110. package/examples/office.muro +2 -2
  111. package/examples/steps/01-one-room.muro +1 -1
  112. package/examples/steps/02-two-rooms.muro +1 -1
  113. package/examples/steps/03-door.muro +1 -1
  114. package/examples/steps/04-exterior.muro +1 -1
  115. package/examples/steps/05-two-storeys.muro +1 -1
  116. package/examples/steps/06-finished.muro +2 -2
  117. package/examples/tower/main.muro +1 -1
  118. package/examples/twin/L1.muro +136 -119
  119. package/examples/twin/L5.muro +85 -123
  120. package/examples/twin/assets.muro +10 -8
  121. package/examples/twin/basement.muro +43 -34
  122. package/examples/twin/core.muro +148 -65
  123. package/examples/twin/hotel.muro +66 -107
  124. package/examples/twin/main.muro +73 -67
  125. package/examples/twin/office.muro +87 -88
  126. package/examples/twin/podium.muro +309 -97
  127. package/examples/twin/residence.muro +61 -116
  128. package/examples/twin/site.muro +16 -13
  129. package/examples/two-rooms.canonical.json +4 -2
  130. package/examples/two-rooms.muro +2 -2
  131. package/package.json +16 -1
  132. package/spec/README.md +28 -0
  133. package/spec/canonical-json.md +98 -0
  134. package/spec/composition.md +121 -0
  135. package/spec/derivation.md +393 -0
  136. package/spec/en/README.md +30 -0
  137. package/spec/en/canonical-json.md +101 -0
  138. package/spec/en/composition.md +121 -0
  139. package/spec/en/derivation.md +393 -0
  140. package/spec/en/language.md +164 -0
  141. package/spec/en/notation-v0.md +145 -0
  142. package/spec/en/scope.md +229 -0
  143. package/spec/en/semantics.md +132 -0
  144. package/spec/en/tools.md +108 -0
  145. package/spec/en/validation.md +79 -0
  146. package/spec/en/vocabulary.md +103 -0
  147. package/spec/language.md +163 -0
  148. package/spec/notation-v0.md +184 -0
  149. package/spec/scope.md +229 -0
  150. package/spec/semantics.md +130 -0
  151. package/spec/tools.md +106 -0
  152. package/spec/validation.md +79 -0
  153. package/spec/vocabulary.md +114 -0
  154. package/src/cli.ts +165 -80
  155. package/src/core/derive.ts +852 -0
  156. package/src/{check.ts → core/diagnose.ts} +260 -229
  157. package/src/{diff.ts → core/diff.ts} +84 -40
  158. package/src/{fabric.ts → core/fabric.ts} +4 -3
  159. package/src/{graph.ts → core/graph.ts} +47 -60
  160. package/src/core/light.ts +69 -0
  161. package/src/{model.ts → core/model.ts} +236 -52
  162. package/src/{parse.ts → core/parse.ts} +584 -116
  163. package/src/{poly.ts → core/poly.ts} +8 -9
  164. package/src/core/tolerance.ts +55 -0
  165. package/src/{vertical.ts → core/vertical.ts} +65 -115
  166. package/src/core/vocabulary.ts +197 -0
  167. package/src/{axo.ts → draw/axo.ts} +51 -94
  168. package/src/draw/index.ts +11 -0
  169. package/src/draw/plan.ts +344 -0
  170. package/src/index.ts +181 -35
  171. package/src/mcp.ts +76 -40
  172. package/src/parse-file.ts +2 -2
  173. package/src/validate/access.ts +279 -0
  174. package/src/validate/envelope.ts +59 -0
  175. package/src/validate/index.ts +107 -0
  176. package/src/validate/light.ts +43 -0
  177. package/src/validate/runs.ts +87 -0
  178. package/src/validate/site.ts +84 -0
  179. package/dist/axo.d.ts.map +0 -1
  180. package/dist/axo.js.map +0 -1
  181. package/dist/check.d.ts.map +0 -1
  182. package/dist/check.js.map +0 -1
  183. package/dist/diff.d.ts.map +0 -1
  184. package/dist/diff.js.map +0 -1
  185. package/dist/fabric.d.ts.map +0 -1
  186. package/dist/fabric.js.map +0 -1
  187. package/dist/graph.d.ts.map +0 -1
  188. package/dist/graph.js.map +0 -1
  189. package/dist/light.d.ts +0 -15
  190. package/dist/light.d.ts.map +0 -1
  191. package/dist/light.js.map +0 -1
  192. package/dist/model.d.ts.map +0 -1
  193. package/dist/model.js.map +0 -1
  194. package/dist/parse.d.ts.map +0 -1
  195. package/dist/parse.js.map +0 -1
  196. package/dist/plan.d.ts +0 -10
  197. package/dist/plan.d.ts.map +0 -1
  198. package/dist/plan.js +0 -354
  199. package/dist/plan.js.map +0 -1
  200. package/dist/poly.d.ts.map +0 -1
  201. package/dist/poly.js.map +0 -1
  202. package/dist/site.d.ts.map +0 -1
  203. package/dist/site.js.map +0 -1
  204. package/dist/vertical.d.ts.map +0 -1
  205. package/dist/vertical.js.map +0 -1
  206. package/src/light.ts +0 -63
  207. package/src/plan.ts +0 -472
  208. /package/dist/{diff.d.ts → core/diff.d.ts} +0 -0
  209. /package/dist/{parse.d.ts → core/parse.d.ts} +0 -0
  210. /package/dist/{site.d.ts → core/site.d.ts} +0 -0
  211. /package/dist/{site.js → core/site.js} +0 -0
  212. /package/src/{site.ts → core/site.ts} +0 -0
@@ -5,7 +5,7 @@
5
5
  // 吹抜け (type:void) はこの不変量の宣言的な免除である。
6
6
  //
7
7
  // 診断契約 (ADR-0016): 一次形式は checkDiagnostics の Diagnostic[] — code / severity /
8
- // 日本語本文 / 出所 / 対象パス。check は互換層で、従来の文字列 (位置接頭辞つき) を組み立てる。
8
+ // 本文 / 出所 / 対象パス。check は互換層で、従来の文字列 (位置接頭辞つき) を組み立てる。
9
9
  // severity はコードの不変属性 — 重さを変えたくなったら新コードを切る。
10
10
 
11
11
  import {
@@ -13,23 +13,21 @@ import {
13
13
  placeOpening,
14
14
  planOverlap,
15
15
  segmentsFor,
16
- segmentLength,
17
- envelopeGaps,
18
16
  drawnCut,
19
17
  spacesOverlap,
20
18
  } from "./graph.js";
21
- import { heff, isSemiOutdoor, levelsSorted, type Attrs, type Boundary, type Edge, type Level, type Model, type Pt, type Rect, type Space,
19
+ import { heff, isSemiOutdoor, levelsSorted, SUPPORTED_LANGUAGE_VERSIONS, type Attrs, type Boundary, type Edge, type Level, type Model, type Pt, type Rect, type Space,
22
20
  columnSites,
21
+ openingIdentity,
22
+ regionOf,
23
23
  columnsFor,
24
24
  pointInPolygon,
25
25
  rectToPoly,
26
- regionOf,
27
26
  srcRef,
28
- polygonAreaM2,
29
27
  polygonSelfIntersection,
30
- shapeEscapesPolygon,
31
28
  } from "./model.js";
32
29
  import { cutsInWindow } from "./poly.js";
30
+ import { ASSET_ELEM, attrSpec, isNamespaced } from "./vocabulary.js";
33
31
  import { runDecls, runIssues } from "./vertical.js";
34
32
 
35
33
  export interface CheckResult {
@@ -42,7 +40,7 @@ export interface Diagnostic {
42
40
  /** 台帳 DIAGNOSTIC_CODES のコード (領域2-3字 + 2桁連番) */
43
41
  code: DiagnosticCode;
44
42
  severity: "error" | "warning";
45
- /** 日本語の本文 (位置接頭辞なし) */
43
+ /** 本文 (位置接頭辞なし) */
46
44
  message: string;
47
45
  /** 出所の行 (位置を持たない診断は省略) */
48
46
  line?: number;
@@ -57,6 +55,8 @@ export interface Diagnostic {
57
55
  /**
58
56
  * 診断コードの台帳 — 全コードと規範severity。specの表 (semantics.md §5) とテストで一致を守る。
59
57
  * BND07 は欠番 — 「接しているのに境界が無い」警告はADR-0014 (既定境界) で廃止された。
58
+ * HGT03・HGT04・HGT05・RUN04 も欠番 — この四つは「高さがどうか」「縦動線がどうか」ではなく
59
+ * 「形を作るのに必要な情報が書かれていない」という一つの話であり、SUF01-04 へ合流した (ADR-0034)。
60
60
  * SYN01 は構文・合成エラー (SourceError) の写し — checkは例外を診断にしない。CLIの check --json だけが写す。
61
61
  */
62
62
  export const DIAGNOSTIC_CODES = {
@@ -96,37 +96,34 @@ export const DIAGNOSTIC_CODES = {
96
96
  ZON02: "warning", // ゾーンと同パスの空間
97
97
  HGT01: "error", // 上階への食い込み (高さ不変量違反)
98
98
  HGT02: "error", // 部分吹抜けの被覆不足
99
- HGT03: "warning", // 上階slab未宣言で高さ検査ができない
100
- HGT04: "warning", // 天井高不明で高さ検査ができない
101
- HGT05: "warning", // レベルが特定できない領域つき空間
99
+ SUF01: "error", // 天井高が決まらず、天井も屋根も生成できない (ADR-0034)
100
+ SUF02: "error", // レベルが特定できず、立体が一つも生成できない
101
+ SUF03: "warning", // レベルに slab が無く、床が一枚も生成されない
102
+ SUF04: "warning", // 縦動線の宣言に対して形が一つも生成されない
102
103
  SIT01: "error", // 敷地形状の重複頂点
103
104
  SIT02: "error", // 敷地形状の自己交差
104
- SIT03: "error", // 建物の敷地形状からのはみ出し
105
105
  SIT04: "warning", // 対応するゾーンの無いpolygon
106
- SIT05: "warning", // 敷地面積の宣言と導出の食い違い
107
106
  UID01: "error", // 数字だけのuid (ADR-0015)
108
107
  UID02: "error", // 空白を含むuid
109
108
  UID03: "error", // uidの重複
109
+ UID04: "error", // 含む対象の中で name が重複 (開口・seg・area・柱の同一性 — ADR-0039)
110
110
  ATT01: "error", // 解釈される属性の値が数値でない (ADR-0028)
111
111
  ATT02: "error", // 解釈される属性の値が台帳の語彙にない (ADR-0028)
112
+ ATT03: "error", // 台帳に無い属性キー — 名前空間が無い (ADR-0033)
112
113
  DAY01: "error", // daylightの値が 0/1 以外 (ADR-0020)
113
114
  RUN01: "error", // 一つの空間に縦動線の宣言が複数 (ADR-0021)
114
115
  RUN02: "error", // 縦動線の値が上る向き (N/E/S/W) でない
115
116
  RUN03: "error", // 縦動線の領域が矩形一つでない / レベルが不明
116
- RUN04: "warning", // 上にレベルが無く縦動線の形が生成できない
117
117
  RUN05: "error", // form の値が不正、または形が決まらない
118
- RUN06: "warning", // 導出された段の寸法が窮屈 (書かないが検査する)
119
- RUN07: "warning", // 導出された勾配が宣言・常用域から外れる
120
- RUN08: "warning", // 縦動線の形はあるが上下を繋ぐ垂直境界が無い
121
118
  LIN01: "error", // 描かれた線が二つの空間を分離しない (ADR-0022)
122
119
  LIN02: "error", // 垂直境界に描かれた線
123
120
  LIN03: "warning", // 描かれた線が何も切っていない
124
- ENV01: "warning", // 外皮に穴 — 何にも面していない外周 (ADR-0025)
125
121
  COL01: "warning", // 柱の宣言に対して立つ柱が0本 (ADR-0023)
126
122
  COL02: "warning", // 同じ通りの交点に複数の柱宣言が重なる (先の宣言が勝つ)
127
123
  VER01: "error", // koyu 0.1 での既定境界の導出 (ADR-0017)
128
124
  VER02: "error", // koyu 0.3以前で採光の推定対象だった型に daylight が無い (ADR-0020)
129
125
  VER03: "error", // koyu 0.4以前のファイルに0.5の語 (縦動線・線・柱・地下)
126
+ VER04: "error", // koyu 0.5以前のファイルに1.0の語 (over・drop・集合編集 — ADR-0035/0038)
130
127
  SYN01: "error", // 構文・合成エラー (SourceError の写し — check --json のみ)
131
128
  } as const satisfies Record<string, "error" | "warning">;
132
129
 
@@ -145,59 +142,61 @@ const VERTICAL = new Set(["stair", "shaft", "void"]);
145
142
  /** 0.3以前が採光の対象と推定していた型 (ADR-0020で廃止)。旧版の受理条件の判定にだけ使う — 意味論には効かない */
146
143
  const LEGACY_DAYLIT = new Set(["unit", "room", "ldk", "bedroom", "living"]);
147
144
 
148
- /** 互換層 — 従来の文字列形式。位置を持つ診断は「file:N行目: 本文」に組み立てる */
149
145
  /**
150
- * 解釈される属性の値の台帳 (ADR-0028)。**spec/vocabulary.md の★が契約であり、これはその写しである。**
151
- *
152
- * `of` があれば列挙、無ければ正の数値。ここに無い属性は自由に書けてそのまま運ばれる
153
- * (台帳の規則3)。daylight は DAY01 が、form は RUN05 が、縦動線の向きは RUN02 が
154
- * 既に守っているので重ねない。
146
+ * 版の新旧は `SUPPORTED_LANGUAGE_VERSIONS` の並びで決まる。**辞書順で比べてはならない** —
147
+ * 文字列としては "0.5" > "1.0" であり、比較を綴りに任せると新しい版が古い版と判定される
155
148
  */
156
- const ATTR_RULES: Record<string, Record<string, { of?: Array<string | number> }>> = {
157
- space: {
158
- h: {},
159
- ceiling: { of: [0, 1] },
160
- turn: { of: ["R", "L"] },
161
- riser: {},
162
- tread: {},
163
- entry: {},
164
- landing: {},
165
- lane: {},
166
- slope: {},
167
- road: {},
168
- },
169
- zone: { site: { of: [0, 1] }, area: {} },
170
- // air:1 の境界の天端高 (手すり・腰壁) — 立体が読むので台帳に載る (ADR-0028)
171
- boundary: { h: {} },
172
- opening: { style: { of: ["hinged", "sliding", "auto"] } },
173
- };
149
+ const olderThan = (version: string, ref: string): boolean =>
150
+ SUPPORTED_LANGUAGE_VERSIONS.indexOf(version) < SUPPORTED_LANGUAGE_VERSIONS.indexOf(ref);
174
151
 
152
+ /** 互換層 — 従来の文字列形式。位置を持つ診断は「file:N行目: 本文」に組み立てる */
175
153
  interface AttrSubject {
176
- rules: Record<string, { of?: Array<string | number> }>;
154
+ /** 台帳を引く要素名 */
155
+ elem: string;
177
156
  of: Attrs;
178
157
  }
179
158
 
180
- /** 値を検査すべき宣言を、出所つきで数え上げる — 母集団は**書かれた宣言**である */
159
+ /**
160
+ * 属性を検査すべき宣言を、出所つきで数え上げる — 母集団は**書かれた宣言**である。
161
+ * 走査は宣言の順 (空間 → ゾーン → 境界 → その開口・seg → 空間の area → 柱)。
162
+ */
181
163
  function attrSubjects(
182
164
  model: Model,
183
165
  ): Array<[string, AttrSubject, { line?: number; file?: string; path?: string[] }]> {
184
166
  const out: Array<[string, AttrSubject, { line?: number; file?: string; path?: string[] }]> = [];
185
167
  for (const s of model.spaces.values()) {
186
- out.push([s.path, { rules: ATTR_RULES["space"]!, of: s.attrs }, { line: s.line, file: s.file, path: [s.path] }]);
168
+ const at = { line: s.line, file: s.file, path: [s.path] };
169
+ out.push([s.path, { elem: "space", of: s.attrs }, at]);
170
+ for (const a of s.areas) {
171
+ out.push([`area (${s.path})`, { elem: "area", of: a.attrs }, { line: a.line, file: s.file, path: [s.path] }]);
172
+ }
187
173
  }
188
174
  for (const z of model.zones.values()) {
189
- out.push([`ゾーン ${z.path}`, { rules: ATTR_RULES["zone"]!, of: z.attrs }, { line: z.line, file: z.file, path: [z.path] }]);
175
+ out.push([`zone ${z.path}`, { elem: "zone", of: z.attrs }, { line: z.line, file: z.file, path: [z.path] }]);
190
176
  }
191
177
  for (const b of model.boundaries) {
192
178
  const at = { line: b.line, file: b.file, path: [b.a, b.b] };
193
- out.push([`境界 ${b.a} | ${b.b}`, { rules: ATTR_RULES["boundary"]!, of: b.attrs }, at]);
179
+ out.push([`boundary ${b.a} | ${b.b}`, { elem: "boundary", of: b.attrs }, at]);
194
180
  for (const o of b.openings) {
195
181
  out.push([
196
182
  `${o.kind} (${b.a} | ${b.b})`,
197
- { rules: ATTR_RULES["opening"]!, of: o.attrs },
183
+ { elem: "opening", of: o.attrs },
198
184
  { line: o.line, file: b.file, path: [b.a, b.b] },
199
185
  ]);
200
186
  }
187
+ for (const g of b.segs) {
188
+ out.push([
189
+ `seg (${b.a} | ${b.b})`,
190
+ { elem: "seg", of: g.attrs },
191
+ { line: g.line, file: b.file, path: [b.a, b.b] },
192
+ ]);
193
+ }
194
+ }
195
+ for (const a of model.assets.values()) {
196
+ out.push([`asset ${a.name}`, { elem: ASSET_ELEM, of: a.attrs }, { line: a.line, file: a.file }]);
197
+ }
198
+ for (const c of model.columns) {
199
+ out.push([`column ${c.size}mm`, { elem: "column", of: c.attrs }, { line: c.line, file: c.file }]);
201
200
  }
202
201
  return out;
203
202
  }
@@ -295,7 +294,6 @@ export function checkDiagnostics(model: Model): Diagnostic[] {
295
294
  checkAttrValues(ctx);
296
295
  checkRuns(ctx);
297
296
  checkDrawnLines(ctx);
298
- checkEnvelopeGaps(ctx);
299
297
  checkColumns(ctx);
300
298
  checkLanguageVersion(ctx);
301
299
  checkUids(ctx);
@@ -303,7 +301,8 @@ export function checkDiagnostics(model: Model): Diagnostic[] {
303
301
  checkAreas(ctx);
304
302
  checkZones(ctx);
305
303
  checkHeights(ctx);
306
- checkOrphanSpaces(ctx);
304
+ checkSpaceSufficiency(ctx);
305
+ checkLevelSufficiency(ctx);
307
306
  checkSite(ctx);
308
307
  return diags;
309
308
  }
@@ -331,11 +330,11 @@ function checkBoundaryRefs(ctx: Ctx): void {
331
330
  for (const b of model.boundaries) {
332
331
  for (const p of [b.a, b.b]) {
333
332
  if (!model.spaces.has(p)) {
334
- emit("REF01", `未定義の空間を参照しています: ${p}`, { line: b.line, file: b.file, path: [b.a, b.b] });
333
+ emit("REF01", `References an undefined space: ${p}`, { line: b.line, file: b.file, path: [b.a, b.b] });
335
334
  }
336
335
  }
337
336
  if (b.a === b.b) {
338
- emit("BND01", `同じ空間同士の境界は書けません: ${b.a}`, { line: b.line, file: b.file, path: [b.a, b.b] });
337
+ emit("BND01", `A boundary between a space and itself cannot be written: ${b.a}`, { line: b.line, file: b.file, path: [b.a, b.b] });
339
338
  }
340
339
  }
341
340
  }
@@ -356,7 +355,7 @@ function checkBoundaryIdentity(ctx: Ctx): void {
356
355
  if (prev) {
357
356
  emit(
358
357
  "BND02",
359
- `境界が重複しています: ${pair}${b.edge ? ` edge:${b.edge}` : ""} (既出: ${srcRef(prev.line, prev.file)})`,
358
+ `Duplicate boundary: ${pair}${b.edge ? ` edge:${b.edge}` : ""} (first seen at ${srcRef(prev.line, prev.file)})`,
360
359
  { line: b.line, file: b.file, path: [b.a, b.b], related: [loc(prev.line, prev.file)] },
361
360
  );
362
361
  } else {
@@ -375,7 +374,7 @@ function checkBoundaryIdentity(ctx: Ctx): void {
375
374
  // 「どこかで併存している」だけでは直す場所が無い
376
375
  const members = model.boundaries.filter((b) => !b.drawn && [b.a, b.b].sort().join(" | ") === pair);
377
376
  const first = members.find((b) => !b.edge) ?? members[0];
378
- emit("BND05", `同じ空間対に edge 限定つきと無しの境界が併存しています (線分が重なります): ${pair}`, {
377
+ emit("BND05", `The same pair of spaces carries both an edge-restricted and an unrestricted boundary (the segments overlap): ${pair}`, {
379
378
  ...(first ? { line: first.line, file: first.file } : {}),
380
379
  path: pair.split(" | "),
381
380
  related: members.filter((b) => b !== first).map((b) => loc(b.line, b.file)),
@@ -390,7 +389,7 @@ function checkLevelDepth(ctx: Ctx): void {
390
389
  // レベルの重複
391
390
  for (let i = 1; i < levels.length; i++) {
392
391
  if (Math.abs(levels[i]!.z - levels[i - 1]!.z) < EPS) {
393
- emit("LVL01", `レベル ${levels[i - 1]!.name} と ${levels[i]!.name} のzが同じです`, {
392
+ emit("LVL01", `Levels ${levels[i - 1]!.name} and ${levels[i]!.name} have the same z`, {
394
393
  line: levels[i]!.line,
395
394
  file: levels[i]!.file,
396
395
  related: [loc(levels[i - 1]!.line, levels[i - 1]!.file)],
@@ -408,7 +407,7 @@ function checkSelfOverlap(ctx: Ctx): void {
408
407
  for (let j = i + 1; j < s.rects.length; j++) {
409
408
  if (planOverlap(s.rects[i]!, s.rects[j]!)) {
410
409
  // どの組かを言わなければ、三つ重なる空間にバイト同一の診断が三件並ぶ
411
- emit("GEO01", `${s.path} の領域同士が重なっています: ${gridRefText(s, i)} と ${gridRefText(s, j)}`, {
410
+ emit("GEO01", `Regions within ${s.path} overlap: ${gridRefText(s, i)} and ${gridRefText(s, j)}`, {
412
411
  line: s.line,
413
412
  file: s.file,
414
413
  path: [s.path],
@@ -429,7 +428,7 @@ function checkSpaceOverlap(ctx: Ctx): void {
429
428
  const b = withRect[j]!;
430
429
  if (a.level !== b.level) continue;
431
430
  if (spacesOverlap(a, b)) {
432
- emit("GEO02", `空間の領域が重なっています: ${a.path} と ${b.path}`, {
431
+ emit("GEO02", `Space regions overlap: ${a.path} and ${b.path}`, {
433
432
  line: a.line,
434
433
  file: a.file,
435
434
  path: [a.path, b.path],
@@ -449,7 +448,7 @@ function checkDaylightScope(ctx: Ctx): void {
449
448
  const v = s.attrs["daylight"];
450
449
  if (v === undefined) continue;
451
450
  if (v !== 0 && v !== 1) {
452
- emit("DAY01", `daylight は 1 (採光判定の対象) か 0 (対象外) です: ${s.path} に daylight:${v}`, {
451
+ emit("DAY01", `daylight is either 1 (in scope for the daylight check) or 0 (out of scope): ${s.path} carries daylight:${v}`, {
453
452
  line: s.line,
454
453
  file: s.file,
455
454
  path: [s.path],
@@ -460,30 +459,40 @@ function checkDaylightScope(ctx: Ctx): void {
460
459
 
461
460
  /** 解釈される属性の値 — ATT01 / ATT02 */
462
461
  function checkAttrValues(ctx: Ctx): void {
463
- const { model, emit, loc, withRect, levels, levelIndex } = ctx;
464
- // 解釈される属性の値 (ADR-0028): **書いたのに解釈されなかった値は、黙って既定へ落とさない。**
462
+ const { model, emit } = ctx;
463
+ // 属性の三層 (spec/scope.md §7)。**書いたのに解釈されなかったものを、黙って落とさない。**
464
+ //
465
+ // ADR-0028 は値を守った — `site:yes` は敷地の判定を、`h:35OO` は高さ不変量を、
466
+ // それぞれ丸ごと無音にしていた。だが**キー**は無防備のままだった。
467
+ // `heigh:2400` `sit:1` `stiar:N` は、一字違いで同じことを起こしながら緑で通る。
465
468
  //
466
- // daylight だけが DAY01 で守られていて、他の★属性は素通りだった。帰結は黙殺である —
467
- // `site:yes` は敷地の検査 (SIT03 error) を丸ごと無効にし、`h:35OO` は高さ不変量
468
- // (HGT01 error) を消し、`ceiling:none` は天井を張り、`turn:l` は階段を鏡像にする。
469
- // どれも check は緑のままだった。台帳 (spec/vocabulary.md) が契約である以上、
470
- // 台帳の型に合わない値はエラーである。
471
- for (const [where, attrs, at] of attrSubjects(model)) {
472
- for (const [key, rule] of Object.entries(attrs.rules)) {
473
- const v = attrs.of[key];
474
- if (v === undefined) continue;
475
- if (rule.of) {
476
- if (!rule.of.includes(v as string | number)) {
477
- emit("ATT02", `${where} の ${key} は ${rule.of.join(" / ")} のどれかです: ${key}:${v}`, at);
469
+ // 台帳に無いキーは、名前空間 (`acme.sensor`) を持たなければエラーである (ATT03) —
470
+ // これが「見ていない」と「見て問題がない」を区別できる唯一の形である (ADR-0033)。
471
+ for (const [where, subj, at] of attrSubjects(model)) {
472
+ for (const [key, v] of Object.entries(subj.of)) {
473
+ const spec = attrSpec(subj.elem, key);
474
+ if (!spec) {
475
+ if (isNamespaced(key)) continue; // 運搬層 — core は中身に一切の意味を与えない
476
+ emit(
477
+ "ATT03",
478
+ `${where} carries ${key}:, which is not in the ledger (check the spelling, or add a namespace if the value is only carried — e.g. acme.${key}:${v})`,
479
+ at,
480
+ );
481
+ continue;
482
+ }
483
+ if (spec.tier === "carry") continue; // 運搬層は値を見ない
484
+ if (spec.of) {
485
+ if (!spec.of.includes(v as string | number)) {
486
+ emit("ATT02", `${key} on ${where} is one of ${spec.of.join(" / ")}: ${key}:${v}`, at);
478
487
  }
479
- } else if (typeof v !== "number" || !(v > 0)) {
480
- emit("ATT01", `${where} の ${key} は正の数値で書きます: ${key}:${v}`, at);
488
+ } else if (spec.num && (typeof v !== "number" || !(v > 0))) {
489
+ emit("ATT01", `${key} on ${where} is written as a positive number: ${key}:${v}`, at);
481
490
  }
482
491
  }
483
492
  }
484
493
  }
485
494
 
486
- /** 縦動線 — RUN01〜RUN08 */
495
+ /** 縦動線 — RUN01〜RUN03 / RUN05 / SUF04 (形が一意に決まるか。登りやすさは検証の面) */
487
496
  function checkRuns(ctx: Ctx): void {
488
497
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
489
498
  // 縦動線 (ADR-0021): 宣言の妥当性と、**書かれていない導出値**の妥当性。
@@ -502,84 +511,39 @@ function checkDrawnLines(ctx: Ctx): void {
502
511
  if (!b.drawn) continue;
503
512
  const bAt = { line: b.drawn.line, file: b.file, path: [b.a, b.b] };
504
513
  if (VERTICAL.has(b.kind)) {
505
- emit("LIN02", `垂直境界に線は描けません (線は平面を区切る行為です): ${b.a} | ${b.b}`, bAt);
514
+ emit("LIN02", `A line cannot be drawn on a vertical boundary (drawing a line is an act of dividing a plan): ${b.a} | ${b.b}`, bAt);
506
515
  continue;
507
516
  }
508
517
  const sa = model.spaces.get(b.a);
509
518
  const sb = model.spaces.get(b.b);
510
519
  if (!sa || !sb) continue;
511
520
  if (sa.rects.length === 0 && sb.rects.length === 0) {
512
- emit("LIN01", `領域を持たない空間同士に線は描けません: ${b.a} | ${b.b}`, bAt);
521
+ emit("LIN01", `A line cannot be drawn between spaces that have no region: ${b.a} | ${b.b}`, bAt);
513
522
  continue;
514
523
  }
515
- // 判定と操作を同じ関数に通す (ADR-0027)。窓の中で分離が決まらなければ LIN01、
516
- // 決まるが実際には何も切っていなければ LIN03。以前は判定だけが別の窓 (線分の
517
- // 外接矩形) を使っていたので、軸平行の線では窓が潰れて必ず誤報していた
518
- const cut = drawnCut(sa, sb, b.drawn.a, b.drawn.b);
519
- if (!cut) {
524
+ // **帰結は導出のその場で記録されている** (ADR-0041)。ここで計算し直すと、
525
+ // 既に切られた形を相手に窓を組み立てることになり、母集団が食い違う —
526
+ // 実際に切った線に「何も切っていない」と言う経路がそこにあった
527
+ if (b.drawn.effect === "undetermined") {
520
528
  emit(
521
529
  "LIN01",
522
530
  sa.rects.length > 0 && sb.rects.length > 0
523
- ? `線 ${b.drawn.aRef}..${b.drawn.bRef} は ${b.a} と ${b.b} を分離していません (二つの割付が線の両側に来るように引きます)`
524
- : `線 ${b.drawn.aRef}..${b.drawn.bRef} が割付をちょうど二等分していて、どちらを残すか決まりません`,
531
+ ? `Line ${b.drawn.aRef}..${b.drawn.bRef} does not separate ${b.a} and ${b.b} (draw it so the two allocations fall on opposite sides)`
532
+ : `Line ${b.drawn.aRef}..${b.drawn.bRef} bisects the allocation exactly, so which side to keep is undetermined`,
525
533
  bAt,
526
534
  );
527
535
  continue;
528
536
  }
529
- const target = cut.solo ? [cut.solo] : [sa, sb];
530
- if (!target.some((s) => cutsInWindow(s.rects.map(rectToPoly), cut.window, b.drawn!.a, b.drawn!.b))) {
537
+ if (b.drawn.effect === "nothing") {
531
538
  emit(
532
539
  "LIN03",
533
- `線 ${b.drawn.aRef}..${b.drawn.bRef} は何も切っていません (既定の隣接線と同じか、割付の外にあります)`,
540
+ `Line ${b.drawn.aRef}..${b.drawn.bRef} cuts nothing (it is the same as the default adjacency line, or falls outside the allocation)`,
534
541
  bAt,
535
542
  );
536
543
  }
537
544
  }
538
545
  }
539
546
 
540
- /** 外皮の穴 — ENV01 */
541
- function checkEnvelopeGaps(ctx: Ctx): void {
542
- const { model, emit, loc, withRect, levels, levelIndex } = ctx;
543
- // 外皮の穴 (ADR-0025): 既定境界は領域を持たない空間との間には導かれない (ADR-0014) ので、
544
- // 外部への境界の書き忘れは黙って壁の不在になる。導出された外周のうち、
545
- // 他の空間とも宣言された境界とも向かい合っていない区間を数える。
546
- // 外構のタイル (site:1 ゾーンの配下)・外部・半屋外は囲われていないのが正常なので数えない。
547
- // そして**外皮を書き始めているレベルだけ**を見る — 外部への境界が一本も無い階は
548
- // 外皮をまだ模型にしていないだけであって、穴が開いているのではない。
549
- // 「書き始めたなら閉じきる」という整合の検査であって、完全性の要求ではない
550
- const siteZones = [...model.zones.values()].filter((z) => z.attrs["site"] === 1).map((z) => z.path);
551
- const envelopedLevels = new Set<string>();
552
- for (const b of model.boundaries) {
553
- if (b.derived || VERTICAL.has(b.kind)) continue;
554
- const sa = model.spaces.get(b.a);
555
- const sb = model.spaces.get(b.b);
556
- if (!sa || !sb) continue;
557
- const outer = sa.rects.length === 0 ? sb : sb.rects.length === 0 ? sa : undefined;
558
- if (outer?.level) envelopedLevels.add(outer.level);
559
- }
560
- for (const s of withRect) {
561
- if (!s.level || !envelopedLevels.has(s.level)) continue;
562
- if (s.type === "exterior" || isSemiOutdoor(model, s)) continue;
563
- if (siteZones.some((z) => s.path.startsWith(z + "/"))) continue;
564
- const gaps = envelopeGaps(model, s);
565
- if (gaps.length === 0) continue;
566
- // **どの辺かを言う。**合計長だけでは、edge を書き分けている図面で直す辺が特定できない。
567
- // envelopeGaps は座標つきの線分を返しているので、方角は既に手元にある
568
- const byDir = new Map<string, number>();
569
- for (const g of gaps) {
570
- const d = g.edgeOfA ?? (g.horizontal ? "N/S" : "E/W");
571
- byDir.set(d, (byDir.get(d) ?? 0) + segmentLength(g));
572
- }
573
- const total = gaps.reduce((a, g) => a + segmentLength(g), 0);
574
- const where = [...byDir].map(([d, mm]) => `${d} ${Math.round(mm)}mm`).join(" / ");
575
- emit(
576
- "ENV01",
577
- `外皮に面していない外周があります: ${s.path} — ${where} (合計 ${Math.round(total)}mm・${gaps.length}区間)。外部への境界を書きます`,
578
- { line: s.line, file: s.file, path: [s.path] },
579
- );
580
- }
581
- }
582
-
583
547
  /** 柱 — COL01 / COL02 */
584
548
  function checkColumns(ctx: Ctx): void {
585
549
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
@@ -612,20 +576,20 @@ function checkColumns(ctx: Ctx): void {
612
576
  });
613
577
  emit(
614
578
  "COL02",
615
- `この柱の宣言 (${c.levels.join(",")} ${c.size}角) は同じ交点を先の宣言に取られていて、一本も立ちません (同じ交点では先の宣言が勝ちます)`,
579
+ `This column declaration (${c.levels.join(",")} ${c.size}mm square) stands nowhere because an earlier declaration took the same intersections (at the same intersection the earlier declaration wins)`,
616
580
  { ...at, related: shadow.map((o) => loc(o.line, o.file)) },
617
581
  );
618
582
  } else {
619
583
  emit(
620
584
  "COL01",
621
- `柱の宣言に対して立つ柱がありません (通りの交点に床がありません): ${c.levels.join(",")} ${c.size}角`,
585
+ `Not one column stands for this declaration (the grid intersections have no floor): ${c.levels.join(",")} ${c.size}mm square`,
622
586
  at,
623
587
  );
624
588
  }
625
589
  }
626
590
  }
627
591
 
628
- /** 言語版の受理条件 — VER01〜VER03 */
592
+ /** 言語版の受理条件 — VER01〜VER04 */
629
593
  function checkLanguageVersion(ctx: Ctx): void {
630
594
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
631
595
  // 言語版の受理条件 (ADR-0017): 旧版は意味保存の場合のみ受理する。
@@ -635,7 +599,7 @@ function checkLanguageVersion(ctx: Ctx): void {
635
599
  if (b.derived) {
636
600
  emit(
637
601
  "VER01",
638
- `koyu 0.1 のファイルに境界が宣言されていない接触ペアがあります: ${b.a} | ${b.b} — 0.2では既定の壁が導出され意味が変わります。境界を宣言するか、koyu 0.2 へ上げます`,
602
+ `A koyu 0.1 file has a touching pair with no declared boundary: ${b.a} | ${b.b} — in 0.2 a default wall is derived and the meaning changes. Declare the boundary, or raise the version to koyu 0.2`,
639
603
  { path: [b.a, b.b] },
640
604
  );
641
605
  }
@@ -649,7 +613,7 @@ function checkLanguageVersion(ctx: Ctx): void {
649
613
  if (!LEGACY_DAYLIT.has(s.type) || s.attrs["daylight"] !== undefined) continue;
650
614
  emit(
651
615
  "VER02",
652
- `koyu ${model.version} のファイルに daylight の無い ${s.type} があります: ${s.path} — 0.4では型から採光の対象を推定しないので判定から外れます。daylight:1 (対象) か daylight:0 (対象外) を書いてから koyu 0.4 へ上げます`,
616
+ `A koyu ${model.version} file has a ${s.type} with no daylight: ${s.path} — 0.4 does not infer the daylight scope from the type, so it falls out of the check. Write daylight:1 (in scope) or daylight:0 (out of scope), then raise the version to koyu 0.4`,
653
617
  { line: s.line, file: s.file, path: [s.path] },
654
618
  );
655
619
  }
@@ -657,12 +621,12 @@ function checkLanguageVersion(ctx: Ctx): void {
657
621
 
658
622
  // 0.5 で入った語 (縦動線の宣言・描かれた線・柱・地下) は 0.4 以前の処理系が知らない。
659
623
  // 知らない処理系では黙って形が生成されないので、版を上げずに使うのはエラー (ADR-0017 決定3)
660
- if (model.version !== "0.5") {
661
- const older = `koyu ${model.version} のファイルに 0.5 の語があります`;
624
+ if (olderThan(model.version, "0.5")) {
625
+ const older = `A koyu ${model.version} file uses a 0.5 word`;
662
626
  for (const s of model.spaces.values()) {
663
627
  const d = runDecls(s);
664
628
  if (d.length > 0) {
665
- emit("VER03", `${older}: ${s.path} の ${d[0]!.device}: (縦動線) — koyu 0.5 へ上げます`, {
629
+ emit("VER03", `${older}: ${s.path} carries ${d[0]!.device}: (a vertical circulation) — raise the version to koyu 0.5`, {
666
630
  line: s.line,
667
631
  file: s.file,
668
632
  path: [s.path],
@@ -671,7 +635,7 @@ function checkLanguageVersion(ctx: Ctx): void {
671
635
  }
672
636
  for (const b of model.boundaries) {
673
637
  if (b.drawn) {
674
- emit("VER03", `${older}: ${b.a} | ${b.b} の line (描かれた線) — koyu 0.5 へ上げます`, {
638
+ emit("VER03", `${older}: ${b.a} | ${b.b} carries line (a drawn line) — raise the version to koyu 0.5`, {
675
639
  line: b.drawn.line,
676
640
  file: b.file,
677
641
  path: [b.a, b.b],
@@ -679,20 +643,39 @@ function checkLanguageVersion(ctx: Ctx): void {
679
643
  }
680
644
  }
681
645
  for (const c of model.columns) {
682
- emit("VER03", `${older}: column (柱) — koyu 0.5 へ上げます`, { line: c.line, file: c.file });
646
+ emit("VER03", `${older}: column — raise the version to koyu 0.5`, { line: c.line, file: c.file });
683
647
  }
684
648
  for (const l of Object.values(model.levels)) {
685
649
  if (l.underground) {
686
- emit("VER03", `${older}: level ${l.name} の underground: — koyu 0.5 へ上げます`, {
650
+ emit("VER03", `${older}: level ${l.name} carries underground: — raise the version to koyu 0.5`, {
687
651
  line: l.line,
688
652
  file: l.file,
689
653
  });
690
654
  }
691
655
  }
692
656
  }
657
+
658
+ // 1.0 で入った語 (上書き `over`・削除 `drop`・`over` 直下の集合編集 `+` `-` `=`) は
659
+ // 0.5 以前の処理系が知らない。知らない処理系ではその行が語として読めず、上書きも削除も
660
+ // 起きない — **黙って別の建物になる**。VER03 と同型の理屈である (ADR-0017 決定3 / ADR-0035)
661
+ if (olderThan(model.version, "1.0")) {
662
+ const older = `A koyu ${model.version} file uses a 1.0 word`;
663
+ for (const e of model.compositionEdits) {
664
+ const what =
665
+ e.word === "over" ? "a composition override"
666
+ : e.word === "drop" ? "a composition removal"
667
+ : "a set edit under over";
668
+ const paths = e.subject.split(" ").filter((t) => t.startsWith("/"));
669
+ emit("VER04", `${older}: ${[e.word, e.subject].filter(Boolean).join(" ")} (${what}) — raise the version to koyu 1.0`, {
670
+ line: e.line,
671
+ file: e.file,
672
+ ...(paths.length > 0 ? { path: paths } : {}),
673
+ });
674
+ }
675
+ }
693
676
  }
694
677
 
695
- /** uid — UID01〜UID03 */
678
+ /** 同一性 — UID01〜UID04 */
696
679
  function checkUids(ctx: Ctx): void {
697
680
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
698
681
  // uid (ADR-0015): 不透明トークン、space/zone横断でモデル全体一意。
@@ -702,7 +685,7 @@ function checkUids(ctx: Ctx): void {
702
685
  const v = attrs["uid"];
703
686
  if (v === undefined) return;
704
687
  if (typeof v === "number") {
705
- emit("UID01", `uid は数字だけのトークンにできません: uid:${v} (sp-${v} のような形にします)`, {
688
+ emit("UID01", `A uid cannot be a token of digits alone: uid:${v} (write something like sp-${v})`, {
706
689
  line,
707
690
  file,
708
691
  path: [path],
@@ -710,7 +693,7 @@ function checkUids(ctx: Ctx): void {
710
693
  return;
711
694
  }
712
695
  if (v === "" || /\s/.test(v)) {
713
- emit("UID02", `uid に空白は使えません: "${v}"`, { line, file, path: [path] });
696
+ emit("UID02", `A uid cannot contain whitespace: "${v}"`, { line, file, path: [path] });
714
697
  return;
715
698
  }
716
699
  const arr = uidOwners.get(v) ?? [];
@@ -723,11 +706,59 @@ function checkUids(ctx: Ctx): void {
723
706
  if (owners.length > 1) {
724
707
  emit(
725
708
  "UID03",
726
- `uid が重複しています: ${uid} (${owners.map((o) => `${o.kind} ${o.path} — ${srcRef(o.line, o.file)}`).join(", ")})`,
709
+ `Duplicate uid: ${uid} (${owners.map((o) => `${o.kind} ${o.path} — ${srcRef(o.line, o.file)}`).join(", ")})`,
727
710
  { path: owners.map((o) => o.path), related: owners.map((o) => loc(o.line, o.file)) },
728
711
  );
729
712
  }
730
713
  }
714
+
715
+ // 開口・内包物の同一性は「含む対象 + その中で一意な名」から導かれる (spec/scope.md §5)。
716
+ // 名が重複していれば、その同一性は成り立たない — `over ... = door D1` はどちらを指すのか
717
+ // 決められず、`drop column C1` は二本まとめて消してしまう。**推測せずに拒む** (ADR-0039)。
718
+ // 名を書かない要素は同一性を主張していないので、母集団に入らない
719
+ const dupNames = (
720
+ what: string,
721
+ where: string,
722
+ items: Array<{ name?: string; line: number; file?: string }>,
723
+ path?: string[],
724
+ ) => {
725
+ const byName = new Map<string, Array<{ line: number; file?: string }>>();
726
+ for (const it of items) {
727
+ if (it.name === undefined || it.name === "") continue;
728
+ const arr = byName.get(it.name) ?? [];
729
+ arr.push(loc(it.line, it.file));
730
+ byName.set(it.name, arr);
731
+ }
732
+ for (const [name, at] of byName) {
733
+ if (at.length < 2) continue;
734
+ const last = at[at.length - 1]!;
735
+ emit(
736
+ "UID04",
737
+ `Duplicate ${what} name within ${where}: ${name} (${at.map((o) => srcRef(o.line, o.file)).join(", ")}) — the name is what identifies it inside its container`,
738
+ { line: last.line, file: last.file, ...(path ? { path } : {}), related: at.slice(0, -1) },
739
+ );
740
+ }
741
+ };
742
+ const written = (attrs: Attrs): string | undefined => {
743
+ const n = attrs["name"];
744
+ return n === undefined || n === "" ? undefined : String(n);
745
+ };
746
+ for (const b of model.boundaries) {
747
+ const where = `boundary ${b.a} | ${b.b}`;
748
+ const at = b.file !== undefined ? { file: b.file } : {};
749
+ // 開口だけは、アセットから継いだ型の名を主張として数えない (ADR-0039)
750
+ dupNames("opening", where, b.openings.map((o) => ({ name: openingIdentity(model, o), line: o.line, ...at })), [b.a, b.b]);
751
+ dupNames("seg", where, b.segs.map((g) => ({ name: written(g.attrs), line: g.line, ...at })), [b.a, b.b]);
752
+ }
753
+ for (const s of model.spaces.values()) {
754
+ const at = s.file !== undefined ? { file: s.file } : {};
755
+ dupNames("area", `space ${s.path}`, s.areas.map((a) => ({ name: written(a.attrs), line: a.line, ...at })), [s.path]);
756
+ }
757
+ dupNames(
758
+ "column",
759
+ "the model",
760
+ model.columns.map((c) => ({ name: written(c.attrs), line: c.line, ...(c.file !== undefined ? { file: c.file } : {}) })),
761
+ );
731
762
  }
732
763
 
733
764
  /** 境界の妥当性 — VRT / BND03〜06 / OPN / SEG */
@@ -751,7 +782,7 @@ function checkBoundaryValidity(ctx: Ctx): void {
751
782
  if (sa.rects.length > 0 && sb.rects.length > 0 && sa.level !== sb.level) {
752
783
  emit(
753
784
  "BND03",
754
- `異なるレベルの空間に壁境界は書けません (垂直は type:stair/shaft/void): ${b.a} | ${b.b}`,
785
+ `A wall boundary cannot be written to a space on a different level (vertical takes type:stair/shaft/void): ${b.a} | ${b.b}`,
755
786
  bAt,
756
787
  );
757
788
  continue; // レベルを跨ぐ壁は成立していない — 線分も開口も問わない
@@ -767,29 +798,29 @@ function checkVerticalBoundary(ctx: Ctx, b: Boundary, sa: Space, sb: Space, bAt:
767
798
  const { emit, levelIndex } = ctx;
768
799
  // 垂直境界: 隣り合うレベルの、平面で重なる空間同士にしか張れない
769
800
  if (sa.rects.length === 0 || sb.rects.length === 0 || !sa.level || !sb.level) {
770
- emit("VRT01", `${b.kind} 境界は領域とレベルを持つ空間同士に書きます`, bAt);
801
+ emit("VRT01", `A ${b.kind} boundary is written between spaces that have both a region and a level`, bAt);
771
802
  return; // 前提が崩れているので、以降の判定は意味を持たない
772
803
  }
773
804
  const ia = levelIndex.get(sa.level);
774
805
  const ib = levelIndex.get(sb.level);
775
806
  if (ia === undefined || ib === undefined || Math.abs(ia - ib) !== 1) {
776
- emit("VRT02", `${b.kind} 境界は隣り合うレベルの間に書きます: ${b.a} | ${b.b}`, bAt);
807
+ emit("VRT02", `A ${b.kind} boundary is written between adjacent levels: ${b.a} | ${b.b}`, bAt);
777
808
  } else if (!spacesOverlap(sa, sb)) {
778
- emit("VRT03", `${b.kind} 境界の空間が平面上で重なっていません: ${b.a} | ${b.b}`, bAt);
809
+ emit("VRT03", `The spaces of a ${b.kind} boundary do not overlap in plan: ${b.a} | ${b.b}`, bAt);
779
810
  }
780
811
  if (b.kind === "void") {
781
812
  const upper = (ia ?? 0) > (ib ?? 0) ? sa : sb;
782
813
  if (upper.type !== "void") {
783
- emit("VRT04", `void境界の上側は type:void の空間を想定しています: ${upper.path}`, bAt);
814
+ emit("VRT04", `The space above a void boundary is expected to be type:void: ${upper.path}`, bAt);
784
815
  }
785
816
  }
786
817
  // 咎めているのは字下げされた door / window / seg の行そのものなので、
787
818
  // 親の境界宣言ではなくその行を指す。宣言が複数あれば診断も複数出る
788
819
  for (const o of b.openings) {
789
- emit("VRT05", `垂直境界の${o.kind}は解釈されません`, { line: o.line, file: b.file, path: [b.a, b.b] });
820
+ emit("VRT05", `A ${o.kind} on a vertical boundary is not interpreted`, { line: o.line, file: b.file, path: [b.a, b.b] });
790
821
  }
791
822
  for (const g of b.segs) {
792
- emit("VRT06", `垂直境界の seg は解釈されません`, { line: g.line, file: b.file, path: [b.a, b.b] });
823
+ emit("VRT06", `A seg on a vertical boundary is not interpreted`, { line: g.line, file: b.file, path: [b.a, b.b] });
793
824
  }
794
825
  }
795
826
 
@@ -809,19 +840,19 @@ function checkBoundarySegments(ctx: Ctx, b: Boundary, sa: Space, sb: Space, bAt:
809
840
  const dirs = [...new Set(without.map((g) => g.edgeOfA))].filter((d): d is Edge => d !== undefined);
810
841
  emit(
811
842
  "BND04",
812
- `edge:${b.edge} に共有辺がありません: ${b.a} | ${b.b} (実際に接しているのは ${
813
- dirs.join("・") || "別の辺"
814
- } です)`,
843
+ `No shared edge on edge:${b.edge}: ${b.a} | ${b.b} (they actually touch on ${
844
+ dirs.join(" / ") || "another edge"
845
+ })`,
815
846
  bAt,
816
847
  );
817
848
  } else {
818
- emit("BND04", `空間が接していないため境界を導けません: ${b.a} | ${b.b}`, bAt);
849
+ emit("BND04", `The spaces do not touch, so no boundary can be derived: ${b.a} | ${b.b}`, bAt);
819
850
  }
820
851
  }
821
852
  if ((sa.rects.length > 0 ? 1 : 0) + (sb.rects.length > 0 ? 1 : 0) === 1 && segs.length === 0) {
822
853
  emit(
823
854
  "BND06",
824
- `${b.edge ? `edge:${b.edge} の` : ""}外周に残る辺が無く、境界線分がゼロです: ${b.a} | ${b.b}`,
855
+ `No edge remains on the perimeter${b.edge ? ` for edge:${b.edge}` : ""}, so the boundary segment is of zero length: ${b.a} | ${b.b}`,
825
856
  bAt,
826
857
  );
827
858
  }
@@ -836,7 +867,7 @@ function checkOpenings(ctx: Ctx, b: Boundary): void {
836
867
  const { model, emit, loc } = ctx;
837
868
  if (b.kind === "open" && b.openings.length > 0) {
838
869
  for (const o of b.openings) {
839
- emit("OPN03", `open境界の${o.kind}は通行に影響しません (常に通れます)`, {
870
+ emit("OPN03", `A ${o.kind} on an open boundary has no effect on passage (it is always passable)`, {
840
871
  line: o.line,
841
872
  file: b.file,
842
873
  path: [b.a, b.b],
@@ -865,7 +896,7 @@ function checkOpenings(ctx: Ctx, b: Boundary): void {
865
896
  if (!okAxis) {
866
897
  emit(
867
898
  "OPN01",
868
- `hinge:${o.hinge} は${placed.segment.horizontal ? "水平線分 (W/E)" : "垂直線分 (N/S)"}で指定します`,
899
+ `hinge:${o.hinge}: ${placed.segment.horizontal ? "a horizontal segment takes W/E" : "a vertical segment takes N/S"}`,
869
900
  { line: o.line, file: b.file, path: [b.a, b.b] },
870
901
  );
871
902
  }
@@ -887,9 +918,9 @@ function checkOpenings(ctx: Ctx, b: Boundary): void {
887
918
  if (q.c - p.c < need - EPS) {
888
919
  emit(
889
920
  "OPN02",
890
- `開口同士が重なっています (${p.o.kind}と${q.o.kind} — 中心間 ${Math.round(
921
+ `Openings overlap (${p.o.kind} and ${q.o.kind} — center to center ${Math.round(
891
922
  q.c - p.c,
892
- )}mm < 必要 ${Math.round(need)}mm)`,
923
+ )}mm < the required ${Math.round(need)}mm)`,
893
924
  { line: q.o.line, file: b.file, path: [b.a, b.b], related: [loc(p.o.line, b.file)] },
894
925
  );
895
926
  }
@@ -902,7 +933,7 @@ function checkBoundarySegs(ctx: Ctx, b: Boundary): void {
902
933
  const { model, emit } = ctx;
903
934
  for (const g of b.segs) {
904
935
  if (b.kind === "open") {
905
- emit("SEG03", `open境界 (壁が無い) の seg は解釈されません`, { line: g.line, file: b.file, path: [b.a, b.b] });
936
+ emit("SEG03", `A seg on an open boundary (there is no wall) is not interpreted`, { line: g.line, file: b.file, path: [b.a, b.b] });
906
937
  continue;
907
938
  }
908
939
  const placed = placeBand(model, b, g, "seg");
@@ -919,7 +950,7 @@ function checkAreas(ctx: Ctx): void {
919
950
  for (const s of model.spaces.values()) {
920
951
  for (const a of s.areas) {
921
952
  if (s.rects.length === 0) {
922
- emit("SEG01", `領域を持たない空間 ${s.path} に area は書けません`, {
953
+ emit("SEG01", `An area cannot be written on ${s.path}, which has no region`, {
923
954
  line: a.line,
924
955
  file: s.file,
925
956
  path: [s.path],
@@ -931,7 +962,7 @@ function checkAreas(ctx: Ctx): void {
931
962
  rectToPoly(a.rect).every((pt) => pointInPolygon(pt, g, EPS)),
932
963
  );
933
964
  if (!inside) {
934
- emit("SEG02", `area が ${s.path} の領域からはみ出しています`, { line: a.line, file: s.file, path: [s.path] });
965
+ emit("SEG02", `The area spills outside the region of ${s.path}`, { line: a.line, file: s.file, path: [s.path] });
935
966
  }
936
967
  }
937
968
  }
@@ -944,10 +975,10 @@ function checkZones(ctx: Ctx): void {
944
975
  for (const z of model.zones.values()) {
945
976
  const children = [...model.spaces.keys()].filter((p) => p.startsWith(z.path + "/"));
946
977
  if (children.length === 0) {
947
- emit("ZON01", `ゾーン ${z.path} の下に空間がありません`, { line: z.line, file: z.file, path: [z.path] });
978
+ emit("ZON01", `There are no spaces beneath zone ${z.path}`, { line: z.line, file: z.file, path: [z.path] });
948
979
  }
949
980
  if (model.spaces.has(z.path)) {
950
- emit("ZON02", `ゾーンと同じパスの空間があります (どちらかに寄せます): ${z.path}`, {
981
+ emit("ZON02", `A space shares its path with a zone (settle on one of them): ${z.path}`, {
951
982
  line: z.line,
952
983
  file: z.file,
953
984
  path: [z.path],
@@ -956,7 +987,12 @@ function checkZones(ctx: Ctx): void {
956
987
  }
957
988
  }
958
989
 
959
- /** 高さ方向の一貫性 — HGT01〜HGT04 */
990
+ /**
991
+ * 高さ方向の一貫性 — HGT01 / HGT02。
992
+ * **ここは「書かれた値が矛盾しているか」だけを見る。**値が書かれていないこと (上階の slab が無い、
993
+ * 天井高が決まらない) は不変量の破れではなく情報の欠落なので、充足性の節が SUF01 / SUF03 で言う
994
+ * (ADR-0034)。以前はここが HGT03 / HGT04 として二重に言っていた
995
+ */
960
996
  function checkHeights(ctx: Ctx): void {
961
997
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
962
998
  // 高さ方向の一貫性: 下階の空間の天井高 + 上階のslab ≤ 階高
@@ -991,7 +1027,6 @@ function checkHeights(ctx: Ctx): void {
991
1027
  const below = byLevel.get(lb.name) ?? [];
992
1028
  const above = byLevel.get(lu.name) ?? [];
993
1029
  const pitch = lu.z - lb.z;
994
- let slabMissing = false;
995
1030
  for (const s of below) {
996
1031
  if (isSemiOutdoor(model, s)) continue; // 屋外・半屋外 (庭・バルコニー等) に天井は無い
997
1032
  // 縦動線の宣言的免除 (ADR-0021)。void の免除が「床の不在」だったのに対し、
@@ -1000,19 +1035,9 @@ function checkHeights(ctx: Ctx): void {
1000
1035
  if (runDecls(s).length > 0) continue;
1001
1036
  const covered = above.some((u) => spacesOverlap(s, u)) || above.length === 0;
1002
1037
  if (!covered) continue;
1003
- if (lu.slab === undefined) {
1004
- slabMissing = true;
1005
- continue;
1006
- }
1038
+ if (lu.slab === undefined) continue; // 立式に要る値が無い — SUF03 が言う
1007
1039
  const h = heff(model, s);
1008
- if (h === undefined) {
1009
- emit("HGT04", `${s.path} の天井高が不明で、${lu.name} との高さ検査ができません`, {
1010
- line: s.line,
1011
- file: s.file,
1012
- path: [s.path],
1013
- });
1014
- continue;
1015
- }
1040
+ if (h === undefined) continue; // 同上 — SUF01 が言う
1016
1041
  if (h + lu.slab > pitch + EPS) {
1017
1042
  const partners = voidPartners.get(`${s.path}|${lu.name}`) ?? [];
1018
1043
  const cover = partners.length ? voidCoverage(s, partners) : 0;
@@ -1023,45 +1048,78 @@ function checkHeights(ctx: Ctx): void {
1023
1048
  // 被覆は免除しきい値 (99%) と衝突しないよう小数一桁で言う
1024
1049
  emit(
1025
1050
  "HGT02",
1026
- `${s.path} が上階に食い込みます: 天井高${h} + ${lu.name}のslab${lu.slab} = ${
1051
+ `${s.path} collides into the floor above: ceiling height ${h} + ${lu.name}'s slab ${lu.slab} = ${
1027
1052
  h + lu.slab
1028
- } > 階高${pitch}。吹抜けの被覆は${(cover * 100).toFixed(1)}%しかありません — 部分吹抜けでは天井高を階高内に収めます (吹抜け部分の高さは導出)`,
1053
+ } > storey height ${pitch}. The void covers only ${(cover * 100).toFixed(1)}% — under a partial void keep the ceiling height within the storey height (the height of the void part is derived)`,
1029
1054
  { line: s.line, file: s.file, path: [s.path] },
1030
1055
  );
1031
1056
  } else {
1032
1057
  emit(
1033
1058
  "HGT01",
1034
- `${s.path} が上階に食い込みます: 天井高${h} + ${lu.name}のslab${lu.slab} = ${h + lu.slab} > 階高${pitch}`,
1059
+ `${s.path} collides into the floor above: ceiling height ${h} + ${lu.name}'s slab ${lu.slab} = ${h + lu.slab} > storey height ${pitch}`,
1035
1060
  { line: s.line, file: s.file, path: [s.path] },
1036
1061
  );
1037
1062
  }
1038
1063
  }
1039
1064
  }
1040
- if (slabMissing) {
1041
- emit("HGT03", `レベル ${lu.name} に slab が未宣言のため、${lb.name} との高さ検査ができません`, {
1042
- line: lu.line,
1043
- file: lu.file,
1044
- });
1045
- }
1046
1065
  }
1047
1066
  }
1048
1067
 
1049
- /** レベルに載らない空間 — HGT05 */
1050
- function checkOrphanSpaces(ctx: Ctx): void {
1051
- const { model, emit, loc, withRect, levels, levelIndex } = ctx;
1052
- // レベルに載らない領域つき空間
1068
+ /**
1069
+ * 充足性 — 領域を持つ空間の走査 (SUF02 / SUF01)。
1070
+ *
1071
+ * **妥当性の判定ではなく、完全性の検査である** (spec/scope.md §6-2)。形を作らないことと
1072
+ * 形を作れないことは違う — 天井高が決まらなければ押し出す高さが無く、レベルが決まらなければ
1073
+ * z が無い。どちらも「書いてある構成から一意な形が出る」という契約 (ADR-0034) の破れである。
1074
+ *
1075
+ * 除くのは、その空間の形が天井高に依らないものだけ — 吹抜け (床も天井も無い)、外部 (地面)、
1076
+ * 半屋外 (`fabric.ts` が天井も屋根も架けない)。**節の粒度は走査単位である** (ADR-0028) ので、
1077
+ * 一つの空間が出す二つのコードはこの一本のループの中で決まる
1078
+ */
1079
+ function checkSpaceSufficiency(ctx: Ctx): void {
1080
+ const { model, emit, withRect } = ctx;
1053
1081
  for (const s of withRect) {
1082
+ const at = { line: s.line, file: s.file, path: [s.path] };
1054
1083
  if (!s.level) {
1055
- emit("HGT05", `${s.path} は領域を持ちますが、レベルが特定できません (パス先頭か level: で指定します)`, {
1056
- line: s.line,
1057
- file: s.file,
1058
- path: [s.path],
1059
- });
1084
+ emit("SUF02", `${s.path} has a region, but its level cannot be determined (give it at the head of the path or with level:)`, at);
1085
+ continue; // z が決まらない空間には、天井高を問う意味が無い
1086
+ }
1087
+ if (s.type === "void" || s.type === "exterior" || isSemiOutdoor(model, s)) continue;
1088
+ if (heff(model, s) === undefined) {
1089
+ emit(
1090
+ "SUF01",
1091
+ `The ceiling height of ${s.path} cannot be determined (neither the space's h: nor level ${s.level}'s h: is there)`,
1092
+ at,
1093
+ );
1060
1094
  }
1061
1095
  }
1062
1096
  }
1063
1097
 
1064
- /** 敷地形状 — SIT01〜SIT05 */
1098
+ /**
1099
+ * 充足性 — レベルの走査 (SUF03)。
1100
+ *
1101
+ * 床は level の `slab` (床組み厚) だけが与える (ADR-0024) ので、書かなければその階に床は
1102
+ * 一枚も生成されない。**形そのものは定まる**ので警告である — 「slab が無ければ床要素を作らない」は
1103
+ * 決定的な規則であり、複数の形が出るわけではない。ただし床の無い建物になることは知らされるべきである
1104
+ */
1105
+ function checkLevelSufficiency(ctx: Ctx): void {
1106
+ const { emit, withRect, levels } = ctx;
1107
+ for (const l of levels) {
1108
+ if (l.slab !== undefined) continue;
1109
+ // 床を持ちうる空間が一つも載っていない階 (最上階の上限を与えるだけの屋上レベルなど) には
1110
+ // 言うことが無い — 生成されなかった床が無いのだから
1111
+ const n = withRect.filter(
1112
+ (s) => s.level === l.name && s.type !== "void" && s.type !== "exterior",
1113
+ ).length;
1114
+ if (n === 0) continue;
1115
+ emit("SUF03", `Level ${l.name} has no slab:, so not one floor is generated on this storey`, {
1116
+ line: l.line,
1117
+ file: l.file,
1118
+ });
1119
+ }
1120
+ }
1121
+
1122
+ /** 敷地形状 — SIT01 / SIT02 / SIT04 (与件の健全性。建物との関係の判断は検証の面) */
1065
1123
  function checkSite(ctx: Ctx): void {
1066
1124
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
1067
1125
  // 敷地形状 (ADR-0011): 形の妥当性、対応ゾーンの存在、宣言面積との照合、建物のはみ出し検査。
@@ -1072,7 +1130,7 @@ function checkSite(ctx: Ctx): void {
1072
1130
  const a = poly.points[i]!;
1073
1131
  const b = poly.points[(i + 1) % poly.points.length]!;
1074
1132
  if (Math.hypot(b.x - a.x, b.y - a.y) <= EPS_SITE) {
1075
- emit("SIT01", `敷地形状に重複する頂点があります (${Math.round(a.x)},${Math.round(a.y)})`, {
1133
+ emit("SIT01", `The site shape has a duplicate vertex (${Math.round(a.x)},${Math.round(a.y)})`, {
1076
1134
  line: poly.line,
1077
1135
  file: poly.file,
1078
1136
  path: [poly.path],
@@ -1081,7 +1139,7 @@ function checkSite(ctx: Ctx): void {
1081
1139
  }
1082
1140
  const selfX = polygonSelfIntersection(poly.points);
1083
1141
  if (selfX) {
1084
- emit("SIT02", `敷地形状が自己交差しています (${Math.round(selfX.x)},${Math.round(selfX.y)} 付近)`, {
1142
+ emit("SIT02", `The site shape is self-intersecting (near ${Math.round(selfX.x)},${Math.round(selfX.y)})`, {
1085
1143
  line: poly.line,
1086
1144
  file: poly.file,
1087
1145
  path: [poly.path],
@@ -1090,39 +1148,12 @@ function checkSite(ctx: Ctx): void {
1090
1148
  }
1091
1149
  const zone = model.zones.get(poly.path);
1092
1150
  if (!zone) {
1093
- emit("SIT04", `polygon ${poly.path} に対応するゾーンがありません`, {
1151
+ emit("SIT04", `No zone corresponds to polygon ${poly.path}`, {
1094
1152
  line: poly.line,
1095
1153
  file: poly.file,
1096
1154
  path: [poly.path],
1097
1155
  });
1098
1156
  continue;
1099
1157
  }
1100
- if (zone.attrs["site"] !== 1) continue;
1101
- const declared = zone.attrs["area"];
1102
- if (typeof declared === "number") {
1103
- const derived = polygonAreaM2(poly.points);
1104
- if (Math.abs(declared - derived) >= 0.05) {
1105
- emit(
1106
- "SIT05",
1107
- `敷地面積の宣言と導出が食い違います: 宣言 ${declared}㎡ / 導出 ${derived.toFixed(2)}㎡`,
1108
- { line: zone.line, file: zone.file, path: [zone.path] },
1109
- );
1110
- }
1111
- }
1112
- for (const s of withRect) {
1113
- if (s.type === "exterior" || s.path.startsWith(poly.path + "/")) continue;
1114
- // 照合するのは割付ではなく**導出された領域** — 敷地なりに切った外形はここで通る
1115
- for (const r of regionOf(s)) {
1116
- const out = shapeEscapesPolygon(r, poly.points, EPS_SITE);
1117
- if (out) {
1118
- emit("SIT03", `${s.path} が敷地形状からはみ出しています (${Math.round(out.x)},${Math.round(out.y)} 付近)`, {
1119
- line: s.line,
1120
- file: s.file,
1121
- path: [s.path],
1122
- });
1123
- break;
1124
- }
1125
- }
1126
- }
1127
1158
  }
1128
1159
  }