@atlaskit/ads-cli 0.7.0 → 0.8.0

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 (34) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +35 -7
  3. package/bin/ads-cli.js +6 -4
  4. package/dist/cjs/cli.js +19 -3
  5. package/dist/cjs/commands/definitions.js +29 -3
  6. package/dist/cjs/output/compact-results.js +119 -0
  7. package/dist/cjs/output/format-doc-object.js +18 -5
  8. package/dist/cjs/output/format-icon.js +2 -1
  9. package/dist/cjs/output/format-results.js +37 -71
  10. package/dist/cjs/output/format-token.js +19 -5
  11. package/dist/cjs/output/write-json-envelope.js +2 -1
  12. package/dist/es2019/cli.js +19 -3
  13. package/dist/es2019/commands/definitions.js +31 -3
  14. package/dist/es2019/output/compact-results.js +104 -0
  15. package/dist/es2019/output/format-doc-object.js +12 -4
  16. package/dist/es2019/output/format-icon.js +2 -1
  17. package/dist/es2019/output/format-results.js +37 -66
  18. package/dist/es2019/output/format-token.js +14 -5
  19. package/dist/es2019/output/write-json-envelope.js +2 -1
  20. package/dist/esm/cli.js +19 -3
  21. package/dist/esm/commands/definitions.js +29 -3
  22. package/dist/esm/output/compact-results.js +112 -0
  23. package/dist/esm/output/format-doc-object.js +18 -5
  24. package/dist/esm/output/format-icon.js +2 -1
  25. package/dist/esm/output/format-results.js +37 -71
  26. package/dist/esm/output/format-token.js +19 -5
  27. package/dist/esm/output/write-json-envelope.js +2 -1
  28. package/dist/types/commands/types.d.ts +8 -8
  29. package/dist/types/envelope/types.d.ts +3 -2
  30. package/dist/types/output/compact-results.d.ts +41 -0
  31. package/dist/types/output/format-results.d.ts +3 -3
  32. package/dist/types/output/format-token.d.ts +3 -3
  33. package/dist/types/output/write-json-envelope.d.ts +2 -1
  34. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,68 @@
1
1
  # @atlaskit/ads-cli
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`7b42e3dbea8db`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7b42e3dbea8db) -
8
+ Several updates to the ADS CLI output.
9
+
10
+ **`--json` contract change:** `search --json` and `component|token|icon --all --json` now return
11
+ concise summaries for each result.
12
+ - Component JSON summaries replace `props` and `examples` with `propCount` and `exampleCount`, and
13
+ omit `designSource` and other detail-only metadata.
14
+ - Token `--all --json` summaries omit `usageGuidelines`.
15
+ - Icon `--all --json` summaries omit fields such as `keywords`, `categorization`, `team`,
16
+ `status`, and `shouldRecommendSmallIcon`.
17
+
18
+ For example, a component result from `ads-cli search avatar --json` changes from a detailed
19
+ record:
20
+
21
+ ```jsonc
22
+ {
23
+ "name": "Avatar",
24
+ "package": "@atlaskit/avatar",
25
+ "props": [
26
+ /* ... */
27
+ ],
28
+ "examples": [
29
+ /* ... */
30
+ ],
31
+ "designSource": {
32
+ /* ... */
33
+ },
34
+ }
35
+ ```
36
+
37
+ to a compact summary:
38
+
39
+ ```json
40
+ {
41
+ "name": "Avatar",
42
+ "package": "@atlaskit/avatar",
43
+ "propCount": 21,
44
+ "exampleCount": 1,
45
+ "followUp": "component Avatar"
46
+ }
47
+ ```
48
+
49
+ The fields omitted from the summary are available by running the individual command, for example
50
+ `ads-cli component Avatar --json`.
51
+
52
+ Other changes:
53
+ - Search JSON summaries include a `followUp` command for retrieving the individual record.
54
+ - Individual token JSON (`token <name> --json`) now includes usage guidelines and an actionable
55
+ `usage` value. Previously, usage guidelines were only available through `token --all --json`.
56
+ - Human-readable token details now surface usage guidelines; the actionable usage line was already
57
+ present.
58
+ - Icon details (`icon <name>`) now include an import statement for `--json` mode.
59
+ - Human-readable migration guides now preserve before/after steps.
60
+ - Large JSON responses are allowed to drain before exit.
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies
65
+
3
66
  ## 0.7.0
4
67
 
5
68
  ### Minor Changes
package/README.md CHANGED
@@ -26,7 +26,7 @@ The CLI has these commands:
26
26
  | `search <query...>` | **Unified** fuzzy-search across components, tokens, icons, and foundations docs at once. Narrow results with `--type component\|token\|icon\|docs`; limit with `--limit N`. |
27
27
  | `batch --command <command> [args...]...` | Run multiple ADS CLI queries, including different command types, in one process. Repeat `--command` once per child; each keeps its normal arguments, flags, and response envelope. Tokenized requests are canonical; complete quoted requests are also accepted. |
28
28
  | `component <name>` | Detail for a single component. Exact name → detail; ambiguous → a "did you mean?" list. `--all` lists every component. |
29
- | `token <name>` | Detail for a single token. Exact name → detail; ambiguous → a "did you mean?" list. `--all` lists every token. |
29
+ | `token <name>` | Full detail for a single token, including usage guidelines. Exact name → detail; ambiguous → a "did you mean?" list. `--all` lists every token as a concise summary. |
30
30
  | `icon <name>` | Detail for a single icon (with a copy-paste import). Exact name → detail; ambiguous → a "did you mean?" list. `--all` lists every icon. |
31
31
  | `lint-rules [term...]` | ADS ESLint rules. A term that matches one rule (exactly or uniquely) prints its docs; several matches show a "did you mean?" list. Bare `lint-rules` prints every rule; `--limit N` caps the candidate list. |
32
32
  | `docs <topic...>` | Read ADS reference docs. Three forms:<br>• `docs <term...>` — foundations guidelines (spacing, color, …)<br>• `docs a11y [topic]` — accessibility guidance (optional topic e.g. `buttons`, `forms`, `colors`)<br>• `docs migration <id>` — a structured migration guide |
@@ -91,7 +91,13 @@ npx @atlaskit/ads-cli manifest --json
91
91
  prints the full matched Markdown. `component`/`token`/`icon` print a readable detail view (the
92
92
  icon view includes a copy-paste `import` line); `docs` (`foundations`, `a11y`, and `migration`)
93
93
  and `lint-rules` print prose/Markdown. A raw JSON dump is only ever a last-resort fallback for an
94
- unrecognised shape. For the **full structured payload**, use `--json`.
94
+ unrecognised shape.
95
+ - **Structured output mirrors the human retrieval budget.** Search and `--all` responses contain the
96
+ same compact fields shown by the human rows rather than embedding every component prop and
97
+ example. Each search record includes a machine-readable `followUp`; run that exact detail command
98
+ for the full component, token, or icon data. Exact detail commands retain the information shown by
99
+ their human view, including token `usageGuidelines` and `usage`, and an icon `import`.
100
+ `manifest --json` is the intentional exception: it remains the full CLI contract.
95
101
  - **Lookups never silently guess.** `component`/`token`/`icon <name>` — and a fuzzy
96
102
  `lint-rules <term>` — render the entry whose name matches exactly (case-insensitively). If there
97
103
  is no exact match but several candidates, they print a `Did you mean?` list (each with a
@@ -114,7 +120,7 @@ npx @atlaskit/ads-cli manifest --json
114
120
  - **The manifest is derived from the live command registry.** `manifest --json` lists every command,
115
121
  positional argument, flag, example, and success response type without maintaining a separate copy
116
122
  of the CLI surface.
117
- - With `--json`, every success prints a `SuccessEnvelope` and every failure prints an
123
+ - With `--json`, every success prints a formatted `SuccessEnvelope` and every failure prints an
118
124
  `ErrorEnvelope`:
119
125
 
120
126
  ```jsonc
@@ -124,9 +130,23 @@ npx @atlaskit/ads-cli manifest --json
124
130
  "command": "search",
125
131
  "ok": true,
126
132
  "data": {
127
- "components": [ /* … */ ],
128
- "tokens": [ /* … */ ],
129
- "icons": [ /* … */ ],
133
+ "components": [
134
+ {
135
+ "name": "Button",
136
+ "package": "@atlaskit/button",
137
+ "propCount": 13,
138
+ "exampleCount": 3,
139
+ "followUp": "component Button"
140
+ }
141
+ ],
142
+ "tokens": [
143
+ {
144
+ "name": "motion.button.hovered",
145
+ "exampleValue": "background-color 150ms cubic-bezier(0.4, 1, 0.6, 1)",
146
+ "followUp": "token motion.button.hovered"
147
+ }
148
+ ],
149
+ "icons": [],
130
150
  "docs": [
131
151
  {
132
152
  "title": "Button",
@@ -143,7 +163,15 @@ npx @atlaskit/ads-cli manifest --json
143
163
  "type": "ads-cli/search-components",
144
164
  "command": "search",
145
165
  "ok": true,
146
- "data": [ /* tool output */ ],
166
+ "data": [
167
+ {
168
+ "name": "Avatar",
169
+ "package": "@atlaskit/avatar",
170
+ "propCount": 7,
171
+ "exampleCount": 1,
172
+ "followUp": "component Avatar"
173
+ }
174
+ ],
147
175
  "meta": { "terms": ["avatar"], "limit": 5, "count": 2 }
148
176
  }
149
177
 
package/bin/ads-cli.js CHANGED
@@ -31,14 +31,16 @@ const invocation = process.env.ADS_CLI_DISPLAY_INVOCATION || 'npx @atlaskit/ads-
31
31
  require(path.join('..', isDev ? 'src/cli' : 'dist/cjs/cli'))
32
32
  .run(process.argv.slice(2), undefined, { invocation })
33
33
  .then((exitCode) => {
34
- // A resolved numeric value is treated as an explicit exit code.
35
- process.exit(typeof exitCode === 'number' ? exitCode : 0);
34
+ // Set the eventual exit code without forcing the process to stop. A forced `process.exit()` can
35
+ // truncate output that is still draining to a pipe (for example, `icon --all --json`).
36
+ process.exitCode = typeof exitCode === 'number' ? exitCode : 0;
36
37
  })
37
38
  .catch((error) => {
38
39
  // A thrown number is treated as an explicit exit code (e.g. usage errors).
39
40
  if (typeof error === 'number') {
40
- process.exit(error);
41
+ process.exitCode = error;
42
+ return;
41
43
  }
42
44
  console.error(error);
43
- process.exit(1);
45
+ process.exitCode = 1;
44
46
  });
package/dist/cjs/cli.js CHANGED
@@ -18,6 +18,7 @@ var _importToolHandler = require("./commands/import-tool-handler");
18
18
  var _runTool = require("./commands/run-tool");
19
19
  var _createErrorEnvelope = require("./envelope/create-error-envelope");
20
20
  var _createSuccessEnvelope = require("./envelope/create-success-envelope");
21
+ var _compactResults3 = require("./output/compact-results");
21
22
  var _createDocSearchResults = require("./output/create-doc-search-results");
22
23
  var _disambiguation = require("./output/disambiguation");
23
24
  var _formatGroupedResults = require("./output/format-grouped-results");
@@ -344,11 +345,18 @@ var renderSingleResult = function renderSingleResult(_ref8) {
344
345
  input: input
345
346
  }) : result.data;
346
347
  if (json) {
348
+ var _command$resultKind2, _compactResults;
349
+ var resultKind = (_command$resultKind2 = command.resultKind) === null || _command$resultKind2 === void 0 ? void 0 : _command$resultKind2.call(command, input);
350
+ var outputData = resultKind ? (_compactResults = (0, _compactResults3.compactResults)({
351
+ kind: resultKind,
352
+ data: data,
353
+ showFollowUp: command.name === 'search'
354
+ })) !== null && _compactResults !== void 0 ? _compactResults : data : data;
347
355
  (0, _writeJsonEnvelope.writeJsonEnvelope)({
348
356
  envelope: (0, _createSuccessEnvelope.createSuccessEnvelope)({
349
357
  envelopeType: command.envelopeType(input),
350
358
  command: command.name,
351
- data: data,
359
+ data: outputData,
352
360
  meta: meta
353
361
  }),
354
362
  writer: writer
@@ -640,6 +648,14 @@ var renderGroupedResult = function renderGroupedResult(_ref12) {
640
648
  }
641
649
  return _types.ExitCode.NotFound;
642
650
  }
651
+ var compactGrouped = Object.fromEntries(['components', 'tokens', 'icons', 'docs'].map(function (kind) {
652
+ var _compactResults2, _grouped$kind;
653
+ return [kind, (_compactResults2 = (0, _compactResults3.compactResults)({
654
+ kind: kind,
655
+ data: (_grouped$kind = grouped[kind]) !== null && _grouped$kind !== void 0 ? _grouped$kind : [],
656
+ showFollowUp: true
657
+ })) !== null && _compactResults2 !== void 0 ? _compactResults2 : []];
658
+ }));
643
659
  if (json) {
644
660
  (0, _writeJsonEnvelope.writeJsonEnvelope)({
645
661
  envelope: (0, _createSuccessEnvelope.createSuccessEnvelope)({
@@ -647,7 +663,7 @@ var renderGroupedResult = function renderGroupedResult(_ref12) {
647
663
  command: command.name,
648
664
  // `data` for grouped commands is `{ components, tokens, icons, docs }` (already
649
665
  // counted per group), so `count` is the combined total across groups.
650
- data: grouped,
666
+ data: compactGrouped,
651
667
  meta: _objectSpread(_objectSpread({}, meta), {}, {
652
668
  count: totalCount
653
669
  })
@@ -657,7 +673,7 @@ var renderGroupedResult = function renderGroupedResult(_ref12) {
657
673
  return _types.ExitCode.Ok;
658
674
  }
659
675
  writer.out((0, _formatGroupedResults.formatGroupedResults)({
660
- groups: grouped,
676
+ groups: compactGrouped,
661
677
  totalCount: totalCount,
662
678
  invocation: invocation
663
679
  }));
@@ -299,6 +299,28 @@ var EXAMPLE_NAME = {
299
299
  icons: 'AddIcon'
300
300
  };
301
301
 
302
+ /**
303
+ * Add the actionable fields that exact human detail views derive from the raw record. Including
304
+ * them in JSON keeps both representations content-equivalent without requiring consumers to know
305
+ * ADS import or token-call conventions.
306
+ */
307
+ var addActionableDetail = function addActionableDetail(kind, item) {
308
+ if (kind === 'tokens') {
309
+ var name = itemFields.tokens.nameOf(item);
310
+ return name ? _objectSpread(_objectSpread({}, item), {}, {
311
+ usage: "token('".concat(name, "')")
312
+ }) : item;
313
+ }
314
+ if (kind === 'icons') {
315
+ var componentName = itemFields.icons.nameOf(item);
316
+ var packageName = typeof item.package === 'string' ? item.package : undefined;
317
+ return componentName && packageName ? _objectSpread(_objectSpread({}, item), {}, {
318
+ import: "import ".concat(componentName, " from '").concat(packageName, "';")
319
+ }) : item;
320
+ }
321
+ return item;
322
+ };
323
+
302
324
  /**
303
325
  * Build one of the singular item commands (`component <name>`, `token <name>`, `icon <name>`).
304
326
  *
@@ -369,11 +391,11 @@ var makeItemCommand = function makeItemCommand(_ref3) {
369
391
  return nameOf(item).toLowerCase() === query.toLowerCase();
370
392
  });
371
393
  if (exact) {
372
- return exact;
394
+ return addActionableDetail(kind, exact);
373
395
  }
374
396
  // A single candidate is unambiguous — show it.
375
397
  if (candidates.length === 1) {
376
- return candidates[0];
398
+ return addActionableDetail(kind, candidates[0]);
377
399
  }
378
400
  // Otherwise do not guess: surface a disambiguation list.
379
401
  return {
@@ -413,7 +435,11 @@ var makeItemCommand = function makeItemCommand(_ref3) {
413
435
  return singleTool({
414
436
  importPath: searchTool.importPath,
415
437
  handlerName: searchTool.handlerName,
416
- args: {
438
+ args: kind === 'tokens' ? {
439
+ terms: [name_],
440
+ limit: ITEM_LOOKUP_LIMIT,
441
+ includeMetadata: true
442
+ } : {
417
443
  terms: [name_],
418
444
  limit: ITEM_LOOKUP_LIMIT
419
445
  },
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.compactResults = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ /**
13
+ * Shared compact projections for ADS search and list results.
14
+ *
15
+ * Human-readable rows and `--json` responses both consume these records. Keeping the projection in
16
+ * one place prevents the machine-readable output from silently expanding back to the underlying
17
+ * MCP payload (for example, every component prop and example during discovery).
18
+ */
19
+
20
+ var countOf = function countOf(value) {
21
+ return Array.isArray(value) ? value.length : 0;
22
+ };
23
+
24
+ /**
25
+ * Truncate a one-line value so discovery results stay bounded. Exact detail commands preserve the
26
+ * full value.
27
+ */
28
+ var truncateCompactText = function truncateCompactText(text) {
29
+ var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 80;
30
+ var oneLine = text.replace(/\s+/g, ' ').trim();
31
+ return oneLine.length > max ? "".concat(oneLine.slice(0, max - 1).trimEnd(), "\u2026") : oneLine;
32
+ };
33
+ var asRecord = function asRecord(value) {
34
+ return value !== null && (0, _typeof2.default)(value) === 'object' ? value : {};
35
+ };
36
+ var optionalString = function optionalString(value) {
37
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
38
+ };
39
+ var withFollowUp = function withFollowUp(result, showFollowUp, followUp) {
40
+ return showFollowUp ? _objectSpread(_objectSpread({}, result), {}, {
41
+ followUp: followUp
42
+ }) : result;
43
+ };
44
+ var compactComponent = function compactComponent(value, showFollowUp) {
45
+ var _optionalString, _optionalString2;
46
+ var record = asRecord(value);
47
+ var name = (_optionalString = optionalString(record.name)) !== null && _optionalString !== void 0 ? _optionalString : '(unknown)';
48
+ var propCount = typeof record.propCount === 'number' ? record.propCount : countOf(record.props);
49
+ var exampleCount = typeof record.exampleCount === 'number' ? record.exampleCount : countOf(record.examples);
50
+ return withFollowUp(_objectSpread(_objectSpread({
51
+ name: name
52
+ }, optionalString(record.package) ? {
53
+ package: String(record.package)
54
+ } : {}), {}, {
55
+ propCount: propCount,
56
+ exampleCount: exampleCount
57
+ }), showFollowUp, (_optionalString2 = optionalString(record.followUp)) !== null && _optionalString2 !== void 0 ? _optionalString2 : "component ".concat(name));
58
+ };
59
+ var compactToken = function compactToken(value, showFollowUp) {
60
+ var _optionalString3, _optionalString4;
61
+ var record = asRecord(value);
62
+ var name = (_optionalString3 = optionalString(record.name)) !== null && _optionalString3 !== void 0 ? _optionalString3 : '(unknown)';
63
+ var exampleValue = optionalString(record.exampleValue);
64
+ return withFollowUp(_objectSpread({
65
+ name: name
66
+ }, exampleValue ? {
67
+ exampleValue: truncateCompactText(exampleValue)
68
+ } : {}), showFollowUp, (_optionalString4 = optionalString(record.followUp)) !== null && _optionalString4 !== void 0 ? _optionalString4 : "token ".concat(name));
69
+ };
70
+ var compactIcon = function compactIcon(value, showFollowUp) {
71
+ var _optionalString5, _optionalString6;
72
+ var record = asRecord(value);
73
+ var componentName = (_optionalString5 = optionalString(record.componentName)) !== null && _optionalString5 !== void 0 ? _optionalString5 : '(unknown)';
74
+ var usage = optionalString(record.usage);
75
+ return withFollowUp(_objectSpread(_objectSpread({
76
+ componentName: componentName
77
+ }, optionalString(record.package) ? {
78
+ package: String(record.package)
79
+ } : {}), usage ? {
80
+ usage: truncateCompactText(usage)
81
+ } : {}), showFollowUp, (_optionalString6 = optionalString(record.followUp)) !== null && _optionalString6 !== void 0 ? _optionalString6 : "icon ".concat(componentName));
82
+ };
83
+ var compactDoc = function compactDoc(value, showFollowUp) {
84
+ var _optionalString7, _optionalString8;
85
+ var record = asRecord(value);
86
+ var title = (_optionalString7 = optionalString(record.title)) !== null && _optionalString7 !== void 0 ? _optionalString7 : '(unknown)';
87
+ var summary = optionalString(record.summary);
88
+ return withFollowUp(_objectSpread({
89
+ title: title
90
+ }, summary ? {
91
+ summary: truncateCompactText(summary)
92
+ } : {}), showFollowUp, (_optionalString8 = optionalString(record.followUp)) !== null && _optionalString8 !== void 0 ? _optionalString8 : "docs ".concat(title.toLowerCase()));
93
+ };
94
+
95
+ /**
96
+ * Project raw MCP rows into the compact records shared by human and JSON output. The function is
97
+ * idempotent so batch rendering can safely receive child envelopes that were already compacted.
98
+ */
99
+ var compactResults = exports.compactResults = function compactResults(_ref) {
100
+ var kind = _ref.kind,
101
+ data = _ref.data,
102
+ _ref$showFollowUp = _ref.showFollowUp,
103
+ showFollowUp = _ref$showFollowUp === void 0 ? false : _ref$showFollowUp;
104
+ if (!Array.isArray(data)) {
105
+ return null;
106
+ }
107
+ return data.map(function (entry) {
108
+ switch (kind) {
109
+ case 'components':
110
+ return compactComponent(entry, showFollowUp);
111
+ case 'tokens':
112
+ return compactToken(entry, showFollowUp);
113
+ case 'icons':
114
+ return compactIcon(entry, showFollowUp);
115
+ case 'docs':
116
+ return compactDoc(entry, showFollowUp);
117
+ }
118
+ });
119
+ };
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.formatDocObject = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
11
  /**
12
12
  * Human-readable renderer for a single "doc object" payload — the shape returned by the
@@ -46,12 +46,25 @@ var formatListItem = function formatListItem(item) {
46
46
  if (item !== null && (0, _typeof2.default)(item) === 'object') {
47
47
  var record = item;
48
48
  var title = typeof record.title === 'string' ? record.title : null;
49
- var code = ['code', 'before', 'after'].find(function (key) {
49
+ var codeKeys = ['code', 'before', 'after'].filter(function (key) {
50
50
  return typeof record[key] === 'string';
51
51
  });
52
- if (title && code) {
53
- var description = typeof record.description === 'string' ? "\n ".concat(oneLine(record.description)) : '';
54
- return " - ".concat(title).concat(description, "\n ```tsx\n").concat(record[code], "\n ```");
52
+ if (title && codeKeys.length > 0) {
53
+ var description = typeof record.description === 'string' ? [" ".concat(oneLine(record.description))] : [];
54
+ var labelCodeBlocks = codeKeys.length > 1 || codeKeys[0] !== 'code';
55
+ var codeBlocks = codeKeys.flatMap(function (key) {
56
+ return [].concat((0, _toConsumableArray2.default)(labelCodeBlocks ? [" ".concat(humanizeKey(key), ":")] : []), [" ```tsx\n".concat(record[key], "\n ```")]);
57
+ });
58
+ var additionalFields = Object.entries(record).flatMap(function (_ref) {
59
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
60
+ key = _ref2[0],
61
+ value = _ref2[1];
62
+ if (['title', 'description'].concat((0, _toConsumableArray2.default)(codeKeys)).includes(key) || value === null || value === undefined) {
63
+ return [];
64
+ }
65
+ return [" ".concat(humanizeKey(key), ": ").concat(typeof value === 'string' ? oneLine(value) : JSON.stringify(value))];
66
+ });
67
+ return [" - ".concat(title)].concat(description, (0, _toConsumableArray2.default)(codeBlocks), (0, _toConsumableArray2.default)(additionalFields)).join('\n');
55
68
  }
56
69
  if (title) {
57
70
  return " - ".concat(title);
@@ -38,9 +38,10 @@ var formatIcon = exports.formatIcon = function formatIcon(data) {
38
38
  }
39
39
  var sections = [icon.componentName, '='.repeat(icon.componentName.length)];
40
40
  if (icon.package) {
41
+ var _icon$import;
41
42
  sections.push('', "Package: ".concat(icon.package));
42
43
  // The actionable bit: the barrel-correct import for this icon.
43
- sections.push('', 'Import:', " import ".concat(icon.componentName, " from '").concat(icon.package, "';"));
44
+ sections.push('', 'Import:', " ".concat((_icon$import = icon.import) !== null && _icon$import !== void 0 ? _icon$import : "import ".concat(icon.componentName, " from '").concat(icon.package, "';")));
44
45
  }
45
46
  if (icon.usage) {
46
47
  sections.push('', "Usage: ".concat(oneLine(icon.usage)));
@@ -7,37 +7,18 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.formatCompactResults = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _cliMetadata = require("../commands/cli-metadata");
10
+ var _compactResults = require("./compact-results");
10
11
  /**
11
12
  * Compact, human-readable renderers for the structured search/list results.
12
13
  *
13
- * The underlying ADS MCP tools return rich JSON arrays. Dumping that raw is unreadable at a
14
- * terminal, so the default (non-`--json`) output renders a compact one line per result. Full
15
- * structured data remains available via `--json`.
14
+ * The underlying ADS MCP tools return rich JSON arrays. Search and list commands first project
15
+ * those arrays into shared compact records, then both human and `--json` output consume the same
16
+ * data. Exact detail commands retain the full structured payload.
16
17
  *
17
18
  * Anything this module does not recognise (e.g. guideline markdown, the `plan` payload) is
18
19
  * left to the caller's generic fallback.
19
20
  */
20
21
 
21
- /**
22
- * A component result as returned by `searchComponentsTool` / `getAllComponentsTool`.
23
- * Only the fields the compact view needs are modelled; others are ignored.
24
- */
25
-
26
- /**
27
- * A token result as returned by `searchTokensTool` / `getAllTokensTool`.
28
- */
29
-
30
- /**
31
- * An icon result as returned by `searchIconsTool` / `getAllIconsTool`.
32
- */
33
-
34
- /**
35
- * Count helper that is safe against non-array / missing fields.
36
- */
37
- var countOf = function countOf(value) {
38
- return Array.isArray(value) ? value.length : 0;
39
- };
40
-
41
22
  /**
42
23
  * Pluralise a `count`-prefixed noun, e.g. `1 prop` / `2 props`.
43
24
  */
@@ -46,26 +27,16 @@ var pluralize = function pluralize(count, noun) {
46
27
  };
47
28
 
48
29
  /**
49
- * Truncate a one-line description so compact rows stay on a single line.
50
- */
51
- var truncate = function truncate(text) {
52
- var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 80;
53
- return text.length > max ? "".concat(text.slice(0, max - 1).trimEnd(), "\u2026") : text;
54
- };
55
-
56
- /**
57
- * Append a `→ <invocation> <command> <name>` drill-in hint beneath a row.
30
+ * Append a distribution-specific invocation to a compact row's follow-up command.
58
31
  *
59
32
  * Used for every `search` result, where the natural next step is to view that match in full.
60
33
  * `--all` listings omit it because echoing every row's own name would just be noise.
61
34
  */
62
35
  var withFollowUp = function withFollowUp(_ref) {
63
36
  var line = _ref.line,
64
- command = _ref.command,
65
- name = _ref.name,
66
- showFollowUp = _ref.showFollowUp,
37
+ followUp = _ref.followUp,
67
38
  invocation = _ref.invocation;
68
- return showFollowUp ? "".concat(line, "\n \u2192 ").concat(invocation, " ").concat(command, " ").concat(name) : line;
39
+ return followUp ? "".concat(line, "\n \u2192 ").concat(invocation, " ").concat(followUp) : line;
69
40
  };
70
41
 
71
42
  /**
@@ -75,18 +46,13 @@ var withFollowUp = function withFollowUp(_ref) {
75
46
  * (`--all`, `--type`) or a titled section of grouped `search` — so the kind is always clear from
76
47
  * context and a tag would just be noise.
77
48
  */
78
- var formatComponentLine = function formatComponentLine(component, showFollowUp, invocation) {
79
- var _component$name;
80
- var name = (_component$name = component.name) !== null && _component$name !== void 0 ? _component$name : '(unknown)';
49
+ var formatComponentLine = function formatComponentLine(component, invocation) {
50
+ var name = component.name;
81
51
  var pkg = component.package ? " ".concat(component.package) : '';
82
- var propCount = countOf(component.props);
83
- var exampleCount = countOf(component.examples);
84
- var meta = [pluralize(propCount, 'prop'), pluralize(exampleCount, 'example')].join(', ');
52
+ var meta = [pluralize(component.propCount, 'prop'), pluralize(component.exampleCount, 'example')].join(', ');
85
53
  return withFollowUp({
86
54
  line: "".concat(name).concat(pkg, " (").concat(meta, ")"),
87
- command: 'component',
88
- name: name,
89
- showFollowUp: showFollowUp,
55
+ followUp: component.followUp,
90
56
  invocation: invocation
91
57
  });
92
58
  };
@@ -94,17 +60,11 @@ var formatComponentLine = function formatComponentLine(component, showFollowUp,
94
60
  /**
95
61
  * Render one token as a compact `name = value` line.
96
62
  */
97
- var formatTokenLine = function formatTokenLine(tokenResult, showFollowUp, invocation) {
98
- var _tokenResult$name;
99
- var name = (_tokenResult$name = tokenResult.name) !== null && _tokenResult$name !== void 0 ? _tokenResult$name : '(unknown)';
100
- // Some token values (e.g. motion easing curves) are very long; truncate so each token stays
101
- // on a single readable line. The full value is always available via `--json`.
102
- var line = tokenResult.exampleValue ? "".concat(name, " = ").concat(truncate(tokenResult.exampleValue)) : name;
63
+ var formatTokenLine = function formatTokenLine(tokenResult, invocation) {
64
+ var line = tokenResult.exampleValue ? "".concat(tokenResult.name, " = ").concat(tokenResult.exampleValue) : tokenResult.name;
103
65
  return withFollowUp({
104
66
  line: line,
105
- command: 'token',
106
- name: name,
107
- showFollowUp: showFollowUp,
67
+ followUp: tokenResult.followUp,
108
68
  invocation: invocation
109
69
  });
110
70
  };
@@ -112,16 +72,13 @@ var formatTokenLine = function formatTokenLine(tokenResult, showFollowUp, invoca
112
72
  /**
113
73
  * Render one icon as a compact line with its import package and short usage note.
114
74
  */
115
- var formatIconLine = function formatIconLine(iconResult, showFollowUp, invocation) {
116
- var _iconResult$component;
117
- var name = (_iconResult$component = iconResult.componentName) !== null && _iconResult$component !== void 0 ? _iconResult$component : '(unknown)';
75
+ var formatIconLine = function formatIconLine(iconResult, invocation) {
76
+ var name = iconResult.componentName;
118
77
  var pkg = iconResult.package ? " ".concat(iconResult.package) : '';
119
- var usage = iconResult.usage ? " \u2014 ".concat(truncate(iconResult.usage)) : '';
78
+ var usage = iconResult.usage ? " \u2014 ".concat(iconResult.usage) : '';
120
79
  return withFollowUp({
121
80
  line: "".concat(name).concat(pkg).concat(usage),
122
- command: 'icon',
123
- name: name,
124
- showFollowUp: showFollowUp,
81
+ followUp: iconResult.followUp,
125
82
  invocation: invocation
126
83
  });
127
84
  };
@@ -129,10 +86,14 @@ var formatIconLine = function formatIconLine(iconResult, showFollowUp, invocatio
129
86
  /**
130
87
  * Render one foundations-document match without dumping its full Markdown body.
131
88
  */
132
- var formatDocLine = function formatDocLine(doc, showFollowUp, invocation) {
89
+ var formatDocLine = function formatDocLine(doc, invocation) {
133
90
  var summary = doc.summary ? " \u2014 ".concat(doc.summary) : '';
134
91
  var line = "".concat(doc.title).concat(summary);
135
- return showFollowUp ? "".concat(line, "\n \u2192 ").concat(invocation, " ").concat(doc.followUp) : line;
92
+ return withFollowUp({
93
+ line: line,
94
+ followUp: doc.followUp,
95
+ invocation: invocation
96
+ });
136
97
  };
137
98
 
138
99
  /**
@@ -149,26 +110,31 @@ var formatCompactResults = exports.formatCompactResults = function formatCompact
149
110
  showFollowUp = _ref2$showFollowUp === void 0 ? false : _ref2$showFollowUp,
150
111
  _ref2$invocation = _ref2.invocation,
151
112
  invocation = _ref2$invocation === void 0 ? _cliMetadata.CLI_BIN_NAME : _ref2$invocation;
152
- if (!Array.isArray(data)) {
113
+ var compact = (0, _compactResults.compactResults)({
114
+ kind: kind,
115
+ data: data,
116
+ showFollowUp: showFollowUp
117
+ });
118
+ if (compact === null) {
153
119
  return null;
154
120
  }
155
- if (data.length === 0) {
121
+ if (compact.length === 0) {
156
122
  return 'No results.';
157
123
  }
158
- var lines = data.map(function (entry) {
124
+ var lines = compact.map(function (entry) {
159
125
  switch (kind) {
160
126
  case 'components':
161
- return formatComponentLine(entry, showFollowUp, invocation);
127
+ return formatComponentLine(entry, invocation);
162
128
  case 'tokens':
163
- return formatTokenLine(entry, showFollowUp, invocation);
129
+ return formatTokenLine(entry, invocation);
164
130
  case 'icons':
165
- return formatIconLine(entry, showFollowUp, invocation);
131
+ return formatIconLine(entry, invocation);
166
132
  case 'docs':
167
- return formatDocLine(entry, showFollowUp, invocation);
133
+ return formatDocLine(entry, invocation);
168
134
  default:
169
135
  return JSON.stringify(entry);
170
136
  }
171
137
  });
172
- var header = "Results (".concat(data.length, "):");
138
+ var header = "Results (".concat(compact.length, "):");
173
139
  return [header, ''].concat((0, _toConsumableArray2.default)(lines)).join('\n');
174
140
  };