@atlaskit/ads-cli 0.6.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 (38) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +51 -14
  3. package/bin/ads-cli.js +6 -4
  4. package/dist/cjs/cli.js +23 -4
  5. package/dist/cjs/commands/definitions.js +46 -15
  6. package/dist/cjs/commands/normalize-batch-request.js +176 -0
  7. package/dist/cjs/output/compact-results.js +119 -0
  8. package/dist/cjs/output/format-doc-object.js +18 -5
  9. package/dist/cjs/output/format-icon.js +2 -1
  10. package/dist/cjs/output/format-results.js +37 -71
  11. package/dist/cjs/output/format-token.js +19 -5
  12. package/dist/cjs/output/write-json-envelope.js +2 -1
  13. package/dist/es2019/cli.js +23 -4
  14. package/dist/es2019/commands/definitions.js +48 -15
  15. package/dist/es2019/commands/normalize-batch-request.js +142 -0
  16. package/dist/es2019/output/compact-results.js +104 -0
  17. package/dist/es2019/output/format-doc-object.js +12 -4
  18. package/dist/es2019/output/format-icon.js +2 -1
  19. package/dist/es2019/output/format-results.js +37 -66
  20. package/dist/es2019/output/format-token.js +14 -5
  21. package/dist/es2019/output/write-json-envelope.js +2 -1
  22. package/dist/esm/cli.js +23 -4
  23. package/dist/esm/commands/definitions.js +46 -15
  24. package/dist/esm/commands/normalize-batch-request.js +169 -0
  25. package/dist/esm/output/compact-results.js +112 -0
  26. package/dist/esm/output/format-doc-object.js +18 -5
  27. package/dist/esm/output/format-icon.js +2 -1
  28. package/dist/esm/output/format-results.js +37 -71
  29. package/dist/esm/output/format-token.js +19 -5
  30. package/dist/esm/output/write-json-envelope.js +2 -1
  31. package/dist/types/commands/normalize-batch-request.d.ts +16 -0
  32. package/dist/types/commands/types.d.ts +8 -8
  33. package/dist/types/envelope/types.d.ts +3 -2
  34. package/dist/types/output/compact-results.d.ts +41 -0
  35. package/dist/types/output/format-results.d.ts +3 -3
  36. package/dist/types/output/format-token.d.ts +3 -3
  37. package/dist/types/output/write-json-envelope.d.ts +2 -1
  38. package/package.json +2 -2
@@ -37,6 +37,7 @@ import { formatToken } from '../output/format-token';
37
37
  import { parseLintRuleRecords } from '../output/parse-lint-rule-records';
38
38
  import { buildManifest } from './build-manifest';
39
39
  import { getVersion } from './get-version';
40
+ import { normalizeBatchRequest } from './normalize-batch-request';
40
41
  /**
41
42
  * Shared `--limit` flag definition reused across the search-style commands.
42
43
  */
@@ -293,6 +294,28 @@ var EXAMPLE_NAME = {
293
294
  icons: 'AddIcon'
294
295
  };
295
296
 
297
+ /**
298
+ * Add the actionable fields that exact human detail views derive from the raw record. Including
299
+ * them in JSON keeps both representations content-equivalent without requiring consumers to know
300
+ * ADS import or token-call conventions.
301
+ */
302
+ var addActionableDetail = function addActionableDetail(kind, item) {
303
+ if (kind === 'tokens') {
304
+ var name = itemFields.tokens.nameOf(item);
305
+ return name ? _objectSpread(_objectSpread({}, item), {}, {
306
+ usage: "token('".concat(name, "')")
307
+ }) : item;
308
+ }
309
+ if (kind === 'icons') {
310
+ var componentName = itemFields.icons.nameOf(item);
311
+ var packageName = typeof item.package === 'string' ? item.package : undefined;
312
+ return componentName && packageName ? _objectSpread(_objectSpread({}, item), {}, {
313
+ import: "import ".concat(componentName, " from '").concat(packageName, "';")
314
+ }) : item;
315
+ }
316
+ return item;
317
+ };
318
+
296
319
  /**
297
320
  * Build one of the singular item commands (`component <name>`, `token <name>`, `icon <name>`).
298
321
  *
@@ -363,11 +386,11 @@ var makeItemCommand = function makeItemCommand(_ref3) {
363
386
  return nameOf(item).toLowerCase() === query.toLowerCase();
364
387
  });
365
388
  if (exact) {
366
- return exact;
389
+ return addActionableDetail(kind, exact);
367
390
  }
368
391
  // A single candidate is unambiguous — show it.
369
392
  if (candidates.length === 1) {
370
- return candidates[0];
393
+ return addActionableDetail(kind, candidates[0]);
371
394
  }
372
395
  // Otherwise do not guess: surface a disambiguation list.
373
396
  return {
@@ -407,7 +430,11 @@ var makeItemCommand = function makeItemCommand(_ref3) {
407
430
  return singleTool({
408
431
  importPath: searchTool.importPath,
409
432
  handlerName: searchTool.handlerName,
410
- args: {
433
+ args: kind === 'tokens' ? {
434
+ terms: [name_],
435
+ limit: ITEM_LOOKUP_LIMIT,
436
+ includeMetadata: true
437
+ } : {
411
438
  terms: [name_],
412
439
  limit: ITEM_LOOKUP_LIMIT
413
440
  },
@@ -466,9 +493,9 @@ var resolveUnifiedSearch = function resolveUnifiedSearch(input) {
466
493
  };
467
494
 
468
495
  /**
469
- * Split a batch invocation into argv groups introduced by repeated `--command` flags. The groups
470
- * remain tokenized, so child commands can be routed through the existing parser without evaluating
471
- * shell strings.
496
+ * Split a batch invocation into argv groups introduced by repeated `--command` flags. Canonical
497
+ * tokenized groups remain unchanged; a complete request in the first token is safely normalized
498
+ * to argv without evaluating shell strings.
472
499
  */
473
500
  var resolveBatch = function resolveBatch(input) {
474
501
  var _input$rawArgs;
@@ -503,9 +530,11 @@ var resolveBatch = function resolveBatch(input) {
503
530
  error: '`--command` must be followed by a non-empty command request.'
504
531
  };
505
532
  }
506
- requests.push({
507
- argv: current
508
- });
533
+ var _normalized = normalizeBatchRequest(current);
534
+ if ('error' in _normalized) {
535
+ return _normalized;
536
+ }
537
+ requests.push(_normalized);
509
538
  current = [];
510
539
  continue;
511
540
  }
@@ -521,9 +550,11 @@ var resolveBatch = function resolveBatch(input) {
521
550
  error: '`--command` must be followed by a non-empty command request.'
522
551
  };
523
552
  }
524
- requests.push({
525
- argv: current
526
- });
553
+ var normalized = normalizeBatchRequest(current);
554
+ if ('error' in normalized) {
555
+ return normalized;
556
+ }
557
+ requests.push(normalized);
527
558
  return {
528
559
  tools: [],
529
560
  batch: requests,
@@ -596,15 +627,15 @@ export var commands = [{
596
627
  }
597
628
  }, {
598
629
  name: 'batch',
599
- description: 'Run multiple ADS CLI queries, including different command types, in one process.',
630
+ description: 'Run multiple ADS CLI queries in one process. Tokenized child requests are canonical; complete-request strings are also accepted.',
600
631
  usage: 'batch [--json] --command <command> [args...] [--command <command> [args...]]...',
601
632
  arguments: [],
602
633
  flags: [{
603
634
  name: 'command',
604
635
  type: 'string[]',
605
- description: 'A child command name followed by its arguments. Repeat once per child command.'
636
+ description: 'Canonical: a tokenized child command and its arguments. A complete quoted request is also accepted. Repeat once per child command.'
606
637
  }],
607
- examples: ['batch --command search button --type icon --command token space.200', 'batch --json --command component Button --command docs spacing'],
638
+ examples: ['batch --command search button --type icon --command token space.200', 'batch --command "search button" --type icon --command "token space.200"', 'batch --json --command component Button --command docs spacing'],
608
639
  responseTypes: ['ads-cli/batch'],
609
640
  envelopeType: function envelopeType() {
610
641
  return 'batch';
@@ -0,0 +1,169 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _toArray from "@babel/runtime/helpers/toArray";
3
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
+ /**
7
+ * Normalise one batch child request without involving a shell.
8
+ *
9
+ * The canonical form is already-tokenized argv, for example
10
+ * `['search', 'Grid', '--type', 'component']`. For compatibility with agent-generated commands,
11
+ * the first token may instead contain a complete request, for example `['search Grid', '--type',
12
+ * 'component']`. Only that first token is split; trailing tokens have already been tokenized by the
13
+ * caller and must remain unchanged so multi-word arguments keep their boundaries.
14
+ */
15
+
16
+ var shellSyntaxError = function shellSyntaxError(syntax) {
17
+ return {
18
+ error: "Shell syntax ".concat(syntax, " is not supported in batch requests. Pass child commands as argv only; pipes, redirects, expansion, and command substitution are not allowed.")
19
+ };
20
+ };
21
+
22
+ /**
23
+ * Reject syntax that would have special meaning to a shell even though this parser never invokes
24
+ * one. Failing closed gives callers an actionable error instead of accepting input that only looks
25
+ * safe because it currently remains an argv array.
26
+ */
27
+ var findShellSyntax = function findShellSyntax(value) {
28
+ var _value$match;
29
+ if (value.includes('$(')) {
30
+ return 'command substitution (`$(...)`)';
31
+ }
32
+ if (value.includes('`')) {
33
+ return 'command substitution (backticks)';
34
+ }
35
+ if (value.includes('$')) {
36
+ return 'environment expansion (`$`)';
37
+ }
38
+ if (/\r|\n/.test(value)) {
39
+ return 'a command separator (line break)';
40
+ }
41
+ if (value.includes('&&')) {
42
+ return 'the `&&` operator';
43
+ }
44
+ if (value.includes('||')) {
45
+ return 'the `||` operator';
46
+ }
47
+ var operator = (_value$match = value.match(/[|&;<>()]/)) === null || _value$match === void 0 ? void 0 : _value$match[0];
48
+ return operator ? "the `".concat(operator, "` operator") : null;
49
+ };
50
+
51
+ /**
52
+ * Split a complete child request into argv using quoting and escaping rules only. This is
53
+ * intentionally not a shell grammar: it performs no expansion, substitution, redirection, or
54
+ * operator evaluation.
55
+ */
56
+ var tokenizeCompleteRequest = function tokenizeCompleteRequest(value) {
57
+ var argv = [];
58
+ var current = '';
59
+ var quote = null;
60
+ var escaped = false;
61
+ var tokenStarted = false;
62
+ var _iterator = _createForOfIteratorHelper(value),
63
+ _step;
64
+ try {
65
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
66
+ var character = _step.value;
67
+ if (escaped) {
68
+ current += character;
69
+ escaped = false;
70
+ tokenStarted = true;
71
+ continue;
72
+ }
73
+ if (character === '\\') {
74
+ escaped = true;
75
+ tokenStarted = true;
76
+ continue;
77
+ }
78
+ if (quote !== null) {
79
+ if (character === quote) {
80
+ quote = null;
81
+ } else {
82
+ current += character;
83
+ }
84
+ continue;
85
+ }
86
+ if (character === "'" || character === '"') {
87
+ quote = character;
88
+ tokenStarted = true;
89
+ continue;
90
+ }
91
+ if (/\s/.test(character)) {
92
+ if (tokenStarted) {
93
+ argv.push(current);
94
+ current = '';
95
+ tokenStarted = false;
96
+ }
97
+ continue;
98
+ }
99
+ current += character;
100
+ tokenStarted = true;
101
+ }
102
+ } catch (err) {
103
+ _iterator.e(err);
104
+ } finally {
105
+ _iterator.f();
106
+ }
107
+ if (escaped) {
108
+ return {
109
+ error: 'Invalid complete batch request: it ends with an escape character.'
110
+ };
111
+ }
112
+ if (quote !== null) {
113
+ return {
114
+ error: "Invalid complete batch request: unterminated ".concat(quote, " quote.")
115
+ };
116
+ }
117
+ if (tokenStarted) {
118
+ argv.push(current);
119
+ }
120
+ if (argv.length === 0) {
121
+ return {
122
+ error: 'Invalid complete batch request: a command name is required.'
123
+ };
124
+ }
125
+ return {
126
+ argv: argv
127
+ };
128
+ };
129
+ export var normalizeBatchRequest = function normalizeBatchRequest(argv) {
130
+ var _iterator2 = _createForOfIteratorHelper(argv),
131
+ _step2;
132
+ try {
133
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
134
+ var token = _step2.value;
135
+ var syntax = findShellSyntax(token);
136
+ if (syntax !== null) {
137
+ return shellSyntaxError(syntax);
138
+ }
139
+ }
140
+ } catch (err) {
141
+ _iterator2.e(err);
142
+ } finally {
143
+ _iterator2.f();
144
+ }
145
+ var _argv = _toArray(argv),
146
+ first = _argv[0],
147
+ trailing = _arrayLikeToArray(_argv).slice(1);
148
+ if (first === undefined) {
149
+ return {
150
+ error: '`--command` must be followed by a non-empty command request.'
151
+ };
152
+ }
153
+
154
+ // A normal command name cannot contain whitespace, quotes, or escapes. Their presence in the
155
+ // first argv entry therefore identifies the complete-string compatibility form. Tokenized
156
+ // trailing entries are never re-split.
157
+ if (!/[\s'"\\]/.test(first)) {
158
+ return {
159
+ argv: _toConsumableArray(argv)
160
+ };
161
+ }
162
+ var normalized = tokenizeCompleteRequest(first);
163
+ if ('error' in normalized) {
164
+ return normalized;
165
+ }
166
+ return {
167
+ argv: [].concat(_toConsumableArray(normalized.argv), _toConsumableArray(trailing))
168
+ };
169
+ };
@@ -0,0 +1,112 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _typeof from "@babel/runtime/helpers/typeof";
3
+ 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; }
4
+ 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) { _defineProperty(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; }
5
+ /**
6
+ * Shared compact projections for ADS search and list results.
7
+ *
8
+ * Human-readable rows and `--json` responses both consume these records. Keeping the projection in
9
+ * one place prevents the machine-readable output from silently expanding back to the underlying
10
+ * MCP payload (for example, every component prop and example during discovery).
11
+ */
12
+
13
+ var countOf = function countOf(value) {
14
+ return Array.isArray(value) ? value.length : 0;
15
+ };
16
+
17
+ /**
18
+ * Truncate a one-line value so discovery results stay bounded. Exact detail commands preserve the
19
+ * full value.
20
+ */
21
+ var truncateCompactText = function truncateCompactText(text) {
22
+ var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 80;
23
+ var oneLine = text.replace(/\s+/g, ' ').trim();
24
+ return oneLine.length > max ? "".concat(oneLine.slice(0, max - 1).trimEnd(), "\u2026") : oneLine;
25
+ };
26
+ var asRecord = function asRecord(value) {
27
+ return value !== null && _typeof(value) === 'object' ? value : {};
28
+ };
29
+ var optionalString = function optionalString(value) {
30
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
31
+ };
32
+ var withFollowUp = function withFollowUp(result, showFollowUp, followUp) {
33
+ return showFollowUp ? _objectSpread(_objectSpread({}, result), {}, {
34
+ followUp: followUp
35
+ }) : result;
36
+ };
37
+ var compactComponent = function compactComponent(value, showFollowUp) {
38
+ var _optionalString, _optionalString2;
39
+ var record = asRecord(value);
40
+ var name = (_optionalString = optionalString(record.name)) !== null && _optionalString !== void 0 ? _optionalString : '(unknown)';
41
+ var propCount = typeof record.propCount === 'number' ? record.propCount : countOf(record.props);
42
+ var exampleCount = typeof record.exampleCount === 'number' ? record.exampleCount : countOf(record.examples);
43
+ return withFollowUp(_objectSpread(_objectSpread({
44
+ name: name
45
+ }, optionalString(record.package) ? {
46
+ package: String(record.package)
47
+ } : {}), {}, {
48
+ propCount: propCount,
49
+ exampleCount: exampleCount
50
+ }), showFollowUp, (_optionalString2 = optionalString(record.followUp)) !== null && _optionalString2 !== void 0 ? _optionalString2 : "component ".concat(name));
51
+ };
52
+ var compactToken = function compactToken(value, showFollowUp) {
53
+ var _optionalString3, _optionalString4;
54
+ var record = asRecord(value);
55
+ var name = (_optionalString3 = optionalString(record.name)) !== null && _optionalString3 !== void 0 ? _optionalString3 : '(unknown)';
56
+ var exampleValue = optionalString(record.exampleValue);
57
+ return withFollowUp(_objectSpread({
58
+ name: name
59
+ }, exampleValue ? {
60
+ exampleValue: truncateCompactText(exampleValue)
61
+ } : {}), showFollowUp, (_optionalString4 = optionalString(record.followUp)) !== null && _optionalString4 !== void 0 ? _optionalString4 : "token ".concat(name));
62
+ };
63
+ var compactIcon = function compactIcon(value, showFollowUp) {
64
+ var _optionalString5, _optionalString6;
65
+ var record = asRecord(value);
66
+ var componentName = (_optionalString5 = optionalString(record.componentName)) !== null && _optionalString5 !== void 0 ? _optionalString5 : '(unknown)';
67
+ var usage = optionalString(record.usage);
68
+ return withFollowUp(_objectSpread(_objectSpread({
69
+ componentName: componentName
70
+ }, optionalString(record.package) ? {
71
+ package: String(record.package)
72
+ } : {}), usage ? {
73
+ usage: truncateCompactText(usage)
74
+ } : {}), showFollowUp, (_optionalString6 = optionalString(record.followUp)) !== null && _optionalString6 !== void 0 ? _optionalString6 : "icon ".concat(componentName));
75
+ };
76
+ var compactDoc = function compactDoc(value, showFollowUp) {
77
+ var _optionalString7, _optionalString8;
78
+ var record = asRecord(value);
79
+ var title = (_optionalString7 = optionalString(record.title)) !== null && _optionalString7 !== void 0 ? _optionalString7 : '(unknown)';
80
+ var summary = optionalString(record.summary);
81
+ return withFollowUp(_objectSpread({
82
+ title: title
83
+ }, summary ? {
84
+ summary: truncateCompactText(summary)
85
+ } : {}), showFollowUp, (_optionalString8 = optionalString(record.followUp)) !== null && _optionalString8 !== void 0 ? _optionalString8 : "docs ".concat(title.toLowerCase()));
86
+ };
87
+
88
+ /**
89
+ * Project raw MCP rows into the compact records shared by human and JSON output. The function is
90
+ * idempotent so batch rendering can safely receive child envelopes that were already compacted.
91
+ */
92
+ export var compactResults = function compactResults(_ref) {
93
+ var kind = _ref.kind,
94
+ data = _ref.data,
95
+ _ref$showFollowUp = _ref.showFollowUp,
96
+ showFollowUp = _ref$showFollowUp === void 0 ? false : _ref$showFollowUp;
97
+ if (!Array.isArray(data)) {
98
+ return null;
99
+ }
100
+ return data.map(function (entry) {
101
+ switch (kind) {
102
+ case 'components':
103
+ return compactComponent(entry, showFollowUp);
104
+ case 'tokens':
105
+ return compactToken(entry, showFollowUp);
106
+ case 'icons':
107
+ return compactIcon(entry, showFollowUp);
108
+ case 'docs':
109
+ return compactDoc(entry, showFollowUp);
110
+ }
111
+ });
112
+ };
@@ -1,5 +1,5 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  import _typeof from "@babel/runtime/helpers/typeof";
4
4
  /**
5
5
  * Human-readable renderer for a single "doc object" payload — the shape returned by the
@@ -39,12 +39,25 @@ var formatListItem = function formatListItem(item) {
39
39
  if (item !== null && _typeof(item) === 'object') {
40
40
  var record = item;
41
41
  var title = typeof record.title === 'string' ? record.title : null;
42
- var code = ['code', 'before', 'after'].find(function (key) {
42
+ var codeKeys = ['code', 'before', 'after'].filter(function (key) {
43
43
  return typeof record[key] === 'string';
44
44
  });
45
- if (title && code) {
46
- var description = typeof record.description === 'string' ? "\n ".concat(oneLine(record.description)) : '';
47
- return " - ".concat(title).concat(description, "\n ```tsx\n").concat(record[code], "\n ```");
45
+ if (title && codeKeys.length > 0) {
46
+ var description = typeof record.description === 'string' ? [" ".concat(oneLine(record.description))] : [];
47
+ var labelCodeBlocks = codeKeys.length > 1 || codeKeys[0] !== 'code';
48
+ var codeBlocks = codeKeys.flatMap(function (key) {
49
+ return [].concat(_toConsumableArray(labelCodeBlocks ? [" ".concat(humanizeKey(key), ":")] : []), [" ```tsx\n".concat(record[key], "\n ```")]);
50
+ });
51
+ var additionalFields = Object.entries(record).flatMap(function (_ref) {
52
+ var _ref2 = _slicedToArray(_ref, 2),
53
+ key = _ref2[0],
54
+ value = _ref2[1];
55
+ if (['title', 'description'].concat(_toConsumableArray(codeKeys)).includes(key) || value === null || value === undefined) {
56
+ return [];
57
+ }
58
+ return [" ".concat(humanizeKey(key), ": ").concat(typeof value === 'string' ? oneLine(value) : JSON.stringify(value))];
59
+ });
60
+ return [" - ".concat(title)].concat(description, _toConsumableArray(codeBlocks), _toConsumableArray(additionalFields)).join('\n');
48
61
  }
49
62
  if (title) {
50
63
  return " - ".concat(title);
@@ -31,9 +31,10 @@ export var formatIcon = function formatIcon(data) {
31
31
  }
32
32
  var sections = [icon.componentName, '='.repeat(icon.componentName.length)];
33
33
  if (icon.package) {
34
+ var _icon$import;
34
35
  sections.push('', "Package: ".concat(icon.package));
35
36
  // The actionable bit: the barrel-correct import for this icon.
36
- sections.push('', 'Import:', " import ".concat(icon.componentName, " from '").concat(icon.package, "';"));
37
+ sections.push('', 'Import:', " ".concat((_icon$import = icon.import) !== null && _icon$import !== void 0 ? _icon$import : "import ".concat(icon.componentName, " from '").concat(icon.package, "';")));
37
38
  }
38
39
  if (icon.usage) {
39
40
  sections.push('', "Usage: ".concat(oneLine(icon.usage)));
@@ -2,35 +2,16 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  /**
3
3
  * Compact, human-readable renderers for the structured search/list results.
4
4
  *
5
- * The underlying ADS MCP tools return rich JSON arrays. Dumping that raw is unreadable at a
6
- * terminal, so the default (non-`--json`) output renders a compact one line per result. Full
7
- * structured data remains available via `--json`.
5
+ * The underlying ADS MCP tools return rich JSON arrays. Search and list commands first project
6
+ * those arrays into shared compact records, then both human and `--json` output consume the same
7
+ * data. Exact detail commands retain the full structured payload.
8
8
  *
9
9
  * Anything this module does not recognise (e.g. guideline markdown, the `plan` payload) is
10
10
  * left to the caller's generic fallback.
11
11
  */
12
12
 
13
13
  import { CLI_BIN_NAME } from '../commands/cli-metadata';
14
-
15
- /**
16
- * A component result as returned by `searchComponentsTool` / `getAllComponentsTool`.
17
- * Only the fields the compact view needs are modelled; others are ignored.
18
- */
19
-
20
- /**
21
- * A token result as returned by `searchTokensTool` / `getAllTokensTool`.
22
- */
23
-
24
- /**
25
- * An icon result as returned by `searchIconsTool` / `getAllIconsTool`.
26
- */
27
-
28
- /**
29
- * Count helper that is safe against non-array / missing fields.
30
- */
31
- var countOf = function countOf(value) {
32
- return Array.isArray(value) ? value.length : 0;
33
- };
14
+ import { compactResults } from './compact-results';
34
15
 
35
16
  /**
36
17
  * Pluralise a `count`-prefixed noun, e.g. `1 prop` / `2 props`.
@@ -40,26 +21,16 @@ var pluralize = function pluralize(count, noun) {
40
21
  };
41
22
 
42
23
  /**
43
- * Truncate a one-line description so compact rows stay on a single line.
44
- */
45
- var truncate = function truncate(text) {
46
- var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 80;
47
- return text.length > max ? "".concat(text.slice(0, max - 1).trimEnd(), "\u2026") : text;
48
- };
49
-
50
- /**
51
- * Append a `→ <invocation> <command> <name>` drill-in hint beneath a row.
24
+ * Append a distribution-specific invocation to a compact row's follow-up command.
52
25
  *
53
26
  * Used for every `search` result, where the natural next step is to view that match in full.
54
27
  * `--all` listings omit it because echoing every row's own name would just be noise.
55
28
  */
56
29
  var withFollowUp = function withFollowUp(_ref) {
57
30
  var line = _ref.line,
58
- command = _ref.command,
59
- name = _ref.name,
60
- showFollowUp = _ref.showFollowUp,
31
+ followUp = _ref.followUp,
61
32
  invocation = _ref.invocation;
62
- return showFollowUp ? "".concat(line, "\n \u2192 ").concat(invocation, " ").concat(command, " ").concat(name) : line;
33
+ return followUp ? "".concat(line, "\n \u2192 ").concat(invocation, " ").concat(followUp) : line;
63
34
  };
64
35
 
65
36
  /**
@@ -69,18 +40,13 @@ var withFollowUp = function withFollowUp(_ref) {
69
40
  * (`--all`, `--type`) or a titled section of grouped `search` — so the kind is always clear from
70
41
  * context and a tag would just be noise.
71
42
  */
72
- var formatComponentLine = function formatComponentLine(component, showFollowUp, invocation) {
73
- var _component$name;
74
- var name = (_component$name = component.name) !== null && _component$name !== void 0 ? _component$name : '(unknown)';
43
+ var formatComponentLine = function formatComponentLine(component, invocation) {
44
+ var name = component.name;
75
45
  var pkg = component.package ? " ".concat(component.package) : '';
76
- var propCount = countOf(component.props);
77
- var exampleCount = countOf(component.examples);
78
- var meta = [pluralize(propCount, 'prop'), pluralize(exampleCount, 'example')].join(', ');
46
+ var meta = [pluralize(component.propCount, 'prop'), pluralize(component.exampleCount, 'example')].join(', ');
79
47
  return withFollowUp({
80
48
  line: "".concat(name).concat(pkg, " (").concat(meta, ")"),
81
- command: 'component',
82
- name: name,
83
- showFollowUp: showFollowUp,
49
+ followUp: component.followUp,
84
50
  invocation: invocation
85
51
  });
86
52
  };
@@ -88,17 +54,11 @@ var formatComponentLine = function formatComponentLine(component, showFollowUp,
88
54
  /**
89
55
  * Render one token as a compact `name = value` line.
90
56
  */
91
- var formatTokenLine = function formatTokenLine(tokenResult, showFollowUp, invocation) {
92
- var _tokenResult$name;
93
- var name = (_tokenResult$name = tokenResult.name) !== null && _tokenResult$name !== void 0 ? _tokenResult$name : '(unknown)';
94
- // Some token values (e.g. motion easing curves) are very long; truncate so each token stays
95
- // on a single readable line. The full value is always available via `--json`.
96
- var line = tokenResult.exampleValue ? "".concat(name, " = ").concat(truncate(tokenResult.exampleValue)) : name;
57
+ var formatTokenLine = function formatTokenLine(tokenResult, invocation) {
58
+ var line = tokenResult.exampleValue ? "".concat(tokenResult.name, " = ").concat(tokenResult.exampleValue) : tokenResult.name;
97
59
  return withFollowUp({
98
60
  line: line,
99
- command: 'token',
100
- name: name,
101
- showFollowUp: showFollowUp,
61
+ followUp: tokenResult.followUp,
102
62
  invocation: invocation
103
63
  });
104
64
  };
@@ -106,16 +66,13 @@ var formatTokenLine = function formatTokenLine(tokenResult, showFollowUp, invoca
106
66
  /**
107
67
  * Render one icon as a compact line with its import package and short usage note.
108
68
  */
109
- var formatIconLine = function formatIconLine(iconResult, showFollowUp, invocation) {
110
- var _iconResult$component;
111
- var name = (_iconResult$component = iconResult.componentName) !== null && _iconResult$component !== void 0 ? _iconResult$component : '(unknown)';
69
+ var formatIconLine = function formatIconLine(iconResult, invocation) {
70
+ var name = iconResult.componentName;
112
71
  var pkg = iconResult.package ? " ".concat(iconResult.package) : '';
113
- var usage = iconResult.usage ? " \u2014 ".concat(truncate(iconResult.usage)) : '';
72
+ var usage = iconResult.usage ? " \u2014 ".concat(iconResult.usage) : '';
114
73
  return withFollowUp({
115
74
  line: "".concat(name).concat(pkg).concat(usage),
116
- command: 'icon',
117
- name: name,
118
- showFollowUp: showFollowUp,
75
+ followUp: iconResult.followUp,
119
76
  invocation: invocation
120
77
  });
121
78
  };
@@ -123,10 +80,14 @@ var formatIconLine = function formatIconLine(iconResult, showFollowUp, invocatio
123
80
  /**
124
81
  * Render one foundations-document match without dumping its full Markdown body.
125
82
  */
126
- var formatDocLine = function formatDocLine(doc, showFollowUp, invocation) {
83
+ var formatDocLine = function formatDocLine(doc, invocation) {
127
84
  var summary = doc.summary ? " \u2014 ".concat(doc.summary) : '';
128
85
  var line = "".concat(doc.title).concat(summary);
129
- return showFollowUp ? "".concat(line, "\n \u2192 ").concat(invocation, " ").concat(doc.followUp) : line;
86
+ return withFollowUp({
87
+ line: line,
88
+ followUp: doc.followUp,
89
+ invocation: invocation
90
+ });
130
91
  };
131
92
 
132
93
  /**
@@ -143,26 +104,31 @@ export var formatCompactResults = function formatCompactResults(_ref2) {
143
104
  showFollowUp = _ref2$showFollowUp === void 0 ? false : _ref2$showFollowUp,
144
105
  _ref2$invocation = _ref2.invocation,
145
106
  invocation = _ref2$invocation === void 0 ? CLI_BIN_NAME : _ref2$invocation;
146
- if (!Array.isArray(data)) {
107
+ var compact = compactResults({
108
+ kind: kind,
109
+ data: data,
110
+ showFollowUp: showFollowUp
111
+ });
112
+ if (compact === null) {
147
113
  return null;
148
114
  }
149
- if (data.length === 0) {
115
+ if (compact.length === 0) {
150
116
  return 'No results.';
151
117
  }
152
- var lines = data.map(function (entry) {
118
+ var lines = compact.map(function (entry) {
153
119
  switch (kind) {
154
120
  case 'components':
155
- return formatComponentLine(entry, showFollowUp, invocation);
121
+ return formatComponentLine(entry, invocation);
156
122
  case 'tokens':
157
- return formatTokenLine(entry, showFollowUp, invocation);
123
+ return formatTokenLine(entry, invocation);
158
124
  case 'icons':
159
- return formatIconLine(entry, showFollowUp, invocation);
125
+ return formatIconLine(entry, invocation);
160
126
  case 'docs':
161
- return formatDocLine(entry, showFollowUp, invocation);
127
+ return formatDocLine(entry, invocation);
162
128
  default:
163
129
  return JSON.stringify(entry);
164
130
  }
165
131
  });
166
- var header = "Results (".concat(data.length, "):");
132
+ var header = "Results (".concat(compact.length, "):");
167
133
  return [header, ''].concat(_toConsumableArray(lines)).join('\n');
168
134
  };