@solidactions/cli 3.19.0 → 3.20.1
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/README.md +19 -3
- package/dist/command-manifest.json +148 -1
- package/dist/commands/doc-pull.js +7 -7
- package/dist/commands/doc-push.js +6 -6
- package/dist/commands/role-pull.js +215 -0
- package/dist/commands/role-push.js +226 -44
- package/dist/commands/skill-publish.js +12 -4
- package/dist/commands/skill-pull.js +144 -66
- package/dist/commands/skill-push.js +89 -24
- package/dist/index.js +22 -0
- package/dist/utils/atomic-dir.js +111 -0
- package/dist/utils/crew.js +31 -0
- package/dist/utils/mcp.js +161 -22
- package/dist/utils/mutating-commands.js +2 -1
- package/dist/utils/skill-snapshot.js +15 -6
- package/package.json +1 -1
package/dist/utils/mcp.js
CHANGED
|
@@ -40,7 +40,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
40
40
|
};
|
|
41
41
|
})();
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.McpRpcError = void 0;
|
|
44
|
+
exports.retryAfterSeconds = retryAfterSeconds;
|
|
45
|
+
exports.resolveCrewsCall = resolveCrewsCall;
|
|
43
46
|
exports.callCrewsTool = callCrewsTool;
|
|
47
|
+
exports.resolveDocsCall = resolveDocsCall;
|
|
44
48
|
exports.callDocsTool = callDocsTool;
|
|
45
49
|
exports.callCrewsToolContent = callCrewsToolContent;
|
|
46
50
|
const http = __importStar(require("http"));
|
|
@@ -50,6 +54,42 @@ const api_1 = require("./api");
|
|
|
50
54
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
51
55
|
const pkg = require('../../package.json');
|
|
52
56
|
const CLI_VERSION = pkg.version;
|
|
57
|
+
/** A JSON-RPC `error` member in the server's response (protocol-level failure, not a tool isError). */
|
|
58
|
+
class McpRpcError extends Error {
|
|
59
|
+
code;
|
|
60
|
+
constructor(code, message) {
|
|
61
|
+
super(message);
|
|
62
|
+
this.code = code;
|
|
63
|
+
this.name = 'McpRpcError';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.McpRpcError = McpRpcError;
|
|
67
|
+
/** Total HTTP attempts for one call when the server answers 429 (the first try plus 2 retries). */
|
|
68
|
+
const RATE_LIMIT_MAX_ATTEMPTS = 3;
|
|
69
|
+
/** Wait used when a 429 carries no usable Retry-After. */
|
|
70
|
+
const RATE_LIMIT_DEFAULT_WAIT_SEC = 5;
|
|
71
|
+
/** No single wait exceeds this, whatever the server asks for. */
|
|
72
|
+
const RATE_LIMIT_MAX_WAIT_SEC = 60;
|
|
73
|
+
/** Seconds to wait for a Retry-After value (integer seconds or HTTP-date, RFC 9110); default when missing/invalid; capped. */
|
|
74
|
+
function retryAfterSeconds(header) {
|
|
75
|
+
const value = (Array.isArray(header) ? header[0] : header)?.trim();
|
|
76
|
+
let sec = RATE_LIMIT_DEFAULT_WAIT_SEC;
|
|
77
|
+
if (value) {
|
|
78
|
+
if (/^\d+$/.test(value)) {
|
|
79
|
+
sec = parseInt(value, 10);
|
|
80
|
+
}
|
|
81
|
+
else if (/^[+-]?\d+(\.\d+)?$/.test(value)) {
|
|
82
|
+
// Signed or fractional numbers are not valid Retry-After; wait at least 1s (only a literal "0" waits 0).
|
|
83
|
+
sec = Math.max(1, Math.ceil(Number(value)));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const at = Date.parse(value);
|
|
87
|
+
if (!Number.isNaN(at))
|
|
88
|
+
sec = Math.max(1, Math.ceil((at - Date.now()) / 1000));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return Math.min(sec, RATE_LIMIT_MAX_WAIT_SEC);
|
|
92
|
+
}
|
|
53
93
|
/** Internal: POST one tools/call and return the raw result envelope (isError + content blocks). */
|
|
54
94
|
async function postMcpTool(config, endpointPath, toolName, args) {
|
|
55
95
|
const baseHeaders = (0, api_1.getApiHeaders)(config, 'application/json');
|
|
@@ -66,7 +106,7 @@ async function postMcpTool(config, endpointPath, toolName, args) {
|
|
|
66
106
|
const parsed = new url_1.URL(`${config.host}${endpointPath}`);
|
|
67
107
|
const isHttps = parsed.protocol === 'https:';
|
|
68
108
|
const transport = isHttps ? https : http;
|
|
69
|
-
const
|
|
109
|
+
const attempt = () => new Promise((resolve, reject) => {
|
|
70
110
|
const options = {
|
|
71
111
|
hostname: parsed.hostname,
|
|
72
112
|
port: parsed.port || (isHttps ? 443 : 80),
|
|
@@ -75,24 +115,38 @@ async function postMcpTool(config, endpointPath, toolName, args) {
|
|
|
75
115
|
headers: { ...headers, 'Content-Length': Buffer.byteLength(body) },
|
|
76
116
|
};
|
|
77
117
|
const req = transport.request(options, (res) => {
|
|
78
|
-
|
|
79
|
-
|
|
118
|
+
// Collect bytes and decode once: appending Buffer chunks to a string decodes
|
|
119
|
+
// each chunk separately and corrupts multibyte UTF-8 split across chunks.
|
|
120
|
+
const chunks = [];
|
|
121
|
+
res.on('data', (chunk) => { chunks.push(chunk); });
|
|
80
122
|
res.on('end', () => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
resolve(raw);
|
|
89
|
-
}
|
|
123
|
+
resolve({
|
|
124
|
+
status: res.statusCode ?? 0,
|
|
125
|
+
retryAfter: res.headers['retry-after'],
|
|
126
|
+
raw: Buffer.concat(chunks).toString('utf8'),
|
|
127
|
+
});
|
|
90
128
|
});
|
|
91
129
|
});
|
|
92
130
|
req.on('error', reject);
|
|
93
131
|
req.write(body);
|
|
94
132
|
req.end();
|
|
95
133
|
});
|
|
134
|
+
let last;
|
|
135
|
+
for (let n = 1;; n++) {
|
|
136
|
+
last = await attempt();
|
|
137
|
+
if (last.status !== 429 || n >= RATE_LIMIT_MAX_ATTEMPTS)
|
|
138
|
+
break;
|
|
139
|
+
const waitSec = retryAfterSeconds(last.retryAfter);
|
|
140
|
+
process.stderr.write(`solidactions: rate limited by server (429); retrying in ${waitSec}s (attempt ${n + 1}/${RATE_LIMIT_MAX_ATTEMPTS})\n`);
|
|
141
|
+
await new Promise((resolve) => setTimeout(resolve, waitSec * 1000));
|
|
142
|
+
}
|
|
143
|
+
if (last.status === 404) {
|
|
144
|
+
throw new Error(`MCP request failed: ${parsed.host} has no ${endpointPath} endpoint — the server may be older or newer than this CLI (${CLI_VERSION}). Raw: HTTP 404 ${last.raw}`);
|
|
145
|
+
}
|
|
146
|
+
if (last.status >= 400) {
|
|
147
|
+
throw new Error(`MCP request failed with HTTP ${last.status}: ${last.raw}`);
|
|
148
|
+
}
|
|
149
|
+
const responseData = last.raw;
|
|
96
150
|
let parsed2;
|
|
97
151
|
try {
|
|
98
152
|
parsed2 = JSON.parse(responseData);
|
|
@@ -100,6 +154,9 @@ async function postMcpTool(config, endpointPath, toolName, args) {
|
|
|
100
154
|
catch {
|
|
101
155
|
throw new Error(`MCP server returned non-JSON response: ${responseData}`);
|
|
102
156
|
}
|
|
157
|
+
if (parsed2?.error) {
|
|
158
|
+
throw new McpRpcError(parsed2.error.code ?? -1, `MCP ${toolName}: ${parsed2.error.message ?? JSON.stringify(parsed2.error)}`);
|
|
159
|
+
}
|
|
103
160
|
const result = parsed2?.result;
|
|
104
161
|
return { isError: result?.isError === true, content: result?.content ?? [] };
|
|
105
162
|
}
|
|
@@ -110,7 +167,10 @@ async function postMcpTool(config, endpointPath, toolName, args) {
|
|
|
110
167
|
*/
|
|
111
168
|
async function callMcpTool(config, endpointPath, toolName, args) {
|
|
112
169
|
const raw = await postMcpTool(config, endpointPath, toolName, args);
|
|
113
|
-
|
|
170
|
+
if (!raw.content || raw.content.length === 0) {
|
|
171
|
+
return { ok: false, data: { code: 'empty_result', message: `MCP ${toolName} returned no content` } };
|
|
172
|
+
}
|
|
173
|
+
const textContent = raw.content[0]?.text ?? '{}';
|
|
114
174
|
let toolData;
|
|
115
175
|
try {
|
|
116
176
|
toolData = JSON.parse(textContent);
|
|
@@ -121,21 +181,99 @@ async function callMcpTool(config, endpointPath, toolName, args) {
|
|
|
121
181
|
return { ok: !raw.isError, data: toolData };
|
|
122
182
|
}
|
|
123
183
|
const UNIFIED_MCP_PATH = '/mcp';
|
|
124
|
-
//
|
|
125
|
-
|
|
184
|
+
// Current catalog (solidactions-app ToolCatalog.php): the public tool depends on the action.
|
|
185
|
+
// Only actions the CLI actually sends are routed; anything else throws in resolveCrewsCall.
|
|
186
|
+
const CREWS_ROUTES = {
|
|
187
|
+
skills: {
|
|
188
|
+
list: { tool: 'crews_skills_read' },
|
|
189
|
+
read: { tool: 'crews_skills_read' },
|
|
190
|
+
read_reference_file: { tool: 'crews_skills_read' },
|
|
191
|
+
create: { tool: 'crews_skills_manage' },
|
|
192
|
+
edit: { tool: 'crews_skills_manage' },
|
|
193
|
+
delete: { tool: 'crews_delete', action: 'delete_skill' },
|
|
194
|
+
sandbox_exec: { tool: 'crews_sandbox', action: 'skill_exec', rename: { environment: 'skill_exec_environment' } },
|
|
195
|
+
},
|
|
196
|
+
roles: {
|
|
197
|
+
list: { tool: 'crews_roles_read' },
|
|
198
|
+
read: { tool: 'crews_roles_read' },
|
|
199
|
+
list_skills: { tool: 'crews_roles_read' },
|
|
200
|
+
read_skill: { tool: 'crews_roles_read' },
|
|
201
|
+
read_reference_file: { tool: 'crews_roles_read' },
|
|
202
|
+
create: { tool: 'crews_roles_manage' },
|
|
203
|
+
edit: { tool: 'crews_roles_manage' },
|
|
204
|
+
create_skill: { tool: 'crews_roles_manage' },
|
|
205
|
+
edit_skill: { tool: 'crews_roles_manage' },
|
|
206
|
+
sandbox_exec: { tool: 'crews_sandbox', action: 'role_exec', rename: { environment: 'role_exec_environment' } },
|
|
207
|
+
},
|
|
208
|
+
};
|
|
126
209
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
210
|
+
* Map a CLI-level crews call (group + action) to the public MCP tool, action and
|
|
211
|
+
* param names of the current catalog. Throws for an action the CLI has no route for.
|
|
129
212
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
213
|
+
function resolveCrewsCall(group, args) {
|
|
214
|
+
const action = String(args.action ?? '');
|
|
215
|
+
const route = CREWS_ROUTES[group][action];
|
|
216
|
+
if (!route)
|
|
217
|
+
throw new Error(`unsupported crews action: ${group}.${action}`);
|
|
218
|
+
const out = {};
|
|
219
|
+
for (const [k, v] of Object.entries(args)) {
|
|
220
|
+
if (v === undefined)
|
|
221
|
+
continue;
|
|
222
|
+
out[route.rename?.[k] ?? k] = v;
|
|
223
|
+
}
|
|
224
|
+
if (route.action)
|
|
225
|
+
out.action = route.action;
|
|
226
|
+
return { tool: route.tool, args: out };
|
|
227
|
+
}
|
|
228
|
+
function isCrewsGroup(name) {
|
|
229
|
+
return name === 'skills' || name === 'roles';
|
|
132
230
|
}
|
|
133
231
|
/**
|
|
134
|
-
* Call a
|
|
232
|
+
* Call a crews MCP tool on the unified /mcp endpoint. 'skills' / 'roles' are CLI
|
|
233
|
+
* groups resolved per action via resolveCrewsCall; any other name (e.g.
|
|
234
|
+
* 'crews_history_manage') is passed through unchanged.
|
|
135
235
|
*/
|
|
136
|
-
async function
|
|
236
|
+
async function callCrewsTool(config, toolName, args) {
|
|
237
|
+
if (isCrewsGroup(toolName)) {
|
|
238
|
+
const r = resolveCrewsCall(toolName, args);
|
|
239
|
+
return callMcpTool(config, UNIFIED_MCP_PATH, r.tool, r.args);
|
|
240
|
+
}
|
|
137
241
|
return callMcpTool(config, UNIFIED_MCP_PATH, toolName, args);
|
|
138
242
|
}
|
|
243
|
+
// Current catalog (solidactions-app ToolCatalog.php): the public docs tool depends on the action.
|
|
244
|
+
// Call sites send the public action names, so only the tool is routed (no action/param renames).
|
|
245
|
+
// Only actions the CLI actually sends are routed; anything else throws in resolveDocsCall.
|
|
246
|
+
const DOCS_ROUTES = {
|
|
247
|
+
list: 'docs_read',
|
|
248
|
+
bulk_read: 'docs_read',
|
|
249
|
+
read_doc: 'docs_read',
|
|
250
|
+
bulk_create: 'docs_manage',
|
|
251
|
+
write: 'docs_manage',
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Map a docs call (public action name) to the public MCP tool of the current
|
|
255
|
+
* catalog. Throws for an action the CLI has no route for; drops undefined values.
|
|
256
|
+
*/
|
|
257
|
+
function resolveDocsCall(args) {
|
|
258
|
+
const action = String(args.action ?? '');
|
|
259
|
+
const tool = DOCS_ROUTES[action];
|
|
260
|
+
if (!tool)
|
|
261
|
+
throw new Error(`unsupported docs action: ${action}`);
|
|
262
|
+
const out = {};
|
|
263
|
+
for (const [k, v] of Object.entries(args)) {
|
|
264
|
+
if (v === undefined)
|
|
265
|
+
continue;
|
|
266
|
+
out[k] = v;
|
|
267
|
+
}
|
|
268
|
+
return { tool, args: out };
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Call a docs MCP tool on the unified /mcp endpoint; the tool is resolved from the action.
|
|
272
|
+
*/
|
|
273
|
+
async function callDocsTool(config, args) {
|
|
274
|
+
const r = resolveDocsCall(args);
|
|
275
|
+
return callMcpTool(config, UNIFIED_MCP_PATH, r.tool, r.args);
|
|
276
|
+
}
|
|
139
277
|
/**
|
|
140
278
|
* Call a crews MCP tool and return the RAW content blocks. Needed for
|
|
141
279
|
* read_reference_file, whose success responses can be an MCP image block
|
|
@@ -143,6 +281,7 @@ async function callDocsTool(config, toolName, args) {
|
|
|
143
281
|
* (callCrewsTool) would throw on those.
|
|
144
282
|
*/
|
|
145
283
|
async function callCrewsToolContent(config, toolName, args) {
|
|
146
|
-
const
|
|
284
|
+
const r = isCrewsGroup(toolName) ? resolveCrewsCall(toolName, args) : { tool: toolName, args };
|
|
285
|
+
const raw = await postMcpTool(config, UNIFIED_MCP_PATH, r.tool, r.args);
|
|
147
286
|
return { ok: !raw.isError, content: raw.content };
|
|
148
287
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* and checking which HTTP verb it sends. Most commands call axios directly
|
|
11
11
|
* (GET = read, POST/PUT/PATCH/DELETE = write). The MCP-backed commands
|
|
12
12
|
* (crews/roles tools: skill push/publish/pull/list/view/delete, role push;
|
|
13
|
-
*
|
|
13
|
+
* docs_read/docs_manage tools: doc push/pull) are transported as a single JSON-RPC
|
|
14
14
|
* `tools/call` POST regardless of semantics (see `postMcpTool` in
|
|
15
15
|
* src/utils/mcp.ts) — for those, the classification follows the MCP tool's
|
|
16
16
|
* `action` argument instead of the outer HTTP verb ('list'/'read' = read,
|
|
@@ -152,6 +152,7 @@ exports.READONLY_COMMANDS = new Set([
|
|
|
152
152
|
'ai init',
|
|
153
153
|
'ai examples',
|
|
154
154
|
'skill pull',
|
|
155
|
+
'role pull',
|
|
155
156
|
'skill list',
|
|
156
157
|
'skill view',
|
|
157
158
|
// Fetches crew variables (read) and runs the working copy locally, like
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Composes two existing MCP actions: crews_skills.read resolves a skill name to
|
|
6
6
|
* its doc_id and reports whether the current revision is unpublished, and
|
|
7
|
-
*
|
|
7
|
+
* crews_history_manage.take_doc_snapshot promotes that revision to all agents.
|
|
8
8
|
*/
|
|
9
9
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -15,11 +15,11 @@ exports.publishSkillByName = publishSkillByName;
|
|
|
15
15
|
exports.emitPublishOutcome = emitPublishOutcome;
|
|
16
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
17
|
const mcp_1 = require("./mcp");
|
|
18
|
-
/** Snapshot a skill by its doc_id (
|
|
18
|
+
/** Snapshot a skill by its doc_id (crews_history_manage.take_doc_snapshot). */
|
|
19
19
|
async function publishSkillByDocId(config, docId) {
|
|
20
20
|
let result;
|
|
21
21
|
try {
|
|
22
|
-
result = await (0, mcp_1.callCrewsTool)(config, '
|
|
22
|
+
result = await (0, mcp_1.callCrewsTool)(config, 'crews_history_manage', { action: 'take_doc_snapshot', doc_id: docId });
|
|
23
23
|
}
|
|
24
24
|
catch (e) {
|
|
25
25
|
return { status: 'error', code: 'mcp_request_failed', message: e.message };
|
|
@@ -35,10 +35,19 @@ async function publishSkillByDocId(config, docId) {
|
|
|
35
35
|
* read response, NOT the take_snapshot error code (the server maps both
|
|
36
36
|
* "nothing to snapshot" and "live-mode" to the same not_snapshotable code).
|
|
37
37
|
*/
|
|
38
|
-
async function publishSkillByName(config, name) {
|
|
38
|
+
async function publishSkillByName(config, name, opts = {}) {
|
|
39
39
|
let read;
|
|
40
40
|
try {
|
|
41
|
-
|
|
41
|
+
if (opts.role) {
|
|
42
|
+
// Role-scoped skill: addressed by role + name (in_crew disambiguates the role).
|
|
43
|
+
const args = { action: 'read_skill', role: opts.role, name };
|
|
44
|
+
if (opts.inCrew)
|
|
45
|
+
args.in_crew = opts.inCrew;
|
|
46
|
+
read = await (0, mcp_1.callCrewsTool)(config, 'roles', args);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
read = await (0, mcp_1.callCrewsTool)(config, 'skills', { action: 'read', identifier: name });
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
52
|
catch (e) {
|
|
44
53
|
return { status: 'error', code: 'mcp_request_failed', message: e.message };
|
|
@@ -81,7 +90,7 @@ function emitPublishOutcome(name, outcome, opts = {}) {
|
|
|
81
90
|
const prefix = opts.pushed ? 'pushed, but publish failed — ' : '';
|
|
82
91
|
process.stderr.write(chalk_1.default.red(`${prefix}${outcome.code}: ${outcome.message}\n`));
|
|
83
92
|
if (opts.pushed) {
|
|
84
|
-
process.stderr.write(chalk_1.default.yellow(` The skill was pushed. Retry: solidactions skill publish ${name}\n`));
|
|
93
|
+
process.stderr.write(chalk_1.default.yellow(` The skill was pushed. Retry: solidactions skill publish ${name}${opts.role ? ` --role ${opts.role}` : ''}${opts.role && opts.inCrew ? ` --in-crew ${opts.inCrew}` : ''}\n`));
|
|
85
94
|
}
|
|
86
95
|
process.exit(1);
|
|
87
96
|
}
|