@astryxdesign/cli 0.6.5-canary.84fdbd1 → 0.6.5-canary.8a5b3fb

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 (81) hide show
  1. package/README.md +21 -21
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +2 -0
  4. package/api/build/build.type.d.mts +8 -0
  5. package/api/build/build.type.mjs +2 -0
  6. package/api/build/kit/kit.mjs +1 -0
  7. package/api/component/component.mjs +17 -15
  8. package/api/component/component.type.d.mts +33 -3
  9. package/api/component/component.type.mjs +10 -3
  10. package/api/component/detail/blocks/blocks.d.mts +2 -1
  11. package/api/component/detail/blocks/blocks.mjs +5 -2
  12. package/api/component/detail/detail.mjs +5 -1
  13. package/api/component/detail/props/props.d.mts +2 -1
  14. package/api/component/detail/props/props.mjs +3 -2
  15. package/api/component/detail/showcase/showcase.d.mts +3 -1
  16. package/api/component/detail/showcase/showcase.mjs +3 -1
  17. package/api/component/detail/source/source.d.mts +3 -2
  18. package/api/component/detail/source/source.mjs +7 -3
  19. package/api/component/list/list.mjs +18 -6
  20. package/api/docs/_adapter.d.mts +11 -0
  21. package/api/docs/_adapter.mjs +25 -0
  22. package/api/docs/detail/detail.mjs +19 -3
  23. package/api/docs/detail/section/section.mjs +7 -1
  24. package/api/docs/docs.depth.test.mjs +2 -0
  25. package/api/docs/docs.mjs +2 -0
  26. package/api/docs/docs.type.d.mts +43 -3
  27. package/api/docs/docs.type.mjs +23 -3
  28. package/api/docs/index/index.mjs +11 -2
  29. package/api/docs/index/index.test.mjs +2 -1
  30. package/api/docs/node/node.mjs +3 -0
  31. package/api/hook/_adapter.d.mts +1 -0
  32. package/api/hook/_adapter.mjs +3 -0
  33. package/api/hook/detail/detail.mjs +2 -2
  34. package/api/hook/detail/params/params.mjs +2 -2
  35. package/api/hook/hook.type.d.mts +12 -0
  36. package/api/hook/hook.type.mjs +3 -0
  37. package/api/hook/list/list.mjs +8 -8
  38. package/api/search/search.d.mts +3 -3
  39. package/api/search/search.mjs +9 -5
  40. package/api/search/search.type.d.mts +2 -2
  41. package/api/search/search.type.mjs +1 -1
  42. package/api/swizzle/_adapter.d.mts +1 -0
  43. package/api/swizzle/_adapter.mjs +3 -0
  44. package/api/swizzle/copy/copy.mjs +1 -1
  45. package/api/swizzle/list/list.mjs +2 -2
  46. package/api/swizzle/swizzle.type.d.mts +8 -0
  47. package/api/swizzle/swizzle.type.mjs +2 -0
  48. package/api/template/copy/copy.mjs +2 -1
  49. package/api/template/show/show.mjs +2 -0
  50. package/api/template/skeleton/skeleton.mjs +2 -1
  51. package/api/template/template.d.mts +1 -1
  52. package/api/template/template.mjs +1 -0
  53. package/api/template/template.type.d.mts +12 -0
  54. package/api/template/template.type.mjs +3 -0
  55. package/api/upgrade/_adapter.d.mts +1 -0
  56. package/api/upgrade/_adapter.mjs +3 -0
  57. package/api/upgrade/list/list.mjs +9 -3
  58. package/api/upgrade/upgrade.type.d.mts +4 -0
  59. package/api/upgrade/upgrade.type.mjs +1 -0
  60. package/clients/cli/commands/build.mjs +7 -6
  61. package/clients/cli/commands/build.text-fields.test.mjs +1 -1
  62. package/clients/cli/commands/component/index.mjs +34 -6
  63. package/clients/cli/commands/docs.mjs +63 -23
  64. package/clients/cli/commands/hook/index.mjs +7 -2
  65. package/clients/cli/commands/swizzle.mjs +2 -1
  66. package/clients/cli/commands/template.mjs +8 -4
  67. package/clients/cli/commands/text-json-parity.test.mjs +22 -0
  68. package/clients/cli/commands/upgrade.mjs +1 -1
  69. package/clients/cli/index.mjs +1 -1
  70. package/foundation/discovery/docs-output-budget.d.mts +6 -2
  71. package/foundation/discovery/docs-output-budget.mjs +2 -1
  72. package/foundation/discovery/docs-section-key.d.mts +4 -2
  73. package/foundation/discovery/docs-section-key.mjs +1 -1
  74. package/foundation/doc-compiler/lenses.d.mts +4 -2
  75. package/foundation/doc-compiler/lenses.mjs +1 -1
  76. package/foundation/response/base.d.ts +9 -3
  77. package/foundation/response/json.d.mts +7 -4
  78. package/foundation/response/json.mjs +10 -6
  79. package/foundation/response/response-types.doc.mjs +25 -20
  80. package/foundation/response/response.doc.mjs +17 -3
  81. package/package.json +9 -9
@@ -34,6 +34,7 @@ import {
34
34
  text,
35
35
  code,
36
36
  wrapText,
37
+ record,
37
38
  } from '../formatters/index.mjs';
38
39
  import {cliError} from '../lib/cli-error.mjs';
39
40
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
@@ -247,17 +248,22 @@ function docsBelow(count) {
247
248
  * it sits below the read's namespace.
248
249
  * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild[]} children
249
250
  * @param {string} root
251
+ * @param {string} owner the package that owns the read's namespace
250
252
  * @returns {{name: string, summary: string}[]}
251
253
  */
252
- function treeRows(children, root) {
254
+ function treeRows(children, root, owner) {
253
255
  return children.flatMap(child => [
254
256
  {
255
- name: belowRoot(child.route, root),
257
+ // A child another package owns says which one.
258
+ name:
259
+ child.package === owner
260
+ ? belowRoot(child.route, root)
261
+ : `${belowRoot(child.route, root)} (${child.package})`,
256
262
  summary: child.childCount
257
- ? `${childRow(child).summary} (${docsBelow(child.childCount)})`
258
- : childRow(child).summary,
263
+ ? `${childRow(child, owner).summary} (${docsBelow(child.childCount)})`
264
+ : childRow(child, owner).summary,
259
265
  },
260
- ...(child.slots ?? []).flatMap(slot => treeRows(slot.children, root)),
266
+ ...(child.slots ?? []).flatMap(slot => treeRows(slot.children, root, owner)),
261
267
  ]);
262
268
  }
263
269
 
@@ -269,12 +275,16 @@ function treeRows(children, root) {
269
275
  * @param {number} level
270
276
  * @param {string} root
271
277
  * @param {string} run
278
+ * @param {string} owner the package that owns the read's namespace
272
279
  * @returns {string}
273
280
  */
274
- function formatTreeChild(child, detail, level, root, run) {
275
- const parts = [
276
- `${treeHeading(child.title, level)} (${belowRoot(child.route, root)})`,
277
- ];
281
+ function formatTreeChild(child, detail, level, root, run, owner) {
282
+ // A child another package owns says which one.
283
+ const place =
284
+ child.package === owner
285
+ ? belowRoot(child.route, root)
286
+ : `${belowRoot(child.route, root)}, ${child.package}`;
287
+ const parts = [`${treeHeading(child.title, level)} (${place})`];
278
288
  if (
279
289
  child.summary &&
280
290
  (child.kind === 'namespace' || child.kind === 'generic')
@@ -296,7 +306,7 @@ function formatTreeChild(child, detail, level, root, run) {
296
306
  for (const slot of child.slots ?? []) {
297
307
  parts.push(
298
308
  ...slot.children.map(each =>
299
- formatTreeChild(each, detail, level + 1, root, run),
309
+ formatTreeChild(each, detail, level + 1, root, run, owner),
300
310
  ),
301
311
  );
302
312
  }
@@ -332,6 +342,7 @@ function emitTree(node, detail, childDetail, run) {
332
342
  const root = allBelow ? node.route : '';
333
343
  emit(
334
344
  section(node.title, wrapText(node.summary)),
345
+ record({package: node.package}),
335
346
  ...(node.content?.length
336
347
  ? [
337
348
  text(
@@ -354,13 +365,15 @@ function emitTree(node, detail, childDetail, run) {
354
365
  ? []
355
366
  : [section(slot.title)]),
356
367
  childDetail === 'brief'
357
- ? records(treeRows(slot.children, root), {
368
+ ? records(treeRows(slot.children, root, node.package), {
358
369
  fields: ['name', 'summary'],
359
370
  layout: 'inline',
360
371
  })
361
372
  : code(
362
373
  slot.children
363
- .map(child => formatTreeChild(child, childDetail, 2, root, run))
374
+ .map(child =>
375
+ formatTreeChild(child, childDetail, 2, root, run, node.package),
376
+ )
364
377
  .join('\n\n'),
365
378
  ),
366
379
  ]),
@@ -401,20 +414,27 @@ function linkLines(links) {
401
414
  * A topic's section index: what the topic is, one line per section with the
402
415
  * key to read it by, and how to read further.
403
416
  * @param {import('../../../api/docs/docs.type.mjs').DocsIndex} index
417
+ * @param {string} owner the package that owns the topic
404
418
  * @param {string} run
405
419
  */
406
- function emitIndex(index, run) {
420
+ function emitIndex(index, owner, run) {
407
421
  emit(
408
422
  section(
409
423
  index.title,
410
424
  index.description ? wrapText(index.description) : undefined,
411
425
  ),
426
+ record({package: owner}),
412
427
  // Summaries wrap rather than being cut: the summary is how a reader picks
413
- // the one section to open.
414
- records(index.sections, {
415
- fields: ['id', 'title', 'summary'],
416
- layout: 'inline',
417
- }),
428
+ // the one section to open. A section another package wrote says which one.
429
+ records(
430
+ index.sections.map(s =>
431
+ s.package === owner ? s : {...s, title: `${s.title} (${s.package})`},
432
+ ),
433
+ {
434
+ fields: ['id', 'title', 'summary'],
435
+ layout: 'inline',
436
+ },
437
+ ),
418
438
  text(
419
439
  [
420
440
  `Read one section: ${run} docs ${index.name} <section>`,
@@ -431,15 +451,17 @@ function emitIndex(index, run) {
431
451
  * template`). Typed docs keep a distinct title when it carries the real symbol
432
452
  * name (`assert-response assertResponse()`).
433
453
  * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild} child
454
+ * @param {string} owner the package that owns the namespace
434
455
  * @returns {{name: string, summary: string}}
435
456
  */
436
- function childRow(child) {
457
+ function childRow(child, owner) {
437
458
  const titleAddsIdentity =
438
459
  child.kind !== 'namespace' &&
439
460
  child.kind !== 'generic' &&
440
461
  child.title !== child.name;
441
462
  return {
442
- name: child.name,
463
+ // A child another package owns says which one.
464
+ name: child.package === owner ? child.name : `${child.name} (${child.package})`,
443
465
  summary: titleAddsIdentity
444
466
  ? `${child.title}: ${child.summary}`
445
467
  : child.summary,
@@ -458,6 +480,7 @@ function emitNode(node, detail, run) {
458
480
  if (node.kind === 'namespace') {
459
481
  emit(
460
482
  section(node.title, wrapText(node.summary)),
483
+ record({package: node.package}),
461
484
  // A namespace may author intro `blocks`; they render above its children.
462
485
  ...(node.content?.length
463
486
  ? [
@@ -474,7 +497,7 @@ function emitNode(node, detail, run) {
474
497
  ...(node.slots.length === 1 && slot.title === node.title
475
498
  ? []
476
499
  : [section(slot.title)]),
477
- records(slot.children.map(childRow), {
500
+ records(slot.children.map(child => childRow(child, node.package)), {
478
501
  fields: ['name', 'summary'],
479
502
  layout: 'inline',
480
503
  }),
@@ -495,6 +518,7 @@ function emitNode(node, detail, run) {
495
518
  return;
496
519
  }
497
520
  emit(
521
+ record({package: node.package}),
498
522
  code(formatSection({title: node.title, content: node.content}, detail)),
499
523
  text(linkLines(node.links).join('\n')),
500
524
  );
@@ -655,13 +679,28 @@ export function registerDocs(program) {
655
679
  }
656
680
 
657
681
  case 'docs.index': {
658
- emitIndex(result.data, run);
682
+ emitIndex(result.data, result.package, run);
659
683
  break;
660
684
  }
661
685
 
662
686
  case 'docs.detail': {
687
+ const owner = result.package;
663
688
  emit(
664
- code(formatReferenceFull(result.data, detail)),
689
+ record({package: owner}),
690
+ code(
691
+ formatReferenceFull(
692
+ {
693
+ ...result.data,
694
+ // A section another package wrote says which one.
695
+ sections: result.data.sections.map(s =>
696
+ s.package === owner
697
+ ? s
698
+ : {...s, title: `${s.title} (${s.package})`},
699
+ ),
700
+ },
701
+ detail,
702
+ ),
703
+ ),
665
704
  text(linkLines(result.data.links).join('\n')),
666
705
  );
667
706
  break;
@@ -671,6 +710,7 @@ export function registerDocs(program) {
671
710
  // One section ends with its moves: up to its topic's index, and to
672
711
  // the sections before and after it.
673
712
  emit(
713
+ record({package: result.package}),
674
714
  code(formatSection(result.data, detail)),
675
715
  text(linkLines(result.data.links).join('\n')),
676
716
  );
@@ -14,7 +14,7 @@ import {
14
14
  } from '../../lib/hook-format.mjs';
15
15
  import {getCliInvocation} from '../../../../foundation/env/package-manager.mjs';
16
16
  import {jsonOut} from '../../../../foundation/response/json.mjs';
17
- import {emit, section, text, list, records, code} from '../../formatters/index.mjs';
17
+ import {emit, section, text, list, records, code, record} from '../../formatters/index.mjs';
18
18
  import {cliError} from '../../lib/cli-error.mjs';
19
19
  import {defineCommand} from '../../lib/define-command.mjs';
20
20
  import {resultSet} from '../../../../foundation/debug/index.mjs';
@@ -103,6 +103,7 @@ export function registerHook(program) {
103
103
  // ── Text output ────────────────────────────────────────────
104
104
  switch (result.type) {
105
105
  case 'hook.list': {
106
+ emit(record({package: result.package}));
106
107
  // One list type across all three detail levels; the depth is carried
107
108
  // in result.data.detail and the grouped map in result.data.components.
108
109
  if (result.data.detail === 'full') {
@@ -172,6 +173,7 @@ export function registerHook(program) {
172
173
  // under `component <name> --blocks`.
173
174
  const related = result.data.relatedComponents ?? [];
174
175
  emit(
176
+ record({package: result.package}),
175
177
  code(doc),
176
178
  related.length > 0 &&
177
179
  text(
@@ -182,7 +184,10 @@ export function registerHook(program) {
182
184
  }
183
185
 
184
186
  case 'hook.detail.params': {
185
- emit(code(formatHookParams({params: result.data, name})));
187
+ emit(
188
+ record({package: result.package}),
189
+ code(formatHookParams({params: result.data, name})),
190
+ );
186
191
  break;
187
192
  }
188
193
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {jsonOut} from '../../../foundation/response/json.mjs';
14
- import {emit, section, list, text, WARN} from '../formatters/index.mjs';
14
+ import {emit, section, list, text, WARN, record} from '../formatters/index.mjs';
15
15
  import {cliError} from '../lib/cli-error.mjs';
16
16
  import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
17
17
  import {swizzle as swizzleApi} from '../../../api/swizzle/swizzle.mjs';
@@ -60,6 +60,7 @@ export function registerSwizzle(program) {
60
60
  if (result.type === 'swizzle.list') {
61
61
  const components = result.data;
62
62
  emit(
63
+ record({package: result.package}),
63
64
  section('Available components'),
64
65
  list(components),
65
66
  text(`Usage: ${run} swizzle <component>`),
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import {jsonOut} from '../../../foundation/response/json.mjs';
8
- import {emit, section, text, records, code} from '../formatters/index.mjs';
8
+ import {emit, section, text, records, code, record} from '../formatters/index.mjs';
9
9
  import {cliError} from '../lib/cli-error.mjs';
10
10
  import {template as templateApi} from '../../../api/template/template.mjs';
11
11
  import {Project} from '../../../foundation/config/project.mjs';
@@ -146,6 +146,7 @@ export function registerTemplate(program) {
146
146
  case 'template.skeleton': {
147
147
  const {template: tName, description, components, skeleton} = result.data;
148
148
  emit(
149
+ record({package: result.package}),
149
150
  text(
150
151
  `# ${tName}${description ? ' — ' + description : ''}\n` +
151
152
  `# Components: ${components.join(', ')}`,
@@ -156,10 +157,12 @@ export function registerTemplate(program) {
156
157
  }
157
158
 
158
159
  case 'template.show': {
159
- // Source must survive piping byte-for-byte, so the note about
160
- // replaced demo media goes to stderr, in the copy receipt's words.
161
- // (Text mode only: --json returned above with the count in data.)
160
+ // Source must survive piping byte-for-byte, so the package it comes
161
+ // from (cli-surface INV28) and the note about replaced demo media go
162
+ // to stderr, the note in the copy receipt's words. (Text mode only:
163
+ // --json returned above with both in the envelope.)
162
164
  const {source, demoMediaReplaced} = result.data;
165
+ console.error(`package: ${result.package}`);
163
166
  emit(code(source));
164
167
  if (demoMediaReplaced > 0) {
165
168
  console.error(
@@ -175,6 +178,7 @@ export function registerTemplate(program) {
175
178
  const file = `${outputDir}/${fileName}`;
176
179
  emit(
177
180
  text(`Copied template to ${file}`),
181
+ record({package: result.package}),
178
182
  demoMediaReplaced > 0 &&
179
183
  text(
180
184
  `Replaced ${demoMediaReplaced} Astryx demo media reference${demoMediaReplaced === 1 ? '' : 's'} in ${file}: ` +
@@ -35,6 +35,17 @@ import {runCli} from '../../../test-utils/run-cli.mjs';
35
35
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
36
36
  const REPO_ROOT = path.resolve(__dirname, '../../../../..');
37
37
 
38
+ /**
39
+ * Response types whose text output is the artifact's source, printed byte for
40
+ * byte so it can be piped (spec cli-surface INV28). Their JSON still names the
41
+ * package; their text does not.
42
+ */
43
+ const VERBATIM_TYPES = new Set([
44
+ 'component.detail.source',
45
+ 'component.detail.showcase',
46
+ 'template.show',
47
+ ]);
48
+
38
49
  // ─── Helpers ────────────────────────────────────────────────────────────────
39
50
 
40
51
  /**
@@ -561,6 +572,15 @@ describe('text-json-parity', () => {
561
572
  expect(run.textStatus).toBe(run.jsonStatus);
562
573
  });
563
574
 
575
+ // spec cli-surface INV28: text names the package the envelope names.
576
+ // Verbatim source output prints only the source, so a pipe gets the
577
+ // file byte for byte.
578
+ it('text names the package the JSON envelope names', () => {
579
+ if (run.json?.package === undefined) return;
580
+ if (VERBATIM_TYPES.has(run.json.type)) return;
581
+ expect(run.text).toContain(run.json.package);
582
+ });
583
+
564
584
  if (!tc.skipFieldChecks && !tc.errorExpected) {
565
585
  it('every text record key exists in the JSON data', () => {
566
586
  if (!run.json?.data) return;
@@ -569,6 +589,8 @@ describe('text-json-parity', () => {
569
589
  if (run.json.meta) {
570
590
  for (const k of jsonLeafKeys(run.json.meta)) jsonKeys.add(k);
571
591
  }
592
+ // The envelope's own `package` (spec cli-surface INV28) is JSON too.
593
+ if (run.json.package !== undefined) jsonKeys.add('package');
572
594
  const violations = [];
573
595
  for (const key of textKeys.keys()) {
574
596
  if (!jsonKeys.has(key)) {
@@ -69,7 +69,7 @@ export function registerUpgrade(program) {
69
69
  emit(
70
70
  section('Available codemods'),
71
71
  records(result.data, {
72
- fields: ['name', 'title', 'version', 'optional'],
72
+ fields: ['name', 'package', 'title', 'version', 'optional'],
73
73
  }),
74
74
  );
75
75
  }
@@ -366,7 +366,7 @@ export async function createProgram() {
366
366
  )
367
367
  .option(
368
368
  '--json',
369
- 'Output as typed JSON. Success envelope: { apiVersion, type, data, meta? }. Error envelope: { apiVersion, error, code, suggestions? }.',
369
+ 'Output as typed JSON. Success envelope: { apiVersion, type, package?, data, meta? }. Error envelope: { apiVersion, error, code, suggestions? }.',
370
370
  )
371
371
  .addHelpCommand('help', 'Show all commands')
372
372
  .action((options, cmd) => {
@@ -9,10 +9,14 @@
9
9
  */
10
10
  export function docPayloadBytes(payload: unknown): number;
11
11
  /**
12
- * @param {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links'> | import('../../api/docs/docs.type.mjs').DocsIndex} index
12
+ * @param {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links' | 'sections'> & {sections: import('../../api/docs/docs.type.mjs').DocsIndexEntry[], links?: import('../../api/docs/docs.type.mjs').DocsLinks}} index
13
+ * an index, with or without its links; its sections may or may not name their package
13
14
  * @returns {number}
14
15
  */
15
- export function docsIndexBytes(index: Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links"> | import("../../api/docs/docs.type.mjs").DocsIndex): number;
16
+ export function docsIndexBytes(index: Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links" | "sections"> & {
17
+ sections: import("../../api/docs/docs.type.mjs").DocsIndexEntry[];
18
+ links?: import("../../api/docs/docs.type.mjs").DocsLinks;
19
+ }): number;
16
20
  /**
17
21
  * The sections a single read would return more than `budget` bytes for.
18
22
  * @param {any[]} sections
@@ -26,7 +26,8 @@ export function docPayloadBytes(payload) {
26
26
  }
27
27
 
28
28
  /**
29
- * @param {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links'> | import('../../api/docs/docs.type.mjs').DocsIndex} index
29
+ * @param {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links' | 'sections'> & {sections: import('../../api/docs/docs.type.mjs').DocsIndexEntry[], links?: import('../../api/docs/docs.type.mjs').DocsLinks}} index
30
+ * an index, with or without its links; its sections may or may not name their package
30
31
  * @returns {number}
31
32
  */
32
33
  export function docsIndexBytes(index) {
@@ -91,14 +91,16 @@ export function sectionSummary(section: any, max?: number): string;
91
91
  * The index a topic-only read returns: what the topic is, and one entry per
92
92
  * section with the key to read it by.
93
93
  * @param {{name: string, title: string, description: string, sections: any[]}} doc
94
- * @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links'>}
94
+ * @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links' | 'sections'> & {sections: import('../../api/docs/docs.type.mjs').DocsIndexEntry[]}}
95
95
  */
96
96
  export function buildDocsIndexData(doc: {
97
97
  name: string;
98
98
  title: string;
99
99
  description: string;
100
100
  sections: any[];
101
- }): Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links">;
101
+ }): Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links" | "sections"> & {
102
+ sections: import("../../api/docs/docs.type.mjs").DocsIndexEntry[];
103
+ };
102
104
  /**
103
105
  * @file Stable section keys, section lookup, and the topic index.
104
106
  *
@@ -306,7 +306,7 @@ export function sectionSummary(section, max = SECTION_SUMMARY_MAX) {
306
306
  * The index a topic-only read returns: what the topic is, and one entry per
307
307
  * section with the key to read it by.
308
308
  * @param {{name: string, title: string, description: string, sections: any[]}} doc
309
- * @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links'>}
309
+ * @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links' | 'sections'> & {sections: import('../../api/docs/docs.type.mjs').DocsIndexEntry[]}}
310
310
  */
311
311
  export function buildDocsIndexData(doc) {
312
312
  return {
@@ -20,9 +20,11 @@ export function detailView(node: import("./compile.mjs").CompiledReferenceNode):
20
20
  * `docs.index`: what the topic is, and each section's key, title and summary.
21
21
  * The index leaf adds the moves.
22
22
  * @param {import('./compile.mjs').CompiledReferenceNode} node
23
- * @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links'>}
23
+ * @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links' | 'sections'> & {sections: import('../../api/docs/docs.type.mjs').DocsIndexEntry[]}}
24
24
  */
25
- export function indexView(node: import("./compile.mjs").CompiledReferenceNode): Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links">;
25
+ export function indexView(node: import("./compile.mjs").CompiledReferenceNode): Omit<import("../../api/docs/docs.type.mjs").DocsIndex, "links" | "sections"> & {
26
+ sections: import("../../api/docs/docs.type.mjs").DocsIndexEntry[];
27
+ };
26
28
  /**
27
29
  * `docs.detail.section`: one section with its token references and reference
28
30
  * blocks inlined, so a read returns only the stable block kinds. A referenced
@@ -64,7 +64,7 @@ export function detailView(node) {
64
64
  * `docs.index`: what the topic is, and each section's key, title and summary.
65
65
  * The index leaf adds the moves.
66
66
  * @param {import('./compile.mjs').CompiledReferenceNode} node
67
- * @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links'>}
67
+ * @returns {Omit<import('../../api/docs/docs.type.mjs').DocsIndex, 'links' | 'sections'> & {sections: import('../../api/docs/docs.type.mjs').DocsIndexEntry[]}}
68
68
  */
69
69
  export function indexView(node) {
70
70
  return buildDocsIndexData(node.doc);
@@ -44,15 +44,21 @@ export interface CLIUnsupportedError {
44
44
  }
45
45
 
46
46
  /**
47
- * A success response: a `type` discriminator, its `data` payload, and an
48
- * optional `meta` sidecar (emitted as a sibling of `data`, never merged in).
49
- * `--json` prints it with `apiVersion` added (see `parseResponse`).
47
+ * A success response: a `type` discriminator, the `package` that owns what the
48
+ * response is about, its `data` payload, and an optional `meta` sidecar
49
+ * (emitted as a sibling of `data`, never merged in). `--json` prints it with
50
+ * `apiVersion` added (see `parseResponse`).
51
+ *
52
+ * `package` is present when the response is about one thing: one component,
53
+ * one doc, one template. A response that lists things from more than one
54
+ * package leaves it out, and each listed item names its own `package`.
50
55
  *
51
56
  * Structural by design — there is no central union of every response `type`.
52
57
  * A specific command narrows `data` via its own return type.
53
58
  */
54
59
  export interface CLIResponse {
55
60
  type: string;
61
+ package?: string;
56
62
  data: unknown;
57
63
  meta?: Record<string, unknown>;
58
64
  }
@@ -31,15 +31,18 @@ export function humanWarn(...args: unknown[]): void;
31
31
  * Output a JSON response envelope and mark it handled.
32
32
  *
33
33
  * Structural serializer: pass a command/API result straight through as
34
- * `{type, data, meta?}`. There is no central response union — the correctness
35
- * of the `type` discriminator is guaranteed at each API function's `@returns`
36
- * (that's the fractal source-of-truth point), not by a map in this file.
34
+ * `{type, package?, data, meta?}`. There is no central response union — the
35
+ * correctness of the `type` discriminator is guaranteed at each API function's
36
+ * `@returns` (that's the fractal source-of-truth point), not by a map in this
37
+ * file. `package` names the npm package that owns the one thing the result is
38
+ * about (spec cli-surface INV28); it is written directly after `type`.
37
39
  *
38
- * @param {{type: string, data: unknown, meta?: Record<string, unknown>}} response
40
+ * @param {{type: string, package?: string, data: unknown, meta?: Record<string, unknown>}} response
39
41
  * @returns {void}
40
42
  */
41
43
  export function jsonOut(response: {
42
44
  type: string;
45
+ package?: string;
43
46
  data: unknown;
44
47
  meta?: Record<string, unknown>;
45
48
  }): void;
@@ -7,7 +7,7 @@
7
7
  * The contract has four guarantees, enforced here and in index.mjs:
8
8
  *
9
9
  * 1. EVERY emission in --json mode is a single valid JSON envelope.
10
- * Success: { apiVersion, type, data }
10
+ * Success: { apiVersion, type, package?, data, meta? }
11
11
  * Error: { apiVersion, error, code, suggestions? }
12
12
  * The `code` is a stable, machine-readable identifier (see
13
13
  * error-codes.mjs). Consumers should branch on `code`, never on the
@@ -87,16 +87,20 @@ export function humanWarn(...args) {
87
87
  * Output a JSON response envelope and mark it handled.
88
88
  *
89
89
  * Structural serializer: pass a command/API result straight through as
90
- * `{type, data, meta?}`. There is no central response union — the correctness
91
- * of the `type` discriminator is guaranteed at each API function's `@returns`
92
- * (that's the fractal source-of-truth point), not by a map in this file.
90
+ * `{type, package?, data, meta?}`. There is no central response union — the
91
+ * correctness of the `type` discriminator is guaranteed at each API function's
92
+ * `@returns` (that's the fractal source-of-truth point), not by a map in this
93
+ * file. `package` names the npm package that owns the one thing the result is
94
+ * about (spec cli-surface INV28); it is written directly after `type`.
93
95
  *
94
- * @param {{type: string, data: unknown, meta?: Record<string, unknown>}} response
96
+ * @param {{type: string, package?: string, data: unknown, meta?: Record<string, unknown>}} response
95
97
  * @returns {void}
96
98
  */
97
99
  export function jsonOut(response) {
98
100
  /** @type {any} */
99
- const envelope = {apiVersion: API_VERSION, type: response.type, data: response.data};
101
+ const envelope = {apiVersion: API_VERSION, type: response.type};
102
+ if (response.package !== undefined) envelope.package = response.package;
103
+ envelope.data = response.data;
100
104
  if (response.meta !== undefined) envelope.meta = response.meta;
101
105
  // Serialize BEFORE marking handled. If JSON.stringify throws (a circular
102
106
  // reference or a BigInt in `data` — an author bug in a command's return