@kensnzk/koyu 0.19.0 → 0.21.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 (92) hide show
  1. package/README.ja.md +7 -5
  2. package/README.md +8 -6
  3. package/dist/analysis/contracts.d.ts +11 -1
  4. package/dist/analysis/contracts.d.ts.map +1 -1
  5. package/dist/analysis/contracts.js +11 -1
  6. package/dist/analysis/contracts.js.map +1 -1
  7. package/dist/cli.js +48 -9
  8. package/dist/cli.js.map +1 -1
  9. package/dist/core/diagnose.d.ts +2 -0
  10. package/dist/core/diagnose.d.ts.map +1 -1
  11. package/dist/core/diagnose.js +20 -1
  12. package/dist/core/diagnose.js.map +1 -1
  13. package/dist/core/diff.d.ts.map +1 -1
  14. package/dist/core/diff.js +4 -1
  15. package/dist/core/diff.js.map +1 -1
  16. package/dist/core/model.d.ts +171 -8
  17. package/dist/core/model.d.ts.map +1 -1
  18. package/dist/core/model.js +219 -15
  19. package/dist/core/model.js.map +1 -1
  20. package/dist/core/parse.d.ts.map +1 -1
  21. package/dist/core/parse.js +42 -11
  22. package/dist/core/parse.js.map +1 -1
  23. package/dist/core/vocabulary.d.ts +16 -0
  24. package/dist/core/vocabulary.d.ts.map +1 -1
  25. package/dist/core/vocabulary.js +11 -2
  26. package/dist/core/vocabulary.js.map +1 -1
  27. package/dist/form.d.ts +1 -0
  28. package/dist/form.d.ts.map +1 -1
  29. package/dist/form.js +5 -0
  30. package/dist/form.js.map +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/mcp.js +49 -12
  36. package/dist/mcp.js.map +1 -1
  37. package/dist/model.d.ts +1 -1
  38. package/dist/model.d.ts.map +1 -1
  39. package/dist/model.js +1 -1
  40. package/dist/model.js.map +1 -1
  41. package/dist/validate/builtin/access.js +30 -6
  42. package/dist/validate/builtin/access.js.map +1 -1
  43. package/dist/validate/contracts.d.ts +6 -1
  44. package/dist/validate/contracts.d.ts.map +1 -1
  45. package/dist/validate/contracts.js +6 -1
  46. package/dist/validate/contracts.js.map +1 -1
  47. package/editors/vscode/package.json +1 -1
  48. package/editors/vscode/syntaxes/koyu.tmLanguage.json +55 -55
  49. package/examples/basement/main.muro +9 -9
  50. package/examples/complex/L1.muro +22 -22
  51. package/examples/complex/basement.muro +4 -4
  52. package/examples/complex/core.muro +9 -9
  53. package/examples/complex/hotel.muro +14 -14
  54. package/examples/complex/main.muro +1 -1
  55. package/examples/complex/office.muro +3 -3
  56. package/examples/complex/plant.muro +4 -4
  57. package/examples/complex/podium.muro +23 -23
  58. package/examples/house/main.muro +2 -2
  59. package/examples/house.muro +2 -2
  60. package/examples/mansion.muro +27 -27
  61. package/examples/office.muro +16 -16
  62. package/examples/steps/06-finished.muro +1 -1
  63. package/examples/tower/L1.muro +12 -12
  64. package/examples/tower/L11.muro +4 -4
  65. package/examples/tower/L2.muro +10 -10
  66. package/examples/tower/main.muro +1 -1
  67. package/examples/tower/typical.muro +10 -10
  68. package/examples/twin/L1.muro +29 -29
  69. package/examples/twin/L5.muro +14 -14
  70. package/examples/twin/basement.muro +9 -9
  71. package/examples/twin/core.muro +49 -49
  72. package/examples/twin/hotel.muro +15 -15
  73. package/examples/twin/main.muro +1 -1
  74. package/examples/twin/office.muro +10 -10
  75. package/examples/twin/podium.muro +73 -73
  76. package/examples/twin/residence.muro +10 -10
  77. package/examples/two-rooms.canonical.json +2 -2
  78. package/examples/two-rooms.muro +1 -1
  79. package/package.json +17 -2
  80. package/src/analysis/contracts.ts +11 -1
  81. package/src/cli.ts +50 -10
  82. package/src/core/diagnose.ts +24 -1
  83. package/src/core/diff.ts +4 -1
  84. package/src/core/model.ts +231 -15
  85. package/src/core/parse.ts +57 -9
  86. package/src/core/vocabulary.ts +30 -2
  87. package/src/form.ts +13 -0
  88. package/src/index.ts +5 -0
  89. package/src/mcp.ts +56 -12
  90. package/src/model.ts +7 -1
  91. package/src/validate/builtin/access.ts +32 -6
  92. package/src/validate/contracts.ts +6 -1
package/src/core/model.ts CHANGED
@@ -8,11 +8,189 @@ export type AttrValue = string | number;
8
8
  export type Attrs = Record<string, AttrValue>;
9
9
 
10
10
  /**
11
- * このツールが受理する言語版 (ADR-0017)。旧版は意味保存の場合のみ受理される (checkが検査する)。
12
- * **この並びが版の新旧の順である** — 版の比較はここの添字で行う (辞書順では 0.5 が 1.0 より後になる)
11
+ * The correspondence between the two version lines, and the only place it is recorded.
12
+ *
13
+ * muro is the language; koyu is the implementation that reads it. They are counted
14
+ * separately because they promise different things, and until this ledger existed nothing
15
+ * said which koyu implemented which muro — the published norm asserted the declaration in
16
+ * prose while no such declaration existed on any surface.
17
+ *
18
+ * - `muro` the language version, as written in a `.muro` file
19
+ * - `since` the koyu version that first read it. **A version that shipped** — `1.0.0-rc.1`
20
+ * carried muro 1.0 in the tree but never reached npm, so muro 1.0 arrived for
21
+ * anyone outside this repository at 0.16.0, and that is what this records
22
+ * - `until` the last koyu version that reads it, once a version is retired. Empty on every
23
+ * row: nothing has been retired. The field exists so that retiring is filling in
24
+ * a value rather than reshaping the ledger
25
+ *
26
+ * **The order of this array is the order of the versions, oldest first.** Comparison is by
27
+ * index, never by spelling — as strings, "0.5" sorts after "1.0".
28
+ *
29
+ * Cutting a language version is adding a row here. `test/release.test.ts` holds that: a
30
+ * release that moves the newest version must carry a row whose `since` is its own version.
31
+ */
32
+ export const MURO_SUPPORT: readonly { muro: string; since: string; until: string | null }[] = [
33
+ // The `koyu` keyword was read from the first commit, accepting whatever followed it.
34
+ { muro: "0.1", since: "0.0.1", until: null },
35
+ // 0.9.0 introduced the accepted-version list, and with it the first rejection.
36
+ { muro: "0.2", since: "0.9.0", until: null },
37
+ { muro: "0.3", since: "0.11.0", until: null },
38
+ { muro: "0.4", since: "0.11.0", until: null },
39
+ { muro: "0.5", since: "0.11.0", until: null },
40
+ // Not 1.0.0-rc.1. That version set muro 1.0 in the tree and was never published; the
41
+ // implementation version was returned to the 0.x line and shipped as 0.16.0 instead.
42
+ { muro: "1.0", since: "0.16.0", until: null },
43
+ { muro: "1.1", since: "0.17.0", until: null },
44
+ // The version line stops answering to the implementation's name: `muro 1.2`, not `koyu 1.2`.
45
+ { muro: "1.2", since: "0.20.0", until: null },
46
+ // 1.3 adds no notation. It retires `use`, whose job was never a use — it held one grouping per
47
+ // space, so tenancy, fire compartment and department all competed for it. VER07 stops it here;
48
+ // the ledger row stays so that every version up to 1.2 goes on reading it (ADR-0061).
49
+ { muro: "1.3", since: "0.21.0", until: null },
50
+ ];
51
+
52
+ /** The word a version line is written with from 1.2 on. */
53
+ export const MURO_KEYWORD = "muro";
54
+
55
+ /**
56
+ * The last version whose line is spelled `koyu`.
57
+ *
58
+ * **One spelling per version, never both.** Up to and including this version a file declares
59
+ * itself `koyu <v>`, and from the next one it declares itself `muro <v>`. Accepting both for
60
+ * the same version would give one declaration two spellings, and the canonical form's
61
+ * uniqueness — which the whole conformance suite rests on — would go with it.
62
+ *
63
+ * Files written before 1.2 keep the old spelling and keep meaning exactly what they meant.
64
+ * Nothing migrates, and nothing has to.
65
+ */
66
+ export const LAST_KOYU_SPELLED_VERSION = "1.1";
67
+
68
+ /**
69
+ * This implementation's own version — the one npm installs, held in step with `package.json`
70
+ * by `test/release.test.ts`.
71
+ *
72
+ * It sits beside `MURO_SUPPORT` because the two are one fact read from two directions: the
73
+ * `since` column is written in this vocabulary, and every surface that answers "which muro
74
+ * does this build speak" needs both halves at once.
75
+ */
76
+ export const KOYU_VERSION = "0.21.0";
77
+
78
+ /**
79
+ * Whether `a` names a later language version than `b`.
80
+ *
81
+ * **Not by index in the ledger** — the whole point is to answer for a version the ledger has
82
+ * never heard of, which is what a file from the future carries. Compared as numbers, because
83
+ * as strings `"0.5" > "1.0"`. A spelling that is not `major.minor` is not a version at all
84
+ * and is never "newer": it is unreadable, which is a different answer.
85
+ */
86
+ export function isNewerVersion(a: string, b: string): boolean {
87
+ const shape = /^(\d+)\.(\d+)$/;
88
+ const pa = shape.exec(a);
89
+ const pb = shape.exec(b);
90
+ if (!pa || !pb) return false;
91
+ const major = Number(pa[1]) - Number(pb[1]);
92
+ return major !== 0 ? major > 0 : Number(pa[2]) > Number(pb[2]);
93
+ }
94
+
95
+ /**
96
+ * What this build reads, what the newest version is, and how an undeclared file is read.
97
+ *
98
+ * The last two are separate facts and only coincide today. Once a newer version exists they
99
+ * differ permanently, and the line has to say both or it is telling half the truth to the
100
+ * person most likely to be surprised by it.
101
+ */
102
+ export function versionLine(): string {
103
+ const read = SUPPORTED_LANGUAGE_VERSIONS;
104
+ const range = `${read[0]}–${read[read.length - 1]}`;
105
+ return `koyu ${KOYU_VERSION} — reads muro ${range} (newest ${NEWEST_LANGUAGE_VERSION}; a file with no version line is read as ${DEFAULT_LANGUAGE_VERSION})`;
106
+ }
107
+
108
+ /**
109
+ * The koyu version that first read this muro version, or `undefined` if no such version is
110
+ * accepted. This is the direction a downstream needs: it depends on a language version and
111
+ * has to turn that into a package range.
112
+ */
113
+ export function koyuSince(muro: string): string | undefined {
114
+ return MURO_SUPPORT.find((r) => r.muro === muro)?.since;
115
+ }
116
+
117
+ /**
118
+ * Whether this build reads the given muro version.
119
+ *
120
+ * **What a downstream actually depends on is a language version, not a package range.** An
121
+ * application that writes `muro 1.1` needs a koyu that reads 1.1; which koyu that is, is the
122
+ * ledger's business, not the application's. Asserting this at startup turns a version skew
123
+ * into one sentence instead of a parse error somewhere later.
124
+ */
125
+ export function speaksMuro(muro: string): boolean {
126
+ return SUPPORTED_LANGUAGE_VERSIONS.includes(muro);
127
+ }
128
+
129
+ /**
130
+ * Throw unless this build reads the given muro version, naming what would fix it.
131
+ *
132
+ * Separate from `speaksMuro` because the useful thing at a startup check is the message: the
133
+ * caller knows the version it needs and nothing else, and the ledger is the only place that
134
+ * can say which koyu to install for it.
135
+ */
136
+ export function requireMuro(muro: string): void {
137
+ if (speaksMuro(muro)) return;
138
+ const row = MURO_SUPPORT.find((r) => r.muro === muro);
139
+ const head = `This build of koyu (${KOYU_VERSION}) does not read muro ${muro}.`;
140
+ // A row with `until` set is retired, and the advice is the opposite of the usual one:
141
+ // a newer koyu will not help, because newer is what dropped it.
142
+ if (row?.until) {
143
+ throw new Error(
144
+ `${head} It was retired after koyu ${row.until} — migrate the file, or install koyu ${row.until} or earlier.`,
145
+ );
146
+ }
147
+ if (row) throw new Error(`${head} It arrived in koyu ${row.since} — install koyu ${row.since} or later.`);
148
+ // **No row is not evidence that no koyu reads it.** A build only carries the rows compiled
149
+ // into it, so a version released after this one looks exactly like a version that never
150
+ // existed. Saying which is which is not this build's to say; saying what it knows is.
151
+ const newer = isNewerVersion(muro, NEWEST_LANGUAGE_VERSION);
152
+ throw new Error(
153
+ newer
154
+ ? `${head} It is newer than anything this build knows (it reads up to ${NEWEST_LANGUAGE_VERSION}) — upgrade koyu.`
155
+ : `${head} This build reads ${SUPPORTED_LANGUAGE_VERSIONS.join(", ")}.`,
156
+ );
157
+ }
158
+
159
+ /**
160
+ * The language versions this build accepts (ADR-0017). An older version is accepted only
161
+ * where the meaning is preserved; `check` is what decides that.
162
+ *
163
+ * **Derived from `MURO_SUPPORT`, not declared beside it.** Two lists of one fact is how the
164
+ * correspondence drifted in the first place.
165
+ */
166
+ export const SUPPORTED_LANGUAGE_VERSIONS: readonly string[] = MURO_SUPPORT.filter(
167
+ (r) => r.until === null,
168
+ ).map((r) => r.muro);
169
+
170
+ /**
171
+ * The newest language version this build accepts — what to declare to get everything.
172
+ * Derived, for the same reason as above.
173
+ */
174
+ export const NEWEST_LANGUAGE_VERSION = SUPPORTED_LANGUAGE_VERSIONS[SUPPORTED_LANGUAGE_VERSIONS.length - 1]!;
175
+
176
+ /**
177
+ * How a file with no version line is read. **Frozen at 1.1, and it does not follow the newest
178
+ * version.**
179
+ *
180
+ * It used to be the newest, which meant an undeclared file was re-read under new semantics
181
+ * every time the tool moved — silently, because nothing reports the absence of a declaration.
182
+ * That is not hypothetical: the 1.0 → 1.1 move read `exterior` out of the type position, and
183
+ * undeclared files written in the old dialect lost their outside spaces without a word.
184
+ *
185
+ * Freezing removes the danger rather than reporting it. **Newer semantics are opt-in: you get
186
+ * them by naming them.** The cost is that an undeclared file never gets new notation, which is
187
+ * the same statement read from the other side.
188
+ *
189
+ * Freezing this was not itself a version bump: at the moment it froze, the frozen value and
190
+ * the newest version were both 1.1, so no file that existed read differently. They part
191
+ * company from 1.2 on, and that gap is the whole point — an old file that names no version
192
+ * does not quietly become a 1.2 file.
13
193
  */
14
- export const SUPPORTED_LANGUAGE_VERSIONS: readonly string[] = ["0.1", "0.2", "0.3", "0.4", "0.5", "1.0", "1.1"];
15
- /** 版宣言を省略したときの解釈 — 常に最新版の意味論 (省略はツール版を跨いで意味安定ではない) */
16
194
  export const DEFAULT_LANGUAGE_VERSION = "1.1";
17
195
 
18
196
  /**
@@ -20,9 +198,19 @@ export const DEFAULT_LANGUAGE_VERSION = "1.1";
20
198
  * 数えるのは綴りだけである。minorはキーが増えたとき、majorは既存のキーの名前・並び・照合順・
21
199
  * 正規化・数の綴りが変わったとき。**minorでも全ての文書のバイトは動く** — この文字列自体が
22
200
  * 第一キーだからで、増えたキーを持たない文書も先頭行だけは変わる (ADR-0051 が実測している)。
23
- * 意味論の版は muro が持つので、`koyu` キー (書かれた版宣言の素通し) とは別の面である
201
+ * 意味論の版は muro が持つので、`muro` キー (書かれた版宣言の素通し) とは別の面である。
202
+ *
203
+ * The format keeps the name `koyu` because it is the implementation's output spelling — the
204
+ * shape koyu writes. The key inside it names the language, and is spelled `muro` for the same
205
+ * reason the version line is.
206
+ *
207
+ * **That rename is why this is 2.0 and not 1.3.** An existing key changed its name, which the
208
+ * rule above puts squarely in major. Shipping it as a minor would have told every reader that
209
+ * `1.x` stays compatible — so a reader expecting `koyu` would have accepted the document and
210
+ * found no language version in it, which is the silent misread the format version exists to
211
+ * prevent.
24
212
  */
25
- export const CANONICAL_FORMAT = "koyu-canonical/1.2";
213
+ export const CANONICAL_FORMAT = "koyu-canonical/2.0";
26
214
 
27
215
  /** 方位。edge指定は「最初に書いた空間」の矩形から見た辺。N=+Y, S=-Y, E=+X, W=-X */
28
216
  export type Edge = "N" | "E" | "S" | "W";
@@ -461,6 +649,19 @@ export class SourceError extends Error {
461
649
  public raw: string,
462
650
  /** 出所ファイル (合成時) */
463
651
  public file?: string,
652
+ /**
653
+ * The diagnostic code this failure carries in `check --json`, when it has one of its own.
654
+ *
655
+ * Most parse failures are just syntax and are reported as `SYN01`. A few are a named
656
+ * condition a caller has to be able to act on without matching the message text — a file
657
+ * declaring a language version this build cannot read is the case that forced this: the
658
+ * answer is "upgrade koyu", and a viewer wanting to say so should not be reading English.
659
+ *
660
+ * Narrow on purpose. The diagnostic ledger lives in `diagnose.ts`, which reads this
661
+ * module, so the union cannot be imported here — and widening it to `string` would let
662
+ * a typo reach `check --json` as a code no page documents.
663
+ */
664
+ public code?: "VER06",
464
665
  ) {
465
666
  super(`${file ? `${file}:` : ""}line ${line}: ${raw}`);
466
667
  this.name = "SourceError";
@@ -649,17 +850,29 @@ export function isIndoor(model: Model, s: Space): boolean {
649
850
  return !isSemiOutdoor(model, s);
650
851
  }
651
852
 
652
- /** 実効use属性 — 自分に無ければ、最も深いゾーン祖先から継承する */
653
- export function effectiveUse(model: Model, s: Space): string | undefined {
654
- const own = s.attrs["use"];
655
- if (typeof own === "string") return own;
656
- let best: string | undefined;
853
+ /**
854
+ * The value a space carries for `key`: its own declaration, else the one on the deepest zone
855
+ * whose path is a prefix of the space's.
856
+ *
857
+ * **The caller names the key, and core forms no opinion about what it means.** That is what
858
+ * makes this legitimate for a carried namespaced key such as `lease.category`: asking is not
859
+ * reading. Core still gives the key no meaning, decides nothing by it, and would answer the
860
+ * same way for a key it has never seen.
861
+ *
862
+ * The resolution is the one `use` had before it was retired, with the literal `"use"` moved out
863
+ * to the caller. Non-string values resolve too — a space that writes `dept.name:2024` now
864
+ * answers with the number rather than falling through to its zone, which is what was written.
865
+ */
866
+ export function effectiveAttr(model: Model, s: Space, key: string): AttrValue | undefined {
867
+ const own = s.attrs[key];
868
+ if (own !== undefined) return own;
869
+ let best: AttrValue | undefined;
657
870
  let bestLen = -1;
658
871
  for (const z of model.zones.values()) {
659
872
  if (s.path.startsWith(z.path + "/") && z.path.length > bestLen) {
660
- const u = z.attrs["use"];
661
- if (typeof u === "string") {
662
- best = u;
873
+ const v = z.attrs[key];
874
+ if (v !== undefined) {
875
+ best = v;
663
876
  bestLen = z.path.length;
664
877
  }
665
878
  }
@@ -941,7 +1154,10 @@ export function toCanonical(model: Model): string {
941
1154
  // 出せば、その版を著者は書いていないのに書いたことになり、しかもツールの既定が動いた日に
942
1155
  // 同じ入力のバイトが変わる。決定性は形式の側の約束なので、ツールの既定に預けない
943
1156
  format: CANONICAL_FORMAT,
944
- ...(model.versionDeclared ? { koyu: model.version } : {}),
1157
+ // **The key names the language, so it is spelled `muro`** — whatever word the file used.
1158
+ // A document written `koyu 1.1` still says `"muro": "1.1"` here: the key is the name of
1159
+ // the thing being versioned, not a copy of how the author spelled the declaration.
1160
+ ...(model.versionDeclared ? { muro: model.version } : {}),
945
1161
  ...(model.name ? { name: model.name } : {}),
946
1162
  unit: model.unit,
947
1163
  // 測地の枠 (ADR-0057) — **単位を言った直後、グリッドを言う前。**この二つは grid が張る
package/src/core/parse.ts CHANGED
@@ -11,6 +11,11 @@ import {
11
11
  type Boundary,
12
12
  DEFAULT_LANGUAGE_VERSION,
13
13
  type Edge,
14
+ isNewerVersion,
15
+ KOYU_VERSION,
16
+ LAST_KOYU_SPELLED_VERSION,
17
+ MURO_KEYWORD,
18
+ NEWEST_LANGUAGE_VERSION,
14
19
  type Level,
15
20
  type Model,
16
21
  normalizeRegionOrder,
@@ -254,25 +259,68 @@ function ingest(
254
259
  currentSpaces = [];
255
260
  over = undefined;
256
261
  switch (head) {
257
- case "koyu": {
262
+ // **The version line is the only declaration that names the language, which is why it
263
+ // was the one that carried the wrong name.** `koyu` is the implementation; the language
264
+ // is muro. One spelling per version, never both: two ways to write the same declaration
265
+ // would end the uniqueness the canonical form rests on.
266
+ case "koyu":
267
+ case "muro": {
258
268
  const v = rest[0];
259
- if (!v) throw new SourceError(ln, `koyu takes a version: koyu ${DEFAULT_LANGUAGE_VERSION}`);
269
+ const spelling = head;
270
+ if (!v) {
271
+ throw new SourceError(ln, `${spelling} takes a version: ${MURO_KEYWORD} ${NEWEST_LANGUAGE_VERSION}`);
272
+ }
260
273
  if (rest.length > 1) {
261
- throw new SourceError(ln, `Extra tokens on the koyu version declaration: ${rest.slice(1).join(" ")}`);
274
+ throw new SourceError(ln, `Extra tokens on the ${spelling} version declaration: ${rest.slice(1).join(" ")}`);
275
+ }
276
+ // **A version nobody ever released has no keyword to enforce.** `muro 0.6` is not a
277
+ // file whose author picked the wrong word — 0.6 does not exist, and answering with
278
+ // "a 0.6 file declares itself koyu 0.6" would send them to write a second invalid
279
+ // thing. Unknown-and-not-plausibly-future is settled first, on its own terms.
280
+ const known = SUPPORTED_LANGUAGE_VERSIONS.includes(v);
281
+ const future = isNewerVersion(v, NEWEST_LANGUAGE_VERSION);
282
+ if (!known && !future) {
283
+ throw new SourceError(
284
+ ln,
285
+ `Unsupported ${spelling} version: ${v} (this tool supports ${SUPPORTED_LANGUAGE_VERSIONS.join(", ")})`,
286
+ );
287
+ }
288
+
289
+ // **The spelling belongs to the version, and that is true of every build.** Decided
290
+ // before anything about what this build supports: `koyu 9.9` is not a file from the
291
+ // future, it is a declaration no version ever accepts, and telling its author to
292
+ // upgrade would send them to fix the one thing that is not wrong.
293
+ const wants = isNewerVersion(v, LAST_KOYU_SPELLED_VERSION) ? "muro" : "koyu";
294
+ if (spelling !== wants) {
295
+ throw new SourceError(
296
+ ln,
297
+ wants === "muro"
298
+ ? `muro ${v} names itself muro: write "muro ${v}". The koyu spelling names the implementation and stops at ${LAST_KOYU_SPELLED_VERSION}`
299
+ : `The muro keyword arrives in 1.2, and a ${v} processor cannot read it — a ${v} file declares itself "koyu ${v}"`,
300
+ );
262
301
  }
263
- if (!SUPPORTED_LANGUAGE_VERSIONS.includes(v)) {
302
+
303
+ if (future) {
304
+ // **A file from the future is not a broken file.** It says the reader is behind, and
305
+ // the only useful advice is to upgrade — the opposite of the advice for a version
306
+ // that never existed. Both used to print the same sentence, so a viewer could not
307
+ // tell a stale build from a corrupt file, and one downstream rebuilt the
308
+ // distinction for itself out of the version list.
264
309
  throw new SourceError(
265
310
  ln,
266
- `Unsupported koyu version: ${v} (this tool supports ${SUPPORTED_LANGUAGE_VERSIONS.join(", ")})`,
311
+ `This file is written in muro ${v}, and this build of koyu (${KOYU_VERSION}) reads up to ${NEWEST_LANGUAGE_VERSION}. The file is not the problem — upgrade koyu`,
312
+ undefined,
313
+ "VER06",
267
314
  );
268
315
  }
316
+
269
317
  // 版はbase層 (entry) でのみ・一度だけ宣言する — 合成順による黙った上書きを禁じる (ADR-0017)。
270
318
  // gridの規律に合わせ、再宣言は同値でもエラー
271
319
  if (file !== undefined && model.layers[0] !== file) {
272
- throw new SourceError(ln, "The koyu version is declared only in the base layer (the entry)");
320
+ throw new SourceError(ln, "The version is declared only in the base layer (the entry)");
273
321
  }
274
322
  if (model.versionDeclared) {
275
- throw new SourceError(ln, `The koyu version is declared once (already ${model.version})`);
323
+ throw new SourceError(ln, `The version is declared once (already ${model.version})`);
276
324
  }
277
325
  model.version = v;
278
326
  model.versionDeclared = true;
@@ -721,7 +769,7 @@ function ingest(
721
769
  } catch (e) {
722
770
  // 合成時はどのファイルのエラーかを言葉にする
723
771
  if (e instanceof SourceError && !e.file && file) {
724
- throw new SourceError(e.line, e.raw, file);
772
+ throw new SourceError(e.line, e.raw, file, e.code);
725
773
  }
726
774
  throw e;
727
775
  }
@@ -732,7 +780,7 @@ function ingest(
732
780
  expandBand(model, band, file);
733
781
  } catch (e) {
734
782
  if (e instanceof SourceError && !e.file && file) {
735
- throw new SourceError(e.line, e.raw, file);
783
+ throw new SourceError(e.line, e.raw, file, e.code);
736
784
  }
737
785
  throw e;
738
786
  }
@@ -33,6 +33,19 @@ export interface AttrSpec {
33
33
  of?: Array<string | number>;
34
34
  /** 正の数値でなければ ATT01 */
35
35
  num?: true;
36
+ /**
37
+ * The key may be written up to and including muro `after`, and not after it.
38
+ *
39
+ * **A retired key stays in the ledger.** Taking the row out would make the key unknown at
40
+ * every version at once, because `checkAttrValues` reads `attrSpec` alone and never sees
41
+ * `model.version` — a file declaring an older version would start failing with ATT03 for a
42
+ * word that version legitimately has. The row is what keeps the old reading alive; VER07 is
43
+ * what stops the new one.
44
+ *
45
+ * `instead` names what to write from the next version, and is carried here so that no state
46
+ * exists where a key is retired with nothing offered in its place.
47
+ */
48
+ retired?: { after: string; instead: string };
36
49
  }
37
50
 
38
51
  /** 台帳を読みやすく書くための小道具 */
@@ -41,6 +54,10 @@ const one = (...of: Array<string | number>): AttrSpec => ({ tier: "interpreted",
41
54
  const free = (): AttrSpec => ({ tier: "interpreted" });
42
55
  const carry = (): AttrSpec => ({ tier: "carry" });
43
56
  const structure = (): AttrSpec => ({ tier: "structure" });
57
+ const retired = (after: string, instead: string, base: AttrSpec = free()): AttrSpec => ({
58
+ ...base,
59
+ retired: { after, instead },
60
+ });
44
61
 
45
62
  /**
46
63
  * 運搬層の名前空間の綴り — **ドット区切り** (`acme.sensor` `bems.temp` `survey.measured`)。
@@ -86,7 +103,14 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
86
103
 
87
104
  // 解釈 — core が読む
88
105
  h: num(), // 天井高 mm。高さ不変量と矩計が読む
89
- use: free(), // 集計軸。zone から継承
106
+ // Retired after muro 1.2. It was never a use: ADR-0005 introduced it to answer the ratio of
107
+ // common to exclusive area, and it held one grouping per space, so tenancy, fire compartment
108
+ // and department all competed for it. A room's purpose is the type position; any other
109
+ // division of the building is a namespaced key, of which a space may carry as many as it likes.
110
+ use: retired(
111
+ "1.2",
112
+ "a namespaced key of your own (lease.category:, fire.compartment:, dept.name:)",
113
+ ),
90
114
  road: num(), // outside:1 の幅員 mm。接道の導出
91
115
  daylight: free(), // 採光の問いの対象 (ADR-0020)。値域は DAY01 が守るので台帳では重ねない
92
116
  ceiling: one(0, 1), // 0 = 天井を張らない (ADR-0024)
@@ -114,7 +138,11 @@ export const ATTR_LEDGER: Record<string, Record<string, AttrSpec>> = {
114
138
 
115
139
  zone: {
116
140
  name: free(),
117
- use: free(), // 配下へ継承される集計軸
141
+ // Retired after muro 1.2, for the reason given on the space row above.
142
+ use: retired(
143
+ "1.2",
144
+ "a namespaced key of your own (lease.category:, fire.compartment:, dept.name:)",
145
+ ),
118
146
  site: one(0, 1), // 敷地の集約 (ADR-0009)
119
147
  area: num(), // 敷地の宣言面積 ㎡ (測量値)
120
148
  uid: free(),
package/src/form.ts CHANGED
@@ -1,5 +1,18 @@
1
1
  // Public Form surface. derive() is the only public operation that assembles shape.
2
2
 
3
+ // The constructors of matter. `Form` holds centre lines, thicknesses and z; raising matter from
4
+ // those is part of the derivation, so **there is exactly one implementation and it is this one.**
5
+ // A consumer that cannot import them has to rewrite them, and then the parts are shared while the
6
+ // rules of assembly are not — which is the door to "two shapes from one Form".
7
+ export {
8
+ band,
9
+ bandLine,
10
+ columnRect,
11
+ runPrism,
12
+ thicken,
13
+ type FormPrism,
14
+ } from "./core/derive.js";
15
+
3
16
  export {
4
17
  derive,
5
18
  DERIVATION_CONSTANTS,
package/src/index.ts CHANGED
@@ -46,8 +46,13 @@ export {
46
46
  } from "./core/diagnose.js";
47
47
 
48
48
  // ---- 機械形式と、版 ----
49
+ // `requireMuro` is the one thing a consumer *does* about versions: assert, at startup, that
50
+ // this build reads the language it writes. The ledger behind it lives on `/model` with the
51
+ // rest of the model surface — the root stays the smallest set that gets you to a decision.
49
52
  export {
50
53
  DEFAULT_LANGUAGE_VERSION,
54
+ NEWEST_LANGUAGE_VERSION,
55
+ requireMuro,
51
56
  SourceError,
52
57
  SUPPORTED_LANGUAGE_VERSIONS,
53
58
  toCanonical,
package/src/mcp.ts CHANGED
@@ -9,7 +9,13 @@
9
9
  import { mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs";
10
10
  import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
11
11
  import { daylightInputs } from "./core/light.js";
12
- import { polygonAreaM2 } from "./core/model.js";
12
+ import {
13
+ DEFAULT_LANGUAGE_VERSION,
14
+ KOYU_VERSION,
15
+ NEWEST_LANGUAGE_VERSION,
16
+ polygonAreaM2,
17
+ SUPPORTED_LANGUAGE_VERSIONS,
18
+ } from "./core/model.js";
13
19
  import { check } from "./core/diagnose.js";
14
20
  import { siteReport } from "./core/site.js";
15
21
  import { assess } from "./validate/assessment.js";
@@ -21,7 +27,7 @@ import {
21
27
  areaM2,
22
28
  isIndoor,
23
29
  displayName,
24
- effectiveUse,
30
+ effectiveAttr,
25
31
  isOutside,
26
32
  isSemiOutdoor,
27
33
  isVoid,
@@ -74,7 +80,7 @@ function assertInside(entryDir: string, targetDir: string): void {
74
80
  }
75
81
  }
76
82
 
77
- function summarize(model: Model, file: string): unknown {
83
+ function summarize(model: Model, file: string, by: readonly string[] = []): unknown {
78
84
  const rooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level);
79
85
  const indoor = rooms.filter((s) => isIndoor(model, s));
80
86
  const semi = rooms.filter((s) => !isVoid(s) && isSemiOutdoor(model, s));
@@ -87,10 +93,17 @@ function summarize(model: Model, file: string): unknown {
87
93
  subtotalM2: Math.round(rs.reduce((a, s) => a + (areaM2(s) ?? 0), 0) * 100) / 100,
88
94
  };
89
95
  }
90
- const byUse: Record<string, number> = {};
91
- for (const s of indoor) {
92
- const u = effectiveUse(model, s) ?? "(unspecified)";
93
- byUse[u] = Math.round(((byUse[u] ?? 0) + (areaM2(s) ?? 0)) * 100) / 100;
96
+ // One grouping per key the caller asked for, and none at all when it asked for none.
97
+ // A default key would put back the single privileged grouping that `use` was.
98
+ const byM2: Record<string, Record<string, number>> = {};
99
+ for (const key of by) {
100
+ const bucket: Record<string, number> = {};
101
+ for (const s of indoor) {
102
+ const v = effectiveAttr(model, s, key);
103
+ const label = v === undefined ? "(unspecified)" : String(v);
104
+ bucket[label] = Math.round(((bucket[label] ?? 0) + (areaM2(s) ?? 0)) * 100) / 100;
105
+ }
106
+ byM2[key] = bucket;
94
107
  }
95
108
  const r = check(model);
96
109
  return {
@@ -139,7 +152,7 @@ function summarize(model: Model, file: string): unknown {
139
152
  totalFloorM2: Math.round(indoor.reduce((a, s) => a + (areaM2(s) ?? 0), 0) * 100) / 100,
140
153
  semiOutdoorM2: Math.round(semi.reduce((a, s) => a + (areaM2(s) ?? 0), 0) * 100) / 100,
141
154
  floorsM2: byLevel,
142
- byUseM2: byUse,
155
+ ...(by.length > 0 ? { byM2 } : {}),
143
156
  check: { errors: r.errors.length, warnings: r.warnings.length },
144
157
  hint: "Read layer contents with layers, check with check, and edit with write_layer (check is the gatekeeper). Architectural verdicts come from validate.",
145
158
  };
@@ -178,14 +191,35 @@ const str = (v: unknown, name: string): string => {
178
191
  return v;
179
192
  };
180
193
 
194
+ /** An optional array of attribute keys. Absent is not the same as empty, but both group nothing. */
195
+ const keys = (v: unknown, name: string): string[] => {
196
+ if (v === undefined) return [];
197
+ if (!Array.isArray(v) || v.some((k) => typeof k !== "string" || !k)) {
198
+ throw new Error(`${name} (an array of attribute keys) must hold non-empty strings`);
199
+ }
200
+ return v as string[];
201
+ };
202
+
181
203
  const TOOLS: Record<string, Tool> = {
182
204
  model_summary: {
183
205
  description:
184
- "Summary of the building: name, levels, layer composition, zones, door/window assets, areas, and check counts. Call this first",
185
- schema: { type: "object", properties: FILE_PROP, required: ["file"] },
206
+ "Summary of the building: name, levels, layer composition, zones, door/window assets, areas, and check counts. Call this first. Pass by:[\"lease.category\"] to also get floor area grouped by those attribute keys",
207
+ schema: {
208
+ type: "object",
209
+ properties: {
210
+ ...FILE_PROP,
211
+ by: {
212
+ type: "array",
213
+ items: { type: "string" },
214
+ description:
215
+ "Attribute keys to group indoor floor area by, e.g. [\"lease.category\"]. A space's own declaration wins, otherwise the deepest zone above it supplies the value; a space with no value falls into \"(unspecified)\". Omit for no grouping — there is no default key",
216
+ },
217
+ },
218
+ required: ["file"],
219
+ },
186
220
  run: (a) => {
187
221
  const file = str(a.file, "file");
188
- return summarize(load(file), file);
222
+ return summarize(load(file), file, keys(a.by, "by"));
189
223
  },
190
224
  },
191
225
  check: {
@@ -430,7 +464,17 @@ function handle(msg: Json): void {
430
464
  result(id, {
431
465
  protocolVersion: (params.protocolVersion as string) ?? "2025-06-18",
432
466
  capabilities: { tools: {} },
433
- serverInfo: { name: "koyu", version: "0.19.0" },
467
+ serverInfo: {
468
+ name: "koyu",
469
+ version: KOYU_VERSION,
470
+ // Which muro this build speaks. An agent choosing how to spell a version line
471
+ // has nothing else to read it from.
472
+ muro: {
473
+ reads: SUPPORTED_LANGUAGE_VERSIONS,
474
+ newest: NEWEST_LANGUAGE_VERSION,
475
+ undeclared: DEFAULT_LANGUAGE_VERSION,
476
+ },
477
+ },
434
478
  instructions:
435
479
  "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.",
436
480
  });
package/src/model.ts CHANGED
@@ -30,16 +30,22 @@ export {
30
30
  areaM2,
31
31
  DEFAULT_LANGUAGE_VERSION,
32
32
  displayName,
33
- effectiveUse,
33
+ effectiveAttr,
34
34
  heff,
35
35
  isCoveredAbove,
36
36
  isIndoor,
37
37
  isOutside,
38
38
  isSemiOutdoor,
39
39
  isVoid,
40
+ KOYU_VERSION,
41
+ koyuSince,
40
42
  levelsSorted,
43
+ MURO_SUPPORT,
44
+ NEWEST_LANGUAGE_VERSION,
41
45
  newUids,
46
+ speaksMuro,
42
47
  SUPPORTED_LANGUAGE_VERSIONS,
43
48
  toCanonical,
49
+ versionLine,
44
50
  zoneAreaM2,
45
51
  } from "./core/model.js";