@astryxdesign/cli 0.7.2 → 0.7.3-canary.1379cb7

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 (181) 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/doctor/doctor.mjs +86 -12
  34. package/api/init/init.doc.mjs +20 -6
  35. package/api/init/init.test.mjs +18 -2
  36. package/api/init/init.type.d.mts +3 -3
  37. package/api/init/init.type.mjs +3 -3
  38. package/api/init/remove/remove.mjs +17 -4
  39. package/api/init/remove/remove.test.mjs +114 -2
  40. package/api/init/run/run.mjs +69 -6
  41. package/api/integration/authoring-checks.mjs +83 -9
  42. package/api/integration/pack-check.mjs +14 -1
  43. package/api/integration/pack-check.test.mjs +18 -0
  44. package/api/integration/validate-integration-case-disk.test.mjs +111 -0
  45. package/api/integration/validate-integration-gaps.test.mjs +1672 -0
  46. package/api/integration/validate-integration.d.mts +9 -1
  47. package/api/integration/validate-integration.mjs +216 -26
  48. package/api/integration/validate-integration.type.d.mts +57 -1
  49. package/api/integration/validate-integration.type.mjs +44 -2
  50. package/api/integration/validateIntegration.doc.mjs +1 -1
  51. package/api/search/ORDERING.md +28 -0
  52. package/api/search/_adapter.d.mts +66 -2
  53. package/api/search/_adapter.mjs +118 -10
  54. package/api/search/_candidate-score.d.mts +40 -0
  55. package/api/search/_candidate-score.mjs +238 -0
  56. package/api/search/_cards.json +6098 -0
  57. package/api/search/_compound.d.mts +50 -0
  58. package/api/search/_compound.mjs +170 -0
  59. package/api/search/_doc-searcher.d.mts +4 -0
  60. package/api/search/_doc-searcher.mjs +23 -0
  61. package/api/search/_doc-searcher.test.mjs +36 -0
  62. package/api/search/_doc-searcher.weights.json +1 -0
  63. package/api/search/_doc-text.d.mts +30 -0
  64. package/api/search/_doc-text.mjs +87 -0
  65. package/api/search/_entries.d.mts +52 -0
  66. package/api/search/_entries.mjs +158 -0
  67. package/api/search/_features.d.mts +35 -0
  68. package/api/search/_features.mjs +155 -0
  69. package/api/search/_gather-components.d.mts +26 -0
  70. package/api/search/_gather-components.mjs +284 -0
  71. package/api/search/_gather-docs.d.mts +20 -0
  72. package/api/search/_gather-docs.mjs +254 -0
  73. package/api/search/_gather-hooks.d.mts +12 -0
  74. package/api/search/_gather-hooks.mjs +52 -0
  75. package/api/search/_gather-templates.d.mts +25 -0
  76. package/api/search/_gather-templates.mjs +107 -0
  77. package/api/search/_lexical.d.mts +135 -0
  78. package/api/search/_lexical.mjs +351 -0
  79. package/api/search/_main-searcher.d.mts +19 -0
  80. package/api/search/_main-searcher.mjs +115 -0
  81. package/api/search/_main-searcher.test.mjs +106 -0
  82. package/api/search/_main-searcher.weights.json +1 -0
  83. package/api/search/_module-doc.d.mts +32 -0
  84. package/api/search/_module-doc.mjs +78 -0
  85. package/api/search/_order.d.mts +32 -0
  86. package/api/search/_order.mjs +162 -0
  87. package/api/search/_order.test.mjs +72 -0
  88. package/api/search/_priority.d.mts +50 -0
  89. package/api/search/_priority.mjs +139 -0
  90. package/api/search/_query-words.d.mts +25 -0
  91. package/api/search/_query-words.mjs +92 -0
  92. package/api/search/_query.d.mts +65 -0
  93. package/api/search/_query.mjs +176 -0
  94. package/api/search/_result.d.mts +97 -0
  95. package/api/search/_result.mjs +150 -0
  96. package/api/search/_score.d.mts +60 -0
  97. package/api/search/_score.mjs +283 -0
  98. package/api/search/_synonyms.d.mts +21 -0
  99. package/api/search/_synonyms.mjs +67 -0
  100. package/api/search/_template-searcher.d.mts +4 -0
  101. package/api/search/_template-searcher.mjs +23 -0
  102. package/api/search/_template-searcher.test.mjs +40 -0
  103. package/api/search/_template-searcher.weights.json +1 -0
  104. package/api/search/_titles.d.mts +33 -0
  105. package/api/search/_titles.mjs +65 -0
  106. package/api/search/_words.d.mts +64 -0
  107. package/api/search/_words.mjs +157 -0
  108. package/api/search/search.d.mts +22 -305
  109. package/api/search/search.doc.mjs +7 -5
  110. package/api/search/search.mjs +53 -2483
  111. package/api/search/search.type.d.mts +6 -1
  112. package/api/search/search.type.mjs +6 -1
  113. package/api/search/tree.d.mts +15 -0
  114. package/api/search/tree.mjs +40 -0
  115. package/api/search/tree.test.mjs +66 -0
  116. package/api/search/tree.weights.json +1 -0
  117. package/api/theme/build/build.packed-old-core.test.mjs +1 -0
  118. package/api/upgrade/_adapter.d.mts +0 -6
  119. package/api/upgrade/_adapter.mjs +52 -4
  120. package/api/upgrade/upgrade.test.mjs +194 -0
  121. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +11 -0
  122. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +3 -3
  123. package/assets/docs/tree/api.doc.mjs +6 -0
  124. package/assets/docs/tree/host-entry.doc.mjs +128 -0
  125. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  126. package/assets/docs/working-with-ai.doc.mjs +6 -2
  127. package/authoring/debug/parse.d.mts +1 -1
  128. package/clients/cli/bin/astryx.mjs +7 -78
  129. package/clients/cli/commands/doctor.mjs +30 -0
  130. package/clients/cli/commands/doctor.test.mjs +65 -0
  131. package/clients/cli/commands/init.behavior.test.mjs +230 -1
  132. package/clients/cli/commands/init.doc.mjs +28 -9
  133. package/clients/cli/commands/init.flag-help.test.mjs +1 -0
  134. package/clients/cli/commands/init.mjs +2 -2
  135. package/clients/cli/commands/outside-project.test.mjs +2 -1
  136. package/clients/cli/commands/setup-nudge.test.mjs +61 -0
  137. package/clients/cli/index.mjs +19 -1
  138. package/clients/cli/run.mjs +108 -0
  139. package/foundation/agent-docs/agent-doc-state.d.mts +20 -7
  140. package/foundation/agent-docs/agent-doc-state.mjs +35 -8
  141. package/foundation/agent-docs/agent-docs.d.mts +100 -12
  142. package/foundation/agent-docs/agent-docs.mjs +1010 -99
  143. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +1239 -17
  144. package/foundation/agent-docs/agent-docs.test.mjs +678 -35
  145. package/foundation/config/project.mjs +15 -2
  146. package/foundation/discovery/component-discovery.d.mts +37 -0
  147. package/foundation/discovery/component-discovery.mjs +80 -5
  148. package/foundation/discovery/component-loader.d.mts +1 -1
  149. package/foundation/discovery/docs-discovery.mjs +14 -1
  150. package/foundation/discovery/module-exports.d.mts +41 -0
  151. package/foundation/discovery/module-exports.mjs +253 -0
  152. package/foundation/doc-compiler/doc-loads.test.mjs +8 -0
  153. package/foundation/fs/paths.mjs +30 -3
  154. package/foundation/integrations/computer-integrations.d.mts +6 -3
  155. package/foundation/integrations/computer-integrations.mjs +38 -9
  156. package/foundation/integrations/contribution-inventory.d.mts +15 -20
  157. package/foundation/integrations/contribution-inventory.mjs +41 -5
  158. package/foundation/integrations/integrations.d.mts +7 -0
  159. package/foundation/integrations/integrations.mjs +2 -0
  160. package/foundation/integrations/validate-contributions.d.mts +96 -0
  161. package/foundation/integrations/validate-contributions.mjs +996 -10
  162. package/foundation/release/handoff.d.mts +23 -4
  163. package/foundation/release/handoff.mjs +175 -8
  164. package/foundation/release/run-context.mjs +14 -0
  165. package/foundation/response/response-types.doc.mjs +1 -1
  166. package/foundation/route/route.d.mts +285 -0
  167. package/foundation/route/route.mjs +324 -0
  168. package/foundation/route/route.test.mjs +153 -0
  169. package/foundation/runtime/hosted-runtime.test.mjs +403 -0
  170. package/foundation/runtime/locked-versions.d.mts +32 -0
  171. package/foundation/runtime/locked-versions.mjs +65 -0
  172. package/foundation/runtime/package-root.d.mts +91 -0
  173. package/foundation/runtime/package-root.mjs +174 -0
  174. package/foundation/runtime/package-set.d.mts +62 -0
  175. package/foundation/runtime/package-set.mjs +130 -0
  176. package/foundation/runtime/package-set.test.mjs +432 -0
  177. package/host/door-conformance.test.mjs +274 -0
  178. package/host/index.d.ts +116 -0
  179. package/host/index.mjs +295 -0
  180. package/host/index.test.mjs +302 -0
  181. package/package.json +14 -9
@@ -89,6 +89,10 @@ import {
89
89
  } from '../../assets/codemods/integration-discovery.mjs';
90
90
  import {validateLoadedIntegration} from '../integrations/validate-contributions.mjs';
91
91
  import {recordDeclaredCliCommands} from '../env/cli-command.mjs';
92
+ import {
93
+ hostedRun,
94
+ recordResolvedIntegrations,
95
+ } from '../runtime/package-root.mjs';
92
96
  import {
93
97
  InMemoryConfigCache,
94
98
  cacheKey,
@@ -121,9 +125,16 @@ function errorMessage(err) {
121
125
  */
122
126
  export function computerIntegrationCandidates(cwd = process.cwd()) {
123
127
  try {
124
- const cliRoot = isOutsideProject(cwd) ? CLI_ROOT : globalCliRoot(cwd);
128
+ const outside = isOutsideProject(cwd);
129
+ const cliRoot = outside ? CLI_ROOT : globalCliRoot(cwd);
125
130
  return cliRoot
126
- ? scanComputerIntegrations({cliRoot, release: cliVersion()})
131
+ ? scanComputerIntegrations({
132
+ cliRoot,
133
+ release: cliVersion(),
134
+ // Outside a project, the integrations a host approves load from the
135
+ // package set that serves the run too (cli-surface INV30).
136
+ approved: outside ? (hostedRun()?.integrations ?? []) : [],
137
+ })
127
138
  : [];
128
139
  } catch {
129
140
  return [];
@@ -580,6 +591,8 @@ export class Project {
580
591
  : []),
581
592
  ]);
582
593
  loadedIntegrations = resolution.integrations;
594
+ // A hosted run returns each package it resolved (cli-surface INV30).
595
+ recordResolvedIntegrations(loadedIntegrations);
583
596
  // The picker (getCliInvocation) is synchronous, so the commands these
584
597
  // integrations declare are recorded here, where they become known.
585
598
  recordDeclaredCliCommands(projectDir, loadedIntegrations);
@@ -1,6 +1,13 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Whether a component doc is hidden (`hidden: true`), read as discovery
6
+ * reads it: discovery skips a hidden doc.
7
+ * @param {string} docPath
8
+ * @returns {boolean}
9
+ */
10
+ export function isHiddenComponentDoc(docPath: string): boolean;
4
11
  /**
5
12
  * The entry a family doc gives `name` in its `components`, when the doc is not
6
13
  * the component's own (Stack's doc for VStack); null otherwise.
@@ -117,6 +124,36 @@ export function discoverExternalComponentsGrouped(docsDir: string): Record<strin
117
124
  export function findExternalComponentDoc(docsDir: string, name: string): string | null;
118
125
  /** @param {string} docPath */
119
126
  export function docStem(docPath: string): string;
127
+ /**
128
+ * The local module a doc's import names: the doc's own `import`, else the
129
+ * subpath its directory publishes, read through the package's `exports` (its
130
+ * `main` when it has none). Undefined when the package directory is unknown;
131
+ * null when the import names another package or resolves to no file.
132
+ *
133
+ * @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
134
+ * @param {string} docPath
135
+ * @param {Record<string, any> | null} doc
136
+ * @returns {string | null | undefined}
137
+ */
138
+ export function importedModule(integration: {
139
+ name?: string;
140
+ __packageDir?: string;
141
+ __packageExports?: Record<string, unknown> | null;
142
+ }, docPath: string, doc: Record<string, any> | null): string | null | undefined;
143
+ /**
144
+ * The file an import of the package's own name resolves to, through its
145
+ * package.json `exports` (or `main` when it has none): `@acme/kit` or
146
+ * `@acme/kit/widget`. Null when the specifier names another package, or the
147
+ * package publishes nothing at it.
148
+ * @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown> | null}} integration
149
+ * @param {string} specifier
150
+ * @returns {string | null}
151
+ */
152
+ export function ownPackageModule(integration: {
153
+ name?: string;
154
+ __packageDir?: string;
155
+ __packageExports?: Record<string, unknown> | null;
156
+ }, specifier: string): string | null;
120
157
  /**
121
158
  * The `.tsx` file in `folder`, or below it, that declares `name`, taking files
122
159
  * in path order: the source of a member whose import never reaches a `.tsx`
@@ -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
@@ -248,6 +248,10 @@ const RUNNERS = {
248
248
  runs: 'astryx.config, through the config parser',
249
249
  sites: ['loadModuleWithParser(..., parseConfig)'],
250
250
  },
251
+ 'foundation/agent-docs/agent-docs.mjs': {
252
+ runs: 'git, sl or hg, to read whether the repository ignores an untracked agent file',
253
+ sites: ['child_process.spawnSync'],
254
+ },
251
255
  'foundation/fs/file-protection.mjs': {
252
256
  runs: 'the ignore matcher (CommonJS), loaded when a resolver first reads an ignore file',
253
257
  sites: ['require(ignore)'],
@@ -339,6 +343,10 @@ const RUNNERS = {
339
343
  runs: "the CLI release that answers a project's run, when it is not this copy",
340
344
  sites: ['child_process.spawn'],
341
345
  },
346
+ 'host/index.mjs': {
347
+ runs: "another release's host entry, from one of the host's package sets, when that release answers a hosted run",
348
+ sites: ['import(<computed>)'],
349
+ },
342
350
  'scripts/generate-cli-readme.mjs': {
343
351
  runs: '`astryx manifest` and the error-code and response-type docs, to write the README tables (build time, not shipped)',
344
352
  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,