@workover/cli 0.12.1 → 0.13.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 CHANGED
@@ -21,6 +21,7 @@ workover doc list --project 11
21
21
  workover doc read 1234
22
22
  workover rules list --project 11 # the style guide agents should write by
23
23
  workover comments list 1234 # the feedback people left on a document
24
+ workover doc images 1234 # image file names and alt text (set them with `doc image`)
24
25
  workover draft --org 3 --project 11 "Document the billing flow"
25
26
  workover whoami # show the current sign-in
26
27
  workover logout # sign out and revoke this device's token
@@ -89,6 +90,27 @@ is how images get deleted by something that thought it was filling in a blank. I
89
90
  without that scope it is refused and `doc propose` is the way through. Every direct edit is recorded
90
91
  in the workspace's audit log, since unlike a proposal it leaves no review trail of its own.
91
92
 
93
+ ## Image file names and alt text
94
+
95
+ The editor's **Edit image** dialog, from the terminal. Each image has a file name, which becomes its
96
+ name in the WordPress media library on publish, and alt text, which screen readers read out and
97
+ search engines index.
98
+
99
+ ```sh
100
+ workover doc images 1234 # every image: number, file name, alt, src
101
+ workover doc images https://workover.io/app/acme/docs/<id> # the URL works too
102
+ workover doc image 1234 2 --name lifterlms-groups-list --alt "Groups screen listing two groups"
103
+ workover doc image 1234 3 --alt "Course settings with seats set to 10" # file name kept
104
+ ```
105
+
106
+ `<n>` is the image's number in `doc images`. Pass `--src <url>` instead to name it exactly. Whichever
107
+ of `--name` and `--alt` you leave out is kept, and the extension is kept if you leave it off.
108
+
109
+ The alt text is written onto every copy of that image in the document, in every tab, because the
110
+ document's own `<img alt>` is what publishing reads. It is a single attribute change: the rest of the
111
+ body is not rewritten. Setting either needs `workover login --write`, and the change is recorded in
112
+ the document's activity with the agent's name against it. Listing needs a normal login.
113
+
92
114
  ## Comments
93
115
 
94
116
  The other half of coworking: the feedback a person left on the work, readable and answerable from
package/bin/workover.mjs CHANGED
@@ -1,7 +1,7 @@
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), `rules`, `comments`, `draft`, `draft-set`, `eval`.
4
+ // (list/read/create/propose/write/search/tabs/images/image), `rules`, `comments`, `draft`, `draft-set`, `eval`.
5
5
  //
6
6
  // This header used to say "auth only for now", left over from the first version and never updated
7
7
  // as the commands landed. On 2026-09-09 an agent read it, concluded the CLI could not edit
@@ -31,6 +31,8 @@ import {
31
31
  contentCommitted,
32
32
  renderRulesBlock,
33
33
  threadComments,
34
+ docRef,
35
+ imagesInHtml,
34
36
  } from '../lib.mjs';
35
37
 
36
38
  /*
@@ -770,6 +772,10 @@ const DOC_USAGE = [
770
772
  ' the linked repository and corrects what it finds wrong;',
771
773
  ' applied as suggestions, or directly with --write. Needs',
772
774
  ' `login --draft`',
775
+ ' images <doc> [--tab <tabId>] [--json] the images in it: file name, alt',
776
+ ' image <doc> <n | --src <url>> set an image’s file name and/or',
777
+ ' [--name <file>] [--alt "<text>"] alt text; needs `login --write`',
778
+ ' [--tab <tabId>]',
773
779
  ' search "<query>" [--limit N] [--json] find documents by title/content',
774
780
  ' activity <docId> [--limit N] [--json] who changed this document, and how',
775
781
  '',
@@ -793,6 +799,127 @@ const DOC_USAGE = [
793
799
  '',
794
800
  ].join('\n');
795
801
 
802
+ /**
803
+ * The document a `<doc>` argument names: a row id, or a document URL / handle resolved through the
804
+ * api, so the link somebody pasted works as it is.
805
+ */
806
+ const resolveDocArg = async (cfg, positionals, usage) => {
807
+ const ref = docRef(positionals[0]);
808
+ if (!ref) {
809
+ console.log(`\n Usage: ${usage}`);
810
+ console.log(' The document id ("#123" in `workover doc list`) or its URL.\n');
811
+ process.exit(1);
812
+ }
813
+ if (ref.id) return ref.id;
814
+ const doc = await authedCall(cfg, `/project/doc/by-handle/${encodeURIComponent(ref.handle)}`);
815
+ if (!doc?.id) {
816
+ console.error(`\n ✗ No document at that link (or no access).\n`);
817
+ process.exit(1);
818
+ }
819
+ return doc.id;
820
+ };
821
+
822
+ /**
823
+ * `doc images` and `doc image`: the browser's "Edit image" dialog, from a terminal.
824
+ *
825
+ * The images are read off the live body, then each one's file name comes from its media record —
826
+ * the name WordPress gets on publish, which the body itself does not carry. Setting writes through
827
+ * `PATCH /project/doc/:id/media` with `syncDoc`, so the alt lands on the image nodes in the live
828
+ * document (where publishing reads it) and not only on the record.
829
+ */
830
+ async function imagesCommand(cfg, sub, positionals, flags, tabId, asJson) {
831
+ const usage =
832
+ sub === 'images'
833
+ ? 'workover doc images <doc> [--tab <tabId>]'
834
+ : 'workover doc image <doc> <n | --src <url>> [--name <file>] [--alt "<text>"]';
835
+ const docId = await resolveDocArg(cfg, positionals, usage);
836
+ const tabQuery = tabId === null ? '' : `?tabId=${tabId}`;
837
+
838
+ const list = async () => {
839
+ const live = await authedCall(cfg, `/project/doc/${docId}/content${tabQuery}`);
840
+ const images = imagesInHtml(live?.html || '');
841
+ for (const img of images) {
842
+ const meta = await authedCall(
843
+ cfg,
844
+ `/project/doc/${docId}/media/meta?src=${encodeURIComponent(img.src)}`,
845
+ );
846
+ img.filename = meta?.filename || '';
847
+ }
848
+ return { images, live };
849
+ };
850
+
851
+ if (sub === 'images') {
852
+ const { images, live } = await list();
853
+ if (asJson) return console.log(JSON.stringify(images, null, 2));
854
+ if (!images.length) {
855
+ console.log(`\n No images in ${live?.tab ? `the "${live.tab.title}" tab of ` : ''}document #${docId}.\n`);
856
+ return;
857
+ }
858
+ console.log('');
859
+ for (const img of images) {
860
+ console.log(` ${String(img.index).padStart(2)}. ${img.filename}${img.count > 1 ? ` (appears ${img.count}×)` : ''}`);
861
+ console.log(` alt: ${img.alt ? img.alt : '\x1b[33m(none)\x1b[0m'}`);
862
+ console.log(` ${img.src}`);
863
+ }
864
+ const missing = images.filter((i) => !i.alt).length;
865
+ console.log(
866
+ `\n ${images.length} image${images.length === 1 ? '' : 's'}${missing ? `, ${missing} without alt text` : ''}.`,
867
+ );
868
+ console.log(` Set one: workover doc image ${docId} <n> --name <file> --alt "<text>"\n`);
869
+ if (Array.isArray(live?.tabs) && live.tabs.length) {
870
+ console.error(` ── ${live.tabs.length} tabs; this was "${live?.tab?.title || 'the main body'}". Pass --tab <id> for another.\n`);
871
+ }
872
+ return;
873
+ }
874
+
875
+ const name = typeof flags.name === 'string' ? flags.name : undefined;
876
+ const alt = typeof flags.alt === 'string' ? flags.alt : undefined;
877
+ if (name === undefined && alt === undefined) {
878
+ console.log(`\n Usage: ${usage}`);
879
+ console.log(' Pass --name, --alt or both; whichever you leave out is kept.\n');
880
+ process.exit(1);
881
+ }
882
+
883
+ // Which image: an explicit --src, or its number in `doc images` (same tab).
884
+ let src = typeof flags.src === 'string' ? flags.src : null;
885
+ if (!src) {
886
+ const n = rowId(positionals[1]);
887
+ const { images } = await list();
888
+ const hit = n === null ? null : images.find((i) => i.index === n);
889
+ if (!hit) {
890
+ console.log(`\n Usage: ${usage}`);
891
+ console.log(
892
+ ` <n> is the image's number in \`workover doc images ${docId}\` (1–${images.length || 0}).\n`,
893
+ );
894
+ process.exit(1);
895
+ }
896
+ src = hit.src;
897
+ }
898
+
899
+ const res = await authedCall(
900
+ cfg,
901
+ `/project/doc/${docId}/media`,
902
+ {
903
+ src,
904
+ ...(name !== undefined ? { filename: name } : {}),
905
+ ...(alt !== undefined ? { alt } : {}),
906
+ syncDoc: true,
907
+ },
908
+ { method: 'PATCH' },
909
+ );
910
+ if (asJson) return console.log(JSON.stringify(res, null, 2));
911
+ console.log(`\n \x1b[32m✓\x1b[0m ${res?.filename}`);
912
+ console.log(` alt: ${res?.alt || '(none)'}`);
913
+ if (alt !== undefined && typeof res?.updatedInDoc === 'number') {
914
+ console.log(
915
+ res.updatedInDoc
916
+ ? ` Alt text set on ${res.updatedInDoc} image${res.updatedInDoc === 1 ? '' : 's'} in the document.`
917
+ : ' The alt text was already that in the document.',
918
+ );
919
+ }
920
+ console.log(' The file name is what WordPress gets on the next publish.\n');
921
+ }
922
+
796
923
  async function docCommand() {
797
924
  const sub = process.argv[3];
798
925
  // Usage before sign-in: someone who typed the command wrong is asking what the commands are, and
@@ -810,6 +937,8 @@ async function docCommand() {
810
937
  'activity',
811
938
  'reshoot',
812
939
  'verify',
940
+ 'images',
941
+ 'image',
813
942
  ].includes(sub)
814
943
  ) {
815
944
  console.log(DOC_USAGE);
@@ -892,6 +1021,10 @@ async function docCommand() {
892
1021
  return;
893
1022
  }
894
1023
 
1024
+ if (sub === 'images' || sub === 'image') {
1025
+ return imagesCommand(cfg, sub, positionals, flags, tabId, asJson);
1026
+ }
1027
+
895
1028
  if (sub === 'list') {
896
1029
  const projectId = projectIdFlag('workover doc list --project <id>');
897
1030
  const all = (await authedCall(cfg, `/project/${projectId}/documents`)) || [];
@@ -1459,6 +1592,7 @@ else {
1459
1592
  console.log(' doc Work on documents: list, read, create, propose, write, search');
1460
1593
  console.log(' plus activity, to see who changed one and how');
1461
1594
  console.log(' plus tabs and tab-new for documents with several bodies');
1595
+ console.log(' plus images and image, for image file names and alt text');
1462
1596
  console.log(' workover doc create --project 11 --title "Billing" --file b.md');
1463
1597
  console.log(' workover doc read 123 · workover doc propose 123 --file new.md');
1464
1598
  console.log(' comments Read, answer and resolve feedback on a document');
package/lib.mjs CHANGED
@@ -271,3 +271,58 @@ export const threadComments = (comments, { includeResolved = false } = {}) => {
271
271
  .sort(order)
272
272
  .map((r) => ({ ...r, replies: (repliesByRoot.get(r.id) || []).sort(order) }));
273
273
  };
274
+
275
+ /**
276
+ * Which document a user meant: a row id (`1234`, `#1234`) or the handle out of a document URL
277
+ * (`https://workover.io/app/acme/docs/<uuid>`, or the bare uuid).
278
+ *
279
+ * The URL is what people paste, because it is what the browser shows them, and a command that takes
280
+ * only a row id sends them off to `doc search` for a number they already have a link to.
281
+ */
282
+ export const docRef = (value) => {
283
+ const s = String(value ?? '').trim();
284
+ const id = rowId(s);
285
+ if (id !== null) return { id };
286
+ const m = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i.exec(s);
287
+ return m ? { handle: m[1].toLowerCase() } : null;
288
+ };
289
+
290
+ const decodeAttr = (v) =>
291
+ String(v ?? '')
292
+ .replace(/&quot;/g, '"')
293
+ .replace(/&#39;/g, "'")
294
+ .replace(/&lt;/g, '<')
295
+ .replace(/&gt;/g, '>')
296
+ // &amp; last, for the same reason as in stripHtml.
297
+ .replace(/&amp;/g, '&');
298
+
299
+ const attrOf = (tag, name) => {
300
+ const m = new RegExp(`\\s${name}\\s*=\\s*("([^"]*)"|'([^']*)')`, 'i').exec(tag);
301
+ return m ? decodeAttr(m[2] ?? m[3]) : null;
302
+ };
303
+
304
+ /**
305
+ * The images in a document body, in reading order, one entry per distinct `src`.
306
+ *
307
+ * Read off the HTML the live room renders rather than the markdown, because the HTML carries the
308
+ * node's own `src` byte for byte, and that src is how the api identifies an image. `count` says how
309
+ * many times it appears: setting alt on one sets it on every copy, and saying so beats surprising
310
+ * someone with a change in a paragraph they were not looking at.
311
+ */
312
+ export const imagesInHtml = (html) => {
313
+ const out = [];
314
+ const bySrc = new Map();
315
+ for (const m of String(html || '').matchAll(/<img\b[^>]*>/gi)) {
316
+ const src = attrOf(m[0], 'src');
317
+ if (!src) continue;
318
+ const seen = bySrc.get(src);
319
+ if (seen) {
320
+ seen.count += 1;
321
+ continue;
322
+ }
323
+ const entry = { index: out.length + 1, src, alt: attrOf(m[0], 'alt') || '', count: 1 };
324
+ bySrc.set(src, entry);
325
+ out.push(entry);
326
+ }
327
+ return out;
328
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workover/cli",
3
- "version": "0.12.1",
3
+ "version": "0.13.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",