@kensnzk/koyu 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +14 -10
- package/README.md +16 -13
- package/dist/cli.js +162 -84
- package/dist/cli.js.map +1 -1
- package/dist/core/derive.d.ts +264 -0
- package/dist/core/derive.d.ts.map +1 -0
- package/dist/core/derive.js +576 -0
- package/dist/core/derive.js.map +1 -0
- package/dist/{check.d.ts → core/diagnose.d.ts} +15 -15
- package/dist/core/diagnose.d.ts.map +1 -0
- package/dist/{check.js → core/diagnose.js} +269 -223
- package/dist/core/diagnose.js.map +1 -0
- package/dist/{diff.d.ts → core/diff.d.ts} +3 -2
- package/dist/core/diff.d.ts.map +1 -0
- package/dist/{diff.js → core/diff.js} +89 -43
- package/dist/core/diff.js.map +1 -0
- package/dist/{fabric.d.ts → core/fabric.d.ts} +5 -3
- package/dist/core/fabric.d.ts.map +1 -0
- package/dist/{fabric.js → core/fabric.js} +12 -11
- package/dist/core/fabric.js.map +1 -0
- package/dist/{graph.d.ts → core/graph.d.ts} +2 -4
- package/dist/core/graph.d.ts.map +1 -0
- package/dist/{graph.js → core/graph.js} +53 -54
- package/dist/core/graph.js.map +1 -0
- package/dist/core/light.d.ts +24 -0
- package/dist/core/light.d.ts.map +1 -0
- package/dist/{light.js → core/light.js} +17 -12
- package/dist/core/light.js.map +1 -0
- package/dist/{model.d.ts → core/model.d.ts} +178 -18
- package/dist/core/model.d.ts.map +1 -0
- package/dist/{model.js → core/model.js} +307 -68
- package/dist/core/model.js.map +1 -0
- package/dist/core/parse.d.ts.map +1 -0
- package/dist/{parse.js → core/parse.js} +546 -133
- package/dist/core/parse.js.map +1 -0
- package/dist/{poly.d.ts → core/poly.d.ts} +3 -6
- package/dist/core/poly.d.ts.map +1 -0
- package/dist/{poly.js → core/poly.js} +8 -13
- package/dist/core/poly.js.map +1 -0
- package/dist/core/site.d.ts.map +1 -0
- package/dist/{site.js → core/site.js} +2 -2
- package/dist/core/site.js.map +1 -0
- package/dist/core/tolerance.d.ts +26 -0
- package/dist/core/tolerance.d.ts.map +1 -0
- package/dist/core/tolerance.js +48 -0
- package/dist/core/tolerance.js.map +1 -0
- package/dist/{vertical.d.ts → core/vertical.d.ts} +48 -12
- package/dist/core/vertical.d.ts.map +1 -0
- package/dist/{vertical.js → core/vertical.js} +53 -105
- package/dist/core/vertical.js.map +1 -0
- package/dist/core/vocabulary.d.ts +40 -0
- package/dist/core/vocabulary.d.ts.map +1 -0
- package/dist/core/vocabulary.js +176 -0
- package/dist/core/vocabulary.js.map +1 -0
- package/dist/{axo.d.ts → draw/axo.d.ts} +1 -1
- package/dist/draw/axo.d.ts.map +1 -0
- package/dist/{axo.js → draw/axo.js} +53 -81
- package/dist/draw/axo.js.map +1 -0
- package/dist/draw/index.d.ts +3 -0
- package/dist/draw/index.d.ts.map +1 -0
- package/dist/draw/index.js +11 -0
- package/dist/draw/index.js.map +1 -0
- package/dist/draw/plan.d.ts +10 -0
- package/dist/draw/plan.d.ts.map +1 -0
- package/dist/draw/plan.js +284 -0
- package/dist/draw/plan.js.map +1 -0
- package/dist/index.d.ts +16 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -12
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +112 -50
- package/dist/mcp.js.map +1 -1
- package/dist/parse-file.d.ts +1 -1
- package/dist/parse-file.d.ts.map +1 -1
- package/dist/parse-file.js +19 -4
- package/dist/parse-file.js.map +1 -1
- package/dist/validate/access.d.ts +6 -0
- package/dist/validate/access.d.ts.map +1 -0
- package/dist/validate/access.js +248 -0
- package/dist/validate/access.js.map +1 -0
- package/dist/validate/envelope.d.ts +4 -0
- package/dist/validate/envelope.d.ts.map +1 -0
- package/dist/validate/envelope.js +55 -0
- package/dist/validate/envelope.js.map +1 -0
- package/dist/validate/index.d.ts +60 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +77 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/light.d.ts +6 -0
- package/dist/validate/light.d.ts.map +1 -0
- package/dist/validate/light.js +28 -0
- package/dist/validate/light.js.map +1 -0
- package/dist/validate/runs.d.ts +16 -0
- package/dist/validate/runs.d.ts.map +1 -0
- package/dist/validate/runs.js +60 -0
- package/dist/validate/runs.js.map +1 -0
- package/dist/validate/site.d.ts +6 -0
- package/dist/validate/site.d.ts.map +1 -0
- package/dist/validate/site.js +63 -0
- package/dist/validate/site.js.map +1 -0
- package/editors/vscode/.vscodeignore +2 -0
- package/editors/vscode/README.md +28 -0
- package/editors/vscode/extension.js +150 -0
- package/editors/vscode/language-configuration.json +19 -0
- package/editors/vscode/package.json +57 -0
- package/editors/vscode/syntaxes/koyu.tmLanguage.json +226 -0
- package/examples/basement/main.muro +3 -3
- package/examples/complex/main.muro +1 -1
- package/examples/complex/podium.muro +1 -1
- package/examples/complex/site.muro +6 -6
- package/examples/house/L2.muro +1 -1
- package/examples/house/main.muro +2 -2
- package/examples/house/site.muro +4 -4
- package/examples/house.muro +7 -7
- package/examples/mansion.muro +3 -3
- package/examples/office.muro +4 -4
- package/examples/steps/01-one-room.muro +1 -1
- package/examples/steps/02-two-rooms.muro +1 -1
- package/examples/steps/03-door.muro +1 -1
- package/examples/steps/04-exterior.muro +2 -2
- package/examples/steps/05-two-storeys.muro +2 -2
- package/examples/steps/06-finished.muro +3 -3
- package/examples/tower/L2.muro +1 -1
- package/examples/tower/main.muro +1 -1
- package/examples/tower/site.muro +4 -4
- package/examples/twin/main.muro +2 -2
- package/examples/twin/podium.muro +4 -4
- package/examples/twin/site.muro +8 -8
- package/examples/two-rooms.canonical.json +6 -4
- package/examples/two-rooms.muro +3 -3
- package/package.json +18 -3
- package/src/cli.ts +173 -83
- package/src/core/derive.ts +869 -0
- package/src/{check.ts → core/diagnose.ts} +313 -235
- package/src/{diff.ts → core/diff.ts} +91 -43
- package/src/{fabric.ts → core/fabric.ts} +22 -12
- package/src/{graph.ts → core/graph.ts} +64 -63
- package/src/core/light.ts +69 -0
- package/src/{model.ts → core/model.ts} +361 -74
- package/src/{parse.ts → core/parse.ts} +618 -135
- package/src/{poly.ts → core/poly.ts} +8 -16
- package/src/{site.ts → core/site.ts} +2 -2
- package/src/core/tolerance.ts +55 -0
- package/src/{vertical.ts → core/vertical.ts} +73 -116
- package/src/core/vocabulary.ts +210 -0
- package/src/{axo.ts → draw/axo.ts} +51 -94
- package/src/draw/index.ts +11 -0
- package/src/draw/plan.ts +344 -0
- package/src/index.ts +201 -34
- package/src/mcp.ts +119 -50
- package/src/parse-file.ts +19 -5
- package/src/validate/access.ts +291 -0
- package/src/validate/envelope.ts +59 -0
- package/src/validate/index.ts +107 -0
- package/src/validate/light.ts +43 -0
- package/src/validate/runs.ts +87 -0
- package/src/validate/site.ts +84 -0
- package/dist/axo.d.ts.map +0 -1
- package/dist/axo.js.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js.map +0 -1
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js.map +0 -1
- package/dist/fabric.d.ts.map +0 -1
- package/dist/fabric.js.map +0 -1
- package/dist/graph.d.ts.map +0 -1
- package/dist/graph.js.map +0 -1
- package/dist/light.d.ts +0 -15
- package/dist/light.d.ts.map +0 -1
- package/dist/light.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/parse.d.ts.map +0 -1
- package/dist/parse.js.map +0 -1
- package/dist/plan.d.ts +0 -10
- package/dist/plan.d.ts.map +0 -1
- package/dist/plan.js +0 -354
- package/dist/plan.js.map +0 -1
- package/dist/poly.d.ts.map +0 -1
- package/dist/poly.js.map +0 -1
- package/dist/site.d.ts.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/vertical.d.ts.map +0 -1
- package/dist/vertical.js.map +0 -1
- package/src/light.ts +0 -63
- package/src/plan.ts +0 -472
- /package/dist/{parse.d.ts → core/parse.d.ts} +0 -0
- /package/dist/{site.d.ts → core/site.d.ts} +0 -0
package/src/mcp.ts
CHANGED
|
@@ -11,21 +11,25 @@ import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
|
11
11
|
import {
|
|
12
12
|
areaM2,
|
|
13
13
|
isIndoor,
|
|
14
|
-
|
|
14
|
+
daylightInputs,
|
|
15
|
+
validate,
|
|
15
16
|
displayName,
|
|
16
17
|
doorsBetween,
|
|
17
18
|
effectiveUse,
|
|
19
|
+
isOutside,
|
|
18
20
|
isSemiOutdoor,
|
|
21
|
+
isVoid,
|
|
19
22
|
levelsSorted,
|
|
23
|
+
newUids,
|
|
20
24
|
polygonAreaM2,
|
|
21
25
|
toCanonical,
|
|
22
26
|
zoneAreaM2,
|
|
23
27
|
type Model,
|
|
24
28
|
type Space,
|
|
25
29
|
} from "./index.js";
|
|
26
|
-
import { check, checkDiagnostics } from "./
|
|
27
|
-
import { svgPlan } from "./plan.js";
|
|
28
|
-
import { siteReport } from "./site.js";
|
|
30
|
+
import { check, checkDiagnostics } from "./core/diagnose.js";
|
|
31
|
+
import { svgPlan } from "./draw/plan.js";
|
|
32
|
+
import { siteReport } from "./core/site.js";
|
|
29
33
|
import { parseFile, parseFileWith } from "./parse-file.js";
|
|
30
34
|
|
|
31
35
|
// ---- モデルの読み込みと要約 ----
|
|
@@ -34,23 +38,44 @@ function load(file: string): Model {
|
|
|
34
38
|
return parseFile(resolve(file));
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Every layer that took part in the composition — the Model records them all, whether or not
|
|
43
|
+
* they carry elements (a layer holding only `grid`/`level` is not dropped).
|
|
44
|
+
*
|
|
45
|
+
* The entry is always index 0 (`ingestLayer` pushes every layer). **Do not add the spelled
|
|
46
|
+
* `resolve(entry)`** — layer identity is filesystem identity, so adding a different spelling
|
|
47
|
+
* (a symlink, another letter case) counts one layer twice.
|
|
48
|
+
*
|
|
49
|
+
* **The order is strength order, which is what `model.layers` already is** — never sorted. The
|
|
50
|
+
* tool says "in strength order" and `koyu layers` prints the same order; sorting by path here made
|
|
51
|
+
* the two disagree about the same question, and strength is the answer an agent needs (it decides
|
|
52
|
+
* which layer's opinion wins).
|
|
53
|
+
*/
|
|
54
|
+
function layerFiles(model: Model): string[] {
|
|
55
|
+
return [...model.layers];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A path as the filesystem sees it; the spelling if it cannot be resolved — the same rule as layer identity (`parse-file.ts`) */
|
|
59
|
+
function real(path: string): string {
|
|
60
|
+
try {
|
|
61
|
+
return realpathSync.native(path);
|
|
62
|
+
} catch {
|
|
63
|
+
return path;
|
|
64
|
+
}
|
|
40
65
|
}
|
|
41
66
|
|
|
42
67
|
/** entryディレクトリ境界の検査 — 文字列prefixではなく相対パスで判定する (ADR-0013) */
|
|
43
68
|
function assertInside(entryDir: string, targetDir: string): void {
|
|
44
69
|
const rel = relative(entryDir, targetDir);
|
|
45
70
|
if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
46
|
-
throw new Error("entry
|
|
71
|
+
throw new Error("Cannot write outside the entry's directory");
|
|
47
72
|
}
|
|
48
73
|
}
|
|
49
74
|
|
|
50
75
|
function summarize(model: Model, file: string): unknown {
|
|
51
76
|
const rooms = [...model.spaces.values()].filter((s) => s.rects.length > 0 && s.level);
|
|
52
77
|
const indoor = rooms.filter((s) => isIndoor(model, s));
|
|
53
|
-
const semi = rooms.filter((s) => s
|
|
78
|
+
const semi = rooms.filter((s) => !isVoid(s) && isSemiOutdoor(model, s));
|
|
54
79
|
const byLevel: Record<string, { rooms: number; subtotalM2: number }> = {};
|
|
55
80
|
for (const lv of levelsSorted(model)) {
|
|
56
81
|
const rs = indoor.filter((s) => s.level === lv.name);
|
|
@@ -62,14 +87,14 @@ function summarize(model: Model, file: string): unknown {
|
|
|
62
87
|
}
|
|
63
88
|
const byUse: Record<string, number> = {};
|
|
64
89
|
for (const s of indoor) {
|
|
65
|
-
const u = effectiveUse(model, s) ?? "(
|
|
90
|
+
const u = effectiveUse(model, s) ?? "(unspecified)";
|
|
66
91
|
byUse[u] = Math.round(((byUse[u] ?? 0) + (areaM2(s) ?? 0)) * 100) / 100;
|
|
67
92
|
}
|
|
68
93
|
const r = check(model);
|
|
69
94
|
return {
|
|
70
95
|
name: model.name,
|
|
71
96
|
unit: model.unit,
|
|
72
|
-
layers: layerFiles(model
|
|
97
|
+
layers: layerFiles(model),
|
|
73
98
|
levels: levelsSorted(model).map((l) => ({
|
|
74
99
|
name: l.name,
|
|
75
100
|
z: l.z,
|
|
@@ -99,17 +124,22 @@ function summarize(model: Model, file: string): unknown {
|
|
|
99
124
|
floorsM2: byLevel,
|
|
100
125
|
byUseM2: byUse,
|
|
101
126
|
check: { errors: r.errors.length, warnings: r.warnings.length },
|
|
102
|
-
hint: "
|
|
127
|
+
hint: "Read layer contents with layers, check with check, and edit with write_layer (check is the gatekeeper). Architectural verdicts come from validate.",
|
|
103
128
|
};
|
|
104
129
|
}
|
|
105
130
|
|
|
106
131
|
function spaceInfo(model: Model, s: Space): unknown {
|
|
107
132
|
return {
|
|
108
133
|
path: s.path,
|
|
109
|
-
|
|
134
|
+
// 型は任意の自由なラベルなので、書かれていなければ鍵ごと出ない。
|
|
135
|
+
// **構成の事実はこの語ではなく下の二つが答える** — 型が無い空間について
|
|
136
|
+
// 「外部か」「吹抜けか」を消費側が推測できてしまうと、廃止した推定が戻る
|
|
137
|
+
...(s.type !== undefined ? { type: s.type } : {}),
|
|
110
138
|
name: displayName(s),
|
|
111
139
|
level: s.level,
|
|
112
140
|
areaM2: areaM2(s),
|
|
141
|
+
...(isOutside(s) ? { outside: true } : {}),
|
|
142
|
+
...(isVoid(s) ? { void: true } : {}),
|
|
113
143
|
semiOutdoor: isSemiOutdoor(model, s),
|
|
114
144
|
...(s.file ? { layer: s.file } : {}),
|
|
115
145
|
};
|
|
@@ -124,17 +154,17 @@ interface Tool {
|
|
|
124
154
|
}
|
|
125
155
|
|
|
126
156
|
const FILE_PROP = {
|
|
127
|
-
file: { type: "string", description: "entry
|
|
157
|
+
file: { type: "string", description: "Path to the entry .muro file (imports are composed automatically)" },
|
|
128
158
|
};
|
|
129
159
|
const str = (v: unknown, name: string): string => {
|
|
130
|
-
if (typeof v !== "string" || !v) throw new Error(`${name} (
|
|
160
|
+
if (typeof v !== "string" || !v) throw new Error(`${name} (a string) is required`);
|
|
131
161
|
return v;
|
|
132
162
|
};
|
|
133
163
|
|
|
134
164
|
const TOOLS: Record<string, Tool> = {
|
|
135
165
|
model_summary: {
|
|
136
166
|
description:
|
|
137
|
-
"
|
|
167
|
+
"Summary of the building: name, levels, layer composition, zones, door/window assets, areas, and check counts. Call this first",
|
|
138
168
|
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
139
169
|
run: (a) => {
|
|
140
170
|
const file = str(a.file, "file");
|
|
@@ -143,7 +173,7 @@ const TOOLS: Record<string, Tool> = {
|
|
|
143
173
|
},
|
|
144
174
|
check: {
|
|
145
175
|
description:
|
|
146
|
-
"
|
|
176
|
+
"The gatekeeper of the build: composes the layers and checks structural consistency. Errors and warnings carry layer:line. Call it after every edit. **This says nothing about architectural soundness** — that is the validate tool",
|
|
147
177
|
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
148
178
|
run: (a) => {
|
|
149
179
|
const m = load(str(a.file, "file"));
|
|
@@ -153,40 +183,44 @@ const TOOLS: Record<string, Tool> = {
|
|
|
153
183
|
spaces: m.spaces.size,
|
|
154
184
|
boundaries: m.boundaries.length,
|
|
155
185
|
...r,
|
|
156
|
-
// 構造化診断 (ADR-0016) — errors
|
|
186
|
+
// 構造化診断 (ADR-0016) — errors と warnings を足したものと同件。並びは走査の順で、
|
|
187
|
+
// errors/warnings はそれを severity で二本に割ったものなので、連結して添字で対応させてはならない。
|
|
188
|
+
// code/severity/path/relatedつき
|
|
157
189
|
diagnostics: checkDiagnostics(m),
|
|
158
190
|
};
|
|
159
191
|
},
|
|
160
192
|
},
|
|
161
193
|
layers: {
|
|
162
|
-
description: "
|
|
194
|
+
description: "Returns every layer (.muro file) taking part in the composition, in strength order (later layers are stronger), with its source — this is how you read the original",
|
|
163
195
|
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
164
196
|
run: (a) => {
|
|
165
197
|
const file = str(a.file, "file");
|
|
166
198
|
const m = load(file);
|
|
167
|
-
return layerFiles(m
|
|
199
|
+
return layerFiles(m).map((f) => ({ file: f, source: readFileSync(f, "utf8") }));
|
|
168
200
|
},
|
|
169
201
|
},
|
|
170
202
|
write_layer: {
|
|
171
203
|
description:
|
|
172
|
-
"
|
|
173
|
-
"checkのエラーは返すが書き込みは行う (複数レイヤーにまたがる編集の途中を許す) — 直して再度書くこと。履歴はgitに任せる",
|
|
204
|
+
"Checks a layer (.muro file) before replacing it. Content that would make the composition unparsable is never written (the original stays intact). Check errors are returned but the write still happens, so that an edit spanning several layers can be made in steps — fix it and write again. History is left to git",
|
|
174
205
|
schema: {
|
|
175
206
|
type: "object",
|
|
176
207
|
properties: {
|
|
177
208
|
...FILE_PROP,
|
|
178
|
-
layer: { type: "string", description: "
|
|
179
|
-
content: { type: "string", description: "
|
|
209
|
+
layer: { type: "string", description: "Path of the .muro file to write (relative to the entry, or absolute)" },
|
|
210
|
+
content: { type: "string", description: "The full text of the layer (a whole-file replacement)" },
|
|
180
211
|
},
|
|
181
212
|
required: ["file", "layer", "content"],
|
|
182
213
|
},
|
|
183
214
|
run: (a) => {
|
|
184
215
|
const file = str(a.file, "file");
|
|
185
216
|
const content = str(a.content, "content");
|
|
186
|
-
|
|
217
|
+
// Resolve to the real path: it stops a spelling that goes through a symlink from slipping
|
|
218
|
+
// past the boundary check, and it matches the identity the composition counts layers by
|
|
219
|
+
// (mismatch would make the gatekeeper validate stale content)
|
|
220
|
+
const entryDir = real(resolve(dirname(resolve(file))));
|
|
187
221
|
const target = resolve(entryDir, str(a.layer, "layer"));
|
|
188
|
-
if (!target.endsWith(".muro")) throw new Error("
|
|
189
|
-
assertInside(entryDir, dirname(target));
|
|
222
|
+
if (!target.endsWith(".muro")) throw new Error("Only .muro files can be written");
|
|
223
|
+
assertInside(entryDir, real(dirname(target)));
|
|
190
224
|
// 門番は書き込みの前 — 差し替え内容で仮想合成し、parse不能なら原本に触れない (ADR-0013)。
|
|
191
225
|
// 合成に参加しないファイルの内容は検証されない (importされた時のcheckが捕まえる)
|
|
192
226
|
let m: Model;
|
|
@@ -209,14 +243,36 @@ const TOOLS: Record<string, Tool> = {
|
|
|
209
243
|
return { written: target, ok: r.errors.length === 0, spaces: m.spaces.size, ...r };
|
|
210
244
|
},
|
|
211
245
|
},
|
|
246
|
+
new_uids: {
|
|
247
|
+
description:
|
|
248
|
+
"Mints fresh identity tokens (uid) to write onto spaces or zones with write_layer. They collide with nothing already composed into this model, and 80 bits of randomness keeps them apart from layers that are not composed here. **Nothing assigns a uid on its own** — call this only when a space has to be pointed at across renames (sensors, registers, long-running operations), and run check afterwards, because UID03 is the only thing that proves uniqueness",
|
|
249
|
+
schema: {
|
|
250
|
+
type: "object",
|
|
251
|
+
properties: {
|
|
252
|
+
...FILE_PROP,
|
|
253
|
+
count: { type: "integer", description: "How many tokens to mint (default 1)" },
|
|
254
|
+
},
|
|
255
|
+
required: ["file"],
|
|
256
|
+
},
|
|
257
|
+
run: (a) => {
|
|
258
|
+
const count = a.count === undefined ? 1 : Number(a.count);
|
|
259
|
+
if (!Number.isInteger(count) || count < 1 || count > 1000) {
|
|
260
|
+
throw new Error("count is an integer between 1 and 1000");
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
uids: newUids(load(str(a.file, "file")), count),
|
|
264
|
+
note: "Write these as uid: on a space or zone. No other element accepts uid (the ledger rejects it). A uid is carried across renames by hand — that act is the record of the design decision that it is still the same space",
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
},
|
|
212
268
|
doors: {
|
|
213
|
-
description: "
|
|
269
|
+
description: "Circulation query: how many doors lie between space A and space B (the path with the fewest doors)",
|
|
214
270
|
schema: {
|
|
215
271
|
type: "object",
|
|
216
272
|
properties: {
|
|
217
273
|
...FILE_PROP,
|
|
218
|
-
from: { type: "string", description: "
|
|
219
|
-
to: { type: "string", description: "
|
|
274
|
+
from: { type: "string", description: "Path of the space to start from (e.g. /L9/A/ldk)" },
|
|
275
|
+
to: { type: "string", description: "Path of the space to reach (e.g. /out/road-s)" },
|
|
220
276
|
},
|
|
221
277
|
required: ["file", "from", "to"],
|
|
222
278
|
},
|
|
@@ -226,10 +282,10 @@ const TOOLS: Record<string, Tool> = {
|
|
|
226
282
|
},
|
|
227
283
|
},
|
|
228
284
|
spaces: {
|
|
229
|
-
description: "
|
|
285
|
+
description: "List of spaces: path, type, level, area, semi-outdoor flag, and originating layer. Optionally filtered by level",
|
|
230
286
|
schema: {
|
|
231
287
|
type: "object",
|
|
232
|
-
properties: { ...FILE_PROP, level: { type: "string", description: "
|
|
288
|
+
properties: { ...FILE_PROP, level: { type: "string", description: "Filter by level name (optional)" } },
|
|
233
289
|
required: ["file"],
|
|
234
290
|
},
|
|
235
291
|
run: (a) => {
|
|
@@ -240,22 +296,37 @@ const TOOLS: Record<string, Tool> = {
|
|
|
240
296
|
},
|
|
241
297
|
},
|
|
242
298
|
light: {
|
|
243
|
-
description:
|
|
299
|
+
description:
|
|
300
|
+
"Daylight inputs: floor area and effective window area for every space written with daylight:1 (a 0.7 factor applies through a covered semi-outdoor space). **It delivers no verdict** — the 1/7 judgement comes from the validate tool",
|
|
244
301
|
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
245
302
|
run: (a) => {
|
|
246
303
|
const m = load(str(a.file, "file"));
|
|
247
|
-
return
|
|
248
|
-
path:
|
|
249
|
-
name: displayName(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
needM2: r.need,
|
|
304
|
+
return daylightInputs(m).map((d) => ({
|
|
305
|
+
path: d.space.path,
|
|
306
|
+
name: displayName(d.space),
|
|
307
|
+
windowM2: d.window,
|
|
308
|
+
floorM2: d.floor,
|
|
309
|
+
missingH: d.missingH,
|
|
254
310
|
}));
|
|
255
311
|
},
|
|
256
312
|
},
|
|
313
|
+
validate: {
|
|
314
|
+
description:
|
|
315
|
+
"Architectural verdicts: daylight, envelope continuity, stair proportions, slopes, reachability, column/door collisions, and the site. **This is a different surface from the check guarantee** — findings carry rule/level, never code/severity. The surface grows and is not frozen",
|
|
316
|
+
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
317
|
+
run: (a) => {
|
|
318
|
+
const m = load(str(a.file, "file"));
|
|
319
|
+
const findings = validate(m);
|
|
320
|
+
return {
|
|
321
|
+
findings,
|
|
322
|
+
violations: findings.filter((f) => f.level === "violation").length,
|
|
323
|
+
cautions: findings.filter((f) => f.level === "caution").length,
|
|
324
|
+
note: "These are verdicts, not the structural-consistency guarantee of koyu check",
|
|
325
|
+
};
|
|
326
|
+
},
|
|
327
|
+
},
|
|
257
328
|
site: {
|
|
258
|
-
description: "
|
|
329
|
+
description: "Site query: site area (declared against derived), road frontage, footprint, and the coverage and floor-area ratios",
|
|
259
330
|
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
260
331
|
run: (a) => {
|
|
261
332
|
const r = siteReport(load(str(a.file, "file")));
|
|
@@ -282,16 +353,16 @@ const TOOLS: Record<string, Tool> = {
|
|
|
282
353
|
},
|
|
283
354
|
},
|
|
284
355
|
plan_svg: {
|
|
285
|
-
description: "
|
|
356
|
+
description: "Generates and returns the plan SVG for a level (form is generated, not written — the lowest level doubles as the site plan)",
|
|
286
357
|
schema: {
|
|
287
358
|
type: "object",
|
|
288
|
-
properties: { ...FILE_PROP, level: { type: "string", description: "
|
|
359
|
+
properties: { ...FILE_PROP, level: { type: "string", description: "Level name (e.g. L5)" } },
|
|
289
360
|
required: ["file", "level"],
|
|
290
361
|
},
|
|
291
362
|
run: (a) => svgPlan(load(str(a.file, "file")), { level: str(a.level, "level") }),
|
|
292
363
|
},
|
|
293
364
|
canonical_json: {
|
|
294
|
-
description: "
|
|
365
|
+
description: "The canonical JSON (machine format — one composed model, byte-stable). The ground for diffing and for external connections",
|
|
295
366
|
schema: { type: "object", properties: FILE_PROP, required: ["file"] },
|
|
296
367
|
run: (a) => JSON.parse(toCanonical(load(str(a.file, "file")))),
|
|
297
368
|
},
|
|
@@ -327,11 +398,9 @@ function handle(msg: Json): void {
|
|
|
327
398
|
result(id, {
|
|
328
399
|
protocolVersion: (params.protocolVersion as string) ?? "2025-06-18",
|
|
329
400
|
capabilities: { tools: {} },
|
|
330
|
-
serverInfo: { name: "koyu", version: "0.
|
|
401
|
+
serverInfo: { name: "koyu", version: "0.17.0" },
|
|
331
402
|
instructions:
|
|
332
|
-
"
|
|
333
|
-
"write_layerで編集する。checkが一棟のビルドの門番 — エラーは出所レイヤー:行つきで返る。" +
|
|
334
|
-
"doors/light/site/spacesは同じ記述への異なる問い。形 (plan_svg) は生成物。",
|
|
403
|
+
"Server for koyu, a space-first architectural description. Grasp the building with model_summary, read the original layers with layers, and edit with write_layer. check is the gatekeeper of the build and returns errors tagged layer:line — it guarantees structural consistency only. validate delivers the architectural verdicts, which are a separate and unfrozen surface. doors/light/site/spaces are different questions put to the same description. Form (plan_svg) is generated, never written.",
|
|
335
404
|
});
|
|
336
405
|
return;
|
|
337
406
|
}
|
|
@@ -352,7 +421,7 @@ function handle(msg: Json): void {
|
|
|
352
421
|
const name = params.name as string;
|
|
353
422
|
const tool = TOOLS[name];
|
|
354
423
|
if (!tool) {
|
|
355
|
-
rpcError(id, -32602,
|
|
424
|
+
rpcError(id, -32602, `Unknown tool: ${name}`);
|
|
356
425
|
return;
|
|
357
426
|
}
|
|
358
427
|
try {
|
|
@@ -374,7 +443,7 @@ function handle(msg: Json): void {
|
|
|
374
443
|
result(id, { prompts: [] });
|
|
375
444
|
return;
|
|
376
445
|
default:
|
|
377
|
-
rpcError(id, -32601,
|
|
446
|
+
rpcError(id, -32601, `Unsupported method: ${method}`);
|
|
378
447
|
}
|
|
379
448
|
}
|
|
380
449
|
|
package/src/parse-file.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// パーサ本体 (parse.ts) は純粋で、fsはこの薄い層だけが知る。
|
|
3
3
|
// ブラウザ (ugatsu等) は parseFiles (仮想ファイル群) を使う。
|
|
4
4
|
|
|
5
|
-
import { readFileSync } from "node:fs";
|
|
5
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
6
6
|
import { dirname, resolve } from "node:path";
|
|
7
|
-
import type { Model } from "./model.js";
|
|
8
|
-
import { parseWith } from "./parse.js";
|
|
7
|
+
import type { Model } from "./core/model.js";
|
|
8
|
+
import { parseWith } from "./core/parse.js";
|
|
9
9
|
|
|
10
10
|
/** ファイルから読む。import は書かれたファイルからの相対で解決される */
|
|
11
11
|
export function parseFile(filePath: string): Model {
|
|
@@ -21,8 +21,22 @@ export function parseFileWith(
|
|
|
21
21
|
overlay?: (absPath: string) => string | undefined,
|
|
22
22
|
): Model {
|
|
23
23
|
return parseWith((from, ref) => {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const spelled = from === undefined ? resolve(ref) : resolve(dirname(from), ref);
|
|
25
|
+
// **Layer identity is filesystem identity, not spelling.** Deciding it by spelling composes
|
|
26
|
+
// one file twice when it arrives through a symlink or in different letter case, breaking the
|
|
27
|
+
// promise that a layer imported twice is still composed once (rule 1) — in practice it failed
|
|
28
|
+
// with `grid X is declared once`. A path that does not exist yet (the overlay holds its
|
|
29
|
+
// content) has no realpath, so the spelling stands as its identity.
|
|
30
|
+
// `.native` asks the OS: on a case-insensitive filesystem (the macOS default) the JS
|
|
31
|
+
// implementation returns the spelling as given, so `B.muro` and `b.muro` become two layers
|
|
32
|
+
let key = spelled;
|
|
33
|
+
try {
|
|
34
|
+
key = realpathSync.native(spelled);
|
|
35
|
+
} catch {
|
|
36
|
+
/* not on disk yet — the spelling is the identity */
|
|
37
|
+
}
|
|
38
|
+
// The overlay answers to either spelling — the MCP gatekeeper matches on the resolved one
|
|
39
|
+
const src = overlay?.(spelled) ?? overlay?.(key) ?? readFileSync(key, "utf8");
|
|
26
40
|
return { key, src };
|
|
27
41
|
}, filePath);
|
|
28
42
|
}
|