@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
@@ -1,77 +1,29 @@
1
- // koyu — 検証の面 (建築的な判定)
1
+ // koyu — the validation surface (`@kensnzk/koyu/validate`)
2
2
  //
3
- // **ここは core ではない。**core が言うのは「書かれたものがデータとして矛盾していない」
4
- // までであって、建築として妥当かは何も言わない (docs/reference/scope.md)。採光・面積率・
5
- // 外皮の連続・階段の寸法・到達可能性 — 建築の側の判断はすべてこの面に属す。
3
+ // **This is not core.** core says "what is written is not self-contradictory as data" and stops
4
+ // there; whether the building works is a different question with a different answer, and this
5
+ // face is where it gets answered (docs/reference/scope.md).
6
6
  //
7
- // この面は**凍らない**。規則が粗くても、管轄が一つしかなくても、精度が足りなくても、
8
- // 増やしてよいし捨ててよい。値段が安いのは、凍らないからである。
7
+ // This face does not freeze. Rules may be coarse, a rule set may cover one jurisdiction or none,
8
+ // and the resolution may be too low — add freely, throw away freely. It is cheap because it
9
+ // does not freeze. One condition attaches to that freedom: **a judgement must never be mistaken
10
+ // for what core guarantees.** The two are different from the type up:
9
11
  //
10
- // 汚くてよい条件は一つだけある — **判定の結果が、原本の保証と混同されないこと。**
11
- // そのために、core の Diagnostic とは**型ごと分けてある**:
12
+ // core Diagnostic { code: "HGT01", severity: "error" | "warning" }
13
+ // validation RuleOutcome { status: "pass" | "fail" | "indeterminate" } inside an AssessmentReport
12
14
  //
13
- // core Diagnostic { code: "HGT01", severity: "error" | "warning" }
14
- // 検証 Finding { rule: "daylight.ratio", level: "violation" | "caution" }
15
+ // Nothing here judges on its own. This module is the **SPI and the runner**: the caller composes
16
+ // an immutable registry of rules, rule sets and profiles, names one profile and one context, and
17
+ // gets back an `AssessmentReport`. There is no registration API, no process-global registry and
18
+ // no import-time side effect — a rule pack that is merely imported does nothing. koyu's own pack
19
+ // is one such value and gets no privileged path: see `@kensnzk/koyu/validate/builtin`.
15
20
  //
16
- // フィールド名が違うので、二つの配列は取り違えようがない。連結しようとすれば型が落ちる。
17
- // 「core の緑」と「判定の緑」を同じ言葉で語れないようにすることが、この分離の目的である。
21
+ // The report never collapses to a boolean or a bare array. "No finding" and "could not be
22
+ // judged" have to stay distinguishable, so the report keeps pass, fail, not-applicable,
23
+ // indeterminate and rule error apart, along with the identity of everything that was applied.
18
24
  //
19
- // 依存は一方向 — 検証は core を読むが、core は検証を知らない
20
- // (test/domains.test.ts が import を機械的に検査する)。
21
- import { accessFindings } from "./access.js";
22
- import { daylightFindings } from "./light.js";
23
- import { envelopeFindings } from "./envelope.js";
24
- import { runFindings } from "./runs.js";
25
- import { siteFindings } from "./site.js";
26
- /**
27
- * 判定の台帳。**綴りが core の診断コードと違う**のは事故を防ぐためである —
28
- * `ENV01` と `envelope.gap` を取り違える読み手はいない。
29
- *
30
- * 章 (`envelope` / `daylight` / `stair` / `run` / `access` / `column` / `site`) は管轄ではなく
31
- * 主題である。管轄が二つ目を持ったとき (日本の法規と別の国の法規) に章の下へ足す。
32
- */
33
- export const VALIDATION_RULES = {
34
- "envelope.gap": "caution", // 外皮に穴 — 何にも面していない外周 (ADR-0025)
35
- "daylight.ratio": "violation", // 有効窓面積 < 床面積/7 (ADR-0020)
36
- "daylight.unknown": "caution", // h を持たない窓があり、窓面積を数え切れていない
37
- "stair.proportion": "caution", // 導出された段が窮屈 (踏面 <240 / 2R+T が 550〜700 の外)
38
- "run.slope": "caution", // 導出された勾配が宣言より急・常用域の外
39
- "run.disconnected": "caution", // 縦動線の形はあるが上下を繋ぐ垂直境界が無い
40
- "access.unreachable": "violation", // 領域を持つ室から外部へ辿り着けない
41
- "access.voidonly": "violation", // 扉が吹抜け (床の無い所) にしか開いていない
42
- "access.throughtenant": "caution", // 階段室からの避難が賃貸区画を通る
43
- "access.parking": "violation", // 駐車場から車が出られない
44
- "access.backofhouse": "caution", // 共用廊下からバックヤードを通らずに縦動線へ届かない
45
- "column.blocksdoor": "violation", // 導出された柱が導出された扉と重なる (ADR-0023)
46
- "site.escape": "violation", // 建物が敷地形状からはみ出す
47
- "site.area": "caution", // 敷地面積の宣言と導出の食い違い
48
- "site.frontage": "violation", // 接道長が 2m 未満 (法43条の粗い写し)
49
- };
50
- /** Finding を組み立てる — level は規則の不変属性であって、場合によって変わらない */
51
- export function finding(rule, message, at = {}) {
52
- return {
53
- rule,
54
- level: VALIDATION_RULES[rule],
55
- message,
56
- ...(at.line !== undefined ? { line: at.line } : {}),
57
- ...(at.line !== undefined && at.file !== undefined ? { file: at.file } : {}),
58
- ...(at.path ? { path: at.path } : {}),
59
- };
60
- }
61
- /**
62
- * 全ての判定を回す。並びは章の順で、章の中は走査の順である
63
- * (core の checkDiagnostics と同じ規律 — ADR-0028)。
64
- *
65
- * **合否は返さない。**返るのは「守られなかったこと」の列であって、
66
- * 建物が使えるかどうかの結論ではない。
67
- */
68
- export function validate(model) {
69
- return [
70
- ...envelopeFindings(model),
71
- ...daylightFindings(model),
72
- ...runFindings(model),
73
- ...accessFindings(model),
74
- ...siteFindings(model),
75
- ];
76
- }
25
+ // Dependency runs one way — validation reads core, core knows nothing of validation
26
+ // (test/domains.test.ts checks the imports by machine).
27
+ export { assess, createAssessmentRegistry } from "./assessment.js";
28
+ export { ASSESSMENT_FORMAT, AssessmentConfigError, } from "./contracts.js";
77
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,EAAE;AACF,qDAAqD;AACrD,2DAA2D;AAC3D,yCAAyC;AACzC,EAAE;AACF,8CAA8C;AAC9C,kCAAkC;AAClC,EAAE;AACF,8CAA8C;AAC9C,0CAA0C;AAC1C,EAAE;AACF,gFAAgF;AAChF,iFAAiF;AACjF,EAAE;AACF,8CAA8C;AAC9C,iDAAiD;AACjD,EAAE;AACF,uCAAuC;AACvC,6CAA6C;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,cAAc,EAAE,SAAS,EAAE,gCAAgC;IAC3D,gBAAgB,EAAE,WAAW,EAAE,2BAA2B;IAC1D,kBAAkB,EAAE,SAAS,EAAE,2BAA2B;IAC1D,kBAAkB,EAAE,SAAS,EAAE,0CAA0C;IACzE,WAAW,EAAE,SAAS,EAAE,sBAAsB;IAC9C,kBAAkB,EAAE,SAAS,EAAE,wBAAwB;IACvD,oBAAoB,EAAE,WAAW,EAAE,oBAAoB;IACvD,iBAAiB,EAAE,WAAW,EAAE,0BAA0B;IAC1D,sBAAsB,EAAE,SAAS,EAAE,mBAAmB;IACtD,gBAAgB,EAAE,WAAW,EAAE,eAAe;IAC9C,oBAAoB,EAAE,SAAS,EAAE,4BAA4B;IAC7D,mBAAmB,EAAE,WAAW,EAAE,+BAA+B;IACjE,aAAa,EAAE,WAAW,EAAE,gBAAgB;IAC5C,WAAW,EAAE,SAAS,EAAE,kBAAkB;IAC1C,eAAe,EAAE,WAAW,EAAE,yBAAyB;CACG,CAAC;AAwB7D,sDAAsD;AACtD,MAAM,UAAU,OAAO,CACrB,IAAoB,EACpB,OAAe,EACf,KAAwD,EAAE;IAE1D,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC;QAC7B,OAAO;QACP,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAY;IACnC,OAAO;QACL,GAAG,gBAAgB,CAAC,KAAK,CAAC;QAC1B,GAAG,gBAAgB,CAAC,KAAK,CAAC;QAC1B,GAAG,WAAW,CAAC,KAAK,CAAC;QACrB,GAAG,cAAc,CAAC,KAAK,CAAC;QACxB,GAAG,YAAY,CAAC,KAAK,CAAC;KACvB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,EAAE;AACF,gGAAgG;AAChG,8FAA8F;AAC9F,4DAA4D;AAC5D,EAAE;AACF,iGAAiG;AACjG,4FAA4F;AAC5F,gGAAgG;AAChG,sEAAsE;AACtE,EAAE;AACF,4EAA4E;AAC5E,qGAAqG;AACrG,EAAE;AACF,iGAAiG;AACjG,iGAAiG;AACjG,gGAAgG;AAChG,iGAAiG;AACjG,uFAAuF;AACvF,EAAE;AACF,0FAA0F;AAC1F,wFAAwF;AACxF,8FAA8F;AAC9F,EAAE;AACF,oFAAoF;AACpF,wDAAwD;AAExD,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GAqBtB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ATTR_LEDGER, attrSpec, isNamespaced, type AttrSpec, type AttrTier, } from "./core/vocabulary.js";
2
+ //# sourceMappingURL=vocabulary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocabulary.d.ts","sourceRoot":"","sources":["../src/vocabulary.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,KAAK,QAAQ,EACb,KAAK,QAAQ,GACd,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ // Public vocabulary surface. Expose queries and the ledger, not implementation aliases.
2
+ export { ATTR_LEDGER, attrSpec, isNamespaced, } from "./core/vocabulary.js";
3
+ //# sourceMappingURL=vocabulary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocabulary.js","sourceRoot":"","sources":["../src/vocabulary.ts"],"names":[],"mappings":"AAAA,wFAAwF;AAExF,OAAO,EACL,WAAW,EACX,QAAQ,EACR,YAAY,GAGb,MAAM,sBAAsB,CAAC"}
@@ -168,7 +168,7 @@
168
168
  },
169
169
  "keyword-directive": {
170
170
  "comment": "行頭に書く語 — src/core/parse.ts の switch (head)",
171
- "match": "^(koyu|import|over|drop|asset|polygon|name|unit|grid|level|column|band|space|boundary|zone|stack)\\b",
171
+ "match": "^(koyu|import|over|drop|asset|polygon|origin|azimuth|name|unit|grid|level|column|band|space|boundary|zone|stack)\\b",
172
172
  "captures": { "1": { "name": "keyword.control.directive.koyu" } }
173
173
  },
174
174
  "path": {
@@ -178,7 +178,7 @@
178
178
  },
179
179
  "attr-ledger": {
180
180
  "comment": "The ledger keys that are not carrier-tier — the attributes the tools act on. ATTR_LEDGER in src/core/vocabulary.ts is the contract; free k:v gets a different colour",
181
- "match": "\\b(underground|escalator|daylight|ceiling|landing|outside|hinge|level|riser|slope|stair|style|swing|tread|pitch|entry|lane|lift|form|road|slab|site|area|turn|type|edge|name|ramp|void|uid|air|use|at|h|w|t|d|x|y)(:)",
181
+ "match": "\\b(underground|escalator|elevation|daylight|northing|vertical|ceiling|landing|outside|easting|hinge|level|riser|slope|stair|style|swing|tread|pitch|entry|lane|lift|form|road|slab|site|area|turn|type|edge|name|ramp|void|epsg|uid|air|use|at|h|w|t|d|x|y)(:)",
182
182
  "captures": {
183
183
  "1": { "name": "entity.other.attribute-name.koyu" },
184
184
  "2": { "name": "punctuation.separator.key-value.koyu" }
@@ -5,3 +5,12 @@
5
5
  # 北側隣地境界が斜め (2点で振れる) の五角形 — シューレースで 1,097.80㎡。
6
6
 
7
7
  polygon /site -2600,-7000 38000,-7000 38000,19600 2000,21000 -2600,15000
8
+
9
+ # 測地の枠 — 位置と真北 (ADR-0057)。これも測量に由来する所与なので同じレイヤーに住む。
10
+ # 値はメートル (mm ではない)。easting/northing は EPSG:6677 = JGD2011 平面直角座標系 IX 系、
11
+ # 成果の X 欄が northing、Y 欄が easting である。elevation はモデルの z=0 の高さで、
12
+ # EPSG:6695 (JGD2011 鉛直、T.P.) で測る — GL でも地盤面でも平均地盤面でもない。
13
+ # azimuth は +Y 軸の真方位角 (真北から時計回り) で、この建物は真北から 7.6 度西に振れている。
14
+ # koyu はこの二行から何も導出しない。座標系への配置は外の道具の仕事である。
15
+ origin epsg:6677 easting:-6250.480 northing:-35720.115 elevation:3.850 vertical:6695
16
+ azimuth Y 352.4
@@ -1,5 +1,5 @@
1
1
  {
2
- "format": "koyu-canonical/1.1",
2
+ "format": "koyu-canonical/1.2",
3
3
  "koyu": "1.1",
4
4
  "name": "二室",
5
5
  "unit": "mm",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kensnzk/koyu",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "空間を一次要素とするテキストネイティブ建築記述の探求 — writing architecture, not buildings",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -10,21 +10,53 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "default": "./dist/index.js"
12
12
  },
13
+ "./model": {
14
+ "types": "./dist/model.d.ts",
15
+ "default": "./dist/model.js"
16
+ },
17
+ "./diagnostics": {
18
+ "types": "./dist/diagnostics.d.ts",
19
+ "default": "./dist/diagnostics.js"
20
+ },
21
+ "./graph": {
22
+ "types": "./dist/graph.d.ts",
23
+ "default": "./dist/graph.js"
24
+ },
25
+ "./form": {
26
+ "types": "./dist/form.d.ts",
27
+ "default": "./dist/form.js"
28
+ },
29
+ "./analysis": {
30
+ "types": "./dist/analysis/index.d.ts",
31
+ "default": "./dist/analysis/index.js"
32
+ },
33
+ "./diff": {
34
+ "types": "./dist/diff.d.ts",
35
+ "default": "./dist/diff.js"
36
+ },
37
+ "./vocabulary": {
38
+ "types": "./dist/vocabulary.d.ts",
39
+ "default": "./dist/vocabulary.js"
40
+ },
13
41
  "./validate": {
14
42
  "types": "./dist/validate/index.d.ts",
15
43
  "default": "./dist/validate/index.js"
16
44
  },
45
+ "./validate/builtin": {
46
+ "types": "./dist/validate/builtin/index.d.ts",
47
+ "default": "./dist/validate/builtin/index.js"
48
+ },
17
49
  "./draw": {
18
50
  "types": "./dist/draw/index.d.ts",
19
51
  "default": "./dist/draw/index.js"
20
52
  },
21
- "./examples/*": "./examples/*",
22
- "./syntax": "./editors/vscode/syntaxes/koyu.tmLanguage.json",
23
- "./package.json": "./package.json",
24
53
  "./node": {
25
54
  "types": "./dist/parse-file.d.ts",
26
55
  "default": "./dist/parse-file.js"
27
- }
56
+ },
57
+ "./examples/*": "./examples/*",
58
+ "./syntax": "./editors/vscode/syntaxes/koyu.tmLanguage.json",
59
+ "./package.json": "./package.json"
28
60
  },
29
61
  "bin": {
30
62
  "koyu": "dist/cli.js",
@@ -0,0 +1,234 @@
1
+ import type { Diagnostic } from "../core/diagnose.js";
2
+ import type { Model } from "../core/model.js";
3
+ import type { JsonObject, JsonValue } from "./json.js";
4
+
5
+ export const COMPONENT_ID_PATTERN = /^[a-z][a-z0-9-]*(?:\.[a-z0-9-]+)+$/;
6
+
7
+ export interface ComponentIdentity {
8
+ readonly id: string;
9
+ readonly revision: string;
10
+ }
11
+
12
+ export function isComponentIdentity(value: unknown): value is ComponentIdentity {
13
+ if (typeof value !== "object" || value === null) return false;
14
+ try {
15
+ const id = Object.getOwnPropertyDescriptor(value, "id");
16
+ const revision = Object.getOwnPropertyDescriptor(value, "revision");
17
+ return !!id
18
+ && "value" in id
19
+ && id.enumerable === true
20
+ && typeof id.value === "string"
21
+ && COMPONENT_ID_PATTERN.test(id.value)
22
+ && !!revision
23
+ && "value" in revision
24
+ && revision.enumerable === true
25
+ && typeof revision.value === "string"
26
+ && revision.value.trim() !== "";
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ export function sameIdentity(a: ComponentIdentity, b: ComponentIdentity): boolean {
33
+ return a.id === b.id && a.revision === b.revision;
34
+ }
35
+
36
+ export interface JurisdictionRef {
37
+ readonly country: string;
38
+ readonly region?: string;
39
+ readonly locality?: string;
40
+ readonly authority?: string;
41
+ }
42
+
43
+ export interface EffectiveRange {
44
+ readonly from: string;
45
+ readonly to?: string;
46
+ }
47
+
48
+ export type SubjectRef =
49
+ | { readonly kind: "model"; readonly ref: "/" }
50
+ | { readonly kind: "level" | "space" | "zone" | "boundary" | "opening" | "run" | "site"; readonly ref: string }
51
+ | { readonly kind: `${string}.${string}`; readonly ref: string };
52
+
53
+ export interface SourceLocation {
54
+ readonly file?: string;
55
+ readonly line?: number;
56
+ }
57
+
58
+ export interface ContextSource {
59
+ readonly kind: "authority" | "survey" | "brief" | "user" | "import" | "other";
60
+ readonly ref: string;
61
+ readonly observedAt?: string;
62
+ readonly retrievedAt?: string;
63
+ }
64
+
65
+ export interface AuthorityCitation {
66
+ readonly jurisdiction: JurisdictionRef;
67
+ readonly instrument: string;
68
+ readonly provision?: string;
69
+ readonly uri?: string;
70
+ readonly effective?: EffectiveRange;
71
+ }
72
+
73
+ export type SourceRef =
74
+ | { readonly kind: "model"; readonly subject: SubjectRef; readonly location?: SourceLocation }
75
+ | { readonly kind: "context"; readonly key: string; readonly source: ContextSource }
76
+ | { readonly kind: "authority"; readonly citation: AuthorityCitation }
77
+ | { readonly kind: `${string}.${string}`; readonly data: JsonObject };
78
+
79
+ export interface Quantity {
80
+ readonly value: number;
81
+ readonly unit: string;
82
+ }
83
+
84
+ interface EvidenceBase {
85
+ readonly id: string;
86
+ readonly subjects: readonly [SubjectRef, ...SubjectRef[]];
87
+ readonly sources: readonly [SourceRef, ...SourceRef[]];
88
+ readonly producedBy: ComponentIdentity;
89
+ }
90
+
91
+ export type Evidence =
92
+ | (EvidenceBase & { readonly kind: "fact"; readonly name: string; readonly value: JsonValue | Quantity })
93
+ | (EvidenceBase & {
94
+ readonly kind: "comparison";
95
+ readonly observed: Quantity;
96
+ readonly operator: "<" | "<=" | "=" | ">=" | ">" | "inside" | "outside";
97
+ readonly required: Quantity | { readonly minimum?: Quantity; readonly maximum?: Quantity };
98
+ })
99
+ | (EvidenceBase & {
100
+ readonly kind: "route";
101
+ readonly reachable: boolean;
102
+ readonly profile: string;
103
+ readonly path: readonly string[];
104
+ readonly cost?: Quantity;
105
+ })
106
+ | (EvidenceBase & { readonly kind: "geometry"; readonly geometry: JsonObject })
107
+ | (EvidenceBase & {
108
+ readonly kind: "missing";
109
+ readonly missing: readonly [MissingInput, ...MissingInput[]];
110
+ })
111
+ | (EvidenceBase & { readonly kind: `${string}.${string}`; readonly data: JsonObject });
112
+
113
+ export interface ContextEntry {
114
+ readonly value: JsonValue;
115
+ readonly source: ContextSource;
116
+ }
117
+
118
+ export interface ContextSnapshot {
119
+ readonly schema: "koyu-context/1";
120
+ readonly asOf: string;
121
+ readonly jurisdiction?: JurisdictionRef;
122
+ readonly values: Readonly<Record<string, ContextEntry>>;
123
+ }
124
+
125
+ export type ContextDecode<T extends JsonValue> =
126
+ | { readonly ok: true; readonly value: T }
127
+ | { readonly ok: false; readonly message: string };
128
+
129
+ export interface ContextKey<T extends JsonValue> extends ComponentIdentity {
130
+ readonly description: string;
131
+ readonly decode: (value: JsonValue) => ContextDecode<T>;
132
+ }
133
+
134
+ export interface ContextRequirement<T extends JsonValue = JsonValue> {
135
+ readonly key: ContextKey<T>;
136
+ readonly presence: "required" | "optional";
137
+ }
138
+
139
+ export type ContextRead<T extends JsonValue> =
140
+ | { readonly state: "present"; readonly value: T; readonly entry: ContextEntry }
141
+ | { readonly state: "missing" }
142
+ | { readonly state: "invalid"; readonly entry: ContextEntry; readonly message: string };
143
+
144
+ export interface ContextReader {
145
+ get<T extends JsonValue>(key: ContextKey<T>): ContextRead<T>;
146
+ }
147
+
148
+ export type MissingInput =
149
+ | { readonly kind: "context"; readonly key: string; readonly reason: "missing" | "invalid"; readonly message?: string }
150
+ | { readonly kind: "model"; readonly subjects: readonly SubjectRef[]; readonly reason: string }
151
+ | { readonly kind: "analysis"; readonly analysis: ComponentIdentity; readonly reason: "partial" | "unavailable" }
152
+ | { readonly kind: `${string}.${string}`; readonly data: JsonObject };
153
+
154
+ export interface ExecutionIssue {
155
+ readonly kind:
156
+ | "model-inconsistent"
157
+ | "dependency-unavailable"
158
+ | "missing-context"
159
+ | "invalid-context"
160
+ | "execution-error"
161
+ | `${string}.${string}`;
162
+ readonly message: string;
163
+ readonly subjects?: readonly SubjectRef[];
164
+ readonly missing?: readonly MissingInput[];
165
+ }
166
+
167
+ export type AnalysisArtifact<T extends JsonValue> =
168
+ | {
169
+ readonly state: "complete";
170
+ readonly value: T;
171
+ readonly evidence: readonly Evidence[];
172
+ }
173
+ | {
174
+ readonly state: "partial";
175
+ readonly value: T;
176
+ readonly missing: readonly [MissingInput, ...MissingInput[]];
177
+ readonly evidence: readonly Evidence[];
178
+ }
179
+ | {
180
+ readonly state: "unavailable";
181
+ readonly missing: readonly [MissingInput, ...MissingInput[]];
182
+ readonly issues: readonly [ExecutionIssue, ...ExecutionIssue[]];
183
+ };
184
+
185
+ export interface AnalysisRef<T extends JsonValue = JsonValue> extends ComponentIdentity {
186
+ readonly __output?: T;
187
+ }
188
+
189
+ export interface AnalysisRequirement<T extends JsonValue = JsonValue> {
190
+ readonly analysis: AnalysisRef<T>;
191
+ readonly accept: "complete" | "partial";
192
+ }
193
+
194
+ export type DeepReadonly<T> =
195
+ T extends (...args: never[]) => unknown ? T
196
+ : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
197
+ : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>>
198
+ : T extends readonly (infer U)[] ? readonly DeepReadonly<U>[]
199
+ : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> }
200
+ : T;
201
+
202
+ export interface AnalysisRunContext {
203
+ readonly model: DeepReadonly<Model>;
204
+ readonly context: ContextReader;
205
+ get<T extends JsonValue>(analysis: AnalysisRef<T>): AnalysisArtifact<T>;
206
+ }
207
+
208
+ export interface AnalysisDefinition<T extends JsonValue = JsonValue> extends AnalysisRef<T> {
209
+ readonly title: string;
210
+ readonly model: "consistent" | "any";
211
+ readonly dependencies: readonly AnalysisRequirement[];
212
+ readonly context: readonly ContextRequirement[];
213
+ readonly run: (context: AnalysisRunContext) => AnalysisArtifact<T>;
214
+ }
215
+
216
+ export interface AnalysisResult<T extends JsonValue = JsonValue> {
217
+ readonly analysis: ComponentIdentity;
218
+ readonly artifact: AnalysisArtifact<T>;
219
+ }
220
+
221
+ export const ANALYSIS_FORMAT = "koyu-analysis/1" as const;
222
+
223
+ export interface AnalysisReport<T extends JsonValue = JsonValue> {
224
+ readonly schema: typeof ANALYSIS_FORMAT;
225
+ readonly profile: ComponentIdentity;
226
+ readonly model: {
227
+ readonly languageVersion: string;
228
+ readonly name?: string;
229
+ readonly state: "consistent" | "inconsistent";
230
+ readonly diagnostics: readonly Diagnostic[];
231
+ };
232
+ readonly context: ContextSnapshot;
233
+ readonly result: AnalysisResult<T>;
234
+ }
@@ -0,0 +1,61 @@
1
+ // koyu — the analysis surface (`@kensnzk/koyu/analysis`)
2
+ //
3
+ // **Analysis makes the material for a judgement; it never holds the authority to judge.**
4
+ // An artifact carries measurements, evidence you can walk back to the model, the identity of
5
+ // the profile and inputs it came from, and whatever input was missing. It carries no `pass`,
6
+ // no `fail`, no level and no verdict — drawing the line is what `@kensnzk/koyu/validate` does.
7
+ //
8
+ // Every run names its context and its versioned profile explicitly. There is no implicit
9
+ // jurisdiction, no process-wide default profile, and no overload that lets a required input
10
+ // be omitted. Two runs that differ do so because the arguments differed, and the difference
11
+ // is visible in the result's provenance rather than hidden in process state.
12
+
13
+ export {
14
+ COMPONENT_ID_PATTERN,
15
+ isComponentIdentity,
16
+ sameIdentity,
17
+ ANALYSIS_FORMAT,
18
+ type AnalysisArtifact,
19
+ type AnalysisDefinition,
20
+ type AnalysisRef,
21
+ type AnalysisReport,
22
+ type AnalysisRequirement,
23
+ type AnalysisResult,
24
+ type AnalysisRunContext,
25
+ type AuthorityCitation,
26
+ type ComponentIdentity,
27
+ type ContextDecode,
28
+ type ContextEntry,
29
+ type ContextKey,
30
+ type ContextRead,
31
+ type ContextReader,
32
+ type ContextRequirement,
33
+ type ContextSnapshot,
34
+ type ContextSource,
35
+ type DeepReadonly,
36
+ type EffectiveRange,
37
+ type Evidence,
38
+ type ExecutionIssue,
39
+ type JurisdictionRef,
40
+ type MissingInput,
41
+ type Quantity,
42
+ type SourceLocation,
43
+ type SourceRef,
44
+ type SubjectRef,
45
+ } from "./contracts.js";
46
+
47
+ export {
48
+ assertJsonValue,
49
+ canonicalJsonValue,
50
+ codePointCompare,
51
+ isJsonValue,
52
+ JsonBoundaryError,
53
+ type JsonObject,
54
+ type JsonPrimitive,
55
+ type JsonValue,
56
+ } from "./json.js";
57
+
58
+ // Running one analysis, without running any rule. The registry and profile are the caller's
59
+ // values; see `@kensnzk/koyu/validate` for how they are built.
60
+ export { runAnalysis } from "../validate/assessment.js";
61
+ export type { RunAnalysisOptions } from "../validate/contracts.js";
@@ -0,0 +1,117 @@
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+
3
+ export type JsonValue =
4
+ | JsonPrimitive
5
+ | readonly JsonValue[]
6
+ | { readonly [key: string]: JsonValue };
7
+
8
+ export type JsonObject = { readonly [key: string]: JsonValue };
9
+
10
+ export class JsonBoundaryError extends TypeError {
11
+ readonly path: string;
12
+
13
+ constructor(path: string, message: string) {
14
+ super(`${path}: ${message}`);
15
+ this.name = "JsonBoundaryError";
16
+ this.path = path;
17
+ }
18
+ }
19
+
20
+ /** True only for finite JSON primitives, arrays, and plain string-keyed objects without cycles. */
21
+ export function isJsonValue(value: unknown): value is JsonValue {
22
+ try {
23
+ assertJsonValue(value);
24
+ return true;
25
+ } catch {
26
+ return false;
27
+ }
28
+ }
29
+
30
+ export function assertJsonValue(value: unknown, path = "$", ancestors = new Set<object>()): asserts value is JsonValue {
31
+ if (value === null || typeof value === "string" || typeof value === "boolean") return;
32
+ if (typeof value === "number") {
33
+ if (!Number.isFinite(value)) throw new JsonBoundaryError(path, "number must be finite");
34
+ return;
35
+ }
36
+ if (typeof value !== "object") {
37
+ throw new JsonBoundaryError(path, `${typeof value} is not a JSON value`);
38
+ }
39
+ if (ancestors.has(value)) throw new JsonBoundaryError(path, "cyclic value is not JSON");
40
+
41
+ const prototype = Object.getPrototypeOf(value) as object | null;
42
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {
43
+ throw new JsonBoundaryError(path, "object must have Object.prototype or a null prototype");
44
+ }
45
+
46
+ ancestors.add(value);
47
+ try {
48
+ if (Array.isArray(value)) {
49
+ for (const key of Reflect.ownKeys(value)) {
50
+ if (key === "length") continue;
51
+ if (typeof key !== "string" || !/^(0|[1-9]\d*)$/.test(key) || Number(key) >= value.length) {
52
+ throw new JsonBoundaryError(path, "array has a non-index own property");
53
+ }
54
+ const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
55
+ if (!("value" in descriptor) || !descriptor.enumerable) {
56
+ throw new JsonBoundaryError(`${path}[${key}]`, "array entries must be enumerable data properties");
57
+ }
58
+ }
59
+ for (let index = 0; index < value.length; index++) {
60
+ if (!Object.hasOwn(value, index)) throw new JsonBoundaryError(`${path}[${index}]`, "sparse arrays are not JSON values");
61
+ assertJsonValue(value[index], `${path}[${index}]`, ancestors);
62
+ }
63
+ return;
64
+ }
65
+ for (const key of Reflect.ownKeys(value)) {
66
+ if (typeof key !== "string") throw new JsonBoundaryError(path, "symbol keys are not JSON object keys");
67
+ const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
68
+ if (!("value" in descriptor) || !descriptor.enumerable) {
69
+ throw new JsonBoundaryError(`${path}.${key}`, "object members must be enumerable data properties");
70
+ }
71
+ assertJsonValue(descriptor.value, `${path}.${key}`, ancestors);
72
+ }
73
+ } finally {
74
+ ancestors.delete(value);
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Clones a JSON boundary value deterministically. Non-index keys use Unicode code-point order;
80
+ * ECMAScript integer-index keys retain the language's mandatory numeric enumeration order.
81
+ */
82
+ export function canonicalJsonValue(value: unknown): JsonValue {
83
+ assertJsonValue(value);
84
+ return canonical(value);
85
+ }
86
+
87
+ function canonical(value: JsonValue): JsonValue {
88
+ if (value === null || typeof value !== "object") {
89
+ return typeof value === "number" && Object.is(value, -0) ? 0 : value;
90
+ }
91
+ if (Array.isArray(value)) return value.map(canonical);
92
+
93
+ const record = value as { readonly [key: string]: JsonValue };
94
+ const out: Record<string, JsonValue> = {};
95
+ for (const key of Object.keys(record).sort(codePointCompare)) {
96
+ Object.defineProperty(out, key, {
97
+ value: canonical(record[key]!),
98
+ enumerable: true,
99
+ configurable: true,
100
+ writable: true,
101
+ });
102
+ }
103
+ return out;
104
+ }
105
+
106
+ export function codePointCompare(a: string, b: string): number {
107
+ const left = a[Symbol.iterator]();
108
+ const right = b[Symbol.iterator]();
109
+ while (true) {
110
+ const x = left.next();
111
+ const y = right.next();
112
+ if (x.done || y.done) return x.done === y.done ? 0 : x.done ? -1 : 1;
113
+ const xPoint = x.value.codePointAt(0)!;
114
+ const yPoint = y.value.codePointAt(0)!;
115
+ if (xPoint !== yPoint) return xPoint < yPoint ? -1 : 1;
116
+ }
117
+ }