@arkitektio/bsx 5.0.0 → 6.1.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 (230) hide show
  1. package/README.md +2 -2
  2. package/dist/bsx/analyze.d.ts +6 -5
  3. package/dist/bsx/analyze.d.ts.map +1 -1
  4. package/dist/bsx/analyze.js +12 -10
  5. package/dist/bsx/analyze.js.map +1 -1
  6. package/dist/bsx/declared.d.ts +111 -0
  7. package/dist/bsx/declared.d.ts.map +1 -0
  8. package/dist/bsx/declared.js +311 -0
  9. package/dist/bsx/declared.js.map +1 -0
  10. package/dist/bsx/index.d.ts +1 -0
  11. package/dist/bsx/index.d.ts.map +1 -1
  12. package/dist/bsx/index.js +1 -0
  13. package/dist/bsx/index.js.map +1 -1
  14. package/dist/bsx/infer.d.ts +40 -17
  15. package/dist/bsx/infer.d.ts.map +1 -1
  16. package/dist/bsx/infer.js +105 -49
  17. package/dist/bsx/infer.js.map +1 -1
  18. package/dist/bsx/language.d.ts +6 -2
  19. package/dist/bsx/language.d.ts.map +1 -1
  20. package/dist/bsx/language.js +65 -21
  21. package/dist/bsx/language.js.map +1 -1
  22. package/dist/bsx/parse.d.ts +6 -1
  23. package/dist/bsx/parse.d.ts.map +1 -1
  24. package/dist/bsx/parse.js +32 -3
  25. package/dist/bsx/parse.js.map +1 -1
  26. package/dist/bsx/print.d.ts.map +1 -1
  27. package/dist/bsx/print.js +3 -0
  28. package/dist/bsx/print.js.map +1 -1
  29. package/dist/bsx/references.d.ts +45 -51
  30. package/dist/bsx/references.d.ts.map +1 -1
  31. package/dist/bsx/references.js +265 -138
  32. package/dist/bsx/references.js.map +1 -1
  33. package/dist/catalogs/html.d.ts +2 -2
  34. package/dist/catalogs/index.d.ts +49 -71
  35. package/dist/catalogs/index.d.ts.map +1 -1
  36. package/dist/catalogs/index.js +1 -1
  37. package/dist/catalogs/logo.d.ts +14 -28
  38. package/dist/catalogs/logo.d.ts.map +1 -1
  39. package/dist/catalogs/logo.js +1 -2
  40. package/dist/catalogs/logo.js.map +1 -1
  41. package/dist/catalogs/parts/data.d.ts +1 -1
  42. package/dist/catalogs/parts/feedback.d.ts +3 -3
  43. package/dist/catalogs/parts/forms.d.ts +4 -4
  44. package/dist/catalogs/parts/html.d.ts +2 -2
  45. package/dist/catalogs/parts/icons.d.ts +2 -2
  46. package/dist/catalogs/parts/index.d.ts +35 -57
  47. package/dist/catalogs/parts/index.d.ts.map +1 -1
  48. package/dist/catalogs/parts/logo.d.ts +10 -25
  49. package/dist/catalogs/parts/logo.d.ts.map +1 -1
  50. package/dist/catalogs/parts/logo.js +12 -14
  51. package/dist/catalogs/parts/logo.js.map +1 -1
  52. package/dist/catalogs/parts/navigation.d.ts +4 -4
  53. package/dist/catalogs/parts/overlays.d.ts +11 -11
  54. package/dist/catalogs/parts/run.d.ts +2 -10
  55. package/dist/catalogs/parts/run.d.ts.map +1 -1
  56. package/dist/catalogs/parts/scene.d.ts +7 -15
  57. package/dist/catalogs/parts/scene.d.ts.map +1 -1
  58. package/dist/catalogs/parts/scene.js +1 -5
  59. package/dist/catalogs/parts/scene.js.map +1 -1
  60. package/dist/catalogs/parts/typography.d.ts +3 -3
  61. package/dist/catalogs/props.d.ts +2 -2
  62. package/dist/catalogs/scene.d.ts +5 -13
  63. package/dist/catalogs/scene.d.ts.map +1 -1
  64. package/dist/catalogs/shadcn.d.ts +11 -11
  65. package/dist/catalogs/ui.d.ts +16 -16
  66. package/dist/logo/actionLogoSource.d.ts +3 -3
  67. package/dist/logo/actionLogoSource.d.ts.map +1 -1
  68. package/dist/logo/actionLogoSource.js +4 -4
  69. package/dist/logo/actionLogoSource.js.map +1 -1
  70. package/dist/renderer/BlokRenderer.d.ts +16 -6
  71. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  72. package/dist/renderer/BlokRenderer.js +32 -13
  73. package/dist/renderer/BlokRenderer.js.map +1 -1
  74. package/dist/renderer/baseCatalog.d.ts +3 -3
  75. package/dist/renderer/baseCatalog.js +2 -2
  76. package/dist/renderer/bloks/control.d.ts +18 -2
  77. package/dist/renderer/bloks/control.d.ts.map +1 -1
  78. package/dist/renderer/bloks/control.js +85 -14
  79. package/dist/renderer/bloks/control.js.map +1 -1
  80. package/dist/renderer/bloks/data.d.ts +1 -1
  81. package/dist/renderer/bloks/feedback.d.ts +3 -3
  82. package/dist/renderer/bloks/forms.d.ts +4 -4
  83. package/dist/renderer/bloks/html.d.ts +2 -2
  84. package/dist/renderer/bloks/icons.d.ts +1 -1
  85. package/dist/renderer/bloks/index.d.ts +30 -37
  86. package/dist/renderer/bloks/index.d.ts.map +1 -1
  87. package/dist/renderer/bloks/logo/index.d.ts +1 -8
  88. package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
  89. package/dist/renderer/bloks/logo/index.js +1 -2
  90. package/dist/renderer/bloks/logo/index.js.map +1 -1
  91. package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
  92. package/dist/renderer/bloks/navigation.d.ts +4 -4
  93. package/dist/renderer/bloks/overlays.d.ts +11 -11
  94. package/dist/renderer/bloks/run/components.d.ts +1 -5
  95. package/dist/renderer/bloks/run/components.d.ts.map +1 -1
  96. package/dist/renderer/bloks/scene/Scene.d.ts.map +1 -1
  97. package/dist/renderer/bloks/scene/Scene.js +4 -2
  98. package/dist/renderer/bloks/scene/Scene.js.map +1 -1
  99. package/dist/renderer/bloks/scene/host.d.ts +2 -0
  100. package/dist/renderer/bloks/scene/host.d.ts.map +1 -1
  101. package/dist/renderer/bloks/scene/host.js +8 -0
  102. package/dist/renderer/bloks/scene/host.js.map +1 -1
  103. package/dist/renderer/bloks/scene/index.d.ts +4 -8
  104. package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
  105. package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
  106. package/dist/renderer/bloks/scene/interaction.js +3 -2
  107. package/dist/renderer/bloks/scene/interaction.js.map +1 -1
  108. package/dist/renderer/bloks/shared/props.d.ts +2 -2
  109. package/dist/renderer/bloks/typography.d.ts +3 -3
  110. package/dist/renderer/declarations.d.ts +40 -33
  111. package/dist/renderer/declarations.d.ts.map +1 -1
  112. package/dist/renderer/declarations.js +41 -56
  113. package/dist/renderer/declarations.js.map +1 -1
  114. package/dist/renderer/declare.js +4 -4
  115. package/dist/renderer/declare.js.map +1 -1
  116. package/dist/renderer/persist.d.ts +22 -13
  117. package/dist/renderer/persist.d.ts.map +1 -1
  118. package/dist/renderer/persist.js +40 -21
  119. package/dist/renderer/persist.js.map +1 -1
  120. package/dist/renderer/runtime/catalog.d.ts +4 -4
  121. package/dist/renderer/runtime/catalog.js +3 -3
  122. package/dist/renderer/runtime/components.d.ts +4 -4
  123. package/dist/renderer/runtime/components.d.ts.map +1 -1
  124. package/dist/renderer/runtime/components.js +5 -5
  125. package/dist/renderer/runtime/components.js.map +1 -1
  126. package/dist/renderer/runtime/context.d.ts +5 -5
  127. package/dist/renderer/runtime/context.d.ts.map +1 -1
  128. package/dist/renderer/runtime/context.js +11 -5
  129. package/dist/renderer/runtime/context.js.map +1 -1
  130. package/dist/renderer/runtime/describe.d.ts +3 -3
  131. package/dist/renderer/runtime/describe.d.ts.map +1 -1
  132. package/dist/renderer/runtime/describe.js +2 -2
  133. package/dist/renderer/runtime/describe.js.map +1 -1
  134. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  135. package/dist/renderer/runtime/hooks.js +8 -4
  136. package/dist/renderer/runtime/hooks.js.map +1 -1
  137. package/dist/renderer/runtime/index.d.ts +1 -0
  138. package/dist/renderer/runtime/index.d.ts.map +1 -1
  139. package/dist/renderer/runtime/index.js +1 -0
  140. package/dist/renderer/runtime/index.js.map +1 -1
  141. package/dist/renderer/runtime/locals.d.ts +57 -0
  142. package/dist/renderer/runtime/locals.d.ts.map +1 -0
  143. package/dist/renderer/runtime/locals.js +87 -0
  144. package/dist/renderer/runtime/locals.js.map +1 -0
  145. package/dist/renderer/runtime/scope.d.ts +14 -0
  146. package/dist/renderer/runtime/scope.d.ts.map +1 -1
  147. package/dist/renderer/runtime/scope.js +25 -3
  148. package/dist/renderer/runtime/scope.js.map +1 -1
  149. package/dist/renderer/runtime/tree.d.ts.map +1 -1
  150. package/dist/renderer/runtime/tree.js +7 -1
  151. package/dist/renderer/runtime/tree.js.map +1 -1
  152. package/dist/renderer/runtime/types.d.ts +8 -3
  153. package/dist/renderer/runtime/types.d.ts.map +1 -1
  154. package/dist/shadcn.d.ts +36 -43
  155. package/dist/shadcn.d.ts.map +1 -1
  156. package/dist/shadcn.js +1 -2
  157. package/dist/shadcn.js.map +1 -1
  158. package/dist/spec/bsx_v2.json +11067 -6321
  159. package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
  160. package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
  161. package/dist/spec/catalogs/orkestrator@1.json +10 -10
  162. package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
  163. package/dist/spec/catalogs.d.ts +4 -4
  164. package/dist/spec/catalogs.d.ts.map +1 -1
  165. package/dist/spec/catalogs.js +7 -7
  166. package/dist/spec/catalogs.js.map +1 -1
  167. package/dist/spec/vocabulary.d.ts +25 -4
  168. package/dist/spec/vocabulary.d.ts.map +1 -1
  169. package/dist/spec/vocabulary.js +50 -5
  170. package/dist/spec/vocabulary.js.map +1 -1
  171. package/dist/spec/vocabulary.json +58 -32
  172. package/dist/spec/vocabulary.json.js +58 -32
  173. package/package.json +1 -1
  174. package/src/bsx/analyze.ts +14 -12
  175. package/src/bsx/bsx.test.ts +4 -4
  176. package/src/bsx/declared.ts +346 -0
  177. package/src/bsx/index.ts +1 -0
  178. package/src/bsx/infer.test.ts +42 -32
  179. package/src/bsx/infer.ts +128 -71
  180. package/src/bsx/language.test.ts +37 -25
  181. package/src/bsx/language.ts +72 -25
  182. package/src/bsx/parse.ts +34 -3
  183. package/src/bsx/print.ts +3 -0
  184. package/src/bsx/references.test.ts +82 -81
  185. package/src/bsx/references.ts +313 -178
  186. package/src/catalogs/catalogs.test.ts +3 -2
  187. package/src/catalogs/index.ts +1 -1
  188. package/src/catalogs/logo.ts +1 -2
  189. package/src/catalogs/parts/logo.ts +13 -17
  190. package/src/catalogs/parts/scene.ts +1 -7
  191. package/src/logo/actionLogoSource.ts +4 -4
  192. package/src/renderer/BlokComponentHost.test.tsx +5 -5
  193. package/src/renderer/BlokRenderer.test.tsx +22 -0
  194. package/src/renderer/BlokRenderer.tsx +70 -20
  195. package/src/renderer/addBlokComponents.test.tsx +1 -1
  196. package/src/renderer/baseCatalog.ts +2 -2
  197. package/src/renderer/bloks/control.tsx +119 -16
  198. package/src/renderer/bloks/logo/index.tsx +2 -3
  199. package/src/renderer/bloks/logo/logo.fixture.json +266 -250
  200. package/src/renderer/bloks/logo/logo.test.tsx +18 -7
  201. package/src/renderer/bloks/run/space.test.tsx +12 -4
  202. package/src/renderer/bloks/scene/Scene.tsx +4 -2
  203. package/src/renderer/bloks/scene/host.tsx +11 -0
  204. package/src/renderer/bloks/scene/interaction.tsx +11 -6
  205. package/src/renderer/bloks/scene/transform.test.ts +8 -7
  206. package/src/renderer/declarations.test.ts +38 -51
  207. package/src/renderer/declarations.ts +67 -88
  208. package/src/renderer/declare.test.ts +4 -4
  209. package/src/renderer/declare.ts +4 -4
  210. package/src/renderer/persist.test.ts +70 -49
  211. package/src/renderer/persist.ts +57 -34
  212. package/src/renderer/runtime/catalog.test.ts +2 -2
  213. package/src/renderer/runtime/catalog.ts +4 -4
  214. package/src/renderer/runtime/components.tsx +8 -8
  215. package/src/renderer/runtime/context.tsx +17 -10
  216. package/src/renderer/runtime/describe.ts +5 -5
  217. package/src/renderer/runtime/hooks.ts +6 -4
  218. package/src/renderer/runtime/index.ts +1 -0
  219. package/src/renderer/runtime/locals.tsx +105 -0
  220. package/src/renderer/runtime/scope.tsx +31 -3
  221. package/src/renderer/runtime/tree.tsx +16 -4
  222. package/src/renderer/runtime/types.ts +8 -3
  223. package/src/shadcn.ts +1 -2
  224. package/src/spec/bsx_v2.json +11067 -6321
  225. package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
  226. package/src/spec/catalogs/orkestrator@1.json +10 -10
  227. package/src/spec/catalogs.ts +8 -8
  228. package/src/spec/spec.test.ts +19 -16
  229. package/src/spec/vocabulary.json +58 -32
  230. package/src/spec/vocabulary.ts +69 -10
@@ -5,24 +5,47 @@ import type {
5
5
  BlokComponentProp,
6
6
  BlokUtilCall,
7
7
  } from '../renderer/runtime/types';
8
- import {defaultBlokView, type BlokView, type SpecComponent} from '../spec/catalogs';
8
+ import {blokViewFor, defaultBlokView, type BlokView, type SpecComponent} from '../spec/catalogs';
9
9
  import {TEXT_NODE} from './parse';
10
10
  import {valueFitsPort} from '../spec/locals';
11
- import {LOCAL_ANY, resolveBlokScope} from './infer';
11
+ import {LOCAL_ANY, localDeclared, resolveLocals, type ResolvedLocal} from './infer';
12
+ import {
13
+ blokCatalog,
14
+ blokHeader,
15
+ content,
16
+ declarationProblem,
17
+ declaredQueries,
18
+ declaredSubscriptions,
19
+ headerProblem,
20
+ isDeclaration,
21
+ iterWithParents,
22
+ LIKE_PROP,
23
+ LOCAL_COMPONENT,
24
+ localName,
25
+ localProblem,
26
+ QUERY_COMPONENT,
27
+ SUBSCRIPTION_COMPONENT,
28
+ VAR_COMPONENT,
29
+ type BlokHeader,
30
+ type DeclaredQuery,
31
+ type DeclaredSubscription,
32
+ } from './declared';
12
33
  import {
13
34
  argFits,
14
35
  finding,
36
+ kindIn,
15
37
  loadVocabulary,
16
38
  type BlokFinding,
17
39
  type BlokKind,
18
40
  type BlokVocabulary,
19
41
  type DiagnosticFields,
42
+ type VocabKind,
20
43
  type VocabRecordField,
21
44
  } from '../spec/vocabulary';
22
45
 
23
46
  /**
24
- * The v2 validator: a blok's tree against what it declares, its kind, and the
25
- * catalogs that draw it. The port of arkitekt-spec's
47
+ * The v2 validator: a blok's tree (its `<Blok>` header and its declarations),
48
+ * where it is mounted, and the catalogs that draw it. The port of arkitekt-spec's
26
49
  * `declare/blok/validate.py` (with `walk.py`), held to the `checked` cases of
27
50
  * the corpus (`core/blok/spec/bsx_v2.json`). The server runs the same rules on
28
51
  * save; here they mark the source while the author types.
@@ -33,7 +56,7 @@ import {
33
56
  */
34
57
 
35
58
  /* -------------------------------------------------------------------------- */
36
- /* The scope: the corpus' `scope` shape */
59
+ /* The scope: where a blok is mounted (the corpus' `mount`) */
37
60
  /* -------------------------------------------------------------------------- */
38
61
 
39
62
  /** A port match, as the server's `PortMatchInput` spells it (snake_case, nulls allowed). */
@@ -79,35 +102,16 @@ export type BlokScopeLocalPort = {
79
102
  };
80
103
 
81
104
  /**
82
- * A local (vocabulary `locals`): an arg port plus `persist`. Its kind is a
83
- * port kind or `ANY`; left out (absent or null), it is inferred from the tree
84
- * (`resolveBlokScope`), and a given kind, `ANY` included, is kept.
105
+ * A local (vocabulary `locals`), as its `<local>` node declares it: an arg
106
+ * port plus `persist`. Its kind is a port kind or `ANY`; left out (absent or
107
+ * null), it is inferred from the tree (`resolveLocals`), and a given kind,
108
+ * `ANY` included, is kept.
85
109
  */
86
110
  export type BlokScopeLocal = Omit<BlokScopeLocalPort, 'kind'> & {kind?: string | null; persist?: boolean | null};
87
111
 
88
112
  /** A local after inference: its kind always said. */
89
113
  export type ResolvedBlokLocal = BlokScopeLocalPort & {persist?: boolean | null};
90
114
 
91
- export type BlokScopeQuery = {
92
- key: string;
93
- service?: string | null;
94
- document?: string | null;
95
- /** The variables, as stored arguments (`parseBsxArgument`). */
96
- variables?: readonly BlokActionArgument[] | null;
97
- poll?: number | null;
98
- /** The list field `fetch_more` appends to; a query without it cannot fetch more. */
99
- more?: string | null;
100
- };
101
-
102
- export type BlokScopeSubscription = {
103
- key: string;
104
- service?: string | null;
105
- document?: string | null;
106
- variables?: readonly BlokActionArgument[] | null;
107
- keep?: number | null;
108
- history?: string | null;
109
- };
110
-
111
115
  /** A class at its variant colons, those inside brackets left alone (`[&>*]:p-2`). */
112
116
  const splitClass = (token: string): string[] => {
113
117
  const parts: string[] = [];
@@ -145,19 +149,28 @@ export const unportableClass = (token: string, vocabulary: BlokVocabulary): stri
145
149
  return null;
146
150
  };
147
151
 
148
- /** What a blok declares beside its tree; the corpus' `scope` verbatim. */
152
+ /**
153
+ * Where a blok is mounted: what its mount provides, which its reads and calls
154
+ * resolve against (the spec's `BlokScope`, the corpus' `mount`, the record
155
+ * `arkitekt check --json` hands the editor tooling). What the blok is (its kind
156
+ * and context) and what it owns (its locals, queries and subscriptions) are
157
+ * read off its tree, never from here.
158
+ */
149
159
  export type BlokCheckScope = {
150
- kind: BlokKind;
151
- /** `HTML`, `SCENE`, `OVERLAY`, `LOGO`, or `ACTION_LOGO` (drawn as a logo). */
152
- context: string;
153
- dependencies: readonly BlokScopeDependency[];
154
- locals: readonly BlokScopeLocal[];
155
- queries: readonly BlokScopeQuery[];
156
- subscriptions: readonly BlokScopeSubscription[];
160
+ /** The kinds the mount takes (`app.blok`: agent; an action's `bloks=`: action or assign); empty or absent takes any. */
161
+ kinds?: readonly string[] | null;
162
+ /** What the mount is, for a message (`bloks= of process_slides`). */
163
+ mount?: string | null;
164
+ /**
165
+ * What `self` and `deps.<key>` resolve against; a `self` entry types `self`,
166
+ * which is open without one. Null: not mounted, every agent is taken as
167
+ * written (`deps.<key>`, `Placed`/`Route` keys and `like` are not checked).
168
+ */
169
+ dependencies: readonly BlokScopeDependency[] | null;
157
170
  /** The keys `args.<key>` may read; null reads any. */
158
171
  args: readonly string[] | null;
159
- /** The id of the catalog the blok is written for; null (or absent): the base catalog. The corpus' `target`. */
160
- target?: string | null;
172
+ /** The catalog the blok's `<Blok>` names, as the mount saw it; informational (the tree says it). */
173
+ catalog?: string | null;
161
174
  /** Per declared query, the shape of its value when its service's schema is known. */
162
175
  query_values?: Readonly<Record<string, BlokPortMatch>>;
163
176
  /** The assets `self.assets.<name>` may name; null (or absent) names any. */
@@ -166,37 +179,22 @@ export type BlokCheckScope = {
166
179
  demo?: {deps?: unknown; args?: unknown; task?: unknown} | null;
167
180
  };
168
181
 
169
- /** A scope after inference: every local kinded (dependencies are never inferred). */
170
- export type ResolvedBlokScope = Omit<BlokCheckScope, 'locals'> & {locals: readonly ResolvedBlokLocal[]};
171
-
172
- export const emptyBlokScope = (kind: BlokKind = 'agent', context = 'HTML'): BlokCheckScope => ({
173
- kind,
174
- context,
175
- dependencies: [],
176
- locals: [],
177
- queries: [],
178
- subscriptions: [],
179
- args: null,
180
- });
182
+ /** A blok checked on its own, mounted nowhere: what an editor checks from the source alone. */
183
+ export const unmountedBlokScope = (): BlokCheckScope => ({kinds: [], dependencies: null, args: null});
184
+
185
+ /** A blok mounted where `kinds` go, with `dependencies` (none by default): every agent it reads must be one of them. */
186
+ export const mountedBlokScope = (
187
+ kinds: readonly string[] = [],
188
+ dependencies: readonly BlokScopeDependency[] = [],
189
+ args: readonly string[] | null = null,
190
+ ): BlokCheckScope => ({kinds, dependencies, args});
181
191
 
182
- const ACTION_LOGO = 'ACTION_LOGO';
183
192
  const LOGO = 'LOGO';
184
193
  const SCENE = 'SCENE';
194
+ const PANEL = 'PANEL';
185
195
 
186
- /** The context a scope's components are drawn in: an action logo's is a logo's. */
187
- export const drawnIn = (scope: BlokCheckScope): string => (scope.context === ACTION_LOGO ? LOGO : scope.context);
188
-
189
- /** The root components a blok of ``context`` may start with (`HTML` → `Html`; `SCENE` → `Scene`, `Space`): a blok's root names its context. */
190
- export const blokRootsOf = (context: string): string[] =>
191
- Object.entries(loadVocabulary().blokRoots)
192
- .filter(([, named]) => named === context)
193
- .map(([root]) => root);
194
-
195
- /** The root a new blok of ``context`` starts with: the first it may start with (`SCENE` → `Scene`). */
196
- export const blokRootOf = (context: string): string | null => blokRootsOf(context)[0] ?? null;
197
-
198
- /** The blok context a root component names (`Space` → `SCENE`), or null when it names none. */
199
- export const blokContextOf = (component: string): string | null => loadVocabulary().blokRoots[component] ?? null;
196
+ /** A context as a `<Blok context>` spells it (`PANEL` → `panel`). */
197
+ export const spelledContext = (context: string): string => context.toLowerCase();
200
198
 
201
199
  /* -------------------------------------------------------------------------- */
202
200
  /* Matches */
@@ -209,7 +207,6 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
209
207
  const RUN_KINDS: readonly string[] = ['action', 'assign'];
210
208
  const ASSIGN_KIND = 'assign';
211
209
  const ASK_COMPONENT = 'ask';
212
- const CHROME_PROP = 'chrome';
213
210
  const CHROME_NONE = 'none';
214
211
  /** The language's elements whose children do not always show: a host part inside one still claims its slot. */
215
212
  const CONDITIONAL_COMPONENTS: ReadonlySet<string> = new Set(['if', 'else', 'match', 'case', 'default', 'foreach', 'suspense', 'fallback', 'error']);
@@ -324,21 +321,31 @@ export const foreachLet = (node: BlokComponentNode): string | null => {
324
321
  return node.props?.find(prop => prop.key === FOREACH_LET && prop.declares_value)?.declares_value ?? null;
325
322
  };
326
323
 
327
- const iterNodes = (node: BlokComponentNode): BlokComponentNode[] => [node, ...(node.children ?? []).flatMap(iterNodes)];
328
324
 
329
- /** Every path a list of arguments reads (a query's variables), depth first. */
330
- const argumentPaths = (args: readonly BlokActionArgument[]): string[] => {
331
- const paths: string[] = [];
332
- const visit = (argument: BlokActionArgument) => {
333
- if (argument.value_path != null) paths.push(argument.value_path);
334
- for (const call of [argument.util_call, argument.agent_call]) call?.arguments?.forEach(visit);
335
- [...(argument.value_list ?? []), ...(argument.value_dict ?? [])].forEach(visit);
336
- };
337
- args.forEach(visit);
338
- return paths;
325
+ /** A `<local>` in scope: its node and the port it resolved to. */
326
+ type LocalBinding = {local: true; node: string; name: string; port: ResolvedBlokLocal};
327
+ type Binding = Match | LocalBinding;
328
+ const isLocalBinding = (binding: Binding | undefined): binding is LocalBinding =>
329
+ binding !== null && binding !== undefined && (binding as LocalBinding).local === true;
330
+
331
+ type Scope = ReadonlyMap<string, Binding>;
332
+
333
+ /** What a name in scope is, for `roots.shadow`. */
334
+ const bindingWhat = (name: string, binding: Binding | undefined, into: ReadonlySet<string>): string => {
335
+ if (isLocalBinding(binding)) return `the local ${binding.node}`;
336
+ if (into.has(name)) return "a call's record";
337
+ return 'a let';
339
338
  };
340
339
 
341
- type Scope = ReadonlyMap<string, Match>;
340
+ const LOCAL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
341
+ const FIELD_PATH = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/;
342
+
343
+ /** The kind of a GraphQL document's first operation: `query` (also for `{ ... }`), `mutation`, `subscription`, `fragment`. */
344
+ export const operationKeyword = (document: string): string => {
345
+ const text = document.replace(/#[^\n]*/g, '').trimStart();
346
+ if (text.startsWith('{')) return 'query';
347
+ return /^[A-Za-z_]+/.exec(text)?.[0] ?? '';
348
+ };
342
349
 
343
350
  /* -------------------------------------------------------------------------- */
344
351
  /* The checker */
@@ -363,7 +370,7 @@ const DIGITS = /^[0-9]+$/;
363
370
  * - an agent blok has none: ``agent bloks read only `self` ``.
364
371
  */
365
372
  export const dependencyHint = (key: string, kind: BlokKind): string => {
366
- if (kind === 'action' || kind === 'assign' || kind === 'action_logo') return `add a dependency parameter \`${key}\` to the action`;
373
+ if (kind === 'action' || kind === 'assign') return `add a dependency parameter \`${key}\` to the action`;
367
374
  if (kind === 'agent') return 'agent bloks read only `self`';
368
375
  return `dependencies=[AgentDependencyInput(key="${key}")]`;
369
376
  };
@@ -438,32 +445,39 @@ const argumentWhat = (argument: BlokActionArgument): string => {
438
445
  class Checker {
439
446
  readonly findings: BlokFinding[] = [];
440
447
  private readonly vocabulary = loadVocabulary();
441
- private readonly kind;
448
+ /** The kind's row in the blok's context (an action's logo reads only `task`). */
449
+ private readonly kind: VocabKind;
450
+ private readonly kindName: BlokKind;
451
+ private readonly context: string;
452
+ private readonly mounted: boolean;
442
453
  private readonly dependencies: Map<string, BlokScopeDependency>;
443
- private readonly locals: Map<string, ResolvedBlokLocal>;
444
- private readonly queries: Map<string, BlokScopeQuery>;
445
- private readonly subscriptions: Map<string, BlokScopeSubscription>;
454
+ /** Per `<local>` node id, its port with its kind resolved. */
455
+ private readonly resolved: ReadonlyMap<string, ResolvedLocal>;
456
+ private queries = new Map<string, DeclaredQuery>();
457
+ private subscriptions = new Map<string, DeclaredSubscription>();
458
+ /** The node ids of the locals a control binds. */
446
459
  private readonly boundLocals = new Set<string>();
447
460
  private readonly into = new Set<string>();
448
461
  private asks = false;
449
462
  /** The id of the root that says `chrome="none"`, when it does. */
450
- private chromeless: string | null = null;
463
+ private readonly chromeless: string | null;
451
464
  private readonly colour: RegExp;
452
465
 
453
- readonly scope: ResolvedBlokScope;
466
+ readonly header: BlokHeader;
467
+ readonly scope: BlokCheckScope;
454
468
  readonly view: BlokView | null;
455
469
 
456
- constructor(
457
- scope: ResolvedBlokScope,
458
- view: BlokView | null,
459
- ) {
470
+ constructor(header: BlokHeader, scope: BlokCheckScope, view: BlokView | null, resolved: ReadonlyMap<string, ResolvedLocal>) {
471
+ this.header = header;
460
472
  this.scope = scope;
461
473
  this.view = view;
462
- this.kind = this.vocabulary.kinds[scope.kind];
463
- this.dependencies = new Map(scope.dependencies.map(dependency => [dependency.key, dependency]));
464
- this.locals = new Map(scope.locals.map(local => [local.key, local]));
465
- this.queries = new Map(scope.queries.map(query => [query.key, query]));
466
- this.subscriptions = new Map(scope.subscriptions.map(subscription => [subscription.key, subscription]));
474
+ this.kindName = header.kind;
475
+ this.context = header.context;
476
+ this.kind = kindIn(this.vocabulary.kinds[header.kind], header.context);
477
+ this.mounted = scope.dependencies !== null;
478
+ this.dependencies = new Map((scope.dependencies ?? []).map(dependency => [dependency.key, dependency]));
479
+ this.resolved = resolved;
480
+ this.chromeless = header.chrome === CHROME_NONE ? header.node : null;
467
481
  this.colour = colourPattern(this.vocabulary);
468
482
  }
469
483
 
@@ -476,51 +490,136 @@ class Checker {
476
490
  }
477
491
 
478
492
  private notInKind(nodeId: string | null, path: string, root: string, propKey?: string): void {
479
- this.add('roots.not_in_kind', nodeId, {path, n: article(this.scope.kind), kind: this.scope.kind, root, roots: this.rootsText()}, propKey);
493
+ this.add('roots.not_in_kind', nodeId, {path, n: article(this.kindName), kind: this.kindName, root, roots: this.rootsText()}, propKey);
480
494
  }
481
495
 
482
496
  /* -- declarations -- */
483
497
 
484
498
  checkDeclarations(tree: BlokComponentNode): void {
485
- const {vocabulary, scope} = this;
486
- const drawn = drawnIn(scope);
487
- const wrongLogo = (scope.context === ACTION_LOGO) !== (scope.kind === 'action_logo');
488
- if (wrongLogo || !(this.kind.contexts as readonly string[]).includes(drawn)) {
489
- this.add('context.kind', null, {n: article(scope.kind), kind: scope.kind, contexts: this.kind.contexts.join(', '), context: scope.context});
490
- }
491
- // A context may have several roots (a SCENE blok is a <Scene> or a <Space>).
492
- const roots = blokRootsOf(scope.context);
493
- if (roots.length && !roots.includes(tree.component)) {
494
- this.add('context.root', tree.id, {context: scope.context.toLowerCase(), root: roots.join('> or <'), component: tree.component});
495
- }
496
- if (scope.locals.length && !this.kind.locals) this.notInKind(null, 'locals', 'locals');
497
- for (const local of scope.locals) {
498
- if (vocabulary.reserved.has(local.key)) this.add('roots.reserved', `locals.${local.key}`, {name: local.key});
499
- this.checkLocalDefault(local);
499
+ const {vocabulary, header} = this;
500
+ const kind = this.kindName;
501
+ const row = vocabulary.kinds[kind];
502
+ const contextName = spelledContext(header.context);
503
+ if (!row.contexts.includes(header.context)) {
504
+ this.add('context.kind', tree.id, {n: article(kind), kind, contexts: row.contexts.map(spelledContext).join(', '), context: contextName});
505
+ }
506
+ const kinds = this.scope.kinds ?? [];
507
+ if (kinds.length && !kinds.includes(kind)) {
508
+ this.add('kind.placement', tree.id, {n: article(kind), kind, m: article(kinds[0]), expected: kinds.join(' or '), where: this.scope.mount || 'here'});
500
509
  }
510
+ if (header.chrome !== null && !vocabulary.blok.chrome.includes(header.context)) this.add('chrome.context', tree.id, {context: contextName});
511
+ const allowed = vocabulary.blok.content[header.context];
512
+ if (allowed) {
513
+ const drawn = content(tree);
514
+ if (drawn.length !== 1 || !allowed.includes(drawn[0].component)) {
515
+ const found = drawn.map(node => (node.component === TEXT_NODE ? 'text' : `<${node.component}>`)).join(', ') || 'nothing';
516
+ this.add('blok.content', tree.id, {context: contextName, expected: allowed.map(name => `one <${name}>`).join(' or '), found});
517
+ }
518
+ }
519
+ this.checkLocalPositions(tree);
520
+ this.checkQueries(tree);
501
521
  for (const [name, sites] of intoSites(tree)) {
502
522
  this.into.add(name);
503
523
  if (vocabulary.reserved.has(name)) this.add('roots.reserved', sites[0].site, {name});
504
- if (this.locals.has(name)) this.add('roots.shadow', sites[0].site, {name, first: 'a local', second: `the record of ${sites[0].site}`});
505
524
  if (sites.length > 1) this.add('into.twice', sites[1].site, {name, first: sites[0].site, second: sites[1].site});
506
525
  }
507
- for (const node of iterNodes(tree)) {
508
- const declared = foreachLet(node);
509
- if (declared === null) continue;
510
- if (vocabulary.reserved.has(declared)) this.add('roots.reserved', node.id, {name: declared});
511
- else if (this.locals.has(declared) || this.into.has(declared)) {
512
- this.add('roots.shadow', node.id, {
513
- name: declared,
514
- first: this.locals.has(declared) ? 'a local' : "a call's record",
515
- second: `the let of <foreach> (${node.id})`,
516
- });
526
+ }
527
+
528
+ /**
529
+ * Each `<local>` reads, comes first among its parent's children, inside an
530
+ * element that takes children, in a kind that has locals; a persisted one
531
+ * inside a keyless foreach is a warning.
532
+ */
533
+ private checkLocalPositions(tree: BlokComponentNode): void {
534
+ for (const [node, ancestors] of iterWithParents(tree)) {
535
+ const parent = ancestors.length ? ancestors[ancestors.length - 1] : null;
536
+ if (node.component === VAR_COMPONENT && (parent === null || (parent.component !== QUERY_COMPONENT && parent.component !== SUBSCRIPTION_COMPONENT))) {
537
+ this.add('query.declaration', node.id, {component: 'var', problem: 'belongs inside a <query> or <subscription>'});
538
+ }
539
+ if (node.component !== LOCAL_COMPONENT) continue;
540
+ const name = localName(node) ?? '?';
541
+ const problem = localProblem(node);
542
+ if (problem !== null) {
543
+ this.findings.push(problem);
544
+ continue;
545
+ }
546
+ if (!this.kind.locals) this.notInKind(node.id, `<local name='${name}'>`, 'locals');
547
+ if (this.vocabulary.reserved.has(name)) this.add('roots.reserved', node.id, {name});
548
+ if (parent === null) {
549
+ this.add('local.position', node.id, {name, problem: "is a blok's root; a blok is a <Blok>"});
550
+ continue;
551
+ }
552
+ const siblings = parent.children ?? [];
553
+ const other = siblings.slice(0, siblings.indexOf(node)).find(sibling => sibling.component !== LOCAL_COMPONENT);
554
+ if (other) {
555
+ const shown = other.component === TEXT_NODE ? 'text' : `<${other.component}>`;
556
+ this.add('local.position', node.id, {name, problem: `comes after ${shown} (${other.id}); locals come first among their parent's children`});
557
+ }
558
+ if ([QUERY_COMPONENT, SUBSCRIPTION_COMPONENT, LOCAL_COMPONENT, VAR_COMPONENT].includes(parent.component)) {
559
+ this.add('local.position', node.id, {name, problem: `is inside <${parent.component}>, which declares, and draws nothing`});
560
+ } else if (this.view) {
561
+ const spec = this.view.components.get(parent.component);
562
+ if (spec && !spec.acceptsChildren) this.add('local.position', node.id, {name, problem: `is inside <${parent.component}>, which takes no children`});
563
+ }
564
+ const resolved = this.resolved.get(node.id);
565
+ if (!resolved) continue;
566
+ if (resolved.likeProblem !== null) {
567
+ const like = node.props?.find(prop => prop.key === LIKE_PROP)?.static_value ?? null;
568
+ this.add('local.like', node.id, {name, like, problem: resolved.likeProblem});
569
+ }
570
+ this.checkLocalDefault(node.id, resolved.local);
571
+ if (resolved.local.persist) {
572
+ const loop = [...ancestors].reverse().find(ancestor => ancestor.component === FOREACH);
573
+ if (loop && !(loop.props ?? []).some(prop => prop.key === FOREACH_KEY)) this.add('local.persist_id', node.id, {name});
574
+ }
575
+ }
576
+ }
577
+
578
+ /** Queries and subscriptions are children of the `<Blok>`, each declared once and readable. */
579
+ private checkQueries(tree: BlokComponentNode): void {
580
+ const first = new Map<string, string>();
581
+ for (const [node, ancestors] of iterWithParents(tree)) {
582
+ if (node.component !== QUERY_COMPONENT && node.component !== SUBSCRIPTION_COMPONENT) continue;
583
+ const named = node.props?.find(prop => prop.key === 'name')?.static_value;
584
+ const name = typeof named === 'string' ? named : '?';
585
+ if (ancestors.length !== 1) {
586
+ const at = ancestors.length ? ancestors[ancestors.length - 1].id : 'the root';
587
+ this.add('query.position', node.id, {component: node.component, name, at});
517
588
  }
589
+ const problem = declarationProblem(node);
590
+ if (problem !== null) {
591
+ this.findings.push(problem);
592
+ continue;
593
+ }
594
+ const key = `${node.component}\u0000${name}`;
595
+ const seen = first.get(key);
596
+ if (seen !== undefined) this.add('query.duplicate', node.id, {what: node.component, name, first: seen, second: node.id});
597
+ else first.set(key, node.id);
518
598
  }
519
- for (const query of scope.queries) {
520
- for (const path of argumentPaths(query.variables ?? [])) this.resolve(path, null, new Map(), `query ${query.key}`);
599
+ this.queries = new Map(declaredQueries(tree).map(query => [query.key, query]));
600
+ this.subscriptions = new Map(declaredSubscriptions(tree).map(subscription => [subscription.key, subscription]));
601
+ const declared: Array<[string, DeclaredQuery | DeclaredSubscription]> = [
602
+ ...[...this.queries.values()].map(query => ['query', query] as [string, DeclaredQuery]),
603
+ ...[...this.subscriptions.values()].map(subscription => ['subscription', subscription] as [string, DeclaredSubscription]),
604
+ ];
605
+ for (const [what, each] of declared) {
606
+ const at = `${what === 'query' ? 'queries' : 'subscriptions'}.${each.key}`;
607
+ if (!LOCAL_NAME.test(each.key)) this.add('manifest.name', at, {what, key: each.key});
608
+ if (this.vocabulary.reserved.has(each.key)) this.add('roots.reserved', at, {name: each.key});
609
+ const operation = operationKeyword(each.document);
610
+ if (operation === 'mutation') {
611
+ this.add('query.read_only', at, {kind: what, name: each.key, problem: 'is a mutation: a blok reads, and writes only through a task'});
612
+ } else if (operation !== what) {
613
+ this.add('query.kind', at, {kind: what, name: each.key, operation: operation || 'document without an operation'});
614
+ }
521
615
  }
522
- for (const subscription of scope.subscriptions) {
523
- for (const path of argumentPaths(subscription.variables ?? [])) this.resolve(path, null, new Map(), `subscription ${subscription.key}`);
616
+ for (const query of this.queries.values()) {
617
+ if (query.more != null && !FIELD_PATH.test(query.more)) {
618
+ this.add('query.more', `queries.${query.key}`, {name: query.key, more: query.more, problem: 'is not a field path into its data (positions, images.items)'});
619
+ }
620
+ }
621
+ if (this.kindName === 'action' && this.context === LOGO && this.dependencies.size) this.add('manifest.action_logo', this.header.node);
622
+ for (const subscription of this.subscriptions.values()) {
524
623
  if (subscription.history != null && !this.queries.has(subscription.history)) {
525
624
  this.add('query.history', `subscriptions.${subscription.key}`, {name: subscription.key, history: subscription.history});
526
625
  }
@@ -528,18 +627,17 @@ class Checker {
528
627
  }
529
628
 
530
629
  /** A local's default fits its port: a number for a number, a list for a list, one of its choices. */
531
- private checkLocalDefault(local: ResolvedBlokLocal): void {
630
+ private checkLocalDefault(nodeId: string, local: ResolvedBlokLocal): void {
532
631
  if (local.kind === LOCAL_ANY) return;
533
632
  if (!valueFitsPort(local.default, local)) {
534
- this.add('local.default', `locals.${local.key}`, {name: local.key, default: local.default, kind: local.kind});
633
+ this.add('local.default', nodeId, {name: local.key, default: local.default, kind: local.kind});
535
634
  }
536
635
  }
537
636
 
538
637
  /** The port a path into a local names (the local, or a field of it), or null when its shape does not say (an ANY local). */
539
- private localPort(path: string): BlokScopeLocalPort | null {
540
- const [root, ...rest] = path.split('.');
541
- const local = this.locals.get(root) ?? null;
542
- let port: BlokScopeLocalPort | null = local !== null && local.kind !== LOCAL_ANY ? local : null;
638
+ private localPort(binding: LocalBinding, path: string): BlokScopeLocalPort | null {
639
+ const rest = path.split('.').slice(1);
640
+ let port: BlokScopeLocalPort | null = binding.port.kind !== LOCAL_ANY ? binding.port : null;
543
641
  for (const part of rest) {
544
642
  if (port === null) return null;
545
643
  const children: readonly BlokScopeLocalPort[] = port.children ?? [];
@@ -551,8 +649,8 @@ class Checker {
551
649
  }
552
650
 
553
651
  finish(): void {
554
- for (const local of this.scope.locals) {
555
- if (local.persist && !this.boundLocals.has(local.key)) this.add('local.unused_persist', `locals.${local.key}`, {name: local.key});
652
+ for (const [nodeId, resolved] of this.resolved) {
653
+ if (resolved.local.persist && !this.boundLocals.has(nodeId)) this.add('local.unused_persist', nodeId, {name: resolved.local.key});
556
654
  }
557
655
  if (this.chromeless !== null && this.kind.roots.includes('task') && !this.asks) this.add('chrome.no_ask', this.chromeless);
558
656
  }
@@ -560,13 +658,13 @@ class Checker {
560
658
  /* -- the walk -- */
561
659
 
562
660
  walk(tree: BlokComponentNode): void {
563
- const scope = new Map<string, Match>();
661
+ const scope = new Map<string, Binding>();
564
662
  for (const [name, sites] of intoSites(tree)) scope.set(name, this.bindInto(sites[0].call));
565
663
  this.walkNode(tree, scope, [], false);
566
664
  }
567
665
 
568
666
  private walkNode(node: BlokComponentNode, scope: Scope, ancestors: readonly BlokComponentNode[], inError: boolean): void {
569
- this.visitComponent(node, ancestors);
667
+ this.visitComponent(node, ancestors, scope);
570
668
  const inner = new Map(scope);
571
669
  const declared = foreachLet(node);
572
670
  if (declared !== null) {
@@ -579,7 +677,13 @@ class Checker {
579
677
  this.walkProp(node, prop, propScope, inError);
580
678
  }
581
679
  const inSlot = inError || (node.component === ERROR_SLOT && ancestors.length > 0 && ancestors[ancestors.length - 1].component === SUSPENSE);
582
- for (const child of node.children ?? []) this.walkNode(child, inner, [...ancestors, node], inSlot);
680
+ // Every local of a node is bound before any of its children is walked, in order: a second local of one name sees the first.
681
+ const children = node.children ?? [];
682
+ for (const child of children) {
683
+ const name = localDeclared(child);
684
+ if (name !== null) inner.set(name, this.bindLocal(name, child, new Map(inner)));
685
+ }
686
+ for (const child of children) this.walkNode(child, inner, [...ancestors, node], inSlot);
583
687
  }
584
688
 
585
689
  private walkProp(node: BlokComponentNode, prop: BlokComponentProp, scope: Scope, inError: boolean): void {
@@ -609,7 +713,7 @@ class Checker {
609
713
 
610
714
  /* -- components and props -- */
611
715
 
612
- private visitComponent(node: BlokComponentNode, ancestors: readonly BlokComponentNode[]): void {
716
+ private visitComponent(node: BlokComponentNode, ancestors: readonly BlokComponentNode[], scope: Scope): void {
613
717
  const spec = this.view?.components.get(node.component);
614
718
  if (this.view && !spec) {
615
719
  const foreign = this.view.foreign.get(node.component);
@@ -621,14 +725,14 @@ class Checker {
621
725
  }
622
726
  if (spec) this.checkCatalog(node, spec, ancestors);
623
727
  this.checkHostPart(node, ancestors);
624
- for (const prop of node.props ?? []) this.checkProp(node, prop, spec);
728
+ for (const prop of node.props ?? []) this.checkProp(node, prop, spec, scope);
625
729
  }
626
730
 
627
731
  private checkCatalog(node: BlokComponentNode, spec: SpecComponent, ancestors: readonly BlokComponentNode[]): void {
628
732
  const view = this.view;
629
733
  if (!view) return;
630
734
  const texts = (node.children ?? []).filter(child => child.component === TEXT_NODE);
631
- const elements = (node.children ?? []).length - texts.length;
735
+ const elements = (node.children ?? []).filter(child => child.component !== TEXT_NODE && !isDeclaration(child)).length;
632
736
  if (elements && !spec.acceptsChildren) this.add('catalog.children', node.id, {component: node.component});
633
737
  if (texts.length) {
634
738
  // Text is a child like any other; what takes it is the catalog's to say.
@@ -647,7 +751,7 @@ class Checker {
647
751
  if (unknown.length) this.add('catalog.props', node.id, {component: node.component, detail: `has no props [${unknown.map(pythonRepr).join(', ')}]`});
648
752
  const missing = spec.props.filter(prop => prop.required && !present.has(prop.key)).map(prop => prop.key).sort();
649
753
  if (missing.length) this.add('catalog.props', node.id, {component: node.component, detail: `requires props [${missing.map(pythonRepr).join(', ')}]`});
650
- let context = 'HTML';
754
+ let context = PANEL;
651
755
  for (const ancestor of ancestors) {
652
756
  const above = view.components.get(ancestor.component);
653
757
  if (above && !above.inheritsContext) context = above.childrenContext ?? above.context;
@@ -666,21 +770,18 @@ class Checker {
666
770
  if (forbidden.length) {
667
771
  this.add('catalog.placement', node.id, {component: node.component, detail: `must not be inside [${forbidden.map(pythonRepr).join(', ')}]`});
668
772
  }
669
- if (spec.kinds.length && !spec.kinds.includes(this.scope.kind)) {
670
- this.add('catalog.kind', node.id, {component: node.component, kinds: spec.kinds.join(' and '), n: article(this.scope.kind), kind: this.scope.kind});
773
+ if (spec.kinds.length && !spec.kinds.includes(this.kindName)) {
774
+ this.add('catalog.kind', node.id, {component: node.component, kinds: spec.kinds.join(' and '), n: article(this.kindName), kind: this.kindName});
671
775
  }
672
776
  }
673
777
 
674
778
  /**
675
779
  * What the language itself says of the host's parts, whatever catalog draws
676
- * them: a part placed anywhere claims its slot, and a root without chrome
677
- * leaves the asks to the blok.
780
+ * them: a part placed anywhere claims its slot (a blok without chrome
781
+ * leaves the asks to itself: `finish`).
678
782
  */
679
783
  private checkHostPart(node: BlokComponentNode, ancestors: readonly BlokComponentNode[]): void {
680
784
  if (node.component === ASK_COMPONENT) this.asks = true;
681
- if (ancestors.length === 0 && (node.props ?? []).some(prop => prop.key === CHROME_PROP && prop.static_value === CHROME_NONE)) {
682
- this.chromeless = node.id;
683
- }
684
785
  if (this.vocabulary.hostParts.includes(node.component)) {
685
786
  const inside = [...ancestors].reverse().find(ancestor => CONDITIONAL_COMPONENTS.has(ancestor.component));
686
787
  if (inside) this.add('part.conditional', node.id, {component: node.component, inside: inside.component});
@@ -689,8 +790,8 @@ class Checker {
689
790
 
690
791
  /** A ``Placed dep`` or ``Route through`` names dependencies of the blok, written out as keys. */
691
792
  private checkDependencyKeys(node: BlokComponentNode, prop: BlokComponentProp): void {
692
- // catalog.kind says it: a Space and its parts belong to an action's own blok.
693
- if (!RUN_KINDS.includes(this.scope.kind)) return;
793
+ // catalog.kind says it: a Space and its parts belong to an action's own blok. Unmounted, its keys are taken as written.
794
+ if (!RUN_KINDS.includes(this.kindName) || !this.mounted) return;
694
795
  const path = `${node.component}.${prop.key}`;
695
796
  const value = prop.static_value;
696
797
  const keys = typeof value === 'string' ? [value] : Array.isArray(value) ? value.filter((key): key is string => typeof key === 'string') : [];
@@ -699,14 +800,14 @@ class Checker {
699
800
  this.add(
700
801
  'deps.unknown',
701
802
  node.id,
702
- {path, key, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(key, this.scope.kind)},
803
+ {path, key, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(key, this.kindName)},
703
804
  prop.key,
704
805
  );
705
806
  }
706
807
  }
707
808
  }
708
809
 
709
- private checkProp(node: BlokComponentNode, prop: BlokComponentProp, spec: SpecComponent | undefined): void {
810
+ private checkProp(node: BlokComponentNode, prop: BlokComponentProp, spec: SpecComponent | undefined, scope: Scope): void {
710
811
  const {vocabulary} = this;
711
812
  const propSpec = spec?.props.find(candidate => candidate.key === prop.key);
712
813
  const holds = isCallbackValue(prop);
@@ -745,15 +846,16 @@ class Checker {
745
846
  this.add('local.bind', node.id, {what: what(prop)}, prop.key);
746
847
  } else {
747
848
  const root = path.split('.')[0];
748
- if (!this.locals.has(root)) this.add('local.unknown', node.id, {path, root}, prop.key);
849
+ const binding = scope.get(root);
850
+ if (!isLocalBinding(binding)) this.add('local.unknown', node.id, {path, root}, prop.key);
749
851
  else {
750
- this.boundLocals.add(root);
751
- if (propSpec) this.checkBindKind(node, propSpec.kind, path);
852
+ this.boundLocals.add(binding.node);
853
+ if (propSpec) this.checkBindKind(node, propSpec.kind, binding, path);
752
854
  }
753
855
  }
754
856
  }
755
- if (prop.util_call?.operation === START_EFFECT && this.scope.kind !== ASSIGN_KIND) {
756
- this.add('assign.kind', node.id, {what: 'assign.start()', n: article(this.scope.kind), kind: this.scope.kind}, prop.key);
857
+ if (prop.util_call?.operation === START_EFFECT && this.kindName !== ASSIGN_KIND) {
858
+ this.add('assign.kind', node.id, {what: 'assign.start()', n: article(this.kindName), kind: this.kindName}, prop.key);
757
859
  }
758
860
  if (DEPENDENCY_KEY_PROPS.has(`${node.component}.${prop.key}`)) this.checkDependencyKeys(node, prop);
759
861
  if (node.component === TOAST_COMPONENT && prop.key === TOAST_TASK_PROP) {
@@ -762,7 +864,7 @@ class Checker {
762
864
  }
763
865
  if (typeof prop.static_value === 'string') {
764
866
  if (prop.key === CLASS_NAME) this.checkClasses(prop.static_value, node.id, prop.key);
765
- if (drawnIn(this.scope) === LOGO && vocabulary.theme.logoPaintProps.includes(prop.key)) this.checkPaint(node, prop.key, prop.static_value);
867
+ if (this.context === LOGO && vocabulary.theme.logoPaintProps.includes(prop.key)) this.checkPaint(node, prop.key, prop.static_value);
766
868
  if (spec?.context === SCENE && vocabulary.theme.scenePaintProps.includes(prop.key)) this.checkSceneColour(node, prop.key, prop.static_value);
767
869
  }
768
870
  if (prop.key === CLASS_NAME && prop.util_call) {
@@ -771,9 +873,9 @@ class Checker {
771
873
  }
772
874
 
773
875
  /** The local a control writes is of a kind the control writes (`Slider`: FLOAT or INT). */
774
- private checkBindKind(node: BlokComponentNode, propKind: string, path: string): void {
876
+ private checkBindKind(node: BlokComponentNode, propKind: string, binding: LocalBinding, path: string): void {
775
877
  const allowed = this.vocabulary.locals.bindKinds[propKind];
776
- const port = this.localPort(path);
878
+ const port = this.localPort(binding, path);
777
879
  if (!allowed || port === null) return;
778
880
  if (!allowed.includes(port.kind)) {
779
881
  this.add(
@@ -840,11 +942,11 @@ class Checker {
840
942
  }
841
943
  const dependency = this.dependencies.get(call.dependency);
842
944
  if (!dependency) {
843
- if (call.dependency !== 'self') {
945
+ if (call.dependency !== 'self' && this.mounted) {
844
946
  this.add(
845
947
  'deps.unknown',
846
948
  where.node.id,
847
- {path: owner, key: call.dependency, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(call.dependency, this.scope.kind)},
949
+ {path: owner, key: call.dependency, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(call.dependency, this.kindName)},
848
950
  where.key,
849
951
  );
850
952
  }
@@ -872,9 +974,9 @@ class Checker {
872
974
  const path = argument.value_path;
873
975
  const match = ports.get(argument.key ?? '');
874
976
  if (path == null || !match || match.kind == null) continue;
875
- const root = path.split('.')[0];
876
- if (scope.has(root) || !this.locals.has(root)) continue;
877
- const port = this.localPort(path);
977
+ const binding = scope.get(path.split('.')[0]);
978
+ if (!isLocalBinding(binding)) continue;
979
+ const port = this.localPort(binding, path);
878
980
  if (port === null) continue;
879
981
  const target = {kind: match.kind, identifier: match.identifier ?? null};
880
982
  if (!argFits(port, target)) {
@@ -940,7 +1042,11 @@ class Checker {
940
1042
  if (call.operation === FETCH_MORE_FUNCTION && query.more == null) this.add('query.fetch_more', where.node.id, {path, name}, where.key);
941
1043
  }
942
1044
 
943
- private bindLet(name: string, items: BlokComponentProp | null, where: Where, scope: Scope): Match {
1045
+ private bindLet(name: string, items: BlokComponentProp | null, where: Where, scope: Scope): Binding {
1046
+ if (this.vocabulary.reserved.has(name)) this.add('roots.reserved', where.node.id, {name});
1047
+ else if (scope.has(name)) {
1048
+ this.add('roots.shadow', where.node.id, {name, first: bindingWhat(name, scope.get(name), this.into), second: `the let of <foreach> (${where.node.id})`});
1049
+ }
944
1050
  const keyed = (where.node.props ?? []).some(prop => prop.key === FOREACH_KEY);
945
1051
  const literal = items?.static_value;
946
1052
  if (!keyed && Array.isArray(literal) && literal.some(item => typeof item === 'object' && item !== null)) {
@@ -963,6 +1069,15 @@ class Checker {
963
1069
  return openMatch(name);
964
1070
  }
965
1071
 
1072
+ private bindLocal(name: string, node: BlokComponentNode, scope: Scope): Binding {
1073
+ if (scope.has(name) && !this.vocabulary.reserved.has(name)) {
1074
+ this.add('roots.shadow', node.id, {name, first: bindingWhat(name, scope.get(name), this.into), second: `the local ${node.id}`});
1075
+ }
1076
+ const resolved = this.resolved.get(node.id);
1077
+ if (!resolved) return openMatch(name);
1078
+ return {local: true, node: node.id, name, port: resolved.local};
1079
+ }
1080
+
966
1081
  private bindInto(call: BlokAgentCall): Match {
967
1082
  const dependency = this.dependencies.get(call.dependency);
968
1083
  const action = actionKeyFor(call);
@@ -989,13 +1104,14 @@ class Checker {
989
1104
  const [root, ...rest] = parts;
990
1105
  const report = (code: string, fields: DiagnosticFields) => this.add(code, nodeId, fields, propKey);
991
1106
  if (scope.has(root)) {
1107
+ const binding = scope.get(root) ?? null;
1108
+ if (isLocalBinding(binding)) {
1109
+ const local = binding.port;
1110
+ if (local.kind === LOCAL_ANY || OPAQUE_KINDS.has(local.kind)) return openMatch(root);
1111
+ return this.descend({...portMatch(local), key: root}, rest, path, nodeId, propKey);
1112
+ }
992
1113
  if (this.into.has(root)) this.checkReturns(path, rest, nodeId, propKey);
993
- return this.descend(scope.get(root) ?? null, rest, path, nodeId, propKey);
994
- }
995
- const local = this.locals.get(root);
996
- if (local) {
997
- if (local.kind === LOCAL_ANY || OPAQUE_KINDS.has(local.kind)) return openMatch(root);
998
- return this.descend({...portMatch(local), key: root}, rest, path, nodeId, propKey);
1114
+ return this.descend(binding, rest, path, nodeId, propKey);
999
1115
  }
1000
1116
  if (root === 'event') {
1001
1117
  if (!where || !where.callback) {
@@ -1033,7 +1149,8 @@ class Checker {
1033
1149
  }
1034
1150
  const dependency = this.dependencies.get(rest[0]);
1035
1151
  if (!dependency) {
1036
- report('deps.unknown', {path, key: rest[0], keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(rest[0], this.scope.kind)});
1152
+ if (!this.mounted) return openMatch(path);
1153
+ report('deps.unknown', {path, key: rest[0], keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(rest[0], this.kindName)});
1037
1154
  return null;
1038
1155
  }
1039
1156
  return this.agent(dependency, rest[0], rest.slice(1), path, nodeId, propKey);
@@ -1269,15 +1386,33 @@ export const checkLogo = (tree: BlokComponentNode, demo?: BlokCheckScope['demo']
1269
1386
  };
1270
1387
 
1271
1388
  /**
1272
- * Every finding of `tree` against `scope` and `view`: errors and warnings, in
1273
- * tree order. `view` defaults to the Orkestrator's (base, the standard catalogs
1274
- * and its module); `null` skips every catalog rule.
1389
+ * The view a blok is checked with when none is given: that of the catalog its
1390
+ * `<Blok catalog>` names when it is known here, the app's own when it names
1391
+ * none, and an incomplete base view (nothing reported unknown) otherwise.
1392
+ */
1393
+ export const viewForTree = (tree: BlokComponentNode): BlokView => {
1394
+ const catalog = blokCatalog(tree);
1395
+ return catalog === null ? defaultBlokView() : blokViewFor(catalog);
1396
+ };
1397
+
1398
+ /**
1399
+ * Every finding of `tree` mounted as `scope` says (unmounted by default),
1400
+ * against `view`: errors and warnings, in tree order. A root that is no
1401
+ * readable `<Blok>` is the one finding. `view` defaults to that of the catalog
1402
+ * the blok names (`viewForTree`); `null` skips every catalog rule.
1275
1403
  */
1276
- export const checkBlokTree = (tree: BlokComponentNode, scope: BlokCheckScope, view: BlokView | null = defaultBlokView()): BlokFinding[] => {
1277
- const checker = new Checker(resolveBlokScope(tree, scope, view), view);
1404
+ export const checkBlokTree = (
1405
+ tree: BlokComponentNode,
1406
+ scope: BlokCheckScope = unmountedBlokScope(),
1407
+ view: BlokView | null = viewForTree(tree),
1408
+ ): BlokFinding[] => {
1409
+ const problem = headerProblem(tree);
1410
+ if (problem !== null) return [problem];
1411
+ const header = blokHeader(tree) as BlokHeader;
1412
+ const checker = new Checker(header, scope, view, resolveLocals(tree, scope.dependencies, view));
1278
1413
  checker.checkDeclarations(tree);
1279
1414
  checker.walk(tree);
1280
- if (drawnIn(scope) === LOGO) checker.findings.push(...checkLogo(tree, scope.demo));
1415
+ if (header.context === LOGO) checker.findings.push(...checkLogo(tree, scope.demo));
1281
1416
  checker.finish();
1282
1417
  return checker.findings;
1283
1418
  };