@workover/cli 0.25.0 → 0.27.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/bin/workover.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  // The Workover CLI. `login` / `logout` / `whoami` authenticate through the device-authorization
3
3
  // flow (RFC 8628); everything else works on documents with the stored token: `projects`, `doc`
4
- // (list/read/create/propose/write/search/tabs/images/image/status), `rules`, `comments`, `draft`, `draft-set`, `eval`,
4
+ // (list/read/create/propose/write/search/tabs/images/image/status), `media` (list/replace), `rules`, `comments`, `draft`,
5
+ // `draft-set`, `eval`,
5
6
  // and on hosted Help Centers: `project create` and `site` (create/import/domain/check/publish/status),
6
7
  // which need `login --site`.
7
8
  //
@@ -39,6 +40,8 @@ import {
39
40
  docRef,
40
41
  environmentMismatch,
41
42
  imagesInHtml,
43
+ mediaListQuery,
44
+ formatMediaList,
42
45
  signInHelp,
43
46
  jsonObjectFlag,
44
47
  vetImageUpload,
@@ -1477,10 +1480,24 @@ async function docCommand() {
1477
1480
  : {}),
1478
1481
  });
1479
1482
  if (asJson) return console.log(JSON.stringify(res, null, 2));
1480
- console.log(
1481
- `\n \x1b[32m✓\x1b[0m Proposed changes to ${res?.tab ? `the "${res.tab.title}" tab of ` : ''}document #${docId}.`,
1482
- );
1483
- console.log(' They appear as tracked-change suggestions for a person to accept or reject.');
1483
+ // Said from the api's `outcome` (WO-1748): "they appear" used to be printed for a resend that
1484
+ // changed nothing, and for a suggestion the editor had already been unable to show.
1485
+ const where = `${res?.tab ? `the "${res.tab.title}" tab of ` : ''}document #${docId}`;
1486
+ const sid = res?.id != null ? ` (suggestion #${res.id})` : '';
1487
+ if (res?.outcome === 'unchanged') {
1488
+ console.log(`\n Nothing changed: the open suggestion on ${where}${sid} already says exactly this.`);
1489
+ } else if (res?.outcome === 'held') {
1490
+ console.log(`\n Not applied: the open suggestion on ${where}${sid} is out with Workover AI for a revision.`);
1491
+ console.log(' Your text would be overwritten when that lands. Propose again once it is back.');
1492
+ } else if (res?.outcome === 'reoffered') {
1493
+ console.log(`\n \x1b[32m✓\x1b[0m Offered the open suggestion on ${where}${sid} to the editor again.`);
1494
+ console.log(' It says exactly this already, and the editor had not been able to show it before.');
1495
+ } else {
1496
+ console.log(
1497
+ `\n \x1b[32m✓\x1b[0m ${res?.outcome === 'updated' ? 'Updated the open suggestion on' : 'Proposed changes to'} ${where}${sid}.`,
1498
+ );
1499
+ console.log(' They appear as tracked-change suggestions for a person to accept or reject.');
1500
+ }
1484
1501
  if (res?.documentUrl) console.log(` ${res.documentUrl}`);
1485
1502
  printTitleHeading(res?.titleHeading);
1486
1503
  printStyleFeedback(res?.style);
@@ -2129,6 +2146,67 @@ const PROJECT_USAGE = [
2129
2146
  '',
2130
2147
  ].join('\n');
2131
2148
 
2149
+ const MEDIA_USAGE = [
2150
+ '',
2151
+ ' Usage: workover media <command>',
2152
+ '',
2153
+ ' list <project> [--filter <f>] [--source workover|wordpress]',
2154
+ ' [--search "<q>"] [--cursor <n>] [--json]',
2155
+ ' the project\u2019s Media library: every image its documents use',
2156
+ ' and every WordPress attachment, with usage, alt text and',
2157
+ ' problems. <f> is all, in_use, unused, attention, missing_alt,',
2158
+ ' oversized, broken, stale or deleted',
2159
+ ' replace <project> <assetId> <replacementAssetId> [--json]',
2160
+ ' raise ONE reviewed fix that swaps the image for the other in',
2161
+ ' every document using it; accepting it in Health is what',
2162
+ ' changes them. Needs `login --write`',
2163
+ '',
2164
+ ' Asset ids are the #numbers `media list` prints; project ids come from',
2165
+ ' `workover projects`.',
2166
+ '',
2167
+ ].join('\n');
2168
+
2169
+ /** `workover media`: the project Media library (WO-1811), as workover_list_media and _replace_media. */
2170
+ async function mediaCommand() {
2171
+ const sub = process.argv[3];
2172
+ if (sub !== 'list' && sub !== 'replace') {
2173
+ console.log(MEDIA_USAGE);
2174
+ process.exit(sub ? 1 : 0);
2175
+ }
2176
+ const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
2177
+ const projectId = rowId(positionals[0] ?? '');
2178
+ if (projectId === null) {
2179
+ console.log(MEDIA_USAGE);
2180
+ process.exit(1);
2181
+ }
2182
+ const cfg = requireSignIn();
2183
+ if (sub === 'list') {
2184
+ const res = await authedCall(cfg, `/project/${projectId}/media?${mediaListQuery(flags)}`);
2185
+ if (flags.json === true) return console.log(JSON.stringify(res, null, 2));
2186
+ const out = formatMediaList(projectId, res);
2187
+ return console.log(`\n${out.replace(/^(?=.)/gm, ' ')}\n`);
2188
+ }
2189
+ const assetId = rowId(positionals[1] ?? '');
2190
+ const replacementAssetId = rowId(positionals[2] ?? '');
2191
+ if (assetId === null || replacementAssetId === null || assetId === replacementAssetId) {
2192
+ console.error(
2193
+ '\n Name the image to replace and a different one to put in its place: ' +
2194
+ 'workover media replace <project> <assetId> <replacementAssetId>\n',
2195
+ );
2196
+ process.exit(1);
2197
+ }
2198
+ const res = await authedCall(cfg, `/project/${projectId}/media/${assetId}/replace`, {
2199
+ replacementAssetId,
2200
+ });
2201
+ if (flags.json === true) return console.log(JSON.stringify(res, null, 2));
2202
+ console.log(
2203
+ `\n Raised a fix to replace #${assetId} with #${replacementAssetId} in every document that uses it` +
2204
+ `${res?.suggestionId ? ` (fix #${res.suggestionId})` : ''}.\n` +
2205
+ ' Nothing has changed yet: accepting it in the project’s Health page rewrites the documents. The old image\n' +
2206
+ ' stays in the library.\n',
2207
+ );
2208
+ }
2209
+
2132
2210
  async function projectCommand() {
2133
2211
  const sub = process.argv[3];
2134
2212
  if (sub !== 'create') {
@@ -2529,6 +2607,7 @@ else if (cmd === 'comments') await commentsCommand();
2529
2607
  else if (cmd === 'projects') await projects();
2530
2608
  else if (cmd === 'status') await status();
2531
2609
  else if (cmd === 'project') await projectCommand();
2610
+ else if (cmd === 'media') await mediaCommand();
2532
2611
  else if (cmd === 'site') await siteCommand();
2533
2612
  else if (cmd === 'feedback') await feedbackCommand();
2534
2613
  else if (cmd === 'install-claude') installClaude();
@@ -2559,6 +2638,8 @@ else {
2559
2638
  console.log(' rules The style guide agents should write by: list, export, add');
2560
2639
  console.log(' workover rules export --project 11 >> AGENTS.md');
2561
2640
  console.log(' projects List the projects you can reach, with their ids and workspaces');
2641
+ console.log(' media A project\u2019s Media library: list (usage, alt, problems), replace');
2642
+ console.log(' workover media list 11 --filter missing_alt');
2562
2643
  console.log(' status Where a project’s setup has got to, and what is left to do');
2563
2644
  console.log(' workover status 11 [--json]');
2564
2645
  console.log(' project create: a new project that publishes to a Workover Help Center');
package/lib.mjs CHANGED
@@ -851,3 +851,59 @@ export const renderSetupStatus = (s, { web } = {}) => {
851
851
  lines.push('');
852
852
  return lines;
853
853
  };
854
+
855
+ // The same two helpers as apps/mcp/lib.mjs (workover_list_media); keep them in step.
856
+ /** `workover media`'s filters, as the flags GET /project/:id/media takes. */
857
+ const MEDIA_FLAGS = {
858
+ attention: 'attention',
859
+ missing_alt: 'missingAlt',
860
+ oversized: 'oversized',
861
+ broken: 'broken',
862
+ stale: 'stale',
863
+ };
864
+
865
+ /** The query string for GET /project/:id/media, from `workover media`'s flags. */
866
+ export function mediaListQuery(args = {}) {
867
+ const q = new URLSearchParams();
868
+ const filter = String(args.filter || 'all');
869
+ if (filter === 'in_use' || filter === 'unused' || filter === 'deleted') q.set('tab', filter);
870
+ if (MEDIA_FLAGS[filter]) q.set(MEDIA_FLAGS[filter], 'true');
871
+ if (args.source === 'workover' || args.source === 'wordpress') q.set('source', args.source);
872
+ const search = typeof args.search === 'string' ? args.search.trim() : '';
873
+ if (search) q.set('search', search);
874
+ const cursor = Number(args.cursor);
875
+ if (Number.isInteger(cursor) && cursor > 0) q.set('cursor', String(cursor));
876
+ q.set('limit', '50');
877
+ return q.toString();
878
+ }
879
+
880
+ /** `workover media`'s answer: the counts, one block per asset, then the next page. */
881
+ export function formatMediaList(projectId, res) {
882
+ const items = Array.isArray(res?.items) ? res.items : [];
883
+ const c = res?.counts || {};
884
+ const head =
885
+ `Media library of project #${projectId}: ${c.all ?? items.length} images, ` +
886
+ `${c.inUse ?? 0} in use, ${c.unused ?? 0} not found in imported content, ` +
887
+ `${c.attention ?? 0} need attention.`;
888
+ if (!items.length) return `${head}\n\nNothing matches.`;
889
+ const lines = items.map((a) => {
890
+ const problems = [];
891
+ // Alt text is an image's; a PDF in the WordPress library has none to miss.
892
+ if (!a.alt && (a.mime == null || String(a.mime).startsWith('image/')))
893
+ problems.push('no alt text');
894
+ if (a.oversized) problems.push(`oversized (${Math.round((a.bytes || 0) / 1024)} KB)`);
895
+ if (a.brokenAt) problems.push('broken');
896
+ if (a.staleAt) problems.push(`outdated: ${a.staleReason || 'the UI changed'}`);
897
+ if (a.deletedAt) problems.push('deleted');
898
+ const from = a.wpAttachmentId ? `WordPress #${a.wpAttachmentId}` : 'Workover';
899
+ const used = a.useCount
900
+ ? `used in ${a.useCount} doc${a.useCount === 1 ? '' : 's'}`
901
+ : 'not found in imported content';
902
+ return (
903
+ `#${a.id} ${a.filename} (${from}, ${used})\n alt: ${a.alt || '(none)'}` +
904
+ (problems.length ? `\n problems: ${problems.join('; ')}` : '')
905
+ );
906
+ });
907
+ const more = res?.nextCursor ? `\n\nMore: pass cursor ${res.nextCursor} for the next page.` : '';
908
+ return `${head}\n\n${lines.join('\n')}${more}`;
909
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workover/cli",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "Workover command line — sign in and cowork on your documents from the terminal.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "ScaleMath",