@astryxdesign/cli 0.7.2-canary.621784f → 0.7.2-canary.6a3ff0f

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 (143) hide show
  1. package/README.md +10 -10
  2. package/api/doctor/doctor.mjs +27 -3
  3. package/api/doctor/doctor.test.mjs +43 -0
  4. package/api/gap-report/gap-report.d.mts +3 -0
  5. package/api/gap-report/gap-report.doc.mjs +11 -3
  6. package/api/gap-report/gap-report.mjs +152 -48
  7. package/api/gap-report/gap-report.test.mjs +233 -0
  8. package/api/gap-report/gap-report.type.d.mts +41 -0
  9. package/api/gap-report/gap-report.type.mjs +18 -0
  10. package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
  11. package/api/integration/validateIntegration.doc.mjs +3 -1
  12. package/api/search/search.d.mts +72 -12
  13. package/api/search/search.domain-priority.test.mjs +108 -18
  14. package/api/search/search.mjs +501 -37
  15. package/api/search/search.test.mjs +139 -0
  16. package/api/theme/build/build.family.test.mjs +54 -6
  17. package/api/theme/build/build.mjs +110 -13
  18. package/api/theme/themeBuild.doc.mjs +4 -4
  19. package/api/upgrade/_adapter.d.mts +40 -2
  20. package/api/upgrade/_adapter.mjs +117 -4
  21. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  22. package/api/upgrade/run/run.mjs +30 -1
  23. package/api/upgrade/status/status.d.mts +21 -5
  24. package/api/upgrade/status/status.mjs +45 -8
  25. package/api/upgrade/upgrade.doc.mjs +5 -3
  26. package/api/upgrade/upgrade.type.d.mts +23 -0
  27. package/api/upgrade/upgrade.type.mjs +16 -1
  28. package/assets/codemods/runner.mjs +7 -1
  29. package/assets/docs/styling-overview.doc.mjs +1 -1
  30. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  31. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  32. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  33. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  34. package/assets/docs/tree/block-template.doc.mjs +6 -18
  35. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  36. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  37. package/assets/docs/tree/check-your-docs.doc.mjs +10 -5
  38. package/assets/docs/tree/checks.doc.mjs +5 -5
  39. package/assets/docs/tree/codemods.doc.mjs +4 -4
  40. package/assets/docs/tree/component-family.doc.mjs +3 -5
  41. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  42. package/assets/docs/tree/components.doc.mjs +1 -1
  43. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +25 -16
  44. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  45. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  46. package/assets/docs/tree/docs.doc.mjs +3 -3
  47. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  48. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  49. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  50. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  51. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  52. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  53. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  54. package/assets/docs/tree/integrations.doc.mjs +8 -0
  55. package/assets/docs/tree/links.doc.mjs +5 -4
  56. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  57. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  58. package/assets/docs/tree/migration.doc.mjs +0 -1
  59. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  60. package/assets/docs/tree/page-template.doc.mjs +3 -7
  61. package/assets/docs/tree/publishing.doc.mjs +1 -1
  62. package/assets/docs/tree/quick-start.doc.mjs +36 -20
  63. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  64. package/assets/docs/tree/replace-a-core-template.doc.mjs +5 -7
  65. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  66. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  67. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  68. package/assets/docs/tree/single-component.doc.mjs +12 -4
  69. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  70. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  71. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  72. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  73. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  74. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  75. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  76. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  77. package/assets/docs/tree/templates.doc.mjs +1 -1
  78. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  79. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  80. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  81. package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
  82. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  83. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  84. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  85. package/assets/docs/tree/versioning.doc.mjs +6 -6
  86. package/assets/docs/tree/write-the-template-file.doc.mjs +2 -2
  87. package/authoring/codemod/codemod.doc.mjs +7 -3
  88. package/authoring/config/config.doc.mjs +9 -6
  89. package/authoring/config/type.ts +4 -2
  90. package/authoring/discover/discover.doc.mjs +1 -1
  91. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  92. package/authoring/doctypes/command/command.doc.mjs +14 -12
  93. package/authoring/doctypes/component/component.doc.mjs +28 -25
  94. package/authoring/doctypes/component/type.ts +7 -5
  95. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  96. package/authoring/doctypes/function/function.doc.mjs +9 -8
  97. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  98. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  99. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  100. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  101. package/authoring/doctypes/template/template.doc.mjs +2 -2
  102. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  103. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  104. package/authoring/identity/identity.doc.mjs +3 -3
  105. package/authoring/integration/integration.doc.mjs +4 -3
  106. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  107. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  108. package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -1
  109. package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
  110. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  111. package/clients/cli/commands/gap-report.mjs +24 -2
  112. package/clients/cli/commands/gap-report.test.mjs +79 -0
  113. package/clients/cli/commands/integration-check.test.mjs +17 -0
  114. package/clients/cli/commands/integration.mjs +2 -3
  115. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  116. package/clients/cli/commands/swizzle.mjs +5 -3
  117. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  118. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  119. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  120. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  121. package/clients/cli/index.mjs +29 -5
  122. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  123. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  124. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  125. package/foundation/agent-docs/agent-docs.mjs +8 -6
  126. package/foundation/discovery/authoring-self-docs.mjs +1 -1
  127. package/foundation/discovery/doc-types.d.mts +1 -1
  128. package/foundation/discovery/doc-types.mjs +3 -3
  129. package/foundation/discovery/doc-types.test.mjs +48 -0
  130. package/foundation/discovery/project-typescript.d.mts +11 -2
  131. package/foundation/discovery/project-typescript.mjs +32 -4
  132. package/foundation/discovery/prop-drift.d.mts +1 -1
  133. package/foundation/discovery/prop-drift.mjs +2 -2
  134. package/foundation/discovery/prop-drift.test.mjs +55 -2
  135. package/foundation/discovery/type-text.mjs +1 -1
  136. package/foundation/discovery/type-text.test.mjs +1 -1
  137. package/foundation/doc-compiler/doc-loads.test.mjs +6 -2
  138. package/foundation/env/package-manager.d.mts +32 -0
  139. package/foundation/env/package-manager.mjs +47 -0
  140. package/foundation/env/package-manager.test.mjs +194 -7
  141. package/foundation/response/response-types.doc.mjs +5 -4
  142. package/package.json +9 -9
  143. package/scripts/postinstall.mjs +3 -3
package/README.md CHANGED
@@ -447,8 +447,8 @@ Every response has a `type` discriminant. The full set is below (generated from
447
447
  | `build.kit` | The template to start from and its kit: query, hasResults, matchCount (never a cap), directMatch, start {name, package, command, basis, reason, alternatives, ...} (the start and each alternative name the package that owns the template), pages (search's closest templates), blocks and domain as SearchResultEntry[] (each naming its package), frame and foundation (Core component names), and hint {reason, commands} when thin. |
448
448
  | `swizzle.list` | The names of swizzlable components discoverable from cwd's @astryxdesign/core. The envelope's package is @astryxdesign/core. |
449
449
  | `swizzle.copy` | An eject receipt: component name, owning package, output directory, files-copied count, the written file names, whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling. The envelope's package names the same owning package. |
450
- | `gap-report.categories` | The fixed gap category values and human-readable labels. |
451
- | `gap-report.file` | An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project \| integration \| fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals. |
450
+ | `gap-report.categories` | The fixed gap category values and human-readable labels; when a loaded integration names its own issues URL, meta.destinations lists every destination ({to, default, issuesUrl}) and meta.ask tells an agent to ask the person. |
451
+ | `gap-report.file` | An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project \| integration \| fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals; without --to, when a loaded integration names its own issues URL, destinations and ask as on gap-report.categories. |
452
452
  | `template.list` | The effective discovered TemplateListEntry[] for pages and blocks. A winning replacement entry includes optional `replaces`, naming the Core id omitted from the default list. |
453
453
  | `template.show` | The resolved template's source, exactly as a copy writes it, plus its description, kind, the component names it composes, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media). |
454
454
  | `template.skeleton` | A layout skeleton (structural tags with spatial annotations) plus the template's description and the components it composes. The envelope's package names the npm package that owns the template. |
@@ -468,8 +468,8 @@ Every response has a `type` discriminant. The full set is below (generated from
468
468
  | `theme.palette.generate` | An author-reviewable OKLCH palette candidate, its reproducibility receipt, summary counts, and optional candidate/receipt file-write result. |
469
469
  | `upgrade.list` | Every available codemod, oldest→newest, as {name, package, title, version, optional}; returned for --list without running anything. |
470
470
  | `upgrade.registry` | The copied-composition receipt for --registry: applied, ok, the counts (found, current, wouldUpdate, updated, wouldMerge, merged, wouldRefreshReceipt, receiptsRefreshed, conflicts, missing, invalid, failed), and items. |
471
- | `upgrade.status` | A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. |
472
- | `upgrade.run` | The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. |
471
+ | `upgrade.status` | A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. no_codemods and config_fixable carry cliBehindCore ({cliVersion, command}) when the installed Core is newer than the CLI, which then has no codemods for the releases after its own version. |
472
+ | `upgrade.run` | The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run. |
473
473
  | `manifest` | The CLI capability manifest: name, version, apiVersion, description, globalOptions, commands (each name, description, arguments, options, json, aliases?, responseTypes?, examples?, exitCodes? as [{code, when}], subcommands?), jsonSupported, and the flat responseTypes index. |
474
474
  | `help` | Help, in one of two shapes. A bare `astryx --json` returns the root manifest: name, version, commands (the command names), jsonSupported, and manifest (the full payload `astryx manifest --json` returns). `--help --json` on any command, or `astryx help [command] --json`, returns that command's help: command, description, usage, options (each flags, description, and defaultValue and choices when set), and subcommands (each name and description). data.manifest marks the first shape; data.usage marks the second. |
475
475
  | `version` | The CLI version, for `astryx --version --json`: {version}. |
@@ -581,12 +581,12 @@ There is no factory: write a plain object. For editor autocomplete and
581
581
  type-checking, annotate it with the `AstryxConfig` type exported from
582
582
  `@astryxdesign/cli/authoring`.
583
583
 
584
- | Field | Type | Purpose |
585
- | ----------------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------- |
586
- | `integrations` | `string[]` | Integration package names to load (see [Integrations](#integrations)). |
587
- | `issuesUrl` | `string` | Where "report an issue" links point for your project. Defaults to the core issue tracker. |
588
- | `hooks.postCodemod` | `PostCodemodHook[]` | Commands to run after `astryx upgrade` applies codemods (e.g. reinstall, rebuild, reformat). |
589
- | `experimental.xle.components` | `Record<string, XleComponent>` | Register app-local components so layout (XLE) expressions can reference them by name. Unstable. |
584
+ | Field | Type | Purpose |
585
+ | ----------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
586
+ | `integrations` | `string[]` | Integration package names to load (see [Integrations](#integrations)). |
587
+ | `issuesUrl` | `string` | Where "report an issue" links point for your project. Defaults to the core issue tracker. |
588
+ | `hooks.postCodemod` | `PostCodemodHook[]` | Commands to run after `astryx upgrade` applies codemods (e.g. reinstall, rebuild, reformat). |
589
+ | `experimental.xle.components` | `Record<string, XleComponent>` | Custom components for the removed layout expander, keyed by component name. The CLI still validates the field, so an entry without a string `from` makes `astryx.config` invalid, but nothing reads it. |
590
590
 
591
591
  The config is validated against a strict schema when the CLI loads it, so an
592
592
  unknown field is a hard error rather than a silent no-op. `astryx doctor`
@@ -351,6 +351,26 @@ export async function checkConfig(ctx) {
351
351
  }
352
352
  }
353
353
 
354
+ /**
355
+ * Why no integration is implicitly linked, from what actually loaded. A
356
+ * configured integration is named in astryx.config; the package's own manifest
357
+ * loads as itself (`__local`). Only the first may be described as named in
358
+ * astryx.config: a package with no config that loads its own manifest has no
359
+ * config file to name it.
360
+ *
361
+ * @param {Array<{name?: string, __local?: boolean}>} integrations loaded, none
362
+ * autolinked and none that failed to load
363
+ * @returns {string}
364
+ */
365
+ function describeNoImplicit(integrations) {
366
+ const own = integrations.filter(integration => integration.__local);
367
+ const configured = integrations.length - own.length;
368
+ const ownNames = own.map(integration => integration.name ?? 'this package').join(', ');
369
+ if (own.length === 0) return 'None — every loaded integration is named in astryx.config.';
370
+ if (configured === 0) return `None — the only loaded integration is this package's own manifest (${ownNames}).`;
371
+ return `None — every loaded integration is named in astryx.config or is this package's own manifest (${ownNames}).`;
372
+ }
373
+
354
374
  /**
355
375
  * Check 6 — integrations that are loaded without an astryx.config entry.
356
376
  *
@@ -395,14 +415,18 @@ export function checkImplicitIntegrations(ctx) {
395
415
  const unreadable = describeUnreadableManifests(ctx.autolinkFailures ?? []);
396
416
 
397
417
  if (implicit.length === 0) {
418
+ // A record that carries `__loadError` (the package's own manifest, or a
419
+ // configured one, that failed to load) loaded nothing, so it is not named
420
+ // as loaded beside the line reporting that it could not be loaded.
421
+ const loaded = ctx.integrations.filter(integration => !integration.__loadError);
398
422
  return {
399
423
  id,
400
424
  label,
401
425
  status: 'info',
402
426
  message:
403
- (ctx.integrations.length > 0
404
- ? 'None — every loaded integration is named in astryx.config.'
405
- : unreadable
427
+ (loaded.length > 0
428
+ ? describeNoImplicit(loaded)
429
+ : ctx.integrations.length > 0 || unreadable
406
430
  ? 'None loaded.'
407
431
  : 'None — no installed dependency ships an astryx.integration.* manifest.') +
408
432
  unreadable,
@@ -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-'));
@@ -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
  }