@arkitektio/bsx 6.6.2 → 6.8.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 (91) hide show
  1. package/dist/bsx/analyze.d.ts.map +1 -1
  2. package/dist/bsx/analyze.js +2 -2
  3. package/dist/bsx/analyze.js.map +1 -1
  4. package/dist/bsx/declared.d.ts +25 -1
  5. package/dist/bsx/declared.d.ts.map +1 -1
  6. package/dist/bsx/declared.js +34 -2
  7. package/dist/bsx/declared.js.map +1 -1
  8. package/dist/bsx/expr.d.ts +18 -4
  9. package/dist/bsx/expr.d.ts.map +1 -1
  10. package/dist/bsx/expr.js +46 -9
  11. package/dist/bsx/expr.js.map +1 -1
  12. package/dist/bsx/language.d.ts.map +1 -1
  13. package/dist/bsx/language.js +4 -2
  14. package/dist/bsx/language.js.map +1 -1
  15. package/dist/bsx/parse.d.ts +2 -0
  16. package/dist/bsx/parse.d.ts.map +1 -1
  17. package/dist/bsx/parse.js +63 -6
  18. package/dist/bsx/parse.js.map +1 -1
  19. package/dist/bsx/print.d.ts.map +1 -1
  20. package/dist/bsx/print.js +53 -10
  21. package/dist/bsx/print.js.map +1 -1
  22. package/dist/bsx/references.d.ts +23 -1
  23. package/dist/bsx/references.d.ts.map +1 -1
  24. package/dist/bsx/references.js +266 -14
  25. package/dist/bsx/references.js.map +1 -1
  26. package/dist/ports/rekuest.d.ts +1 -0
  27. package/dist/ports/rekuest.d.ts.map +1 -1
  28. package/dist/renderer/BlokRenderer.d.ts +4 -2
  29. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  30. package/dist/renderer/BlokRenderer.js +5 -1
  31. package/dist/renderer/BlokRenderer.js.map +1 -1
  32. package/dist/renderer/bloks/control.d.ts +5 -1
  33. package/dist/renderer/bloks/control.d.ts.map +1 -1
  34. package/dist/renderer/bloks/control.js +25 -3
  35. package/dist/renderer/bloks/control.js.map +1 -1
  36. package/dist/renderer/bloks/run/host.d.ts +5 -0
  37. package/dist/renderer/bloks/run/host.d.ts.map +1 -1
  38. package/dist/renderer/bloks/run/host.js.map +1 -1
  39. package/dist/renderer/runtime/context.d.ts +2 -1
  40. package/dist/renderer/runtime/context.d.ts.map +1 -1
  41. package/dist/renderer/runtime/context.js +4 -0
  42. package/dist/renderer/runtime/context.js.map +1 -1
  43. package/dist/renderer/runtime/hooks.d.ts +2 -0
  44. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  45. package/dist/renderer/runtime/hooks.js +12 -0
  46. package/dist/renderer/runtime/hooks.js.map +1 -1
  47. package/dist/renderer/runtime/resolution.d.ts +1 -0
  48. package/dist/renderer/runtime/resolution.d.ts.map +1 -1
  49. package/dist/renderer/runtime/resolution.js +11 -0
  50. package/dist/renderer/runtime/resolution.js.map +1 -1
  51. package/dist/renderer/runtime/schemas.d.ts.map +1 -1
  52. package/dist/renderer/runtime/schemas.js +1 -0
  53. package/dist/renderer/runtime/schemas.js.map +1 -1
  54. package/dist/renderer/runtime/types.d.ts +13 -0
  55. package/dist/renderer/runtime/types.d.ts.map +1 -1
  56. package/dist/renderer/runtime/types.js.map +1 -1
  57. package/dist/spec/bsx_v2.json +4804 -440
  58. package/dist/spec/catalogs/base@4.json +57 -1
  59. package/dist/spec/catalogs/base@4.json.js +57 -1
  60. package/dist/spec/vocabulary.d.ts +2 -0
  61. package/dist/spec/vocabulary.d.ts.map +1 -1
  62. package/dist/spec/vocabulary.js +2 -0
  63. package/dist/spec/vocabulary.js.map +1 -1
  64. package/dist/spec/vocabulary.json +19 -10
  65. package/dist/spec/vocabulary.json.js +19 -10
  66. package/package.json +1 -1
  67. package/src/bsx/analyze.ts +2 -2
  68. package/src/bsx/declared.ts +48 -2
  69. package/src/bsx/expr.ts +55 -11
  70. package/src/bsx/infer.test.ts +1 -1
  71. package/src/bsx/language.test.ts +17 -16
  72. package/src/bsx/language.ts +4 -2
  73. package/src/bsx/parse.ts +61 -5
  74. package/src/bsx/print.ts +50 -8
  75. package/src/bsx/references.test.ts +12 -11
  76. package/src/bsx/references.ts +277 -12
  77. package/src/ports/rekuest.ts +1 -1
  78. package/src/renderer/BlokRenderer.tsx +9 -0
  79. package/src/renderer/bloks/control.tsx +36 -4
  80. package/src/renderer/bloks/run/host.tsx +5 -0
  81. package/src/renderer/runtime/context.tsx +6 -0
  82. package/src/renderer/runtime/hooks.ts +13 -0
  83. package/src/renderer/runtime/resolution.ts +11 -1
  84. package/src/renderer/runtime/schemas.ts +1 -0
  85. package/src/renderer/runtime/types.ts +14 -0
  86. package/src/renderer/unbound.test.tsx +34 -1
  87. package/src/spec/bsx_v2.json +4804 -440
  88. package/src/spec/catalogs/base@4.json +57 -1
  89. package/src/spec/spec.test.ts +2 -2
  90. package/src/spec/vocabulary.json +19 -10
  91. package/src/spec/vocabulary.ts +4 -0
@@ -1,9 +1,10 @@
1
1
  import { blokViewFor, defaultBlokView } from '../spec/catalogs.js';
2
- import { TEXT_NODE } from './parse.js';
2
+ import { PICK_FUNCTION, TEXT_NODE } from './parse.js';
3
+ import { AGENTS_ROOT, PICK_VERB, REFERENCE_SEPARATOR } from './expr.js';
3
4
  import { valueFitsPort } from '../spec/locals.js';
4
5
  import { LOCAL_ANY, localDeclared, resolveLocals } from './infer.js';
5
- import { blokCatalog, blokHeader, content, declarationProblem, declaredQueries, declaredSubscriptions, headerProblem, isDeclaration, iterWithParents, LIKE_PROP, LOCAL_COMPONENT, localName, localProblem, QUERY_COMPONENT, SUBSCRIPTION_COMPONENT, VAR_COMPONENT, } from './declared.js';
6
- import { argFits, finding, kindIn, loadVocabulary, } from '../spec/vocabulary.js';
6
+ import { blokCatalog, blokHeader, content, declarationProblem, declaredDependencies, dependenciesAction, dependenciesOwner, dependenciesTarget, DEPENDENCIES_COMPONENT, declaredQueries, declaredSubscriptions, headerProblem, isDeclaration, iterWithParents, LIKE_PROP, LOCAL_COMPONENT, localName, localProblem, QUERY_COMPONENT, SUBSCRIPTION_COMPONENT, VAR_COMPONENT, } from './declared.js';
7
+ import { argFits, finding, kindIn, kindReads, loadVocabulary, } from '../spec/vocabulary.js';
7
8
  /** A class at its variant colons, those inside brackets left alone (`[&>*]:p-2`). */
8
9
  const splitClass = (token) => {
9
10
  const parts = [];
@@ -54,6 +55,74 @@ export const mountedBlokScope = (kinds = [], dependencies = [], args = null) =>
54
55
  const LOGO = 'LOGO';
55
56
  const SCENE = 'SCENE';
56
57
  const PANEL = 'PANEL';
58
+ const PICKER_COMPONENT = 'deppicker';
59
+ /** `cells.options.<dependency>`: the agents that fit a declared dependency, to pick among. */
60
+ const OPTIONS_SEGMENT = 'options';
61
+ /** What one of them reads as. */
62
+ const OPTION_FIELDS = [
63
+ { key: 'id', kind: 'STRING' },
64
+ { key: 'name', kind: 'STRING', nullable: true },
65
+ { key: 'connected', kind: 'BOOL' },
66
+ { key: 'picked', kind: 'BOOL' },
67
+ ];
68
+ /** The dependency `<key>.<name>` of declared dependencies, as it is stored. */
69
+ export const referenceKey = (key, name) => `${key}${REFERENCE_SEPARATOR}${name}`;
70
+ /** A stored dependency at its first separator: `[key, name]`, or null when it holds none. */
71
+ const splitReference = (dependency) => {
72
+ const at = dependency.indexOf(REFERENCE_SEPARATOR);
73
+ return at < 0 ? null : [dependency.slice(0, at), dependency.slice(at + REFERENCE_SEPARATOR.length)];
74
+ };
75
+ /** The dependencies `declared` borrows, each keyed `<key>__<dependency>`; or what is wrong with its `like`. */
76
+ export const borrowedDependencies = (declared, workflows) => {
77
+ const action = dependenciesAction(declared);
78
+ if (action === null)
79
+ return 'is not self.<action>';
80
+ if (!Object.prototype.hasOwnProperty.call(workflows, action))
81
+ return `names no action of the app ('${action}')`;
82
+ if (!workflows[action].length)
83
+ return `names an action with no dependencies ('${action}')`;
84
+ const taken = workflows[action].find(each => each.key === OPTIONS_SEGMENT || each.key === PICK_VERB || each.key.includes(REFERENCE_SEPARATOR));
85
+ if (taken)
86
+ return `names an action with a dependency called '${taken.key}', which cannot be read through a reference: rename that parameter of ${action}`;
87
+ return workflows[action].map(dependency => ({ ...dependency, key: referenceKey(declared.key, dependency.key) }));
88
+ };
89
+ /**
90
+ * `scope` with the dependencies an agent blok declares itself (`<dependencies>`)
91
+ * among its dependencies, keyed `<key>__<dependency>` and demanded as their
92
+ * action demands them. A declaration whose `like` does not resolve is left out
93
+ * (the checker says why), as is every one where the app's actions are not
94
+ * known (`workflows` null).
95
+ */
96
+ export const boundScope = (tree, scope) => {
97
+ const workflows = scope.workflows ?? null;
98
+ if (workflows === null || blokHeader(tree)?.kind !== 'agent')
99
+ return scope;
100
+ const known = new Set((scope.dependencies ?? []).map(dependency => dependency.key));
101
+ const borrowed = [];
102
+ for (const declared of declaredDependencies(tree)) {
103
+ const found = borrowedDependencies(declared, workflows);
104
+ if (typeof found === 'string')
105
+ continue;
106
+ for (const dependency of found) {
107
+ if (known.has(dependency.key))
108
+ continue;
109
+ known.add(dependency.key);
110
+ borrowed.push(dependency);
111
+ }
112
+ }
113
+ return borrowed.length ? { ...scope, dependencies: [...(scope.dependencies ?? []), ...borrowed] } : scope;
114
+ };
115
+ const CUSTOM_KIND = 'custom';
116
+ /**
117
+ * `text` (a path, a call) as a custom blok writes it: a bound agent stored `deps.<key>`
118
+ * reads `agents.<key>`; one through declared dependencies is left.
119
+ */
120
+ const asWritten = (text) => {
121
+ if (!text.startsWith('deps.'))
122
+ return text;
123
+ const rest = text.slice('deps.'.length);
124
+ return rest.split('.')[0].split('(')[0].includes(REFERENCE_SEPARATOR) ? text : `${AGENTS_ROOT}.${rest}`;
125
+ };
57
126
  /** A context as a `<Blok context>` spells it (`PANEL` → `panel`). */
58
127
  export const spelledContext = (context) => context.toLowerCase();
59
128
  /* -------------------------------------------------------------------------- */
@@ -203,13 +272,13 @@ const DIGITS = /^[0-9]+$/;
203
272
  * (the spec's `dependency_hint`):
204
273
  * - a custom or task blok declares it, to copy as it is: `dependencies=[AgentDependencyInput(key="laser")]`;
205
274
  * - an action blok's dependencies are its action's: ``add a dependency parameter `laser` to the action``;
206
- * - an agent blok has none: ``agent bloks read only `self` ``.
275
+ * - an agent blok declares it in its own tree: `<dependencies key="laser" like="self.<action>" />`.
207
276
  */
208
277
  export const dependencyHint = (key, kind) => {
209
278
  if (kind === 'action' || kind === 'assign' || kind === 'port')
210
279
  return `add a dependency parameter \`${key}\` to the action`;
211
280
  if (kind === 'agent')
212
- return 'agent bloks read only `self`';
281
+ return `declare it in the blok: <dependencies key="${key}" like="self.<action>" />, then read ${key}.<dependency>`;
213
282
  return `dependencies=[AgentDependencyInput(key="${key}")]`;
214
283
  };
215
284
  /** How a string on a typed prop is written as the literal it meant (`fullWidth={true}`): the spec's `literal_hint`. */
@@ -309,6 +378,8 @@ class Checker {
309
378
  /** The id of the root that says `chrome="none"`, when it does. */
310
379
  chromeless;
311
380
  colour;
381
+ /** The dependencies an agent blok declares itself, by key. */
382
+ declared = new Map();
312
383
  header;
313
384
  scope;
314
385
  view;
@@ -325,9 +396,20 @@ class Checker {
325
396
  this.chromeless = header.chrome === CHROME_NONE ? header.node : null;
326
397
  this.colour = colourPattern(this.vocabulary);
327
398
  }
328
- add(code, nodeId, fields = {}, propKey) {
399
+ add(code, nodeId, written = {}, propKey) {
400
+ const fields = this.kindName === CUSTOM_KIND
401
+ ? Object.fromEntries(Object.entries(written).map(([key, value]) => [key, typeof value === 'string' ? asWritten(value) : value]))
402
+ : written;
329
403
  this.findings.push(finding(code, fields, { ...(nodeId !== null ? { nodeId } : {}), ...(propKey !== undefined ? { propKey } : {}) }));
330
404
  }
405
+ /** Whether the kind reads the stored `root`: a custom blok's `agents` is stored `deps`. */
406
+ reads(root) {
407
+ return kindReads(this.kind, root);
408
+ }
409
+ /** Whether `dependency` (as stored) is declared in the blok's own tree: any of an agent blok, a `<key>__<name>` one of a custom blok. */
410
+ declares(dependency) {
411
+ return this.kindName === 'agent' || (this.kindName === CUSTOM_KIND && dependency.includes(REFERENCE_SEPARATOR));
412
+ }
331
413
  rootsText() {
332
414
  return [...this.kind.roots].sort().join(', ');
333
415
  }
@@ -357,6 +439,7 @@ class Checker {
357
439
  this.add('blok.content', tree.id, { context: contextName, expected: allowed.map(name => `one <${name}>`).join(' or '), found });
358
440
  }
359
441
  }
442
+ this.checkDependencies(tree);
360
443
  this.checkLocalPositions(tree);
361
444
  this.checkQueries(tree);
362
445
  for (const [name, sites] of intoSites(tree)) {
@@ -423,6 +506,147 @@ class Checker {
423
506
  }
424
507
  }
425
508
  }
509
+ /**
510
+ * A `<dependencies>` is a child of an agent or custom blok's `<Blok>`, keyed once, and
511
+ * names an action that has dependencies: one of the app's own, or of a bound agent (custom).
512
+ */
513
+ checkDependencies(tree) {
514
+ for (const [node, ancestors] of iterWithParents(tree)) {
515
+ if (node.component !== DEPENDENCIES_COMPONENT)
516
+ continue;
517
+ const literal = (name) => node.props?.find(prop => prop.key === name)?.static_value;
518
+ const key = literal('key');
519
+ if (ancestors.length !== 1 || (this.kindName !== 'agent' && this.kindName !== CUSTOM_KIND)) {
520
+ const at = ancestors.length > 1 ? ancestors[ancestors.length - 1].id : `a${article(this.kindName)} ${this.kindName} blok`;
521
+ this.add('dependencies.position', node.id, { key: typeof key === 'string' ? key : '?', at });
522
+ continue;
523
+ }
524
+ if (typeof key !== 'string' || !LOCAL_NAME.test(key)) {
525
+ this.add('dependencies.key', node.id, { node: node.id, problem: 'has no plain key' });
526
+ continue;
527
+ }
528
+ if (key === 'self' || this.declared.has(key)) {
529
+ const problem = key === 'self' ? "is keyed self, which is the blok's own agent" : `declares '${key}' a second time`;
530
+ this.add('dependencies.key', node.id, { node: node.id, problem });
531
+ continue;
532
+ }
533
+ const like = literal(LIKE_PROP);
534
+ const declared = { key, node: node.id, like: typeof like === 'string' ? like : null };
535
+ this.declared.set(key, declared);
536
+ const workflows = this.scope.workflows ?? null;
537
+ const owner = dependenciesOwner(declared);
538
+ if (this.kindName === CUSTOM_KIND) {
539
+ if (owner === null || owner === 'self') {
540
+ this.add('dependencies.like', node.id, { key, like: declared.like ?? '', problem: 'is not agents.<name>.<action>' });
541
+ }
542
+ else if (this.mounted && !this.dependencies.has(owner)) {
543
+ this.add('dependencies.like', node.id, { key, like: declared.like ?? '', problem: `names the agent '${owner}', which the blok is not bound to` });
544
+ }
545
+ }
546
+ else if (owner !== 'self') {
547
+ this.add('dependencies.like', node.id, { key, like: declared.like ?? '', problem: 'is not self.<action>' });
548
+ }
549
+ else if (workflows !== null) {
550
+ const borrowed = borrowedDependencies(declared, workflows);
551
+ if (typeof borrowed === 'string')
552
+ this.add('dependencies.like', node.id, { key, like: declared.like ?? '', problem: borrowed });
553
+ }
554
+ }
555
+ }
556
+ /**
557
+ * Whether the dependencies declared as `key` are known here: its action is
558
+ * one of the app's, so what is read through it is held to that action's dependencies.
559
+ */
560
+ typed(key) {
561
+ const declared = this.declared.get(key);
562
+ const workflows = this.scope.workflows ?? null;
563
+ // A bound agent's actions are known only where the blok runs.
564
+ if (declared === undefined || dependenciesOwner(declared) !== 'self' || workflows === null)
565
+ return false;
566
+ return typeof borrowedDependencies(declared, workflows) !== 'string';
567
+ }
568
+ /**
569
+ * Whether `dependency` (stored `<key>__<name>`) is none this blok
570
+ * declares: such dependencies are the ones in its own tree, mounted or not.
571
+ */
572
+ undeclared(dependency) {
573
+ if (!this.declares(dependency) || dependency === 'self')
574
+ return false;
575
+ const split = splitReference(dependency);
576
+ if (split === null || !this.declared.has(split[0]))
577
+ return true;
578
+ return this.typed(split[0]) && split[1] !== OPTIONS_SEGMENT && !this.dependencies.has(dependency);
579
+ }
580
+ /** `<key>.options.<dependency>`: the agents that fit it, each `{id, name, connected, picked}`. */
581
+ options(key, rest, path, nodeId, propKey) {
582
+ if (!rest.length) {
583
+ this.add('roots.whole', nodeId, { path, root: `${key}.${OPTIONS_SEGMENT}` }, propKey);
584
+ return null;
585
+ }
586
+ if (this.typed(key) && !this.dependencies.has(referenceKey(key, rest[0]))) {
587
+ this.add('deps.unknown', nodeId, { path, key: `${key}.${rest[0]}`, keys: this.dependencyKnown(key), hint: dependencyHint(key, this.kindName) }, propKey);
588
+ return null;
589
+ }
590
+ const listed = { key: rest[0], kind: 'LIST', children: [{ key: ITEM, kind: 'DICT', children: OPTION_FIELDS }] };
591
+ return this.descend(listed, rest.slice(1), path, nodeId, propKey);
592
+ }
593
+ /** `<key>.pick(<dependency>: <agent id>)`: declared dependencies, and dependencies of them. */
594
+ checkPick(call, where) {
595
+ const named = (call.arguments ?? []).find(argument => argument.key === 'key');
596
+ const picks = (call.arguments ?? []).find(argument => argument.key === 'picks');
597
+ const key = named?.value_literal;
598
+ if (typeof key !== 'string' || !this.declared.has(key)) {
599
+ const shown = typeof key === 'string' ? key : '?';
600
+ this.add('deps.unknown', where.node.id, { path: `${shown}.${PICK_VERB}(...)`, key: shown, keys: this.dependencyKnown(shown), hint: dependencyHint(shown, this.kindName) }, where.key);
601
+ return;
602
+ }
603
+ if (!this.typed(key))
604
+ return;
605
+ for (const pick of picks?.value_dict ?? []) {
606
+ if (pick.key != null && !this.dependencies.has(referenceKey(key, pick.key))) {
607
+ this.add('deps.unknown', where.node.id, { path: `${key}.${PICK_VERB}(...)`, key: `${key}.${pick.key}`, keys: this.dependencyKnown(key), hint: dependencyHint(key, this.kindName) }, where.key);
608
+ }
609
+ }
610
+ }
611
+ /** `<deppicker key="cells" />` or `key="cells.microscope"`: declared dependencies. */
612
+ checkPicker(node) {
613
+ const written = node.props?.find(prop => prop.key === 'key')?.static_value;
614
+ if (typeof written !== 'string')
615
+ return; // catalog.props says a key is needed
616
+ const dot = written.indexOf('.');
617
+ const key = dot < 0 ? written : written.slice(0, dot);
618
+ const name = dot < 0 ? '' : written.slice(dot + 1);
619
+ const known = this.declared.has(key) && (!name || !this.typed(key) || this.dependencies.has(referenceKey(key, name)));
620
+ if (!known) {
621
+ this.add('deps.unknown', node.id, { path: `${node.component}.key`, key: written, keys: this.dependencyKnown(key), hint: dependencyHint(key, this.kindName) }, 'key');
622
+ }
623
+ }
624
+ /** `with <key>`: dependencies the blok declares, of the action that is called. */
625
+ checkWith(call, where) {
626
+ const given = call.given ?? '';
627
+ const action = actionKeyFor(call);
628
+ const declared = this.declared.get(given);
629
+ if (!declared) {
630
+ const keys = [...this.declared.keys()].sort().join(', ') || 'none';
631
+ this.add('deps.unknown', where.node.id, { path: `with ${given}`, key: given, keys, hint: dependencyHint(given, this.kindName) }, where.key);
632
+ return;
633
+ }
634
+ const target = dependenciesTarget(declared);
635
+ const of = dependenciesAction(declared);
636
+ if (target !== null && (target[0] !== call.dependency || target[1] !== action))
637
+ this.add('with.mismatch', where.node.id, { path: whereText(where), key: given, action, of }, where.key);
638
+ }
639
+ /** What `key` may read through, for a message: the dependencies declared under it, else the keys the blok declares. */
640
+ dependencyKnown(key) {
641
+ if (this.kindName !== 'agent' && !this.declared.has(key))
642
+ return [...this.dependencies.keys()].sort().join(', ') || 'none';
643
+ if (this.declared.has(key) && this.typed(key)) {
644
+ const prefix = `${key}${REFERENCE_SEPARATOR}`;
645
+ const names = [...this.dependencies.keys()].filter(name => name.startsWith(prefix)).map(name => `${key}.${name.slice(prefix.length)}`);
646
+ return names.sort().join(', ') || 'none';
647
+ }
648
+ return [...this.declared.keys()].sort().join(', ') || 'none';
649
+ }
426
650
  /** Queries and subscriptions are children of the `<Blok>`, each declared once and readable. */
427
651
  checkQueries(tree) {
428
652
  const first = new Map();
@@ -586,6 +810,8 @@ class Checker {
586
810
  if (spec)
587
811
  this.checkCatalog(node, spec, ancestors);
588
812
  this.checkHostPart(node, ancestors);
813
+ if (node.component === PICKER_COMPONENT)
814
+ this.checkPicker(node);
589
815
  for (const prop of node.props ?? [])
590
816
  this.checkProp(node, prop, spec, scope);
591
817
  }
@@ -700,7 +926,7 @@ class Checker {
700
926
  }
701
927
  // An effect that is a root's own (port.set) belongs to the kinds that read that root.
702
928
  const needs = effect === undefined ? null : (vocabulary.functions.get(effect)?.needs ?? null);
703
- if (effect !== undefined && needs !== null && !this.kind.roots.includes(needs)) {
929
+ if (effect !== undefined && needs !== null && !this.reads(needs)) {
704
930
  this.notInKind(node.id, effect, needs, prop.key);
705
931
  }
706
932
  if (prop.key === BIND_PROP) {
@@ -808,14 +1034,21 @@ class Checker {
808
1034
  return;
809
1035
  }
810
1036
  }
811
- else if (!this.kind.roots.includes('deps')) {
1037
+ else if (!this.reads('deps')) {
812
1038
  this.notInKind(where.node.id, `deps.${call.dependency}.${action}(...)`, 'deps', where.key);
813
1039
  return;
814
1040
  }
815
- const dependency = this.dependencies.get(call.dependency);
1041
+ if (call.given != null)
1042
+ this.checkWith(call, where);
1043
+ const dependency = this.undeclared(call.dependency) ? undefined : this.dependencies.get(call.dependency);
816
1044
  if (!dependency) {
817
- if (call.dependency !== 'self' && this.mounted) {
818
- this.add('deps.unknown', where.node.id, { path: owner, key: call.dependency, keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(call.dependency, this.kindName) }, where.key);
1045
+ const agent = this.declares(call.dependency);
1046
+ if (call.dependency !== 'self' && (agent ? this.undeclared(call.dependency) : this.mounted)) {
1047
+ // One the blok does not declare itself is the mount's, taken as it is keyed.
1048
+ const written = agent ? (splitReference(call.dependency)?.[0] ?? call.dependency) : call.dependency;
1049
+ const key = agent ? call.dependency.split(REFERENCE_SEPARATOR).join('.') : call.dependency;
1050
+ const keys = agent ? this.dependencyKnown(written) : [...this.dependencies.keys()].sort().join(', ') || 'none';
1051
+ this.add('deps.unknown', where.node.id, { path: owner, key, keys, hint: dependencyHint(written, this.kindName) }, where.key);
819
1052
  }
820
1053
  return;
821
1054
  }
@@ -872,6 +1105,8 @@ class Checker {
872
1105
  this.add('callback.nested', where.node.id, { what: call.operation }, where.key);
873
1106
  if (call.operation in VERBS && top)
874
1107
  this.checkQueryEffect(call, where);
1108
+ if (call.operation === PICK_FUNCTION)
1109
+ this.checkPick(call, where);
875
1110
  const keys = new Set((call.arguments ?? []).map(argument => argument.key).filter((key) => key != null));
876
1111
  const unknown = [...keys].filter(key => !fn.keys.includes(key) && !DIGITS.test(key)).sort();
877
1112
  if (unknown.length) {
@@ -1008,7 +1243,8 @@ class Checker {
1008
1243
  report('roots.unknown', { path, root: namespace ? `${root} (a function namespace)` : root });
1009
1244
  return null;
1010
1245
  }
1011
- if (!this.kind.roots.includes(root)) {
1246
+ // `agents` is how a custom blok writes `deps`: a stored tree never holds it.
1247
+ if (!this.reads(root) || root === AGENTS_ROOT) {
1012
1248
  this.notInKind(nodeId, path, root, propKey);
1013
1249
  return null;
1014
1250
  }
@@ -1024,9 +1260,24 @@ class Checker {
1024
1260
  report('roots.whole', { path, root: 'deps' });
1025
1261
  return null;
1026
1262
  }
1263
+ // An agent blok's dependencies are in its own tree (`cells.microscope`, stored
1264
+ // `deps.cells__microscope`): one it does not declare is unknown, mounted or not;
1265
+ // one it declares and this side cannot type is open.
1266
+ if (this.declares(rest[0]) && rest[0] !== 'self') {
1267
+ const split = splitReference(rest[0]);
1268
+ const key = split ? split[0] : rest[0];
1269
+ if (split && this.declared.has(key) && split[1] === OPTIONS_SEGMENT)
1270
+ return this.options(key, rest.slice(1), path, nodeId, propKey);
1271
+ if (this.undeclared(rest[0])) {
1272
+ report('deps.unknown', { path, key: split ? `${key}.${split[1]}` : rest[0], keys: this.dependencyKnown(key), hint: dependencyHint(key, this.kindName) });
1273
+ return null;
1274
+ }
1275
+ const found = this.dependencies.get(rest[0]);
1276
+ return found ? this.agent(found, rest[0], rest.slice(1), path, nodeId, propKey) : openMatch(path);
1277
+ }
1027
1278
  const dependency = this.dependencies.get(rest[0]);
1028
1279
  if (!dependency) {
1029
- if (!this.mounted)
1280
+ if (!this.mounted || this.declares(rest[0]))
1030
1281
  return openMatch(path);
1031
1282
  report('deps.unknown', { path, key: rest[0], keys: [...this.dependencies.keys()].sort().join(', ') || 'none', hint: dependencyHint(rest[0], this.kindName) });
1032
1283
  return null;
@@ -1275,7 +1526,8 @@ export const checkBlokTree = (tree, scope = unmountedBlokScope(), view = viewFor
1275
1526
  if (problem !== null)
1276
1527
  return [problem];
1277
1528
  const header = blokHeader(tree);
1278
- const checker = new Checker(header, scope, view, resolveLocals(tree, scope.dependencies, view));
1529
+ const bound = boundScope(tree, scope);
1530
+ const checker = new Checker(header, bound, view, resolveLocals(tree, bound.dependencies, view));
1279
1531
  checker.checkDeclarations(tree);
1280
1532
  checker.walk(tree);
1281
1533
  if (header.context === LOGO)