@kensnzk/koyu 0.15.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 (188) hide show
  1. package/README.ja.md +14 -10
  2. package/README.md +16 -13
  3. package/dist/cli.js +162 -84
  4. package/dist/cli.js.map +1 -1
  5. package/dist/core/derive.d.ts +264 -0
  6. package/dist/core/derive.d.ts.map +1 -0
  7. package/dist/core/derive.js +576 -0
  8. package/dist/core/derive.js.map +1 -0
  9. package/dist/{check.d.ts → core/diagnose.d.ts} +15 -15
  10. package/dist/core/diagnose.d.ts.map +1 -0
  11. package/dist/{check.js → core/diagnose.js} +269 -223
  12. package/dist/core/diagnose.js.map +1 -0
  13. package/dist/{diff.d.ts → core/diff.d.ts} +3 -2
  14. package/dist/core/diff.d.ts.map +1 -0
  15. package/dist/{diff.js → core/diff.js} +89 -43
  16. package/dist/core/diff.js.map +1 -0
  17. package/dist/{fabric.d.ts → core/fabric.d.ts} +5 -3
  18. package/dist/core/fabric.d.ts.map +1 -0
  19. package/dist/{fabric.js → core/fabric.js} +12 -11
  20. package/dist/core/fabric.js.map +1 -0
  21. package/dist/{graph.d.ts → core/graph.d.ts} +2 -4
  22. package/dist/core/graph.d.ts.map +1 -0
  23. package/dist/{graph.js → core/graph.js} +53 -54
  24. package/dist/core/graph.js.map +1 -0
  25. package/dist/core/light.d.ts +24 -0
  26. package/dist/core/light.d.ts.map +1 -0
  27. package/dist/{light.js → core/light.js} +17 -12
  28. package/dist/core/light.js.map +1 -0
  29. package/dist/{model.d.ts → core/model.d.ts} +178 -18
  30. package/dist/core/model.d.ts.map +1 -0
  31. package/dist/{model.js → core/model.js} +307 -68
  32. package/dist/core/model.js.map +1 -0
  33. package/dist/core/parse.d.ts.map +1 -0
  34. package/dist/{parse.js → core/parse.js} +546 -133
  35. package/dist/core/parse.js.map +1 -0
  36. package/dist/{poly.d.ts → core/poly.d.ts} +3 -6
  37. package/dist/core/poly.d.ts.map +1 -0
  38. package/dist/{poly.js → core/poly.js} +8 -13
  39. package/dist/core/poly.js.map +1 -0
  40. package/dist/core/site.d.ts.map +1 -0
  41. package/dist/{site.js → core/site.js} +2 -2
  42. package/dist/core/site.js.map +1 -0
  43. package/dist/core/tolerance.d.ts +26 -0
  44. package/dist/core/tolerance.d.ts.map +1 -0
  45. package/dist/core/tolerance.js +48 -0
  46. package/dist/core/tolerance.js.map +1 -0
  47. package/dist/{vertical.d.ts → core/vertical.d.ts} +48 -12
  48. package/dist/core/vertical.d.ts.map +1 -0
  49. package/dist/{vertical.js → core/vertical.js} +53 -105
  50. package/dist/core/vertical.js.map +1 -0
  51. package/dist/core/vocabulary.d.ts +40 -0
  52. package/dist/core/vocabulary.d.ts.map +1 -0
  53. package/dist/core/vocabulary.js +176 -0
  54. package/dist/core/vocabulary.js.map +1 -0
  55. package/dist/{axo.d.ts → draw/axo.d.ts} +1 -1
  56. package/dist/draw/axo.d.ts.map +1 -0
  57. package/dist/{axo.js → draw/axo.js} +53 -81
  58. package/dist/draw/axo.js.map +1 -0
  59. package/dist/draw/index.d.ts +3 -0
  60. package/dist/draw/index.d.ts.map +1 -0
  61. package/dist/draw/index.js +11 -0
  62. package/dist/draw/index.js.map +1 -0
  63. package/dist/draw/plan.d.ts +10 -0
  64. package/dist/draw/plan.d.ts.map +1 -0
  65. package/dist/draw/plan.js +284 -0
  66. package/dist/draw/plan.js.map +1 -0
  67. package/dist/index.d.ts +16 -11
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +55 -12
  70. package/dist/index.js.map +1 -1
  71. package/dist/mcp.js +112 -50
  72. package/dist/mcp.js.map +1 -1
  73. package/dist/parse-file.d.ts +1 -1
  74. package/dist/parse-file.d.ts.map +1 -1
  75. package/dist/parse-file.js +19 -4
  76. package/dist/parse-file.js.map +1 -1
  77. package/dist/validate/access.d.ts +6 -0
  78. package/dist/validate/access.d.ts.map +1 -0
  79. package/dist/validate/access.js +248 -0
  80. package/dist/validate/access.js.map +1 -0
  81. package/dist/validate/envelope.d.ts +4 -0
  82. package/dist/validate/envelope.d.ts.map +1 -0
  83. package/dist/validate/envelope.js +55 -0
  84. package/dist/validate/envelope.js.map +1 -0
  85. package/dist/validate/index.d.ts +60 -0
  86. package/dist/validate/index.d.ts.map +1 -0
  87. package/dist/validate/index.js +77 -0
  88. package/dist/validate/index.js.map +1 -0
  89. package/dist/validate/light.d.ts +6 -0
  90. package/dist/validate/light.d.ts.map +1 -0
  91. package/dist/validate/light.js +28 -0
  92. package/dist/validate/light.js.map +1 -0
  93. package/dist/validate/runs.d.ts +16 -0
  94. package/dist/validate/runs.d.ts.map +1 -0
  95. package/dist/validate/runs.js +60 -0
  96. package/dist/validate/runs.js.map +1 -0
  97. package/dist/validate/site.d.ts +6 -0
  98. package/dist/validate/site.d.ts.map +1 -0
  99. package/dist/validate/site.js +63 -0
  100. package/dist/validate/site.js.map +1 -0
  101. package/editors/vscode/.vscodeignore +2 -0
  102. package/editors/vscode/README.md +28 -0
  103. package/editors/vscode/extension.js +150 -0
  104. package/editors/vscode/language-configuration.json +19 -0
  105. package/editors/vscode/package.json +57 -0
  106. package/editors/vscode/syntaxes/koyu.tmLanguage.json +226 -0
  107. package/examples/basement/main.muro +3 -3
  108. package/examples/complex/main.muro +1 -1
  109. package/examples/complex/podium.muro +1 -1
  110. package/examples/complex/site.muro +6 -6
  111. package/examples/house/L2.muro +1 -1
  112. package/examples/house/main.muro +2 -2
  113. package/examples/house/site.muro +4 -4
  114. package/examples/house.muro +7 -7
  115. package/examples/mansion.muro +3 -3
  116. package/examples/office.muro +4 -4
  117. package/examples/steps/01-one-room.muro +1 -1
  118. package/examples/steps/02-two-rooms.muro +1 -1
  119. package/examples/steps/03-door.muro +1 -1
  120. package/examples/steps/04-exterior.muro +2 -2
  121. package/examples/steps/05-two-storeys.muro +2 -2
  122. package/examples/steps/06-finished.muro +3 -3
  123. package/examples/tower/L2.muro +1 -1
  124. package/examples/tower/main.muro +1 -1
  125. package/examples/tower/site.muro +4 -4
  126. package/examples/twin/main.muro +2 -2
  127. package/examples/twin/podium.muro +4 -4
  128. package/examples/twin/site.muro +8 -8
  129. package/examples/two-rooms.canonical.json +6 -4
  130. package/examples/two-rooms.muro +3 -3
  131. package/package.json +18 -3
  132. package/src/cli.ts +173 -83
  133. package/src/core/derive.ts +869 -0
  134. package/src/{check.ts → core/diagnose.ts} +313 -235
  135. package/src/{diff.ts → core/diff.ts} +91 -43
  136. package/src/{fabric.ts → core/fabric.ts} +22 -12
  137. package/src/{graph.ts → core/graph.ts} +64 -63
  138. package/src/core/light.ts +69 -0
  139. package/src/{model.ts → core/model.ts} +361 -74
  140. package/src/{parse.ts → core/parse.ts} +618 -135
  141. package/src/{poly.ts → core/poly.ts} +8 -16
  142. package/src/{site.ts → core/site.ts} +2 -2
  143. package/src/core/tolerance.ts +55 -0
  144. package/src/{vertical.ts → core/vertical.ts} +73 -116
  145. package/src/core/vocabulary.ts +210 -0
  146. package/src/{axo.ts → draw/axo.ts} +51 -94
  147. package/src/draw/index.ts +11 -0
  148. package/src/draw/plan.ts +344 -0
  149. package/src/index.ts +201 -34
  150. package/src/mcp.ts +119 -50
  151. package/src/parse-file.ts +19 -5
  152. package/src/validate/access.ts +291 -0
  153. package/src/validate/envelope.ts +59 -0
  154. package/src/validate/index.ts +107 -0
  155. package/src/validate/light.ts +43 -0
  156. package/src/validate/runs.ts +87 -0
  157. package/src/validate/site.ts +84 -0
  158. package/dist/axo.d.ts.map +0 -1
  159. package/dist/axo.js.map +0 -1
  160. package/dist/check.d.ts.map +0 -1
  161. package/dist/check.js.map +0 -1
  162. package/dist/diff.d.ts.map +0 -1
  163. package/dist/diff.js.map +0 -1
  164. package/dist/fabric.d.ts.map +0 -1
  165. package/dist/fabric.js.map +0 -1
  166. package/dist/graph.d.ts.map +0 -1
  167. package/dist/graph.js.map +0 -1
  168. package/dist/light.d.ts +0 -15
  169. package/dist/light.d.ts.map +0 -1
  170. package/dist/light.js.map +0 -1
  171. package/dist/model.d.ts.map +0 -1
  172. package/dist/model.js.map +0 -1
  173. package/dist/parse.d.ts.map +0 -1
  174. package/dist/parse.js.map +0 -1
  175. package/dist/plan.d.ts +0 -10
  176. package/dist/plan.d.ts.map +0 -1
  177. package/dist/plan.js +0 -354
  178. package/dist/plan.js.map +0 -1
  179. package/dist/poly.d.ts.map +0 -1
  180. package/dist/poly.js.map +0 -1
  181. package/dist/site.d.ts.map +0 -1
  182. package/dist/site.js.map +0 -1
  183. package/dist/vertical.d.ts.map +0 -1
  184. package/dist/vertical.js.map +0 -1
  185. package/src/light.ts +0 -63
  186. package/src/plan.ts +0 -472
  187. /package/dist/{parse.d.ts → core/parse.d.ts} +0 -0
  188. /package/dist/{site.d.ts → core/site.d.ts} +0 -0
package/src/mcp.ts CHANGED
@@ -11,21 +11,25 @@ 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,
19
+ isOutside,
18
20
  isSemiOutdoor,
21
+ isVoid,
19
22
  levelsSorted,
23
+ newUids,
20
24
  polygonAreaM2,
21
25
  toCanonical,
22
26
  zoneAreaM2,
23
27
  type Model,
24
28
  type Space,
25
29
  } from "./index.js";
26
- import { check, checkDiagnostics } from "./check.js";
27
- import { svgPlan } from "./plan.js";
28
- import { siteReport } from "./site.js";
30
+ import { check, checkDiagnostics } from "./core/diagnose.js";
31
+ import { svgPlan } from "./draw/plan.js";
32
+ import { siteReport } from "./core/site.js";
29
33
  import { parseFile, parseFileWith } from "./parse-file.js";
30
34
 
31
35
  // ---- モデルの読み込みと要約 ----
@@ -34,23 +38,44 @@ function load(file: string): Model {
34
38
  return parseFile(resolve(file));
35
39
  }
36
40
 
37
- /** 合成に参加した全レイヤー — 要素の有無によらずModelが記録する (grid/levelだけの層も落ちない) */
38
- function layerFiles(model: Model, entry: string): string[] {
39
- 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
+ }
40
65
  }
41
66
 
42
67
  /** entryディレクトリ境界の検査 — 文字列prefixではなく相対パスで判定する (ADR-0013) */
43
68
  function assertInside(entryDir: string, targetDir: string): void {
44
69
  const rel = relative(entryDir, targetDir);
45
70
  if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
46
- throw new Error("entryのディレクトリの外へは書き込めません");
71
+ throw new Error("Cannot write outside the entry's directory");
47
72
  }
48
73
  }
49
74
 
50
75
  function summarize(model: Model, file: string): unknown {
51
76
  const rooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level);
52
77
  const indoor = rooms.filter((s) => isIndoor(model, s));
53
- const semi = rooms.filter((s) => s.type !== "void" && isSemiOutdoor(model, s));
78
+ const semi = rooms.filter((s) => !isVoid(s) && isSemiOutdoor(model, s));
54
79
  const byLevel: Record<string, { rooms: number; subtotalM2: number }> = {};
55
80
  for (const lv of levelsSorted(model)) {
56
81
  const rs = indoor.filter((s) => s.level === lv.name);
@@ -62,14 +87,14 @@ function summarize(model: Model, file: string): unknown {
62
87
  }
63
88
  const byUse: Record<string, number> = {};
64
89
  for (const s of indoor) {
65
- const u = effectiveUse(model, s) ?? "(未指定)";
90
+ const u = effectiveUse(model, s) ?? "(unspecified)";
66
91
  byUse[u] = Math.round(((byUse[u] ?? 0) + (areaM2(s) ?? 0)) * 100) / 100;
67
92
  }
68
93
  const r = check(model);
69
94
  return {
70
95
  name: model.name,
71
96
  unit: model.unit,
72
- layers: layerFiles(model, file),
97
+ layers: layerFiles(model),
73
98
  levels: levelsSorted(model).map((l) => ({
74
99
  name: l.name,
75
100
  z: l.z,
@@ -99,17 +124,22 @@ function summarize(model: Model, file: string): unknown {
99
124
  floorsM2: byLevel,
100
125
  byUseM2: byUse,
101
126
  check: { errors: r.errors.length, warnings: r.warnings.length },
102
- hint: "レイヤーの中身は layers で、検査は check で、変更は write_layer で (checkが門番)。",
127
+ hint: "Read layer contents with layers, check with check, and edit with write_layer (check is the gatekeeper). Architectural verdicts come from validate.",
103
128
  };
104
129
  }
105
130
 
106
131
  function spaceInfo(model: Model, s: Space): unknown {
107
132
  return {
108
133
  path: s.path,
109
- type: s.type,
134
+ // 型は任意の自由なラベルなので、書かれていなければ鍵ごと出ない。
135
+ // **構成の事実はこの語ではなく下の二つが答える** — 型が無い空間について
136
+ // 「外部か」「吹抜けか」を消費側が推測できてしまうと、廃止した推定が戻る
137
+ ...(s.type !== undefined ? { type: s.type } : {}),
110
138
  name: displayName(s),
111
139
  level: s.level,
112
140
  areaM2: areaM2(s),
141
+ ...(isOutside(s) ? { outside: true } : {}),
142
+ ...(isVoid(s) ? { void: true } : {}),
113
143
  semiOutdoor: isSemiOutdoor(model, s),
114
144
  ...(s.file ? { layer: s.file } : {}),
115
145
  };
@@ -124,17 +154,17 @@ interface Tool {
124
154
  }
125
155
 
126
156
  const FILE_PROP = {
127
- file: { type: "string", description: "entryの.muroファイルパス (importは自動で合成される)" },
157
+ file: { type: "string", description: "Path to the entry .muro file (imports are composed automatically)" },
128
158
  };
129
159
  const str = (v: unknown, name: string): string => {
130
- if (typeof v !== "string" || !v) throw new Error(`${name} (文字列) が必要です`);
160
+ if (typeof v !== "string" || !v) throw new Error(`${name} (a string) is required`);
131
161
  return v;
132
162
  };
133
163
 
134
164
  const TOOLS: Record<string, Tool> = {
135
165
  model_summary: {
136
166
  description:
137
- "建物の要約 (名前・レベル・レイヤー構成・ゾーン・建具アセット・面積・check結果)。まずこれを呼ぶ",
167
+ "Summary of the building: name, levels, layer composition, zones, door/window assets, areas, and check counts. Call this first",
138
168
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
139
169
  run: (a) => {
140
170
  const file = str(a.file, "file");
@@ -143,7 +173,7 @@ const TOOLS: Record<string, Tool> = {
143
173
  },
144
174
  check: {
145
175
  description:
146
- "一棟のビルドの門番: 合成して整合を検査する。エラー・警告は出所レイヤー:行つき。編集のたびに呼ぶこと",
176
+ "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
177
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
148
178
  run: (a) => {
149
179
  const m = load(str(a.file, "file"));
@@ -153,40 +183,44 @@ const TOOLS: Record<string, Tool> = {
153
183
  spaces: m.spaces.size,
154
184
  boundaries: m.boundaries.length,
155
185
  ...r,
156
- // 構造化診断 (ADR-0016) — errors/warningsの文字列と同件・同順。code/severity/path/relatedつき
186
+ // 構造化診断 (ADR-0016) — errors と warnings を足したものと同件。並びは走査の順で、
187
+ // errors/warnings はそれを severity で二本に割ったものなので、連結して添字で対応させてはならない。
188
+ // code/severity/path/relatedつき
157
189
  diagnostics: checkDiagnostics(m),
158
190
  };
159
191
  },
160
192
  },
161
193
  layers: {
162
- description: "合成に参加している全レイヤー (.muroファイル) の名前と中身を返す — 原本を読む",
194
+ 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
195
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
164
196
  run: (a) => {
165
197
  const file = str(a.file, "file");
166
198
  const m = load(file);
167
- return layerFiles(m, file).map((f) => ({ file: f, source: readFileSync(f, "utf8") }));
199
+ return layerFiles(m).map((f) => ({ file: f, source: readFileSync(f, "utf8") }));
168
200
  },
169
201
  },
170
202
  write_layer: {
171
203
  description:
172
- "レイヤー (.muroファイル) を検査してから書き換える。parse不能な合成になる内容は書き込まれない (原本不変)。" +
173
- "checkのエラーは返すが書き込みは行う (複数レイヤーにまたがる編集の途中を許す) — 直して再度書くこと。履歴はgitに任せる",
204
+ "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
205
  schema: {
175
206
  type: "object",
176
207
  properties: {
177
208
  ...FILE_PROP,
178
- layer: { type: "string", description: "書き込む.muroファイルパス (entryからの相対または絶対)" },
179
- content: { type: "string", description: "レイヤーの全文 (全置換)" },
209
+ layer: { type: "string", description: "Path of the .muro file to write (relative to the entry, or absolute)" },
210
+ content: { type: "string", description: "The full text of the layer (a whole-file replacement)" },
180
211
  },
181
212
  required: ["file", "layer", "content"],
182
213
  },
183
214
  run: (a) => {
184
215
  const file = str(a.file, "file");
185
216
  const content = str(a.content, "content");
186
- 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))));
187
221
  const target = resolve(entryDir, str(a.layer, "layer"));
188
- if (!target.endsWith(".muro")) throw new Error("書き込みは .muro ファイルに限ります");
189
- assertInside(entryDir, dirname(target));
222
+ if (!target.endsWith(".muro")) throw new Error("Only .muro files can be written");
223
+ assertInside(entryDir, real(dirname(target)));
190
224
  // 門番は書き込みの前 — 差し替え内容で仮想合成し、parse不能なら原本に触れない (ADR-0013)。
191
225
  // 合成に参加しないファイルの内容は検証されない (importされた時のcheckが捕まえる)
192
226
  let m: Model;
@@ -209,14 +243,36 @@ const TOOLS: Record<string, Tool> = {
209
243
  return { written: target, ok: r.errors.length === 0, spaces: m.spaces.size, ...r };
210
244
  },
211
245
  },
246
+ new_uids: {
247
+ description:
248
+ "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",
249
+ schema: {
250
+ type: "object",
251
+ properties: {
252
+ ...FILE_PROP,
253
+ count: { type: "integer", description: "How many tokens to mint (default 1)" },
254
+ },
255
+ required: ["file"],
256
+ },
257
+ run: (a) => {
258
+ const count = a.count === undefined ? 1 : Number(a.count);
259
+ if (!Number.isInteger(count) || count < 1 || count > 1000) {
260
+ throw new Error("count is an integer between 1 and 1000");
261
+ }
262
+ return {
263
+ uids: newUids(load(str(a.file, "file")), count),
264
+ 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",
265
+ };
266
+ },
267
+ },
212
268
  doors: {
213
- description: "避難・動線の問い: 空間Aから空間Bまで扉を何枚通るか (最少扉数の経路)",
269
+ description: "Circulation query: how many doors lie between space A and space B (the path with the fewest doors)",
214
270
  schema: {
215
271
  type: "object",
216
272
  properties: {
217
273
  ...FILE_PROP,
218
- from: { type: "string", description: "起点の空間パス (例 /L9/A/ldk)" },
219
- to: { type: "string", description: "終点の空間パス (例 /out/road-s)" },
274
+ from: { type: "string", description: "Path of the space to start from (e.g. /L9/A/ldk)" },
275
+ to: { type: "string", description: "Path of the space to reach (e.g. /out/road-s)" },
220
276
  },
221
277
  required: ["file", "from", "to"],
222
278
  },
@@ -226,10 +282,10 @@ const TOOLS: Record<string, Tool> = {
226
282
  },
227
283
  },
228
284
  spaces: {
229
- description: "空間の一覧 (パス・型・レベル・面積・半屋外・出所レイヤー)。levelで絞り込み可",
285
+ description: "List of spaces: path, type, level, area, semi-outdoor flag, and originating layer. Optionally filtered by level",
230
286
  schema: {
231
287
  type: "object",
232
- properties: { ...FILE_PROP, level: { type: "string", description: "レベル名で絞る (省略可)" } },
288
+ properties: { ...FILE_PROP, level: { type: "string", description: "Filter by level name (optional)" } },
233
289
  required: ["file"],
234
290
  },
235
291
  run: (a) => {
@@ -240,22 +296,37 @@ const TOOLS: Record<string, Tool> = {
240
296
  },
241
297
  },
242
298
  light: {
243
- description: "採光の検査: daylight:1 を書いた室で窓面積/床面積 ≥ 1/7 (バルコニー・庇下は0.7掛け)",
299
+ description:
300
+ "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
301
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
245
302
  run: (a) => {
246
303
  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,
304
+ return daylightInputs(m).map((d) => ({
305
+ path: d.space.path,
306
+ name: displayName(d.space),
307
+ windowM2: d.window,
308
+ floorM2: d.floor,
309
+ missingH: d.missingH,
254
310
  }));
255
311
  },
256
312
  },
313
+ validate: {
314
+ description:
315
+ "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",
316
+ schema: { type: "object", properties: FILE_PROP, required: ["file"] },
317
+ run: (a) => {
318
+ const m = load(str(a.file, "file"));
319
+ const findings = validate(m);
320
+ return {
321
+ findings,
322
+ violations: findings.filter((f) => f.level === "violation").length,
323
+ cautions: findings.filter((f) => f.level === "caution").length,
324
+ note: "These are verdicts, not the structural-consistency guarantee of koyu check",
325
+ };
326
+ },
327
+ },
257
328
  site: {
258
- description: "敷地の問い: 敷地面積 (宣言/導出の照合)・接道・建築面積・建蔽率・容積率",
329
+ description: "Site query: site area (declared against derived), road frontage, footprint, and the coverage and floor-area ratios",
259
330
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
260
331
  run: (a) => {
261
332
  const r = siteReport(load(str(a.file, "file")));
@@ -282,16 +353,16 @@ const TOOLS: Record<string, Tool> = {
282
353
  },
283
354
  },
284
355
  plan_svg: {
285
- description: "指定レベルの平面図SVGを生成して返す (形は生成物 — 最下階は配置図兼用)",
356
+ description: "Generates and returns the plan SVG for a level (form is generated, not written — the lowest level doubles as the site plan)",
286
357
  schema: {
287
358
  type: "object",
288
- properties: { ...FILE_PROP, level: { type: "string", description: "レベル名 (例 L5)" } },
359
+ properties: { ...FILE_PROP, level: { type: "string", description: "Level name (e.g. L5)" } },
289
360
  required: ["file", "level"],
290
361
  },
291
362
  run: (a) => svgPlan(load(str(a.file, "file")), { level: str(a.level, "level") }),
292
363
  },
293
364
  canonical_json: {
294
- description: "正準JSON (機械形式 — 合成後の単一モデル、バイト安定)。diff・外部接続の土台",
365
+ description: "The canonical JSON (machine format — one composed model, byte-stable). The ground for diffing and for external connections",
295
366
  schema: { type: "object", properties: FILE_PROP, required: ["file"] },
296
367
  run: (a) => JSON.parse(toCanonical(load(str(a.file, "file")))),
297
368
  },
@@ -327,11 +398,9 @@ function handle(msg: Json): void {
327
398
  result(id, {
328
399
  protocolVersion: (params.protocolVersion as string) ?? "2025-06-18",
329
400
  capabilities: { tools: {} },
330
- serverInfo: { name: "koyu", version: "0.15.0" },
401
+ serverInfo: { name: "koyu", version: "0.17.0" },
331
402
  instructions:
332
- "空間一次の建築記述koyuのサーバー。model_summaryで建物を掴み、layersで原本 (.muroレイヤー群) を読み、" +
333
- "write_layerで編集する。checkが一棟のビルドの門番 — エラーは出所レイヤー:行つきで返る。" +
334
- "doors/light/site/spacesは同じ記述への異なる問い。形 (plan_svg) は生成物。",
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.",
335
404
  });
336
405
  return;
337
406
  }
@@ -352,7 +421,7 @@ function handle(msg: Json): void {
352
421
  const name = params.name as string;
353
422
  const tool = TOOLS[name];
354
423
  if (!tool) {
355
- rpcError(id, -32602, `未知のツールです: ${name}`);
424
+ rpcError(id, -32602, `Unknown tool: ${name}`);
356
425
  return;
357
426
  }
358
427
  try {
@@ -374,7 +443,7 @@ function handle(msg: Json): void {
374
443
  result(id, { prompts: [] });
375
444
  return;
376
445
  default:
377
- rpcError(id, -32601, `未対応のメソッドです: ${method}`);
446
+ rpcError(id, -32601, `Unsupported method: ${method}`);
378
447
  }
379
448
  }
380
449
 
package/src/parse-file.ts CHANGED
@@ -2,10 +2,10 @@
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
- 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 {
@@ -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
  }