@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
package/src/index.ts CHANGED
@@ -1,44 +1,190 @@
1
- // koyu v0 — 公開API
2
- export * from "./model.js";
3
- export { parse, parseFiles, parseWith, tokenize, type LayerLoader } from "./parse.js";
4
- export * from "./graph.js";
5
- export { check, checkDiagnostics, DIAGNOSTIC_CODES, type CheckResult, type Diagnostic } from "./check.js";
1
+ // koyu — 公開面 (ADR-0037)
2
+ //
3
+ // **ここに書き下された名だけが約束である。**`export *` は使わない — モジュールに
4
+ // export を足した瞬間に、誰も宣言していない約束が凍る面に増えてしまうからである。
5
+ // 凍らせる面は、書き下されていなければならない (spec/scope.md §8)。
6
+ //
7
+ // 載せる基準は一つ — **面の外に利用者がいること。**
8
+ // 1. パッケージの外 (ugatsu / eval / scripts / editors) が実際に呼ぶ
9
+ // 2. CLI か MCP が答えるものを API からも答えるために要る
10
+ // (「CLIが答えるものはすべてこのAPIが答える」— guide/api.md)
11
+ // 3. spec が名指しで約束する導出 (scope.md §4・§6 / semantics.md)
12
+ // 4. test が契約として固定している
13
+ // core のモジュール同士が引き合うだけの配管は面ではない。型は、載せた値の署名を
14
+ // 書き下すのに要るものだけを載せる。
15
+ //
16
+ // この一覧と spec/tools.md の一覧は集合として一致する — test/public-api.test.ts が縛る。
17
+
18
+ // ---- 解析と合成 (spec/composition.md) ----
19
+ export { parse, parseFiles, parseWith, tokenize, type LayerLoader } from "./core/parse.js";
20
+
21
+ // ---- モデルの語彙 — 書かれた構成の型 ----
22
+ export type {
23
+ Area,
24
+ Asset,
25
+ Attrs,
26
+ AttrValue,
27
+ Boundary,
28
+ BoundaryKind,
29
+ Column,
30
+ ColumnDecl,
31
+ DrawnLine,
32
+ Edge,
33
+ GridAxis,
34
+ GridRef,
35
+ Level,
36
+ Model,
37
+ Opening,
38
+ Pt,
39
+ Rect,
40
+ Seg,
41
+ SitePolygon,
42
+ Space,
43
+ Zone,
44
+ } from "./core/model.js";
45
+
46
+ // ---- モデルへの問い・導出・機械形式 ----
47
+ // **合否は言わない** (spec/scope.md §4)。数と形を返すところまでが core である
6
48
  export {
7
- semanticDiff,
8
- renderDiff,
9
- type ModelDiff,
10
- type FieldChange,
11
- type ChangedItem,
12
- type RenamedItem,
13
- type GridChange,
14
- type SpaceItem,
15
- type BoundaryItem,
16
- type BoundaryChange,
17
- } from "./diff.js";
18
- export { daylight, type DaylightResult } from "./light.js";
19
- export { slabs, type Slab, type SlabKind } from "./fabric.js";
49
+ areaM2,
50
+ canonicalBoundaryOrder,
51
+ columnsFor,
52
+ DEFAULT_LANGUAGE_VERSION,
53
+ displayName,
54
+ effectiveUse,
55
+ heff,
56
+ isCoveredAbove,
57
+ isIndoor,
58
+ isSemiOutdoor,
59
+ levelsSorted,
60
+ newUids,
61
+ pointInPolygon,
62
+ polyBounds,
63
+ polygonAreaM2,
64
+ rectToPoly,
65
+ SourceError,
66
+ srcRef,
67
+ SUPPORTED_LANGUAGE_VERSIONS,
68
+ toCanonical,
69
+ unionAreaM2,
70
+ zoneAreaM2,
71
+ } from "./core/model.js";
72
+
73
+ // ---- 構造整合の診断 (ADR-0016) ----
74
+ export {
75
+ check,
76
+ checkDiagnostics,
77
+ DIAGNOSTIC_CODES,
78
+ type CheckResult,
79
+ type Diagnostic,
80
+ type DiagnosticCode,
81
+ } from "./core/diagnose.js";
82
+
83
+ // ---- 空間グラフと導出の部品 ----
84
+ export {
85
+ deriveDefaultBoundaries,
86
+ doorsBetween,
87
+ envelopeGaps,
88
+ neighbors,
89
+ passable,
90
+ placeBand,
91
+ placeOpening,
92
+ segmentsFor,
93
+ type Band,
94
+ type BandCode,
95
+ type BandError,
96
+ type NeighborInfo,
97
+ type PlacedBand,
98
+ type Route,
99
+ type Segment,
100
+ } from "./core/graph.js";
101
+
102
+ // ---- 形の参照実装 (ADR-0040) — **これが形の唯一の入口である** ----
103
+ // Form は見た目を持たない (spec/scope.md §6)。規則は spec/derivation.md が持つ
104
+ // 実体の構成子 (thicken / bandLine / band / columnRect / runPrism) も core が唯一の実装を
105
+ // 持つ — 芯線と厚みから四辺形や角柱を起こす規則も導出の一部だからである
106
+ export {
107
+ band,
108
+ bandLine,
109
+ columnRect,
110
+ derive,
111
+ DERIVATION_CONSTANTS,
112
+ levelPitch,
113
+ runPrism,
114
+ thicken,
115
+ type DeriveOptions,
116
+ type Form,
117
+ type FormBoundary,
118
+ type FormColumn,
119
+ type FormInput,
120
+ type FormLevel,
121
+ type FormOpening,
122
+ type FormPanel,
123
+ type FormPlan,
124
+ type FormPrism,
125
+ type FormRun,
126
+ type FormSeg,
127
+ type FormSite,
128
+ type FormSpace,
129
+ type FormSwing,
130
+ type PlanClass,
131
+ type PlanEntity,
132
+ type PlanRole,
133
+ type PlanSubject,
134
+ } from "./core/derive.js";
135
+ export { TOLERANCES } from "./core/tolerance.js";
136
+
137
+ // ---- 床・天井・屋根 (ADR-0024) ----
138
+ export { slabs, type Slab, type SlabKind } from "./core/fabric.js";
139
+
140
+ // ---- 採光の入力 (ADR-0020) ----
141
+ export { daylightInputs, type DaylightInput } from "./core/light.js";
142
+
143
+ // ---- 縦動線 (ADR-0021) ----
20
144
  export {
21
- verticalRuns,
22
- verticalRun,
23
- runDecls,
24
- runSolids,
25
145
  runDrawsForLevel,
26
- runIssues,
146
+ runSolids,
27
147
  slopeText,
28
- toWorld,
29
- CUT_HEIGHT,
30
- RUN_KEYS,
31
- RUN_FORMS,
148
+ verticalRuns,
149
+ type RunArrow,
32
150
  type RunDevice,
151
+ type RunDraw,
33
152
  type RunForm,
34
153
  type RunPart,
35
- type VerticalRun,
36
154
  type RunSolid,
37
- type RunDraw,
38
- type RunArrow,
39
- type RunIssue,
40
155
  type Seg2,
41
- } from "./vertical.js";
42
- export { siteReport, type SiteReport, type RoadFrontage } from "./site.js";
43
- export { svgPlan, type PlanOptions } from "./plan.js";
44
- export { svgAxo, type AxoOptions } from "./axo.js";
156
+ type VerticalRun,
157
+ } from "./core/vertical.js";
158
+
159
+ // ---- 敷地 (ADR-0009 / ADR-0011) ----
160
+ export { siteReport, type RoadFrontage, type SiteReport } from "./core/site.js";
161
+
162
+ // ---- 構成の言葉の差分 (ADR-0018) ----
163
+ export {
164
+ renderDiff,
165
+ semanticDiff,
166
+ type BoundaryChange,
167
+ type BoundaryItem,
168
+ type ChangedItem,
169
+ type ColumnItem,
170
+ type FieldChange,
171
+ type GridChange,
172
+ type ModelDiff,
173
+ type RenamedItem,
174
+ type SpaceItem,
175
+ } from "./core/diff.js";
176
+
177
+ // ---- 生成 — **凍らない** (spec/scope.md §8)。SVGの中身は約束の外にある ----
178
+ // 領域としては `@kensnzk/koyu/draw` にも分けてある
179
+ export { svgPlan, type PlanOptions } from "./draw/plan.js";
180
+ export { svgAxo, type AxoOptions } from "./draw/axo.js";
181
+
182
+ // ---- 検証 — **core ではない。**凍らない・増える・合否を言う (spec/scope.md §3) ----
183
+ // Finding は Diagnostic と別の型で、フィールド名から違う (rule/level と code/severity)。
184
+ // 領域としては `@kensnzk/koyu/validate` にも分けてある
185
+ export {
186
+ validate,
187
+ VALIDATION_RULES,
188
+ type Finding,
189
+ type ValidationRule,
190
+ } from "./validate/index.js";
package/src/mcp.ts CHANGED
@@ -11,21 +11,23 @@ import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
11
11
  import {
12
12
  areaM2,
13
13
  isIndoor,
14
- daylight,
14
+ daylightInputs,
15
+ validate,
15
16
  displayName,
16
17
  doorsBetween,
17
18
  effectiveUse,
18
19
  isSemiOutdoor,
19
20
  levelsSorted,
21
+ newUids,
20
22
  polygonAreaM2,
21
23
  toCanonical,
22
24
  zoneAreaM2,
23
25
  type Model,
24
26
  type Space,
25
27
  } from "./index.js";
26
- import { check, checkDiagnostics } from "./check.js";
27
- import { svgPlan } from "./plan.js";
28
- import { siteReport } from "./site.js";
28
+ import { check, checkDiagnostics } from "./core/diagnose.js";
29
+ import { svgPlan } from "./draw/plan.js";
30
+ import { siteReport } from "./core/site.js";
29
31
  import { parseFile, parseFileWith } from "./parse-file.js";
30
32
 
31
33
  // ---- モデルの読み込みと要約 ----
@@ -43,7 +45,7 @@ function layerFiles(model: Model, entry: string): string[] {
43
45
  function assertInside(entryDir: string, targetDir: string): void {
44
46
  const rel = relative(entryDir, targetDir);
45
47
  if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
46
- throw new Error("entryのディレクトリの外へは書き込めません");
48
+ throw new Error("Cannot write outside the entry's directory");
47
49
  }
48
50
  }
49
51
 
@@ -62,7 +64,7 @@ function summarize(model: Model, file: string): unknown {
62
64
  }
63
65
  const byUse: Record<string, number> = {};
64
66
  for (const s of indoor) {
65
- const u = effectiveUse(model, s) ?? "(未指定)";
67
+ const u = effectiveUse(model, s) ?? "(unspecified)";
66
68
  byUse[u] = Math.round(((byUse[u] ?? 0) + (areaM2(s) ?? 0)) * 100) / 100;
67
69
  }
68
70
  const r = check(model);
@@ -99,7 +101,7 @@ function summarize(model: Model, file: string): unknown {
99
101
  floorsM2: byLevel,
100
102
  byUseM2: byUse,
101
103
  check: { errors: r.errors.length, warnings: r.warnings.length },
102
- hint: "レイヤーの中身は layers で、検査は check で、変更は write_layer で (checkが門番)。",
104
+ hint: "Read layer contents with layers, check with check, and edit with write_layer (check is the gatekeeper). Architectural verdicts come from validate.",
103
105
  };
104
106
  }
105
107
 
@@ -124,17 +126,17 @@ interface Tool {
124
126
  }
125
127
 
126
128
  const FILE_PROP = {
127
- file: { type: "string", description: "entryの.muroファイルパス (importは自動で合成される)" },
129
+ file: { type: "string", description: "Path to the entry .muro file (imports are composed automatically)" },
128
130
  };
129
131
  const str = (v: unknown, name: string): string => {
130
- if (typeof v !== "string" || !v) throw new Error(`${name} (文字列) が必要です`);
132
+ if (typeof v !== "string" || !v) throw new Error(`${name} (a string) is required`);
131
133
  return v;
132
134
  };
133
135
 
134
136
  const TOOLS: Record<string, Tool> = {
135
137
  model_summary: {
136
138
  description:
137
- "建物の要約 (名前・レベル・レイヤー構成・ゾーン・建具アセット・面積・check結果)。まずこれを呼ぶ",
139
+ "Summary of the building: name, levels, layer composition, zones, door/window assets, areas, and check counts. Call this first",
138
140
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
139
141
  run: (a) => {
140
142
  const file = str(a.file, "file");
@@ -143,7 +145,7 @@ const TOOLS: Record<string, Tool> = {
143
145
  },
144
146
  check: {
145
147
  description:
146
- "一棟のビルドの門番: 合成して整合を検査する。エラー・警告は出所レイヤー:行つき。編集のたびに呼ぶこと",
148
+ "The gatekeeper of the build: composes the layers and checks structural consistency. Errors and warnings carry layer:line. Call it after every edit. **This says nothing about architectural soundness** — that is the validate tool",
147
149
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
148
150
  run: (a) => {
149
151
  const m = load(str(a.file, "file"));
@@ -159,7 +161,7 @@ const TOOLS: Record<string, Tool> = {
159
161
  },
160
162
  },
161
163
  layers: {
162
- description: "合成に参加している全レイヤー (.muroファイル) の名前と中身を返す — 原本を読む",
164
+ description: "Returns every layer (.muro file) taking part in the composition, in strength order (later layers are stronger), with its source — this is how you read the original",
163
165
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
164
166
  run: (a) => {
165
167
  const file = str(a.file, "file");
@@ -169,14 +171,13 @@ const TOOLS: Record<string, Tool> = {
169
171
  },
170
172
  write_layer: {
171
173
  description:
172
- "レイヤー (.muroファイル) を検査してから書き換える。parse不能な合成になる内容は書き込まれない (原本不変)。" +
173
- "checkのエラーは返すが書き込みは行う (複数レイヤーにまたがる編集の途中を許す) — 直して再度書くこと。履歴はgitに任せる",
174
+ "Checks a layer (.muro file) before replacing it. Content that would make the composition unparsable is never written (the original stays intact). Check errors are returned but the write still happens, so that an edit spanning several layers can be made in steps — fix it and write again. History is left to git",
174
175
  schema: {
175
176
  type: "object",
176
177
  properties: {
177
178
  ...FILE_PROP,
178
- layer: { type: "string", description: "書き込む.muroファイルパス (entryからの相対または絶対)" },
179
- content: { type: "string", description: "レイヤーの全文 (全置換)" },
179
+ layer: { type: "string", description: "Path of the .muro file to write (relative to the entry, or absolute)" },
180
+ content: { type: "string", description: "The full text of the layer (a whole-file replacement)" },
180
181
  },
181
182
  required: ["file", "layer", "content"],
182
183
  },
@@ -185,7 +186,7 @@ const TOOLS: Record<string, Tool> = {
185
186
  const content = str(a.content, "content");
186
187
  const entryDir = resolve(dirname(resolve(file)));
187
188
  const target = resolve(entryDir, str(a.layer, "layer"));
188
- if (!target.endsWith(".muro")) throw new Error("書き込みは .muro ファイルに限ります");
189
+ if (!target.endsWith(".muro")) throw new Error("Only .muro files can be written");
189
190
  assertInside(entryDir, dirname(target));
190
191
  // 門番は書き込みの前 — 差し替え内容で仮想合成し、parse不能なら原本に触れない (ADR-0013)。
191
192
  // 合成に参加しないファイルの内容は検証されない (importされた時のcheckが捕まえる)
@@ -209,14 +210,36 @@ const TOOLS: Record<string, Tool> = {
209
210
  return { written: target, ok: r.errors.length === 0, spaces: m.spaces.size, ...r };
210
211
  },
211
212
  },
213
+ new_uids: {
214
+ description:
215
+ "Mints fresh identity tokens (uid) to write onto spaces or zones with write_layer. They collide with nothing already composed into this model, and 80 bits of randomness keeps them apart from layers that are not composed here. **Nothing assigns a uid on its own** — call this only when a space has to be pointed at across renames (sensors, registers, long-running operations), and run check afterwards, because UID03 is the only thing that proves uniqueness",
216
+ schema: {
217
+ type: "object",
218
+ properties: {
219
+ ...FILE_PROP,
220
+ count: { type: "integer", description: "How many tokens to mint (default 1)" },
221
+ },
222
+ required: ["file"],
223
+ },
224
+ run: (a) => {
225
+ const count = a.count === undefined ? 1 : Number(a.count);
226
+ if (!Number.isInteger(count) || count < 1 || count > 1000) {
227
+ throw new Error("count is an integer between 1 and 1000");
228
+ }
229
+ return {
230
+ uids: newUids(load(str(a.file, "file")), count),
231
+ note: "Write these as uid: on a space or zone. No other element accepts uid (the ledger rejects it). A uid is carried across renames by hand — that act is the record of the design decision that it is still the same space",
232
+ };
233
+ },
234
+ },
212
235
  doors: {
213
- description: "避難・動線の問い: 空間Aから空間Bまで扉を何枚通るか (最少扉数の経路)",
236
+ description: "Circulation query: how many doors lie between space A and space B (the path with the fewest doors)",
214
237
  schema: {
215
238
  type: "object",
216
239
  properties: {
217
240
  ...FILE_PROP,
218
- from: { type: "string", description: "起点の空間パス (例 /L9/A/ldk)" },
219
- to: { type: "string", description: "終点の空間パス (例 /out/road-s)" },
241
+ from: { type: "string", description: "Path of the space to start from (e.g. /L9/A/ldk)" },
242
+ to: { type: "string", description: "Path of the space to reach (e.g. /out/road-s)" },
220
243
  },
221
244
  required: ["file", "from", "to"],
222
245
  },
@@ -226,10 +249,10 @@ const TOOLS: Record<string, Tool> = {
226
249
  },
227
250
  },
228
251
  spaces: {
229
- description: "空間の一覧 (パス・型・レベル・面積・半屋外・出所レイヤー)。levelで絞り込み可",
252
+ description: "List of spaces: path, type, level, area, semi-outdoor flag, and originating layer. Optionally filtered by level",
230
253
  schema: {
231
254
  type: "object",
232
- properties: { ...FILE_PROP, level: { type: "string", description: "レベル名で絞る (省略可)" } },
255
+ properties: { ...FILE_PROP, level: { type: "string", description: "Filter by level name (optional)" } },
233
256
  required: ["file"],
234
257
  },
235
258
  run: (a) => {
@@ -240,22 +263,37 @@ const TOOLS: Record<string, Tool> = {
240
263
  },
241
264
  },
242
265
  light: {
243
- description: "採光の検査: daylight:1 を書いた室で窓面積/床面積 ≥ 1/7 (バルコニー・庇下は0.7掛け)",
266
+ description:
267
+ "Daylight inputs: floor area and effective window area for every space written with daylight:1 (a 0.7 factor applies through a covered semi-outdoor space). **It delivers no verdict** — the 1/7 judgement comes from the validate tool",
244
268
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
245
269
  run: (a) => {
246
270
  const m = load(str(a.file, "file"));
247
- return daylight(m).map((r) => ({
248
- path: r.space.path,
249
- name: displayName(r.space),
250
- ok: r.ok,
251
- windowM2: r.window,
252
- floorM2: r.floor,
253
- needM2: r.need,
271
+ return daylightInputs(m).map((d) => ({
272
+ path: d.space.path,
273
+ name: displayName(d.space),
274
+ windowM2: d.window,
275
+ floorM2: d.floor,
276
+ missingH: d.missingH,
254
277
  }));
255
278
  },
256
279
  },
280
+ validate: {
281
+ 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"] },
284
+ run: (a) => {
285
+ 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
+ };
293
+ },
294
+ },
257
295
  site: {
258
- description: "敷地の問い: 敷地面積 (宣言/導出の照合)・接道・建築面積・建蔽率・容積率",
296
+ description: "Site query: site area (declared against derived), road frontage, footprint, and the coverage and floor-area ratios",
259
297
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
260
298
  run: (a) => {
261
299
  const r = siteReport(load(str(a.file, "file")));
@@ -282,16 +320,16 @@ const TOOLS: Record<string, Tool> = {
282
320
  },
283
321
  },
284
322
  plan_svg: {
285
- description: "指定レベルの平面図SVGを生成して返す (形は生成物 — 最下階は配置図兼用)",
323
+ description: "Generates and returns the plan SVG for a level (form is generated, not written — the lowest level doubles as the site plan)",
286
324
  schema: {
287
325
  type: "object",
288
- properties: { ...FILE_PROP, level: { type: "string", description: "レベル名 (例 L5)" } },
326
+ properties: { ...FILE_PROP, level: { type: "string", description: "Level name (e.g. L5)" } },
289
327
  required: ["file", "level"],
290
328
  },
291
329
  run: (a) => svgPlan(load(str(a.file, "file")), { level: str(a.level, "level") }),
292
330
  },
293
331
  canonical_json: {
294
- description: "正準JSON (機械形式 — 合成後の単一モデル、バイト安定)。diff・外部接続の土台",
332
+ description: "The canonical JSON (machine format — one composed model, byte-stable). The ground for diffing and for external connections",
295
333
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
296
334
  run: (a) => JSON.parse(toCanonical(load(str(a.file, "file")))),
297
335
  },
@@ -327,11 +365,9 @@ function handle(msg: Json): void {
327
365
  result(id, {
328
366
  protocolVersion: (params.protocolVersion as string) ?? "2025-06-18",
329
367
  capabilities: { tools: {} },
330
- serverInfo: { name: "koyu", version: "0.14.0" },
368
+ serverInfo: { name: "koyu", version: "0.16.0" },
331
369
  instructions:
332
- "空間一次の建築記述koyuのサーバー。model_summaryで建物を掴み、layersで原本 (.muroレイヤー群) を読み、" +
333
- "write_layerで編集する。checkが一棟のビルドの門番 — エラーは出所レイヤー:行つきで返る。" +
334
- "doors/light/site/spacesは同じ記述への異なる問い。形 (plan_svg) は生成物。",
370
+ "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.",
335
371
  });
336
372
  return;
337
373
  }
@@ -352,7 +388,7 @@ function handle(msg: Json): void {
352
388
  const name = params.name as string;
353
389
  const tool = TOOLS[name];
354
390
  if (!tool) {
355
- rpcError(id, -32602, `未知のツールです: ${name}`);
391
+ rpcError(id, -32602, `Unknown tool: ${name}`);
356
392
  return;
357
393
  }
358
394
  try {
@@ -374,7 +410,7 @@ function handle(msg: Json): void {
374
410
  result(id, { prompts: [] });
375
411
  return;
376
412
  default:
377
- rpcError(id, -32601, `未対応のメソッドです: ${method}`);
413
+ rpcError(id, -32601, `Unsupported method: ${method}`);
378
414
  }
379
415
  }
380
416
 
package/src/parse-file.ts CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { readFileSync } from "node:fs";
6
6
  import { dirname, resolve } from "node:path";
7
- import type { Model } from "./model.js";
8
- import { parseWith } from "./parse.js";
7
+ import type { Model } from "./core/model.js";
8
+ import { parseWith } from "./core/parse.js";
9
9
 
10
10
  /** ファイルから読む。import は書かれたファイルからの相対で解決される */
11
11
  export function parseFile(filePath: string): Model {