@solidactions/cli 1.28.0 → 1.30.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.
@@ -16,9 +16,12 @@ exports.docsPushWithConfig = docsPushWithConfig;
16
16
  exports.docsPush = docsPush;
17
17
  const fs_1 = __importDefault(require("fs"));
18
18
  const path_1 = __importDefault(require("path"));
19
+ const axios_1 = __importDefault(require("axios"));
20
+ const form_data_1 = __importDefault(require("form-data"));
19
21
  const chalk_1 = __importDefault(require("chalk"));
20
22
  const api_1 = require("../utils/api");
21
23
  const mcp_1 = require("../utils/mcp");
24
+ const docs_manifest_1 = require("../utils/docs-manifest");
22
25
  const CHUNK_SIZE = 50;
23
26
  /**
24
27
  * Recursively walk `dir` and collect all *.md files.
@@ -40,6 +43,35 @@ function walkMarkdownFiles(dir) {
40
43
  walk(dir);
41
44
  return results;
42
45
  }
46
+ const SKIP_DIRS = new Set(['node_modules']);
47
+ /**
48
+ * Recursively walk `dir` and collect relative paths of non-.md files that
49
+ * are not present in the manifest — never uploaded by `docs push`; `docs
50
+ * upload` is the way to create media docs from these. Dotfiles and
51
+ * dot-directories are excluded (`entry.name.startsWith('.')` also covers the
52
+ * `.solidactions-docs.json` sidecar itself).
53
+ */
54
+ function walkUntrackedBinaries(dir, manifest) {
55
+ const results = [];
56
+ const walk = (current) => {
57
+ for (const entry of fs_1.default.readdirSync(current, { withFileTypes: true })) {
58
+ if (entry.name.startsWith('.') || SKIP_DIRS.has(entry.name))
59
+ continue;
60
+ const abs = path_1.default.join(current, entry.name);
61
+ if (entry.isDirectory()) {
62
+ walk(abs);
63
+ }
64
+ else if (entry.isFile() && !entry.name.endsWith('.md')) {
65
+ const relPath = path_1.default.relative(dir, abs).split(path_1.default.sep).join('/');
66
+ if (!manifest?.docs[relPath]) {
67
+ results.push(relPath);
68
+ }
69
+ }
70
+ }
71
+ };
72
+ walk(dir);
73
+ return results;
74
+ }
43
75
  /**
44
76
  * Convert an absolute file path to a bulk_create item, relative to `rootDir`.
45
77
  */
@@ -114,16 +146,171 @@ async function docsPushWithConfig(dir, options, config) {
114
146
  process.exit(1);
115
147
  }
116
148
  const allFiles = walkMarkdownFiles(absDir);
117
- if (allFiles.length === 0) {
118
- process.stderr.write(chalk_1.default.red(`error: no .md files found under "${dir}" — nothing to push.\n`));
149
+ // A missing/unparseable manifest means nothing is tracked — everything is untracked,
150
+ // matching the existing (pre-drift-guard) bulk_create behavior byte-for-byte.
151
+ const manifest = (0, docs_manifest_1.readManifest)(absDir, { warnOnParseError: true });
152
+ const trackedMediaEntries = Object.entries(manifest?.docs ?? {}).filter(([, e]) => e.media);
153
+ // A pulled folder of images alone (no .md files) must still be pushable — the early
154
+ // exit only fires when there's truly nothing to push.
155
+ if (allFiles.length === 0 && trackedMediaEntries.length === 0) {
156
+ process.stderr.write(chalk_1.default.red(`error: no .md files or tracked media found under "${dir}" — nothing to push.\n`));
119
157
  process.exit(1);
120
158
  }
121
- const items = allFiles.map((f) => fileToItem(f, absDir));
159
+ // Partition into tracked (relative path present in the pull manifest) vs. untracked.
160
+ // A media doc titled *.md (e.g. `notes.md`) is bytes, not markdown — it's owned by
161
+ // the media pass below, not this markdown pass, or its bytes would be sent through
162
+ // docs_edit as a text body and corrupt the doc.
163
+ const trackedFiles = [];
164
+ const untrackedFiles = [];
165
+ for (const f of allFiles) {
166
+ const relPath = path_1.default.relative(absDir, f).split(path_1.default.sep).join('/');
167
+ const entry = manifest?.docs[relPath];
168
+ if (entry?.media) {
169
+ continue;
170
+ }
171
+ if (entry) {
172
+ trackedFiles.push({ absPath: f, relPath });
173
+ }
174
+ else {
175
+ untrackedFiles.push(f);
176
+ }
177
+ }
178
+ const trackedWritten = [];
179
+ const trackedDrifted = [];
180
+ const trackedPlanned = [];
181
+ const trackedUnchanged = [];
182
+ const trackedMissing = [];
183
+ for (const { absPath, relPath } of trackedFiles) {
184
+ const entry = manifest.docs[relPath];
185
+ const body = fs_1.default.readFileSync(absPath, 'utf8');
186
+ const bodyHash = (0, docs_manifest_1.sha256Hex)(body);
187
+ // Skip-unchanged applies regardless of --force or --dry-run: force answers
188
+ // drift, not staleness, and an old manifest lacking body_sha256 (undefined)
189
+ // never matches, so it always falls through to a write (graceful degradation).
190
+ if (entry.body_sha256 != null && entry.body_sha256 === bodyHash) {
191
+ trackedUnchanged.push({ file: relPath, id: entry.id });
192
+ continue;
193
+ }
194
+ // --dry-run must never live-write: preview the tracked doc instead of calling docs_edit.
195
+ if (options.dryRun) {
196
+ trackedPlanned.push({ file: relPath, id: entry.id });
197
+ continue;
198
+ }
199
+ const editArgs = { action: 'write', id: entry.id, body };
200
+ if (!options.force && entry.current_revision_id !== null) {
201
+ editArgs.base_revision = entry.current_revision_id;
202
+ }
203
+ let mcpResult;
204
+ try {
205
+ mcpResult = await (0, mcp_1.callDocsTool)(config, 'docs_edit', editArgs);
206
+ }
207
+ catch (e) {
208
+ process.stderr.write(chalk_1.default.red(`error: ${e.message}\n`));
209
+ process.exit(1);
210
+ }
211
+ if (!mcpResult.ok) {
212
+ const code = mcpResult.data?.code ?? 'unknown_error';
213
+ if (code === 'doc_not_found') {
214
+ // The tracked doc was deleted remotely since the last pull. Not a genuine
215
+ // drift/error: report it and move on rather than aborting the whole push.
216
+ trackedMissing.push({ file: relPath, id: entry.id });
217
+ continue;
218
+ }
219
+ const message = mcpResult.data?.message ?? 'MCP returned an error with no message';
220
+ process.stderr.write(chalk_1.default.red(`error: ${code}: ${message}\n`));
221
+ process.exit(1);
222
+ }
223
+ const data = mcpResult.data;
224
+ if (data?.stale === true || data?.code === 'stale_revision') {
225
+ trackedDrifted.push({ file: relPath, their: data.current_revision_id ?? null, base: entry.current_revision_id });
226
+ continue;
227
+ }
228
+ entry.current_revision_id = data?.current_revision_id ?? entry.current_revision_id;
229
+ entry.body_sha256 = bodyHash;
230
+ trackedWritten.push({ file: relPath, id: entry.id, current_revision_id: entry.current_revision_id });
231
+ // Persist immediately so a later failure (another tracked write, or an
232
+ // untracked bulk_create error) never loses this file's refreshed revision.
233
+ (0, docs_manifest_1.writeManifest)(absDir, manifest);
234
+ }
235
+ // Media pass: tracked binaries (media: true) replace via POST /api/v1/docs/{id}/media,
236
+ // sharing the report arrays above.
237
+ for (const [relPath, entry] of trackedMediaEntries) {
238
+ const absPath = path_1.default.join(absDir, ...relPath.split('/'));
239
+ // Existence before hash: a pull whose media download failed records
240
+ // `media: true, body_sha256: null` and writes no file. push never deletes.
241
+ if (!fs_1.default.existsSync(absPath)) {
242
+ continue;
243
+ }
244
+ // A directory sitting where a media file is tracked (e.g. `hero.png/`) would
245
+ // otherwise make readFileSync throw EISDIR uncaught mid-push. push never deletes,
246
+ // so skip it rather than crash.
247
+ if (!fs_1.default.statSync(absPath).isFile()) {
248
+ continue;
249
+ }
250
+ const bytes = fs_1.default.readFileSync(absPath);
251
+ const bodyHash = (0, docs_manifest_1.sha256Hex)(bytes);
252
+ if (entry.body_sha256 != null && entry.body_sha256 === bodyHash) {
253
+ trackedUnchanged.push({ file: relPath, id: entry.id });
254
+ continue;
255
+ }
256
+ if (options.dryRun) {
257
+ trackedPlanned.push({ file: relPath, id: entry.id });
258
+ continue;
259
+ }
260
+ const form = new form_data_1.default();
261
+ form.append('file', bytes, { filename: path_1.default.basename(relPath) });
262
+ if (!options.force && entry.current_revision_id !== null) {
263
+ form.append('base_revision', String(entry.current_revision_id));
264
+ }
265
+ let doc;
266
+ try {
267
+ const response = await axios_1.default.post(`${config.host}/api/v1/docs/${entry.id}/media`, form, {
268
+ headers: { ...form.getHeaders(), ...(0, api_1.getApiHeaders)(config) },
269
+ maxContentLength: Infinity,
270
+ maxBodyLength: Infinity,
271
+ });
272
+ doc = response.data?.doc;
273
+ }
274
+ catch (error) {
275
+ const status = error.response?.status;
276
+ const data = error.response?.data;
277
+ if (status === 409 && data?.code === 'stale_revision') {
278
+ trackedDrifted.push({ file: relPath, their: data.current_revision_id ?? null, base: entry.current_revision_id });
279
+ continue;
280
+ }
281
+ if (status === 404 && data?.code === 'doc_not_found') {
282
+ // The tracked doc was deleted remotely since the last pull — same
283
+ // treatment as the markdown pass. `media_not_found` is a different case
284
+ // (doc exists but isn't a media doc) and is not handled here.
285
+ trackedMissing.push({ file: relPath, id: entry.id });
286
+ continue;
287
+ }
288
+ process.stderr.write(chalk_1.default.red(`error: ${relPath}: ${data?.message ?? error.message}\n`));
289
+ process.exit(1);
290
+ }
291
+ // The REST presenter names the revision `current_version_id`; MCP docs_edit
292
+ // names it `current_revision_id`. Reading the wrong one nulls the entry and
293
+ // silently disarms the drift guard on every later push.
294
+ entry.current_revision_id = doc?.current_version_id ?? entry.current_revision_id;
295
+ entry.body_sha256 = bodyHash;
296
+ trackedWritten.push({ file: relPath, id: entry.id, current_revision_id: entry.current_revision_id });
297
+ (0, docs_manifest_1.writeManifest)(absDir, manifest);
298
+ }
299
+ const untrackedMedia = walkUntrackedBinaries(absDir, manifest);
300
+ const items = untrackedFiles.map((f) => fileToItem(f, absDir));
301
+ // Untracked docs (new files, or files re-orphaned by a deleted-remotely re-pull)
302
+ // must land back under the folder this directory was pulled into, not the docs
303
+ // root — an explicit --folder always overrides the manifest's recorded folder.
304
+ const effectiveFolder = options.folder ?? manifest?.folder_path;
305
+ const folderInferredFromManifest = !options.folder && !!manifest?.folder_path;
122
306
  // Chunk into groups of CHUNK_SIZE
123
307
  const chunks = [];
124
308
  for (let i = 0; i < items.length; i += CHUNK_SIZE) {
125
309
  chunks.push(items.slice(i, i + CHUNK_SIZE));
126
310
  }
311
+ if (folderInferredFromManifest && items.length > 0 && !options.json) {
312
+ console.log(chalk_1.default.gray(`creating untracked docs under "${effectiveFolder}" (from ${docs_manifest_1.DOCS_MANIFEST})`));
313
+ }
127
314
  const onConflict = options.onConflict ?? 'skip';
128
315
  const allResultRows = [];
129
316
  let mergedSummary = {};
@@ -142,9 +329,11 @@ async function docsPushWithConfig(dir, options, config) {
142
329
  if (options.type) {
143
330
  callArgs.type = options.type;
144
331
  }
145
- if (options.folder) {
332
+ if (effectiveFolder) {
146
333
  // Top-level base for every item; each item's relative_folder_path nests under it.
147
- callArgs.folder_path = options.folder;
334
+ // Explicit --folder wins; otherwise defaults to the manifest's folder_path so
335
+ // untracked docs in a pulled directory land back in the folder they came from.
336
+ callArgs.folder_path = effectiveFolder;
148
337
  }
149
338
  if (options.dryRun) {
150
339
  callArgs.dry_run = true;
@@ -184,23 +373,66 @@ async function docsPushWithConfig(dir, options, config) {
184
373
  missing: r.property_validation.missing ?? [],
185
374
  invalid: r.property_validation.invalid ?? [],
186
375
  }));
376
+ // `done: N errors` on its own says nothing. Name the file and the server's reason.
377
+ const erroredRows = allResultRows.filter((r) => r.status === 'error');
378
+ const exitCode = trackedDrifted.length > 0 || erroredRows.length > 0 ? 1 : 0;
187
379
  // --json: output single JSON object
188
380
  if (options.json) {
189
381
  console.log(JSON.stringify({
190
382
  summary: mergedSummary,
191
383
  pending: pendingItems,
192
384
  results: allResultRows,
385
+ tracked: { written: trackedWritten, drifted: trackedDrifted, planned: trackedPlanned, unchanged: trackedUnchanged, missing: trackedMissing },
386
+ untracked_media: untrackedMedia,
193
387
  }));
194
- process.exit(0);
388
+ process.exit(exitCode);
195
389
  }
196
390
  // Human-readable output
391
+ if (options.dryRun) {
392
+ if (trackedPlanned.length > 0) {
393
+ console.log(chalk_1.default.cyan(`tracked: ${trackedPlanned.length} planned write`));
394
+ for (const p of trackedPlanned) {
395
+ console.log(chalk_1.default.gray(` ${p.file}`));
396
+ }
397
+ }
398
+ if (trackedUnchanged.length > 0) {
399
+ console.log(chalk_1.default.gray(`tracked: ${trackedUnchanged.length} planned unchanged (skip)`));
400
+ for (const u of trackedUnchanged) {
401
+ console.log(chalk_1.default.gray(` ${u.file}`));
402
+ }
403
+ }
404
+ }
405
+ else if (trackedWritten.length > 0 || trackedDrifted.length > 0 || trackedUnchanged.length > 0) {
406
+ console.log(chalk_1.default.green(`tracked: ${trackedWritten.length} written, ${trackedDrifted.length} drifted, ${trackedUnchanged.length} unchanged`));
407
+ for (const w of trackedWritten) {
408
+ console.log(chalk_1.default.gray(` ${w.file}`));
409
+ }
410
+ }
411
+ if (untrackedMedia.length > 0) {
412
+ for (const file of untrackedMedia.slice(0, 10)) {
413
+ process.stderr.write(chalk_1.default.yellow(`${file}: not pushed — use \`solidactions docs upload\`\n`));
414
+ }
415
+ if (untrackedMedia.length > 10) {
416
+ process.stderr.write(chalk_1.default.yellow(`… and ${untrackedMedia.length - 10} more\n`));
417
+ }
418
+ }
419
+ for (const m of trackedMissing) {
420
+ process.stderr.write(chalk_1.default.yellow(`${m.file}: doc ${m.id} no longer exists (deleted remotely) — re-pull to untrack it, then push to re-create (restore or empty it from the trash first, or the title stays taken)\n`));
421
+ }
197
422
  const summaryLine = formatSummaryLine(mergedSummary, !!options.dryRun);
198
423
  if (options.dryRun) {
199
424
  console.log(chalk_1.default.cyan(`[dry-run preview] ${summaryLine}`));
200
425
  }
201
- else {
426
+ else if (items.length > 0) {
427
+ // Suppress "done: 0 docs" when there was nothing to bulk_create — printing it
428
+ // alongside a successful tracked/media write reads as a contradiction.
202
429
  console.log(chalk_1.default.green(`done: ${summaryLine}`));
203
430
  }
431
+ if (erroredRows.length > 0 && !options.json) {
432
+ for (const row of erroredRows) {
433
+ process.stderr.write(chalk_1.default.red(`${row.file}: ${row.error ?? row.code ?? 'unknown error'}\n`));
434
+ }
435
+ }
204
436
  if (pendingItems.length > 0) {
205
437
  console.log(chalk_1.default.yellow(`\nProperties pending (${pendingItems.length} doc${pendingItems.length === 1 ? '' : 's'}):`));
206
438
  for (const item of pendingItems) {
@@ -213,7 +445,14 @@ async function docsPushWithConfig(dir, options, config) {
213
445
  }
214
446
  }
215
447
  }
216
- process.exit(0);
448
+ if (trackedDrifted.length > 0) {
449
+ process.stderr.write(chalk_1.default.red(`\ndrift: ${trackedDrifted.length} tracked doc${trackedDrifted.length === 1 ? '' : 's'} changed on the server since the last pull:\n`));
450
+ for (const d of trackedDrifted) {
451
+ process.stderr.write(chalk_1.default.red(` ${d.file} (local base_revision ${d.base}, server now at ${d.their})\n`));
452
+ }
453
+ process.stderr.write(chalk_1.default.red('re-pull to merge, or pass --force to overwrite\n'));
454
+ }
455
+ process.exit(exitCode);
217
456
  }
218
457
  /**
219
458
  * Entry point called from index.ts.
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.docsUpload = docsUpload;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const axios_1 = __importDefault(require("axios"));
43
+ const form_data_1 = __importDefault(require("form-data"));
44
+ const chalk_1 = __importDefault(require("chalk"));
45
+ const api_1 = require("../utils/api");
46
+ /**
47
+ * Resolve `--replace` to a doc id. A purely numeric value is an id; anything else
48
+ * is a docs path, resolved against the doc's *title* via GET /docs/by-path.
49
+ *
50
+ * Note the title is not always the local filename: `docs pull` sanitizes
51
+ * filesystem-illegal characters and may suffix collisions. For path-based work
52
+ * on a pulled folder, `docs push` is the right verb.
53
+ */
54
+ async function resolveReplaceTarget(config, replace) {
55
+ if (/^\d+$/.test(replace)) {
56
+ return Number(replace);
57
+ }
58
+ const slash = replace.lastIndexOf('/');
59
+ const folderPath = slash === -1 ? undefined : replace.slice(0, slash);
60
+ const title = slash === -1 ? replace : replace.slice(slash + 1);
61
+ // A trailing slash ("marketing/") leaves no title to look up. Fail here rather
62
+ // than asking the server to resolve an empty title and reporting its 404.
63
+ if (title === '') {
64
+ console.error(chalk_1.default.red(`✗ --replace "${replace}" names a folder, not a doc`));
65
+ return process.exit(1);
66
+ }
67
+ try {
68
+ const params = {};
69
+ if (folderPath)
70
+ params.folder_path = folderPath;
71
+ params.title = title;
72
+ const response = await axios_1.default.get(`${config.host}/api/v1/docs/by-path`, {
73
+ params,
74
+ headers: (0, api_1.getApiHeaders)(config),
75
+ });
76
+ return response.data.doc.id;
77
+ }
78
+ catch (error) {
79
+ const status = error.response?.status;
80
+ const code = error.response?.data?.code;
81
+ if (status === 422 && code === 'folder_path_not_found') {
82
+ console.error(chalk_1.default.red(`✗ no folder "${folderPath}" in this workspace`));
83
+ }
84
+ else if (status === 404) {
85
+ console.error(chalk_1.default.red(`✗ no doc titled "${title}"${folderPath ? ` in "${folderPath}"` : ' at the docs root'}`));
86
+ }
87
+ else {
88
+ console.error(chalk_1.default.red(`✗ could not resolve "${replace}" — ${error.response?.data?.message ?? error.message}`));
89
+ }
90
+ return process.exit(1);
91
+ }
92
+ }
93
+ /**
94
+ * Uploads one or more local files to SA-Docs media (`POST /api/v1/docs/media`),
95
+ * sequentially. `--title` is only valid for a single file — with multiple
96
+ * files, every upload would otherwise silently collide on the same title.
97
+ */
98
+ async function docsUpload(files, options = {}) {
99
+ if (options.title && files.length > 1) {
100
+ console.error(chalk_1.default.red('--title can only be used when uploading a single file.'));
101
+ process.exit(1);
102
+ }
103
+ if (options.replace && files.length > 1) {
104
+ console.error(chalk_1.default.red('--replace can only be used when uploading a single file.'));
105
+ process.exit(1);
106
+ }
107
+ if (options.replace && (options.title || options.folder)) {
108
+ console.error(chalk_1.default.red('--replace cannot be combined with --title or --folder — replace never renames or moves a doc.'));
109
+ process.exit(1);
110
+ }
111
+ const config = await (0, api_1.requireConfigWithWorkspace)();
112
+ let hadError = false;
113
+ for (const file of files) {
114
+ const absPath = path.resolve(file);
115
+ const displayName = path.basename(absPath);
116
+ if (!fs.existsSync(absPath) || !fs.statSync(absPath).isFile()) {
117
+ console.error(chalk_1.default.red(`✗ ${displayName} — file not found`));
118
+ hadError = true;
119
+ continue;
120
+ }
121
+ const form = new form_data_1.default();
122
+ form.append('file', fs.createReadStream(absPath));
123
+ if (!options.replace) {
124
+ if (options.folder)
125
+ form.append('folder_path', options.folder);
126
+ if (options.title)
127
+ form.append('title', options.title);
128
+ }
129
+ // Resolved once (--replace forbids multiple files), and kept so error messages
130
+ // can name the numeric doc id rather than echoing back a path.
131
+ const replaceDocId = options.replace ? await resolveReplaceTarget(config, options.replace) : null;
132
+ const url = replaceDocId !== null
133
+ ? `${config.host}/api/v1/docs/${replaceDocId}/media`
134
+ : `${config.host}/api/v1/docs/media`;
135
+ try {
136
+ const response = await axios_1.default.post(url, form, {
137
+ headers: {
138
+ ...form.getHeaders(),
139
+ ...(0, api_1.getApiHeaders)(config),
140
+ },
141
+ maxContentLength: Infinity,
142
+ maxBodyLength: Infinity,
143
+ });
144
+ // The 201/200 body nests the created/updated doc under a `doc` key.
145
+ const doc = response.data?.doc;
146
+ if (options.replace) {
147
+ console.log(chalk_1.default.green(`✓ ${displayName} → doc ${doc?.id} (replaced, rev ${doc?.current_version_id})`));
148
+ }
149
+ else {
150
+ const location = doc?.folder_path || '/';
151
+ console.log(chalk_1.default.green(`✓ ${displayName} → ${location} (doc ${doc?.id})`));
152
+ }
153
+ }
154
+ catch (error) {
155
+ hadError = true;
156
+ if (error.response) {
157
+ const { status, data } = error.response;
158
+ if (status === 413) {
159
+ console.error(chalk_1.default.red(`✗ ${displayName} — ${data?.message || 'File exceeds the maximum upload size (20MB).'}`));
160
+ }
161
+ else if (status === 401) {
162
+ console.error(chalk_1.default.red(`✗ ${displayName} — Authentication failed. Run "solidactions login <api-key>" to re-configure.`));
163
+ }
164
+ else if (status === 404 && data?.code === 'media_not_found') {
165
+ console.error(chalk_1.default.red(`✗ ${displayName} — doc ${replaceDocId} is not a media doc`));
166
+ }
167
+ else if (status === 422) {
168
+ console.error(chalk_1.default.red(`✗ ${displayName} — ${(0, api_1.formatValidationError)(data)}`));
169
+ }
170
+ else {
171
+ console.error(chalk_1.default.red(`✗ ${displayName} — ${data?.message || `request failed with status ${status}`}`));
172
+ }
173
+ }
174
+ else {
175
+ console.error(chalk_1.default.red(`✗ ${displayName} — ${error.message}`));
176
+ }
177
+ }
178
+ }
179
+ if (hadError) {
180
+ process.exit(1);
181
+ }
182
+ }
@@ -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
+ }
@@ -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);