@astryxdesign/cli 0.7.2 → 0.7.3-canary.b1e1936

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 (154) hide show
  1. package/README.md +99 -66
  2. package/api/build/_adapter.d.mts +58 -0
  3. package/api/build/_adapter.mjs +115 -3
  4. package/api/build/blocks/blocks.d.mts +42 -0
  5. package/api/build/blocks/blocks.mjs +169 -0
  6. package/api/build/blocks/blocks.test.mjs +108 -0
  7. package/api/build/blocks/blocks.weights.json +1 -0
  8. package/api/build/build.mjs +25 -6
  9. package/api/build/kit/answer.d.mts +14 -0
  10. package/api/build/kit/answer.mjs +85 -0
  11. package/api/build/kit/answer.test.mjs +38 -0
  12. package/api/build/kit/kind.d.mts +25 -0
  13. package/api/build/kit/kind.mjs +170 -0
  14. package/api/build/kit/kit.d.mts +2 -4
  15. package/api/build/kit/kit.mjs +8 -398
  16. package/api/build/kit/rank.d.mts +3 -32
  17. package/api/build/kit/rank.mjs +25 -342
  18. package/api/build/kit/rank.test.mjs +2 -1
  19. package/api/build/kit/signals.d.mts +60 -0
  20. package/api/build/kit/signals.mjs +284 -0
  21. package/api/build/kit/start.d.mts +32 -0
  22. package/api/build/kit/start.mjs +163 -0
  23. package/api/build/kit/words.d.mts +72 -0
  24. package/api/build/kit/words.mjs +202 -0
  25. package/api/build/tree.d.mts +20 -0
  26. package/api/build/tree.mjs +52 -0
  27. package/api/build/tree.test.mjs +177 -0
  28. package/api/build/tree.weights.json +1 -0
  29. package/api/discover/_adapter.mjs +36 -9
  30. package/api/discover/_adapter.test.mjs +42 -0
  31. package/api/docs/_adapter.mjs +17 -5
  32. package/api/docs/docs.test.mjs +7 -1
  33. package/api/integration/authoring-checks.mjs +83 -9
  34. package/api/integration/pack-check.mjs +14 -1
  35. package/api/integration/pack-check.test.mjs +18 -0
  36. package/api/integration/validate-integration-case-disk.test.mjs +111 -0
  37. package/api/integration/validate-integration-gaps.test.mjs +1672 -0
  38. package/api/integration/validate-integration.d.mts +9 -1
  39. package/api/integration/validate-integration.mjs +216 -26
  40. package/api/integration/validate-integration.type.d.mts +57 -1
  41. package/api/integration/validate-integration.type.mjs +44 -2
  42. package/api/integration/validateIntegration.doc.mjs +1 -1
  43. package/api/search/ORDERING.md +28 -0
  44. package/api/search/_adapter.d.mts +66 -2
  45. package/api/search/_adapter.mjs +118 -10
  46. package/api/search/_candidate-score.d.mts +40 -0
  47. package/api/search/_candidate-score.mjs +238 -0
  48. package/api/search/_cards.json +6098 -0
  49. package/api/search/_compound.d.mts +50 -0
  50. package/api/search/_compound.mjs +170 -0
  51. package/api/search/_doc-searcher.d.mts +4 -0
  52. package/api/search/_doc-searcher.mjs +23 -0
  53. package/api/search/_doc-searcher.test.mjs +36 -0
  54. package/api/search/_doc-searcher.weights.json +1 -0
  55. package/api/search/_doc-text.d.mts +30 -0
  56. package/api/search/_doc-text.mjs +87 -0
  57. package/api/search/_entries.d.mts +52 -0
  58. package/api/search/_entries.mjs +158 -0
  59. package/api/search/_features.d.mts +35 -0
  60. package/api/search/_features.mjs +155 -0
  61. package/api/search/_gather-components.d.mts +26 -0
  62. package/api/search/_gather-components.mjs +284 -0
  63. package/api/search/_gather-docs.d.mts +20 -0
  64. package/api/search/_gather-docs.mjs +254 -0
  65. package/api/search/_gather-hooks.d.mts +12 -0
  66. package/api/search/_gather-hooks.mjs +52 -0
  67. package/api/search/_gather-templates.d.mts +25 -0
  68. package/api/search/_gather-templates.mjs +107 -0
  69. package/api/search/_lexical.d.mts +135 -0
  70. package/api/search/_lexical.mjs +351 -0
  71. package/api/search/_main-searcher.d.mts +19 -0
  72. package/api/search/_main-searcher.mjs +115 -0
  73. package/api/search/_main-searcher.test.mjs +106 -0
  74. package/api/search/_main-searcher.weights.json +1 -0
  75. package/api/search/_module-doc.d.mts +32 -0
  76. package/api/search/_module-doc.mjs +78 -0
  77. package/api/search/_order.d.mts +32 -0
  78. package/api/search/_order.mjs +162 -0
  79. package/api/search/_order.test.mjs +72 -0
  80. package/api/search/_priority.d.mts +50 -0
  81. package/api/search/_priority.mjs +139 -0
  82. package/api/search/_query-words.d.mts +25 -0
  83. package/api/search/_query-words.mjs +92 -0
  84. package/api/search/_query.d.mts +65 -0
  85. package/api/search/_query.mjs +176 -0
  86. package/api/search/_result.d.mts +97 -0
  87. package/api/search/_result.mjs +150 -0
  88. package/api/search/_score.d.mts +60 -0
  89. package/api/search/_score.mjs +283 -0
  90. package/api/search/_synonyms.d.mts +21 -0
  91. package/api/search/_synonyms.mjs +67 -0
  92. package/api/search/_template-searcher.d.mts +4 -0
  93. package/api/search/_template-searcher.mjs +23 -0
  94. package/api/search/_template-searcher.test.mjs +40 -0
  95. package/api/search/_template-searcher.weights.json +1 -0
  96. package/api/search/_titles.d.mts +33 -0
  97. package/api/search/_titles.mjs +65 -0
  98. package/api/search/_words.d.mts +64 -0
  99. package/api/search/_words.mjs +157 -0
  100. package/api/search/search.d.mts +22 -305
  101. package/api/search/search.doc.mjs +7 -5
  102. package/api/search/search.mjs +53 -2483
  103. package/api/search/search.type.d.mts +6 -1
  104. package/api/search/search.type.mjs +6 -1
  105. package/api/search/tree.d.mts +15 -0
  106. package/api/search/tree.mjs +40 -0
  107. package/api/search/tree.test.mjs +66 -0
  108. package/api/search/tree.weights.json +1 -0
  109. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +11 -0
  110. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +3 -3
  111. package/assets/docs/tree/api.doc.mjs +6 -0
  112. package/assets/docs/tree/host-entry.doc.mjs +128 -0
  113. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  114. package/authoring/debug/parse.d.mts +1 -1
  115. package/clients/cli/bin/astryx.mjs +7 -78
  116. package/clients/cli/commands/doctor.mjs +30 -0
  117. package/clients/cli/run.mjs +108 -0
  118. package/foundation/config/project.mjs +15 -2
  119. package/foundation/discovery/component-discovery.d.mts +37 -0
  120. package/foundation/discovery/component-discovery.mjs +80 -5
  121. package/foundation/discovery/component-loader.d.mts +1 -1
  122. package/foundation/discovery/docs-discovery.mjs +14 -1
  123. package/foundation/discovery/module-exports.d.mts +41 -0
  124. package/foundation/discovery/module-exports.mjs +253 -0
  125. package/foundation/doc-compiler/doc-loads.test.mjs +4 -0
  126. package/foundation/fs/paths.mjs +30 -3
  127. package/foundation/integrations/computer-integrations.d.mts +6 -3
  128. package/foundation/integrations/computer-integrations.mjs +38 -9
  129. package/foundation/integrations/contribution-inventory.d.mts +15 -20
  130. package/foundation/integrations/contribution-inventory.mjs +41 -5
  131. package/foundation/integrations/integrations.d.mts +7 -0
  132. package/foundation/integrations/integrations.mjs +2 -0
  133. package/foundation/integrations/validate-contributions.d.mts +96 -0
  134. package/foundation/integrations/validate-contributions.mjs +996 -10
  135. package/foundation/release/handoff.d.mts +23 -4
  136. package/foundation/release/handoff.mjs +175 -8
  137. package/foundation/release/run-context.mjs +14 -0
  138. package/foundation/response/response-types.doc.mjs +1 -1
  139. package/foundation/route/route.d.mts +285 -0
  140. package/foundation/route/route.mjs +324 -0
  141. package/foundation/route/route.test.mjs +153 -0
  142. package/foundation/runtime/hosted-runtime.test.mjs +403 -0
  143. package/foundation/runtime/locked-versions.d.mts +32 -0
  144. package/foundation/runtime/locked-versions.mjs +65 -0
  145. package/foundation/runtime/package-root.d.mts +91 -0
  146. package/foundation/runtime/package-root.mjs +174 -0
  147. package/foundation/runtime/package-set.d.mts +62 -0
  148. package/foundation/runtime/package-set.mjs +130 -0
  149. package/foundation/runtime/package-set.test.mjs +432 -0
  150. package/host/door-conformance.test.mjs +274 -0
  151. package/host/index.d.ts +116 -0
  152. package/host/index.mjs +295 -0
  153. package/host/index.test.mjs +302 -0
  154. package/package.json +14 -9
@@ -118,6 +118,16 @@ function scanDocText(text) {
118
118
  };
119
119
  }
120
120
 
121
+ /**
122
+ * Whether a component doc is hidden (`hidden: true`), read as discovery
123
+ * reads it: discovery skips a hidden doc.
124
+ * @param {string} docPath
125
+ * @returns {boolean}
126
+ */
127
+ export function isHiddenComponentDoc(docPath) {
128
+ return readDocMeta(docPath).hidden;
129
+ }
130
+
121
131
  /**
122
132
  * Read the `group`, `hiddenComponents`, and `hidden` fields from a
123
133
  * component's .doc.mjs file (synchronous), with what {@link scanDocText}
@@ -994,7 +1004,7 @@ function packageMain(packageDir) {
994
1004
  * @param {Record<string, any> | null} doc
995
1005
  * @returns {string | null | undefined}
996
1006
  */
997
- function importedModule(integration, docPath, doc) {
1007
+ export function importedModule(integration, docPath, doc) {
998
1008
  const packageName = integration?.name;
999
1009
  const packageDir = integration?.__packageDir;
1000
1010
  if (!packageName || !packageDir) return undefined;
@@ -1024,6 +1034,42 @@ function importedModule(integration, docPath, doc) {
1024
1034
  ).target;
1025
1035
  }
1026
1036
 
1037
+ /**
1038
+ * The file an import of the package's own name resolves to, through its
1039
+ * package.json `exports` (or `main` when it has none): `@acme/kit` or
1040
+ * `@acme/kit/widget`. Null when the specifier names another package, or the
1041
+ * package publishes nothing at it.
1042
+ * @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown> | null}} integration
1043
+ * @param {string} specifier
1044
+ * @returns {string | null}
1045
+ */
1046
+ export function ownPackageModule(integration, specifier) {
1047
+ const packageName = integration?.name;
1048
+ const packageDir = integration?.__packageDir;
1049
+ if (!packageName || !packageDir) return null;
1050
+ if (specifier !== packageName && !specifier.startsWith(`${packageName}/`)) {
1051
+ return null;
1052
+ }
1053
+ const exportsMap =
1054
+ integration.__packageExports === undefined
1055
+ ? readPackageExports(packageDir)
1056
+ : integration.__packageExports;
1057
+ if (specifier === packageName && exportsMap == null) {
1058
+ return packageMain(packageDir) ?? null;
1059
+ }
1060
+ const subpath =
1061
+ specifier === packageName
1062
+ ? '.'
1063
+ : `./${specifier.slice(packageName.length + 1)}`;
1064
+ return (
1065
+ inspectPackageExport(
1066
+ {name: packageName, exports: exportsMap ?? undefined},
1067
+ packageDir,
1068
+ subpath,
1069
+ ).target ?? null
1070
+ );
1071
+ }
1072
+
1027
1073
  /**
1028
1074
  * Whether `file` sits in `folder` or below it.
1029
1075
  * @param {string} folder
@@ -1211,6 +1257,19 @@ export function integrationMemberEntry(doc, record) {
1211
1257
  );
1212
1258
  }
1213
1259
 
1260
+ /**
1261
+ * Whether `dir` is a folder to list. A declared root that is a file is
1262
+ * reported by the root check; discovery finds nothing in it.
1263
+ * @param {string} dir
1264
+ */
1265
+ function isFolder(dir) {
1266
+ try {
1267
+ return fs.statSync(dir).isDirectory();
1268
+ } catch {
1269
+ return false;
1270
+ }
1271
+ }
1272
+
1214
1273
  /**
1215
1274
  * Visit every component doc under an integration's components root, hidden
1216
1275
  * ones included, in discovery order, with its stem.
@@ -1218,10 +1277,26 @@ export function integrationMemberEntry(doc, record) {
1218
1277
  * @param {(docPath: string, stem: string) => void} visit
1219
1278
  */
1220
1279
  export function forEachIntegrationDoc(componentsDir, visit) {
1221
- if (!componentsDir || !pathExists(componentsDir)) return;
1280
+ if (!componentsDir || !isFolder(componentsDir)) return;
1281
+ /** @param {string} name */
1282
+ const key = name => {
1283
+ const rank = INTEGRATION_DOC_SUFFIXES.findIndex(s => name.endsWith(s));
1284
+ return rank < 0
1285
+ ? {stem: name, rank}
1286
+ : {stem: name.slice(0, -INTEGRATION_DOC_SUFFIXES[rank].length), rank};
1287
+ };
1222
1288
  /** @param {string} dirPath */
1223
1289
  function scanDir(dirPath) {
1224
- for (const entry of listDirEntries(dirPath)) {
1290
+ // Name order, and for two docs of one stem the suffix precedence, so the
1291
+ // doc a stem records is the one a lookup by name finds, on every disk.
1292
+ const entries = listDirEntries(dirPath).sort((a, b) => {
1293
+ const left = key(a.name);
1294
+ const right = key(b.name);
1295
+ return left.stem === right.stem
1296
+ ? left.rank - right.rank
1297
+ : byCodeUnit(left.stem, right.stem);
1298
+ });
1299
+ for (const entry of entries) {
1225
1300
  if (entry.name === 'node_modules' || entry.name === '__tests__') continue;
1226
1301
  const fullPath = path.join(dirPath, entry.name);
1227
1302
  if (entry.isDirectory()) {
@@ -1270,7 +1345,7 @@ export function discoverIntegrationComponents(
1270
1345
  {documentedNames = true} = {},
1271
1346
  ) {
1272
1347
  const componentsDir = integration?.components;
1273
- if (!componentsDir || !pathExists(componentsDir)) return [];
1348
+ if (!componentsDir || !isFolder(componentsDir)) return [];
1274
1349
 
1275
1350
  /** @type {Map<string, {name: string, package: string, docPath: string, sourcePath: string|null, issuesUrl: string|undefined, group: string|null}>} */
1276
1351
  const byName = new Map();
@@ -1485,7 +1560,7 @@ function findDocumentedComponent(integration, componentsDir, name) {
1485
1560
  */
1486
1561
  export function findIntegrationComponent(integration, name) {
1487
1562
  const componentsDir = integration?.components;
1488
- if (!componentsDir || !pathExists(componentsDir)) return null;
1563
+ if (!componentsDir || !isFolder(componentsDir)) return null;
1489
1564
  const sameStem = findSameStemDoc(componentsDir, name);
1490
1565
  if (sameStem) {
1491
1566
  const exportName = otherExportName({
@@ -43,5 +43,5 @@ export type LoadDocOptions = {
43
43
  * which root reads the doc
44
44
  * (default: components)
45
45
  */
46
- root?: "hooks" | "components" | undefined;
46
+ root?: "components" | "hooks" | undefined;
47
47
  };
@@ -423,6 +423,19 @@ export function problemsInNamespace(doc) {
423
423
  return problems;
424
424
  }
425
425
 
426
+ /**
427
+ * Whether `dir` is a folder to list. A declared root that is a file is
428
+ * reported by the root check; discovery finds nothing in it.
429
+ * @param {string} dir
430
+ */
431
+ function isFolder(dir) {
432
+ try {
433
+ return fs.statSync(dir).isDirectory();
434
+ } catch {
435
+ return false;
436
+ }
437
+ }
438
+
426
439
  /**
427
440
  * Discover the topics contributed by a single loaded integration. Mirrors
428
441
  * `discoverIntegrationComponents`: walk the resolved root, take every
@@ -450,7 +463,7 @@ export async function discoverIntegrationDocs(integration) {
450
463
  const namespaces = [];
451
464
  /** @type {import('../doc-compiler/tree.mjs').TreeDocInput[]} */
452
465
  const guides = [];
453
- if (!docsDir || !fs.existsSync(docsDir)) {
466
+ if (!docsDir || !isFolder(docsDir)) {
454
467
  return {records, errors, namespaces, guides};
455
468
  }
456
469
  const providerId = integration.providerId ?? integration.name;
@@ -18,6 +18,39 @@ export function moduleExportsName(file: string, exportName: string, seen?: Set<s
18
18
  * @returns {string | null}
19
19
  */
20
20
  export function moduleExportSource(file: string, exportName: string, seen?: Set<string>): string | null;
21
+ /**
22
+ * Every runtime name a module exports that this read can see (`default` for
23
+ * a default export), or null when it cannot see them all: an `export *`, `export =`, CommonJS exports, or a
24
+ * file that does not parse.
25
+ * @param {string} file
26
+ * @returns {string[] | null}
27
+ */
28
+ export function moduleExportNames(file: string): string[] | null;
29
+ /**
30
+ * @typedef {{verdict: 'exports'} | {verdict: 'lacks'} | {verdict: 'unknown', reason: string}} ExportVerdict
31
+ */
32
+ /**
33
+ * Whether a module exports `exportName` at runtime, read without executing
34
+ * it: `exports` when a declaration or a followed re-export binds it, `lacks`
35
+ * only when every export the module writes was read and none binds it, and
36
+ * `unknown`, with the first reason, when some export could not be read: a
37
+ * re-export from another package or from a specifier that resolves to no
38
+ * file, a destructured binding, a namespace, an ambient or const enum
39
+ * declaration, `export =`, CommonJS exports, or a file that does not parse.
40
+ * @param {string} file
41
+ * @param {string} exportName
42
+ * @param {Set<string>} [seen]
43
+ * @returns {ExportVerdict}
44
+ */
45
+ export function moduleExportVerdict(file: string, exportName: string, seen?: Set<string>): ExportVerdict;
46
+ /**
47
+ * Whether a module provably does not export `exportName` at runtime: see
48
+ * {@link moduleExportVerdict}.
49
+ * @param {string} file
50
+ * @param {string} exportName
51
+ * @returns {boolean}
52
+ */
53
+ export function moduleLacksExport(file: string, exportName: string): boolean;
21
54
  /**
22
55
  * The object a module exports, as plain data, read without running it: the
23
56
  * first of `exportNames` it exports, an object literal in place or a top-level
@@ -35,3 +68,11 @@ export function staticExportObject(file: string, exportNames: readonly string[])
35
68
  * enumerable, so the object compares and serializes as its literal properties.
36
69
  */
37
70
  export const HAS_COMPUTED: unique symbol;
71
+ export type ExportVerdict = {
72
+ verdict: "exports";
73
+ } | {
74
+ verdict: "lacks";
75
+ } | {
76
+ verdict: "unknown";
77
+ reason: string;
78
+ };
@@ -309,6 +309,259 @@ export function moduleExportSource(file, exportName, seen = new Set()) {
309
309
  return found;
310
310
  }
311
311
 
312
+ /**
313
+ * The module's own top-level statements of one type: an `export` inside a
314
+ * TypeScript namespace names a member of that namespace, not of the module.
315
+ * @param {any} program
316
+ * @param {string} type
317
+ * @returns {any[]}
318
+ */
319
+ function topLevel(program, type) {
320
+ return program.body.filter((/** @type {any} */ node) => node.type === type);
321
+ }
322
+
323
+ /**
324
+ * Every runtime name a module exports that this read can see (`default` for
325
+ * a default export), or null when it cannot see them all: an `export *`, `export =`, CommonJS exports, or a
326
+ * file that does not parse.
327
+ * @param {string} file
328
+ * @returns {string[] | null}
329
+ */
330
+ export function moduleExportNames(file) {
331
+ let text;
332
+ let ast;
333
+ try {
334
+ if (!fs.statSync(file).isFile()) return null;
335
+ text = moduleText(file);
336
+ ast = parseModule(file);
337
+ } catch {
338
+ return null;
339
+ }
340
+ if (/\bmodule\.exports\b|\bexports\.[$\w]/u.test(text)) return null;
341
+ if (
342
+ topLevel(ast.program, 'TSExportAssignment').length > 0 ||
343
+ topLevel(ast.program, 'ExportAllDeclaration').length > 0
344
+ ) {
345
+ return null;
346
+ }
347
+ /** @type {Set<string>} */
348
+ const names = new Set();
349
+ for (const node of topLevel(ast.program, 'TSImportEqualsDeclaration')) {
350
+ if (!node.isExport) continue;
351
+ // A type-only alias has no runtime value; any other might.
352
+ if (node.importKind === 'type') continue;
353
+ if (typeof node.id?.name !== 'string') return null;
354
+ names.add(node.id.name);
355
+ }
356
+ for (const node of topLevel(ast.program, 'ExportNamedDeclaration')) {
357
+ if (node.exportKind === 'type') continue;
358
+ const declaration = node.declaration;
359
+ if (declaration?.type === 'VariableDeclaration') {
360
+ for (const item of declaration.declarations) {
361
+ if (item.id?.type !== 'Identifier') return null;
362
+ names.add(item.id.name);
363
+ }
364
+ } else if (declaration != null) {
365
+ if (!runtimeDefault(declaration)) continue;
366
+ if (typeof declaration.id?.name !== 'string') return null;
367
+ names.add(declaration.id.name);
368
+ }
369
+ for (const specifier of node.specifiers ?? []) {
370
+ if (specifier.exportKind === 'type') continue;
371
+ const exported = specifier.exported?.name ?? specifier.exported?.value;
372
+ if (typeof exported === 'string') names.add(exported);
373
+ }
374
+ }
375
+ if (
376
+ topLevel(ast.program, 'ExportDefaultDeclaration').some(
377
+ (/** @type {any} */ node) => runtimeDefault(node.declaration),
378
+ )
379
+ ) {
380
+ names.add('default');
381
+ }
382
+ return [...names].sort();
383
+ }
384
+
385
+ /**
386
+ * @typedef {{verdict: 'exports'} | {verdict: 'lacks'} | {verdict: 'unknown', reason: string}} ExportVerdict
387
+ */
388
+
389
+ /**
390
+ * Whether a module exports `exportName` at runtime, read without executing
391
+ * it: `exports` when a declaration or a followed re-export binds it, `lacks`
392
+ * only when every export the module writes was read and none binds it, and
393
+ * `unknown`, with the first reason, when some export could not be read: a
394
+ * re-export from another package or from a specifier that resolves to no
395
+ * file, a destructured binding, a namespace, an ambient or const enum
396
+ * declaration, `export =`, CommonJS exports, or a file that does not parse.
397
+ * @param {string} file
398
+ * @param {string} exportName
399
+ * @param {Set<string>} [seen]
400
+ * @returns {ExportVerdict}
401
+ */
402
+ export function moduleExportVerdict(file, exportName, seen = new Set()) {
403
+ const identity = `${file}\0${exportName}`;
404
+ // A cycle adds nothing a module's own exports have not already said.
405
+ if (seen.has(identity)) return {verdict: 'lacks'};
406
+ seen.add(identity);
407
+ const shown = path.basename(file);
408
+ let text;
409
+ let ast;
410
+ try {
411
+ if (!fs.statSync(file).isFile()) {
412
+ return {verdict: 'unknown', reason: `${shown} is not a file.`};
413
+ }
414
+ text = moduleText(file);
415
+ ast = parseModule(file);
416
+ } catch {
417
+ return {
418
+ verdict: 'unknown',
419
+ reason: `${shown} could not be read or parsed.`,
420
+ };
421
+ }
422
+ /** @type {string[]} */
423
+ const unknown = [];
424
+ if (/\bmodule\.exports\b|\bexports\.[$\w]/u.test(text)) {
425
+ unknown.push(
426
+ `${shown} uses CommonJS exports, whose names this check does not read.`,
427
+ );
428
+ }
429
+ if (topLevel(ast.program, 'TSExportAssignment').length > 0) {
430
+ unknown.push(`${shown} uses \`export =\`, whose names this check does not read.`);
431
+ }
432
+ /**
433
+ * Follow a re-export of `imported` from `specifier`.
434
+ * @param {string} specifier
435
+ * @param {string} imported
436
+ * @param {string} what how the reason names what is re-exported
437
+ * @returns {boolean} true when it proves the export
438
+ */
439
+ const follow = (specifier, imported, what) => {
440
+ if (!specifier.startsWith('.')) {
441
+ unknown.push(
442
+ `${shown} re-exports ${what} from "${specifier}", another package this check does not read.`,
443
+ );
444
+ return false;
445
+ }
446
+ const target = resolveLocalModule(specifier, file);
447
+ if (!target) {
448
+ unknown.push(
449
+ `${shown} re-exports ${what} from "${specifier}", which resolves to no file this check can read.`,
450
+ );
451
+ return false;
452
+ }
453
+ const inner = moduleExportVerdict(target, imported, seen);
454
+ if (inner.verdict === 'exports') return true;
455
+ if (inner.verdict === 'unknown') unknown.push(inner.reason);
456
+ return false;
457
+ };
458
+ // `export import Name = Some.Path;` binds a runtime value unless it is
459
+ // type-only.
460
+ for (const node of topLevel(ast.program, 'TSImportEqualsDeclaration')) {
461
+ if (!node.isExport || node.id?.name !== exportName) continue;
462
+ if (node.importKind === 'type') {
463
+ unknown.push(
464
+ `${shown} exports ${exportName} with \`export import type\`, which has no runtime value this check can see.`,
465
+ );
466
+ } else {
467
+ return {verdict: 'exports'};
468
+ }
469
+ }
470
+ for (const node of topLevel(ast.program, 'ExportNamedDeclaration')) {
471
+ if (node.exportKind === 'type') continue;
472
+ const declaration = node.declaration;
473
+ if (declaration?.type === 'VariableDeclaration') {
474
+ for (const item of declaration.declarations) {
475
+ if (item.id?.type !== 'Identifier') {
476
+ unknown.push(
477
+ `${shown} exports a destructured binding, whose names this check does not read.`,
478
+ );
479
+ } else if (item.id.name === exportName) {
480
+ if (declaration.declare === true) {
481
+ unknown.push(
482
+ `${shown} declares ${exportName} with \`declare\`, which has no runtime value this check can see.`,
483
+ );
484
+ } else {
485
+ return {verdict: 'exports'};
486
+ }
487
+ }
488
+ }
489
+ } else if (declaration != null && declaration.id?.name === exportName) {
490
+ if (
491
+ ['TSInterfaceDeclaration', 'TSTypeAliasDeclaration'].includes(
492
+ declaration.type,
493
+ )
494
+ ) {
495
+ // A type only: no runtime export.
496
+ } else if (declaration.type === 'TSModuleDeclaration') {
497
+ unknown.push(
498
+ `${shown} exports ${exportName} as a TypeScript namespace, which has a runtime value only when it holds one.`,
499
+ );
500
+ } else if (declaration.declare === true || declaration.const === true) {
501
+ unknown.push(
502
+ `${shown} declares ${exportName} as an ambient or const declaration, which has no runtime value this check can see.`,
503
+ );
504
+ } else if (runtimeDefault(declaration)) {
505
+ return {verdict: 'exports'};
506
+ }
507
+ }
508
+ for (const specifier of node.specifiers ?? []) {
509
+ if (specifier.exportKind === 'type') continue;
510
+ const exported = specifier.exported?.name ?? specifier.exported?.value;
511
+ if (exported !== exportName) continue;
512
+ if (!node.source || specifier.type === 'ExportNamespaceSpecifier') {
513
+ return {verdict: 'exports'};
514
+ }
515
+ if (specifier.type !== 'ExportSpecifier') {
516
+ unknown.push(`${shown} re-exports ${exportName} in a form this check does not read.`);
517
+ continue;
518
+ }
519
+ const imported =
520
+ specifier.local?.name ?? specifier.local?.value ?? exportName;
521
+ if (follow(String(node.source.value), imported, exportName)) {
522
+ return {verdict: 'exports'};
523
+ }
524
+ }
525
+ }
526
+ if (exportName === 'default') {
527
+ const defaults = topLevel(ast.program, 'ExportDefaultDeclaration');
528
+ if (
529
+ defaults.some((/** @type {any} */ node) =>
530
+ runtimeDefault(node.declaration),
531
+ )
532
+ ) {
533
+ return {verdict: 'exports'};
534
+ }
535
+ }
536
+ for (const node of topLevel(ast.program, 'ExportAllDeclaration')) {
537
+ if (node.exportKind === 'type') continue;
538
+ const exported = node.exported?.name ?? node.exported?.value;
539
+ if (exported != null) {
540
+ if (exported === exportName) return {verdict: 'exports'};
541
+ continue;
542
+ }
543
+ // `export *` never re-exports a default.
544
+ if (exportName === 'default') continue;
545
+ if (follow(String(node.source?.value ?? ''), exportName, 'everything')) {
546
+ return {verdict: 'exports'};
547
+ }
548
+ }
549
+ return unknown.length > 0
550
+ ? {verdict: 'unknown', reason: unknown[0]}
551
+ : {verdict: 'lacks'};
552
+ }
553
+
554
+ /**
555
+ * Whether a module provably does not export `exportName` at runtime: see
556
+ * {@link moduleExportVerdict}.
557
+ * @param {string} file
558
+ * @param {string} exportName
559
+ * @returns {boolean}
560
+ */
561
+ export function moduleLacksExport(file, exportName) {
562
+ return moduleExportVerdict(file, exportName).verdict === 'lacks';
563
+ }
564
+
312
565
  /**
313
566
  * Marks an object {@link staticExportObject} returns (or one inside it) whose
314
567
  * source also has properties or spreads it could not read as literals. Not
@@ -339,6 +339,10 @@ const RUNNERS = {
339
339
  runs: "the CLI release that answers a project's run, when it is not this copy",
340
340
  sites: ['child_process.spawn'],
341
341
  },
342
+ 'host/index.mjs': {
343
+ runs: "another release's host entry, from one of the host's package sets, when that release answers a hosted run",
344
+ sites: ['import(<computed>)'],
345
+ },
342
346
  'scripts/generate-cli-readme.mjs': {
343
347
  runs: '`astryx manifest` and the error-code and response-type docs, to write the README tables (build time, not shipped)',
344
348
  sites: ['child_process.spawnSync', 'import(<computed>)'],
@@ -14,6 +14,7 @@ import {listDir, pathExists} from './listing-cache.mjs';
14
14
  import {ERROR_CODES} from '../response/error-codes.mjs';
15
15
  import {carriedCore, runChoice} from '../release/run-context.mjs';
16
16
  import {findDeclaringPackage} from '../release/project.mjs';
17
+ import {hostedRun, recordResolved} from '../runtime/package-root.mjs';
17
18
 
18
19
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
20
 
@@ -35,7 +36,33 @@ export const CLI_ROOT = path.resolve(__dirname, '..', '..');
35
36
  * @returns {string | null}
36
37
  */
37
38
  export function findCoreDir(startDir = process.cwd()) {
38
- return findProjectCoreDir(startDir) ?? carriedCoreFor(startDir).dir;
39
+ const own = findProjectCoreDir(startDir);
40
+ return own
41
+ ? noteCore(own, 'project')
42
+ : noteCore(carriedCoreFor(startDir).dir);
43
+ }
44
+
45
+ /**
46
+ * Note the Core a hosted run reads, for the record its host entry returns
47
+ * (architecture:cli-surface INV30). Does nothing outside a hosted run.
48
+ * @template {string | null} T
49
+ * @param {T} dir
50
+ * @param {'project'} [source] where it came from, when the caller knows
51
+ * @returns {T}
52
+ */
53
+ function noteCore(dir, source) {
54
+ if (dir && hostedRun()) {
55
+ let version;
56
+ try {
57
+ version = JSON.parse(
58
+ fs.readFileSync(path.join(dir, 'package.json'), 'utf8'),
59
+ ).version;
60
+ } catch {
61
+ version = null;
62
+ }
63
+ recordResolved('@astryxdesign/core', version, dir, source);
64
+ }
65
+ return dir;
39
66
  }
40
67
 
41
68
  /**
@@ -67,14 +94,14 @@ export function unavailableCoreMessage(found, inProject) {
67
94
  */
68
95
  export function requireCoreDir(startDir = process.cwd()) {
69
96
  const found = findProjectCoreDir(startDir) ?? carriedCoreFor(startDir, true);
70
- if (typeof found === 'string') return found;
97
+ if (typeof found === 'string') return noteCore(found, 'project');
71
98
  if (found.unavailable) {
72
99
  throw codedError(
73
100
  unavailableCoreMessage(found, runChoice(startDir).inProject),
74
101
  ERROR_CODES.ERR_VERSIONS_UNAVAILABLE,
75
102
  );
76
103
  }
77
- if (found.dir) return found.dir;
104
+ if (found.dir) return noteCore(found.dir);
78
105
  throw codedError(
79
106
  'Could not find @astryxdesign/core package',
80
107
  ERROR_CODES.ERR_CORE_NOT_FOUND,
@@ -34,15 +34,18 @@ export function computerInstallRoots(cliRoot: string, options?: {
34
34
  export function peerProblem(pkg: Record<string, any>, release: string): string | null;
35
35
  /**
36
36
  * The computer-level integrations installed beside the CLI at `cliRoot`, in
37
- * name order (declaration order when the root declares them). Reads
37
+ * name order (declaration order when the root declares them), then each
38
+ * integration a host approves (`approved`, architecture:cli-surface INV30),
39
+ * resolved by name from the package set that holds that CLI alone. Reads
38
40
  * package.json files only.
39
- * @param {{cliRoot: string, release: string, cacheDir?: string}} options
41
+ * @param {{cliRoot: string, release: string, cacheDir?: string, approved?: readonly string[]}} options
40
42
  * @returns {ComputerIntegrationCandidate[]}
41
43
  */
42
- export function scanComputerIntegrations({ cliRoot, release, cacheDir }: {
44
+ export function scanComputerIntegrations({ cliRoot, release, cacheDir, approved, }: {
43
45
  cliRoot: string;
44
46
  release: string;
45
47
  cacheDir?: string;
48
+ approved?: readonly string[];
46
49
  }): ComputerIntegrationCandidate[];
47
50
  /**
48
51
  * Load the compatible computer-level integrations as provider candidates,
@@ -225,12 +225,19 @@ export function peerProblem(pkg, release) {
225
225
 
226
226
  /**
227
227
  * The computer-level integrations installed beside the CLI at `cliRoot`, in
228
- * name order (declaration order when the root declares them). Reads
228
+ * name order (declaration order when the root declares them), then each
229
+ * integration a host approves (`approved`, architecture:cli-surface INV30),
230
+ * resolved by name from the package set that holds that CLI alone. Reads
229
231
  * package.json files only.
230
- * @param {{cliRoot: string, release: string, cacheDir?: string}} options
232
+ * @param {{cliRoot: string, release: string, cacheDir?: string, approved?: readonly string[]}} options
231
233
  * @returns {ComputerIntegrationCandidate[]}
232
234
  */
233
- export function scanComputerIntegrations({cliRoot, release, cacheDir}) {
235
+ export function scanComputerIntegrations({
236
+ cliRoot,
237
+ release,
238
+ cacheDir,
239
+ approved = [],
240
+ }) {
234
241
  const self = real(cliRoot);
235
242
  /** @type {ComputerIntegrationCandidate[]} */
236
243
  const found = [];
@@ -238,21 +245,43 @@ export function scanComputerIntegrations({cliRoot, release, cacheDir}) {
238
245
  for (const root of computerInstallRoots(cliRoot, {cacheDir})) {
239
246
  scanRoot(root, {self, release, found, seen});
240
247
  }
248
+ const owner = approved.length > 0 ? installPlaceOf(self).owner : null;
249
+ if (owner) scanRoot(owner, {self, release, found, seen}, approved);
241
250
  return found;
242
251
  }
243
252
 
244
253
  /**
245
- * Add the integrations installed in one install root.
254
+ * `name` as installed in `root`'s own `node_modules`, never in a folder above.
255
+ * @param {string} name
256
+ * @param {string} root
257
+ * @returns {{packageDir: string, hostDir: string} | null}
258
+ */
259
+ function ownPackageDir(name, root) {
260
+ const packageDir = path.join(root, 'node_modules', ...name.split('/'));
261
+ return fs.existsSync(path.join(packageDir, 'package.json'))
262
+ ? {packageDir, hostDir: root}
263
+ : null;
264
+ }
265
+
266
+ /**
267
+ * Add the integrations installed in one install root: those it declares or
268
+ * installs, or, given `approved`, those names installed in its own
269
+ * `node_modules`.
246
270
  * @param {string} root
247
271
  * @param {{self: string, release: string, found: ComputerIntegrationCandidate[], seen: Set<string>}} into
272
+ * @param {readonly string[] | null} [approved]
248
273
  */
249
- function scanRoot(root, {self, release, found, seen}) {
250
- const declared = readPackage(root)
251
- ? readDeclaredDependencies(root).map(d => d.name)
252
- : installedNames(root);
274
+ function scanRoot(root, {self, release, found, seen}, approved = null) {
275
+ const declared =
276
+ approved ??
277
+ (readPackage(root)
278
+ ? readDeclaredDependencies(root).map(d => d.name)
279
+ : installedNames(root));
253
280
  for (const name of declared) {
254
281
  if (NOT_INTEGRATIONS.has(name)) continue;
255
- const resolved = resolveInstalledPackageDir(name, root);
282
+ const resolved = approved
283
+ ? ownPackageDir(name, root)
284
+ : resolveInstalledPackageDir(name, root);
256
285
  if (!resolved) continue;
257
286
  const identity = real(resolved.packageDir);
258
287
  if (identity === self || seen.has(identity)) continue;