@solidactions/cli 1.27.0 → 1.29.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/README.md +20 -2
- package/dist/commands/crew-env-delete.js +50 -0
- package/dist/commands/crew-env-list.js +78 -0
- package/dist/commands/crew-env-push.js +162 -0
- package/dist/commands/crew-env-set.js +78 -0
- package/dist/commands/dev.js +39 -10
- package/dist/commands/docs-pull.js +422 -0
- package/dist/commands/docs-push.js +115 -3
- package/dist/commands/docs-upload.js +111 -0
- package/dist/commands/skill-exec.js +61 -0
- package/dist/commands/skill-publish.js +22 -0
- package/dist/commands/skill-pull.js +12 -0
- package/dist/commands/skill-push.js +160 -7
- package/dist/commands/skill-run.js +164 -0
- package/dist/index.js +106 -1
- package/dist/utils/crew.js +72 -0
- package/dist/utils/skill-snapshot.js +89 -0
- package/package.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.skillExecWithConfig = skillExecWithConfig;
|
|
7
|
+
exports.skillExec = skillExec;
|
|
8
|
+
/**
|
|
9
|
+
* solidactions skill exec <name> [--role <r>] [--environment <env>] -- <command...>
|
|
10
|
+
*
|
|
11
|
+
* Runs a command against the DEPLOYED skill in its real sandbox runtime via
|
|
12
|
+
* the crews MCP exec_skill action — the post-push smoke step. Counterpart to
|
|
13
|
+
* `skill run` (local). DELIBERATE DIVERGENCE from `skill run`: default
|
|
14
|
+
* environment here is `production` (matches the server default — this is the
|
|
15
|
+
* "verify deployed" step); `skill run` defaults to `dev` (a local dev loop).
|
|
16
|
+
*/
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const api_1 = require("../utils/api");
|
|
19
|
+
const mcp_1 = require("../utils/mcp");
|
|
20
|
+
const skill_run_1 = require("./skill-run");
|
|
21
|
+
async function skillExecWithConfig(name, commandParts, options, config) {
|
|
22
|
+
if (commandParts.length === 0) {
|
|
23
|
+
process.stderr.write(chalk_1.default.red('error: no command given — usage: skill exec <name> -- <command...>\n'));
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const command = commandParts.map(skill_run_1.shellQuoteArg).join(' ');
|
|
27
|
+
const isRole = Boolean(options.role);
|
|
28
|
+
const tool = isRole ? 'roles' : 'skills';
|
|
29
|
+
const args = isRole
|
|
30
|
+
? { action: 'exec_skill', role: options.role, name, command }
|
|
31
|
+
: { action: 'exec_skill', identifier: name, command };
|
|
32
|
+
if (options.environment)
|
|
33
|
+
args.environment = options.environment;
|
|
34
|
+
if (isRole && options.inCrew)
|
|
35
|
+
args.in_crew = options.inCrew;
|
|
36
|
+
let result;
|
|
37
|
+
try {
|
|
38
|
+
result = await (0, mcp_1.callCrewsTool)(config, tool, args);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
if (!result.ok) {
|
|
45
|
+
const code = result.data?.code ?? 'unknown_error';
|
|
46
|
+
const message = result.data?.message ?? 'MCP returned an error with no message';
|
|
47
|
+
process.stderr.write(chalk_1.default.red(`error: ${code}: ${message}\n`));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
const data = result.data;
|
|
51
|
+
if (data.stdout)
|
|
52
|
+
process.stdout.write(data.stdout.endsWith('\n') ? data.stdout : data.stdout + '\n');
|
|
53
|
+
if (data.stderr)
|
|
54
|
+
process.stderr.write(data.stderr.endsWith('\n') ? data.stderr : data.stderr + '\n');
|
|
55
|
+
process.stderr.write(chalk_1.default.blue(`remote exec: status=${data.status ?? 'unknown'} exit_code=${data.exit_code ?? 'unknown'}\n`));
|
|
56
|
+
process.exit(data.exit_code ?? 1);
|
|
57
|
+
}
|
|
58
|
+
async function skillExec(name, commandParts, options) {
|
|
59
|
+
const config = await (0, api_1.requireConfigWithWorkspace)();
|
|
60
|
+
await skillExecWithConfig(name, commandParts, options, config);
|
|
61
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* solidactions skill publish <name>
|
|
4
|
+
*
|
|
5
|
+
* Publishes (snapshots) a shared skill so its latest pushed revision goes live
|
|
6
|
+
* for agents.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.skillPublishWithConfig = skillPublishWithConfig;
|
|
10
|
+
exports.skillPublish = skillPublish;
|
|
11
|
+
const api_1 = require("../utils/api");
|
|
12
|
+
const skill_snapshot_1 = require("../utils/skill-snapshot");
|
|
13
|
+
/** Core implementation — accepts an injected config for tests. */
|
|
14
|
+
async function skillPublishWithConfig(name, options, config) {
|
|
15
|
+
const outcome = await (0, skill_snapshot_1.publishSkillByName)(config, name);
|
|
16
|
+
(0, skill_snapshot_1.emitPublishOutcome)(name, outcome, { json: options.json });
|
|
17
|
+
}
|
|
18
|
+
/** Entry point called from index.ts. */
|
|
19
|
+
async function skillPublish(name, options) {
|
|
20
|
+
const config = await (0, api_1.requireConfigWithWorkspace)();
|
|
21
|
+
await skillPublishWithConfig(name, options, config);
|
|
22
|
+
}
|
|
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SKILL_SIDECAR = void 0;
|
|
17
18
|
exports.skillPullWithConfig = skillPullWithConfig;
|
|
18
19
|
exports.skillPull = skillPull;
|
|
19
20
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -22,6 +23,8 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
22
23
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
23
24
|
const api_1 = require("../utils/api");
|
|
24
25
|
const mcp_1 = require("../utils/mcp");
|
|
26
|
+
/** Filename of the provenance sidecar written alongside a pulled skill. */
|
|
27
|
+
exports.SKILL_SIDECAR = '.solidactions-skill.json';
|
|
25
28
|
/**
|
|
26
29
|
* Core implementation — accepts an injected config so tests can point at a
|
|
27
30
|
* stub server without touching the filesystem config.
|
|
@@ -107,6 +110,15 @@ async function skillPullWithConfig(name, dest, options, config) {
|
|
|
107
110
|
fs_1.default.writeFileSync(target, content, 'utf8');
|
|
108
111
|
writtenCount++;
|
|
109
112
|
}
|
|
113
|
+
// Write the provenance sidecar so downstream commands (e.g. `skill push`)
|
|
114
|
+
// can detect drift against the revision this pull was taken from.
|
|
115
|
+
const sidecar = {
|
|
116
|
+
identifier: data.identifier,
|
|
117
|
+
doc_id: typeof data.doc_id === 'string' ? parseInt(data.doc_id, 10) : data.doc_id,
|
|
118
|
+
head_revision_id: typeof data.head_revision_id === 'string' ? parseInt(data.head_revision_id, 10) : (data.head_revision_id ?? null),
|
|
119
|
+
role: null,
|
|
120
|
+
};
|
|
121
|
+
fs_1.default.writeFileSync(path_1.default.join(absOut, exports.SKILL_SIDECAR), JSON.stringify(sidecar, null, 2) + '\n', 'utf8');
|
|
110
122
|
const refSummary = writtenCount === 1 ? '1 reference' : `${writtenCount} references`;
|
|
111
123
|
console.log(chalk_1.default.green(`pulled skill '${name}' → ${out} (${refSummary})`));
|
|
112
124
|
process.exit(0);
|
|
@@ -20,6 +20,7 @@ exports.readReferences = readReferences;
|
|
|
20
20
|
exports.readSkillDir = readSkillDir;
|
|
21
21
|
exports.parseCommandFile = parseCommandFile;
|
|
22
22
|
exports.pushParsedSkill = pushParsedSkill;
|
|
23
|
+
exports.stagedPushWarning = stagedPushWarning;
|
|
23
24
|
exports.skillPushWithConfig = skillPushWithConfig;
|
|
24
25
|
exports.skillPush = skillPush;
|
|
25
26
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -28,6 +29,8 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
28
29
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
29
30
|
const api_1 = require("../utils/api");
|
|
30
31
|
const mcp_1 = require("../utils/mcp");
|
|
32
|
+
const skill_snapshot_1 = require("../utils/skill-snapshot");
|
|
33
|
+
const skill_pull_1 = require("./skill-pull");
|
|
31
34
|
/**
|
|
32
35
|
* Protocol param names reserved by the skills/roles MCP tool actions. Frontmatter
|
|
33
36
|
* keys that collide with these would silently corrupt the request once spread
|
|
@@ -97,6 +100,11 @@ function parseSkillFile(content) {
|
|
|
97
100
|
* keep a bare-filename key (e.g. "helper.py"), and files in subfolders keep
|
|
98
101
|
* their relative path (e.g. "references/member-roles.md") — matching how
|
|
99
102
|
* SKILL.md cites them, so bundled reference docs land complete (#247).
|
|
103
|
+
*
|
|
104
|
+
* Also excludes `skill pull`'s provenance sidecar (SKILL_SIDECAR) and
|
|
105
|
+
* `skill run`'s local runtime-state dir (.sa-state/) — neither is skill
|
|
106
|
+
* content, and uploading them would leak local revision bookkeeping / state
|
|
107
|
+
* into the remote library and agent sandboxes.
|
|
100
108
|
*/
|
|
101
109
|
function readReferences(dir) {
|
|
102
110
|
const references = {};
|
|
@@ -104,6 +112,8 @@ function readReferences(dir) {
|
|
|
104
112
|
for (const entry of fs_1.default.readdirSync(current, { withFileTypes: true })) {
|
|
105
113
|
const abs = path_1.default.join(current, entry.name);
|
|
106
114
|
if (entry.isDirectory()) {
|
|
115
|
+
if (entry.name === '.sa-state')
|
|
116
|
+
continue; // skill run's local runtime-state dir
|
|
107
117
|
walk(abs);
|
|
108
118
|
continue;
|
|
109
119
|
}
|
|
@@ -113,6 +123,8 @@ function readReferences(dir) {
|
|
|
113
123
|
const key = path_1.default.relative(dir, abs).split(path_1.default.sep).join('/');
|
|
114
124
|
if (key === 'SKILL.md')
|
|
115
125
|
continue; // exclude only the top-level skill file
|
|
126
|
+
if (key === skill_pull_1.SKILL_SIDECAR)
|
|
127
|
+
continue; // exclude the skill pull provenance sidecar
|
|
116
128
|
references[key] = fs_1.default.readFileSync(abs, 'utf8');
|
|
117
129
|
}
|
|
118
130
|
};
|
|
@@ -192,8 +204,15 @@ function parseCommandFile(filename, content) {
|
|
|
192
204
|
* When options.dryRun is true, performs only a skills.read pre-flight and
|
|
193
205
|
* returns {status:'would-create'} or {status:'would-update'} without any
|
|
194
206
|
* create or edit call.
|
|
207
|
+
*
|
|
208
|
+
* sidecarRevision (edit path only): the pulled skill's last-known head_revision_id
|
|
209
|
+
* (from the local .solidactions-skill.json sidecar), sent as base_version_id so the
|
|
210
|
+
* server can detect drift. undefined = no sidecar (nothing to guard); null = sidecar
|
|
211
|
+
* present but never published. Ignored when options.force is set. On a concurrent_edit
|
|
212
|
+
* response, throws a message naming the remote's current_revision_id, the local base,
|
|
213
|
+
* and --force as the override.
|
|
195
214
|
*/
|
|
196
|
-
async function pushParsedSkill(payload, options, config) {
|
|
215
|
+
async function pushParsedSkill(payload, options, config, sidecarRevision) {
|
|
197
216
|
const { name, description, properties, body, references } = payload;
|
|
198
217
|
assertNoReservedFrontmatterKeys(properties);
|
|
199
218
|
const isRole = !!options.role;
|
|
@@ -239,9 +258,10 @@ async function pushParsedSkill(payload, options, config) {
|
|
|
239
258
|
}
|
|
240
259
|
// On name collision, switch to the edit path.
|
|
241
260
|
if (!result.ok && result.data?.code === 'name_collision') {
|
|
261
|
+
const guardBaseVersion = sidecarRevision != null && !options.force;
|
|
242
262
|
const editArgs = isRole
|
|
243
|
-
? { ...properties, action: 'edit_skill', role: options.role, name, description, body, references }
|
|
244
|
-
: { ...properties, action: 'edit', identifier: name, description, body, references };
|
|
263
|
+
? { ...properties, action: 'edit_skill', role: options.role, name, description, body, references, ...(guardBaseVersion ? { base_version_id: sidecarRevision } : {}) }
|
|
264
|
+
: { ...properties, action: 'edit', identifier: name, description, body, references, ...(guardBaseVersion ? { base_version_id: sidecarRevision } : {}) };
|
|
245
265
|
try {
|
|
246
266
|
result = await (0, mcp_1.callCrewsTool)(config, tool, editArgs);
|
|
247
267
|
}
|
|
@@ -251,6 +271,10 @@ async function pushParsedSkill(payload, options, config) {
|
|
|
251
271
|
if (!result.ok) {
|
|
252
272
|
const errData = result.data;
|
|
253
273
|
const errCode = errData?.code ?? 'unknown_error';
|
|
274
|
+
if (errCode === 'concurrent_edit') {
|
|
275
|
+
const currentRevisionId = errData?.current_revision_id;
|
|
276
|
+
throw new Error(`remote skill changed since your pull (their revision ${currentRevisionId}, your base ${sidecarRevision}) — re-pull to merge, or pass --force to overwrite`);
|
|
277
|
+
}
|
|
254
278
|
const errMsg = errData?.message ?? 'MCP returned an error with no message';
|
|
255
279
|
throw new Error(`${errCode}: ${errMsg}`);
|
|
256
280
|
}
|
|
@@ -288,6 +312,98 @@ function printPushResult(result, options) {
|
|
|
288
312
|
console.log(chalk_1.default.green(`created skill '${name}' (doc ${skillDocId}, ${refCount} refs)`));
|
|
289
313
|
}
|
|
290
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Build the "staged, not published" warning for a successful single-skill push,
|
|
317
|
+
* or null when nothing needs publishing.
|
|
318
|
+
*
|
|
319
|
+
* Edit path (status 'updated'): default reads return the active snapshot, so a
|
|
320
|
+
* new revision is dark to agents until published — warn when the server reports
|
|
321
|
+
* has_unpublished_revisions === true.
|
|
322
|
+
* Create path (status 'created'): a brand-new skill has no snapshot, so reads
|
|
323
|
+
* fall back to the unversioned draft (it runs, just isn't pinned) — warn on a
|
|
324
|
+
* truthy snapshot_hint (null when the skill is version_mode=live).
|
|
325
|
+
* Dry-run statuses never warn.
|
|
326
|
+
*/
|
|
327
|
+
function stagedPushWarning(result, isRole) {
|
|
328
|
+
const { status, name, data } = result;
|
|
329
|
+
if (status === 'created') {
|
|
330
|
+
if (!data.snapshot_hint) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else if (status === 'updated') {
|
|
335
|
+
if (data.has_unpublished_revisions !== true) {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
const publishLine = isRole
|
|
343
|
+
? ` Publish this role-scoped skill via the MCP crews_versions take_snapshot tool.\n`
|
|
344
|
+
: ` Run: solidactions skill publish ${name}\n`;
|
|
345
|
+
const headline = status === 'updated'
|
|
346
|
+
? `⚠ Staged, not published. This revision won't run for agents until you publish it.\n`
|
|
347
|
+
: `⚠ Not yet published. Agents read the unversioned draft until you publish to pin a version.\n`;
|
|
348
|
+
return headline + publishLine;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Read the local provenance sidecar (written by `skill pull`), if present.
|
|
352
|
+
* Returns null when absent, or unreadable/malformed — nothing to guard against on push.
|
|
353
|
+
*/
|
|
354
|
+
function readSidecar(dir) {
|
|
355
|
+
const sidecarPath = path_1.default.join(dir, skill_pull_1.SKILL_SIDECAR);
|
|
356
|
+
if (!fs_1.default.existsSync(sidecarPath)) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
return JSON.parse(fs_1.default.readFileSync(sidecarPath, 'utf8'));
|
|
361
|
+
}
|
|
362
|
+
catch {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* After a successful guarded edit or a create, refresh the local sidecar's
|
|
368
|
+
* head_revision_id so the *next* push's drift check is against the version we
|
|
369
|
+
* just wrote, not a stale one from the original pull. Prefers the revision id
|
|
370
|
+
* carried on the response; falls back to one skills.read (or roles.read_skill
|
|
371
|
+
* for --role) when the response doesn't carry one.
|
|
372
|
+
*
|
|
373
|
+
* On 'created' specifically, a lookup miss clears head_revision_id to null
|
|
374
|
+
* rather than leaving the sidecar's old value in place: 'created' means the
|
|
375
|
+
* name didn't collide, so this is either a brand-new skill or a remote
|
|
376
|
+
* delete+recreate — either way the old revision id belongs to a different
|
|
377
|
+
* (possibly now-deleted) document, and sending it as base_version_id on a
|
|
378
|
+
* future edit would false-positive the concurrent_edit drift guard.
|
|
379
|
+
*
|
|
380
|
+
* Best-effort otherwise: a failed lookup on the 'updated' path just leaves
|
|
381
|
+
* the sidecar as-is rather than failing the push (which already succeeded).
|
|
382
|
+
*/
|
|
383
|
+
async function refreshSidecarRevision(dir, sidecar, pushResult, options, config) {
|
|
384
|
+
const fromResponse = pushResult.data.head_revision_id ?? pushResult.data.version_id;
|
|
385
|
+
let headRevisionId = typeof fromResponse === 'number' ? fromResponse : null;
|
|
386
|
+
if (headRevisionId === null) {
|
|
387
|
+
const isRole = !!options.role;
|
|
388
|
+
const readArgs = isRole
|
|
389
|
+
? { action: 'read_skill', role: options.role, name: pushResult.name }
|
|
390
|
+
: { action: 'read', identifier: pushResult.name };
|
|
391
|
+
try {
|
|
392
|
+
const readResult = await (0, mcp_1.callCrewsTool)(config, isRole ? 'roles' : 'skills', readArgs);
|
|
393
|
+
if (readResult.ok && typeof readResult.data?.head_revision_id === 'number') {
|
|
394
|
+
headRevisionId = readResult.data.head_revision_id;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
// Best-effort refresh — leave the sidecar stale rather than failing the push.
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (headRevisionId === null && pushResult.status !== 'created') {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const updated = { ...sidecar, head_revision_id: headRevisionId };
|
|
405
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, skill_pull_1.SKILL_SIDECAR), JSON.stringify(updated, null, 2) + '\n', 'utf8');
|
|
406
|
+
}
|
|
291
407
|
/**
|
|
292
408
|
* Core implementation — accepts an injected config so tests can point at a
|
|
293
409
|
* stub server without touching the filesystem config.
|
|
@@ -301,6 +417,10 @@ async function skillPushWithConfig(dir, options, config) {
|
|
|
301
417
|
process.stderr.write(chalk_1.default.red(`error: "${dir}" is not a directory.\n`));
|
|
302
418
|
process.exit(1);
|
|
303
419
|
}
|
|
420
|
+
if (options.publish && options.role) {
|
|
421
|
+
process.stderr.write(chalk_1.default.red('error: --publish is not supported with --role yet; publish the role-scoped skill via the MCP take_snapshot tool.\n'));
|
|
422
|
+
process.exit(1);
|
|
423
|
+
}
|
|
304
424
|
const topLevelSkillMd = path_1.default.join(absDir, 'SKILL.md');
|
|
305
425
|
// -------------------------------------------------------------------------
|
|
306
426
|
// Single-skill mode: <dir>/SKILL.md exists
|
|
@@ -314,25 +434,58 @@ async function skillPushWithConfig(dir, options, config) {
|
|
|
314
434
|
process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
|
|
315
435
|
process.exit(1);
|
|
316
436
|
}
|
|
437
|
+
const sidecar = readSidecar(absDir);
|
|
438
|
+
const sidecarRevision = sidecar ? (sidecar.head_revision_id ?? null) : undefined;
|
|
317
439
|
let pushResult;
|
|
318
440
|
try {
|
|
319
|
-
pushResult = await pushParsedSkill(payload, options, config);
|
|
441
|
+
pushResult = await pushParsedSkill(payload, options, config, sidecarRevision);
|
|
320
442
|
}
|
|
321
443
|
catch (e) {
|
|
322
444
|
process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
|
|
323
445
|
process.exit(1);
|
|
324
446
|
}
|
|
447
|
+
if (sidecar && (pushResult.status === 'updated' || pushResult.status === 'created')) {
|
|
448
|
+
await refreshSidecarRevision(absDir, sidecar, pushResult, options, config);
|
|
449
|
+
}
|
|
450
|
+
// Optionally publish (snapshot) the just-pushed revision (single-skill mode).
|
|
451
|
+
let publishOutcome = null;
|
|
452
|
+
if (options.publish && !options.dryRun) {
|
|
453
|
+
if (pushResult.status === 'created') {
|
|
454
|
+
if (!pushResult.data.snapshot_hint) {
|
|
455
|
+
// Live-mode (version_mode=live) skill: no snapshot to take — already live.
|
|
456
|
+
publishOutcome = { status: 'live_mode' };
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
const createdDocId = (pushResult.data.skill_doc_id ?? pushResult.data.doc_id ?? pushResult.data.id);
|
|
460
|
+
publishOutcome = await (0, skill_snapshot_1.publishSkillByDocId)(config, createdDocId);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
publishOutcome = await (0, skill_snapshot_1.publishSkillByName)(config, pushResult.name);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
325
467
|
if (options.json) {
|
|
326
|
-
|
|
468
|
+
const payload = publishOutcome ? { ...pushResult.data, publish: publishOutcome } : pushResult.data;
|
|
469
|
+
console.log(JSON.stringify(payload));
|
|
470
|
+
process.exit(publishOutcome?.status === 'error' ? 1 : 0);
|
|
327
471
|
}
|
|
328
|
-
|
|
329
|
-
|
|
472
|
+
printPushResult(pushResult, options);
|
|
473
|
+
if (publishOutcome) {
|
|
474
|
+
(0, skill_snapshot_1.emitPublishOutcome)(pushResult.name, publishOutcome, { pushed: true });
|
|
475
|
+
}
|
|
476
|
+
const warning = stagedPushWarning(pushResult, !!options.role);
|
|
477
|
+
if (warning) {
|
|
478
|
+
process.stderr.write(chalk_1.default.yellow(warning));
|
|
330
479
|
}
|
|
331
480
|
process.exit(0);
|
|
332
481
|
}
|
|
333
482
|
// -------------------------------------------------------------------------
|
|
334
483
|
// Plugin mode: push skills/<name>/SKILL.md + commands/<name>.md
|
|
335
484
|
// -------------------------------------------------------------------------
|
|
485
|
+
if (options.publish) {
|
|
486
|
+
process.stderr.write(chalk_1.default.red('error: --publish is not supported when pushing a plugin bundle (multiple skills); publish each with "solidactions skill publish <name>".\n'));
|
|
487
|
+
process.exit(1);
|
|
488
|
+
}
|
|
336
489
|
const payloads = [];
|
|
337
490
|
// One-level glob: skills/*/SKILL.md
|
|
338
491
|
const skillsDir = path_1.default.join(absDir, 'skills');
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.shellQuoteArg = shellQuoteArg;
|
|
7
|
+
exports.parseEnvFile = parseEnvFile;
|
|
8
|
+
exports.assembleEnv = assembleEnv;
|
|
9
|
+
exports.skillRunWithConfig = skillRunWithConfig;
|
|
10
|
+
exports.skillRun = skillRun;
|
|
11
|
+
/**
|
|
12
|
+
* solidactions skill run <dir> [--crew <c>] [--environment <env>] [--env-file <f>] -- <command...>
|
|
13
|
+
*
|
|
14
|
+
* Local analogue of the crews MCP exec_skill: runs <command> with cwd=<dir>
|
|
15
|
+
* (matching the sandbox's cwd=/work/skills/<slug>), with crew variables
|
|
16
|
+
* fetched at runtime from /api/v1/crews/{id}/variables/resolve. Secrets are
|
|
17
|
+
* included only when the API key holds env:reveal; skipped names are printed.
|
|
18
|
+
* DELIBERATE DIVERGENCE from remote exec_skill: default environment is `dev`
|
|
19
|
+
* (this is a dev tool); remote defaults to production. Always prints the env.
|
|
20
|
+
*/
|
|
21
|
+
const fs_1 = __importDefault(require("fs"));
|
|
22
|
+
const os_1 = __importDefault(require("os"));
|
|
23
|
+
const path_1 = __importDefault(require("path"));
|
|
24
|
+
const child_process_1 = require("child_process");
|
|
25
|
+
const axios_1 = __importDefault(require("axios"));
|
|
26
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
27
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
28
|
+
const api_1 = require("../utils/api");
|
|
29
|
+
const crew_1 = require("../utils/crew");
|
|
30
|
+
const RESERVED_KEYS = ['WORKFLOW_INPUT', 'WORKFLOW_INPUT_URL', 'STEPS_TRIGGER_ID', 'TENANT_ID', 'SA_PROXY_URL', 'SA_PROXY_TOKEN', 'WORKFLOW_SLUG', 'PATH', 'HOME'];
|
|
31
|
+
const RESERVED_PREFIXES = ['SOLIDACTIONS_'];
|
|
32
|
+
function isReservedEnvName(name) {
|
|
33
|
+
return RESERVED_KEYS.includes(name) || RESERVED_PREFIXES.some((p) => name.toUpperCase().startsWith(p));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Single-quote a commander-parsed argument for re-injection into a shell
|
|
37
|
+
* command line. commander's `<command...>` variadic already split the
|
|
38
|
+
* user's invocation into discrete argv words (the outer shell did any
|
|
39
|
+
* quote-stripping); joining those words back together with bare spaces and
|
|
40
|
+
* handing them to `sh -c` would let the inner shell reinterpret any
|
|
41
|
+
* metacharacters they contain (spaces, quotes, parens, `&&`, ...). Quoting
|
|
42
|
+
* each word individually keeps it intact as a single shell token, while
|
|
43
|
+
* still letting `shell: true` run multi-word commands.
|
|
44
|
+
*/
|
|
45
|
+
function shellQuoteArg(arg) {
|
|
46
|
+
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
47
|
+
}
|
|
48
|
+
function parseEnvFile(content) {
|
|
49
|
+
const out = {};
|
|
50
|
+
for (const raw of content.split('\n')) {
|
|
51
|
+
const line = raw.trim();
|
|
52
|
+
if (!line || line.startsWith('#'))
|
|
53
|
+
continue;
|
|
54
|
+
const eq = line.indexOf('=');
|
|
55
|
+
if (eq <= 0)
|
|
56
|
+
continue;
|
|
57
|
+
const key = line.slice(0, eq).trim();
|
|
58
|
+
let value = line.slice(eq + 1).trim();
|
|
59
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
60
|
+
value = value.slice(1, -1);
|
|
61
|
+
}
|
|
62
|
+
out[key] = value;
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
function assembleEnv(opts) {
|
|
67
|
+
const warnings = [];
|
|
68
|
+
const env = {};
|
|
69
|
+
for (const [key, value] of Object.entries(opts.resolved)) {
|
|
70
|
+
if (isReservedEnvName(key)) {
|
|
71
|
+
warnings.push(`crew variable '${key}' is reserved (set by the platform at runtime) — ignored`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
env[key] = value;
|
|
75
|
+
}
|
|
76
|
+
for (const [key, value] of Object.entries(opts.fileVars)) {
|
|
77
|
+
if (isReservedEnvName(key)) {
|
|
78
|
+
warnings.push(`env-file key '${key}' is reserved (set by the platform at runtime) — ignored`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (key in env) {
|
|
82
|
+
warnings.push(`env-file override shadows crew variable: ${key}`);
|
|
83
|
+
}
|
|
84
|
+
env[key] = value;
|
|
85
|
+
}
|
|
86
|
+
if (opts.storageScope === 'crew') {
|
|
87
|
+
env.SOLIDACTIONS_STATE_DIR = path_1.default.join(opts.dir, '.sa-state');
|
|
88
|
+
}
|
|
89
|
+
else if (opts.storageScope === 'workspace') {
|
|
90
|
+
env.SOLIDACTIONS_SHARED_DIR = path_1.default.join(os_1.default.homedir(), '.solidactions', 'shared', opts.config.workspaceId ?? 'default');
|
|
91
|
+
}
|
|
92
|
+
env.SOLIDACTIONS_API_URL = `${opts.config.host}/api/v1`;
|
|
93
|
+
env.SOLIDACTIONS_API_TOKEN = opts.config.apiKey;
|
|
94
|
+
env.SOLIDACTIONS_WORKSPACE_ID = opts.config.workspaceId ?? '';
|
|
95
|
+
return { env, warnings };
|
|
96
|
+
}
|
|
97
|
+
function readStorageScope(dir) {
|
|
98
|
+
const skillMd = path_1.default.join(dir, 'SKILL.md');
|
|
99
|
+
if (!fs_1.default.existsSync(skillMd))
|
|
100
|
+
return null;
|
|
101
|
+
const content = fs_1.default.readFileSync(skillMd, 'utf8');
|
|
102
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
103
|
+
if (!match)
|
|
104
|
+
return null;
|
|
105
|
+
const fm = js_yaml_1.default.load(match[1]);
|
|
106
|
+
const scope = fm?.storage?.scope ?? fm?.['storage.scope'] ?? null;
|
|
107
|
+
return scope === 'crew' || scope === 'workspace' ? scope : null;
|
|
108
|
+
}
|
|
109
|
+
async function skillRunWithConfig(dir, commandParts, options, config) {
|
|
110
|
+
const absDir = path_1.default.resolve(dir);
|
|
111
|
+
if (!fs_1.default.existsSync(path_1.default.join(absDir, 'SKILL.md'))) {
|
|
112
|
+
process.stderr.write(chalk_1.default.red(`error: ${dir} does not contain a SKILL.md\n`));
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
if (commandParts.length === 0) {
|
|
116
|
+
process.stderr.write(chalk_1.default.red('error: no command given — usage: skill run <dir> -- <command...>\n'));
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
const environment = options.environment ?? 'dev';
|
|
120
|
+
// Crew vars: --crew wins; else no crew vars (shared-skill parity).
|
|
121
|
+
let resolved = {};
|
|
122
|
+
let skippedSecrets = [];
|
|
123
|
+
if (options.crew) {
|
|
124
|
+
const crew = await (0, crew_1.resolveCrewId)(config, options.crew);
|
|
125
|
+
try {
|
|
126
|
+
const response = await axios_1.default.get(`${config.host}/api/v1/crews/${crew.id}/variables/resolve?environment=${encodeURIComponent(environment)}`, { headers: (0, api_1.getApiHeaders)(config) });
|
|
127
|
+
resolved = response.data?.variables ?? {};
|
|
128
|
+
skippedSecrets = response.data?.skipped_secrets ?? [];
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
process.stderr.write(chalk_1.default.red(`error: failed to resolve crew variables: ${e?.response?.data?.message ?? e.message}\n`));
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
process.stderr.write(chalk_1.default.gray('no --crew given — running without crew variables (shared-skill parity)\n'));
|
|
137
|
+
}
|
|
138
|
+
const fileVars = options.envFile ? parseEnvFile(fs_1.default.readFileSync(path_1.default.resolve(options.envFile), 'utf8')) : {};
|
|
139
|
+
const storageScope = readStorageScope(absDir);
|
|
140
|
+
const { env, warnings } = assembleEnv({ resolved, fileVars, storageScope, dir: absDir, config });
|
|
141
|
+
for (const w of warnings)
|
|
142
|
+
process.stderr.write(chalk_1.default.yellow(`warn: ${w}\n`));
|
|
143
|
+
if (env.SOLIDACTIONS_STATE_DIR)
|
|
144
|
+
fs_1.default.mkdirSync(env.SOLIDACTIONS_STATE_DIR, { recursive: true });
|
|
145
|
+
if (env.SOLIDACTIONS_SHARED_DIR)
|
|
146
|
+
fs_1.default.mkdirSync(env.SOLIDACTIONS_SHARED_DIR, { recursive: true });
|
|
147
|
+
const plainCount = Object.keys(resolved).length;
|
|
148
|
+
process.stderr.write(chalk_1.default.blue(`running locally in ${dir} — env '${environment}', ${plainCount} crew vars loaded\n`));
|
|
149
|
+
if (skippedSecrets.length > 0) {
|
|
150
|
+
process.stderr.write(chalk_1.default.yellow(`${skippedSecrets.length} secret ${skippedSecrets.length === 1 ? 'var' : 'vars'} unavailable (${skippedSecrets.join(', ')}): ` +
|
|
151
|
+
`your API key lacks the 'env:reveal' ability. Mint a key with env:reveal, set a dev value with \`solidactions crew env set\`, or use --env-file.\n`));
|
|
152
|
+
}
|
|
153
|
+
const result = (0, child_process_1.spawnSync)(commandParts.map(shellQuoteArg).join(' '), {
|
|
154
|
+
shell: true,
|
|
155
|
+
cwd: absDir,
|
|
156
|
+
stdio: 'inherit',
|
|
157
|
+
env: { ...process.env, ...env },
|
|
158
|
+
});
|
|
159
|
+
process.exit(result.status ?? 1);
|
|
160
|
+
}
|
|
161
|
+
async function skillRun(dir, commandParts, options) {
|
|
162
|
+
const config = await (0, api_1.requireConfigWithWorkspace)();
|
|
163
|
+
await skillRunWithConfig(dir, commandParts, options, config);
|
|
164
|
+
}
|