@solidactions/cli 3.18.0 → 3.20.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 +34 -4
- package/dist/command-manifest.json +254 -1
- package/dist/commands/database-export.js +512 -0
- 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 +40 -0
- package/dist/utils/atomic-dir.js +111 -0
- package/dist/utils/crew.js +31 -0
- package/dist/utils/mcp.js +129 -19
- package/dist/utils/mutating-commands.js +4 -0
- package/dist/utils/skill-snapshot.js +15 -6
- package/package.json +1 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* solidactions role pull <name> [dir] [--in-crew <crew>] [--no-skills]
|
|
4
|
+
*
|
|
5
|
+
* Fetches a role's PUBLISHED definition from the crews library and reconstructs a
|
|
6
|
+
* local role folder that `role push` accepts as a no-op:
|
|
7
|
+
*
|
|
8
|
+
* <dir>/SKILL.md role frontmatter + body (the format role push reads)
|
|
9
|
+
* <dir>/.solidactions-role.json provenance sidecar (name, in_crew, ...); also the
|
|
10
|
+
* marker that lets a later pull replace this folder
|
|
11
|
+
* <dir>/skills/<skill>/... each role-scoped skill (unless --no-skills), in the
|
|
12
|
+
* same layout as `skill pull --role`
|
|
13
|
+
*
|
|
14
|
+
* Everything is fetched first and then written with ONE writeDirAtomic, so a failed
|
|
15
|
+
* fetch writes nothing and a successful pull replaces the folder as a unit.
|
|
16
|
+
*
|
|
17
|
+
* The role's skill preload configuration is not a property: the server stores
|
|
18
|
+
* always_load_skills / available_skills as role_skill_links rows and returns them top-level
|
|
19
|
+
* in `read`. They are exported into the always_load_skills / available_skills frontmatter
|
|
20
|
+
* fields (identifiers such as "shared/triage", in the server's order), which role push sends
|
|
21
|
+
* back top-level. Skills that sit in the role's own skills/ folder are auto-discovered by the
|
|
22
|
+
* server and appear in its available_skills index under a bare name; those are not links, so
|
|
23
|
+
* bare names are left out of available_skills (they travel in skills/ instead).
|
|
24
|
+
*
|
|
25
|
+
* Inherited properties and skill links are merged by the server (RoleActivator) and are pulled
|
|
26
|
+
* as the effective value: the folder holds what the role resolves to, not only what it sets
|
|
27
|
+
* itself. A role with inherits_from therefore gets a warning: role push of the folder would
|
|
28
|
+
* store the inherited values on the child.
|
|
29
|
+
*/
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.ROLE_SIDECAR = void 0;
|
|
35
|
+
exports.pullRoleWithConfig = pullRoleWithConfig;
|
|
36
|
+
exports.rolePullWithConfig = rolePullWithConfig;
|
|
37
|
+
exports.rolePull = rolePull;
|
|
38
|
+
const path_1 = __importDefault(require("path"));
|
|
39
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const api_1 = require("../utils/api");
|
|
42
|
+
const mcp_1 = require("../utils/mcp");
|
|
43
|
+
const crew_1 = require("../utils/crew");
|
|
44
|
+
const atomic_dir_1 = require("../utils/atomic-dir");
|
|
45
|
+
const skill_push_1 = require("./skill-push");
|
|
46
|
+
const skill_pull_1 = require("./skill-pull");
|
|
47
|
+
Object.defineProperty(exports, "ROLE_SIDECAR", { enumerable: true, get: function () { return skill_pull_1.ROLE_SIDECAR; } });
|
|
48
|
+
/** A user-facing pull failure (message is printed as-is after `error: `). */
|
|
49
|
+
class RolePullError extends Error {
|
|
50
|
+
}
|
|
51
|
+
function isPlainObject(v) {
|
|
52
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
53
|
+
}
|
|
54
|
+
/** A skill name becomes a path segment under skills/, so it must be a single safe segment. */
|
|
55
|
+
function assertSafeSegment(skill) {
|
|
56
|
+
if (typeof skill !== 'string' || skill === '' || skill === '.' || skill === '..' || /[\\/]/.test(skill)) {
|
|
57
|
+
throw new RolePullError(`server returned an unsafe skill name: ${JSON.stringify(skill)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Pull the skill identifiers out of a `read` payload's always_load_skills (resolved bundles) or
|
|
62
|
+
* available_skills (description entries): both carry the link's `identifier`, in server order.
|
|
63
|
+
* A missing field means none; a malformed one is an error rather than a silent loss.
|
|
64
|
+
*/
|
|
65
|
+
function skillIdentifiers(data, key) {
|
|
66
|
+
const raw = data[key];
|
|
67
|
+
if (raw === undefined || raw === null)
|
|
68
|
+
return [];
|
|
69
|
+
if (!Array.isArray(raw))
|
|
70
|
+
throw new RolePullError(`unexpected response shape from server: ${key} is not a list`);
|
|
71
|
+
const out = [];
|
|
72
|
+
for (const entry of raw) {
|
|
73
|
+
const id = isPlainObject(entry) ? entry.identifier : undefined;
|
|
74
|
+
if (typeof id !== 'string' || id === '') {
|
|
75
|
+
throw new RolePullError(`unexpected response shape from server: a ${key} entry has no identifier`);
|
|
76
|
+
}
|
|
77
|
+
if (!out.includes(id))
|
|
78
|
+
out.push(id);
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
function mapReadError(code, message, name, inCrew) {
|
|
83
|
+
if (code === 'no_snapshot') {
|
|
84
|
+
return `role ${name} has no published version (no_snapshot); publish it first, or set version_mode: live`;
|
|
85
|
+
}
|
|
86
|
+
if (code === 'role_not_found') {
|
|
87
|
+
return `role '${name}' not found${inCrew ? ` in crew '${inCrew}'` : ''} (role_not_found); check the name, or pass --in-crew CREW to say which crew it lives in`;
|
|
88
|
+
}
|
|
89
|
+
if (code === 'ambiguous_role') {
|
|
90
|
+
return `role '${name}' exists in multiple crews (ambiguous_role); pass --in-crew CREW to choose one`;
|
|
91
|
+
}
|
|
92
|
+
return `${code}: ${message}`;
|
|
93
|
+
}
|
|
94
|
+
/** Render SKILL.md exactly as `role push` parses it back (body follows the closing --- line verbatim). */
|
|
95
|
+
function renderRoleMd(properties, body) {
|
|
96
|
+
const fm = { name: properties.name, description: properties.description };
|
|
97
|
+
for (const key of skill_push_1.ROLE_FRONTMATTER_PARAMS) {
|
|
98
|
+
if (properties[key] !== undefined && properties[key] !== null)
|
|
99
|
+
fm[key] = properties[key];
|
|
100
|
+
}
|
|
101
|
+
return `---\n${js_yaml_1.default.dump(fm, { lineWidth: -1 })}---\n${body}`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Fetch the role (and, unless withSkills is false, its skills) and replace `dest` with
|
|
105
|
+
* the result as a unit. Throws on any failure, having written nothing.
|
|
106
|
+
*/
|
|
107
|
+
async function pullRoleWithConfig(name, dest, config, opts = {}) {
|
|
108
|
+
const inCrew = opts.inCrew;
|
|
109
|
+
const withSkills = opts.withSkills ?? true;
|
|
110
|
+
// Replacing a folder is destructive: refuse before any network call or write.
|
|
111
|
+
(0, atomic_dir_1.assertReplaceableDir)(dest, skill_pull_1.ROLE_SIDECAR, undefined, 'role');
|
|
112
|
+
const crewArgs = inCrew ? { in_crew: inCrew } : {};
|
|
113
|
+
const read = await (0, mcp_1.callCrewsTool)(config, 'roles', { action: 'read', name, ...crewArgs });
|
|
114
|
+
if (!read.ok) {
|
|
115
|
+
throw new RolePullError(mapReadError(read.data?.code ?? 'unknown_error', read.data?.message ?? 'MCP returned an error with no message', name, inCrew));
|
|
116
|
+
}
|
|
117
|
+
const data = read.data;
|
|
118
|
+
if (!isPlainObject(data) || typeof data.body !== 'string' || !isPlainObject(data.properties)) {
|
|
119
|
+
const keys = isPlainObject(data) ? Object.keys(data) : [];
|
|
120
|
+
throw new RolePullError(`unexpected response shape from server (keys received: ${keys.length ? keys.join(', ') : '(none)'})`);
|
|
121
|
+
}
|
|
122
|
+
const properties = data.properties;
|
|
123
|
+
if (typeof properties.description !== 'string' || properties.description === '') {
|
|
124
|
+
throw new RolePullError(`role '${name}' has no description, so it cannot be written as a pushable SKILL.md`);
|
|
125
|
+
}
|
|
126
|
+
const roleName = typeof properties.name === 'string' && properties.name ? properties.name : name;
|
|
127
|
+
// Values the server redacted are not the real values; pushing them back would corrupt the role.
|
|
128
|
+
const redacted = Array.isArray(data.redacted_keys) ? data.redacted_keys.filter((k) => typeof k === 'string') : [];
|
|
129
|
+
const usable = { ...properties, name: roleName };
|
|
130
|
+
// Skill links are top-level in the payload (not properties). available_skills also lists the
|
|
131
|
+
// role's auto-discovered local skills under bare names, which are not links: keep 'x/y' only.
|
|
132
|
+
const alwaysLoadSkills = skillIdentifiers(data, 'always_load_skills');
|
|
133
|
+
const availableSkills = skillIdentifiers(data, 'available_skills').filter((id) => id.includes('/'));
|
|
134
|
+
if (alwaysLoadSkills.length > 0)
|
|
135
|
+
usable.always_load_skills = alwaysLoadSkills;
|
|
136
|
+
if (availableSkills.length > 0)
|
|
137
|
+
usable.available_skills = availableSkills;
|
|
138
|
+
for (const key of redacted) {
|
|
139
|
+
if (key in usable && key !== 'name' && key !== 'description') {
|
|
140
|
+
delete usable[key];
|
|
141
|
+
process.stderr.write(chalk_1.default.yellow(`warn: property '${key}' is redacted by the server and was not written\n`));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const files = {};
|
|
145
|
+
files['SKILL.md'] = renderRoleMd(usable, data.body);
|
|
146
|
+
if (withSkills) {
|
|
147
|
+
const list = await (0, mcp_1.callCrewsTool)(config, 'roles', { action: 'list_skills', role: name, ...crewArgs });
|
|
148
|
+
if (!list.ok) {
|
|
149
|
+
throw new RolePullError(mapReadError(list.data?.code ?? 'unknown_error', list.data?.message ?? 'MCP returned an error with no message', name, inCrew));
|
|
150
|
+
}
|
|
151
|
+
const skills = list.data?.skills;
|
|
152
|
+
if (!Array.isArray(skills)) {
|
|
153
|
+
throw new RolePullError(`unexpected response shape from list_skills (keys received: ${isPlainObject(list.data) ? Object.keys(list.data).join(', ') : '(none)'})`);
|
|
154
|
+
}
|
|
155
|
+
for (const entry of skills) {
|
|
156
|
+
const skillName = isPlainObject(entry) ? (entry.name ?? entry.identifier) : entry;
|
|
157
|
+
assertSafeSegment(skillName);
|
|
158
|
+
const skillFiles = await (0, skill_pull_1.fetchSkillFiles)(config, skillName, { role: name, inCrew });
|
|
159
|
+
for (const [rel, content] of Object.entries(skillFiles)) {
|
|
160
|
+
files[`skills/${skillName}/${rel}`] = content;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Baseline of the link lists exactly as written to the frontmatter (an absent list is []).
|
|
165
|
+
// role push compares against it, so an unchanged list is left out of the edit and the server
|
|
166
|
+
// keeps every link, including ones this caller could not see.
|
|
167
|
+
const linkBaseline = (key) => Array.isArray(usable[key]) ? usable[key] : [];
|
|
168
|
+
files[skill_pull_1.ROLE_SIDECAR] = JSON.stringify({
|
|
169
|
+
name: roleName,
|
|
170
|
+
in_crew: (0, crew_1.normalizeCrewPath)(inCrew),
|
|
171
|
+
links: {
|
|
172
|
+
always_load_skills: linkBaseline('always_load_skills'),
|
|
173
|
+
available_skills: linkBaseline('available_skills'),
|
|
174
|
+
},
|
|
175
|
+
doc_id: typeof data.doc_id === 'string' ? parseInt(data.doc_id, 10) : (data.doc_id ?? null),
|
|
176
|
+
head_revision_id: typeof data.head_revision_id === 'string' ? parseInt(data.head_revision_id, 10) : (data.head_revision_id ?? null),
|
|
177
|
+
active_snapshot_revision_id: typeof data.active_snapshot_revision_id === 'string'
|
|
178
|
+
? parseInt(data.active_snapshot_revision_id, 10)
|
|
179
|
+
: (data.active_snapshot_revision_id ?? null),
|
|
180
|
+
}, null, 2) + '\n';
|
|
181
|
+
(0, atomic_dir_1.writeDirAtomic)(path_1.default.resolve(dest), files);
|
|
182
|
+
// The server has no unmerged read, so `properties` is the effective (parent-merged) value.
|
|
183
|
+
// Pushing it back would store the parent's entries on this role: make that visible.
|
|
184
|
+
const parent = properties.inherits_from;
|
|
185
|
+
if (typeof parent === 'string' && parent !== '') {
|
|
186
|
+
process.stderr.write(chalk_1.default.yellow(`warn: role ${roleName} inherits from ${parent}; the pulled properties and skill links include inherited values, ` +
|
|
187
|
+
`and pushing this folder back with role push will store them on ${roleName}.\n`));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function fail(message) {
|
|
191
|
+
process.stderr.write(chalk_1.default.red(`error: ${message}\n`));
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
/** CLI wrapper: validates the destination, runs the pull, prints the result and exits. */
|
|
195
|
+
async function rolePullWithConfig(name, dest, options, config) {
|
|
196
|
+
if (dest === undefined && (name === '.' || name === '..' || name.includes('/') || name.includes('\\'))) {
|
|
197
|
+
fail(`'${name}' cannot be used as a default destination folder; pass an explicit [dir] directory`);
|
|
198
|
+
}
|
|
199
|
+
const out = dest ?? './' + name;
|
|
200
|
+
try {
|
|
201
|
+
await pullRoleWithConfig(name, out, config, { inCrew: options.inCrew, withSkills: options.skills !== false });
|
|
202
|
+
}
|
|
203
|
+
catch (e) {
|
|
204
|
+
fail(e.message);
|
|
205
|
+
}
|
|
206
|
+
console.log(chalk_1.default.green(`pulled role '${name}' → ${out}`));
|
|
207
|
+
process.exit(0);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Entry point called from index.ts.
|
|
211
|
+
*/
|
|
212
|
+
async function rolePull(name, dest, options) {
|
|
213
|
+
const config = await (0, api_1.requireConfigWithWorkspace)();
|
|
214
|
+
await rolePullWithConfig(name, dest, options, config);
|
|
215
|
+
}
|
|
@@ -8,16 +8,28 @@
|
|
|
8
8
|
* The role def is a SKILL.md-shaped file (frontmatter name+description, body).
|
|
9
9
|
* Roles carry NO references.
|
|
10
10
|
*
|
|
11
|
-
* Supports --dry-run:
|
|
12
|
-
*
|
|
11
|
+
* Supports --dry-run: prints "[dry-run] would create/update '<name>'" without making any
|
|
12
|
+
* create/edit call, and reports the same outcome (or the same error) the real push would.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* Which crew: --in-crew is required to CREATE a role (the server rejects a create without it
|
|
15
|
+
* before it even checks for a collision). So without --in-crew the role is resolved first via
|
|
16
|
+
* roles `list`: exactly one match -> edit it (in that match's crew); none -> it would be a
|
|
17
|
+
* create, so ask for --in-crew; several -> ambiguous, ask for --in-crew.
|
|
18
|
+
* With --in-crew: create -> on name_collision -> edit (dry-run pre-flights a read).
|
|
15
19
|
* Roles use 'name' (NOT 'identifier') for read and edit.
|
|
20
|
+
*
|
|
21
|
+
* Skill links: `role pull` records the always_load_skills / available_skills it exported in the
|
|
22
|
+
* .solidactions-role.json sidecar. Editing the role the folder was pulled from omits a link list
|
|
23
|
+
* that still equals that baseline (the server keeps all links, including ones the caller cannot
|
|
24
|
+
* see) and refuses a changed list unless --replace-links. Creates and sidecar-less folders send
|
|
25
|
+
* the lists as written.
|
|
16
26
|
*/
|
|
17
27
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
29
|
};
|
|
20
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.readRoleSidecar = readRoleSidecar;
|
|
32
|
+
exports.planLinkBaseline = planLinkBaseline;
|
|
21
33
|
exports.rolePushWithConfig = rolePushWithConfig;
|
|
22
34
|
exports.rolePush = rolePush;
|
|
23
35
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -25,7 +37,149 @@ const path_1 = __importDefault(require("path"));
|
|
|
25
37
|
const chalk_1 = __importDefault(require("chalk"));
|
|
26
38
|
const api_1 = require("../utils/api");
|
|
27
39
|
const mcp_1 = require("../utils/mcp");
|
|
40
|
+
const crew_1 = require("../utils/crew");
|
|
41
|
+
const skill_pull_1 = require("./skill-pull");
|
|
28
42
|
const skill_push_1 = require("./skill-push");
|
|
43
|
+
const LINK_FIELDS = ['always_load_skills', 'available_skills'];
|
|
44
|
+
/** A doc id from JSON (number or numeric string); anything else => null. */
|
|
45
|
+
function asDocId(v) {
|
|
46
|
+
const n = typeof v === 'string' && /^\d+$/.test(v) ? parseInt(v, 10) : v;
|
|
47
|
+
return typeof n === 'number' && Number.isInteger(n) ? n : null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Read the role pull sidecar. Absent, unreadable or nameless => null (treated as a hand-authored
|
|
51
|
+
* folder). A sidecar without `links` (written before links were recorded) has an empty baseline,
|
|
52
|
+
* which errs on the safe side: an unchanged (absent) list is omitted, a present list needs
|
|
53
|
+
* --replace-links.
|
|
54
|
+
*/
|
|
55
|
+
function readRoleSidecar(absDir) {
|
|
56
|
+
const file = path_1.default.join(absDir, skill_pull_1.ROLE_SIDECAR);
|
|
57
|
+
if (!fs_1.default.existsSync(file))
|
|
58
|
+
return null;
|
|
59
|
+
let raw;
|
|
60
|
+
try {
|
|
61
|
+
raw = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (!raw || typeof raw !== 'object' || typeof raw.name !== 'string' || raw.name === '')
|
|
67
|
+
return null;
|
|
68
|
+
const asList = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string') : []);
|
|
69
|
+
return {
|
|
70
|
+
name: raw.name,
|
|
71
|
+
inCrew: (0, crew_1.normalizeCrewPath)(raw.in_crew),
|
|
72
|
+
docId: asDocId(raw.doc_id),
|
|
73
|
+
links: {
|
|
74
|
+
always_load_skills: asList(raw.links?.always_load_skills),
|
|
75
|
+
available_skills: asList(raw.links?.available_skills),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* When editing the role this folder was pulled from, leave unchanged link lists out of the edit
|
|
81
|
+
* (the server then preserves every link, hidden ones included) and refuse a changed list unless
|
|
82
|
+
* --replace-links. Not the pulled role => params as-is. "Pulled role" means the sidecar name equals
|
|
83
|
+
* the frontmatter name and, when both sides know the role's doc id, the doc ids are equal;
|
|
84
|
+
* otherwise (either id unknown) the sidecar's crew, if it recorded one, must equal the target crew
|
|
85
|
+
* after normalisation (trimmed segments, empty ones dropped).
|
|
86
|
+
* Equality is exact and ordered; absent equals []. Returns the params to send and the fields
|
|
87
|
+
* that were kept as-is (present in the frontmatter, left out of the call).
|
|
88
|
+
*/
|
|
89
|
+
function planLinkBaseline(params, sidecar, name, target, replaceLinks) {
|
|
90
|
+
if (!sidecar || sidecar.name !== name)
|
|
91
|
+
return { params, kept: [], refused: null };
|
|
92
|
+
if (sidecar.docId !== null && target.docId != null) {
|
|
93
|
+
if (sidecar.docId !== target.docId)
|
|
94
|
+
return { params, kept: [], refused: null };
|
|
95
|
+
}
|
|
96
|
+
else if (sidecar.inCrew !== null && sidecar.inCrew !== (0, crew_1.normalizeCrewPath)(target.crew)) {
|
|
97
|
+
return { params, kept: [], refused: null };
|
|
98
|
+
}
|
|
99
|
+
const out = { ...params };
|
|
100
|
+
const kept = [];
|
|
101
|
+
for (const field of LINK_FIELDS) {
|
|
102
|
+
const base = sidecar.links[field];
|
|
103
|
+
// Absent equals []; a blank value (`always_load_skills:` => null) is not a list, so it counts as changed.
|
|
104
|
+
const value = out[field] === undefined ? [] : out[field];
|
|
105
|
+
const same = Array.isArray(value) && value.length === base.length && value.every((v, i) => v === base[i]);
|
|
106
|
+
if (same) {
|
|
107
|
+
if (out[field] !== undefined)
|
|
108
|
+
kept.push(field);
|
|
109
|
+
delete out[field];
|
|
110
|
+
}
|
|
111
|
+
else if (!replaceLinks) {
|
|
112
|
+
return {
|
|
113
|
+
params, kept: [],
|
|
114
|
+
refused: `${field} differs from what was pulled. The server may hold skill links you can't see, ` +
|
|
115
|
+
`and replacing the list deletes them. Re-run with --replace-links to replace it anyway.`,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
else if (out[field] === undefined || out[field] === null) {
|
|
119
|
+
out[field] = []; // list removed or left blank in the frontmatter + --replace-links: clear it
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { params: out, kept, refused: null };
|
|
123
|
+
}
|
|
124
|
+
/** planLinkBaseline, exiting 1 with the refusal on stderr. */
|
|
125
|
+
function applyLinkBaseline(params, sidecar, name, target, replaceLinks) {
|
|
126
|
+
const plan = planLinkBaseline(params, sidecar, name, target, replaceLinks);
|
|
127
|
+
if (plan.refused !== null) {
|
|
128
|
+
process.stderr.write(chalk_1.default.red(`error: ${plan.refused}\n`));
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
return plan;
|
|
132
|
+
}
|
|
133
|
+
/** Print a role-push tool error (mapping crew-scoping codes to a hint) and exit 1. */
|
|
134
|
+
function failWithToolError(data, roleName) {
|
|
135
|
+
const code = data?.code ?? 'unknown_error';
|
|
136
|
+
const hint = (0, crew_1.crewErrorHint)(code, roleName, data?.message);
|
|
137
|
+
if (hint) {
|
|
138
|
+
process.stderr.write(chalk_1.default.red(`error: ${hint}\n`));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const errMsg = data?.message ?? 'MCP returned an error with no message';
|
|
142
|
+
process.stderr.write(chalk_1.default.red(`error: ${code}: ${errMsg}\n`));
|
|
143
|
+
}
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Find the role by name via roles `list` (each entry carries `identifier`/`name` and
|
|
148
|
+
* `in_crew`). `list` takes no paging parameters and returns every role, so no role can be
|
|
149
|
+
* missed. Exits 1 if the list call itself fails.
|
|
150
|
+
*/
|
|
151
|
+
async function resolveExistingRole(config, name) {
|
|
152
|
+
let list;
|
|
153
|
+
try {
|
|
154
|
+
list = await (0, mcp_1.callCrewsTool)(config, 'roles', { action: 'list' });
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
if (!list.ok) {
|
|
161
|
+
process.stderr.write(chalk_1.default.red(`error: could not list roles to find '${name}': ${list.data?.code ?? 'unknown_error'}: ${list.data?.message ?? 'MCP returned an error with no message'}\n`));
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
const roles = Array.isArray(list.data?.roles) ? list.data.roles : [];
|
|
165
|
+
const matches = roles.filter((r) => (r.identifier ?? r.name) === name);
|
|
166
|
+
if (matches.length === 0)
|
|
167
|
+
return { kind: 'missing' };
|
|
168
|
+
if (matches.length === 1)
|
|
169
|
+
return { kind: 'edit', inCrew: matches[0].in_crew ?? null, docId: asDocId(matches[0].doc_id) };
|
|
170
|
+
return { kind: 'ambiguous', crews: matches.map((m) => m.in_crew ?? null) };
|
|
171
|
+
}
|
|
172
|
+
/** Exit 1 for a role that cannot be pushed without --in-crew (would be a create, or is ambiguous). */
|
|
173
|
+
function failUnresolved(resolved, name) {
|
|
174
|
+
if (resolved.kind === 'missing') {
|
|
175
|
+
process.stderr.write(chalk_1.default.red(`error: role '${name}' does not exist yet; ${(0, crew_1.crewErrorHint)('crew_required')}\n`));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const crews = resolved.crews.map((c) => c ?? '(legacy flat role)').join(', ');
|
|
179
|
+
process.stderr.write(chalk_1.default.red(`error: ${(0, crew_1.crewErrorHint)('ambiguous_role', name)} (found in: ${crews})\n`));
|
|
180
|
+
}
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
29
183
|
/**
|
|
30
184
|
* Core implementation — accepts an injected config so tests can point at a
|
|
31
185
|
* stub server without touching the filesystem config.
|
|
@@ -62,12 +216,40 @@ async function rolePushWithConfig(dir, options, config) {
|
|
|
62
216
|
process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
|
|
63
217
|
process.exit(1);
|
|
64
218
|
}
|
|
65
|
-
|
|
66
|
-
|
|
219
|
+
const frontmatterParams = (0, skill_push_1.shapeFrontmatterParams)(properties, skill_push_1.ROLE_FRONTMATTER_PARAMS);
|
|
220
|
+
(0, skill_push_1.noteFoldedFrontmatterKeys)(properties, skill_push_1.ROLE_FRONTMATTER_PARAMS);
|
|
221
|
+
// in_crew comes only from --in-crew (never frontmatter); sent only when given.
|
|
222
|
+
const crewArgs = options.inCrew ? { in_crew: options.inCrew } : {};
|
|
223
|
+
// Without --in-crew, find the role first: the outcome (edit / error) is decided here, for
|
|
224
|
+
// the real push and --dry-run alike.
|
|
225
|
+
let resolved = null;
|
|
226
|
+
if (!options.inCrew) {
|
|
227
|
+
resolved = await resolveExistingRole(config, name);
|
|
228
|
+
if (resolved.kind !== 'edit')
|
|
229
|
+
failUnresolved(resolved, name);
|
|
230
|
+
}
|
|
231
|
+
// --dry-run: NO create or edit. Resolved above (no --in-crew) => would update.
|
|
232
|
+
// With --in-crew, pre-flight a read to detect existence. Roles use {action:'read', name} (NOT identifier).
|
|
233
|
+
const sidecar = readRoleSidecar(absDir);
|
|
234
|
+
const replaceLinks = options.replaceLinks === true;
|
|
235
|
+
/** The would-update line, after the same link check the real edit runs (may exit 1). */
|
|
236
|
+
const reportWouldUpdate = (target) => {
|
|
237
|
+
const { kept } = applyLinkBaseline(frontmatterParams, sidecar, name, target, replaceLinks);
|
|
238
|
+
if (options.json) {
|
|
239
|
+
console.log(JSON.stringify({}));
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
const note = kept.length > 0 ? ` (keeping ${kept.join(', ')} as-is on the server)` : '';
|
|
243
|
+
console.log(chalk_1.default.cyan(`[dry-run] would update '${name}'${note}`));
|
|
244
|
+
}
|
|
245
|
+
process.exit(0);
|
|
246
|
+
};
|
|
67
247
|
if (options.dryRun) {
|
|
248
|
+
if (resolved?.kind === 'edit')
|
|
249
|
+
reportWouldUpdate({ crew: resolved.inCrew, docId: resolved.docId });
|
|
68
250
|
let readResult;
|
|
69
251
|
try {
|
|
70
|
-
readResult = await (0, mcp_1.callCrewsTool)(config, 'roles', { action: 'read', name });
|
|
252
|
+
readResult = await (0, mcp_1.callCrewsTool)(config, 'roles', { action: 'read', name, ...crewArgs });
|
|
71
253
|
}
|
|
72
254
|
catch (e) {
|
|
73
255
|
process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
|
|
@@ -84,43 +266,49 @@ async function rolePushWithConfig(dir, options, config) {
|
|
|
84
266
|
}
|
|
85
267
|
process.exit(0);
|
|
86
268
|
}
|
|
269
|
+
// A versioned role with no published snapshot answers read with no_snapshot:
|
|
270
|
+
// the role exists (there is a doc), it just has nothing live yet -> would update.
|
|
271
|
+
if (code === 'no_snapshot')
|
|
272
|
+
reportWouldUpdate({ crew: options.inCrew ?? null });
|
|
87
273
|
// Any other error is unexpected — surface it
|
|
88
|
-
|
|
89
|
-
process.stderr.write(chalk_1.default.red(`error: ${code ?? 'unknown_error'}: ${errMsg}\n`));
|
|
90
|
-
process.exit(1);
|
|
274
|
+
failWithToolError(readResult.data, name);
|
|
91
275
|
}
|
|
92
276
|
// Read succeeded → role exists → would update
|
|
93
|
-
|
|
94
|
-
console.log(JSON.stringify({}));
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
console.log(chalk_1.default.cyan(`[dry-run] would update '${name}'`));
|
|
98
|
-
}
|
|
99
|
-
process.exit(0);
|
|
277
|
+
reportWouldUpdate({ crew: options.inCrew ?? null });
|
|
100
278
|
}
|
|
101
|
-
// Upsert:
|
|
279
|
+
// Upsert. Resolved to an existing role (no --in-crew): edit it in the crew the list gave.
|
|
280
|
+
// With --in-crew: try create first; on name_collision switch to edit.
|
|
102
281
|
// Roles carry NO references — do not send references key.
|
|
103
282
|
// Frontmatter extras are spread FIRST so the fixed protocol keys always win.
|
|
104
|
-
let result;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
283
|
+
let result = null;
|
|
284
|
+
if (resolved?.kind !== 'edit') {
|
|
285
|
+
try {
|
|
286
|
+
result = await (0, mcp_1.callCrewsTool)(config, 'roles', {
|
|
287
|
+
...frontmatterParams,
|
|
288
|
+
...crewArgs,
|
|
289
|
+
action: 'create',
|
|
290
|
+
name,
|
|
291
|
+
description,
|
|
292
|
+
body,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
catch (e) {
|
|
296
|
+
process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
117
299
|
}
|
|
118
|
-
//
|
|
300
|
+
// Edit path: the role was resolved as existing, or the create collided.
|
|
119
301
|
// Roles edit uses 'name' (NOT 'identifier').
|
|
120
|
-
if (!result.ok && result.data?.code === 'name_collision') {
|
|
302
|
+
if (result === null || (!result.ok && result.data?.code === 'name_collision')) {
|
|
303
|
+
const editCrewArgs = resolved?.kind === 'edit'
|
|
304
|
+
? (resolved.inCrew ? { in_crew: resolved.inCrew } : {})
|
|
305
|
+
: crewArgs;
|
|
306
|
+
const { params: editParams } = applyLinkBaseline(frontmatterParams, sidecar, name, resolved?.kind === 'edit' ? { crew: resolved.inCrew, docId: resolved.docId } : { crew: options.inCrew ?? null }, replaceLinks);
|
|
307
|
+
let edited;
|
|
121
308
|
try {
|
|
122
|
-
|
|
123
|
-
...
|
|
309
|
+
edited = await (0, mcp_1.callCrewsTool)(config, 'roles', {
|
|
310
|
+
...editParams,
|
|
311
|
+
...editCrewArgs,
|
|
124
312
|
action: 'edit',
|
|
125
313
|
name,
|
|
126
314
|
description,
|
|
@@ -131,14 +319,11 @@ async function rolePushWithConfig(dir, options, config) {
|
|
|
131
319
|
process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
|
|
132
320
|
process.exit(1);
|
|
133
321
|
}
|
|
134
|
-
if (!
|
|
135
|
-
|
|
136
|
-
const errMsg = result.data?.message ?? 'MCP returned an error with no message';
|
|
137
|
-
process.stderr.write(chalk_1.default.red(`error: ${errCode}: ${errMsg}\n`));
|
|
138
|
-
process.exit(1);
|
|
322
|
+
if (!edited.ok) {
|
|
323
|
+
failWithToolError(edited.data, name);
|
|
139
324
|
}
|
|
140
325
|
if (options.json) {
|
|
141
|
-
console.log(JSON.stringify(
|
|
326
|
+
console.log(JSON.stringify(edited.data ?? {}));
|
|
142
327
|
}
|
|
143
328
|
else {
|
|
144
329
|
console.log(chalk_1.default.green(`updated role '${name}'`));
|
|
@@ -146,10 +331,7 @@ async function rolePushWithConfig(dir, options, config) {
|
|
|
146
331
|
process.exit(0);
|
|
147
332
|
}
|
|
148
333
|
if (!result.ok) {
|
|
149
|
-
|
|
150
|
-
const errMsg = result.data?.message ?? 'MCP returned an error with no message';
|
|
151
|
-
process.stderr.write(chalk_1.default.red(`error: ${errCode}: ${errMsg}\n`));
|
|
152
|
-
process.exit(1);
|
|
334
|
+
failWithToolError(result.data, name);
|
|
153
335
|
}
|
|
154
336
|
if (options.json) {
|
|
155
337
|
console.log(JSON.stringify(result.data ?? {}));
|
|
@@ -2,18 +2,26 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* solidactions skill publish <name>
|
|
4
4
|
*
|
|
5
|
-
* Publishes (snapshots) a
|
|
6
|
-
*
|
|
5
|
+
* Publishes (snapshots) a skill so its latest pushed revision goes live for
|
|
6
|
+
* agents. Shared-library by default; --role [--in-crew] targets a role-scoped skill.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.skillPublishWithConfig = skillPublishWithConfig;
|
|
10
13
|
exports.skillPublish = skillPublish;
|
|
14
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
15
|
const api_1 = require("../utils/api");
|
|
12
16
|
const skill_snapshot_1 = require("../utils/skill-snapshot");
|
|
13
17
|
/** Core implementation — accepts an injected config for tests. */
|
|
14
18
|
async function skillPublishWithConfig(name, options, config) {
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
if (options.inCrew && !options.role) {
|
|
20
|
+
process.stderr.write(chalk_1.default.red('error: --in-crew requires --role.\n'));
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
const outcome = await (0, skill_snapshot_1.publishSkillByName)(config, name, { role: options.role, inCrew: options.inCrew });
|
|
24
|
+
(0, skill_snapshot_1.emitPublishOutcome)(name, outcome, { json: options.json, role: options.role });
|
|
17
25
|
}
|
|
18
26
|
/** Entry point called from index.ts. */
|
|
19
27
|
async function skillPublish(name, options) {
|