@kensnzk/koyu 0.17.0 → 0.18.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/dist/analysis/contracts.d.ts +217 -0
- package/dist/analysis/contracts.d.ts.map +1 -0
- package/dist/analysis/contracts.js +27 -0
- package/dist/analysis/contracts.js.map +1 -0
- package/dist/analysis/index.d.ts +5 -0
- package/dist/analysis/index.d.ts.map +1 -0
- package/dist/analysis/index.js +17 -0
- package/dist/analysis/index.js.map +1 -0
- package/dist/analysis/json.d.ts +21 -0
- package/dist/analysis/json.d.ts.map +1 -0
- package/dist/analysis/json.js +111 -0
- package/dist/analysis/json.js.map +1 -0
- package/dist/cli.js +94 -26
- package/dist/cli.js.map +1 -1
- package/dist/core/site.d.ts +9 -0
- package/dist/core/site.d.ts.map +1 -1
- package/dist/core/site.js +6 -0
- package/dist/core/site.js.map +1 -1
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +3 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/diff.d.ts +2 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +3 -0
- package/dist/diff.js.map +1 -0
- package/dist/form.d.ts +5 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +4 -0
- package/dist/form.js.map +1 -0
- package/dist/graph.d.ts +2 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +3 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +2 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -50
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +40 -20
- package/dist/mcp.js.map +1 -1
- package/dist/model.d.ts +3 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +3 -0
- package/dist/model.js.map +1 -0
- package/dist/validate/assessment.d.ts +8 -0
- package/dist/validate/assessment.d.ts.map +1 -0
- package/dist/validate/assessment.js +1738 -0
- package/dist/validate/assessment.js.map +1 -0
- package/dist/validate/builtin/access.d.ts +55 -0
- package/dist/validate/builtin/access.d.ts.map +1 -0
- package/dist/validate/builtin/access.js +494 -0
- package/dist/validate/builtin/access.js.map +1 -0
- package/dist/validate/builtin/daylight.d.ts +44 -0
- package/dist/validate/builtin/daylight.d.ts.map +1 -0
- package/dist/validate/builtin/daylight.js +233 -0
- package/dist/validate/builtin/daylight.js.map +1 -0
- package/dist/validate/builtin/door-column-collisions.d.ts +47 -0
- package/dist/validate/builtin/door-column-collisions.d.ts.map +1 -0
- package/dist/validate/builtin/door-column-collisions.js +189 -0
- package/dist/validate/builtin/door-column-collisions.js.map +1 -0
- package/dist/validate/builtin/envelope.d.ts +30 -0
- package/dist/validate/builtin/envelope.d.ts.map +1 -0
- package/dist/validate/builtin/envelope.js +169 -0
- package/dist/validate/builtin/envelope.js.map +1 -0
- package/dist/validate/builtin/freeze.d.ts +3 -0
- package/dist/validate/builtin/freeze.d.ts.map +1 -0
- package/dist/validate/builtin/freeze.js +21 -0
- package/dist/validate/builtin/freeze.js.map +1 -0
- package/dist/validate/builtin/index.d.ts +38 -0
- package/dist/validate/builtin/index.d.ts.map +1 -0
- package/dist/validate/builtin/index.js +106 -0
- package/dist/validate/builtin/index.js.map +1 -0
- package/dist/validate/builtin/site.d.ts +62 -0
- package/dist/validate/builtin/site.d.ts.map +1 -0
- package/dist/validate/builtin/site.js +333 -0
- package/dist/validate/builtin/site.js.map +1 -0
- package/dist/validate/builtin/vertical-runs.d.ts +53 -0
- package/dist/validate/builtin/vertical-runs.d.ts.map +1 -0
- package/dist/validate/builtin/vertical-runs.js +290 -0
- package/dist/validate/builtin/vertical-runs.js.map +1 -0
- package/dist/validate/contracts.d.ts +188 -0
- package/dist/validate/contracts.d.ts.map +1 -0
- package/dist/validate/contracts.js +28 -0
- package/dist/validate/contracts.js.map +1 -0
- package/dist/validate/index.d.ts +2 -59
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +22 -70
- package/dist/validate/index.js.map +1 -1
- package/dist/vocabulary.d.ts +2 -0
- package/dist/vocabulary.d.ts.map +1 -0
- package/dist/vocabulary.js +3 -0
- package/dist/vocabulary.js.map +1 -0
- package/package.json +37 -5
- package/src/analysis/contracts.ts +234 -0
- package/src/analysis/index.ts +61 -0
- package/src/analysis/json.ts +117 -0
- package/src/cli.ts +103 -28
- package/src/core/site.ts +17 -0
- package/src/diagnostics.ts +8 -0
- package/src/diff.ts +14 -0
- package/src/form.ts +37 -0
- package/src/graph.ts +12 -0
- package/src/index.ts +39 -195
- package/src/mcp.ts +42 -25
- package/src/model.ts +43 -0
- package/src/validate/assessment.ts +1934 -0
- package/src/validate/builtin/access.ts +642 -0
- package/src/validate/builtin/daylight.ts +321 -0
- package/src/validate/builtin/door-column-collisions.ts +266 -0
- package/src/validate/builtin/envelope.ts +227 -0
- package/src/validate/builtin/freeze.ts +19 -0
- package/src/validate/builtin/index.ts +156 -0
- package/src/validate/builtin/site.ts +445 -0
- package/src/validate/builtin/vertical-runs.ts +390 -0
- package/src/validate/contracts.ts +240 -0
- package/src/validate/index.ts +45 -99
- package/src/vocabulary.ts +9 -0
- package/dist/validate/access.d.ts +0 -6
- package/dist/validate/access.d.ts.map +0 -1
- package/dist/validate/access.js +0 -248
- package/dist/validate/access.js.map +0 -1
- package/dist/validate/envelope.d.ts +0 -4
- package/dist/validate/envelope.d.ts.map +0 -1
- package/dist/validate/envelope.js +0 -55
- package/dist/validate/envelope.js.map +0 -1
- package/dist/validate/light.d.ts +0 -6
- package/dist/validate/light.d.ts.map +0 -1
- package/dist/validate/light.js +0 -28
- package/dist/validate/light.js.map +0 -1
- package/dist/validate/runs.d.ts +0 -16
- package/dist/validate/runs.d.ts.map +0 -1
- package/dist/validate/runs.js +0 -60
- package/dist/validate/runs.js.map +0 -1
- package/dist/validate/site.d.ts +0 -6
- package/dist/validate/site.d.ts.map +0 -1
- package/dist/validate/site.js +0 -63
- package/dist/validate/site.js.map +0 -1
- package/src/validate/access.ts +0 -291
- package/src/validate/envelope.ts +0 -59
- package/src/validate/light.ts +0 -43
- package/src/validate/runs.ts +0 -87
- package/src/validate/site.ts +0 -84
package/dist/validate/index.js
CHANGED
|
@@ -1,77 +1,29 @@
|
|
|
1
|
-
// koyu —
|
|
1
|
+
// koyu — the validation surface (`@kensnzk/koyu/validate`)
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
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
|
-
//
|
|
12
|
+
// core Diagnostic { code: "HGT01", severity: "error" | "warning" }
|
|
13
|
+
// validation RuleOutcome { status: "pass" | "fail" | "indeterminate" } inside an AssessmentReport
|
|
12
14
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
20
|
-
// (test/domains.test.ts
|
|
21
|
-
|
|
22
|
-
|
|
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,
|
|
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 @@
|
|
|
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 @@
|
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kensnzk/koyu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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
|
+
}
|