@kensnzk/koyu 0.16.0 → 0.17.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 (148) hide show
  1. package/README.ja.md +12 -8
  2. package/README.md +13 -10
  3. package/dist/cli.js +14 -11
  4. package/dist/cli.js.map +1 -1
  5. package/dist/core/derive.d.ts +13 -8
  6. package/dist/core/derive.d.ts.map +1 -1
  7. package/dist/core/derive.js +19 -13
  8. package/dist/core/derive.js.map +1 -1
  9. package/dist/core/diagnose.d.ts +4 -3
  10. package/dist/core/diagnose.d.ts.map +1 -1
  11. package/dist/core/diagnose.js +46 -11
  12. package/dist/core/diagnose.js.map +1 -1
  13. package/dist/core/diff.d.ts +3 -2
  14. package/dist/core/diff.d.ts.map +1 -1
  15. package/dist/core/diff.js +8 -5
  16. package/dist/core/diff.js.map +1 -1
  17. package/dist/core/fabric.d.ts +1 -3
  18. package/dist/core/fabric.d.ts.map +1 -1
  19. package/dist/core/fabric.js +8 -8
  20. package/dist/core/fabric.js.map +1 -1
  21. package/dist/core/graph.d.ts +2 -2
  22. package/dist/core/graph.d.ts.map +1 -1
  23. package/dist/core/graph.js +12 -5
  24. package/dist/core/graph.js.map +1 -1
  25. package/dist/core/light.d.ts.map +1 -1
  26. package/dist/core/light.js +2 -2
  27. package/dist/core/light.js.map +1 -1
  28. package/dist/core/model.d.ts +59 -10
  29. package/dist/core/model.d.ts.map +1 -1
  30. package/dist/core/model.js +128 -26
  31. package/dist/core/model.js.map +1 -1
  32. package/dist/core/parse.d.ts.map +1 -1
  33. package/dist/core/parse.js +83 -82
  34. package/dist/core/parse.js.map +1 -1
  35. package/dist/core/poly.d.ts +0 -4
  36. package/dist/core/poly.d.ts.map +1 -1
  37. package/dist/core/poly.js +1 -5
  38. package/dist/core/poly.js.map +1 -1
  39. package/dist/core/site.d.ts.map +1 -1
  40. package/dist/core/site.js +2 -2
  41. package/dist/core/site.js.map +1 -1
  42. package/dist/core/tolerance.d.ts +1 -1
  43. package/dist/core/tolerance.js +2 -2
  44. package/dist/core/tolerance.js.map +1 -1
  45. package/dist/core/vertical.d.ts +9 -2
  46. package/dist/core/vertical.d.ts.map +1 -1
  47. package/dist/core/vertical.js +8 -1
  48. package/dist/core/vertical.js.map +1 -1
  49. package/dist/core/vocabulary.d.ts.map +1 -1
  50. package/dist/core/vocabulary.js +17 -5
  51. package/dist/core/vocabulary.js.map +1 -1
  52. package/dist/draw/index.js +1 -1
  53. package/dist/draw/index.js.map +1 -1
  54. package/dist/draw/plan.js +5 -5
  55. package/dist/draw/plan.js.map +1 -1
  56. package/dist/index.d.ts +3 -2
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +17 -11
  59. package/dist/index.js.map +1 -1
  60. package/dist/mcp.js +43 -12
  61. package/dist/mcp.js.map +1 -1
  62. package/dist/parse-file.d.ts.map +1 -1
  63. package/dist/parse-file.js +18 -3
  64. package/dist/parse-file.js.map +1 -1
  65. package/dist/validate/access.d.ts.map +1 -1
  66. package/dist/validate/access.js +23 -13
  67. package/dist/validate/access.js.map +1 -1
  68. package/dist/validate/envelope.d.ts.map +1 -1
  69. package/dist/validate/envelope.js +3 -3
  70. package/dist/validate/envelope.js.map +1 -1
  71. package/dist/validate/index.d.ts +1 -1
  72. package/dist/validate/index.d.ts.map +1 -1
  73. package/dist/validate/index.js +1 -1
  74. package/dist/validate/index.js.map +1 -1
  75. package/dist/validate/light.js +1 -1
  76. package/dist/validate/light.js.map +1 -1
  77. package/dist/validate/site.d.ts.map +1 -1
  78. package/dist/validate/site.js +2 -2
  79. package/dist/validate/site.js.map +1 -1
  80. package/editors/vscode/syntaxes/koyu.tmLanguage.json +2 -2
  81. package/examples/basement/main.muro +3 -3
  82. package/examples/complex/main.muro +1 -1
  83. package/examples/complex/podium.muro +1 -1
  84. package/examples/complex/site.muro +6 -6
  85. package/examples/house/L2.muro +1 -1
  86. package/examples/house/main.muro +1 -1
  87. package/examples/house/site.muro +4 -4
  88. package/examples/house.muro +6 -6
  89. package/examples/mansion.muro +2 -2
  90. package/examples/office.muro +3 -3
  91. package/examples/steps/04-exterior.muro +1 -1
  92. package/examples/steps/05-two-storeys.muro +1 -1
  93. package/examples/steps/06-finished.muro +2 -2
  94. package/examples/tower/L2.muro +1 -1
  95. package/examples/tower/main.muro +1 -1
  96. package/examples/tower/site.muro +4 -4
  97. package/examples/twin/main.muro +1 -1
  98. package/examples/twin/podium.muro +4 -4
  99. package/examples/twin/site.muro +8 -8
  100. package/examples/two-rooms.canonical.json +4 -4
  101. package/examples/two-rooms.muro +2 -2
  102. package/package.json +5 -5
  103. package/src/cli.ts +15 -10
  104. package/src/core/derive.ts +32 -15
  105. package/src/core/diagnose.ts +63 -16
  106. package/src/core/diff.ts +10 -6
  107. package/src/core/fabric.ts +18 -9
  108. package/src/core/graph.ts +19 -5
  109. package/src/core/light.ts +2 -2
  110. package/src/core/model.ts +141 -31
  111. package/src/core/parse.ts +100 -85
  112. package/src/core/poly.ts +1 -8
  113. package/src/core/site.ts +2 -2
  114. package/src/core/tolerance.ts +2 -2
  115. package/src/core/vertical.ts +10 -3
  116. package/src/core/vocabulary.ts +18 -5
  117. package/src/draw/index.ts +1 -1
  118. package/src/draw/plan.ts +5 -5
  119. package/src/index.ts +30 -9
  120. package/src/mcp.ts +44 -11
  121. package/src/parse-file.ts +17 -3
  122. package/src/validate/access.ts +24 -12
  123. package/src/validate/envelope.ts +3 -3
  124. package/src/validate/index.ts +2 -2
  125. package/src/validate/light.ts +1 -1
  126. package/src/validate/site.ts +2 -2
  127. package/spec/README.md +0 -28
  128. package/spec/canonical-json.md +0 -98
  129. package/spec/composition.md +0 -121
  130. package/spec/derivation.md +0 -393
  131. package/spec/en/README.md +0 -30
  132. package/spec/en/canonical-json.md +0 -101
  133. package/spec/en/composition.md +0 -121
  134. package/spec/en/derivation.md +0 -393
  135. package/spec/en/language.md +0 -164
  136. package/spec/en/notation-v0.md +0 -145
  137. package/spec/en/scope.md +0 -229
  138. package/spec/en/semantics.md +0 -132
  139. package/spec/en/tools.md +0 -108
  140. package/spec/en/validation.md +0 -79
  141. package/spec/en/vocabulary.md +0 -103
  142. package/spec/language.md +0 -163
  143. package/spec/notation-v0.md +0 -184
  144. package/spec/scope.md +0 -229
  145. package/spec/semantics.md +0 -130
  146. package/spec/tools.md +0 -106
  147. package/spec/validation.md +0 -79
  148. package/spec/vocabulary.md +0 -114
package/src/core/poly.ts CHANGED
@@ -1,4 +1,4 @@
1
- // koyu — 凸片の幾何 (ADR-0022 / spec/derivation.md §1)
1
+ // koyu — 凸片の幾何 (ADR-0022 / docs/reference/form/index.md)
2
2
  //
3
3
  // 空間の形は**凸片の集合** (`Pt[][]`) である (ADR-0022)。矩形はその入口の綴りにすぎない。
4
4
  // この層が存在しなかったあいだ、面積・被覆・切り分けの計算が model / graph / fabric /
@@ -110,9 +110,6 @@ export function splitByRect(pieces: Pt[][], w: Rect): { inside: Pt[][]; outside:
110
110
  return { inside, outside };
111
111
  }
112
112
 
113
- /** 軸平行の窓の内側だけ */
114
- export const clipToRect = (poly: Pt[], w: Rect): Pt[] => splitByRect([poly], w).inside[0] ?? [];
115
-
116
113
  /**
117
114
  * 凸片から凸片群を引く (差集合)。結果も凸片の集合。
118
115
  *
@@ -168,10 +165,6 @@ export function unionArea(pieces: Pt[][]): number {
168
165
  return total;
169
166
  }
170
167
 
171
- /** 凸片の集合から凸片群を引く */
172
- export const subtractAll = (pieces: Pt[][], covers: Pt[][]): Pt[][] =>
173
- pieces.flatMap((p) => subtract(p, covers));
174
-
175
168
  // ---- 窓 (どの範囲で測り、どの範囲を切るか) ----
176
169
 
177
170
  /**
package/src/core/site.ts CHANGED
@@ -8,7 +8,6 @@ import { segmentLength, segmentsFor } from "./graph.js";
8
8
  import {
9
9
  areaM2,
10
10
  isIndoor,
11
- isSemiOutdoor,
12
11
  polygonAreaM2,
13
12
  regionOf,
14
13
  unionAreaM2,
@@ -16,6 +15,7 @@ import {
16
15
  type SitePolygon,
17
16
  type Space,
18
17
  type Zone,
18
+ isOutside
19
19
  } from "./model.js";
20
20
 
21
21
  export interface RoadFrontage {
@@ -67,7 +67,7 @@ export function siteReport(model: Model): SiteReport {
67
67
  // 建物の外壁が道路に面していても、それは接道ではない
68
68
  const roads: RoadFrontage[] = [];
69
69
  for (const road of spaces) {
70
- if (road.type !== "exterior" || typeof road.attrs["road"] !== "number") continue;
70
+ if (!isOutside(road) || typeof road.attrs["road"] !== "number") continue;
71
71
  let frontage = 0;
72
72
  for (const b of model.boundaries) {
73
73
  const otherPath = b.a === road.path ? b.b : b.b === road.path ? b.a : undefined;
@@ -6,7 +6,7 @@
6
6
  // あいだ、`poly.ts` の EPS と `graph.ts` の EPS は同じ 0.5 を別々に持ち、`vertical.ts` は
7
7
  // 1 を四箇所に直値で書き、`drawnShare` は軸平行の判定に graph の EPS ではなく直値の 0.5 を
8
8
  // 使っていた。どれも同じ値なので事故は起きていないが、**一つを動かしたときに何が動くのかを
9
- // 誰も言えない**状態だった。許容値は導出の規則の一部であり (spec/derivation.md §6)、
9
+ // 誰も言えない**状態だった。許容値は導出の規則の一部であり (docs/reference/form/index.md)、
10
10
  // 規則が消費者ごとに違えば同じ原本から違う建物が出る。
11
11
  //
12
12
  // 座標は mm の整数が基本である。だから長さの許容は 0.5mm — 「これより細かい差は同一」の線が、
@@ -41,7 +41,7 @@ export const PARALLEL_EPS = 1e-9;
41
41
  export const POINT_EPS = 1;
42
42
 
43
43
  /**
44
- * 許容値の台帳。**spec/derivation.md §6 の表の唯一の出所である** —
44
+ * 許容値の台帳。**docs/reference/form/index.md の表の唯一の出所である** —
45
45
  * `test/derive.test.ts` が表とここの一致を縛る。
46
46
  */
47
47
  export const TOLERANCES: Readonly<Record<string, number>> = {
@@ -37,6 +37,13 @@ export const STEP_MARK = 400;
37
37
  export const TREAD_SOLID = 200;
38
38
  /** 斜路・エスカレーター床版の厚さ mm */
39
39
  export const SLAB_T = 200;
40
+ /**
41
+ * The shortest visible run interval that still carries a direction arrow, in mm.
42
+ *
43
+ * Below this the arrow would be longer than what it points along. The comparison is strict, so an
44
+ * interval of exactly this length carries none.
45
+ */
46
+ export const ARROW_SPAN_MIN = 900;
40
47
 
41
48
  /** 走りと踊り場の一区間。局所座標は t (走り方向) と s (進行方向の左からの幅) */
42
49
  export interface RunPart {
@@ -509,7 +516,7 @@ export interface Seg2 {
509
516
 
510
517
  /**
511
518
  * 進む向きを指す線分。**文字列は持たない** — "UP" と "DN" は言葉であって形ではない
512
- * (spec/scope.md §6)。この面で人が上るかどうかを `up` が言い、注記は描画側が組む
519
+ * (docs/reference/scope.md)。この面で人が上るかどうかを `up` が言い、注記は描画側が組む
513
520
  */
514
521
  export interface RunArrow extends Seg2 {
515
522
  /** この面でこの走りを進むと上るか */
@@ -518,7 +525,7 @@ export interface RunArrow extends Seg2 {
518
525
 
519
526
  /**
520
527
  * そのレベルで切った縦動線の作図。平面図とビュアーが共有する唯一の答え。
521
- * **色も線種も注記文字列も持たない** (spec/scope.md §6 / spec/derivation.md §5)
528
+ * **色も線種も注記文字列も持たない** (docs/reference/scope.md / docs/reference/form/index.md)
522
529
  */
523
530
  export interface RunDraw {
524
531
  path: string;
@@ -695,7 +702,7 @@ function drawRun(
695
702
  const isFirst = i === run.parts.findIndex((q) => q.kind === "flight");
696
703
  const isLast = i === run.parts.map((q) => q.kind).lastIndexOf("flight");
697
704
  const wantArrow = run.device === "escalator" ? true : dir === "up" ? isFirst : isLast;
698
- if (wantArrow && hi - lo > 900) {
705
+ if (wantArrow && hi - lo > ARROW_SPAN_MIN) {
699
706
  const c = (p.s0 + p.s1) / 2;
700
707
  // **矢印は人の進む向きだけから決まる。**reversed が「t の減る向きに進む」、
701
708
  // 昇り降りは進む先の高さで決まる。エスカレーターは機械の向きが固定なので
@@ -1,8 +1,9 @@
1
- // koyu core — 属性の台帳 (spec/vocabulary.md の写しであり、実装の唯一の出所)
1
+ // koyu core — 属性の台帳 (docs/reference/muro/attributes.md の写しであり、実装の唯一の出所)
2
2
  //
3
- // # 属性の三層 (spec/scope.md §7)
3
+ // # 属性の三層 (docs/reference/scope.md)
4
4
  //
5
- // 構造 (structure) パス・型・区画・レベル・関係の相手・kind。**必ず見る**。
5
+ // 構造 (structure) パス・区画・レベル・関係の相手・kind。**必ず見る**。
6
+ // 空間の**型は入らない** — 自由なラベルであり core は読まない (ADR-0051)
6
7
  // parse が typed field へ持ち上げるので、check の時点では attrs に残らない
7
8
  // 解釈 (interpreted) 台帳が値域を定義し、**見る**。h / at / daylight / road / style …
8
9
  // 運搬 (carry) **見ない。**運ぶだけ。spec / fire / sound / floor / sill …
@@ -71,10 +72,22 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
71
72
  level: structure(), // 所属レベルの明示 (メゾネット)
72
73
  w: structure(), // 帯 (band) の要素の寸法。帯の外には書けない
73
74
 
75
+ // 構成の事実 — **core が空間について読む語は、この二つだけである**
76
+ //
77
+ // かつては型の位置に `exterior` `void` と書いた。型の位置は開かれた語彙なので、
78
+ // `exteriorr` の一字が外部を屋内に変え、実測で延床が 16.20㎡ から 32.40㎡ へ倍増しながら
79
+ // check は緑だった。守りは二語の編集距離1だけを拒むヒューリスティックで、
80
+ // `void` の距離2には `road` と `wood` — 人が正当に書く語 — が入るので広げられなかった。
81
+ //
82
+ // 台帳へ移せば、綴りを守るのは ATT03 (未知のキー) と ATT02 (値域) になる。
83
+ // 開かれた語彙は殺さない — 型の位置は今や完全に自由で、core はそこを一切読まない。
84
+ outside: one(0, 1), // 1 = 建物の外部。延べ面積に算入せず、領域が無くてよく、接道の相手になる
85
+ void: one(0, 1), // 1 = 吹抜け。床が無いので延べ面積に算入せず、床も張られない
86
+
74
87
  // 解釈 — core が読む
75
88
  h: num(), // 天井高 mm。高さ不変量と矩計が読む
76
89
  use: free(), // 集計軸。zone から継承
77
- road: num(), // exterior の幅員 mm。接道の導出
90
+ road: num(), // outside:1 の幅員 mm。接道の導出
78
91
  daylight: free(), // 採光の問いの対象 (ADR-0020)。値域は DAY01 が守るので台帳では重ねない
79
92
  ceiling: one(0, 1), // 0 = 天井を張らない (ADR-0024)
80
93
  uid: free(), // 永続同一性トークン (ADR-0015)。UID01-03 が守る
@@ -135,7 +148,7 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
135
148
 
136
149
  // 解釈
137
150
  style: one("hinged", "sliding", "auto"), // 平面の建具表現が変わる
138
- name: free(), // **境界の中で一意な名** — 開口の同一性の鍵 (spec/scope.md §5)
151
+ name: free(), // **境界の中で一意な名** — 開口の同一性の鍵 (docs/reference/scope.md)
139
152
 
140
153
  // 運搬
141
154
  sill: carry(), // 窓台高
package/src/draw/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // koyu — 表現の面 (`@kensnzk/koyu/draw`)
2
2
  //
3
- // **ここは凍らない** (spec/scope.md §8)。サブコマンド `plan` / `axo` の**面** —
3
+ // **ここは凍らない** (docs/reference/scope.md)。サブコマンド `plan` / `axo` の**面** —
4
4
  // 名前・引数・終了コード — は凍るが、出てくる SVG の中身は約束の外にある。
5
5
  // 見た目は自由に変えてよく、形は変えない。
6
6
  //
package/src/draw/plan.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  // **ここに形の規則は一つも無い。**壁の厚みも、開口の位置も、扉の吊元も、階段がどこで
4
4
  // 切れるかも、`derive(model)` が返す `Form` に既に入っている (ADR-0040)。この頁が持つのは
5
5
  // 色・線種・線幅・書体・記号・注記の言葉・縮尺・紙面の余白 — すべて**見た目**であり、
6
- // 消費者ごとに違ってよいものである (spec/scope.md §6)。
6
+ // 消費者ごとに違ってよいものである (docs/reference/scope.md)。
7
7
  //
8
8
  // 形と見た目の線引きはこうである。境界線分の座標・壁の厚み・開口で割られた区間・
9
9
  // 扉の軌跡の中心と半径と掃き方向・切断面を跨ぐ位置は Form が持つ。1/4円を破線で描くか、
@@ -79,7 +79,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
79
79
  // 空間の面 — 切断面が気積を切った姿。同色・輪郭なしなのでL字も切られた形も一体に見える。
80
80
  // 半屋外は淡く塗り分け、屋外であることが図から読めるように
81
81
  for (const s of rooms) {
82
- const isVoid = s.type === "void";
82
+ const isVoid = s.void;
83
83
  for (const poly of s.outline) {
84
84
  parts.push(fill(poly, isVoid ? PAPER : s.semiOutdoor ? "#f8f5ec" : ROOM));
85
85
  if (isVoid) {
@@ -160,7 +160,7 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
160
160
  for (const g of form.segs) {
161
161
  if (g.level !== level) continue;
162
162
  parts.push(fill(band(g.segment, g.cx, g.cy, g.w, g.t), "#77716a"));
163
- // `g.boundary` は **Form の境界の添字 = 正準順の添字**である (spec/derivation.md)。
163
+ // `g.boundary` は **Form の境界の添字 = 正準順の添字**である (docs/reference/form/index.md)。
164
164
  // 宣言順の配列を引くと、宣言順を入れ替えただけで注記が別の境界のものになる
165
165
  const spec = ordered[g.boundary]?.segs[g.index]?.attrs["spec"];
166
166
  if (typeof spec === "string") {
@@ -246,9 +246,9 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
246
246
  const cx = sx((r.x1 + r.x2) / 2);
247
247
  const cy = sy((r.y1 + r.y2) / 2);
248
248
  const sub =
249
- s.type === "void"
249
+ s.void
250
250
  ? "void"
251
- : `${esc(s.type)} · ${s.areaM2} m2${s.semiOutdoor ? " · semi-outdoor" : ""}`;
251
+ : `${s.type ? `${esc(s.type)} · ` : ""}${s.areaM2} m2${s.semiOutdoor ? " · semi-outdoor" : ""}`;
252
252
  parts.push(
253
253
  `<text x="${cx}" y="${cy - 4}" text-anchor="middle" font-size="14" fill="${INK}">${esc(displayName(space))}</text>`,
254
254
  `<text x="${cx}" y="${cy + 13}" text-anchor="middle" font-size="10" fill="#8a8171">${sub}</text>`,
package/src/index.ts CHANGED
@@ -2,20 +2,20 @@
2
2
  //
3
3
  // **ここに書き下された名だけが約束である。**`export *` は使わない — モジュールに
4
4
  // export を足した瞬間に、誰も宣言していない約束が凍る面に増えてしまうからである。
5
- // 凍らせる面は、書き下されていなければならない (spec/scope.md §8)。
5
+ // 凍らせる面は、書き下されていなければならない (docs/reference/scope.md)。
6
6
  //
7
7
  // 載せる基準は一つ — **面の外に利用者がいること。**
8
8
  // 1. パッケージの外 (ugatsu / eval / scripts / editors) が実際に呼ぶ
9
9
  // 2. CLI か MCP が答えるものを API からも答えるために要る
10
- // (「CLIが答えるものはすべてこのAPIが答える」— guide/api.md)
11
- // 3. spec が名指しで約束する導出 (scope.md §4・§6 / semantics.md)
10
+ // (「CLIが答えるものはすべてこのAPIが答える」— docs/reference/api/index.md)
11
+ // 3. 公開文書が名指しで約束する導出 (docs/reference/scope.md)
12
12
  // 4. test が契約として固定している
13
13
  // core のモジュール同士が引き合うだけの配管は面ではない。型は、載せた値の署名を
14
14
  // 書き下すのに要るものだけを載せる。
15
15
  //
16
- // この一覧と spec/tools.md の一覧は集合として一致する — test/public-api.test.ts が縛る。
16
+ // この一覧と docs/reference/api/index.md の表は集合として一致する — test/public-api.test.ts が縛る。
17
17
 
18
- // ---- 解析と合成 (spec/composition.md) ----
18
+ // ---- 解析と合成 (docs/reference/muro/import.md) ----
19
19
  export { parse, parseFiles, parseWith, tokenize, type LayerLoader } from "./core/parse.js";
20
20
 
21
21
  // ---- モデルの語彙 — 書かれた構成の型 ----
@@ -44,7 +44,7 @@ export type {
44
44
  } from "./core/model.js";
45
45
 
46
46
  // ---- モデルへの問い・導出・機械形式 ----
47
- // **合否は言わない** (spec/scope.md §4)。数と形を返すところまでが core である
47
+ // **合否は言わない** (docs/reference/scope.md)。数と形を返すところまでが core である
48
48
  export {
49
49
  areaM2,
50
50
  canonicalBoundaryOrder,
@@ -55,7 +55,9 @@ export {
55
55
  heff,
56
56
  isCoveredAbove,
57
57
  isIndoor,
58
+ isOutside,
58
59
  isSemiOutdoor,
60
+ isVoid,
59
61
  levelsSorted,
60
62
  newUids,
61
63
  pointInPolygon,
@@ -100,7 +102,7 @@ export {
100
102
  } from "./core/graph.js";
101
103
 
102
104
  // ---- 形の参照実装 (ADR-0040) — **これが形の唯一の入口である** ----
103
- // Form は見た目を持たない (spec/scope.md §6)。規則は spec/derivation.md が持つ
105
+ // Form は見た目を持たない (docs/reference/scope.md)。規則は docs/reference/form/index.md が持つ
104
106
  // 実体の構成子 (thicken / bandLine / band / columnRect / runPrism) も core が唯一の実装を
105
107
  // 持つ — 芯線と厚みから四辺形や角柱を起こす規則も導出の一部だからである
106
108
  export {
@@ -142,11 +144,14 @@ export { daylightInputs, type DaylightInput } from "./core/light.js";
142
144
 
143
145
  // ---- 縦動線 (ADR-0021) ----
144
146
  export {
147
+ RUN_KEYS,
148
+ runDecls,
145
149
  runDrawsForLevel,
146
150
  runSolids,
147
151
  slopeText,
148
152
  verticalRuns,
149
153
  type RunArrow,
154
+ type RunDecl,
150
155
  type RunDevice,
151
156
  type RunDraw,
152
157
  type RunForm,
@@ -174,12 +179,28 @@ export {
174
179
  type SpaceItem,
175
180
  } from "./core/diff.js";
176
181
 
177
- // ---- 生成 — **凍らない** (spec/scope.md §8)。SVGの中身は約束の外にある ----
182
+ // ---- 属性の台帳 — **書いてよいキーの一覧であって、読むキーの一覧ではない** ----
183
+ //
184
+ // 利用者の側にも境界が要る。台帳を出していなかった間、消費側のアプリは
185
+ // 「この鍵はこの要素に書けるか」を答えるために台帳を手で写すしかなく、写しは必ずずれる。
186
+ // `outside` と `void` を型の位置から台帳へ移した以上、その台帳は読めなければ意味がない。
187
+ export {
188
+ ASSET_ELEM,
189
+ ATTR_LEDGER,
190
+ attrSpec,
191
+ CARRY_NAMESPACE,
192
+ isNamespaced,
193
+ known,
194
+ type AttrSpec,
195
+ type AttrTier,
196
+ } from "./core/vocabulary.js";
197
+
198
+ // ---- 生成 — **凍らない** (docs/reference/scope.md)。SVGの中身は約束の外にある ----
178
199
  // 領域としては `@kensnzk/koyu/draw` にも分けてある
179
200
  export { svgPlan, type PlanOptions } from "./draw/plan.js";
180
201
  export { svgAxo, type AxoOptions } from "./draw/axo.js";
181
202
 
182
- // ---- 検証 — **core ではない。**凍らない・増える・合否を言う (spec/scope.md §3) ----
203
+ // ---- 検証 — **core ではない。**凍らない・増える・合否を言う (docs/reference/scope.md) ----
183
204
  // Finding は Diagnostic と別の型で、フィールド名から違う (rule/level と code/severity)。
184
205
  // 領域としては `@kensnzk/koyu/validate` にも分けてある
185
206
  export {
package/src/mcp.ts CHANGED
@@ -16,7 +16,9 @@ import {
16
16
  displayName,
17
17
  doorsBetween,
18
18
  effectiveUse,
19
+ isOutside,
19
20
  isSemiOutdoor,
21
+ isVoid,
20
22
  levelsSorted,
21
23
  newUids,
22
24
  polygonAreaM2,
@@ -36,9 +38,30 @@ function load(file: string): Model {
36
38
  return parseFile(resolve(file));
37
39
  }
38
40
 
39
- /** 合成に参加した全レイヤー — 要素の有無によらずModelが記録する (grid/levelだけの層も落ちない) */
40
- function layerFiles(model: Model, entry: string): string[] {
41
- return [...new Set([resolve(entry), ...model.layers])].sort();
41
+ /**
42
+ * Every layer that took part in the composition — the Model records them all, whether or not
43
+ * they carry elements (a layer holding only `grid`/`level` is not dropped).
44
+ *
45
+ * The entry is always index 0 (`ingestLayer` pushes every layer). **Do not add the spelled
46
+ * `resolve(entry)`** — layer identity is filesystem identity, so adding a different spelling
47
+ * (a symlink, another letter case) counts one layer twice.
48
+ *
49
+ * **The order is strength order, which is what `model.layers` already is** — never sorted. The
50
+ * tool says "in strength order" and `koyu layers` prints the same order; sorting by path here made
51
+ * the two disagree about the same question, and strength is the answer an agent needs (it decides
52
+ * which layer's opinion wins).
53
+ */
54
+ function layerFiles(model: Model): string[] {
55
+ return [...model.layers];
56
+ }
57
+
58
+ /** A path as the filesystem sees it; the spelling if it cannot be resolved — the same rule as layer identity (`parse-file.ts`) */
59
+ function real(path: string): string {
60
+ try {
61
+ return realpathSync.native(path);
62
+ } catch {
63
+ return path;
64
+ }
42
65
  }
43
66
 
44
67
  /** entryディレクトリ境界の検査 — 文字列prefixではなく相対パスで判定する (ADR-0013) */
@@ -52,7 +75,7 @@ function assertInside(entryDir: string, targetDir: string): void {
52
75
  function summarize(model: Model, file: string): unknown {
53
76
  const rooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level);
54
77
  const indoor = rooms.filter((s) => isIndoor(model, s));
55
- const semi = rooms.filter((s) => s.type !== "void" && isSemiOutdoor(model, s));
78
+ const semi = rooms.filter((s) => !isVoid(s) && isSemiOutdoor(model, s));
56
79
  const byLevel: Record<string, { rooms: number; subtotalM2: number }> = {};
57
80
  for (const lv of levelsSorted(model)) {
58
81
  const rs = indoor.filter((s) => s.level === lv.name);
@@ -71,7 +94,7 @@ function summarize(model: Model, file: string): unknown {
71
94
  return {
72
95
  name: model.name,
73
96
  unit: model.unit,
74
- layers: layerFiles(model, file),
97
+ layers: layerFiles(model),
75
98
  levels: levelsSorted(model).map((l) => ({
76
99
  name: l.name,
77
100
  z: l.z,
@@ -108,10 +131,15 @@ function summarize(model: Model, file: string): unknown {
108
131
  function spaceInfo(model: Model, s: Space): unknown {
109
132
  return {
110
133
  path: s.path,
111
- type: s.type,
134
+ // 型は任意の自由なラベルなので、書かれていなければ鍵ごと出ない。
135
+ // **構成の事実はこの語ではなく下の二つが答える** — 型が無い空間について
136
+ // 「外部か」「吹抜けか」を消費側が推測できてしまうと、廃止した推定が戻る
137
+ ...(s.type !== undefined ? { type: s.type } : {}),
112
138
  name: displayName(s),
113
139
  level: s.level,
114
140
  areaM2: areaM2(s),
141
+ ...(isOutside(s) ? { outside: true } : {}),
142
+ ...(isVoid(s) ? { void: true } : {}),
115
143
  semiOutdoor: isSemiOutdoor(model, s),
116
144
  ...(s.file ? { layer: s.file } : {}),
117
145
  };
@@ -155,7 +183,9 @@ const TOOLS: Record<string, Tool> = {
155
183
  spaces: m.spaces.size,
156
184
  boundaries: m.boundaries.length,
157
185
  ...r,
158
- // 構造化診断 (ADR-0016) — errors/warningsの文字列と同件・同順。code/severity/path/relatedつき
186
+ // 構造化診断 (ADR-0016) — errors と warnings を足したものと同件。並びは走査の順で、
187
+ // errors/warnings はそれを severity で二本に割ったものなので、連結して添字で対応させてはならない。
188
+ // code/severity/path/relatedつき
159
189
  diagnostics: checkDiagnostics(m),
160
190
  };
161
191
  },
@@ -166,7 +196,7 @@ const TOOLS: Record<string, Tool> = {
166
196
  run: (a) => {
167
197
  const file = str(a.file, "file");
168
198
  const m = load(file);
169
- return layerFiles(m, file).map((f) => ({ file: f, source: readFileSync(f, "utf8") }));
199
+ return layerFiles(m).map((f) => ({ file: f, source: readFileSync(f, "utf8") }));
170
200
  },
171
201
  },
172
202
  write_layer: {
@@ -184,10 +214,13 @@ const TOOLS: Record<string, Tool> = {
184
214
  run: (a) => {
185
215
  const file = str(a.file, "file");
186
216
  const content = str(a.content, "content");
187
- const entryDir = resolve(dirname(resolve(file)));
217
+ // Resolve to the real path: it stops a spelling that goes through a symlink from slipping
218
+ // past the boundary check, and it matches the identity the composition counts layers by
219
+ // (mismatch would make the gatekeeper validate stale content)
220
+ const entryDir = real(resolve(dirname(resolve(file))));
188
221
  const target = resolve(entryDir, str(a.layer, "layer"));
189
222
  if (!target.endsWith(".muro")) throw new Error("Only .muro files can be written");
190
- assertInside(entryDir, dirname(target));
223
+ assertInside(entryDir, real(dirname(target)));
191
224
  // 門番は書き込みの前 — 差し替え内容で仮想合成し、parse不能なら原本に触れない (ADR-0013)。
192
225
  // 合成に参加しないファイルの内容は検証されない (importされた時のcheckが捕まえる)
193
226
  let m: Model;
@@ -365,7 +398,7 @@ function handle(msg: Json): void {
365
398
  result(id, {
366
399
  protocolVersion: (params.protocolVersion as string) ?? "2025-06-18",
367
400
  capabilities: { tools: {} },
368
- serverInfo: { name: "koyu", version: "0.16.0" },
401
+ serverInfo: { name: "koyu", version: "0.17.0" },
369
402
  instructions:
370
403
  "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
404
  });
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
  }
@@ -8,11 +8,11 @@
8
8
  //
9
9
  // 直したことと再発しないことは別なので、その四つと「外部へ到達できない室」
10
10
  // 「柱が塞ぐ扉」を判定として置く。**判定は MCP から呼べなければ、機械にとって
11
- // 存在しないに等しい** (spec/validation.md) — スクリプトの中に閉じている限り、
11
+ // 存在しないに等しい** (docs/reference/validate/index.md) — スクリプトの中に閉じている限り、
12
12
  // 同じ誤りは別の建物で何度でも起きる。
13
13
  //
14
14
  // core が持つのは経路そのもの (`doorsBetween` / `passable` / `placeOpening`) で、
15
- // **どの到達不能が問題かを言うのはここである** (spec/scope.md §4)。
15
+ // **どの到達不能が問題かを言うのはここである** (docs/reference/scope.md)。
16
16
 
17
17
  import { passable, placeOpening } from "../core/graph.js";
18
18
  import {
@@ -22,21 +22,32 @@ import {
22
22
  type Boundary,
23
23
  type Model,
24
24
  type Space,
25
+ isOutside,
26
+ isVoid
25
27
  } from "../core/model.js";
26
28
  import { finding, type Finding } from "./index.js";
27
29
 
28
30
  /** 車が通れる開口の最小幅 mm。人の扉 (900) では車は出られない */
29
31
  export const CAR_WIDTH_MIN = 2400;
30
32
 
31
- /** 空間としては連続するが人も車も通り抜けられない型 — どの到達性の問いでも常に避ける */
32
- const IMPASSABLE = new Set(["shaft", "void"]);
33
+ /**
34
+ * 空間としては連続するが人も車も通り抜けられない — どの到達性の問いでも常に避ける。
35
+ *
36
+ * 二つの出所が混ざっている。`void:1` は**宣言**であり、core が構造として読む二語の一つで、
37
+ * 綴りは台帳が守る。`shaft` は**型の語**であり、型の位置は開かれた語彙なので `shaftt` と
38
+ * 書けば黙って通り抜けられるようになる — この面 (検証) は凍らないので当面それでよい、
39
+ * というのが領域の分離の帰結である (docs/reference/scope.md)。core にはもうこの読みは無い。
40
+ */
41
+ function impassable(s: Space): boolean {
42
+ return isVoid(s) || s.type === "shaft";
43
+ }
33
44
 
34
45
  /** 境界を通れるかの判定。人 (passable) と車 (carPassable) で通れる境界が違うので差し替える */
35
46
  type CanPass = (b: Boundary) => boolean;
36
47
 
37
48
  /**
38
49
  * from (複数可) から toSet のどれかへ、avoid が真になる空間を**通らずに**辿り着けるか。
39
- * 到達先そのものは avoid を問わない (外部は exterior だが、着いた時点で目的は果たされている)。
50
+ * 到達先そのものは avoid を問わない (外部は `outside:1` だが、着いた時点で目的は果たされている)。
40
51
  */
41
52
  function reachableAvoiding(
42
53
  model: Model,
@@ -62,7 +73,7 @@ function reachableAvoiding(
62
73
  if (!v || seen.has(v)) continue;
63
74
  if (toSet.has(v)) return true;
64
75
  const s = model.spaces.get(v);
65
- if (!s || IMPASSABLE.has(s.type) || avoid(s)) continue;
76
+ if (!s || impassable(s) || avoid(s)) continue;
66
77
  seen.add(v);
67
78
  queue.push(v);
68
79
  }
@@ -72,7 +83,7 @@ function reachableAvoiding(
72
83
 
73
84
  /** 外部の空間パスの集合。空なら到達性は問えない (外部が書かれていない模型に穴は無い) */
74
85
  function exteriorSet(model: Model): Set<string> {
75
- return new Set([...model.spaces.values()].filter((s) => s.type === "exterior").map((s) => s.path));
86
+ return new Set([...model.spaces.values()].filter(isOutside).map((s) => s.path));
76
87
  }
77
88
 
78
89
  /**
@@ -126,7 +137,7 @@ export function accessFindings(model: Model): Finding[] {
126
137
  if (outs.size > 0) {
127
138
  const reached = reachableFromExterior(model);
128
139
  for (const s of model.spaces.values()) {
129
- if (s.rects.length === 0 || s.type === "exterior" || IMPASSABLE.has(s.type)) continue;
140
+ if (s.rects.length === 0 || isOutside(s) || impassable(s)) continue;
130
141
  if (reached.has(s.path)) continue;
131
142
  out.push(
132
143
  finding(
@@ -139,10 +150,10 @@ export function accessFindings(model: Model): Finding[] {
139
150
  }
140
151
 
141
152
  // ---- 吹抜けにしか扉が開かない区画 ----
142
- // 通れる境界を持つのに行き先が全部 type:void なら、扉は床の無い穴に向かって開いている。
153
+ // 通れる境界を持つのに行き先が全部 void:1 なら、扉は床の無い穴に向かって開いている。
143
154
  // violation — 出入りしたつもりでどこへも行けない。旗艦例はこれを20区画抱えたまま緑だった。
144
155
  for (const s of model.spaces.values()) {
145
- if (s.rects.length === 0 || s.type === "exterior" || IMPASSABLE.has(s.type)) continue;
156
+ if (s.rects.length === 0 || isOutside(s) || impassable(s)) continue;
146
157
  let doors = 0;
147
158
  let allVoid = true;
148
159
  for (const b of model.boundaries) {
@@ -150,7 +161,8 @@ export function accessFindings(model: Model): Finding[] {
150
161
  const other = b.a === s.path ? b.b : b.b === s.path ? b.a : undefined;
151
162
  if (!other) continue;
152
163
  doors++;
153
- if (model.spaces.get(other)?.type !== "void") allVoid = false;
164
+ const o = model.spaces.get(other);
165
+ if (!o || !isVoid(o)) allVoid = false;
154
166
  }
155
167
  if (doors > 0 && allVoid) {
156
168
  out.push(
@@ -188,7 +200,7 @@ export function accessFindings(model: Model): Finding[] {
188
200
  if (outs.size > 0) {
189
201
  const canPass = carPassable(model);
190
202
  for (const s of model.spaces.values()) {
191
- if (s.rects.length === 0 || s.type === "exterior" || IMPASSABLE.has(s.type)) continue;
203
+ if (s.rects.length === 0 || isOutside(s) || impassable(s)) continue;
192
204
  if (effectiveUse(model, s) !== "parking") continue;
193
205
  if (reachableAvoiding(model, [s.path], outs, () => false, canPass)) continue;
194
206
  out.push(
@@ -1,6 +1,6 @@
1
1
  // 検証 — 外皮の連続 (ADR-0025)
2
2
  //
3
- // 方針が「保証しないもの」に**外皮の連続**を名指しで挙げている (spec/scope.md §3)。
3
+ // 方針が「保証しないもの」に**外皮の連続**を名指しで挙げている (docs/reference/scope.md)。
4
4
  // core に残るのは `envelopeGaps` — 何にも面していない外周の**線分を返す導出**であって、
5
5
  // それが穴かどうかの判断はしない。判断はここが引き受ける。
6
6
  //
@@ -9,7 +9,7 @@
9
9
  // 整合の要求であって、完全性の要求ではない。粗さが許されるのは、ここが凍らないからである。
10
10
 
11
11
  import { envelopeGaps, segmentLength } from "../core/graph.js";
12
- import { isSemiOutdoor, type Model } from "../core/model.js";
12
+ import { isOutside, isSemiOutdoor, type Model } from "../core/model.js";
13
13
  import { finding, type Finding } from "./index.js";
14
14
 
15
15
  const VERTICAL = new Set(["stair", "shaft", "void"]);
@@ -33,7 +33,7 @@ export function envelopeFindings(model: Model): Finding[] {
33
33
  if (s.rects.length === 0) continue;
34
34
  if (!s.level || !envelopedLevels.has(s.level)) continue;
35
35
  // 外部・半屋外・外構のタイルは囲われていないのが正常
36
- if (s.type === "exterior" || isSemiOutdoor(model, s)) continue;
36
+ if (isOutside(s) || isSemiOutdoor(model, s)) continue;
37
37
  if (siteZones.some((z) => s.path.startsWith(z + "/"))) continue;
38
38
 
39
39
  const gaps = envelopeGaps(model, s);
@@ -1,7 +1,7 @@
1
1
  // koyu — 検証の面 (建築的な判定)
2
2
  //
3
3
  // **ここは core ではない。**core が言うのは「書かれたものがデータとして矛盾していない」
4
- // までであって、建築として妥当かは何も言わない (spec/scope.md §3)。採光・面積率・
4
+ // までであって、建築として妥当かは何も言わない (docs/reference/scope.md)。採光・面積率・
5
5
  // 外皮の連続・階段の寸法・到達可能性 — 建築の側の判断はすべてこの面に属す。
6
6
  //
7
7
  // この面は**凍らない**。規則が粗くても、管轄が一つしかなくても、精度が足りなくても、
@@ -63,7 +63,7 @@ export type ValidationRule = keyof typeof VALIDATION_RULES;
63
63
  export interface Finding {
64
64
  rule: ValidationRule;
65
65
  level: "violation" | "caution";
66
- /** 日本語の本文 (位置接頭辞なし — core の Diagnostic と同じ流儀) */
66
+ /** 本文 (英語・位置接頭辞なし — core の Diagnostic と同じ流儀) */
67
67
  message: string;
68
68
  /** 出所の行 */
69
69
  line?: number;
@@ -1,7 +1,7 @@
1
1
  // 検証 — 採光 (法28条1項の粗い写し)
2
2
  //
3
3
  // **合否はここが言う。**core が返すのは `daylightInputs` — 床面積と、係数を掛けた
4
- // 有効窓面積という**数**だけである (spec/scope.md §4「問いは合否を言わない」)。
4
+ // 有効窓面積という**数**だけである (docs/reference/scope.md「問いは合否を言わない」)。
5
5
  // 1/7 という閾値は建築の側の規則であって、原本の構成が満たすべき不変量ではない。
6
6
  //
7
7
  // 判定は甘い。採光補正係数を掛けない粗い判定であり、基本計画の解像度に合わせた
@@ -10,7 +10,7 @@
10
10
  // 建蔽率・容積率は**数**なので core の siteReport が返す。上限と較べるのは、
11
11
  // 用途地域という原本の外の事実を要するので、ここでも持たない — 持てるようになったら足す。
12
12
 
13
- import { polygonAreaM2, regionOf, shapeEscapesPolygon, type Model } from "../core/model.js";
13
+ import { isOutside, polygonAreaM2, regionOf, shapeEscapesPolygon, type Model } from "../core/model.js";
14
14
  import { siteReport } from "../core/site.js";
15
15
  import { finding, type Finding } from "./index.js";
16
16
 
@@ -63,7 +63,7 @@ export function siteFindings(model: Model): Finding[] {
63
63
  }
64
64
 
65
65
  for (const s of withRect) {
66
- if (s.type === "exterior" || s.path.startsWith(poly.path + "/")) continue;
66
+ if (isOutside(s) || s.path.startsWith(poly.path + "/")) continue;
67
67
  // 照合するのは割付ではなく**導出された領域** — 敷地なりに切った外形はここで通る
68
68
  for (const r of regionOf(s)) {
69
69
  const esc = shapeEscapesPolygon(r, poly.points, EPS_SITE);