@kensnzk/koyu 0.16.0 → 0.18.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 (254) hide show
  1. package/README.ja.md +12 -8
  2. package/README.md +13 -10
  3. package/dist/analysis/contracts.d.ts +217 -0
  4. package/dist/analysis/contracts.d.ts.map +1 -0
  5. package/dist/analysis/contracts.js +27 -0
  6. package/dist/analysis/contracts.js.map +1 -0
  7. package/dist/analysis/index.d.ts +5 -0
  8. package/dist/analysis/index.d.ts.map +1 -0
  9. package/dist/analysis/index.js +17 -0
  10. package/dist/analysis/index.js.map +1 -0
  11. package/dist/analysis/json.d.ts +21 -0
  12. package/dist/analysis/json.d.ts.map +1 -0
  13. package/dist/analysis/json.js +111 -0
  14. package/dist/analysis/json.js.map +1 -0
  15. package/dist/cli.js +106 -35
  16. package/dist/cli.js.map +1 -1
  17. package/dist/core/derive.d.ts +13 -8
  18. package/dist/core/derive.d.ts.map +1 -1
  19. package/dist/core/derive.js +19 -13
  20. package/dist/core/derive.js.map +1 -1
  21. package/dist/core/diagnose.d.ts +4 -3
  22. package/dist/core/diagnose.d.ts.map +1 -1
  23. package/dist/core/diagnose.js +46 -11
  24. package/dist/core/diagnose.js.map +1 -1
  25. package/dist/core/diff.d.ts +3 -2
  26. package/dist/core/diff.d.ts.map +1 -1
  27. package/dist/core/diff.js +8 -5
  28. package/dist/core/diff.js.map +1 -1
  29. package/dist/core/fabric.d.ts +1 -3
  30. package/dist/core/fabric.d.ts.map +1 -1
  31. package/dist/core/fabric.js +8 -8
  32. package/dist/core/fabric.js.map +1 -1
  33. package/dist/core/graph.d.ts +2 -2
  34. package/dist/core/graph.d.ts.map +1 -1
  35. package/dist/core/graph.js +12 -5
  36. package/dist/core/graph.js.map +1 -1
  37. package/dist/core/light.d.ts.map +1 -1
  38. package/dist/core/light.js +2 -2
  39. package/dist/core/light.js.map +1 -1
  40. package/dist/core/model.d.ts +59 -10
  41. package/dist/core/model.d.ts.map +1 -1
  42. package/dist/core/model.js +128 -26
  43. package/dist/core/model.js.map +1 -1
  44. package/dist/core/parse.d.ts.map +1 -1
  45. package/dist/core/parse.js +83 -82
  46. package/dist/core/parse.js.map +1 -1
  47. package/dist/core/poly.d.ts +0 -4
  48. package/dist/core/poly.d.ts.map +1 -1
  49. package/dist/core/poly.js +1 -5
  50. package/dist/core/poly.js.map +1 -1
  51. package/dist/core/site.d.ts +9 -0
  52. package/dist/core/site.d.ts.map +1 -1
  53. package/dist/core/site.js +8 -2
  54. package/dist/core/site.js.map +1 -1
  55. package/dist/core/tolerance.d.ts +1 -1
  56. package/dist/core/tolerance.js +2 -2
  57. package/dist/core/tolerance.js.map +1 -1
  58. package/dist/core/vertical.d.ts +9 -2
  59. package/dist/core/vertical.d.ts.map +1 -1
  60. package/dist/core/vertical.js +8 -1
  61. package/dist/core/vertical.js.map +1 -1
  62. package/dist/core/vocabulary.d.ts.map +1 -1
  63. package/dist/core/vocabulary.js +17 -5
  64. package/dist/core/vocabulary.js.map +1 -1
  65. package/dist/diagnostics.d.ts +2 -0
  66. package/dist/diagnostics.d.ts.map +1 -0
  67. package/dist/diagnostics.js +3 -0
  68. package/dist/diagnostics.js.map +1 -0
  69. package/dist/diff.d.ts +2 -0
  70. package/dist/diff.d.ts.map +1 -0
  71. package/dist/diff.js +3 -0
  72. package/dist/diff.js.map +1 -0
  73. package/dist/draw/index.js +1 -1
  74. package/dist/draw/index.js.map +1 -1
  75. package/dist/draw/plan.js +5 -5
  76. package/dist/draw/plan.js.map +1 -1
  77. package/dist/form.d.ts +5 -0
  78. package/dist/form.d.ts.map +1 -0
  79. package/dist/form.js +4 -0
  80. package/dist/form.js.map +1 -0
  81. package/dist/graph.d.ts +2 -0
  82. package/dist/graph.d.ts.map +1 -0
  83. package/dist/graph.js +3 -0
  84. package/dist/graph.js.map +1 -0
  85. package/dist/index.d.ts +2 -14
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +36 -45
  88. package/dist/index.js.map +1 -1
  89. package/dist/mcp.js +81 -30
  90. package/dist/mcp.js.map +1 -1
  91. package/dist/model.d.ts +3 -0
  92. package/dist/model.d.ts.map +1 -0
  93. package/dist/model.js +3 -0
  94. package/dist/model.js.map +1 -0
  95. package/dist/parse-file.d.ts.map +1 -1
  96. package/dist/parse-file.js +18 -3
  97. package/dist/parse-file.js.map +1 -1
  98. package/dist/validate/assessment.d.ts +8 -0
  99. package/dist/validate/assessment.d.ts.map +1 -0
  100. package/dist/validate/assessment.js +1738 -0
  101. package/dist/validate/assessment.js.map +1 -0
  102. package/dist/validate/builtin/access.d.ts +55 -0
  103. package/dist/validate/builtin/access.d.ts.map +1 -0
  104. package/dist/validate/builtin/access.js +494 -0
  105. package/dist/validate/builtin/access.js.map +1 -0
  106. package/dist/validate/builtin/daylight.d.ts +44 -0
  107. package/dist/validate/builtin/daylight.d.ts.map +1 -0
  108. package/dist/validate/builtin/daylight.js +233 -0
  109. package/dist/validate/builtin/daylight.js.map +1 -0
  110. package/dist/validate/builtin/door-column-collisions.d.ts +47 -0
  111. package/dist/validate/builtin/door-column-collisions.d.ts.map +1 -0
  112. package/dist/validate/builtin/door-column-collisions.js +189 -0
  113. package/dist/validate/builtin/door-column-collisions.js.map +1 -0
  114. package/dist/validate/builtin/envelope.d.ts +30 -0
  115. package/dist/validate/builtin/envelope.d.ts.map +1 -0
  116. package/dist/validate/builtin/envelope.js +169 -0
  117. package/dist/validate/builtin/envelope.js.map +1 -0
  118. package/dist/validate/builtin/freeze.d.ts +3 -0
  119. package/dist/validate/builtin/freeze.d.ts.map +1 -0
  120. package/dist/validate/builtin/freeze.js +21 -0
  121. package/dist/validate/builtin/freeze.js.map +1 -0
  122. package/dist/validate/builtin/index.d.ts +38 -0
  123. package/dist/validate/builtin/index.d.ts.map +1 -0
  124. package/dist/validate/builtin/index.js +106 -0
  125. package/dist/validate/builtin/index.js.map +1 -0
  126. package/dist/validate/builtin/site.d.ts +62 -0
  127. package/dist/validate/builtin/site.d.ts.map +1 -0
  128. package/dist/validate/builtin/site.js +333 -0
  129. package/dist/validate/builtin/site.js.map +1 -0
  130. package/dist/validate/builtin/vertical-runs.d.ts +53 -0
  131. package/dist/validate/builtin/vertical-runs.d.ts.map +1 -0
  132. package/dist/validate/builtin/vertical-runs.js +290 -0
  133. package/dist/validate/builtin/vertical-runs.js.map +1 -0
  134. package/dist/validate/contracts.d.ts +188 -0
  135. package/dist/validate/contracts.d.ts.map +1 -0
  136. package/dist/validate/contracts.js +28 -0
  137. package/dist/validate/contracts.js.map +1 -0
  138. package/dist/validate/index.d.ts +2 -59
  139. package/dist/validate/index.d.ts.map +1 -1
  140. package/dist/validate/index.js +22 -70
  141. package/dist/validate/index.js.map +1 -1
  142. package/dist/vocabulary.d.ts +2 -0
  143. package/dist/vocabulary.d.ts.map +1 -0
  144. package/dist/vocabulary.js +3 -0
  145. package/dist/vocabulary.js.map +1 -0
  146. package/editors/vscode/syntaxes/koyu.tmLanguage.json +2 -2
  147. package/examples/basement/main.muro +3 -3
  148. package/examples/complex/main.muro +1 -1
  149. package/examples/complex/podium.muro +1 -1
  150. package/examples/complex/site.muro +6 -6
  151. package/examples/house/L2.muro +1 -1
  152. package/examples/house/main.muro +1 -1
  153. package/examples/house/site.muro +4 -4
  154. package/examples/house.muro +6 -6
  155. package/examples/mansion.muro +2 -2
  156. package/examples/office.muro +3 -3
  157. package/examples/steps/04-exterior.muro +1 -1
  158. package/examples/steps/05-two-storeys.muro +1 -1
  159. package/examples/steps/06-finished.muro +2 -2
  160. package/examples/tower/L2.muro +1 -1
  161. package/examples/tower/main.muro +1 -1
  162. package/examples/tower/site.muro +4 -4
  163. package/examples/twin/main.muro +1 -1
  164. package/examples/twin/podium.muro +4 -4
  165. package/examples/twin/site.muro +8 -8
  166. package/examples/two-rooms.canonical.json +4 -4
  167. package/examples/two-rooms.muro +2 -2
  168. package/package.json +41 -9
  169. package/src/analysis/contracts.ts +234 -0
  170. package/src/analysis/index.ts +61 -0
  171. package/src/analysis/json.ts +117 -0
  172. package/src/cli.ts +116 -36
  173. package/src/core/derive.ts +32 -15
  174. package/src/core/diagnose.ts +63 -16
  175. package/src/core/diff.ts +10 -6
  176. package/src/core/fabric.ts +18 -9
  177. package/src/core/graph.ts +19 -5
  178. package/src/core/light.ts +2 -2
  179. package/src/core/model.ts +141 -31
  180. package/src/core/parse.ts +100 -85
  181. package/src/core/poly.ts +1 -8
  182. package/src/core/site.ts +19 -2
  183. package/src/core/tolerance.ts +2 -2
  184. package/src/core/vertical.ts +10 -3
  185. package/src/core/vocabulary.ts +18 -5
  186. package/src/diagnostics.ts +8 -0
  187. package/src/diff.ts +14 -0
  188. package/src/draw/index.ts +1 -1
  189. package/src/draw/plan.ts +5 -5
  190. package/src/form.ts +37 -0
  191. package/src/graph.ts +12 -0
  192. package/src/index.ts +40 -175
  193. package/src/mcp.ts +85 -35
  194. package/src/model.ts +43 -0
  195. package/src/parse-file.ts +17 -3
  196. package/src/validate/assessment.ts +1934 -0
  197. package/src/validate/builtin/access.ts +642 -0
  198. package/src/validate/builtin/daylight.ts +321 -0
  199. package/src/validate/builtin/door-column-collisions.ts +266 -0
  200. package/src/validate/builtin/envelope.ts +227 -0
  201. package/src/validate/builtin/freeze.ts +19 -0
  202. package/src/validate/builtin/index.ts +156 -0
  203. package/src/validate/builtin/site.ts +445 -0
  204. package/src/validate/builtin/vertical-runs.ts +390 -0
  205. package/src/validate/contracts.ts +240 -0
  206. package/src/validate/index.ts +45 -99
  207. package/src/vocabulary.ts +9 -0
  208. package/dist/validate/access.d.ts +0 -6
  209. package/dist/validate/access.d.ts.map +0 -1
  210. package/dist/validate/access.js +0 -238
  211. package/dist/validate/access.js.map +0 -1
  212. package/dist/validate/envelope.d.ts +0 -4
  213. package/dist/validate/envelope.d.ts.map +0 -1
  214. package/dist/validate/envelope.js +0 -55
  215. package/dist/validate/envelope.js.map +0 -1
  216. package/dist/validate/light.d.ts +0 -6
  217. package/dist/validate/light.d.ts.map +0 -1
  218. package/dist/validate/light.js +0 -28
  219. package/dist/validate/light.js.map +0 -1
  220. package/dist/validate/runs.d.ts +0 -16
  221. package/dist/validate/runs.d.ts.map +0 -1
  222. package/dist/validate/runs.js +0 -60
  223. package/dist/validate/runs.js.map +0 -1
  224. package/dist/validate/site.d.ts +0 -6
  225. package/dist/validate/site.d.ts.map +0 -1
  226. package/dist/validate/site.js +0 -63
  227. package/dist/validate/site.js.map +0 -1
  228. package/spec/README.md +0 -28
  229. package/spec/canonical-json.md +0 -98
  230. package/spec/composition.md +0 -121
  231. package/spec/derivation.md +0 -393
  232. package/spec/en/README.md +0 -30
  233. package/spec/en/canonical-json.md +0 -101
  234. package/spec/en/composition.md +0 -121
  235. package/spec/en/derivation.md +0 -393
  236. package/spec/en/language.md +0 -164
  237. package/spec/en/notation-v0.md +0 -145
  238. package/spec/en/scope.md +0 -229
  239. package/spec/en/semantics.md +0 -132
  240. package/spec/en/tools.md +0 -108
  241. package/spec/en/validation.md +0 -79
  242. package/spec/en/vocabulary.md +0 -103
  243. package/spec/language.md +0 -163
  244. package/spec/notation-v0.md +0 -184
  245. package/spec/scope.md +0 -229
  246. package/spec/semantics.md +0 -130
  247. package/spec/tools.md +0 -106
  248. package/spec/validation.md +0 -79
  249. package/spec/vocabulary.md +0 -114
  250. package/src/validate/access.ts +0 -279
  251. package/src/validate/envelope.ts +0 -59
  252. package/src/validate/light.ts +0 -43
  253. package/src/validate/runs.ts +0 -87
  254. package/src/validate/site.ts +0 -84
package/src/mcp.ts CHANGED
@@ -8,26 +8,30 @@
8
8
 
9
9
  import { mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs";
10
10
  import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
11
+ import { daylightInputs } from "./core/light.js";
12
+ import { polygonAreaM2 } from "./core/model.js";
13
+ import { check } from "./core/diagnose.js";
14
+ import { siteReport } from "./core/site.js";
15
+ import { assess } from "./validate/assessment.js";
16
+ import { createSchematicRegistry, SCHEMATIC_PROFILE_ID } from "./validate/builtin/index.js";
17
+ import { checkDiagnostics } from "./diagnostics.js";
18
+ import { svgPlan } from "./draw/index.js";
19
+ import { doorsBetween } from "./graph.js";
11
20
  import {
12
21
  areaM2,
13
22
  isIndoor,
14
- daylightInputs,
15
- validate,
16
23
  displayName,
17
- doorsBetween,
18
24
  effectiveUse,
25
+ isOutside,
19
26
  isSemiOutdoor,
27
+ isVoid,
20
28
  levelsSorted,
21
29
  newUids,
22
- polygonAreaM2,
23
30
  toCanonical,
24
31
  zoneAreaM2,
25
32
  type Model,
26
33
  type Space,
27
- } from "./index.js";
28
- import { check, checkDiagnostics } from "./core/diagnose.js";
29
- import { svgPlan } from "./draw/plan.js";
30
- import { siteReport } from "./core/site.js";
34
+ } from "./model.js";
31
35
  import { parseFile, parseFileWith } from "./parse-file.js";
32
36
 
33
37
  // ---- モデルの読み込みと要約 ----
@@ -36,9 +40,30 @@ function load(file: string): Model {
36
40
  return parseFile(resolve(file));
37
41
  }
38
42
 
39
- /** 合成に参加した全レイヤー — 要素の有無によらずModelが記録する (grid/levelだけの層も落ちない) */
40
- function layerFiles(model: Model, entry: string): string[] {
41
- return [...new Set([resolve(entry), ...model.layers])].sort();
43
+ /**
44
+ * Every layer that took part in the composition — the Model records them all, whether or not
45
+ * they carry elements (a layer holding only `grid`/`level` is not dropped).
46
+ *
47
+ * The entry is always index 0 (`ingestLayer` pushes every layer). **Do not add the spelled
48
+ * `resolve(entry)`** — layer identity is filesystem identity, so adding a different spelling
49
+ * (a symlink, another letter case) counts one layer twice.
50
+ *
51
+ * **The order is strength order, which is what `model.layers` already is** — never sorted. The
52
+ * tool says "in strength order" and `koyu layers` prints the same order; sorting by path here made
53
+ * the two disagree about the same question, and strength is the answer an agent needs (it decides
54
+ * which layer's opinion wins).
55
+ */
56
+ function layerFiles(model: Model): string[] {
57
+ return [...model.layers];
58
+ }
59
+
60
+ /** A path as the filesystem sees it; the spelling if it cannot be resolved — the same rule as layer identity (`parse-file.ts`) */
61
+ function real(path: string): string {
62
+ try {
63
+ return realpathSync.native(path);
64
+ } catch {
65
+ return path;
66
+ }
42
67
  }
43
68
 
44
69
  /** entryディレクトリ境界の検査 — 文字列prefixではなく相対パスで判定する (ADR-0013) */
@@ -52,7 +77,7 @@ function assertInside(entryDir: string, targetDir: string): void {
52
77
  function summarize(model: Model, file: string): unknown {
53
78
  const rooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level);
54
79
  const indoor = rooms.filter((s) => isIndoor(model, s));
55
- const semi = rooms.filter((s) => s.type !== "void" && isSemiOutdoor(model, s));
80
+ const semi = rooms.filter((s) => !isVoid(s) && isSemiOutdoor(model, s));
56
81
  const byLevel: Record<string, { rooms: number; subtotalM2: number }> = {};
57
82
  for (const lv of levelsSorted(model)) {
58
83
  const rs = indoor.filter((s) => s.level === lv.name);
@@ -71,7 +96,7 @@ function summarize(model: Model, file: string): unknown {
71
96
  return {
72
97
  name: model.name,
73
98
  unit: model.unit,
74
- layers: layerFiles(model, file),
99
+ layers: layerFiles(model),
75
100
  levels: levelsSorted(model).map((l) => ({
76
101
  name: l.name,
77
102
  z: l.z,
@@ -108,10 +133,15 @@ function summarize(model: Model, file: string): unknown {
108
133
  function spaceInfo(model: Model, s: Space): unknown {
109
134
  return {
110
135
  path: s.path,
111
- type: s.type,
136
+ // 型は任意の自由なラベルなので、書かれていなければ鍵ごと出ない。
137
+ // **構成の事実はこの語ではなく下の二つが答える** — 型が無い空間について
138
+ // 「外部か」「吹抜けか」を消費側が推測できてしまうと、廃止した推定が戻る
139
+ ...(s.type !== undefined ? { type: s.type } : {}),
112
140
  name: displayName(s),
113
141
  level: s.level,
114
142
  areaM2: areaM2(s),
143
+ ...(isOutside(s) ? { outside: true } : {}),
144
+ ...(isVoid(s) ? { void: true } : {}),
115
145
  semiOutdoor: isSemiOutdoor(model, s),
116
146
  ...(s.file ? { layer: s.file } : {}),
117
147
  };
@@ -155,7 +185,9 @@ const TOOLS: Record<string, Tool> = {
155
185
  spaces: m.spaces.size,
156
186
  boundaries: m.boundaries.length,
157
187
  ...r,
158
- // 構造化診断 (ADR-0016) — errors/warningsの文字列と同件・同順。code/severity/path/relatedつき
188
+ // 構造化診断 (ADR-0016) — errors と warnings を足したものと同件。並びは走査の順で、
189
+ // errors/warnings はそれを severity で二本に割ったものなので、連結して添字で対応させてはならない。
190
+ // code/severity/path/relatedつき
159
191
  diagnostics: checkDiagnostics(m),
160
192
  };
161
193
  },
@@ -166,7 +198,7 @@ const TOOLS: Record<string, Tool> = {
166
198
  run: (a) => {
167
199
  const file = str(a.file, "file");
168
200
  const m = load(file);
169
- return layerFiles(m, file).map((f) => ({ file: f, source: readFileSync(f, "utf8") }));
201
+ return layerFiles(m).map((f) => ({ file: f, source: readFileSync(f, "utf8") }));
170
202
  },
171
203
  },
172
204
  write_layer: {
@@ -184,10 +216,13 @@ const TOOLS: Record<string, Tool> = {
184
216
  run: (a) => {
185
217
  const file = str(a.file, "file");
186
218
  const content = str(a.content, "content");
187
- const entryDir = resolve(dirname(resolve(file)));
219
+ // Resolve to the real path: it stops a spelling that goes through a symlink from slipping
220
+ // past the boundary check, and it matches the identity the composition counts layers by
221
+ // (mismatch would make the gatekeeper validate stale content)
222
+ const entryDir = real(resolve(dirname(resolve(file))));
188
223
  const target = resolve(entryDir, str(a.layer, "layer"));
189
224
  if (!target.endsWith(".muro")) throw new Error("Only .muro files can be written");
190
- assertInside(entryDir, dirname(target));
225
+ assertInside(entryDir, real(dirname(target)));
191
226
  // 門番は書き込みの前 — 差し替え内容で仮想合成し、parse不能なら原本に触れない (ADR-0013)。
192
227
  // 合成に参加しないファイルの内容は検証されない (importされた時のcheckが捕まえる)
193
228
  let m: Model;
@@ -279,37 +314,52 @@ const TOOLS: Record<string, Tool> = {
279
314
  },
280
315
  validate: {
281
316
  description:
282
- "Architectural verdicts: daylight, envelope continuity, stair proportions, slopes, reachability, column/door collisions, and the site. **This is a different surface from the check guarantee** — findings carry rule/level, never code/severity. The surface grows and is not frozen",
283
- schema: { type: "object", properties: FILE_PROP, required: ["file"] },
317
+ "Architectural verdicts under an explicit rule profile: daylight, envelope continuity, stair proportions, slopes, reachability, column/door collisions, and the site. Returns a full AssessmentReport — the profile and rule identities, every rule's outcome, the evidence behind it, and a summary that keeps pass, not-applicable, indeterminate and error apart. **A different surface from the check guarantee**, and not frozen. `profile` is required: no jurisdiction or effective date is inferred",
318
+ schema: {
319
+ type: "object",
320
+ properties: {
321
+ ...FILE_PROP,
322
+ profile: {
323
+ type: "string",
324
+ description: `Rule profile id. koyu ships one: ${SCHEMATIC_PROFILE_ID.id}`,
325
+ },
326
+ asOf: {
327
+ type: "string",
328
+ description: "Effective date as YYYY-MM-DD. Not read from the clock, so the same input judges the same way twice",
329
+ },
330
+ },
331
+ required: ["file", "profile", "asOf"],
332
+ },
284
333
  run: (a) => {
285
334
  const m = load(str(a.file, "file"));
286
- const findings = validate(m);
287
- return {
288
- findings,
289
- violations: findings.filter((f) => f.level === "violation").length,
290
- cautions: findings.filter((f) => f.level === "caution").length,
291
- note: "These are verdicts, not the structural-consistency guarantee of koyu check",
292
- };
335
+ const profile = str(a.profile, "profile");
336
+ if (profile !== SCHEMATIC_PROFILE_ID.id) {
337
+ throw new Error(`Unknown profile: ${profile} (koyu ships one: ${SCHEMATIC_PROFILE_ID.id})`);
338
+ }
339
+ return assess(m, {
340
+ registry: createSchematicRegistry(),
341
+ profile: SCHEMATIC_PROFILE_ID,
342
+ context: { schema: "koyu-context/1", asOf: str(a.asOf, "asOf"), values: {} },
343
+ });
293
344
  },
294
345
  },
295
346
  site: {
296
- description: "Site query: site area (declared against derived), road frontage, footprint, and the coverage and floor-area ratios",
347
+ description:
348
+ "Site query: site area (declared against derived), road frontage, footprint, and the coverage and floor-area ratios. **Numbers only** — whether the declared and derived areas agree closely enough is a verdict, and comes from the validate tool",
297
349
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
298
350
  run: (a) => {
351
+ // The ratios and their rounding belong to core, which is also what the site rules read.
352
+ // Dividing here again is how an adapter and a rule drift apart.
299
353
  const r = siteReport(load(str(a.file, "file")));
300
- const site = r.declaredArea ?? r.derivedArea;
301
354
  return {
302
355
  ...(r.siteZone ? { siteZone: r.siteZone.path } : {}),
303
356
  ...(r.polygon ? { polygonVertices: r.polygon.points.length } : {}),
304
357
  declaredAreaM2: r.declaredArea,
305
358
  derivedAreaM2: r.derivedArea,
306
- ...(r.declaredArea !== undefined && r.derivedArea !== undefined
307
- ? { areaMatch: Math.abs(r.declaredArea - r.derivedArea) < 0.05 }
308
- : {}),
309
359
  footprintM2: r.footprint,
310
360
  totalFloorM2: r.totalFloor,
311
- coverageRatio: site ? Math.round((r.footprint / site) * 1000) / 10 : undefined,
312
- floorAreaRatio: site ? Math.round((r.totalFloor / site) * 1000) / 10 : undefined,
361
+ coverageRatio: r.coveragePercent,
362
+ floorAreaRatio: r.floorAreaRatioPercent,
313
363
  roads: r.roads.map((rd) => ({
314
364
  path: rd.road.path,
315
365
  name: displayName(rd.road),
@@ -365,7 +415,7 @@ function handle(msg: Json): void {
365
415
  result(id, {
366
416
  protocolVersion: (params.protocolVersion as string) ?? "2025-06-18",
367
417
  capabilities: { tools: {} },
368
- serverInfo: { name: "koyu", version: "0.16.0" },
418
+ serverInfo: { name: "koyu", version: "0.18.0" },
369
419
  instructions:
370
420
  "Server for koyu, a space-first architectural description. Grasp the building with model_summary, read the original layers with layers, and edit with write_layer. check is the gatekeeper of the build and returns errors tagged layer:line — it guarantees structural consistency only. validate delivers the architectural verdicts, which are a separate and unfrozen surface. doors/light/site/spaces are different questions put to the same description. Form (plan_svg) is generated, never written.",
371
421
  });
package/src/model.ts ADDED
@@ -0,0 +1,43 @@
1
+ // Public model surface. Keep this facade explicit: adding an export is adding a package promise.
2
+
3
+ export type {
4
+ Area,
5
+ Asset,
6
+ Attrs,
7
+ AttrValue,
8
+ Boundary,
9
+ BoundaryKind,
10
+ Column,
11
+ ColumnDecl,
12
+ DrawnLine,
13
+ Edge,
14
+ GridAxis,
15
+ GridRef,
16
+ Level,
17
+ Model,
18
+ Opening,
19
+ Pt,
20
+ Rect,
21
+ Seg,
22
+ SitePolygon,
23
+ Space,
24
+ Zone,
25
+ } from "./core/model.js";
26
+
27
+ export {
28
+ areaM2,
29
+ DEFAULT_LANGUAGE_VERSION,
30
+ displayName,
31
+ effectiveUse,
32
+ heff,
33
+ isCoveredAbove,
34
+ isIndoor,
35
+ isOutside,
36
+ isSemiOutdoor,
37
+ isVoid,
38
+ levelsSorted,
39
+ newUids,
40
+ SUPPORTED_LANGUAGE_VERSIONS,
41
+ toCanonical,
42
+ zoneAreaM2,
43
+ } from "./core/model.js";
package/src/parse-file.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // パーサ本体 (parse.ts) は純粋で、fsはこの薄い層だけが知る。
3
3
  // ブラウザ (ugatsu等) は parseFiles (仮想ファイル群) を使う。
4
4
 
5
- import { readFileSync } from "node:fs";
5
+ import { readFileSync, realpathSync } from "node:fs";
6
6
  import { dirname, resolve } from "node:path";
7
7
  import type { Model } from "./core/model.js";
8
8
  import { parseWith } from "./core/parse.js";
@@ -21,8 +21,22 @@ export function parseFileWith(
21
21
  overlay?: (absPath: string) => string | undefined,
22
22
  ): Model {
23
23
  return parseWith((from, ref) => {
24
- const key = from === undefined ? resolve(ref) : resolve(dirname(from), ref);
25
- const src = overlay?.(key) ?? readFileSync(key, "utf8");
24
+ const spelled = from === undefined ? resolve(ref) : resolve(dirname(from), ref);
25
+ // **Layer identity is filesystem identity, not spelling.** Deciding it by spelling composes
26
+ // one file twice when it arrives through a symlink or in different letter case, breaking the
27
+ // promise that a layer imported twice is still composed once (rule 1) — in practice it failed
28
+ // with `grid X is declared once`. A path that does not exist yet (the overlay holds its
29
+ // content) has no realpath, so the spelling stands as its identity.
30
+ // `.native` asks the OS: on a case-insensitive filesystem (the macOS default) the JS
31
+ // implementation returns the spelling as given, so `B.muro` and `b.muro` become two layers
32
+ let key = spelled;
33
+ try {
34
+ key = realpathSync.native(spelled);
35
+ } catch {
36
+ /* not on disk yet — the spelling is the identity */
37
+ }
38
+ // The overlay answers to either spelling — the MCP gatekeeper matches on the resolved one
39
+ const src = overlay?.(spelled) ?? overlay?.(key) ?? readFileSync(key, "utf8");
26
40
  return { key, src };
27
41
  }, filePath);
28
42
  }