@solidactions/cli 3.20.1 → 3.22.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.
Files changed (53) hide show
  1. package/README.md +12 -6
  2. package/dist/command-manifest.json +18 -7
  3. package/dist/commands/connection-list.js +2 -2
  4. package/dist/commands/crew-env-delete.js +2 -2
  5. package/dist/commands/crew-env-list.js +2 -2
  6. package/dist/commands/crew-env-push.js +5 -2
  7. package/dist/commands/crew-env-set.js +2 -2
  8. package/dist/commands/database-push.js +1 -1
  9. package/dist/commands/deploy.js +41 -12
  10. package/dist/commands/dev.js +4 -4
  11. package/dist/commands/doc-pull.js +531 -73
  12. package/dist/commands/doc-push.js +291 -28
  13. package/dist/commands/doc-upload.js +5 -2
  14. package/dist/commands/env-delete.js +12 -5
  15. package/dist/commands/env-list.js +19 -14
  16. package/dist/commands/env-map.js +7 -5
  17. package/dist/commands/env-pull.js +5 -6
  18. package/dist/commands/env-push.js +10 -6
  19. package/dist/commands/env-reset.js +12 -8
  20. package/dist/commands/env-set.js +15 -11
  21. package/dist/commands/init.js +4 -1
  22. package/dist/commands/login.js +15 -18
  23. package/dist/commands/oauth-action-list.js +2 -2
  24. package/dist/commands/oauth-action-platforms.js +2 -2
  25. package/dist/commands/oauth-action-search.js +2 -2
  26. package/dist/commands/oauth-action-view.js +2 -2
  27. package/dist/commands/project-create.js +1 -1
  28. package/dist/commands/project-list.js +2 -2
  29. package/dist/commands/project-logs.js +7 -3
  30. package/dist/commands/project-view.js +26 -9
  31. package/dist/commands/pull.js +4 -2
  32. package/dist/commands/run-list.js +27 -22
  33. package/dist/commands/run-start.js +22 -18
  34. package/dist/commands/run-view.js +10 -22
  35. package/dist/commands/schedule-delete.js +5 -10
  36. package/dist/commands/schedule-list.js +5 -10
  37. package/dist/commands/schedule-set.js +39 -44
  38. package/dist/commands/schedule-state.js +12 -16
  39. package/dist/commands/state.js +3 -3
  40. package/dist/commands/webhook-list.js +12 -4
  41. package/dist/commands/webhook-secret.js +12 -4
  42. package/dist/commands/workflow-view.js +3 -3
  43. package/dist/commands/workspaces.js +58 -3
  44. package/dist/index.js +13 -7
  45. package/dist/utils/api.js +69 -4
  46. package/dist/utils/config.js +96 -3
  47. package/dist/utils/crew.js +6 -1
  48. package/dist/utils/mcp.js +7 -3
  49. package/dist/utils/project-ref.js +91 -0
  50. package/dist/utils/run-status.js +61 -0
  51. package/dist/utils/secure-write.js +40 -5
  52. package/dist/utils/workspace-lookup.js +30 -3
  53. package/package.json +2 -2
@@ -1,17 +1,25 @@
1
1
  "use strict";
2
2
  /**
3
- * solidactions doc push <dir>
3
+ * solidactions doc push <path>
4
4
  *
5
- * Recursively uploads a local markdown tree into SA-Docs via the docs MCP
6
- * server's `docs_manage` tool's `bulk_create` action, mirroring folder structure.
5
+ * Recursively uploads a local docs tree (.md, .html, .canvas.json, .canvas) into
6
+ * SA-Docs via the docs MCP server's `docs_manage` tool's `bulk_create` action,
7
+ * mirroring folder structure — or pushes one such file alone.
7
8
  *
8
9
  * Prints a report distinguishing fully-published docs from "properties pending"
9
10
  * ones (docs whose frontmatter properties couldn't be validated yet).
11
+ *
12
+ * Docs the push creates from untracked files are recorded in the directory's
13
+ * manifest (cli#157), so pushing again updates them by id instead of skipping
14
+ * them — but only when they landed in the manifest's own folder tree.
10
15
  */
11
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
18
  };
14
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.MAX_CHUNK_BYTES = exports.MAX_DOC_BODY_BYTES = void 0;
21
+ exports.docFileKind = docFileKind;
22
+ exports.quoteShellPath = quoteShellPath;
15
23
  exports.docPushWithConfig = docPushWithConfig;
16
24
  exports.docPush = docPush;
17
25
  const fs_1 = __importDefault(require("fs"));
@@ -23,6 +31,31 @@ const api_1 = require("../utils/api");
23
31
  const mcp_1 = require("../utils/mcp");
24
32
  const docs_manifest_1 = require("../utils/docs-manifest");
25
33
  const CHUNK_SIZE = 50;
34
+ /**
35
+ * The file kinds `doc push` creates docs from (cli#154). Order matters: `.canvas.json`
36
+ * must be tested before any shorter suffix. `type` is the built-in doc type the server
37
+ * creates the doc as; markdown sends none. `.canvas` is the JSON Canvas extension other
38
+ * tools write (PM ruling 8).
39
+ */
40
+ const DOC_FILE_KINDS = [
41
+ { suffix: '.canvas.json', type: 'canvas' },
42
+ { suffix: '.canvas', type: 'canvas' },
43
+ { suffix: '.html', type: 'visual' },
44
+ { suffix: '.md' },
45
+ ];
46
+ function docFileKind(fileName) {
47
+ return DOC_FILE_KINDS.find((kind) => fileName.endsWith(kind.suffix) && fileName.length > kind.suffix.length) ?? null;
48
+ }
49
+ /** Shell-quote a suggested path only when it needs it (cli#154 I4). */
50
+ function quoteShellPath(suggested) {
51
+ if (/^[A-Za-z0-9_./-]+$/.test(suggested))
52
+ return suggested;
53
+ return `'${suggested.replace(/'/g, `'\\''`)}'`;
54
+ }
55
+ /** The server's body cap (docs.blob_size_cap_bytes): refuse locally rather than send a doomed request (PM ruling 3). */
56
+ exports.MAX_DOC_BODY_BYTES = 1_048_576;
57
+ /** A bulk_create request carries at most CHUNK_SIZE items and about this many body bytes (PM ruling 3). */
58
+ exports.MAX_CHUNK_BYTES = 4_194_304;
26
59
  const SKIP_DIRS = new Set(['node_modules']);
27
60
  /**
28
61
  * Directory/dot entries neither walker descends into or picks up: dotfiles and
@@ -34,10 +67,11 @@ function isSkippedEntry(name) {
34
67
  return name.startsWith('.') || SKIP_DIRS.has(name);
35
68
  }
36
69
  /**
37
- * Recursively walk `dir` and collect all *.md files.
70
+ * Recursively walk `dir` and collect all pushable doc files (.md, .html,
71
+ * .canvas.json, .canvas).
38
72
  * Returns a list of absolute paths.
39
73
  */
40
- function walkMarkdownFiles(dir) {
74
+ function walkDocFiles(dir) {
41
75
  const results = [];
42
76
  const walk = (current) => {
43
77
  for (const entry of fs_1.default.readdirSync(current, { withFileTypes: true })) {
@@ -47,7 +81,7 @@ function walkMarkdownFiles(dir) {
47
81
  if (entry.isDirectory()) {
48
82
  walk(abs);
49
83
  }
50
- else if (entry.isFile() && entry.name.endsWith('.md')) {
84
+ else if (entry.isFile() && docFileKind(entry.name) !== null) {
51
85
  results.push(abs);
52
86
  }
53
87
  }
@@ -56,9 +90,9 @@ function walkMarkdownFiles(dir) {
56
90
  return results;
57
91
  }
58
92
  /**
59
- * Recursively walk `dir` and collect relative paths of non-.md files that
60
- * are not present in the manifest — never uploaded by `doc push`; `doc
61
- * upload` is the way to create media docs from these. Dotfiles and
93
+ * Recursively walk `dir` and collect relative paths of files of no pushable
94
+ * kind that are not present in the manifest — never uploaded by `doc push`;
95
+ * `doc upload` is the way to create media docs from these. Dotfiles and
62
96
  * dot-directories are excluded (`entry.name.startsWith('.')` also covers the
63
97
  * `.solidactions-docs.json` sidecar itself).
64
98
  */
@@ -72,7 +106,7 @@ function walkUntrackedBinaries(dir, manifest) {
72
106
  if (entry.isDirectory()) {
73
107
  walk(abs);
74
108
  }
75
- else if (entry.isFile() && !entry.name.endsWith('.md')) {
109
+ else if (entry.isFile() && docFileKind(entry.name) === null) {
76
110
  const relPath = path_1.default.relative(dir, abs).split(path_1.default.sep).join('/');
77
111
  if (!manifest?.docs[relPath]) {
78
112
  results.push(relPath);
@@ -87,17 +121,159 @@ function walkUntrackedBinaries(dir, manifest) {
87
121
  * Convert an absolute file path to a bulk_create item, relative to `rootDir`.
88
122
  */
89
123
  function fileToItem(absPath, rootDir) {
90
- const title = path_1.default.basename(absPath, '.md');
124
+ const kind = docFileKind(path_1.default.basename(absPath));
125
+ const title = path_1.default.basename(absPath).slice(0, -kind.suffix.length);
91
126
  const body = fs_1.default.readFileSync(absPath, 'utf8');
92
127
  const relDir = path_1.default.relative(rootDir, path_1.default.dirname(absPath));
93
128
  // Use POSIX separators; omit if file is in the root dir
94
129
  const relative_folder_path = relDir === '' ? undefined : relDir.split(path_1.default.sep).join('/');
95
- const item = { title, body, _filePath: absPath };
130
+ const item = { title, body, _filePath: absPath, _hash: (0, docs_manifest_1.sha256Hex)(body) };
96
131
  if (relative_folder_path !== undefined) {
97
132
  item.relative_folder_path = relative_folder_path;
98
133
  }
134
+ if (kind.type !== undefined) {
135
+ item.type = kind.type;
136
+ }
99
137
  return item;
100
138
  }
139
+ /** Two files in one push that would create the same title in the same folder are refused locally (PM ruling 11). */
140
+ function assertUniqueTitles(files, rootDir) {
141
+ const seen = new Map();
142
+ for (const file of files) {
143
+ const name = path_1.default.basename(file);
144
+ const kind = docFileKind(name);
145
+ const relDir = path_1.default.relative(rootDir, path_1.default.dirname(file)).split(path_1.default.sep).join('/');
146
+ const title = name.slice(0, -kind.suffix.length);
147
+ const key = `${relDir}\u0000${title}`;
148
+ const relFile = path_1.default.relative(rootDir, file).split(path_1.default.sep).join('/');
149
+ const other = seen.get(key);
150
+ if (other !== undefined) {
151
+ process.stderr.write(chalk_1.default.red(`error: ${other} and ${relFile} would both create the doc "${title}"${relDir ? ` in ${relDir}` : ''} — rename one of them\n`));
152
+ process.exit(1);
153
+ }
154
+ seen.set(key, relFile);
155
+ }
156
+ }
157
+ function assertBodiesWithinCap(files, rootDir) {
158
+ for (const file of files) {
159
+ const size = fs_1.default.statSync(file).size;
160
+ if (size > exports.MAX_DOC_BODY_BYTES) {
161
+ const rel = path_1.default.relative(rootDir, file).split(path_1.default.sep).join('/');
162
+ process.stderr.write(chalk_1.default.red(`error: ${rel}: ${size} bytes is over the 1 MiB (${exports.MAX_DOC_BODY_BYTES} bytes) doc body limit\n`));
163
+ process.exit(1);
164
+ }
165
+ }
166
+ }
167
+ /** A canvas file must at least be a JSON object; shape is the server's (invalid_canvas_body). */
168
+ function assertCanvasFilesParse(files, rootDir) {
169
+ for (const file of files) {
170
+ if (docFileKind(path_1.default.basename(file))?.type !== 'canvas')
171
+ continue;
172
+ const rel = path_1.default.relative(rootDir, file).split(path_1.default.sep).join('/');
173
+ let parsed;
174
+ try {
175
+ parsed = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
176
+ }
177
+ catch (e) {
178
+ process.stderr.write(chalk_1.default.red(`error: ${rel}: not a valid JSON Canvas file (${e.message})\n`));
179
+ process.exit(1);
180
+ }
181
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
182
+ process.stderr.write(chalk_1.default.red(`error: ${rel}: not a valid JSON Canvas file (expected a JSON object)\n`));
183
+ process.exit(1);
184
+ }
185
+ }
186
+ }
187
+ function chunkItems(items) {
188
+ const chunks = [];
189
+ let current = [];
190
+ let bytes = 0;
191
+ for (const item of items) {
192
+ const size = Buffer.byteLength(item.body, 'utf8');
193
+ if (current.length > 0 && (current.length >= CHUNK_SIZE || bytes + size > exports.MAX_CHUNK_BYTES)) {
194
+ chunks.push(current);
195
+ current = [];
196
+ bytes = 0;
197
+ }
198
+ current.push(item);
199
+ bytes += size;
200
+ }
201
+ if (current.length > 0)
202
+ chunks.push(current);
203
+ return chunks;
204
+ }
205
+ /** Which doc types a file kind may replace. `.md` may replace anything that is not visual, canvas or media. */
206
+ function replaceKindMismatch(fileType, docSlug) {
207
+ if (fileType !== undefined)
208
+ return docSlug !== fileType;
209
+ return docSlug === 'visual' || docSlug === 'canvas' || docSlug === 'media';
210
+ }
211
+ /**
212
+ * `doc push <file> --replace <id>`: replace one existing doc's body by id (cli#154). No
213
+ * base_revision — the user named the doc — so the doc's type is checked first: the server
214
+ * accepts any body under the cap for a visual or markdown doc (PM ruling 2).
215
+ */
216
+ async function replaceDocBody(absPath, singleFile, options, config) {
217
+ const fail = (message) => {
218
+ process.stderr.write(chalk_1.default.red(`error: ${message}\n`));
219
+ process.exit(1);
220
+ };
221
+ if (!/^\d+$/.test(options.replace ?? ''))
222
+ fail(`--replace takes a numeric doc id (got "${options.replace}").`);
223
+ if (!singleFile)
224
+ fail('--replace takes a single .md, .html, .canvas.json or .canvas file, not a directory.');
225
+ if (options.folder !== undefined || options.type !== undefined || options.onConflict !== undefined) {
226
+ fail('--replace cannot be combined with --folder, --type or --on-conflict.');
227
+ }
228
+ assertBodiesWithinCap([absPath], path_1.default.dirname(absPath));
229
+ assertCanvasFilesParse([absPath], path_1.default.dirname(absPath));
230
+ const id = Number(options.replace);
231
+ const file = path_1.default.basename(absPath);
232
+ const fileType = docFileKind(file).type;
233
+ let read;
234
+ try {
235
+ read = await (0, mcp_1.callDocsTool)(config, { action: 'read_doc', id });
236
+ }
237
+ catch (e) {
238
+ return fail(e.message);
239
+ }
240
+ if (!read.ok) {
241
+ fail(`${read.data?.code ?? 'unknown_error'}: ${read.data?.message ?? 'MCP returned an error with no message'}`);
242
+ }
243
+ const title = String(read.data?.title ?? '');
244
+ const docSlug = read.data?.doc_type?.slug ?? null;
245
+ if (replaceKindMismatch(fileType, docSlug)) {
246
+ fail(`doc ${id} ("${title}") is a ${docSlug ?? 'markdown'} doc, and ${file} is a ${fileType ?? 'markdown'} file — refusing to replace it.`);
247
+ }
248
+ if (options.dryRun) {
249
+ if (options.json) {
250
+ console.log(JSON.stringify({ replaced: { id, title, file, dry_run: true } }));
251
+ }
252
+ else {
253
+ console.log(chalk_1.default.cyan(`[dry-run preview] would replace doc ${id} ("${title}") with ${file}`));
254
+ }
255
+ process.exit(0);
256
+ }
257
+ const body = fs_1.default.readFileSync(absPath, 'utf8');
258
+ let result;
259
+ try {
260
+ result = await (0, mcp_1.callDocsTool)(config, { action: 'write', id, body });
261
+ }
262
+ catch (e) {
263
+ return fail(e.message);
264
+ }
265
+ if (!result.ok) {
266
+ fail(`${result.data?.code ?? 'unknown_error'}: ${result.data?.message ?? 'MCP returned an error with no message'}`);
267
+ }
268
+ const revision = result.data?.current_revision_id ?? null;
269
+ if (options.json) {
270
+ console.log(JSON.stringify({ replaced: { id, title, file, current_revision_id: revision } }));
271
+ }
272
+ else {
273
+ console.log(chalk_1.default.green(`replaced doc ${id} ("${title}") with ${file}${revision !== null ? ` (revision ${revision})` : ''}`));
274
+ }
275
+ process.exit(0);
276
+ }
101
277
  /**
102
278
  * Merge two BulkCreateSummary objects by summing all numeric fields.
103
279
  */
@@ -151,20 +327,47 @@ function formatSummaryLine(summary, dryRun) {
151
327
  * stub server without touching the filesystem config.
152
328
  */
153
329
  async function docPushWithConfig(dir, options, config) {
154
- const absDir = path_1.default.resolve(dir);
155
- if (!fs_1.default.existsSync(absDir) || !fs_1.default.statSync(absDir).isDirectory()) {
156
- process.stderr.write(chalk_1.default.red(`error: "${dir}" is not a directory.\n`));
330
+ const absPath = path_1.default.resolve(dir);
331
+ if (!fs_1.default.existsSync(absPath)) {
332
+ process.stderr.write(chalk_1.default.red(`error: "${dir}" does not exist.\n`));
333
+ process.exit(1);
334
+ }
335
+ const singleFile = fs_1.default.statSync(absPath).isFile();
336
+ if (singleFile && docFileKind(path_1.default.basename(absPath)) === null) {
337
+ process.stderr.write(chalk_1.default.red(`error: "${dir}" is not a .md, .html, .canvas.json or .canvas file (use \`solidactions doc upload\` for media).\n`));
157
338
  process.exit(1);
158
339
  }
159
- const allFiles = walkMarkdownFiles(absDir);
340
+ if (options.replace !== undefined) {
341
+ await replaceDocBody(absPath, singleFile, options, config);
342
+ return;
343
+ }
344
+ // A single file is pushed as if its directory held only that file.
345
+ const absDir = singleFile ? path_1.default.dirname(absPath) : absPath;
160
346
  // A missing/unparseable manifest means nothing is tracked — everything is untracked,
161
347
  // matching the existing (pre-drift-guard) bulk_create behavior byte-for-byte.
162
348
  const manifest = (0, docs_manifest_1.readManifest)(absDir, { warnOnParseError: true });
163
- const trackedMediaEntries = Object.entries(manifest?.docs ?? {}).filter(([, e]) => e.media);
164
- // A pulled folder of images alone (no .md files) must still be pushable — the early
349
+ const allFiles = singleFile ? [absPath] : walkDocFiles(absDir);
350
+ // Files the manifest marks `media: true` are owned by the media pass below, not
351
+ // the doc-body pass: skip them in the filename-based preflight (the 1 MiB body
352
+ // cap, the canvas JSON check, the duplicate-title check — a tracked media file
353
+ // creates no new doc title). Media keeps its own size handling (the server's
354
+ // media cap); real doc-body files keep all three checks.
355
+ const mediaRelPaths = new Set(Object.entries(manifest?.docs ?? {})
356
+ .filter(([, entry]) => entry.media)
357
+ .map(([relPath]) => relPath));
358
+ const docBodyFiles = allFiles.filter((file) => !mediaRelPaths.has(path_1.default.relative(absDir, file).split(path_1.default.sep).join('/')));
359
+ assertBodiesWithinCap(docBodyFiles, absDir);
360
+ assertCanvasFilesParse(docBodyFiles, absDir);
361
+ if (!singleFile) {
362
+ assertUniqueTitles(docBodyFiles, absDir);
363
+ }
364
+ const trackedMediaEntries = singleFile
365
+ ? Object.entries(manifest?.docs ?? {}).filter(([relPath, e]) => e.media && relPath === path_1.default.relative(absDir, absPath).split(path_1.default.sep).join('/'))
366
+ : Object.entries(manifest?.docs ?? {}).filter(([, e]) => e.media);
367
+ // A pulled folder of images alone (no doc files) must still be pushable — the early
165
368
  // exit only fires when there's truly nothing to push.
166
369
  if (allFiles.length === 0 && trackedMediaEntries.length === 0) {
167
- process.stderr.write(chalk_1.default.red(`error: no .md files or tracked media found under "${dir}" — nothing to push.\n`));
370
+ process.stderr.write(chalk_1.default.red(`error: no .md, .html, .canvas.json or .canvas files or tracked media found under "${dir}" — nothing to push.\n`));
168
371
  process.exit(1);
169
372
  }
170
373
  // Partition into tracked (relative path present in the pull manifest) vs. untracked.
@@ -307,33 +510,42 @@ async function docPushWithConfig(dir, options, config) {
307
510
  trackedWritten.push({ file: relPath, id: entry.id, current_revision_id: entry.current_revision_id });
308
511
  (0, docs_manifest_1.writeManifest)(absDir, manifest);
309
512
  }
310
- const untrackedMedia = walkUntrackedBinaries(absDir, manifest);
513
+ const untrackedMedia = singleFile ? [] : walkUntrackedBinaries(absDir, manifest);
311
514
  const items = untrackedFiles.map((f) => fileToItem(f, absDir));
312
515
  // Untracked docs (new files, or files re-orphaned by a deleted-remotely re-pull)
313
516
  // must land back under the folder this directory was pulled into, not the docs
314
517
  // root — an explicit --folder always overrides the manifest's recorded folder.
315
518
  const effectiveFolder = options.folder ?? manifest?.folder_path;
316
519
  const folderInferredFromManifest = !options.folder && !!manifest?.folder_path;
317
- // Chunk into groups of CHUNK_SIZE
318
- const chunks = [];
319
- for (let i = 0; i < items.length; i += CHUNK_SIZE) {
320
- chunks.push(items.slice(i, i + CHUNK_SIZE));
321
- }
520
+ // Chunk into groups of CHUNK_SIZE items and about MAX_CHUNK_BYTES of bodies.
521
+ const chunks = chunkItems(items);
322
522
  if (folderInferredFromManifest && items.length > 0 && !options.json) {
323
523
  console.log(chalk_1.default.gray(`creating untracked docs under "${effectiveFolder}" (from ${docs_manifest_1.DOCS_MANIFEST})`));
324
524
  }
325
525
  const onConflict = options.onConflict ?? 'skip';
326
526
  const allResultRows = [];
327
527
  let mergedSummary = {};
528
+ // cli#157: record what this push creates, so the next push updates it instead of skipping it.
529
+ // Only when the docs landed in the manifest's own folder tree.
530
+ // PM ruling 5: a single-file push records only into a manifest its directory already has.
531
+ const recordable = !options.dryRun
532
+ && (manifest !== null || !singleFile)
533
+ && (manifest === null || options.folder === undefined || options.folder === manifest.folder_path);
534
+ const recordTarget = recordable
535
+ ? (manifest ?? { folder_path: options.folder ?? '', docs: {} })
536
+ : null;
328
537
  for (const chunk of chunks) {
329
538
  const callArgs = {
330
539
  action: 'bulk_create',
331
540
  on_conflict: onConflict,
332
- items: chunk.map(({ title, body, relative_folder_path }) => {
541
+ items: chunk.map(({ title, body, relative_folder_path, type }) => {
333
542
  const item = { title, body };
334
543
  if (relative_folder_path !== undefined) {
335
544
  item.relative_folder_path = relative_folder_path;
336
545
  }
546
+ if (type !== undefined) {
547
+ item.type = type;
548
+ }
337
549
  return item;
338
550
  }),
339
551
  };
@@ -367,14 +579,52 @@ async function docPushWithConfig(dir, options, config) {
367
579
  const rows = data?.results ?? [];
368
580
  const summary = data?.summary ?? {};
369
581
  // Correlate rows back to source files using chunk index
582
+ const chunkResultRows = [];
370
583
  for (const row of rows) {
371
584
  const sourceFile = chunk[row.index]?._filePath ?? '(unknown)';
372
- allResultRows.push({
585
+ const resultRow = {
373
586
  ...row,
374
587
  file: path_1.default.relative(absDir, sourceFile),
375
- });
588
+ };
589
+ chunkResultRows.push(resultRow);
590
+ allResultRows.push(resultRow);
376
591
  }
377
592
  mergedSummary = mergeSummaries(mergedSummary, summary);
593
+ // Record and persist this chunk's successes before the next chunk is
594
+ // sent: a later chunk's failure exits first, and docs already created
595
+ // must still be updatable by id on the next push. The folder /
596
+ // dry-run / single-file guards and existing manifest entries are kept
597
+ // (recordTarget is null unless recording applies).
598
+ if (recordTarget !== null) {
599
+ let changed = false;
600
+ for (const row of chunkResultRows) {
601
+ if (!['created', 'renamed', 'overwritten'].includes(row.status) || row.id === undefined)
602
+ continue;
603
+ const snapshotHash = chunk[row.index]?._hash;
604
+ if (snapshotHash === undefined)
605
+ continue;
606
+ const relPath = row.file.split(path_1.default.sep).join('/');
607
+ if (row.status === 'renamed' && row.title) {
608
+ process.stderr.write(chalk_1.default.yellow(`${relPath}: created as "${row.title}" (the original title was taken); the next doc pull will name the local file after "${row.title}"\n`));
609
+ }
610
+ recordTarget.docs[relPath] = {
611
+ id: Number(row.id),
612
+ title: row.title ?? path_1.default.basename(relPath),
613
+ current_revision_id: row.current_revision_id ?? null,
614
+ media: false,
615
+ body_sha256: snapshotHash,
616
+ };
617
+ changed = true;
618
+ }
619
+ if (changed)
620
+ (0, docs_manifest_1.writeManifest)(absDir, recordTarget);
621
+ }
622
+ }
623
+ // PM ruling 8: never dereference a missing manifest. The "went elsewhere" note is only for an
624
+ // existing manifest with a different --folder; a single-file push with no manifest stays quiet.
625
+ if (!options.dryRun && manifest !== null && options.folder !== undefined && options.folder !== manifest.folder_path
626
+ && allResultRows.some((r) => ['created', 'renamed', 'overwritten'].includes(r.status))) {
627
+ process.stderr.write(chalk_1.default.yellow(`created docs were not recorded in ${docs_manifest_1.DOCS_MANIFEST}: they went to "${options.folder}", not "${manifest.folder_path}"\n`));
378
628
  }
379
629
  // Collect pending items (results that have property_validation)
380
630
  const pendingItems = allResultRows
@@ -444,6 +694,19 @@ async function docPushWithConfig(dir, options, config) {
444
694
  process.stderr.write(chalk_1.default.red(`${row.file}: ${row.error ?? row.code ?? 'unknown error'}\n`));
445
695
  }
446
696
  }
697
+ // Docs created by an untracked push are not in the manifest, so re-pushing an edited page
698
+ // skips it under the default --on-conflict skip. Say how to update it (cli#154; the
699
+ // pull-side mapping that would track it is cli#157).
700
+ for (const row of allResultRows) {
701
+ if (row.status !== 'skipped' || docFileKind(path_1.default.basename(row.file))?.type === undefined)
702
+ continue;
703
+ // row.file is relative to the pushed directory; suggest the path the user
704
+ // typed (cli#154 I4): the directory argument joined for a directory push,
705
+ // the file argument itself for a single-file push.
706
+ const suggested = singleFile ? dir : path_1.default.join(dir, row.file);
707
+ process.stderr.write(chalk_1.default.yellow(`${row.file}: skipped — a doc with this title already exists. To update it, push again with --on-conflict overwrite, `
708
+ + `or run \`solidactions doc push ${quoteShellPath(suggested)} --replace ${row.id ?? '<doc-id>'}\`\n`));
709
+ }
447
710
  if (pendingItems.length > 0) {
448
711
  console.log(chalk_1.default.yellow(`\nProperties pending (${pendingItems.length} doc${pendingItems.length === 1 ? '' : 's'}):`));
449
712
  for (const item of pendingItems) {
@@ -78,7 +78,10 @@ async function resolveReplaceTarget(config, replace) {
78
78
  catch (error) {
79
79
  const status = error.response?.status;
80
80
  const code = error.response?.data?.code;
81
- if (status === 422 && code === 'folder_path_not_found') {
81
+ if (status === 401) {
82
+ console.error(chalk_1.default.red(`✗ ${(0, api_1.authFailedLine)(config.host)}`));
83
+ }
84
+ else if (status === 422 && code === 'folder_path_not_found') {
82
85
  console.error(chalk_1.default.red(`✗ no folder "${folderPath}" in this workspace`));
83
86
  }
84
87
  else if (status === 404) {
@@ -159,7 +162,7 @@ async function docUpload(files, options = {}) {
159
162
  console.error(chalk_1.default.red(`✗ ${displayName} — ${data?.message || 'File exceeds the maximum upload size (20MB).'}`));
160
163
  }
161
164
  else if (status === 401) {
162
- console.error(chalk_1.default.red(`✗ ${displayName} — Authentication failed. Run "solidactions login --global" to re-configure.`));
165
+ console.error(chalk_1.default.red(`✗ ${displayName} — ${(0, api_1.authFailedLine)(config.host)}`));
163
166
  }
164
167
  else if (status === 404 && data?.code === 'media_not_found') {
165
168
  console.error(chalk_1.default.red(`✗ ${displayName} — doc ${replaceDocId} is not a media doc`));
@@ -8,6 +8,7 @@ const axios_1 = __importDefault(require("axios"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const prompts_1 = __importDefault(require("prompts"));
10
10
  const api_1 = require("../utils/api");
11
+ const project_ref_1 = require("../utils/project-ref");
11
12
  async function envDelete(keyOrProject, keyIfProject, options = {}) {
12
13
  const config = await (0, api_1.requireConfigWithWorkspace)();
13
14
  // Determine mode: if keyIfProject is provided, it's project mapping delete
@@ -15,11 +16,11 @@ async function envDelete(keyOrProject, keyIfProject, options = {}) {
15
16
  const projectName = isProjectMode ? keyOrProject : undefined;
16
17
  const key = isProjectMode ? keyIfProject : keyOrProject;
17
18
  const environment = options.env ?? 'dev';
18
- const projectSlug = projectName && environment === 'production' ? projectName : `${projectName}-${environment}`;
19
19
  try {
20
20
  if (isProjectMode) {
21
21
  // Delete project variable
22
22
  console.log(chalk_1.default.blue(`Deleting variable "${key}" from project "${projectName}" (${environment})...`));
23
+ const projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName, environment);
23
24
  // First, get the variable to find its ID
24
25
  const listResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, {
25
26
  headers: (0, api_1.getApiHeaders)(config),
@@ -92,19 +93,25 @@ async function envDelete(keyOrProject, keyIfProject, options = {}) {
92
93
  catch (error) {
93
94
  if (error.response) {
94
95
  if (error.response.status === 401) {
95
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
96
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
96
97
  }
97
98
  else if (error.response.status === 404) {
98
99
  if (isProjectMode) {
99
- const envsList = await (0, api_1.describeProjectEnvironments)(config, projectName);
100
- console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment${envsList ? ` (exists in: ${envsList})` : ''}.`));
100
+ const family = await (0, api_1.lookupProjectFamilyEnvironments)(config, projectName);
101
+ const envs = family?.environments ?? [];
102
+ if (envs.length > 0 && !envs.includes(environment)) {
103
+ console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment (exists in: ${envs.join(', ')}).`));
104
+ }
105
+ else {
106
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(404, error.response.data)));
107
+ }
101
108
  }
102
109
  else {
103
110
  console.error(chalk_1.default.red(`Variable "${key}" not found.`));
104
111
  }
105
112
  }
106
113
  else {
107
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
114
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
108
115
  }
109
116
  }
110
117
  else {
@@ -7,6 +7,7 @@ exports.envList = envList;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const api_1 = require("../utils/api");
10
+ const project_ref_1 = require("../utils/project-ref");
10
11
  const table_1 = require("../utils/table");
11
12
  /**
12
13
  * Format a value for display, with inherited badge if applicable.
@@ -33,15 +34,13 @@ async function envList(projectName, options = {}) {
33
34
  try {
34
35
  if (projectName) {
35
36
  // List project variable mappings
36
- const projectSlug = environment === 'production'
37
- ? projectName
38
- : `${projectName}-${environment}`;
39
- if (!options.json) {
40
- console.log(chalk_1.default.blue(`Variables for project "${projectName}" (${environment}):`));
41
- }
37
+ const projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName, environment);
42
38
  const response = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, {
43
39
  headers: (0, api_1.getApiHeaders)(config),
44
40
  });
41
+ if (!options.json) {
42
+ console.log(chalk_1.default.blue(`Variables for project "${projectName}" (${environment}):`));
43
+ }
45
44
  const mappings = response.data || [];
46
45
  if (options.json) {
47
46
  console.log(JSON.stringify(mappings, null, 2));
@@ -109,12 +108,12 @@ async function envList(projectName, options = {}) {
109
108
  }
110
109
  else {
111
110
  // List global variables with per-environment values
112
- if (!options.json) {
113
- console.log(chalk_1.default.blue('Global variables:'));
114
- }
115
111
  const response = await axios_1.default.get(`${config.host}/api/v1/variables`, {
116
112
  headers: (0, api_1.getApiHeaders)(config),
117
113
  });
114
+ if (!options.json) {
115
+ console.log(chalk_1.default.blue('Global variables:'));
116
+ }
118
117
  const variables = response.data?.data || [];
119
118
  if (options.json) {
120
119
  console.log(JSON.stringify(variables, null, 2));
@@ -207,19 +206,25 @@ async function envList(projectName, options = {}) {
207
206
  catch (error) {
208
207
  if (error.response) {
209
208
  if (error.response.status === 401) {
210
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
209
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
211
210
  }
212
211
  else if (error.response.status === 404) {
213
212
  if (projectName) {
214
- const envsList = await (0, api_1.describeProjectEnvironments)(config, projectName);
215
- console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment${envsList ? ` (exists in: ${envsList})` : ''}.`));
213
+ const family = await (0, api_1.lookupProjectFamilyEnvironments)(config, projectName);
214
+ const envs = family?.environments ?? [];
215
+ if (envs.length > 0 && !envs.includes(environment)) {
216
+ console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment (exists in: ${envs.join(', ')}).`));
217
+ }
218
+ else {
219
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(404, error.response.data)));
220
+ }
216
221
  }
217
222
  else {
218
- console.error(chalk_1.default.red('Resource not found.'));
223
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(404, error.response.data)));
219
224
  }
220
225
  }
221
226
  else {
222
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
227
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
223
228
  }
224
229
  }
225
230
  else {
@@ -8,6 +8,7 @@ const axios_1 = __importDefault(require("axios"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const prompts_1 = __importDefault(require("prompts"));
10
10
  const api_1 = require("../utils/api");
11
+ const project_ref_1 = require("../utils/project-ref");
11
12
  const env_1 = require("../utils/env");
12
13
  async function envMap(projectName, projectKey, globalKey, options = {}) {
13
14
  const config = await (0, api_1.requireConfigWithWorkspace)();
@@ -17,6 +18,7 @@ async function envMap(projectName, projectKey, globalKey, options = {}) {
17
18
  }
18
19
  console.log(chalk_1.default.blue(`Mapping global variable "${globalKey}" to project key "${projectKey}" in "${projectName}"...`));
19
20
  try {
21
+ const projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName);
20
22
  // First, get the global variable ID by key
21
23
  const varsResponse = await axios_1.default.get(`${config.host}/api/v1/variables`, {
22
24
  headers: (0, api_1.getApiHeaders)(config),
@@ -30,7 +32,7 @@ async function envMap(projectName, projectKey, globalKey, options = {}) {
30
32
  }
31
33
  // Check if project key already has a mapping
32
34
  if (!options.yes) {
33
- const mappingsResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectName}/variable-mappings`, { headers: (0, api_1.getApiHeaders)(config) });
35
+ const mappingsResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, { headers: (0, api_1.getApiHeaders)(config) });
34
36
  const mappings = mappingsResponse.data || [];
35
37
  const existing = mappings.find((m) => m.env_name === projectKey);
36
38
  if (existing && (existing.has_value || existing.global_variable_id)) {
@@ -51,7 +53,7 @@ async function envMap(projectName, projectKey, globalKey, options = {}) {
51
53
  }
52
54
  }
53
55
  // Create the mapping
54
- await axios_1.default.post(`${config.host}/api/v1/projects/${projectName}/variable-mappings`, {
56
+ await axios_1.default.post(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, {
55
57
  project_key: projectKey,
56
58
  global_variable_id: globalVar.id,
57
59
  }, {
@@ -63,16 +65,16 @@ async function envMap(projectName, projectKey, globalKey, options = {}) {
63
65
  catch (error) {
64
66
  if (error.response) {
65
67
  if (error.response.status === 401) {
66
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
68
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
67
69
  }
68
70
  else if (error.response.status === 404) {
69
71
  console.error(chalk_1.default.red(`Project "${projectName}" not found.`));
70
72
  }
71
73
  else if (error.response.status === 422) {
72
- console.error(chalk_1.default.red('Validation error:'), error.response.data.message || error.response.data.errors);
74
+ console.error(chalk_1.default.red('Validation error:'), (0, api_1.formatValidationError)(error.response.data));
73
75
  }
74
76
  else {
75
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
77
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
76
78
  }
77
79
  }
78
80
  else {