@kensnzk/koyu 0.17.0 → 0.19.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 (167) hide show
  1. package/dist/analysis/contracts.d.ts +217 -0
  2. package/dist/analysis/contracts.d.ts.map +1 -0
  3. package/dist/analysis/contracts.js +27 -0
  4. package/dist/analysis/contracts.js.map +1 -0
  5. package/dist/analysis/index.d.ts +5 -0
  6. package/dist/analysis/index.d.ts.map +1 -0
  7. package/dist/analysis/index.js +17 -0
  8. package/dist/analysis/index.js.map +1 -0
  9. package/dist/analysis/json.d.ts +21 -0
  10. package/dist/analysis/json.d.ts.map +1 -0
  11. package/dist/analysis/json.js +111 -0
  12. package/dist/analysis/json.js.map +1 -0
  13. package/dist/cli.js +116 -26
  14. package/dist/cli.js.map +1 -1
  15. package/dist/core/diagnose.d.ts +1 -0
  16. package/dist/core/diagnose.d.ts.map +1 -1
  17. package/dist/core/diagnose.js +11 -1
  18. package/dist/core/diagnose.js.map +1 -1
  19. package/dist/core/model.d.ts +50 -3
  20. package/dist/core/model.d.ts.map +1 -1
  21. package/dist/core/model.js +19 -3
  22. package/dist/core/model.js.map +1 -1
  23. package/dist/core/parse.d.ts.map +1 -1
  24. package/dist/core/parse.js +79 -0
  25. package/dist/core/parse.js.map +1 -1
  26. package/dist/core/site.d.ts +9 -0
  27. package/dist/core/site.d.ts.map +1 -1
  28. package/dist/core/site.js +6 -0
  29. package/dist/core/site.js.map +1 -1
  30. package/dist/core/vocabulary.d.ts.map +1 -1
  31. package/dist/core/vocabulary.js +11 -0
  32. package/dist/core/vocabulary.js.map +1 -1
  33. package/dist/diagnostics.d.ts +2 -0
  34. package/dist/diagnostics.d.ts.map +1 -0
  35. package/dist/diagnostics.js +3 -0
  36. package/dist/diagnostics.js.map +1 -0
  37. package/dist/diff.d.ts +2 -0
  38. package/dist/diff.d.ts.map +1 -0
  39. package/dist/diff.js +3 -0
  40. package/dist/diff.js.map +1 -0
  41. package/dist/draw/plan.d.ts.map +1 -1
  42. package/dist/draw/plan.js +24 -0
  43. package/dist/draw/plan.js.map +1 -1
  44. package/dist/form.d.ts +5 -0
  45. package/dist/form.d.ts.map +1 -0
  46. package/dist/form.js +4 -0
  47. package/dist/form.js.map +1 -0
  48. package/dist/graph.d.ts +2 -0
  49. package/dist/graph.d.ts.map +1 -0
  50. package/dist/graph.js +3 -0
  51. package/dist/graph.js.map +1 -0
  52. package/dist/index.d.ts +2 -15
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +35 -50
  55. package/dist/index.js.map +1 -1
  56. package/dist/mcp.js +55 -20
  57. package/dist/mcp.js.map +1 -1
  58. package/dist/model.d.ts +3 -0
  59. package/dist/model.d.ts.map +1 -0
  60. package/dist/model.js +3 -0
  61. package/dist/model.js.map +1 -0
  62. package/dist/validate/assessment.d.ts +8 -0
  63. package/dist/validate/assessment.d.ts.map +1 -0
  64. package/dist/validate/assessment.js +1738 -0
  65. package/dist/validate/assessment.js.map +1 -0
  66. package/dist/validate/builtin/access.d.ts +55 -0
  67. package/dist/validate/builtin/access.d.ts.map +1 -0
  68. package/dist/validate/builtin/access.js +494 -0
  69. package/dist/validate/builtin/access.js.map +1 -0
  70. package/dist/validate/builtin/daylight.d.ts +44 -0
  71. package/dist/validate/builtin/daylight.d.ts.map +1 -0
  72. package/dist/validate/builtin/daylight.js +233 -0
  73. package/dist/validate/builtin/daylight.js.map +1 -0
  74. package/dist/validate/builtin/door-column-collisions.d.ts +47 -0
  75. package/dist/validate/builtin/door-column-collisions.d.ts.map +1 -0
  76. package/dist/validate/builtin/door-column-collisions.js +189 -0
  77. package/dist/validate/builtin/door-column-collisions.js.map +1 -0
  78. package/dist/validate/builtin/envelope.d.ts +30 -0
  79. package/dist/validate/builtin/envelope.d.ts.map +1 -0
  80. package/dist/validate/builtin/envelope.js +169 -0
  81. package/dist/validate/builtin/envelope.js.map +1 -0
  82. package/dist/validate/builtin/freeze.d.ts +3 -0
  83. package/dist/validate/builtin/freeze.d.ts.map +1 -0
  84. package/dist/validate/builtin/freeze.js +21 -0
  85. package/dist/validate/builtin/freeze.js.map +1 -0
  86. package/dist/validate/builtin/index.d.ts +38 -0
  87. package/dist/validate/builtin/index.d.ts.map +1 -0
  88. package/dist/validate/builtin/index.js +106 -0
  89. package/dist/validate/builtin/index.js.map +1 -0
  90. package/dist/validate/builtin/site.d.ts +62 -0
  91. package/dist/validate/builtin/site.d.ts.map +1 -0
  92. package/dist/validate/builtin/site.js +333 -0
  93. package/dist/validate/builtin/site.js.map +1 -0
  94. package/dist/validate/builtin/vertical-runs.d.ts +53 -0
  95. package/dist/validate/builtin/vertical-runs.d.ts.map +1 -0
  96. package/dist/validate/builtin/vertical-runs.js +290 -0
  97. package/dist/validate/builtin/vertical-runs.js.map +1 -0
  98. package/dist/validate/contracts.d.ts +188 -0
  99. package/dist/validate/contracts.d.ts.map +1 -0
  100. package/dist/validate/contracts.js +28 -0
  101. package/dist/validate/contracts.js.map +1 -0
  102. package/dist/validate/index.d.ts +2 -59
  103. package/dist/validate/index.d.ts.map +1 -1
  104. package/dist/validate/index.js +22 -70
  105. package/dist/validate/index.js.map +1 -1
  106. package/dist/vocabulary.d.ts +2 -0
  107. package/dist/vocabulary.d.ts.map +1 -0
  108. package/dist/vocabulary.js +3 -0
  109. package/dist/vocabulary.js.map +1 -0
  110. package/editors/vscode/syntaxes/koyu.tmLanguage.json +2 -2
  111. package/examples/tower/site-geometry.muro +9 -0
  112. package/examples/two-rooms.canonical.json +1 -1
  113. package/package.json +37 -5
  114. package/src/analysis/contracts.ts +234 -0
  115. package/src/analysis/index.ts +61 -0
  116. package/src/analysis/json.ts +117 -0
  117. package/src/cli.ts +127 -28
  118. package/src/core/diagnose.ts +11 -1
  119. package/src/core/model.ts +67 -3
  120. package/src/core/parse.ts +99 -0
  121. package/src/core/site.ts +17 -0
  122. package/src/core/vocabulary.ts +12 -0
  123. package/src/diagnostics.ts +8 -0
  124. package/src/diff.ts +14 -0
  125. package/src/draw/plan.ts +31 -0
  126. package/src/form.ts +37 -0
  127. package/src/graph.ts +12 -0
  128. package/src/index.ts +39 -195
  129. package/src/mcp.ts +57 -25
  130. package/src/model.ts +45 -0
  131. package/src/validate/assessment.ts +1934 -0
  132. package/src/validate/builtin/access.ts +642 -0
  133. package/src/validate/builtin/daylight.ts +321 -0
  134. package/src/validate/builtin/door-column-collisions.ts +266 -0
  135. package/src/validate/builtin/envelope.ts +227 -0
  136. package/src/validate/builtin/freeze.ts +19 -0
  137. package/src/validate/builtin/index.ts +156 -0
  138. package/src/validate/builtin/site.ts +445 -0
  139. package/src/validate/builtin/vertical-runs.ts +390 -0
  140. package/src/validate/contracts.ts +240 -0
  141. package/src/validate/index.ts +45 -99
  142. package/src/vocabulary.ts +9 -0
  143. package/dist/validate/access.d.ts +0 -6
  144. package/dist/validate/access.d.ts.map +0 -1
  145. package/dist/validate/access.js +0 -248
  146. package/dist/validate/access.js.map +0 -1
  147. package/dist/validate/envelope.d.ts +0 -4
  148. package/dist/validate/envelope.d.ts.map +0 -1
  149. package/dist/validate/envelope.js +0 -55
  150. package/dist/validate/envelope.js.map +0 -1
  151. package/dist/validate/light.d.ts +0 -6
  152. package/dist/validate/light.d.ts.map +0 -1
  153. package/dist/validate/light.js +0 -28
  154. package/dist/validate/light.js.map +0 -1
  155. package/dist/validate/runs.d.ts +0 -16
  156. package/dist/validate/runs.d.ts.map +0 -1
  157. package/dist/validate/runs.js +0 -60
  158. package/dist/validate/runs.js.map +0 -1
  159. package/dist/validate/site.d.ts +0 -6
  160. package/dist/validate/site.d.ts.map +0 -1
  161. package/dist/validate/site.js +0 -63
  162. package/dist/validate/site.js.map +0 -1
  163. package/src/validate/access.ts +0 -291
  164. package/src/validate/envelope.ts +0 -59
  165. package/src/validate/light.ts +0 -43
  166. package/src/validate/runs.ts +0 -87
  167. package/src/validate/site.ts +0 -84
package/src/cli.ts CHANGED
@@ -18,7 +18,9 @@ import { check, checkDiagnostics, type Diagnostic } from "./core/diagnose.js";
18
18
  import { renderDiff, semanticDiff } from "./core/diff.js";
19
19
  import { doorsBetween, neighbors } from "./core/graph.js";
20
20
  import { daylightInputs } from "./core/light.js";
21
- import { validate, type Finding } from "./validate/index.js";
21
+ import { assess } from "./validate/assessment.js";
22
+ import { AssessmentConfigError, type AssessmentReport } from "./validate/contracts.js";
23
+ import { createSchematicRegistry, SCHEMATIC_PROFILE_ID } from "./validate/builtin/index.js";
22
24
  import { siteReport } from "./core/site.js";
23
25
  import {
24
26
  areaM2,
@@ -119,13 +121,80 @@ function enumOpt<T extends string>(
119
121
  return raw as T;
120
122
  }
121
123
 
124
+ /** The one profile koyu ships. Any other name is the caller's, and this build cannot resolve it. */
125
+ const BUILTIN_PROFILE = SCHEMATIC_PROFILE_ID.id;
126
+
127
+ /**
128
+ * Run a rule set over the model.
129
+ *
130
+ * The profile and the effective date are **required**. Neither is guessed from the filename,
131
+ * the locale, the environment or the clock: a judgement whose grounds were inferred cannot be
132
+ * reproduced, and one that quietly picked a default is worse than one that refused to start.
133
+ */
134
+ function runAssessment(model: Model, rest: string[]): AssessmentReport {
135
+ const profile = opt(rest, "-p", "--profile");
136
+ if (!profile) {
137
+ die(
138
+ "validate needs an explicit profile: --profile <id>\n" +
139
+ ` koyu ships one: ${BUILTIN_PROFILE}`,
140
+ );
141
+ }
142
+ if (profile !== BUILTIN_PROFILE) {
143
+ die(`Unknown profile: ${profile}\n koyu ships one: ${BUILTIN_PROFILE}`);
144
+ }
145
+ const asOf = opt(rest, "--as-of");
146
+ if (!asOf) {
147
+ die(
148
+ "validate needs an explicit effective date: --as-of YYYY-MM-DD\n" +
149
+ " the date is not read from the clock, so that the same file judges the same way twice",
150
+ );
151
+ }
152
+
153
+ try {
154
+ return assess(model, {
155
+ registry: createSchematicRegistry(),
156
+ profile: SCHEMATIC_PROFILE_ID,
157
+ context: { schema: "koyu-context/1", asOf, values: {} },
158
+ });
159
+ } catch (e) {
160
+ // Configuration is the caller's problem, so it exits like a usage error rather than a verdict.
161
+ if (e instanceof AssessmentConfigError) die(`✖ ${e.message}`);
162
+ throw e;
163
+ }
164
+ }
165
+
166
+ /**
167
+ * 0 only when the whole set ran and nothing was violated.
168
+ *
169
+ * A caution that failed still exits 0 — it is a doubt, not a breach. But an indeterminate rule,
170
+ * a rule that errored, or an inconsistent model exits 1: **not being able to judge is not the
171
+ * same as passing**, and silence there is exactly what this exit code exists to prevent.
172
+ */
173
+ function assessmentExit(report: AssessmentReport): number {
174
+ if (report.summary.state !== "complete") return 1;
175
+ if (report.model.state !== "consistent") return 1;
176
+ return report.findings.some((f) => f.level === "violation") ? 1 : 0;
177
+ }
178
+
179
+ /** The first model-anchored line among a finding's evidence, formatted like every other locator. */
180
+ function firstModelLine(evidence: AssessmentReport["findings"][number]["outcome"]["evidence"]): string {
181
+ for (const item of evidence) {
182
+ for (const source of item.sources) {
183
+ if (source.kind === "model" && source.location?.line !== undefined) {
184
+ return `${srcRef(source.location.line, source.location.file)}: `;
185
+ }
186
+ }
187
+ }
188
+ return "";
189
+ }
190
+
122
191
  function main(argv: string[]): number {
123
192
  const [cmd, file, ...rest] = argv;
124
193
  if (!cmd || !file) {
125
194
  console.log(
126
195
  "Usage: koyu <check|validate|layers|diff|plan|axo|doors|graph|stats|levels|runs|light|site|json> <file.muro> [args...]\n" +
127
196
  " check: --json (emit Diagnostic[] as JSON) / --strict (exit 1 if there are warnings) — structural consistency only\n" +
128
- " validate: --json (emit Finding[] as JSON) — architectural judgement (not what check guarantees)\n" +
197
+ " validate: --profile <id> --as-of <YYYY-MM-DD> [--json] — architectural judgement (not what check guarantees)\n" +
129
198
  " layers: the layers that took part in composition, weakest first. --attrs for the provenance of each attribute\n" +
130
199
  " diff: koyu diff <a.muro> <b.muro> [--json] — the difference in the language of composition (0=no difference / 1=differences / 2=the input is broken)",
131
200
  );
@@ -210,26 +279,37 @@ function main(argv: string[]): number {
210
279
  return 1;
211
280
  }
212
281
  case "validate": {
213
- // 建築的な判定 (docs/reference/scope.md)。**check の保証ではない** — 型もコードの綴りも別で、
214
- // 終了コードだけが同じ流儀 (0=違反なし / 1=違反あり)
215
- const findings = validate(model);
282
+ // 建築的な判定 (docs/reference/scope.md)。**check の保証ではない** — 型も綴りも別である。
283
+ //
284
+ // profile と基準日は呼び出し側が明示する。管轄も基準日も推測せず、内蔵 profile を
285
+ // 黙って選ばない — 無根拠に成功して見える判定より、入力不足で止まる方を採る。
286
+ const report = runAssessment(model, rest);
216
287
  if (rest.includes("--json")) {
217
- console.log(JSON.stringify(findings, null, 1));
218
- return findings.some((f) => f.level === "violation") ? 1 : 0;
288
+ console.log(JSON.stringify(report, null, 1));
289
+ return assessmentExit(report);
219
290
  }
220
- const label = (f: Finding) => (f.level === "violation" ? "✖" : "⚠");
221
- for (const f of findings) {
222
- const where = f.line !== undefined ? `${srcRef(f.line, f.file)}: ` : "";
223
- console.log(`${label(f)} [${f.rule}] ${where}${f.message}`);
291
+ for (const f of report.findings) {
292
+ const where = firstModelLine(f.outcome.evidence);
293
+ console.log(
294
+ `${f.level === "violation" ? "✖" : "⚠"} [${f.rule.id}] ${where}${f.outcome.message}`,
295
+ );
224
296
  }
225
- const violations = findings.filter((f) => f.level === "violation").length;
226
- const cautions = findings.length - violations;
297
+ const violations = report.findings.filter((f) => f.level === "violation").length;
298
+ const cautions = report.findings.length - violations;
227
299
  console.log(
228
- findings.length === 0
300
+ report.findings.length === 0
229
301
  ? "✔ Nothing caught by validation (this is a judgement, not a guarantee about the composition)"
230
302
  : `Validation — ${qty(violations, "violation", "violations")} / ${qty(cautions, "caution", "cautions")}`,
231
303
  );
232
- return violations > 0 ? 1 : 0;
304
+ console.log(
305
+ ` ${report.profile.id}@${report.profile.revision} — ` +
306
+ `${report.summary.rules.evaluated} evaluated / ${report.summary.rules.notApplicable} not applicable / ` +
307
+ `${report.summary.rules.indeterminate} indeterminate / ${report.summary.rules.error} error`,
308
+ );
309
+ if (report.summary.state === "incomplete") {
310
+ console.log(" Incomplete — something could not be judged, which is not the same as passing");
311
+ }
312
+ return assessmentExit(report);
233
313
  }
234
314
  case "layers": {
235
315
  // 合成の規則1と6 (docs/reference/muro/import.md) — 強度順序を見せ、最終値の出所を言う。
@@ -381,34 +461,53 @@ function main(argv: string[]): number {
381
461
  return 0;
382
462
  }
383
463
  case "light": {
384
- // 採光は**判定**である — core が返すのは床面積と有効窓面積という数だけで、
385
- // 1/7 の合否は検証の面 (validate) が言う (docs/reference/scope.md)
464
+ // **数だけを返す。**床面積と有効窓面積は模型から出る事実であり、そこへ線を引くのは
465
+ // 規則の側の仕事である。閾値をここに書けば validate と二重になり、片方だけが古くなる
466
+ // (docs/reference/scope.md)。合否は koyu validate が言う
386
467
  const inputs = daylightInputs(model);
387
468
  if (inputs.length === 0) {
388
469
  console.log("Nothing is in daylight scope (write daylight:1 on the rooms to be judged)");
389
470
  return 0;
390
471
  }
391
- const failing = new Set(
392
- validate(model).filter((f) => f.rule === "daylight.ratio").flatMap((f) => f.path ?? []),
393
- );
394
472
  for (const d of inputs) {
395
- const ok = !failing.has(d.space.path);
396
473
  const ratio = d.window > 0 ? `1/${(d.floor / d.window).toFixed(1)}` : "no window";
397
474
  console.log(
398
- `${ok ? "✔" : "✖"} ${d.space.path}\t${displayName(d.space)}\twindow ${d.window.toFixed(2)} m2 / floor ${d.floor.toFixed(2)} m2 = ${ratio} (needs 1/7 ≈ ${(d.floor / 7).toFixed(2)} m2)` +
475
+ ` ${d.space.path}\t${displayName(d.space)}\twindow ${d.window.toFixed(2)} m2 / floor ${d.floor.toFixed(2)} m2 = ${ratio}` +
399
476
  (d.missingH ? " ⚠ windows without h: are not counted" : ""),
400
477
  );
401
478
  }
402
479
  console.log(
403
- failing.size === 0
404
- ? `✔ Every room meets 1/7 — ${qty(inputs.length, "room", "rooms")} in scope (a rough judgement with no correction factor — this is validation, not what check guarantees)`
405
- : `✖ Short of 1/7: ${failing.size} of ${qty(inputs.length, "room", "rooms")} (this is a validation judgement)`,
480
+ `${qty(inputs.length, "room", "rooms")} in daylight scope — these are numbers, not a verdict (koyu validate applies the rule)`,
406
481
  );
407
- return failing.size === 0 ? 0 : 1;
482
+ return 0;
408
483
  }
409
484
  case "site": {
410
485
  // 敷地の問い: 敷地面積・接道・建蔽率・容積率 (基本計画のボリューム検討の数字)
411
486
  const r = siteReport(model);
487
+ // 測地の枠 (ADR-0057) — 敷地の有無と無関係に、書かれていれば読み上げる。
488
+ // **方位は言葉にする。**磁北を書き写した値は範囲内の整った数で、文法では捕まらない。
489
+ // 人が一度声に出して読むことだけが、5〜9.5度の取り違えを捕まえる
490
+ if (model.origin) {
491
+ const o = model.origin;
492
+ const height =
493
+ o.elevation !== undefined
494
+ ? ` / elevation ${o.elevation} m of z=0 (vertical CRS ${o.vertical})`
495
+ : "";
496
+ console.log(`Frame: EPSG ${o.epsg} / easting ${o.easting} m / northing ${o.northing} m${height}`);
497
+ }
498
+ if (model.azimuth) {
499
+ const deg = model.azimuth.deg;
500
+ const trim = (n: number): string => String(Math.round(n * 1e4) / 1e4);
501
+ const words =
502
+ deg === 0
503
+ ? "due north"
504
+ : deg === 180
505
+ ? "due south"
506
+ : deg < 180
507
+ ? `${trim(deg)}° east of true north`
508
+ : `${trim(360 - deg)}° west of true north`;
509
+ console.log(`Bearing: +Y bears ${trim(deg)}° true — ${words}`);
510
+ }
412
511
  if (!r.siteZone && r.roads.length === 0) {
413
512
  console.log("There is no site (write site:1 on a zone and road:<width> on the road)");
414
513
  return 1;
@@ -434,8 +533,8 @@ function main(argv: string[]): number {
434
533
  ` Road: ${road.road.path}${typeof nm === "string" ? ` (${nm})` : ""} width ${road.width}mm / frontage ${road.frontage}mm`,
435
534
  );
436
535
  }
437
- console.log(` Building footprint (horizontal projection, rough): ${r.footprint.toFixed(2)} m2 → building coverage ratio ${((r.footprint / site) * 100).toFixed(1)}%`);
438
- console.log(` Total floor area: ${r.totalFloor.toFixed(2)} m2 → floor area ratio ${((r.totalFloor / site) * 100).toFixed(1)}%`);
536
+ console.log(` Building footprint (horizontal projection, rough): ${r.footprint.toFixed(2)} m2 → building coverage ratio ${r.coveragePercent ?? "—"}%`);
537
+ console.log(` Total floor area: ${r.totalFloor.toFixed(2)} m2 → floor area ratio ${r.floorAreaRatioPercent ?? "—"}%`);
439
538
  return 0;
440
539
  }
441
540
  case "axo": {
@@ -103,6 +103,7 @@ export const DIAGNOSTIC_CODES = {
103
103
  SIT01: "error", // 敷地形状の重複頂点
104
104
  SIT02: "error", // 敷地形状の自己交差
105
105
  SIT04: "warning", // 対応するゾーンの無いpolygon
106
+ SIT06: "warning", // originがあってazimuthが無い — 位置は決まるが向きが決まらない (ADR-0057)
106
107
  UID01: "error", // 数字だけのuid (ADR-0015)
107
108
  UID02: "error", // 空白を含むuid
108
109
  UID03: "error", // uidの重複
@@ -1166,9 +1167,18 @@ function checkLevelSufficiency(ctx: Ctx): void {
1166
1167
  }
1167
1168
  }
1168
1169
 
1169
- /** 敷地形状 — SIT01 / SIT02 / SIT04 (与件の健全性。建物との関係の判断は検証の面) */
1170
+ /** 敷地形状と測地の枠 — SIT06 / SIT01 / SIT02 / SIT04 (与件の健全性。建物との関係の判断は検証の面) */
1170
1171
  function checkSite(ctx: Ctx): void {
1171
1172
  const { model, emit, loc, withRect, levels, levelIndex } = ctx;
1173
+ // 測地の枠 (ADR-0057): 位置だけ書いて向きを書かないモデルは配置できない。回転を受け取らなかった
1174
+ // 消費者は 0 と仮定して最大360度間違える — 両方書かないより悪い静かな失敗なので警告する。
1175
+ // 逆は警告しない: azimuth 単独は完結した言明である (向きを知り、位置を知らない)
1176
+ if (model.origin && !model.azimuth) {
1177
+ emit("SIT06", "origin is written without azimuth, so the model has a position but no bearing", {
1178
+ line: model.origin.line,
1179
+ file: model.origin.file,
1180
+ });
1181
+ }
1172
1182
  // 敷地形状 (ADR-0011): 形の妥当性、対応ゾーンの存在、宣言面積との照合、建物のはみ出し検査。
1173
1183
  // はみ出しは四隅の内包に加え、多角形の頂点の入り込みと辺の交差を見る — 凹敷地でも正しい (ADR-0013)。
1174
1184
  // 地上の外部空間タイル (庭・通路) は近似なので検査しない — 面積の真は多角形が持つ
package/src/core/model.ts CHANGED
@@ -17,11 +17,12 @@ export const DEFAULT_LANGUAGE_VERSION = "1.1";
17
17
 
18
18
  /**
19
19
  * 機械形式 (正準JSON) が自分を名乗る版 (ADR-0036)。**言語版でもツール版でもない** —
20
- * 数えるのは綴りだけである。minorはキーが増えたとき (増えたキーを持たない文書のバイトは変わらない)、
21
- * majorは既存のキーの名前・並び・照合順・正規化・数の綴りが変わったとき (既存の文書のバイトが変わる)。
20
+ * 数えるのは綴りだけである。minorはキーが増えたとき、majorは既存のキーの名前・並び・照合順・
21
+ * 正規化・数の綴りが変わったとき。**minorでも全ての文書のバイトは動く** — この文字列自体が
22
+ * 第一キーだからで、増えたキーを持たない文書も先頭行だけは変わる (ADR-0051 が実測している)。
22
23
  * 意味論の版は muro が持つので、`koyu` キー (書かれた版宣言の素通し) とは別の面である
23
24
  */
24
- export const CANONICAL_FORMAT = "koyu-canonical/1.1";
25
+ export const CANONICAL_FORMAT = "koyu-canonical/1.2";
25
26
 
26
27
  /** 方位。edge指定は「最初に書いた空間」の矩形から見た辺。N=+Y, S=-Y, E=+X, W=-X */
27
28
  export type Edge = "N" | "E" | "S" | "W";
@@ -250,6 +251,13 @@ export interface Model {
250
251
  version: string;
251
252
  name?: string;
252
253
  unit: "mm";
254
+ /**
255
+ * 測地の枠 — 位置 (ADR-0057)。**core は持つだけで、投影も子午線収差角も計算しない。**
256
+ * モデルは一つの枠を持つ (`origin` は全レイヤーを通して一度)
257
+ */
258
+ origin?: SiteOrigin;
259
+ /** 測地の枠 — 真北 (ADR-0057)。**不在は 0 ではなく「未知」である** */
260
+ azimuth?: Azimuth;
253
261
  grid: { X: GridAxis; Y: GridAxis };
254
262
  levels: Record<string, Level>;
255
263
  spaces: Map<string, Space>;
@@ -350,6 +358,47 @@ export interface SitePolygon {
350
358
  file?: string;
351
359
  }
352
360
 
361
+ /**
362
+ * 測地の原点 (ADR-0057) — モデルの (0,0,0) が外の座標系のどこに座るか。測量に由来する所与で、
363
+ * 敷地形状 (SitePolygon) と同じ隔離レイヤーに住む。
364
+ *
365
+ * **単位はメートルであって mm ではない。** これはモデルの中の長さではなく、外の枠の中の点であり、
366
+ * 外の枠は自分の数字を持つ。mm を選べば `-8000.12` → `-800012` の桁埋め誤りが 7.2m のずれとして
367
+ * 完全に静かに通る (1000倍の誤りは騒がしいが、桁埋めの誤りは騒がない)。
368
+ *
369
+ * **EPSG コードは解釈しない。**測地系・投影・系番号・軸順を一語で言い切るので、測地系を別に綴れば
370
+ * 矛盾の余地ができる。core が見るのは正の整数であることだけで、コード表は持たない
371
+ */
372
+ export interface SiteOrigin {
373
+ /** 水平 (2D 投影) CRS の EPSG コード。複合コードは受けない — `vertical` と役割を分ける */
374
+ epsg: number;
375
+ /** 東距 m。**平面直角座標系の成果では Y 欄である** */
376
+ easting: number;
377
+ /** 北距 m。**平面直角座標系の成果では X 欄である** — 通常の慣習の逆 */
378
+ northing: number;
379
+ /** モデルの z=0 の高さ m。**GL でも地盤面でも平均地盤面でもない。**`vertical` と対で書く */
380
+ elevation?: number;
381
+ /** 鉛直 CRS の EPSG コード (日本は 6695 = T.P. 系)。`elevation` と対で必須 */
382
+ vertical?: number;
383
+ line: number;
384
+ file?: string;
385
+ }
386
+
387
+ /**
388
+ * 真北 (ADR-0057) — モデルの +Y 軸の真方位角。真北から時計回りの度、0 ≤ deg < 360。
389
+ *
390
+ * **方位角であって回転角ではない。**「+Y から北へ時計回り」と綴れば逆向きの方位角になり、
391
+ * 建築も測量も時計回りの角を北から対象へ測るので、読者の既定の読みが定義の逆になる。
392
+ *
393
+ * `N/E/S/W` は依然として軸の語である (docs/reference/muro/orientation.md)。方位を持つ場所は
394
+ * ここひとつで、面の真方位角は deg / deg+90 / deg+180 / deg+270 と消費者の側で一行で出る
395
+ */
396
+ export interface Azimuth {
397
+ deg: number;
398
+ line: number;
399
+ file?: string;
400
+ }
401
+
353
402
  /** 多角形の面積 ㎡。シューレースの実体は poly.ts にひとつだけある */
354
403
  export const polygonAreaM2 = (points: Pt[]): number => poly.area(points) / 1e6;
355
404
 
@@ -895,6 +944,21 @@ export function toCanonical(model: Model): string {
895
944
  ...(model.versionDeclared ? { koyu: model.version } : {}),
896
945
  ...(model.name ? { name: model.name } : {}),
897
946
  unit: model.unit,
947
+ // 測地の枠 (ADR-0057) — **単位を言った直後、グリッドを言う前。**この二つは grid が張る
948
+ // 座標系そのものを外の世界に結びつけるので、その座標系より先に立つ。
949
+ // **値はメートル**であって mm ではない (外の枠の中の点だから)。書かれなければ鍵ごと出ない
950
+ ...(model.origin
951
+ ? {
952
+ origin: {
953
+ epsg: model.origin.epsg,
954
+ easting: model.origin.easting,
955
+ northing: model.origin.northing,
956
+ ...(model.origin.elevation !== undefined ? { elevation: model.origin.elevation } : {}),
957
+ ...(model.origin.vertical !== undefined ? { vertical: model.origin.vertical } : {}),
958
+ },
959
+ }
960
+ : {}),
961
+ ...(model.azimuth ? { azimuth: model.azimuth.deg } : {}),
898
962
  grid: { X: model.grid.X.coords, Y: model.grid.Y.coords },
899
963
  levels: sortObj(
900
964
  Object.fromEntries(
package/src/core/parse.ts CHANGED
@@ -385,6 +385,105 @@ function ingest(
385
385
  });
386
386
  break;
387
387
  }
388
+ case "origin": {
389
+ // 測地の枠 — 位置 (ADR-0057)。所与であって設計ではない。**core は持つだけで、投影も
390
+ // 子午線収差角も計算しない。**値はメートル — モデルの中の長さではなく外の枠の中の点だから
391
+ // origin epsg:6677 easting:-8000.123 northing:-34000.456 elevation:2.35 vertical:6695
392
+ if (model.origin) {
393
+ throw new SourceError(
394
+ ln,
395
+ `Duplicate origin: a model has one frame (first seen in ${model.origin.file ?? "the same file"} at line ${model.origin.line})`,
396
+ );
397
+ }
398
+ const attrs = parseAttrs(rest, ln);
399
+ const epsg = takeNumber(attrs, "epsg", ln, { positive: true });
400
+ const easting = takeNumber(attrs, "easting", ln);
401
+ const northing = takeNumber(attrs, "northing", ln);
402
+ const elevation = takeNumber(attrs, "elevation", ln);
403
+ const vertical = takeNumber(attrs, "vertical", ln, { positive: true });
404
+ // **origin は attrs を持たない。**残ったキーは正準JSONにも痕跡を残さず消えるので、
405
+ // ここで拒まないと `eastign:` が黙って原点の無いモデルになる (level と同じ理由 — ADR-0033)
406
+ for (const key of Object.keys(attrs)) {
407
+ throw new SourceError(
408
+ ln,
409
+ `origin carries ${key}:, which is not in the ledger (origin reads epsg / easting / northing / elevation / vertical)`,
410
+ );
411
+ }
412
+ if (epsg === undefined) {
413
+ throw new SourceError(ln, "origin requires epsg: (the EPSG code of a projected CRS)");
414
+ }
415
+ if (!Number.isInteger(epsg)) {
416
+ throw new SourceError(ln, `epsg is written as an EPSG code (a whole number): ${epsg}`);
417
+ }
418
+ // 東距と北距は対 — 片方だけの原点は点を指さない
419
+ if (easting === undefined || northing === undefined) {
420
+ throw new SourceError(
421
+ ln,
422
+ "origin requires easting: and northing: together (metres, in the CRS that epsg: names)",
423
+ );
424
+ }
425
+ // **高さは基準を言わずには受けない。**平面直角座標系の CRS は 2D で鉛直軸を持たないので、
426
+ // 高さだけを書けば何から測ったかが言われない。日本では T.P. / A.P. / O.P. / Y.P. が 1m 超違い、
427
+ // 楕円体高と正標高はジオイド高 (約30〜40m) だけ違う
428
+ if ((elevation === undefined) !== (vertical === undefined)) {
429
+ throw new SourceError(
430
+ ln,
431
+ "elevation: and vertical: are written together (a height needs the datum it is measured from)",
432
+ );
433
+ }
434
+ if (vertical !== undefined && !Number.isInteger(vertical)) {
435
+ throw new SourceError(ln, `vertical is written as an EPSG code (a whole number): ${vertical}`);
436
+ }
437
+ // 桁の上限は測地の規則ではなく書式の規則である — 正準JSONは指数表記を使わないと約束している
438
+ if (Math.abs(easting) > 1e7) {
439
+ throw new SourceError(ln, `easting is out of range for a coordinate in metres: ${easting}`);
440
+ }
441
+ if (Math.abs(northing) > 1e7) {
442
+ throw new SourceError(ln, `northing is out of range for a coordinate in metres: ${northing}`);
443
+ }
444
+ if (elevation !== undefined && Math.abs(elevation) > 1e4) {
445
+ throw new SourceError(ln, `elevation is out of range in metres: ${elevation}`);
446
+ }
447
+ model.origin = {
448
+ epsg,
449
+ easting,
450
+ northing,
451
+ ...(elevation !== undefined ? { elevation } : {}),
452
+ ...(vertical !== undefined ? { vertical } : {}),
453
+ line: ln,
454
+ ...(file ? { file } : {}),
455
+ };
456
+ break;
457
+ }
458
+ case "azimuth": {
459
+ // 測地の枠 — 真北 (ADR-0057)。**+Y 軸の真方位角**であって回転角ではない。
460
+ // 「+Y から北へ時計回り」と綴れば逆向きの方位角になり、読者の既定の読みが定義の逆になる
461
+ // azimuth Y 347.5
462
+ if (model.azimuth) {
463
+ throw new SourceError(
464
+ ln,
465
+ `Duplicate azimuth: a model has one frame (first seen in ${model.azimuth.file ?? "the same file"} at line ${model.azimuth.line})`,
466
+ );
467
+ }
468
+ if (rest[0] !== "Y") {
469
+ throw new SourceError(
470
+ ln,
471
+ `azimuth takes the form azimuth Y <degrees> (the bearing of the +Y axis): ${rest[0] ?? ""}`,
472
+ );
473
+ }
474
+ if (rest.length !== 2) throw new SourceError(ln, "azimuth takes one value, in degrees");
475
+ const deg = toNumber(rest[1]!, ln, "The azimuth");
476
+ // **畳まずに拒む。**370 を黙って 10 にすれば誤りが隠れる。360 も受けない (0 の二つ目の綴り)
477
+ if (!(deg >= 0 && deg < 360)) {
478
+ const hint = deg < 0 && deg > -360 ? ` (write ${deg + 360})` : "";
479
+ throw new SourceError(
480
+ ln,
481
+ `azimuth is a bearing clockwise from true north, 0 <= v < 360: ${deg}${hint}`,
482
+ );
483
+ }
484
+ model.azimuth = { deg, line: ln, ...(file ? { file } : {}) };
485
+ break;
486
+ }
388
487
  case "name": {
389
488
  const nm = rest.join(" ");
390
489
  if (!nm) throw new SourceError(ln, "name takes a value");
package/src/core/site.ts CHANGED
@@ -38,6 +38,15 @@ export interface SiteReport {
38
38
  footprint: number;
39
39
  /** 延べ面積 m² (屋内床面積の合計) */
40
40
  totalFloor: number;
41
+ /** 面積率の分母 — 宣言があれば宣言、無ければ導出 */
42
+ areaBasis: number;
43
+ /**
44
+ * 建蔽率 % (建築面積 ÷ 分母、小数第1位)。分母が 0 なら `undefined`。
45
+ * **数であって合否ではない** — 指定建蔽率と比べるのは規則の側の仕事である
46
+ */
47
+ coveragePercent?: number;
48
+ /** 容積率 % (延べ面積 ÷ 分母、小数第1位)。分母が 0 なら `undefined` */
49
+ floorAreaRatioPercent?: number;
41
50
  roads: RoadFrontage[];
42
51
  }
43
52
 
@@ -78,6 +87,11 @@ export function siteReport(model: Model): SiteReport {
78
87
  roads.push({ road, width: road.attrs["road"], frontage: Math.round(frontage) });
79
88
  }
80
89
 
90
+ // 面積率は一箇所でだけ丸める。CLI・MCP・規則が各々で割れば、いずれ片方だけがずれる
91
+ const areaBasis = typeof declared === "number" ? declared : derivedArea;
92
+ const percent = (part: number): number | undefined =>
93
+ areaBasis === 0 ? undefined : Math.round((part / areaBasis) * 1000) / 10;
94
+
81
95
  return {
82
96
  ...(siteZone ? { siteZone } : {}),
83
97
  ...(polygon ? { polygon } : {}),
@@ -85,6 +99,9 @@ export function siteReport(model: Model): SiteReport {
85
99
  derivedArea,
86
100
  footprint,
87
101
  totalFloor,
102
+ areaBasis,
103
+ ...(percent(footprint) !== undefined ? { coveragePercent: percent(footprint) } : {}),
104
+ ...(percent(totalFloor) !== undefined ? { floorAreaRatioPercent: percent(totalFloor) } : {}),
88
105
  roads,
89
106
  };
90
107
  }
@@ -191,6 +191,18 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
191
191
  pitch: structure(),
192
192
  underground: structure(),
193
193
  },
194
+
195
+ /**
196
+ * 測地の枠の位置 (ADR-0057)。level と同じく attrs を持たない — 台帳外のキーは parse が拒む。
197
+ * **値はメートル**であって mm ではない。EPSG コードは解釈しない不透明な整数である
198
+ */
199
+ origin: {
200
+ epsg: structure(),
201
+ easting: structure(),
202
+ northing: structure(),
203
+ elevation: structure(),
204
+ vertical: structure(),
205
+ },
194
206
  };
195
207
 
196
208
  /** その要素で、名前空間なしに書いてよいキーか */
@@ -0,0 +1,8 @@
1
+ // Public structural-diagnostics surface. Human-readable formatting belongs to the CLI.
2
+
3
+ export {
4
+ checkDiagnostics,
5
+ DIAGNOSTIC_CODES,
6
+ type Diagnostic,
7
+ type DiagnosticCode,
8
+ } from "./core/diagnose.js";
package/src/diff.ts ADDED
@@ -0,0 +1,14 @@
1
+ // Public semantic-diff surface. Text rendering remains a presentation concern.
2
+
3
+ export {
4
+ semanticDiff,
5
+ type BoundaryChange,
6
+ type BoundaryItem,
7
+ type ChangedItem,
8
+ type ColumnItem,
9
+ type FieldChange,
10
+ type GridChange,
11
+ type ModelDiff,
12
+ type RenamedItem,
13
+ type SpaceItem,
14
+ } from "./core/diff.js";
package/src/draw/plan.ts CHANGED
@@ -266,6 +266,37 @@ export function svgPlan(model: Model, opts: PlanOptions = {}): string {
266
266
  );
267
267
  }
268
268
 
269
+ // 北矢印 (ADR-0057) — azimuth が書かれているときだけ描く。**表現であって形ではない**ので
270
+ // Form には無く、紙の座標に直接置く。これがある理由は装飾ではない — 方位の 180度違い・
271
+ // 余角違い・磁北の書き写しは、どれも範囲内の整った数として通る。**絵だけが捕まえる。**
272
+ //
273
+ // 画面上の北: モデルの +Y は上、+X は右。真方位角は +Y から時計回りなので、画面でも時計回り
274
+ if (model.azimuth) {
275
+ const rad = (model.azimuth.deg * Math.PI) / 180;
276
+ const nx = Math.sin(rad);
277
+ const ny = -Math.cos(rad);
278
+ const cx = W - M / 2; // 右余白の中央 (通り芯記号と同じ帯に、離して置く)
279
+ const cy = M / 2;
280
+ const R = 21;
281
+ const px = -ny; // 軸に直交する向き (矢羽根の底辺)
282
+ const py = nx;
283
+ const r2 = (n: number): string => String(Math.round(n * 100) / 100);
284
+ const head = [
285
+ [cx + nx * R, cy + ny * R],
286
+ [cx + nx * R * 0.42 + px * 4.6, cy + ny * R * 0.42 + py * 4.6],
287
+ [cx + nx * R * 0.42 - px * 4.6, cy + ny * R * 0.42 - py * 4.6],
288
+ ]
289
+ .map(([x, y]) => `${r2(x!)},${r2(y!)}`)
290
+ .join(" ");
291
+ parts.push(
292
+ `<g class="north-arrow">`,
293
+ `<line x1="${r2(cx - nx * R * 0.8)}" y1="${r2(cy - ny * R * 0.8)}" x2="${r2(cx + nx * R)}" y2="${r2(cy + ny * R)}" stroke="${INK}" stroke-width="1"/>`,
294
+ `<polygon points="${head}" fill="${INK}"/>`,
295
+ `<text x="${r2(cx + nx * (R + 10))}" y="${r2(cy + ny * (R + 10) + 3.4)}" text-anchor="middle" font-size="9" fill="${INK}">N</text>`,
296
+ `</g>`,
297
+ );
298
+ }
299
+
269
300
  // 表題
270
301
  const title = `${model.name ?? "Untitled"} — ${level} plan`;
271
302
  parts.push(
package/src/form.ts ADDED
@@ -0,0 +1,37 @@
1
+ // Public Form surface. derive() is the only public operation that assembles shape.
2
+
3
+ export {
4
+ derive,
5
+ DERIVATION_CONSTANTS,
6
+ type DeriveOptions,
7
+ type Form,
8
+ type FormBoundary,
9
+ type FormColumn,
10
+ type FormInput,
11
+ type FormLevel,
12
+ type FormOpening,
13
+ type FormPanel,
14
+ type FormPlan,
15
+ type FormRun,
16
+ type FormSeg,
17
+ type FormSite,
18
+ type FormSpace,
19
+ type FormSwing,
20
+ type PlanClass,
21
+ type PlanEntity,
22
+ type PlanRole,
23
+ type PlanSubject,
24
+ } from "./core/derive.js";
25
+
26
+ export { TOLERANCES } from "./core/tolerance.js";
27
+
28
+ export type { Slab, SlabKind } from "./core/fabric.js";
29
+
30
+ export type {
31
+ RunDevice,
32
+ RunForm,
33
+ RunPart,
34
+ RunSolid,
35
+ Seg2,
36
+ VerticalRun,
37
+ } from "./core/vertical.js";
package/src/graph.ts ADDED
@@ -0,0 +1,12 @@
1
+ // Public spatial-graph surface. Placement machinery remains internal.
2
+
3
+ export {
4
+ doorsBetween,
5
+ envelopeGaps,
6
+ neighbors,
7
+ passable,
8
+ segmentsFor,
9
+ type NeighborInfo,
10
+ type Route,
11
+ type Segment,
12
+ } from "./core/graph.js";