@atlaskit/ads-cli 0.5.0 → 0.7.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.
- package/CHANGELOG.md +42 -0
- package/README.md +71 -10
- package/dist/cjs/cli.js +303 -58
- package/dist/cjs/commands/definitions.js +89 -0
- package/dist/cjs/commands/normalize-batch-request.js +176 -0
- package/dist/cjs/output/format-human-result.js +33 -0
- package/dist/cjs/output/write-human-result.js +8 -10
- package/dist/es2019/cli.js +211 -16
- package/dist/es2019/commands/definitions.js +74 -0
- package/dist/es2019/commands/normalize-batch-request.js +142 -0
- package/dist/es2019/output/format-human-result.js +28 -0
- package/dist/es2019/output/write-human-result.js +8 -9
- package/dist/esm/cli.js +303 -58
- package/dist/esm/commands/definitions.js +89 -0
- package/dist/esm/commands/normalize-batch-request.js +169 -0
- package/dist/esm/output/format-human-result.js +27 -0
- package/dist/esm/output/write-human-result.js +8 -9
- package/dist/types/commands/normalize-batch-request.d.ts +16 -0
- package/dist/types/commands/types.d.ts +16 -0
- package/dist/types/output/format-human-result.d.ts +17 -0
- package/dist/types/output/write-human-result.d.ts +2 -2
- package/dist/types/parse-args.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic last-resort human formatting for a successful command result.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Render a successful result with the generic last-resort formatting, used when a command
|
|
9
|
+
* declares neither a compact result kind nor its own `formatHuman`.
|
|
10
|
+
*
|
|
11
|
+
* Structured data is pretty-printed as JSON (the underlying tools already return rich objects),
|
|
12
|
+
* while plain-string payloads such as guideline markdown are returned verbatim.
|
|
13
|
+
*
|
|
14
|
+
* Kept separate from the writer so callers that compose text rather than write it — notably
|
|
15
|
+
* `batch`, which concatenates one section per child — produce byte-identical output without
|
|
16
|
+
* duplicating these rules.
|
|
17
|
+
*/
|
|
18
|
+
export var formatHumanResult = function formatHumanResult(_ref) {
|
|
19
|
+
var data = _ref.data;
|
|
20
|
+
if (typeof data === 'string') {
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
if (data === null || data === undefined) {
|
|
24
|
+
return chalk.yellow('No results.');
|
|
25
|
+
}
|
|
26
|
+
return JSON.stringify(data, null, 2);
|
|
27
|
+
};
|
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
* Human-readable rendering of a successful command result.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { formatHumanResult } from './format-human-result';
|
|
6
6
|
/**
|
|
7
7
|
* Emit a human-readable rendering of a successful result to stdout.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* An absent payload is a diagnostic rather than data, so it goes to stderr to keep stdout clean
|
|
10
|
+
* for piping.
|
|
11
11
|
*/
|
|
12
12
|
export var writeHumanResult = function writeHumanResult(_ref) {
|
|
13
13
|
var data = _ref.data,
|
|
14
14
|
writer = _ref.writer;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
15
|
+
var text = formatHumanResult({
|
|
16
|
+
data: data
|
|
17
|
+
});
|
|
19
18
|
if (data === null || data === undefined) {
|
|
20
|
-
writer.err(
|
|
19
|
+
writer.err(text);
|
|
21
20
|
return;
|
|
22
21
|
}
|
|
23
|
-
writer.out(
|
|
22
|
+
writer.out(text);
|
|
24
23
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise one batch child request without involving a shell.
|
|
3
|
+
*
|
|
4
|
+
* The canonical form is already-tokenized argv, for example
|
|
5
|
+
* `['search', 'Grid', '--type', 'component']`. For compatibility with agent-generated commands,
|
|
6
|
+
* the first token may instead contain a complete request, for example `['search Grid', '--type',
|
|
7
|
+
* 'component']`. Only that first token is split; trailing tokens have already been tokenized by the
|
|
8
|
+
* caller and must remain unchanged so multi-word arguments keep their boundaries.
|
|
9
|
+
*/
|
|
10
|
+
type NormalizedBatchRequest = {
|
|
11
|
+
argv: string[];
|
|
12
|
+
} | {
|
|
13
|
+
error: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const normalizeBatchRequest: (argv: string[]) => NormalizedBatchRequest;
|
|
16
|
+
export {};
|
|
@@ -17,6 +17,11 @@ export type CommandInput = {
|
|
|
17
17
|
* Parsed `--flag` values (numbers, strings, booleans, or repeated string arrays).
|
|
18
18
|
*/
|
|
19
19
|
flags: Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Original argv for commands whose grammar needs token boundaries that generic flag parsing
|
|
22
|
+
* intentionally discards (currently the batch command's repeated `--command` boundaries).
|
|
23
|
+
*/
|
|
24
|
+
rawArgs?: string[];
|
|
20
25
|
};
|
|
21
26
|
/**
|
|
22
27
|
* A documented positional argument for a command, surfaced by `manifest`.
|
|
@@ -55,6 +60,12 @@ export type ToolCall = {
|
|
|
55
60
|
handlerName: string;
|
|
56
61
|
args?: unknown;
|
|
57
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* One independently-addressed command invocation in a composite batch.
|
|
65
|
+
*/
|
|
66
|
+
export type BatchRequest = {
|
|
67
|
+
argv: string[];
|
|
68
|
+
};
|
|
58
69
|
/**
|
|
59
70
|
* The successful result of resolving a command: one or more ADS MCP tool calls.
|
|
60
71
|
*
|
|
@@ -67,6 +78,11 @@ export type ToolCall = {
|
|
|
67
78
|
export type ResolvedCommand = {
|
|
68
79
|
tools: ToolCall[];
|
|
69
80
|
grouped?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* When present, each request is executed through the command registry inside the current
|
|
83
|
+
* process. Its existing envelope and rendering semantics are preserved independently.
|
|
84
|
+
*/
|
|
85
|
+
batch?: BatchRequest[];
|
|
70
86
|
meta?: Record<string, unknown>;
|
|
71
87
|
};
|
|
72
88
|
/**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic last-resort human formatting for a successful command result.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Render a successful result with the generic last-resort formatting, used when a command
|
|
6
|
+
* declares neither a compact result kind nor its own `formatHuman`.
|
|
7
|
+
*
|
|
8
|
+
* Structured data is pretty-printed as JSON (the underlying tools already return rich objects),
|
|
9
|
+
* while plain-string payloads such as guideline markdown are returned verbatim.
|
|
10
|
+
*
|
|
11
|
+
* Kept separate from the writer so callers that compose text rather than write it — notably
|
|
12
|
+
* `batch`, which concatenates one section per child — produce byte-identical output without
|
|
13
|
+
* duplicating these rules.
|
|
14
|
+
*/
|
|
15
|
+
export declare const formatHumanResult: ({ data }: {
|
|
16
|
+
data: unknown;
|
|
17
|
+
}) => string;
|
|
@@ -5,8 +5,8 @@ import type { Writer } from './writer';
|
|
|
5
5
|
/**
|
|
6
6
|
* Emit a human-readable rendering of a successful result to stdout.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* An absent payload is a diagnostic rather than data, so it goes to stderr to keep stdout clean
|
|
9
|
+
* for piping.
|
|
10
10
|
*/
|
|
11
11
|
export declare const writeHumanResult: ({ data, writer }: {
|
|
12
12
|
data: unknown;
|
|
@@ -18,7 +18,7 @@ export type ParsedArgs = {
|
|
|
18
18
|
*/
|
|
19
19
|
positionals: string[];
|
|
20
20
|
/**
|
|
21
|
-
* Parsed flags. Values may be string
|
|
21
|
+
* Parsed flags. Values may be a string (including number-like strings) or a boolean.
|
|
22
22
|
*/
|
|
23
23
|
flags: Record<string, unknown>;
|
|
24
24
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/ads-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "An npx-runnable command-line tool to query Atlassian Design System (ADS) structured content — components, tokens, icons, and guidelines — from the terminal.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|