@workover/cli 0.12.1 → 0.14.1

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
@@ -18,9 +18,11 @@ workover login --write # ...and also allow direct edits, with no suggestions
18
18
  workover login --rules # ...and also allow changing the style guide
19
19
  workover projects # the projects you can reach, with their ids
20
20
  workover doc list --project 11
21
- workover doc read 1234
21
+ workover doc get https://workover.io/app/acme/docs/<id> # a document, from its link
22
+ workover doc read 1234 # ...or its UUID, or its number
22
23
  workover rules list --project 11 # the style guide agents should write by
23
24
  workover comments list 1234 # the feedback people left on a document
25
+ workover doc images 1234 # image file names and alt text (set them with `doc image`)
24
26
  workover draft --org 3 --project 11 "Document the billing flow"
25
27
  workover whoami # show the current sign-in
26
28
  workover logout # sign out and revoke this device's token
@@ -39,6 +41,38 @@ Whatever you grant, a token can never change your account security, your billing
39
41
 
40
42
  ## Working on documents
41
43
 
44
+ **Any command that takes a document takes its link.** Paste the URL from the browser
45
+ (`https://workover.io/app/<workspace>/docs/<id>`, with or without anything after it), the UUID at
46
+ the end of it, or the number `doc list` prints (`1234` or `#1234`). `doc get` and `doc edit` are
47
+ the same as `doc read` and `doc write`.
48
+
49
+ ```sh
50
+ workover doc get https://workover.io/app/acme/docs/7cd7e9ec-28af-4a2a-bb7c-668548380a08
51
+ workover doc edit https://workover.io/app/acme/docs/7cd7e9ec-28af-4a2a-bb7c-668548380a08 --file new.md
52
+ workover comments list 7cd7e9ec-28af-4a2a-bb7c-668548380a08
53
+ ```
54
+
55
+ A link that the signed-in account cannot open says so ("not found, or no access"), and a
56
+ `workover.dev` link used with a production sign-in names the environment rather than reporting a
57
+ missing document.
58
+
59
+ `WORKOVER_CONFIG=/path/to/config.json` uses a different sign-in file, so a second environment can
60
+ be used without replacing the one in `~/.workover`. The MCP server reads it too.
61
+
62
+ ## Claude Code
63
+
64
+ ```sh
65
+ workover install-claude
66
+ ```
67
+
68
+ installs a `workover` skill into `~/.claude/skills`. Claude Code lists skills to the model by their
69
+ description, so a pasted Workover link is matched to it and the agent runs `workover doc get <link>`
70
+ rather than writing its own client around the token file. For the tools as well (all projects):
71
+
72
+ ```sh
73
+ claude mcp add --scope user workover -- npx -y @workover/mcp@latest
74
+ ```
75
+
42
76
  `workover doc` is the whole document surface, so signing in and then doing something with a document
43
77
  are the same tool. Bodies come from `--file`, or from stdin:
44
78
 
@@ -89,6 +123,27 @@ is how images get deleted by something that thought it was filling in a blank. I
89
123
  without that scope it is refused and `doc propose` is the way through. Every direct edit is recorded
90
124
  in the workspace's audit log, since unlike a proposal it leaves no review trail of its own.
91
125
 
126
+ ## Image file names and alt text
127
+
128
+ The editor's **Edit image** dialog, from the terminal. Each image has a file name, which becomes its
129
+ name in the WordPress media library on publish, and alt text, which screen readers read out and
130
+ search engines index.
131
+
132
+ ```sh
133
+ workover doc images 1234 # every image: number, file name, alt, src
134
+ workover doc images https://workover.io/app/acme/docs/<id> # the URL works too
135
+ workover doc image 1234 2 --name lifterlms-groups-list --alt "Groups screen listing two groups"
136
+ workover doc image 1234 3 --alt "Course settings with seats set to 10" # file name kept
137
+ ```
138
+
139
+ `<n>` is the image's number in `doc images`. Pass `--src <url>` instead to name it exactly. Whichever
140
+ of `--name` and `--alt` you leave out is kept, and the extension is kept if you leave it off.
141
+
142
+ The alt text is written onto every copy of that image in the document, in every tab, because the
143
+ document's own `<img alt>` is what publishing reads. It is a single attribute change: the rest of the
144
+ body is not rewritten. Setting either needs `workover login --write`, and the change is recorded in
145
+ the document's activity with the agent's name against it. Listing needs a normal login.
146
+
92
147
  ## Comments
93
148
 
94
149
  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
@@ -17,8 +17,9 @@ import {
17
17
  rmSync,
18
18
  } from 'fs';
19
19
  import { homedir } from 'os';
20
- import { join } from 'path';
20
+ import { dirname, join } from 'path';
21
21
  import { spawn } from 'child_process';
22
+ import { fileURLToPath } from 'url';
22
23
  import {
23
24
  normalizeApi,
24
25
  browserCommand,
@@ -31,6 +32,10 @@ import {
31
32
  contentCommitted,
32
33
  renderRulesBlock,
33
34
  threadComments,
35
+ docRef,
36
+ environmentMismatch,
37
+ imagesInHtml,
38
+ signInHelp,
34
39
  } from '../lib.mjs';
35
40
 
36
41
  /*
@@ -47,8 +52,11 @@ import {
47
52
  * https://api.workover.test for local dev).
48
53
  */
49
54
  const API = normalizeApi(process.env.WORKOVER_API || 'https://api.workover.io');
50
- const CONFIG_DIR = join(homedir(), '.workover');
51
- const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
55
+ // WORKOVER_CONFIG points the CLI at another sign-in file, so a second environment (staging, a PR
56
+ // preview) can be used without replacing the one in ~/.workover. The MCP server reads the same
57
+ // variable, so both see the same sign-in.
58
+ const CONFIG_FILE = process.env.WORKOVER_CONFIG || join(homedir(), '.workover', 'config.json');
59
+ const CONFIG_DIR = dirname(CONFIG_FILE);
52
60
 
53
61
  const saveConfig = (cfg) => {
54
62
  mkdirSync(CONFIG_DIR, { recursive: true });
@@ -127,7 +135,7 @@ const flagValue = (name) => {
127
135
  const requireSignIn = (hint) => {
128
136
  const cfg = loadConfig();
129
137
  if (!cfg?.token) {
130
- console.log(` Not signed in. Run \`${`workover login ${hint || ''}`.trim()}\`.`);
138
+ console.log(signInHelp(hint, CONFIG_FILE));
131
139
  process.exit(1);
132
140
  }
133
141
  return cfg;
@@ -227,9 +235,29 @@ async function login() {
227
235
 
228
236
  async function logout() {
229
237
  const cfg = loadConfig();
238
+ let revoked = true;
230
239
  if (cfg?.token) {
231
- // Best-effort server-side revoke (possessing the token authorizes revoking it).
232
- await post('/cli-auth/logout', { token: cfg.token }).catch(() => {});
240
+ /*
241
+ * Revoke on the api this sign-in BELONGS to, which login recorded as `cfg.api`.
242
+ *
243
+ * This used to post to WORKOVER_API, defaulting to production. So signing out of a staging or
244
+ * PR-preview sign-in (WORKOVER_CONFIG pointing at its own file, WORKOVER_API unset in the new
245
+ * shell) sent the token to production, which did not know it, and the real token stayed valid
246
+ * on the api that issued it while the local file was deleted and "Signed out." was printed.
247
+ * Possessing the token authorizes revoking it; best-effort, but no longer silent when it fails.
248
+ */
249
+ const base = cfg.api ? normalizeApi(cfg.api) : API;
250
+ revoked = await fetch(`${base}/cli-auth/logout`, {
251
+ method: 'POST',
252
+ headers: { 'content-type': 'application/json' },
253
+ body: JSON.stringify({ token: cfg.token }),
254
+ })
255
+ .then((res) => res.ok)
256
+ .catch(() => false);
257
+ if (!revoked) {
258
+ console.log(` ! Could not reach ${base} to revoke this device's token.`);
259
+ console.log(' It is removed from this computer; it stops working when it expires.');
260
+ }
233
261
  }
234
262
  if (existsSync(CONFIG_FILE)) rmSync(CONFIG_FILE);
235
263
  console.log(' Signed out.');
@@ -600,15 +628,6 @@ const readBody = async (flags) => {
600
628
  };
601
629
 
602
630
  /** A document id from the first positional argument, or a usage error naming what to pass. */
603
- const docIdArg = (positionals, usage) => {
604
- const id = rowId(positionals[0]);
605
- if (id === null) {
606
- console.log(`\n Usage: ${usage}`);
607
- console.log(' The numeric document id — `workover doc list` prints it as "#123".\n');
608
- process.exit(1);
609
- }
610
- return id;
611
- };
612
631
 
613
632
  /**
614
633
  * What the api said about house style after a write, printed to STDERR.
@@ -750,28 +769,36 @@ const DOC_USAGE = [
750
769
  ' Usage: workover doc <command>',
751
770
  '',
752
771
  ' list --project <id> [--json] documents in a project',
753
- ' tabs <docId> [--json] the document’s tabs',
754
- ' tab-new <docId> --title "<t>" add an empty tab',
772
+ ' tabs <doc> [--json] the document’s tabs',
773
+ ' tab-new <doc> --title "<t>" add an empty tab',
755
774
  ' [--parent <tabId>]',
756
- ' read <docId> [--json] [--html] a document’s current text',
775
+ ' read <doc> [--json] [--html] a document’s current text',
757
776
  ' [--tab <tabId>] one tab of it',
758
777
  ' create --project <id> --title "<t>" a new document, content written in',
759
778
  ' [--file <path> | piped stdin] [--json]',
760
- ' propose <docId> [--note "<why>"] suggest a rewrite for review',
779
+ ' propose <doc> [--note "<why>"] suggest a rewrite for review',
761
780
  ' [--file <path> | piped stdin] [--json] [--tab <tabId>]',
762
781
  ' [--why "<what was wrong>"] recorded as its reasoning',
763
- ' write <docId> [--note "<why>"] REPLACE the body, no review step',
782
+ ' write <doc> [--note "<why>"] REPLACE the body, no review step',
764
783
  ' [--file <path> | piped stdin] [--json] [--tab <tabId>]',
765
784
  ' needs `workover login --write`; use it only when asked to',
766
- ' reshoot <docId> [--replace] [--write] Workover AI retakes the screenshots',
785
+ ' reshoot <doc> [--replace] [--write] Workover AI retakes the screenshots',
767
786
  ' from the text; --replace drops the old ones; applied as',
768
787
  ' suggestions, or directly with --write. Needs `login --draft`',
769
- ' verify <docId> [--write] Workover AI checks the text against',
788
+ ' verify <doc> [--write] Workover AI checks the text against',
770
789
  ' the linked repository and corrects what it finds wrong;',
771
790
  ' applied as suggestions, or directly with --write. Needs',
772
791
  ' `login --draft`',
792
+ ' images <doc> [--tab <tabId>] [--json] the images in it: file name, alt',
793
+ ' image <doc> <n | --src <url>> set an image’s file name and/or',
794
+ ' [--name <file>] [--alt "<text>"] alt text; needs `login --write`',
795
+ ' [--tab <tabId>]',
773
796
  ' search "<query>" [--limit N] [--json] find documents by title/content',
774
- ' activity <docId> [--limit N] [--json] who changed this document, and how',
797
+ ' activity <doc> [--limit N] [--json] who changed this document, and how',
798
+ '',
799
+ ' <doc> is the document link as the browser shows it',
800
+ ' (https://workover.io/app/<workspace>/docs/<id>), the id at the end of it, or',
801
+ ' the number `doc list` prints. `get` and `edit` work as `read` and `write`.',
775
802
  '',
776
803
  ' `workover projects` lists the project ids.',
777
804
  '',
@@ -788,13 +815,165 @@ const DOC_USAGE = [
788
815
  ' lists or change bullet markers.',
789
816
  '',
790
817
  ' Tabs: a document can hold several separate bodies. read and write act on ONE',
791
- ' of them, so run `workover doc tabs <docId>` first and pass --tab; without it',
818
+ ' of them, so run `workover doc tabs <doc>` first and pass --tab; without it',
792
819
  ' you get the main body, which on a multi-tab document is not the whole thing.',
793
820
  '',
794
821
  ].join('\n');
795
822
 
823
+ /**
824
+ * The document a `<doc>` argument names, as a row id.
825
+ *
826
+ * Takes what people actually have: the URL out of the browser, the UUID in it, or the number
827
+ * `doc list` prints. A URL or UUID is resolved through `GET /project/doc/by-handle/<uuid>`, which
828
+ * applies the same access rules as reading the document by id. Every failure says what to do next,
829
+ * because an agent handed a link that "does not work" will otherwise go looking for another way in.
830
+ */
831
+ const resolveDocArg = async (cfg, positionals, usage) => {
832
+ const ref = docRef(positionals[0]);
833
+ if (!ref) {
834
+ console.log(`\n Usage: ${usage}`);
835
+ console.log(' <doc> is the document link (https://workover.io/app/<workspace>/docs/<id>),');
836
+ console.log(' the id at the end of it, or the number `workover doc list` prints ("#123").\n');
837
+ process.exit(1);
838
+ }
839
+ const mismatch = environmentMismatch(ref, cfg.api);
840
+ if (mismatch) {
841
+ console.error(`\n ✗ ${mismatch}\n`);
842
+ process.exit(1);
843
+ }
844
+ if (ref.id) return ref.id;
845
+
846
+ let res;
847
+ try {
848
+ res = await fetch(`${cfg.api}/project/doc/by-handle/${encodeURIComponent(ref.handle)}`, {
849
+ headers: { authorization: `Bearer ${cfg.token}` },
850
+ });
851
+ } catch {
852
+ console.error(`\n ✗ Couldn't reach Workover at ${cfg.api}\n`);
853
+ process.exit(1);
854
+ }
855
+ if (res.ok) {
856
+ const doc = await res.json().catch(() => null);
857
+ if (doc?.id) return doc.id;
858
+ }
859
+ const where = new URL(cfg.api).host;
860
+ const why =
861
+ res.status === 401
862
+ ? 'Your Workover sign-in has expired or was revoked. Run `workover login`.'
863
+ : res.status === 410
864
+ ? 'That document is in the Trash. Restore it in Workover first.'
865
+ : res.status === 403 || res.status === 404
866
+ ? `No document at that link that this sign-in can open (${where}). Either it does not exist, ` +
867
+ 'or this account has no access to it: ask its owner to share it, or check `workover whoami`.'
868
+ : `Workover answered ${res.status} resolving that link.`;
869
+ console.error(`\n ✗ ${why}\n`);
870
+ process.exit(1);
871
+ };
872
+
873
+ /**
874
+ * `doc images` and `doc image`: the browser's "Edit image" dialog, from a terminal.
875
+ *
876
+ * The images are read off the live body, then each one's file name comes from its media record —
877
+ * the name WordPress gets on publish, which the body itself does not carry. Setting writes through
878
+ * `PATCH /project/doc/:id/media` with `syncDoc`, so the alt lands on the image nodes in the live
879
+ * document (where publishing reads it) and not only on the record.
880
+ */
881
+ async function imagesCommand(cfg, sub, positionals, flags, tabId, asJson) {
882
+ const usage =
883
+ sub === 'images'
884
+ ? 'workover doc images <doc> [--tab <tabId>]'
885
+ : 'workover doc image <doc> <n | --src <url>> [--name <file>] [--alt "<text>"]';
886
+ const docId = await resolveDocArg(cfg, positionals, usage);
887
+ const tabQuery = tabId === null ? '' : `?tabId=${tabId}`;
888
+
889
+ const list = async () => {
890
+ const live = await authedCall(cfg, `/project/doc/${docId}/content${tabQuery}`);
891
+ const images = imagesInHtml(live?.html || '');
892
+ for (const img of images) {
893
+ const meta = await authedCall(
894
+ cfg,
895
+ `/project/doc/${docId}/media/meta?src=${encodeURIComponent(img.src)}`,
896
+ );
897
+ img.filename = meta?.filename || '';
898
+ }
899
+ return { images, live };
900
+ };
901
+
902
+ if (sub === 'images') {
903
+ const { images, live } = await list();
904
+ if (asJson) return console.log(JSON.stringify(images, null, 2));
905
+ if (!images.length) {
906
+ console.log(`\n No images in ${live?.tab ? `the "${live.tab.title}" tab of ` : ''}document #${docId}.\n`);
907
+ return;
908
+ }
909
+ console.log('');
910
+ for (const img of images) {
911
+ console.log(` ${String(img.index).padStart(2)}. ${img.filename}${img.count > 1 ? ` (appears ${img.count}×)` : ''}`);
912
+ console.log(` alt: ${img.alt ? img.alt : '\x1b[33m(none)\x1b[0m'}`);
913
+ console.log(` ${img.src}`);
914
+ }
915
+ const missing = images.filter((i) => !i.alt).length;
916
+ console.log(
917
+ `\n ${images.length} image${images.length === 1 ? '' : 's'}${missing ? `, ${missing} without alt text` : ''}.`,
918
+ );
919
+ console.log(` Set one: workover doc image ${docId} <n> --name <file> --alt "<text>"\n`);
920
+ if (Array.isArray(live?.tabs) && live.tabs.length) {
921
+ console.error(` ── ${live.tabs.length} tabs; this was "${live?.tab?.title || 'the main body'}". Pass --tab <id> for another.\n`);
922
+ }
923
+ return;
924
+ }
925
+
926
+ const name = typeof flags.name === 'string' ? flags.name : undefined;
927
+ const alt = typeof flags.alt === 'string' ? flags.alt : undefined;
928
+ if (name === undefined && alt === undefined) {
929
+ console.log(`\n Usage: ${usage}`);
930
+ console.log(' Pass --name, --alt or both; whichever you leave out is kept.\n');
931
+ process.exit(1);
932
+ }
933
+
934
+ // Which image: an explicit --src, or its number in `doc images` (same tab).
935
+ let src = typeof flags.src === 'string' ? flags.src : null;
936
+ if (!src) {
937
+ const n = rowId(positionals[1]);
938
+ const { images } = await list();
939
+ const hit = n === null ? null : images.find((i) => i.index === n);
940
+ if (!hit) {
941
+ console.log(`\n Usage: ${usage}`);
942
+ console.log(
943
+ ` <n> is the image's number in \`workover doc images ${docId}\` (1–${images.length || 0}).\n`,
944
+ );
945
+ process.exit(1);
946
+ }
947
+ src = hit.src;
948
+ }
949
+
950
+ const res = await authedCall(
951
+ cfg,
952
+ `/project/doc/${docId}/media`,
953
+ {
954
+ src,
955
+ ...(name !== undefined ? { filename: name } : {}),
956
+ ...(alt !== undefined ? { alt } : {}),
957
+ syncDoc: true,
958
+ },
959
+ { method: 'PATCH' },
960
+ );
961
+ if (asJson) return console.log(JSON.stringify(res, null, 2));
962
+ console.log(`\n \x1b[32m✓\x1b[0m ${res?.filename}`);
963
+ console.log(` alt: ${res?.alt || '(none)'}`);
964
+ if (alt !== undefined && typeof res?.updatedInDoc === 'number') {
965
+ console.log(
966
+ res.updatedInDoc
967
+ ? ` Alt text set on ${res.updatedInDoc} image${res.updatedInDoc === 1 ? '' : 's'} in the document.`
968
+ : ' The alt text was already that in the document.',
969
+ );
970
+ }
971
+ console.log(' The file name is what WordPress gets on the next publish.\n');
972
+ }
973
+
796
974
  async function docCommand() {
797
- const sub = process.argv[3];
975
+ // `get` and `edit` are what people (and agents) guess first; they are `read` and `write`.
976
+ const sub = { get: 'read', edit: 'write' }[process.argv[3]] || process.argv[3];
798
977
  // Usage before sign-in: someone who typed the command wrong is asking what the commands are, and
799
978
  // answering "not signed in" sends them to fix the wrong thing.
800
979
  if (
@@ -810,6 +989,8 @@ async function docCommand() {
810
989
  'activity',
811
990
  'reshoot',
812
991
  'verify',
992
+ 'images',
993
+ 'image',
813
994
  ].includes(sub)
814
995
  ) {
815
996
  console.log(DOC_USAGE);
@@ -825,7 +1006,7 @@ async function docCommand() {
825
1006
  // what every one of these commands meant before tabs were addressable.
826
1007
  const tabId = flags.tab == null ? null : rowId(flags.tab);
827
1008
  if (flags.tab != null && tabId === null) {
828
- console.log(`\n ✗ --tab must be a tab id. List them: workover doc tabs <docId>\n`);
1009
+ console.log(`\n ✗ --tab must be a tab id. List them: workover doc tabs <doc>\n`);
829
1010
  process.exit(1);
830
1011
  }
831
1012
 
@@ -840,7 +1021,7 @@ async function docCommand() {
840
1021
  };
841
1022
 
842
1023
  if (sub === 'tabs') {
843
- const docId = docIdArg(positionals, 'workover doc tabs <docId>');
1024
+ const docId = await resolveDocArg(cfg, positionals, 'workover doc tabs <doc>');
844
1025
  const tabs = (await authedCall(cfg, `/project/doc/${docId}/tabs`)) || [];
845
1026
  if (asJson) return console.log(JSON.stringify(tabs, null, 2));
846
1027
  if (!tabs.length) {
@@ -866,8 +1047,8 @@ async function docCommand() {
866
1047
  }
867
1048
 
868
1049
  if (sub === 'tab-new') {
869
- const usage = 'workover doc tab-new <docId> --title "<title>" [--parent <tabId>]';
870
- const docId = docIdArg(positionals, usage);
1050
+ const usage = 'workover doc tab-new <doc> --title "<title>" [--parent <tabId>]';
1051
+ const docId = await resolveDocArg(cfg, positionals, usage);
871
1052
  const title = typeof flags.title === 'string' ? flags.title.trim() : '';
872
1053
  if (!title) {
873
1054
  console.log(`\n Usage: ${usage}\n`);
@@ -892,6 +1073,10 @@ async function docCommand() {
892
1073
  return;
893
1074
  }
894
1075
 
1076
+ if (sub === 'images' || sub === 'image') {
1077
+ return imagesCommand(cfg, sub, positionals, flags, tabId, asJson);
1078
+ }
1079
+
895
1080
  if (sub === 'list') {
896
1081
  const projectId = projectIdFlag('workover doc list --project <id>');
897
1082
  const all = (await authedCall(cfg, `/project/${projectId}/documents`)) || [];
@@ -909,7 +1094,7 @@ async function docCommand() {
909
1094
  }
910
1095
 
911
1096
  if (sub === 'read') {
912
- const docId = docIdArg(positionals, 'workover doc read <docId>');
1097
+ const docId = await resolveDocArg(cfg, positionals, 'workover doc read <doc>');
913
1098
  const doc = await authedCall(cfg, `/project/doc/${docId}`);
914
1099
  if (!doc?.id) {
915
1100
  console.error(`\n ✗ Document ${docId} not found (or no access).\n`);
@@ -1030,8 +1215,8 @@ async function docCommand() {
1030
1215
 
1031
1216
  if (sub === 'propose') {
1032
1217
  const usage =
1033
- 'workover doc propose <docId> --file <path> [--note "<summary>"] [--why "<what was wrong>"]';
1034
- const docId = docIdArg(positionals, usage);
1218
+ 'workover doc propose <doc> --file <path> [--note "<summary>"] [--why "<what was wrong>"]';
1219
+ const docId = await resolveDocArg(cfg, positionals, usage);
1035
1220
  const markdown = (await readBody(flags)).trim();
1036
1221
  if (!markdown) {
1037
1222
  console.log(`\n Usage: ${usage}`);
@@ -1063,8 +1248,8 @@ async function docCommand() {
1063
1248
  }
1064
1249
 
1065
1250
  if (sub === 'write') {
1066
- const usage = 'workover doc write <docId> --file <path> [--note "<why>"]';
1067
- const docId = docIdArg(positionals, usage);
1251
+ const usage = 'workover doc write <doc> --file <path> [--note "<why>"]';
1252
+ const docId = await resolveDocArg(cfg, positionals, usage);
1068
1253
  const markdown = (await readBody(flags)).trim();
1069
1254
  if (!markdown) {
1070
1255
  console.log(`\n Usage: ${usage}`);
@@ -1097,9 +1282,10 @@ async function docCommand() {
1097
1282
  // Workover AI plans and captures this document's screenshots from its current text, signed in
1098
1283
  // to the workspace's connected app with the stored credential (which never reaches this
1099
1284
  // machine). Needs `draft`. The result is applied as suggestions, or written with --write.
1100
- const docId = docIdArg(
1285
+ const docId = await resolveDocArg(
1286
+ cfg,
1101
1287
  positionals,
1102
- 'workover doc reshoot <docId> [--replace] [--write] [--note "<why>"]',
1288
+ 'workover doc reshoot <doc> [--replace] [--write] [--note "<why>"]',
1103
1289
  );
1104
1290
  const res = await authedCall(cfg, `/ai/documents/${docId}/screenshots`, {
1105
1291
  replace: flags.replace === true,
@@ -1142,7 +1328,7 @@ async function docCommand() {
1142
1328
  // Workover AI reads the project's linked repository and corrects what the document gets wrong.
1143
1329
  // Nothing is passed in but the id: the corrections have to come from the source, not from us.
1144
1330
  // The result is applied as suggestions (or written with --write), like `reshoot`.
1145
- const docId = docIdArg(positionals, 'workover doc verify <docId> [--write] [--note "<why>"]');
1331
+ const docId = await resolveDocArg(cfg, positionals, 'workover doc verify <doc> [--write] [--note "<why>"]');
1146
1332
  // Started in the background and polled: the check reads the repository for minutes, and a
1147
1333
  // single request is cut at 100 seconds by Cloudflare (a 524 whose answer never arrives).
1148
1334
  let state = await authedCall(cfg, `/ai/documents/${docId}/verify`, {
@@ -1199,7 +1385,7 @@ async function docCommand() {
1199
1385
  }
1200
1386
 
1201
1387
  if (sub === 'activity') {
1202
- const docId = docIdArg(positionals, 'workover doc activity <docId>');
1388
+ const docId = await resolveDocArg(cfg, positionals, 'workover doc activity <doc>');
1203
1389
  const limit = rowId(flags.limit) ?? 20;
1204
1390
  const rows = (await authedCall(cfg, `/project/doc/${docId}/activity`)) || [];
1205
1391
  const shown = rows.slice(0, limit);
@@ -1251,16 +1437,16 @@ const COMMENTS_USAGE = [
1251
1437
  '',
1252
1438
  ' Usage: workover comments <command>',
1253
1439
  '',
1254
- ' list <docId> [--all] [--json] the feedback on a document,',
1440
+ ' list <doc> [--all] [--json] the feedback on a document,',
1255
1441
  ' open threads only unless --all',
1256
- ' add <docId> "<text>" leave a comment',
1442
+ ' add <doc> "<text>" leave a comment',
1257
1443
  ' [--to <commentId>] ...as a reply in that thread',
1258
1444
  ' [--quote "<text>"] ...against the passage it is about',
1259
1445
  ' resolve <commentId> [--json] mark a thread dealt with',
1260
1446
  ' reopen <commentId> [--json] put it back',
1261
1447
  '',
1262
1448
  ' Resolve the thread you actually answered, and say what you did first —',
1263
- ' `comments add <docId> --to <commentId> "..."` then `comments resolve`. A',
1449
+ ' `comments add <doc> --to <commentId> "..."` then `comments resolve`. A',
1264
1450
  ' thread that closes with no reply tells the person who raised it nothing,',
1265
1451
  ' and reopening is the only way back.',
1266
1452
  '',
@@ -1313,7 +1499,7 @@ async function commentsCommand() {
1313
1499
  const commentId = rowId(positionals[0]);
1314
1500
  if (commentId === null) {
1315
1501
  console.log(`\n Usage: workover comments ${sub} <commentId>`);
1316
- console.log(' The comment id — `workover comments list <docId>` prints it.\n');
1502
+ console.log(' The comment id — `workover comments list <doc>` prints it.\n');
1317
1503
  process.exit(1);
1318
1504
  }
1319
1505
  const res = await authedCall(
@@ -1343,8 +1529,8 @@ async function commentsCommand() {
1343
1529
  }
1344
1530
 
1345
1531
  if (sub === 'add') {
1346
- const usage = 'workover comments add <docId> "<text>" [--to <commentId>]';
1347
- const docId = docIdArg(positionals, usage);
1532
+ const usage = 'workover comments add <doc> "<text>" [--to <commentId>]';
1533
+ const docId = await resolveDocArg(cfg, positionals, usage);
1348
1534
  // The text is everything after the document id, so an unquoted sentence still arrives whole.
1349
1535
  let body = positionals.slice(1).join(' ').trim();
1350
1536
  // `--file` only when asked for. `doc` reads piped stdin without being told, which is right for
@@ -1358,7 +1544,7 @@ async function commentsCommand() {
1358
1544
  }
1359
1545
  const parentId = flags.to == null ? null : rowId(flags.to);
1360
1546
  if (flags.to != null && parentId === null) {
1361
- console.log('\n ✗ --to must be a comment id. List them: workover comments list <docId>\n');
1547
+ console.log('\n ✗ --to must be a comment id. List them: workover comments list <doc>\n');
1362
1548
  process.exit(1);
1363
1549
  }
1364
1550
  const created = await authedCall(cfg, `/project/doc/${docId}/comments`, {
@@ -1376,7 +1562,7 @@ async function commentsCommand() {
1376
1562
  }
1377
1563
 
1378
1564
  // list
1379
- const docId = docIdArg(positionals, 'workover comments list <docId>');
1565
+ const docId = await resolveDocArg(cfg, positionals, 'workover comments list <doc>');
1380
1566
  const rows = (await authedCall(cfg, `/project/doc/${docId}/comments`)) || [];
1381
1567
  const all = threadComments(rows, { includeResolved: true });
1382
1568
  const threads = flags.all === true ? all : all.filter((t) => !t.resolved);
@@ -1436,6 +1622,31 @@ async function projects() {
1436
1622
  console.log('');
1437
1623
  }
1438
1624
 
1625
+ /**
1626
+ * Teach Claude Code to use Workover: install the `workover` skill into ~/.claude/skills.
1627
+ *
1628
+ * A skill is listed to Claude Code in every session by its description, so a pasted
1629
+ * workover.io/app/.../docs/... link matches it and the agent reaches for these commands instead of
1630
+ * writing its own client around the token file (which is what happened on 2026-10-16, in a project
1631
+ * where the MCP server was not registered and this CLI was not installed).
1632
+ *
1633
+ * The MCP server is a separate, optional step, printed rather than run: registering it changes the
1634
+ * user's Claude Code configuration, and they should see the command that does that.
1635
+ */
1636
+ function installClaude() {
1637
+ const root = process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude');
1638
+ const target = join(root, 'skills', 'workover', 'SKILL.md');
1639
+ const source = join(dirname(fileURLToPath(import.meta.url)), '..', 'skill', 'SKILL.md');
1640
+ mkdirSync(dirname(target), { recursive: true });
1641
+ writeFileSync(target, readFileSync(source, 'utf8'));
1642
+ console.log(`\n \x1b[32m✓\x1b[0m Installed the Workover skill for Claude Code: ${target}`);
1643
+ console.log(' New Claude Code sessions will open a pasted Workover link with `workover doc get`.');
1644
+ console.log('\n Optional, to give Claude Code the Workover tools directly (all projects):');
1645
+ console.log(' claude mcp add --scope user workover -- npx -y @workover/mcp@latest');
1646
+ if (!loadConfig()?.token) console.log('\n You are not signed in yet: run `workover login`.');
1647
+ console.log('');
1648
+ }
1649
+
1439
1650
  const cmd = process.argv[2];
1440
1651
  if (cmd === 'login') await login();
1441
1652
  else if (cmd === 'logout') await logout();
@@ -1447,6 +1658,7 @@ else if (cmd === 'doc') await docCommand();
1447
1658
  else if (cmd === 'rules') await rulesCommand();
1448
1659
  else if (cmd === 'comments') await commentsCommand();
1449
1660
  else if (cmd === 'projects') await projects();
1661
+ else if (cmd === 'install-claude') installClaude();
1450
1662
  else {
1451
1663
  console.log('\n Workover CLI\n');
1452
1664
  console.log(' Usage: workover <command>\n');
@@ -1459,8 +1671,11 @@ else {
1459
1671
  console.log(' doc Work on documents: list, read, create, propose, write, search');
1460
1672
  console.log(' plus activity, to see who changed one and how');
1461
1673
  console.log(' plus tabs and tab-new for documents with several bodies');
1674
+ console.log(' plus images and image, for image file names and alt text');
1462
1675
  console.log(' workover doc create --project 11 --title "Billing" --file b.md');
1463
- console.log(' workover doc read 123 · workover doc propose 123 --file new.md');
1676
+ console.log(' <doc> is the link from the browser, its UUID, or the number');
1677
+ console.log(' workover doc get https://workover.io/app/acme/docs/<id>');
1678
+ console.log(' workover doc propose <doc> --file new.md · doc edit <doc> --file new.md');
1464
1679
  console.log(' comments Read, answer and resolve feedback on a document');
1465
1680
  console.log(' workover comments list 123 · workover comments resolve 45');
1466
1681
  console.log(' rules The style guide agents should write by: list, export, add');
@@ -1472,5 +1687,6 @@ else {
1472
1687
  console.log(' eval Score a project’s documentation against the editorial rubric');
1473
1688
  console.log(' --org <id> --project <id> [--limit N] [--json]');
1474
1689
  console.log(' logout Sign out and revoke this device’s token');
1475
- console.log(' whoami Show the current sign-in\n');
1690
+ console.log(' whoami Show the current sign-in');
1691
+ console.log(' install-claude Teach Claude Code to open Workover links (installs a skill)\n');
1476
1692
  }
package/lib.mjs CHANGED
@@ -271,3 +271,155 @@ 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
+ const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
276
+ const FULL_UUID_RE = new RegExp(`^${UUID_RE.source}$`, 'i');
277
+
278
+ /**
279
+ * Which document somebody meant, from whatever they pasted.
280
+ *
281
+ * 1234 / #1234 → { id: 1234 }
282
+ * https://workover.io/app/pellio/docs/<uuid> → { handle, host, workspace }
283
+ * …/docs/<uuid>/anything?tab=3#heading, workover.dev, → the same, with that host
284
+ * a preview host, or no scheme at all
285
+ * https://workover.io/app/projects/1234 → { id: 1234, host } (the old editor URL)
286
+ * <uuid> on its own → { handle }
287
+ *
288
+ * Returns null for anything else. The URL is what people paste because it is what the browser shows
289
+ * them, and on 2026-10-16 an agent handed one went digging through the source to turn it into a row
290
+ * id. Every command that names a document takes all of these, so nobody has to.
291
+ *
292
+ * `host` is kept so a link to one environment opened with a sign-in for another can be named as
293
+ * that, rather than reported as a missing document (see `environmentMismatch`).
294
+ */
295
+ export const docRef = (value) => {
296
+ // Trim the wrapping that pasted links arrive in: <angle brackets>, quotes, a trailing full stop.
297
+ const s = String(value ?? '')
298
+ .trim()
299
+ .replace(/^[<"'([]+/, '')
300
+ .replace(/[>"')\].,;]+$/, '');
301
+ if (!s) return null;
302
+ const id = rowId(s);
303
+ if (id !== null) return { id };
304
+ if (FULL_UUID_RE.test(s)) return { handle: s.toLowerCase() };
305
+
306
+ const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(s);
307
+ if (hasScheme || /^[a-z0-9-]+(\.[a-z0-9-]+)+(:\d+)?\//i.test(s)) {
308
+ let url;
309
+ try {
310
+ url = new URL(hasScheme ? s : `https://${s}`);
311
+ } catch {
312
+ return null;
313
+ }
314
+ const host = url.hostname.toLowerCase();
315
+ const segs = url.pathname.split('/').filter(Boolean);
316
+ const at = segs.findIndex((seg) => FULL_UUID_RE.test(seg));
317
+ if (at !== -1) {
318
+ // /app/<workspace>/docs/<uuid>: the canonical document URL.
319
+ const workspace =
320
+ segs[0] === 'app' && segs[2] === 'docs' && at === 3 ? decodeURIComponent(segs[1]) : null;
321
+ return { handle: segs[at].toLowerCase(), host, ...(workspace ? { workspace } : {}) };
322
+ }
323
+ // /app/projects/<id>: the numeric editor route, kept for old links and bookmarks.
324
+ if (segs[0] === 'app' && segs[1] === 'projects' && rowId(segs[2] ?? '') !== null) {
325
+ return { id: rowId(segs[2]), host };
326
+ }
327
+ return null;
328
+ }
329
+
330
+ // Free text with a handle in it ("the doc 7cd7…"): take the handle.
331
+ const m = UUID_RE.exec(s);
332
+ return m ? { handle: m[0].toLowerCase() } : null;
333
+ };
334
+
335
+ /** The web host each known API serves, for telling a user which environment a link belongs to. */
336
+ const WEB_FOR_API = {
337
+ 'api.workover.io': 'workover.io',
338
+ 'api.workover.dev': 'workover.dev',
339
+ 'api.workover.test': 'workover.test',
340
+ };
341
+
342
+ /**
343
+ * A sentence when a document link is for a different Workover than the one signed in to, else null.
344
+ *
345
+ * Only for hosts we know. A preview deploy's web and api hosts are not related by name, so they are
346
+ * left alone rather than guessed at — a wrong warning here would send someone to sign in somewhere
347
+ * they did not need to.
348
+ */
349
+ export const environmentMismatch = (ref, api) => {
350
+ if (!ref?.host || !api) return null;
351
+ let apiHost;
352
+ try {
353
+ apiHost = new URL(String(api)).hostname.toLowerCase();
354
+ } catch {
355
+ return null;
356
+ }
357
+ const signedInWeb = WEB_FOR_API[apiHost];
358
+ const linkHost = ref.host.replace(/^www\./, '');
359
+ const linkApi = Object.keys(WEB_FOR_API).find((k) => WEB_FOR_API[k] === linkHost);
360
+ if (!signedInWeb || !linkApi || signedInWeb === linkHost) return null;
361
+ return (
362
+ `That link is to ${linkHost}, but you are signed in to ${apiHost}. ` +
363
+ `Sign in there first (it replaces your current sign-in): WORKOVER_API=https://${linkApi} workover login`
364
+ );
365
+ };
366
+
367
+ const decodeAttr = (v) =>
368
+ String(v ?? '')
369
+ .replace(/&quot;/g, '"')
370
+ .replace(/&#39;/g, "'")
371
+ .replace(/&lt;/g, '<')
372
+ .replace(/&gt;/g, '>')
373
+ // &amp; last, for the same reason as in stripHtml.
374
+ .replace(/&amp;/g, '&');
375
+
376
+ const attrOf = (tag, name) => {
377
+ const m = new RegExp(`\\s${name}\\s*=\\s*("([^"]*)"|'([^']*)')`, 'i').exec(tag);
378
+ return m ? decodeAttr(m[2] ?? m[3]) : null;
379
+ };
380
+
381
+ /**
382
+ * The images in a document body, in reading order, one entry per distinct `src`.
383
+ *
384
+ * Read off the HTML the live room renders rather than the markdown, because the HTML carries the
385
+ * node's own `src` byte for byte, and that src is how the api identifies an image. `count` says how
386
+ * many times it appears: setting alt on one sets it on every copy, and saying so beats surprising
387
+ * someone with a change in a paragraph they were not looking at.
388
+ */
389
+ export const imagesInHtml = (html) => {
390
+ const out = [];
391
+ const bySrc = new Map();
392
+ for (const m of String(html || '').matchAll(/<img\b[^>]*>/gi)) {
393
+ const src = attrOf(m[0], 'src');
394
+ if (!src) continue;
395
+ const seen = bySrc.get(src);
396
+ if (seen) {
397
+ seen.count += 1;
398
+ continue;
399
+ }
400
+ const entry = { index: out.length + 1, src, alt: attrOf(m[0], 'alt') || '', count: 1 };
401
+ bySrc.set(src, entry);
402
+ out.push(entry);
403
+ }
404
+ return out;
405
+ };
406
+
407
+ /**
408
+ * What to do when there is no sign-in, as printed lines.
409
+ *
410
+ * Spelled out because the reader is often an agent, and an agent told only "not signed in" goes
411
+ * looking for a token somewhere else. Signing in needs a person to approve it in a browser, so the
412
+ * agent's next move is to ask for that, and the text says so.
413
+ */
414
+ export const signInHelp = (hint, configFile) =>
415
+ [
416
+ '',
417
+ ' Not signed in to Workover.',
418
+ '',
419
+ ` Run \`${`workover login ${hint || ''}`.trim()}\`. It opens a browser where a person approves`,
420
+ ' this machine, so an agent should ask its user to run it rather than look for a token.',
421
+ ' Add --write to allow editing documents directly (without it, changes are proposed).',
422
+ ' Staging instead of production: WORKOVER_API=https://api.workover.dev workover login',
423
+ ...(configFile ? [` The sign-in is saved to ${configFile}.`] : []),
424
+ '',
425
+ ].join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workover/cli",
3
- "version": "0.12.1",
3
+ "version": "0.14.1",
4
4
  "description": "Workover command line — sign in and cowork on your documents from the terminal.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "ScaleMath",
@@ -22,6 +22,7 @@
22
22
  "files": [
23
23
  "bin/",
24
24
  "lib.mjs",
25
+ "skill/",
25
26
  "README.md"
26
27
  ],
27
28
  "engines": {
package/skill/SKILL.md ADDED
@@ -0,0 +1,64 @@
1
+ ---
2
+ name: workover
3
+ description: Read, edit, comment on or propose changes to a Workover document. Use whenever the user pastes a Workover doc link (workover.io/app/<workspace>/docs/<id>, workover.dev/app/..., a Workover PR preview link), a Workover document UUID or id, or asks to work on "my Workover doc". Covers reading the doc, writing it, proposing edits, tabs, comments and the team style guide, through the Workover MCP tools or the `workover` CLI.
4
+ ---
5
+
6
+ # Working on a Workover document
7
+
8
+ A Workover link such as `https://workover.io/app/pellio/docs/7cd7e9ec-28af-4a2a-bb7c-668548380a08`
9
+ IS the document reference. Pass it as it is. The tools take a full link, the UUID at the end of
10
+ it, or the numeric id, and resolve it themselves.
11
+
12
+ **Do not** read `~/.workover/config.json`, call the Workover REST API with curl or a script, or
13
+ search the Workover source code for routes. The tools below already do all of that, with the
14
+ right access checks and error messages.
15
+
16
+ ## 1. Use the Workover MCP tools when they are loaded
17
+
18
+ If tools named `workover_*` are available:
19
+
20
+ - Read: `workover_read_doc` with `docId` set to the link. The result includes the style guide.
21
+ - Tabs: `workover_list_tabs`. Reading or editing acts on ONE tab, so check before editing.
22
+ - Propose a change (the default): `workover_propose_edit` with the FULL revised markdown.
23
+ - Edit directly (only when the user asked for the change to be made): `workover_edit_doc`.
24
+ - Comments are CLI-only for now; see below.
25
+
26
+ ## 2. Otherwise use the `workover` CLI
27
+
28
+ Run `workover` if it is on PATH. If it is not, run `npx -y @workover/cli@latest` instead (same
29
+ commands).
30
+
31
+ ```sh
32
+ workover doc get <link> # the body as markdown; title + tabs go to stderr
33
+ workover doc tabs <link> # the tabs, if any
34
+ workover doc propose <link> --file new.md --note "what changed" # suggestions to accept
35
+ workover doc edit <link> --file new.md --note "what changed" # replace the body now
36
+ workover comments list <link> # open comment threads
37
+ workover comments add <link> "reply" --to <commentId>
38
+ workover doc search "query" # find a doc when you have no link
39
+ ```
40
+
41
+ `get` / `edit` are the same as `read` / `write`. Add `--tab <tabId>` to read or write one tab.
42
+
43
+ ## Editing rules
44
+
45
+ - Read the document first. `propose` and `edit` take the COMPLETE document and replace the
46
+ body of one tab, so anything left out is deleted.
47
+ - The title is the H1. Start the body at `##` and never add a `#` heading.
48
+ - Change only what you mean to. Do not reflow paragraphs or renumber lists. Tables come back as
49
+ HTML; edit inside the cells.
50
+ - `propose` is the default. Use `edit` (or `workover_edit_doc`) only when the user asked for the
51
+ change to be made, and it needs a sign-in made with `workover login --write`.
52
+ - Follow the style guide that comes back with the read.
53
+
54
+ ## When something fails
55
+
56
+ - **Not signed in**: signing in needs a person to approve it in a browser. Ask the user to run
57
+ `workover login` (`workover login --write` to allow direct edits). Do not look for a token.
58
+ - **"That link is to workover.dev, but you are signed in to api.workover.io"**: the link is for a
59
+ different environment. Tell the user and give them the command the error prints.
60
+ - **"No document at that link that this sign-in can open"**: it does not exist, or this account
61
+ has no access. Ask the user to check the link or to get the document shared. Do not try other
62
+ routes.
63
+ - **A permission error mentioning `--write`**: propose instead, or ask the user to sign in again
64
+ with `workover login --write`.