@astryxdesign/cli 0.7.2-canary.91cfb53 → 0.7.2-canary.95e1674

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 (217) hide show
  1. package/README.md +19 -18
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/docs/_adapter.d.mts +11 -0
  4. package/api/docs/_adapter.mjs +244 -1
  5. package/api/docs/integrationDocs.test.mjs +124 -0
  6. package/api/doctor/doctor.mjs +27 -3
  7. package/api/doctor/doctor.test.mjs +43 -0
  8. package/api/doctor/theme-checks.mjs +1 -1
  9. package/api/gap-report/gap-report.d.mts +3 -0
  10. package/api/gap-report/gap-report.doc.mjs +11 -3
  11. package/api/gap-report/gap-report.mjs +152 -48
  12. package/api/gap-report/gap-report.test.mjs +233 -0
  13. package/api/gap-report/gap-report.type.d.mts +41 -0
  14. package/api/gap-report/gap-report.type.mjs +18 -0
  15. package/api/index.d.mts +2 -0
  16. package/api/index.mjs +2 -0
  17. package/api/init/run/run.mjs +2 -2
  18. package/api/integration/_adapter.d.mts +12 -0
  19. package/api/integration/_adapter.mjs +54 -0
  20. package/api/integration/add-contribution.mjs +1 -1
  21. package/api/integration/add-contribution.test.mjs +4 -2
  22. package/api/integration/authoring-checks.mjs +11 -2
  23. package/api/integration/authoring-checks.test.mjs +39 -0
  24. package/api/integration/authoring-checks.type.d.mts +9 -0
  25. package/api/integration/authoring-checks.type.mjs +14 -1
  26. package/api/integration/check/check.d.mts +96 -0
  27. package/api/integration/check/check.mjs +357 -0
  28. package/api/integration/check/check.test.mjs +489 -0
  29. package/api/integration/integration-check.type.d.mts +118 -0
  30. package/api/integration/integration-check.type.mjs +84 -0
  31. package/api/integration/integrationCheck.doc.d.mts +10 -0
  32. package/api/integration/integrationCheck.doc.mjs +73 -0
  33. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  34. package/api/integration/validate-integration.mjs +8 -0
  35. package/api/integration/validate-integration.test.mjs +11 -0
  36. package/api/integration/validate-integration.type.d.mts +8 -0
  37. package/api/integration/validate-integration.type.mjs +12 -1
  38. package/api/integration/validateIntegration.doc.mjs +19 -3
  39. package/api/search/search.d.mts +72 -12
  40. package/api/search/search.domain-priority.test.mjs +108 -18
  41. package/api/search/search.integration-check.test.mjs +24 -0
  42. package/api/search/search.mjs +501 -37
  43. package/api/search/search.test.mjs +139 -0
  44. package/api/theme/build/build.family.test.mjs +54 -6
  45. package/api/theme/build/build.mjs +114 -17
  46. package/api/theme/themeBuild.doc.mjs +4 -4
  47. package/api/upgrade/_adapter.d.mts +40 -2
  48. package/api/upgrade/_adapter.mjs +117 -4
  49. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  50. package/api/upgrade/run/run.mjs +30 -1
  51. package/api/upgrade/status/status.d.mts +21 -5
  52. package/api/upgrade/status/status.mjs +45 -8
  53. package/api/upgrade/upgrade.doc.mjs +5 -3
  54. package/api/upgrade/upgrade.type.d.mts +23 -0
  55. package/api/upgrade/upgrade.type.mjs +16 -1
  56. package/assets/codemods/runner.mjs +7 -1
  57. package/assets/docs/README.md +10 -0
  58. package/assets/docs/author-a-theme.doc.mjs +1 -1
  59. package/assets/docs/getting-started.doc.mjs +3 -3
  60. package/assets/docs/styling-overview.doc.mjs +1 -1
  61. package/assets/docs/theme.doc.dense.mjs +1 -1
  62. package/assets/docs/theme.doc.mjs +1 -1
  63. package/assets/docs/theme.doc.zh.mjs +1 -1
  64. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  65. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  66. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  67. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  68. package/assets/docs/tree/block-template.doc.mjs +8 -20
  69. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  70. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  71. package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
  72. package/assets/docs/tree/checks.doc.mjs +23 -15
  73. package/assets/docs/tree/codemods.doc.mjs +4 -4
  74. package/assets/docs/tree/component-family.doc.mjs +3 -5
  75. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  76. package/assets/docs/tree/components.doc.mjs +1 -1
  77. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +25 -16
  78. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  79. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  80. package/assets/docs/tree/docs.doc.mjs +3 -3
  81. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  82. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  83. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  84. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  85. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  86. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  87. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  88. package/assets/docs/tree/integrations.doc.mjs +8 -0
  89. package/assets/docs/tree/links.doc.mjs +6 -5
  90. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  91. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  92. package/assets/docs/tree/migration.doc.mjs +0 -1
  93. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  94. package/assets/docs/tree/page-template.doc.mjs +4 -8
  95. package/assets/docs/tree/publishing.doc.mjs +1 -1
  96. package/assets/docs/tree/quick-start.doc.mjs +37 -21
  97. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  98. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  99. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  100. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  101. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  102. package/assets/docs/tree/single-component.doc.mjs +14 -5
  103. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  104. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  105. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  106. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  107. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  108. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  109. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  110. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  111. package/assets/docs/tree/templates.doc.mjs +1 -1
  112. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  113. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  114. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  115. package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
  116. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  117. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  118. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  119. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  120. package/assets/docs/tree/versioning.doc.mjs +6 -6
  121. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  122. package/assets/docs/use-a-theme.doc.mjs +2 -2
  123. package/assets/theme.template.ts +1 -1
  124. package/authoring/codemod/codemod.doc.mjs +7 -3
  125. package/authoring/config/config.doc.mjs +9 -6
  126. package/authoring/config/type.ts +4 -2
  127. package/authoring/discover/discover.doc.mjs +1 -1
  128. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  129. package/authoring/doctypes/command/command.doc.mjs +14 -12
  130. package/authoring/doctypes/component/component.doc.mjs +28 -25
  131. package/authoring/doctypes/component/type.ts +7 -5
  132. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  133. package/authoring/doctypes/function/function.doc.mjs +9 -8
  134. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  135. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  136. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  137. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  138. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  139. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  140. package/authoring/doctypes/template/parse.d.mts +6 -2
  141. package/authoring/doctypes/template/parse.mjs +3 -1
  142. package/authoring/doctypes/template/template.doc.mjs +3 -3
  143. package/authoring/doctypes/template/type.ts +22 -0
  144. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  145. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  146. package/authoring/identity/identity.doc.mjs +3 -3
  147. package/authoring/index.d.ts +1 -0
  148. package/authoring/integration/integration.doc.mjs +12 -4
  149. package/authoring/integration/parse.test.mjs +10 -0
  150. package/authoring/integration/schema.d.mts +2 -0
  151. package/authoring/integration/schema.mjs +1 -0
  152. package/authoring/integration/type.ts +4 -0
  153. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  154. package/clients/cli/commands/build-theme.mjs +1 -1
  155. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  156. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  157. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  158. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  159. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  160. package/clients/cli/commands/doctor.mjs +190 -0
  161. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  162. package/clients/cli/commands/gap-report.mjs +24 -2
  163. package/clients/cli/commands/gap-report.test.mjs +79 -0
  164. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  165. package/clients/cli/commands/integration-check.test.mjs +284 -0
  166. package/clients/cli/commands/integration.doc.mjs +6 -2
  167. package/clients/cli/commands/integration.mjs +106 -1
  168. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  169. package/clients/cli/commands/swizzle.mjs +5 -3
  170. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  171. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  172. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  173. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  174. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  175. package/clients/cli/index.mjs +30 -5
  176. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  177. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  178. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  179. package/foundation/agent-docs/agent-docs.mjs +8 -6
  180. package/foundation/config/project.mjs +82 -0
  181. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  182. package/foundation/discovery/component-discovery.d.mts +18 -0
  183. package/foundation/discovery/component-discovery.mjs +2 -2
  184. package/foundation/discovery/doc-types.d.mts +157 -0
  185. package/foundation/discovery/doc-types.mjs +1224 -0
  186. package/foundation/discovery/doc-types.test.mjs +700 -0
  187. package/foundation/discovery/docs-discovery.d.mts +81 -0
  188. package/foundation/discovery/docs-discovery.mjs +57 -0
  189. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  190. package/foundation/discovery/integration-doc-files.mjs +231 -0
  191. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  192. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  193. package/foundation/discovery/package-tsconfig.mjs +228 -0
  194. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  195. package/foundation/discovery/project-typescript.d.mts +32 -0
  196. package/foundation/discovery/project-typescript.mjs +89 -0
  197. package/foundation/discovery/prop-drift.d.mts +278 -0
  198. package/foundation/discovery/prop-drift.mjs +2263 -0
  199. package/foundation/discovery/prop-drift.test.mjs +2272 -0
  200. package/foundation/discovery/type-match.d.mts +53 -0
  201. package/foundation/discovery/type-match.mjs +660 -0
  202. package/foundation/discovery/type-match.test.mjs +169 -0
  203. package/foundation/discovery/type-text.d.mts +68 -0
  204. package/foundation/discovery/type-text.mjs +658 -0
  205. package/foundation/discovery/type-text.test.mjs +196 -0
  206. package/foundation/discovery/unresolved-references.d.mts +62 -0
  207. package/foundation/discovery/unresolved-references.mjs +790 -0
  208. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  209. package/foundation/doc-compiler/doc-loads.test.mjs +10 -0
  210. package/foundation/doc-compiler/links.d.mts +9 -5
  211. package/foundation/doc-compiler/links.mjs +4 -2
  212. package/foundation/env/package-manager.d.mts +32 -0
  213. package/foundation/env/package-manager.mjs +47 -0
  214. package/foundation/env/package-manager.test.mjs +194 -7
  215. package/foundation/response/response-types.doc.mjs +12 -6
  216. package/package.json +9 -9
  217. package/scripts/postinstall.mjs +3 -3
@@ -353,6 +353,49 @@ describe('checkImplicitIntegrations', () => {
353
353
  expect(c.message).toContain('named in astryx.config');
354
354
  });
355
355
 
356
+ // A package with no astryx.config that loads its own manifest: there is no
357
+ // config file, so the message must not say anything is named in one.
358
+ it("names the package's own manifest instead of a config that does not exist", () => {
359
+ const c = checkImplicitIntegrations({
360
+ integrations: [autolinked({__autolinked: false, __local: true, name: '@acme/kit'})],
361
+ });
362
+ expect(c.status).toBe('info');
363
+ expect(c.message).toBe(
364
+ "None — the only loaded integration is this package's own manifest (@acme/kit).",
365
+ );
366
+ expect(c.message).not.toContain('astryx.config');
367
+ });
368
+
369
+ // An own manifest that failed to load keeps a `__local` record carrying
370
+ // `__loadError`; it loaded nothing, so it is never named as loaded.
371
+ it("does not name the package's own manifest as loaded when it failed to load", () => {
372
+ const failed = autolinked({
373
+ __autolinked: false,
374
+ __local: true,
375
+ name: '@acme/kit',
376
+ __loadError: 'astryx.integration.mjs threw: boom',
377
+ });
378
+ const alone = checkImplicitIntegrations({integrations: [failed]});
379
+ expect(alone.status).toBe('info');
380
+ expect(alone.message).toBe('None loaded.');
381
+ const beside = checkImplicitIntegrations({
382
+ integrations: [autolinked({__autolinked: false}), failed],
383
+ });
384
+ expect(beside.message).toBe('None — every loaded integration is named in astryx.config.');
385
+ });
386
+
387
+ it('names both when configured integrations load beside the own manifest', () => {
388
+ const c = checkImplicitIntegrations({
389
+ integrations: [
390
+ autolinked({__autolinked: false}),
391
+ autolinked({__autolinked: false, __local: true, name: '@acme/kit'}),
392
+ ],
393
+ });
394
+ expect(c.message).toBe(
395
+ "None — every loaded integration is named in astryx.config or is this package's own manifest (@acme/kit).",
396
+ );
397
+ });
398
+
356
399
  it('names the package, the field, and what it contributes', () => {
357
400
  // Roots count only when they exist, so this one gives them real folders.
358
401
  const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-implicit-'));
@@ -736,7 +736,7 @@ export async function checkAppThemes(cwd) {
736
736
  label: 'App imports the theme module',
737
737
  status: 'warn',
738
738
  message: `Could not prove that project source imports ${state.module.path}${importEvidence.parseFailures ? `; ${importEvidence.parseFailures} source file(s) could not be parsed` : ''}.`,
739
- fix: `Import {themes, defaultThemeSlug} from the generated module and {Theme} from '@astryxdesign/core', then render <Theme theme={themes[defaultThemeSlug]}>.`,
739
+ fix: `Import {themes, defaultThemeSlug} from the generated module and {Theme} from '@astryxdesign/core/theme', then render <Theme theme={themes[defaultThemeSlug]}>.`,
740
740
  });
741
741
  }
742
742
 
@@ -60,6 +60,9 @@ export const GAP_REPORT_CATEGORIES: readonly (Readonly<{
60
60
  label: "Other";
61
61
  }>)[];
62
62
  export const PUBLIC_CONFIRMATION_MESSAGE: "Rerun with --confirm-public to file this report.";
63
+ /** What an agent does when more than one destination exists. */
64
+ export const ASK_DESTINATION_MESSAGE: "Ask the person where to file this report, then pass their choice with --to <package>. Never pick a package destination yourself; leave --to out to use the default.";
65
+ export type GapReportDestination = import("./gap-report.type.mjs").GapReportDestination;
63
66
  export type ReportTarget = {
64
67
  package: string;
65
68
  version: string | null;
@@ -19,6 +19,8 @@ export const doc = {
19
19
  'Sends a gap report to every configured handler: the project config handler first, then each integration handler in config order. ' +
20
20
  'Each handler has 30 s to finish, and its output goes to stderr. Public handlers run only with confirmPublic; internal handlers always run. ' +
21
21
  "With no handler, it files a GitHub issue for the owning package only with confirmPublic (without it nothing is sent), or returns the package's issues URL when that is not on GitHub. " +
22
+ "With options.to, the report goes only to that integration's issues URL instead, under the same confirmPublic rule. " +
23
+ 'When loaded integrations name their own issues URLs, the response lists every destination with a line telling an agent to ask the person where to file; pass their choice as options.to, never a package the agent picked itself. ' +
22
24
  'The report records whether an agent or a person ran it, and the response lists each handler outcome in order.',
23
25
  importPath: '@astryxdesign/cli/api',
24
26
  signature:
@@ -67,14 +69,20 @@ export const doc = {
67
69
  name: 'options.confirmPublic',
68
70
  type: 'boolean',
69
71
  description:
70
- 'Allow public delivery: public handlers run, and with no handler a GitHub issue is filed through the gh CLI.',
72
+ 'Allow public delivery: public handlers run, and a GitHub issues URL gets an issue filed through the gh CLI.',
71
73
  default: 'false',
72
74
  },
75
+ {
76
+ name: 'options.to',
77
+ type: 'string',
78
+ description:
79
+ 'A destination the person chose: a loaded integration whose manifest names an issues URL. The report goes only to that issues URL; handlers do not run.',
80
+ },
73
81
  {
74
82
  name: 'options.listCategories',
75
83
  type: 'boolean',
76
84
  description:
77
- 'Return categories without resolving a route or writing; the component and every other option are refused with ERR_INVALID_ARGUMENT.',
85
+ 'Return categories, and the destinations in meta when there is more than one, without resolving a route or writing; the component and every other option are refused with ERR_INVALID_ARGUMENT.',
78
86
  default: 'false',
79
87
  },
80
88
  {
@@ -115,7 +123,7 @@ export const doc = {
115
123
  },
116
124
  {
117
125
  code: 'ERR_UNKNOWN_PACKAGE',
118
- when: 'the explicitly selected package is not loaded',
126
+ when: 'the explicitly selected package is not loaded, or options.to names no destination (the error lists the destinations)',
119
127
  },
120
128
  {
121
129
  code: 'ERR_NOT_FOUND',
@@ -55,6 +55,14 @@ export const GAP_REPORT_CATEGORIES = Object.freeze([
55
55
  export const PUBLIC_CONFIRMATION_MESSAGE =
56
56
  'Rerun with --confirm-public to file this report.';
57
57
 
58
+ /** What an agent does when more than one destination exists. */
59
+ export const ASK_DESTINATION_MESSAGE =
60
+ 'Ask the person where to file this report, then pass their choice with --to <package>. Never pick a package destination yourself; leave --to out to use the default.';
61
+
62
+ /**
63
+ * @typedef {import('./gap-report.type.mjs').GapReportDestination} GapReportDestination
64
+ */
65
+
58
66
  /**
59
67
  * @typedef {object} ReportTarget
60
68
  * @property {string} package
@@ -537,15 +545,14 @@ function githubRoute(issuesUrl) {
537
545
  }
538
546
 
539
547
  /**
540
- * Built-in GitHub fallback — runs only when the effective handler set is empty.
541
- * Requires confirmPublic.
548
+ * File a report on GitHub with `gh` — for the zero-handler fallback and for a
549
+ * destination the caller names. Requires confirmPublic.
542
550
  *
543
- * @param {ReportTarget} target
544
551
  * @param {{component: string, categoryLabel: string, intention: string, detail?: string, source: string, timestamp: string}} report
545
552
  * @param {{repo: string}} github
546
553
  * @returns {Promise<Pick<import('./gap-report.type.mjs').GapReportDelivery, 'status'|'url'|'message'>>}
547
554
  */
548
- async function runGithubFallback(target, report, github) {
555
+ async function runGithubFallback(report, github) {
549
556
  const {execFile} = await import('node:child_process');
550
557
  const title = `[gap] ${report.component}: ${report.intention.slice(0, 70)}`;
551
558
  const body = [
@@ -607,6 +614,87 @@ async function runGithubFallback(target, report, github) {
607
614
  }
608
615
  }
609
616
 
617
+ /**
618
+ * Send a report to an issues URL: a GitHub issues URL is filed with `gh` only
619
+ * with consent; any other URL comes back as routed_only. Serves the
620
+ * zero-handler fallback (spec:AST-031/FR8) and a destination named with `to`
621
+ * (architecture:cli-surface INV36).
622
+ *
623
+ * @param {string} issuesUrl
624
+ * @param {{component: string, categoryLabel: string, intention: string, detail?: string, source: string, timestamp: string}} report
625
+ * @param {boolean} confirmPublic
626
+ * @returns {Promise<import('./gap-report.type.mjs').GapReportDelivery>}
627
+ */
628
+ async function deliverToIssuesUrl(issuesUrl, report, confirmPublic) {
629
+ const github = githubRoute(issuesUrl);
630
+ if (github != null && !confirmPublic) {
631
+ return {
632
+ handlerType: 'fallback',
633
+ handler: 'github',
634
+ audience: 'public',
635
+ status: 'consent_required',
636
+ url: null,
637
+ message: PUBLIC_CONFIRMATION_MESSAGE,
638
+ };
639
+ }
640
+ if (github) {
641
+ return {
642
+ handlerType: 'fallback',
643
+ handler: 'github',
644
+ audience: 'public',
645
+ ...(await runGithubFallback(report, github)),
646
+ };
647
+ }
648
+ return {
649
+ handlerType: 'fallback',
650
+ handler: 'issuesUrl',
651
+ audience: null,
652
+ status: 'routed_only',
653
+ url: issuesUrl,
654
+ message:
655
+ 'No automatic handler is available; open the routed URL to file this report.',
656
+ };
657
+ }
658
+
659
+ /**
660
+ * Where a report can go: the default (the handlers, or with none the owning
661
+ * package's issues URL), then each loaded integration that names its own
662
+ * issues URL (architecture:cli-surface INV36).
663
+ *
664
+ * @param {Project} project
665
+ * @returns {GapReportDestination[]}
666
+ */
667
+ function listDestinations(project) {
668
+ /** @type {GapReportDestination[]} */
669
+ const destinations = [{to: null, default: true, issuesUrl: null}];
670
+ for (const integration of project.loadedIntegrations) {
671
+ if (integration.__loadError || !integration.issuesUrl) continue;
672
+ if (destinations.some(destination => destination.to === integration.name))
673
+ continue;
674
+ destinations.push({
675
+ to: integration.name,
676
+ default: false,
677
+ issuesUrl: integration.issuesUrl,
678
+ });
679
+ }
680
+ return destinations;
681
+ }
682
+
683
+ /**
684
+ * The destinations of the project at `cwd`, or only the default when no
685
+ * project loads there.
686
+ * @param {string|undefined} cwd
687
+ * @returns {Promise<GapReportDestination[]>}
688
+ */
689
+ async function destinationsAt(cwd) {
690
+ try {
691
+ const {resolve} = await import('node:path');
692
+ return listDestinations(await Project.load(resolve(cwd ?? process.cwd())));
693
+ } catch {
694
+ return [{to: null, default: true, issuesUrl: null}];
695
+ }
696
+ }
697
+
610
698
  /**
611
699
  * Compute the aggregate status from the deliveries.
612
700
  * @param {import('./gap-report.type.mjs').GapReportDelivery[]} deliveries
@@ -665,6 +753,7 @@ export async function gapReport(component, options = {}) {
665
753
  options.detail ? '--additional-context' : null,
666
754
  options.package ? '--package' : null,
667
755
  options.confirmPublic ? '--confirm-public' : null,
756
+ options.to != null ? '--to' : null,
668
757
  ].filter(Boolean);
669
758
  if (ignored.length > 0) {
670
759
  throw new AstryxError(
@@ -673,9 +762,13 @@ export async function gapReport(component, options = {}) {
673
762
  ERROR_CODES.ERR_INVALID_ARGUMENT,
674
763
  );
675
764
  }
765
+ const destinations = await destinationsAt(options.cwd);
676
766
  return {
677
767
  type: 'gap-report.categories',
678
768
  data: GAP_REPORT_CATEGORIES.map(category => ({...category})),
769
+ ...(destinations.length > 1
770
+ ? {meta: {destinations, ask: ASK_DESTINATION_MESSAGE}}
771
+ : {}),
679
772
  };
680
773
  }
681
774
 
@@ -704,7 +797,33 @@ export async function gapReport(component, options = {}) {
704
797
  options.package,
705
798
  );
706
799
 
707
- const entries = collectGapReportHandlers(project);
800
+ const destinations = listDestinations(project);
801
+ /** @type {GapReportDestination | undefined} */
802
+ let chosen;
803
+ // `to: null` is absent, like `package: null`; any other value is matched
804
+ // against the destinations as given, so an empty or unknown one lists them.
805
+ if (options.to != null) {
806
+ const to = options.to;
807
+ chosen = destinations.find(
808
+ destination => !destination.default && destination.to === to,
809
+ );
810
+ if (!chosen) {
811
+ const choices = destinations.filter(destination => !destination.default);
812
+ const named = JSON.stringify(String(to).slice(0, 214));
813
+ throw new AstryxError(
814
+ choices.length > 0
815
+ ? `No gap-report destination ${named}. Choose one of: ${choices.map(destination => destination.to).join(', ')}; or leave out --to for the default.`
816
+ : `No gap-report destination ${named}: no loaded integration names an issues URL. Leave out --to for the default.`,
817
+ choices.map(destination => ({
818
+ name: /** @type {string} */ (destination.to),
819
+ reason: /** @type {string} */ (destination.issuesUrl),
820
+ })),
821
+ ERROR_CODES.ERR_UNKNOWN_PACKAGE,
822
+ );
823
+ }
824
+ }
825
+
826
+ const entries = chosen ? [] : collectGapReportHandlers(project);
708
827
 
709
828
  const timestamp = new Date().toISOString();
710
829
  const source = captureEnv().invocationSource;
@@ -731,8 +850,24 @@ export async function gapReport(component, options = {}) {
731
850
 
732
851
  /** @type {import('./gap-report.type.mjs').GapReportDelivery[]} */
733
852
  const deliveries = [];
853
+ const routeReport = {
854
+ component: resolvedComponent,
855
+ categoryLabel: categoryEntry.label,
856
+ intention,
857
+ detail,
858
+ source,
859
+ timestamp,
860
+ };
734
861
 
735
- if (entries.length > 0) {
862
+ if (chosen) {
863
+ deliveries.push(
864
+ await deliverToIssuesUrl(
865
+ /** @type {string} */ (chosen.issuesUrl),
866
+ routeReport,
867
+ options.confirmPublic === true,
868
+ ),
869
+ );
870
+ } else if (entries.length > 0) {
736
871
  deliveries.push(
737
872
  ...(await deliverGapReportHandlers(entries, report, {
738
873
  confirmPublic: options.confirmPublic === true,
@@ -746,47 +881,13 @@ export async function gapReport(component, options = {}) {
746
881
  ERROR_CODES.ERR_NOT_FOUND,
747
882
  );
748
883
  }
749
-
750
- const github = githubRoute(target.issuesUrl);
751
- if (github != null && options.confirmPublic !== true) {
752
- deliveries.push({
753
- handlerType: 'fallback',
754
- handler: 'github',
755
- audience: 'public',
756
- status: 'consent_required',
757
- url: null,
758
- message: PUBLIC_CONFIRMATION_MESSAGE,
759
- });
760
- } else if (github) {
761
- const outcome = await runGithubFallback(
762
- target,
763
- {
764
- component: resolvedComponent,
765
- categoryLabel: categoryEntry.label,
766
- intention,
767
- detail,
768
- source,
769
- timestamp,
770
- },
771
- github,
772
- );
773
- deliveries.push({
774
- handlerType: 'fallback',
775
- handler: 'github',
776
- audience: 'public',
777
- ...outcome,
778
- });
779
- } else {
780
- deliveries.push({
781
- handlerType: 'fallback',
782
- handler: 'issuesUrl',
783
- audience: null,
784
- status: 'routed_only',
785
- url: target.issuesUrl,
786
- message:
787
- 'No automatic handler is available; open the routed URL to file this report.',
788
- });
789
- }
884
+ deliveries.push(
885
+ await deliverToIssuesUrl(
886
+ target.issuesUrl,
887
+ routeReport,
888
+ options.confirmPublic === true,
889
+ ),
890
+ );
790
891
  }
791
892
 
792
893
  const filedCount = deliveries.filter(d => d.status === 'filed').length;
@@ -800,10 +901,13 @@ export async function gapReport(component, options = {}) {
800
901
  data: {
801
902
  status,
802
903
  package: target.package,
803
- issuesUrl: target.issuesUrl,
904
+ issuesUrl: chosen ? chosen.issuesUrl : target.issuesUrl,
804
905
  deliveries,
805
906
  filedCount,
806
907
  routedOnlyCount,
908
+ ...(!chosen && destinations.length > 1
909
+ ? {destinations, ask: ASK_DESTINATION_MESSAGE}
910
+ : {}),
807
911
  },
808
912
  };
809
913
  }
@@ -7,6 +7,7 @@ import * as path from 'node:path';
7
7
  import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
8
8
  import {Project} from '../../foundation/config/project.mjs';
9
9
  import {
10
+ ASK_DESTINATION_MESSAGE,
10
11
  GAP_REPORT_CATEGORIES,
11
12
  PUBLIC_CONFIRMATION_MESSAGE,
12
13
  collectGapReportHandlers,
@@ -1022,6 +1023,238 @@ console.log('https://github.com/acme/widgets/issues/42');
1022
1023
  });
1023
1024
  });
1024
1025
 
1026
+ describe('gapReport destinations and --to', () => {
1027
+ /** A shared internal handler that records each call in a marker file. */
1028
+ function addSharedHandler() {
1029
+ const marker = path.join(projectDir, 'shared-called');
1030
+ addIntegration({
1031
+ name: '@test/shared',
1032
+ audience: 'internal',
1033
+ handleBody: `(await import('node:fs')).writeFileSync(${JSON.stringify(marker)}, 'x'); return {status: 'filed', message: 'shared'};`,
1034
+ });
1035
+ return marker;
1036
+ }
1037
+
1038
+ function addWidgets(issuesUrl = 'https://github.com/acme/widgets/issues') {
1039
+ addIntegration({name: '@test/widgets', handler: false, issuesUrl});
1040
+ }
1041
+
1042
+ it('keeps the default route and lists the destinations with the ask line', async () => {
1043
+ const marker = addSharedHandler();
1044
+ addWidgets();
1045
+ configure(['@test/shared', '@test/widgets']);
1046
+ const argsFile = stubGh();
1047
+
1048
+ const result = await gapReport('General', {
1049
+ ...reportOptions,
1050
+ confirmPublic: true,
1051
+ cwd: projectDir,
1052
+ });
1053
+
1054
+ expect(result.data.deliveries).toEqual([
1055
+ expect.objectContaining({handler: '@test/shared', status: 'filed'}),
1056
+ ]);
1057
+ expect(fs.existsSync(marker)).toBe(true);
1058
+ expect(fs.existsSync(argsFile)).toBe(false);
1059
+ expect(result.data.destinations).toEqual([
1060
+ {to: null, default: true, issuesUrl: null},
1061
+ {
1062
+ to: '@test/widgets',
1063
+ default: false,
1064
+ issuesUrl: 'https://github.com/acme/widgets/issues',
1065
+ },
1066
+ ]);
1067
+ expect(result.data.ask).toBe(ASK_DESTINATION_MESSAGE);
1068
+ expect(ASK_DESTINATION_MESSAGE).toMatch(/ask the person/i);
1069
+ });
1070
+
1071
+ it('lists no destinations when no integration names an issuesUrl', async () => {
1072
+ addSharedHandler();
1073
+ configure(['@test/shared']);
1074
+
1075
+ const result = await gapReport('General', {
1076
+ ...reportOptions,
1077
+ cwd: projectDir,
1078
+ });
1079
+
1080
+ expect(result.data).not.toHaveProperty('destinations');
1081
+ expect(result.data).not.toHaveProperty('ask');
1082
+ });
1083
+
1084
+ it('files with the chosen integration GitHub issuesUrl only with consent, and runs no handler', async () => {
1085
+ const marker = addSharedHandler();
1086
+ addWidgets();
1087
+ configure(['@test/shared', '@test/widgets']);
1088
+ const argsFile = stubGh();
1089
+
1090
+ const pending = await gapReport('General', {
1091
+ ...reportOptions,
1092
+ to: '@test/widgets',
1093
+ cwd: projectDir,
1094
+ });
1095
+ expect(pending.data.deliveries).toEqual([
1096
+ {
1097
+ handlerType: 'fallback',
1098
+ handler: 'github',
1099
+ audience: 'public',
1100
+ status: 'consent_required',
1101
+ url: null,
1102
+ message: PUBLIC_CONFIRMATION_MESSAGE,
1103
+ },
1104
+ ]);
1105
+ expect(pending.data.issuesUrl).toBe(
1106
+ 'https://github.com/acme/widgets/issues',
1107
+ );
1108
+ expect(pending.data).not.toHaveProperty('destinations');
1109
+ expect(fs.existsSync(argsFile)).toBe(false);
1110
+
1111
+ const filed = await gapReport('General', {
1112
+ ...reportOptions,
1113
+ to: '@test/widgets',
1114
+ confirmPublic: true,
1115
+ cwd: projectDir,
1116
+ });
1117
+ expect(filed.data.deliveries).toHaveLength(1);
1118
+ expect(filed.data.deliveries[0]).toMatchObject({
1119
+ handlerType: 'fallback',
1120
+ handler: 'github',
1121
+ status: 'filed',
1122
+ });
1123
+ const args = JSON.parse(fs.readFileSync(argsFile, 'utf8'));
1124
+ expect(args.slice(0, 4)).toEqual([
1125
+ 'issue',
1126
+ 'create',
1127
+ '--repo',
1128
+ 'acme/widgets',
1129
+ ]);
1130
+ expect(fs.existsSync(marker)).toBe(false);
1131
+ });
1132
+
1133
+ it('routes a chosen non-GitHub issuesUrl as routed_only', async () => {
1134
+ addSharedHandler();
1135
+ addWidgets('https://tracker.example/widgets');
1136
+ configure(['@test/shared', '@test/widgets']);
1137
+
1138
+ const result = await gapReport('General', {
1139
+ ...reportOptions,
1140
+ to: '@test/widgets',
1141
+ cwd: projectDir,
1142
+ });
1143
+
1144
+ expect(result.data.deliveries).toEqual([
1145
+ expect.objectContaining({
1146
+ handlerType: 'fallback',
1147
+ handler: 'issuesUrl',
1148
+ status: 'routed_only',
1149
+ url: 'https://tracker.example/widgets',
1150
+ }),
1151
+ ]);
1152
+ expect(result.data.status).toBe('routed_only');
1153
+ });
1154
+
1155
+ it.each([
1156
+ ['a package that is not loaded', '@test/nope'],
1157
+ ['a loaded integration without an issuesUrl', '@test/shared'],
1158
+ ])(
1159
+ 'refuses --to naming %s, lists the choices, and sends nothing',
1160
+ async (_label, to) => {
1161
+ const marker = addSharedHandler();
1162
+ addWidgets();
1163
+ configure(['@test/shared', '@test/widgets']);
1164
+
1165
+ await expect(
1166
+ gapReport('General', {...reportOptions, to, cwd: projectDir}),
1167
+ ).rejects.toMatchObject({
1168
+ code: 'ERR_UNKNOWN_PACKAGE',
1169
+ suggestions: [
1170
+ {
1171
+ name: '@test/widgets',
1172
+ reason: 'https://github.com/acme/widgets/issues',
1173
+ },
1174
+ ],
1175
+ });
1176
+ expect(fs.existsSync(marker)).toBe(false);
1177
+ },
1178
+ );
1179
+
1180
+ it.each([
1181
+ ['an empty value', ''],
1182
+ ['a blank value', ' '],
1183
+ ['an over-long value', `@test/${'a'.repeat(300)}`],
1184
+ ])('refuses %s for --to with the destination list', async (_label, to) => {
1185
+ const marker = addSharedHandler();
1186
+ addWidgets();
1187
+ configure(['@test/shared', '@test/widgets']);
1188
+
1189
+ await expect(
1190
+ gapReport('General', {...reportOptions, to, cwd: projectDir}),
1191
+ ).rejects.toMatchObject({
1192
+ code: 'ERR_UNKNOWN_PACKAGE',
1193
+ suggestions: [{name: '@test/widgets'}],
1194
+ });
1195
+ expect(fs.existsSync(marker)).toBe(false);
1196
+ });
1197
+
1198
+ it('treats to: null as absent', async () => {
1199
+ const marker = addSharedHandler();
1200
+ addWidgets();
1201
+ configure(['@test/shared', '@test/widgets']);
1202
+
1203
+ const result = await gapReport('General', {
1204
+ ...reportOptions,
1205
+ to: /** @type {any} */ (null),
1206
+ cwd: projectDir,
1207
+ });
1208
+
1209
+ expect(result.data.deliveries).toHaveLength(1);
1210
+ expect(fs.existsSync(marker)).toBe(true);
1211
+ expect(result.data.destinations).toHaveLength(2);
1212
+ });
1213
+
1214
+ it('lists the destinations with the categories', async () => {
1215
+ addSharedHandler();
1216
+ addWidgets();
1217
+ configure(['@test/shared', '@test/widgets']);
1218
+
1219
+ const listed = await gapReport(undefined, {
1220
+ listCategories: true,
1221
+ cwd: projectDir,
1222
+ });
1223
+
1224
+ expect(listed.data).toEqual(GAP_REPORT_CATEGORIES);
1225
+ expect(listed.meta).toEqual({
1226
+ destinations: [
1227
+ {to: null, default: true, issuesUrl: null},
1228
+ {
1229
+ to: '@test/widgets',
1230
+ default: false,
1231
+ issuesUrl: 'https://github.com/acme/widgets/issues',
1232
+ },
1233
+ ],
1234
+ ask: ASK_DESTINATION_MESSAGE,
1235
+ });
1236
+ });
1237
+
1238
+ it('adds no meta to the categories when there is only the default', async () => {
1239
+ configure([]);
1240
+ const listed = await gapReport(undefined, {
1241
+ listCategories: true,
1242
+ cwd: projectDir,
1243
+ });
1244
+ expect(listed).not.toHaveProperty('meta');
1245
+ });
1246
+
1247
+ it('refuses --to with --list-categories', async () => {
1248
+ await expect(
1249
+ gapReport(undefined, {
1250
+ listCategories: true,
1251
+ to: '@test/widgets',
1252
+ cwd: projectDir,
1253
+ }),
1254
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
1255
+ });
1256
+ });
1257
+
1025
1258
  describe('gapReport target selection', () => {
1026
1259
  it('routes to the unique component owner', async () => {
1027
1260
  addIntegration({
@@ -35,10 +35,42 @@ export type GapReportOptions = {
35
35
  * Return the category vocabulary without routing or writing.
36
36
  */
37
37
  listCategories?: boolean | undefined;
38
+ /**
39
+ * A destination the person chose: a loaded integration
40
+ * whose manifest names an issues URL. The report goes only there.
41
+ */
42
+ to?: string | undefined;
43
+ };
44
+ /**
45
+ * Where a report can go. The default entry (`to: null`) is the configured
46
+ * handlers, or with none the owning package's issues URL.
47
+ */
48
+ export type GapReportDestination = {
49
+ /**
50
+ * The value to pass as `to`; null for the default.
51
+ */
52
+ to: string | null;
53
+ /**
54
+ * Whether this is the default destination.
55
+ */
56
+ default: boolean;
57
+ /**
58
+ * The integration's issues URL; null for the
59
+ * default.
60
+ */
61
+ issuesUrl: string | null;
38
62
  };
39
63
  export type GapReportCategoriesResponse = {
40
64
  type: "gap-report.categories";
41
65
  data: GapReportCategoryEntry[];
66
+ /**
67
+ * Present when a destination besides the default exists: every destination,
68
+ * and the line telling an agent to ask the person.
69
+ */
70
+ meta?: {
71
+ destinations: GapReportDestination[];
72
+ ask: string;
73
+ } | undefined;
42
74
  };
43
75
  export type GapReportAggregateStatus = "filed" | "partial" | "failed" | "routed_only" | "consent_required" | "skipped";
44
76
  export type GapReportDeliveryStatus = "filed" | "routed_only" | "skipped" | "failed" | "consent_required";
@@ -81,6 +113,15 @@ export type GapReportReceipt = {
81
113
  * Count of handlers that routed only.
82
114
  */
83
115
  routedOnlyCount: number;
116
+ /**
117
+ * For a run without `to`,
118
+ * when a destination besides the default exists: every destination.
119
+ */
120
+ destinations?: GapReportDestination[] | undefined;
121
+ /**
122
+ * With `destinations`: ask the person where to file.
123
+ */
124
+ ask?: string | undefined;
84
125
  };
85
126
  export type GapReportReceiptResponse = {
86
127
  type: "gap-report.file";