@workover/cli 0.15.0 → 0.26.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,9 @@
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), `rules`, `comments`, `draft`, `draft-set`, `eval`.
4
+ // (list/read/create/propose/write/search/tabs/images/image/status), `rules`, `comments`, `draft`, `draft-set`, `eval`,
5
+ // and on hosted Help Centers: `project create` and `site` (create/import/domain/check/publish/status),
6
+ // which need `login --site`.
5
7
  //
6
8
  // This header used to say "auth only for now", left over from the first version and never updated
7
9
  // as the commands landed. On 2026-09-09 an agent read it, concluded the CLI could not edit
@@ -40,7 +42,71 @@ import {
40
42
  signInHelp,
41
43
  jsonObjectFlag,
42
44
  vetImageUpload,
45
+ renderStatusList,
46
+ renderStatusChange,
47
+ statusRefusal,
48
+ renderRename,
49
+ renameRefusal,
50
+ canOpenBrowser,
51
+ pendingLogin,
52
+ pendingLoginState,
53
+ renderSignedIn,
54
+ renderWhoami,
55
+ signedInJson,
56
+ renderProjects,
57
+ renderSetupStatus,
58
+ webForApi,
59
+ mdxHelpLines,
43
60
  } from '../lib.mjs';
61
+ import {
62
+ SITE_LOGIN,
63
+ apiError,
64
+ scopeHelp,
65
+ createProject,
66
+ createSite,
67
+ setDomain,
68
+ checkSite,
69
+ importSite,
70
+ publishSite,
71
+ siteStatus,
72
+ setIndexing,
73
+ waitForJob,
74
+ renderProjectCreated,
75
+ renderSiteCreated,
76
+ renderDomain,
77
+ renderMoved,
78
+ renderCheck,
79
+ renderImport,
80
+ renderPublish,
81
+ renderSiteStatus,
82
+ renderIndexing,
83
+ importProgressLine,
84
+ publishProgressLine,
85
+ MOUNT_PLATFORMS,
86
+ detectPlatform,
87
+ proxyRecipe,
88
+ renderRecipe,
89
+ unpublishSite,
90
+ renderUnpublish,
91
+ } from '../site-setup.mjs';
92
+ import { writeRecipe } from '../site-proxy.mjs';
93
+ import { renderFeedbackResult, submitFeedback } from '../feedback.mjs';
94
+ import {
95
+ addApiReference,
96
+ addRedirects,
97
+ importFolder,
98
+ listApiReferences,
99
+ removeApiReference,
100
+ pageCount,
101
+ readDocsFolder,
102
+ syncApiReferences,
103
+ renderAppearance,
104
+ renderFolderImport,
105
+ renderApiReferences,
106
+ renderRedirects,
107
+ setAppearance,
108
+ uploadWith,
109
+ } from '../site-folder.mjs';
44
110
 
45
111
  /*
46
112
  * PRODUCTION is the default, because this package is published to npm and everyone who installs it
@@ -60,6 +126,8 @@ const API = normalizeApi(process.env.WORKOVER_API || 'https://api.workover.io');
60
126
  // preview) can be used without replacing the one in ~/.workover. The MCP server reads the same
61
127
  // variable, so both see the same sign-in.
62
128
  const CONFIG_FILE = process.env.WORKOVER_CONFIG || join(homedir(), '.workover', 'config.json');
129
+ // A sign-in `login --no-wait` started and `login --resume` finishes, beside the sign-in it becomes.
130
+ const PENDING_FILE = `${CONFIG_FILE}.pending`;
63
131
 
64
132
  // Owner read/write only, from the first byte — it holds a bearer token (see writePrivateFile).
65
133
  const saveConfig = (cfg) => writePrivateFile(CONFIG_FILE, JSON.stringify(cfg, null, 2));
@@ -146,6 +214,7 @@ const requireSignIn = (hint) => {
146
214
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
147
215
 
148
216
  async function login() {
217
+ if (process.argv.includes('--resume')) return resumeLogin();
149
218
  // `--publish` and `--draft` ask for scopes beyond the default. Off unless asked: a login that
150
219
  // silently granted them would defeat the point of asking.
151
220
  const scopes = ['read', 'propose'];
@@ -153,6 +222,9 @@ async function login() {
153
222
  if (process.argv.includes('--draft')) scopes.push('draft');
154
223
  if (process.argv.includes('--write')) scopes.push('write');
155
224
  if (process.argv.includes('--rules')) scopes.push('rules');
225
+ if (process.argv.includes('--site')) scopes.push('site');
226
+ // `--no-wait --json` prints the JSON and nothing else, so an agent can parse what it gets.
227
+ const jsonOnly = process.argv.includes('--no-wait') && process.argv.includes('--json');
156
228
 
157
229
  // WHAT IS SIGNING IN, sent so the token can be NAMED it.
158
230
  //
@@ -177,41 +249,127 @@ async function login() {
177
249
  process.exit(1);
178
250
  }
179
251
 
180
- if (scopes.includes('publish')) {
181
- console.log('\n Requesting permission to PUBLISH to your connected WordPress sites.');
252
+ if (scopes.includes('publish') && !jsonOnly) {
253
+ console.log('\n Requesting permission to PUBLISH to your connected WordPress sites, and to mark');
254
+ console.log(' documents Published (or move them out of Published) in Workover.');
182
255
  }
183
- if (scopes.includes('draft')) {
256
+ if (scopes.includes('draft') && !jsonOnly) {
184
257
  console.log('\n Requesting permission to WRITE DRAFTS with AI. This spends AI credits, and a');
185
258
  console.log(' repo-grounded draft also captures screenshots by signing in to your connected');
186
259
  console.log(' app with the credential you stored in Workover.');
187
260
  }
188
- if (scopes.includes('write')) {
261
+ if (scopes.includes('write') && !jsonOnly) {
189
262
  console.log('\n Requesting permission to EDIT DOCUMENTS DIRECTLY — `workover doc write`');
190
263
  console.log(' replaces a document’s body with no suggestions to accept. Without it every');
191
264
  console.log(' change is a proposal you review, which is the default and stays available.');
192
265
  }
193
- if (scopes.includes('rules')) {
266
+ if (scopes.includes('rules') && !jsonOnly) {
194
267
  console.log('\n Requesting permission to CHANGE YOUR STYLE GUIDE. A rule steers every future');
195
268
  console.log(' draft and review for everyone in the workspace until somebody turns it off.');
196
269
  console.log(' Reading the guide never needs this — only adding to or changing it does.');
197
270
  }
198
- console.log(`\n Signing in as: ${client}`);
199
- console.log(`\n Your login code: \x1b[1m${start.user_code}\x1b[0m`);
200
- console.log(` Approve it here: ${start.verification_uri_complete}\n`);
201
- console.log(' Opening your browser…');
202
- openBrowser(start.verification_uri_complete);
271
+ if (scopes.includes('site') && !jsonOnly) {
272
+ console.log('\n Requesting permission to SET UP AND PUBLISH YOUR HELP CENTER: create a project with');
273
+ console.log(' a Workover Help Center, import docs into it, connect its custom domain, and');
274
+ console.log(' publish it live. Billing and payment stay in the browser.');
275
+ }
276
+ const pending = pendingLogin(start, { api: API, scopes, client });
277
+ if (!jsonOnly) {
278
+ console.log(`\n Signing in as: ${client}`);
279
+ console.log(`\n Your login code: \x1b[1m${start.user_code}\x1b[0m`);
280
+ console.log(` Approve it here: ${start.verification_uri_complete}\n`);
281
+ }
282
+
283
+ /*
284
+ * `--no-wait`: print the code and the link, save the sign-in, and exit at once.
285
+ *
286
+ * The poll below waits up to ten minutes for the person, and an agent's shell gives up long before
287
+ * (two minutes by default in Claude Code), which killed the sign-in on 2026-11-14 (WO-1284). With
288
+ * this an agent hands the person the link, and `workover login --resume` finishes it.
289
+ */
290
+ if (process.argv.includes('--no-wait')) {
291
+ writePrivateFile(PENDING_FILE, JSON.stringify(pending, null, 2));
292
+ if (jsonOnly) {
293
+ console.log(
294
+ JSON.stringify({
295
+ user_code: pending.user_code,
296
+ verification_uri_complete: pending.verification_uri_complete,
297
+ expires_at: pending.expires_at,
298
+ resume: 'workover login --resume',
299
+ }),
300
+ );
301
+ } else {
302
+ console.log(' Send that link to the person who is approving. It expires at');
303
+ console.log(` ${pending.expires_at}. Once they approve, run \`workover login --resume\`.\n`);
304
+ }
305
+ return;
306
+ }
307
+
308
+ if (canOpenBrowser(process.platform, process.env)) {
309
+ console.log(' Opening your browser…');
310
+ openBrowser(start.verification_uri_complete);
311
+ } else {
312
+ // No screen here (a container, a server, an SSH session): opening one would show nobody.
313
+ console.log(' Open that link in a browser signed in to Workover.');
314
+ }
315
+ if (!process.stdout.isTTY) {
316
+ console.log(' (Running from an agent? `workover login --no-wait` returns at once, and');
317
+ console.log(' `workover login --resume` finishes the sign-in after the person approves.)');
318
+ }
319
+ await finishLogin(pending);
320
+ }
321
+
322
+ /**
323
+ * `workover login --resume`: finish a sign-in that `--no-wait` started. Polls until the person
324
+ * approves or denies, or the code expires, which can be several minutes, so an agent should run it
325
+ * after the person says they have approved, or in the background.
326
+ */
327
+ async function resumeLogin() {
328
+ let pending = null;
329
+ try {
330
+ pending = JSON.parse(readFileSync(PENDING_FILE, 'utf8'));
331
+ } catch {
332
+ /* none saved */
333
+ }
334
+ const state = pendingLoginState(pending, { api: API });
335
+ if (state === 'none') {
336
+ console.error('\n ✗ No sign-in is waiting. Start one with `workover login --no-wait`.\n');
337
+ process.exit(1);
338
+ }
339
+ if (state === 'elsewhere') {
340
+ console.error(`\n ✗ The waiting sign-in is for ${pending.api}, not ${API}.`);
341
+ console.error(` Run it with WORKOVER_API=${pending.api}, or start again.\n`);
342
+ process.exit(1);
343
+ }
344
+ if (state === 'expired') {
345
+ rmSync(PENDING_FILE, { force: true });
346
+ console.error('\n ✗ The login code expired. Run `workover login --no-wait` again.\n');
347
+ process.exit(1);
348
+ }
349
+ if (!process.argv.includes('--json')) {
350
+ console.log(`\n Waiting for ${pending.user_code} to be approved:`);
351
+ console.log(` ${pending.verification_uri_complete}\n`);
352
+ }
353
+ await finishLogin(pending);
354
+ }
203
355
 
204
- const interval = (start.interval || 5) * 1000;
205
- const deadline = Date.now() + (start.expires_in || 600) * 1000;
206
- process.stdout.write(' Waiting for approval');
356
+ /** Poll the device-token endpoint until the sign-in completes, is denied, or expires. */
357
+ async function finishLogin(pending) {
358
+ const interval = (pending.interval || 5) * 1000;
359
+ const deadline = Date.parse(pending.expires_at);
360
+ const done = () => rmSync(PENDING_FILE, { force: true });
361
+ // `--json` prints one JSON line when it completes, and nothing before it, so it parses.
362
+ const quiet = process.argv.includes('--json');
363
+ if (!quiet) process.stdout.write(' Waiting for approval');
207
364
 
208
365
  while (Date.now() < deadline) {
209
- await new Promise((r) => setTimeout(r, interval));
210
- process.stdout.write('.');
211
- const res = await post('/cli-auth/device/token', { device_code: start.device_code });
366
+ await sleep(interval);
367
+ if (!quiet) process.stdout.write('.');
368
+ const res = await post('/cli-auth/device/token', { device_code: pending.device_code });
212
369
  const decision = pollDecision(res);
213
370
  if (decision === 'complete') {
214
371
  saveConfig({ api: API, token: res.access_token });
372
+ done();
215
373
  /*
216
374
  * NAME THE ENVIRONMENT. There is one token, so signing in REPLACES whichever one was there,
217
375
  * and the only way to notice you have swapped environments used to be running `whoami`
@@ -219,18 +377,30 @@ async function login() {
219
377
  * exported from an earlier command — ends up authenticated somewhere else entirely, and the
220
378
  * next read fails in a way that looks like missing data rather than the wrong server.
221
379
  */
222
- console.log(`\n\n \x1b[32m✓\x1b[0m Signed in to ${API}\n`);
380
+ // NAME THE ACCOUNT TOO: the person may have approved in a browser signed in to another one
381
+ // (WO-1401), and nothing else here would say so until a workspace looked wrong.
382
+ const me = await tryAuthedGet({ api: API, token: res.access_token }, '/cli-auth/me');
383
+ const account = me.ok && me.body?.user ? me.body : null;
384
+ if (process.argv.includes('--json')) {
385
+ console.log(JSON.stringify(signedInJson(account, { api: API })));
386
+ return;
387
+ }
388
+ process.stdout.write('\n');
389
+ console.log(renderSignedIn(account, { api: API }).join('\n').replace('✓', '\x1b[32m✓\x1b[0m'));
223
390
  return;
224
391
  }
225
392
  if (decision === 'denied') {
393
+ done();
226
394
  console.log('\n\n ✗ Approval was denied.\n');
227
395
  process.exit(1);
228
396
  }
229
397
  if (decision === 'expired') {
398
+ done();
230
399
  console.log('\n\n ✗ The code expired. Run `workover login` again.\n');
231
400
  process.exit(1);
232
401
  }
233
402
  }
403
+ done();
234
404
  console.log('\n\n ✗ Timed out waiting for approval. Run `workover login` again.\n');
235
405
  process.exit(1);
236
406
  }
@@ -261,17 +431,58 @@ async function logout() {
261
431
  }
262
432
  }
263
433
  if (existsSync(CONFIG_FILE)) rmSync(CONFIG_FILE);
434
+ rmSync(PENDING_FILE, { force: true });
264
435
  console.log(' Signed out.');
265
436
  }
266
437
 
267
- function whoami() {
438
+ /**
439
+ * A GET that hands back the status instead of exiting, for the commands that can say something
440
+ * useful when the api is older than this CLI and does not have the route yet.
441
+ */
442
+ const tryAuthedGet = async (cfg, path) => {
443
+ try {
444
+ const res = await fetch(`${cfg.api}${path}`, {
445
+ headers: { authorization: `Bearer ${cfg.token}` },
446
+ });
447
+ const text = await res.text();
448
+ let body = null;
449
+ try {
450
+ body = text ? JSON.parse(text) : null;
451
+ } catch {
452
+ /* not JSON */
453
+ }
454
+ return { ok: res.ok, status: res.status, body };
455
+ } catch {
456
+ return { ok: false, status: 0, body: null };
457
+ }
458
+ };
459
+
460
+ /**
461
+ * `workover whoami`: who is signed in, not only where. An agent that set up the sign-in needs to
462
+ * know the person approved with the account they meant to (WO-1284), and the token alone cannot
463
+ * say. Falls back to the server and token when the api predates `GET /cli-auth/me`.
464
+ */
465
+ async function whoami() {
268
466
  const cfg = loadConfig();
269
467
  if (!cfg?.token) {
270
468
  console.log(' Not signed in. Run `workover login`.');
271
469
  process.exit(1);
272
470
  }
273
- console.log(` Signed in to ${cfg.api}`);
274
- console.log(` Token: ${cfg.token.slice(0, 12)}… (manage in Workover → Settings → Developer)`);
471
+ const json = process.argv.includes('--json');
472
+ const me = await tryAuthedGet(cfg, '/cli-auth/me');
473
+ if (me.status === 401 || me.status === 403) {
474
+ console.log(` The sign-in for ${cfg.api} no longer works. Run \`workover login\`.`);
475
+ process.exit(1);
476
+ }
477
+ if (!me.ok || !me.body?.user) {
478
+ if (json) return console.log(JSON.stringify({ api: cfg.api, user: null }));
479
+ console.log(` Signed in to ${cfg.api}`);
480
+ console.log(` Token: ${cfg.token.slice(0, 12)}… (manage in Workover → Settings → Developer)`);
481
+ console.log(' This server does not say which account the token belongs to: check it in the browser.');
482
+ return;
483
+ }
484
+ if (json) return console.log(JSON.stringify({ api: cfg.api, ...me.body }, null, 2));
485
+ console.log(renderWhoami(me.body, { api: cfg.api, token: cfg.token }).join('\n'));
275
486
  }
276
487
 
277
488
  /**
@@ -425,9 +636,10 @@ async function draftSet() {
425
636
  method: body ? 'POST' : 'GET',
426
637
  headers: {
427
638
  authorization: `Bearer ${cfg.token}`,
428
- ...(body ? { 'content-type': 'application/json' } : {}),
639
+ ...(body && !(body instanceof FormData) ? { 'content-type': 'application/json' } : {}),
429
640
  },
430
- ...(body ? { body: JSON.stringify(body) } : {}),
641
+ // A FormData body (a logo upload) goes as it is: fetch sets its multipart boundary.
642
+ ...(body ? { body: body instanceof FormData ? body : JSON.stringify(body) } : {}),
431
643
  });
432
644
  const text = await res.text();
433
645
  if (!res.ok) {
@@ -750,7 +962,8 @@ async function rulesCommand() {
750
962
  }
751
963
 
752
964
  if (!rules.length) {
753
- console.log('\n No style guide rules yet. Add one with `workover rules add`.\n');
965
+ console.log('\n No style guide rules yet. Adding one (`workover rules add`) needs a sign-in');
966
+ console.log(' from `workover login --rules`; reading the guide needs nothing extra.\n');
754
967
  return;
755
968
  }
756
969
  console.log('');
@@ -794,6 +1007,14 @@ const DOC_USAGE = [
794
1007
  ' [--slug <s>] [--excerpt "<t>"] document, linked to it, on its project\u2019s',
795
1008
  ' [--taxonomies <json>] site. Never live: Publish stays a click',
796
1009
  ' [--acf <json>] [--json] in Workover. Needs `login --publish`',
1010
+ ' rename <doc> --title "<t>" [--json] change the document’s title, body',
1011
+ ' untouched; needs `workover login --write`. A `# Heading` in',
1012
+ ' a written body never renames',
1013
+ ' status <doc> [<status>] [--json] the document’s Workover status and the',
1014
+ ' statuses its workflow offers; with <status>, set it (same',
1015
+ ' rules as the browser: role, workflow gates, approvals). Needs',
1016
+ ' `login --write`, plus `--publish` to or from Published. Does',
1017
+ ' not publish to WordPress',
797
1018
  ' upload <doc> <image> [--alt "<text>"] upload a screenshot into the document’s',
798
1019
  ' [--json] media; prints the markdown to place it',
799
1020
  ' images <doc> [--tab <tabId>] [--json] the images in it: file name, alt',
@@ -825,6 +1046,8 @@ const DOC_USAGE = [
825
1046
  ' of them, so run `workover doc tabs <doc>` first and pass --tab; without it',
826
1047
  ' you get the main body, which on a multi-tab document is not the whole thing.',
827
1048
  '',
1049
+ ...mdxHelpLines(),
1050
+ '',
828
1051
  ].join('\n');
829
1052
 
830
1053
  /**
@@ -1000,13 +1223,15 @@ async function docCommand() {
1000
1223
  'upload',
1001
1224
  'images',
1002
1225
  'image',
1226
+ 'status',
1227
+ 'rename',
1003
1228
  ].includes(sub)
1004
1229
  ) {
1005
1230
  console.log(DOC_USAGE);
1006
1231
  process.exit(sub ? 1 : 0);
1007
1232
  }
1008
1233
  const { flags, positionals } = parseArgs(process.argv.slice(4), {
1009
- booleans: ['json', 'html', 'replace', 'write'],
1234
+ booleans: ['json', 'html', 'replace', 'write', 'allow-block-removal'],
1010
1235
  });
1011
1236
  const cfg = requireSignIn();
1012
1237
  const asJson = flags.json === true;
@@ -1145,7 +1370,14 @@ async function docCommand() {
1145
1370
  // about the document, not part of it, so piping the output to a file gets
1146
1371
  // the body alone.
1147
1372
  console.error(`\n Title: ${doc.title || 'Untitled'} (id ${doc.id})`);
1148
- console.error(' The title IS the H1: start the body at ## and never include one.\n');
1373
+ console.error(' The title IS the H1: start the body at ## and never include one.');
1374
+ // A docs-site document reads as Mintlify MDX (WO-1299). Said here, on stderr with the title,
1375
+ // so the agent writes back the format it read and a piped body stays the body alone.
1376
+ if (live?.format === 'mdx')
1377
+ console.error(
1378
+ ' Format: Mintlify MDX. Write it back as MDX, keeping its components (`workover doc --help`).',
1379
+ );
1380
+ console.error('');
1149
1381
  console.log(live?.markdown?.trim() || documentText(doc) || '(empty document)');
1150
1382
  // Which tab this was, and that there are others.
1151
1383
  //
@@ -1245,10 +1477,24 @@ async function docCommand() {
1245
1477
  : {}),
1246
1478
  });
1247
1479
  if (asJson) return console.log(JSON.stringify(res, null, 2));
1248
- console.log(
1249
- `\n \x1b[32m✓\x1b[0m Proposed changes to ${res?.tab ? `the "${res.tab.title}" tab of ` : ''}document #${docId}.`,
1250
- );
1251
- console.log(' They appear as tracked-change suggestions for a person to accept or reject.');
1480
+ // Said from the api's `outcome` (WO-1748): "they appear" used to be printed for a resend that
1481
+ // changed nothing, and for a suggestion the editor had already been unable to show.
1482
+ const where = `${res?.tab ? `the "${res.tab.title}" tab of ` : ''}document #${docId}`;
1483
+ const sid = res?.id != null ? ` (suggestion #${res.id})` : '';
1484
+ if (res?.outcome === 'unchanged') {
1485
+ console.log(`\n Nothing changed: the open suggestion on ${where}${sid} already says exactly this.`);
1486
+ } else if (res?.outcome === 'held') {
1487
+ console.log(`\n Not applied: the open suggestion on ${where}${sid} is out with Workover AI for a revision.`);
1488
+ console.log(' Your text would be overwritten when that lands. Propose again once it is back.');
1489
+ } else if (res?.outcome === 'reoffered') {
1490
+ console.log(`\n \x1b[32m✓\x1b[0m Offered the open suggestion on ${where}${sid} to the editor again.`);
1491
+ console.log(' It says exactly this already, and the editor had not been able to show it before.');
1492
+ } else {
1493
+ console.log(
1494
+ `\n \x1b[32m✓\x1b[0m ${res?.outcome === 'updated' ? 'Updated the open suggestion on' : 'Proposed changes to'} ${where}${sid}.`,
1495
+ );
1496
+ console.log(' They appear as tracked-change suggestions for a person to accept or reject.');
1497
+ }
1252
1498
  if (res?.documentUrl) console.log(` ${res.documentUrl}`);
1253
1499
  printTitleHeading(res?.titleHeading);
1254
1500
  printStyleFeedback(res?.style);
@@ -1272,6 +1518,7 @@ async function docCommand() {
1272
1518
  note: typeof flags.note === 'string' ? flags.note : undefined,
1273
1519
  source: 'Workover CLI',
1274
1520
  ...(tabId === null ? {} : { tabId }),
1521
+ ...(flags['allow-block-removal'] === true ? { allowBlockRemoval: true } : {}),
1275
1522
  });
1276
1523
  if (asJson) return console.log(JSON.stringify(res, null, 2));
1277
1524
  console.log(
@@ -1280,6 +1527,9 @@ async function docCommand() {
1280
1527
  if (res?.replacedCharacters) {
1281
1528
  console.log(` Replaced ${res.replacedCharacters} characters of existing text.`);
1282
1529
  }
1530
+ if (Array.isArray(res?.removedBlocks) && res.removedBlocks.length) {
1531
+ console.log(` Removed as asked: ${res.removedBlocks.join(', ')}.`);
1532
+ }
1283
1533
  if (res?.documentUrl) console.log(` ${res.documentUrl}`);
1284
1534
  printTitleHeading(res?.titleHeading);
1285
1535
  printStyleFeedback(res?.style);
@@ -1320,7 +1570,7 @@ async function docCommand() {
1320
1570
  const applied = await authedCall(
1321
1571
  cfg,
1322
1572
  `/project/doc/${docId}/${direct ? 'content' : 'propose'}`,
1323
- { markdown: res.html, note, source: 'Workover CLI' },
1573
+ { markdown: res.html, format: 'html', note, source: 'Workover CLI' },
1324
1574
  );
1325
1575
  if (asJson) return console.log(JSON.stringify({ ...res, applied }, null, 2));
1326
1576
  console.log(
@@ -1379,7 +1629,7 @@ async function docCommand() {
1379
1629
  const applied = await authedCall(
1380
1630
  cfg,
1381
1631
  `/project/doc/${docId}/${direct ? 'content' : 'propose'}`,
1382
- { markdown: res.html, note, source: 'Workover CLI' },
1632
+ { markdown: res.html, format: 'html', note, source: 'Workover CLI' },
1383
1633
  );
1384
1634
  if (asJson) return console.log(JSON.stringify({ ...res, applied }, null, 2));
1385
1635
  console.log(
@@ -1498,6 +1748,73 @@ async function docCommand() {
1498
1748
  return;
1499
1749
  }
1500
1750
 
1751
+ if (sub === 'status') {
1752
+ // The document's WORKOVER status (Triage, In review, Published, or its workflow's own), read or
1753
+ // set through the same rules as the browser's status picker: the project role, the workflow's
1754
+ // gates and the approval a gated status opens (WO-1264). It never touches WordPress: a post goes
1755
+ // live only from the document's WordPress tab, and this says so next to the status.
1756
+ const usage = 'workover doc status <doc> [<status>] [--json]';
1757
+ const docId = await resolveDocArg(cfg, positionals.slice(0, 1), usage);
1758
+ const wanted = positionals[1] ? String(positionals[1]).trim() : '';
1759
+ let res;
1760
+ try {
1761
+ res = await fetch(`${cfg.api}/project/doc/${docId}/status`, {
1762
+ method: wanted ? 'PATCH' : 'GET',
1763
+ headers: {
1764
+ authorization: `Bearer ${cfg.token}`,
1765
+ ...(wanted ? { 'content-type': 'application/json' } : {}),
1766
+ },
1767
+ ...(wanted ? { body: JSON.stringify({ status: wanted }) } : {}),
1768
+ });
1769
+ } catch {
1770
+ console.error(`\n ✗ Couldn't reach Workover at ${cfg.api}\n`);
1771
+ process.exit(1);
1772
+ }
1773
+ const body = await res.json().catch(() => null);
1774
+ if (!res.ok) {
1775
+ if (asJson) console.log(JSON.stringify({ refused: true, httpStatus: res.status, ...(body || {}) }, null, 2));
1776
+ else console.error(`\n ✗ ${statusRefusal(res.status, body)}\n`);
1777
+ process.exit(1);
1778
+ }
1779
+ if (asJson) return console.log(JSON.stringify(body, null, 2));
1780
+ console.log((wanted ? renderStatusChange(body) : renderStatusList(body)).join('\n'));
1781
+ return;
1782
+ }
1783
+
1784
+ if (sub === 'rename') {
1785
+ // The editor's rename, by document id: only the title is sent, so the body cannot change. Needs
1786
+ // `workover login --write`, like `doc write`. A `# Heading` in a written body never renames.
1787
+ const usage = 'workover doc rename <doc> --title "<new title>" [--json]';
1788
+ const docId = await resolveDocArg(cfg, positionals.slice(0, 1), usage);
1789
+ const title = typeof flags.title === 'string' ? flags.title.trim() : '';
1790
+ if (!title) {
1791
+ console.log(`\n Usage: ${usage}`);
1792
+ console.log(' Pass the new name as --title. Only the title changes; the body is left');
1793
+ console.log(' as it is. Needs a token from `workover login --write`.\n');
1794
+ process.exit(1);
1795
+ }
1796
+ let res;
1797
+ try {
1798
+ res = await fetch(`${cfg.api}/project/doc/${docId}/title`, {
1799
+ method: 'PATCH',
1800
+ headers: { authorization: `Bearer ${cfg.token}`, 'content-type': 'application/json' },
1801
+ body: JSON.stringify({ title }),
1802
+ });
1803
+ } catch {
1804
+ console.error(`\n ✗ Couldn't reach Workover at ${cfg.api}\n`);
1805
+ process.exit(1);
1806
+ }
1807
+ const body = await res.json().catch(() => null);
1808
+ if (!res.ok) {
1809
+ if (asJson) console.log(JSON.stringify({ refused: true, httpStatus: res.status, ...(body || {}) }, null, 2));
1810
+ else console.error(`\n ✗ ${renameRefusal(res.status, body)}\n`);
1811
+ process.exit(1);
1812
+ }
1813
+ if (asJson) return console.log(JSON.stringify(body, null, 2));
1814
+ console.log(renderRename(body).join('\n'));
1815
+ return;
1816
+ }
1817
+
1501
1818
  if (sub === 'activity') {
1502
1819
  const docId = await resolveDocArg(cfg, positionals, 'workover doc activity <doc>');
1503
1820
  const limit = rowId(flags.limit) ?? 20;
@@ -1728,12 +2045,464 @@ async function projects() {
1728
2045
  const res = await authedCall(cfg, '/project');
1729
2046
  const list = Array.isArray(res) ? res : res?.projects || [];
1730
2047
  if (flags.json === true) return console.log(JSON.stringify(list, null, 2));
1731
- if (!list.length) return console.log('\n No projects.\n');
1732
- console.log('');
1733
- for (const p of list) {
1734
- console.log(` #${String(p.id).padEnd(6)} ${p.name || p.title || 'Project'}`);
2048
+ // Grouped by workspace with its slug: a Workover URL needs the slug (`/app/<workspace>/p/<id>`),
2049
+ // and the bare list could not tell two workspaces' "Docs" apart.
2050
+ console.log(renderProjects(list).join('\n'));
2051
+ }
2052
+
2053
+ /**
2054
+ * `workover status <project>`: where a project's setup has got to (site, domain, GitHub, reviewer,
2055
+ * what waits in review) and what is left for the person, so an agent can check its own steps
2056
+ * instead of asking (WO-1284).
2057
+ */
2058
+ async function status() {
2059
+ const cfg = requireSignIn();
2060
+ const { flags, positionals } = parseArgs(process.argv.slice(3), { booleans: ['json'] });
2061
+ const id = rowId(flags.project ?? positionals[0] ?? '');
2062
+ if (id === null) {
2063
+ console.error('\n Usage: workover status <projectId> [--json] (ids from `workover projects`)\n');
2064
+ process.exit(1);
2065
+ }
2066
+ const res = await tryAuthedGet(cfg, `/cli-auth/setup/${id}`);
2067
+ if (res.status === 404 && !res.body?.message?.includes('Project')) {
2068
+ console.error(`\n ✗ ${cfg.api} does not offer setup status yet. Update it, or check in the app.\n`);
2069
+ process.exit(1);
2070
+ }
2071
+ if (!res.ok) {
2072
+ const msg = res.body?.message || `HTTP ${res.status}`;
2073
+ console.error(`\n ✗ ${res.status === 404 ? `No project #${id} that you can see.` : msg}\n`);
2074
+ process.exit(1);
2075
+ }
2076
+ if (flags.json === true) return console.log(JSON.stringify(res.body, null, 2));
2077
+ console.log(renderSetupStatus(res.body, { web: webForApi(cfg.api) }).join('\n'));
2078
+ }
2079
+
2080
+ // ------------------------------------------------------------------ Help Center setup
2081
+
2082
+ /**
2083
+ * The api caller the site commands share with the MCP server (site-setup.mjs): resolves the JSON,
2084
+ * or throws an Error with the HTTP status and the api's own sentence, so each command can say what
2085
+ * to do next instead of exiting from deep inside a helper.
2086
+ */
2087
+ const siteCall = (cfg) => async (path, { method, body } = {}) => {
2088
+ let res;
2089
+ try {
2090
+ res = await fetch(`${cfg.api}${path}`, {
2091
+ method: method || 'GET',
2092
+ headers: {
2093
+ authorization: `Bearer ${cfg.token}`,
2094
+ ...(body && !(body instanceof FormData) ? { 'content-type': 'application/json' } : {}),
2095
+ },
2096
+ // A FormData body (a logo upload) goes as it is: fetch sets its multipart boundary.
2097
+ ...(body ? { body: body instanceof FormData ? body : JSON.stringify(body) } : {}),
2098
+ });
2099
+ } catch {
2100
+ throw apiError(0, `Couldn't reach Workover at ${cfg.api}.`);
2101
+ }
2102
+ const text = await res.text();
2103
+ let parsed = null;
2104
+ try {
2105
+ parsed = text ? JSON.parse(text) : null;
2106
+ } catch {
2107
+ /* not JSON */
2108
+ }
2109
+ if (!res.ok) {
2110
+ const m = Array.isArray(parsed?.message) ? parsed.message.join('; ') : parsed?.message;
2111
+ if (res.status === 401) throw apiError(401, 'This sign-in no longer works. Run `workover login --site` again.');
2112
+ throw apiError(res.status, typeof m === 'string' && m ? m : text.slice(0, 300) || `HTTP ${res.status}`);
2113
+ }
2114
+ return parsed;
2115
+ };
2116
+
2117
+ /** Print a refusal the way an agent can act on it, and exit. */
2118
+ const siteFail = (e) => {
2119
+ console.error(`\n ✗ ${e.message}`);
2120
+ const help = e.status === 403 ? scopeHelp(e.message) : null;
2121
+ if (help) console.error(` ${help}`);
2122
+ console.error('');
2123
+ process.exit(1);
2124
+ };
2125
+
2126
+ /** `--wait <seconds>`: how long import and publish wait before handing back "still running". */
2127
+ const waitMs = (flags) => {
2128
+ const n = Number(flags.wait);
2129
+ return Number.isFinite(n) && n >= 0 ? n * 1000 : 110_000;
2130
+ };
2131
+
2132
+ const PROJECT_USAGE = [
2133
+ '',
2134
+ ' Usage: workover project create --name "<name>" [--workspace <slug|id>]',
2135
+ ' [--address <name>] [--start blank|starter|empty] [--json]',
2136
+ '',
2137
+ ' A new project that publishes to a Workover Help Center: the project, its site at',
2138
+ ' <address>.workover.site, and its first pages (blank: one page; starter: the starter',
2139
+ ' template; empty: none, for `workover site import` to fill). Nothing is published.',
2140
+ ' --workspace is needed only when the account has more than one (`workover whoami`).',
2141
+ ' --address defaults to one made from the name; a taken or reserved one gets a free alternative.',
2142
+ ` Needs \`${SITE_LOGIN}\`.`,
2143
+ '',
2144
+ ].join('\n');
2145
+
2146
+ async function projectCommand() {
2147
+ const sub = process.argv[3];
2148
+ if (sub !== 'create') {
2149
+ console.log(PROJECT_USAGE);
2150
+ process.exit(sub ? 1 : 0);
2151
+ }
2152
+ const { flags } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
2153
+ if (typeof flags.name !== 'string' || !flags.name.trim()) {
2154
+ console.log(PROJECT_USAGE);
2155
+ process.exit(1);
2156
+ }
2157
+ const cfg = requireSignIn();
2158
+ try {
2159
+ const res = await createProject(siteCall(cfg), {
2160
+ workspace: flags.workspace ?? flags.org,
2161
+ name: flags.name,
2162
+ address: typeof flags.address === 'string' ? flags.address : undefined,
2163
+ start: typeof flags.start === 'string' ? flags.start : 'blank',
2164
+ });
2165
+ if (flags.json === true) return console.log(JSON.stringify(res, null, 2));
2166
+ console.log(renderProjectCreated(res, { web: webForApi(cfg.api) }).join('\n'));
2167
+ } catch (e) {
2168
+ siteFail(e);
2169
+ }
2170
+ }
2171
+
2172
+ const SITE_USAGE = [
2173
+ '',
2174
+ ' Usage: workover site <command> --project <id>',
2175
+ '',
2176
+ ' create --project <id> [--address <name>] give the project a Workover Help Center',
2177
+ ' at <address>.workover.site (or change its address)',
2178
+ ' import --project <id> --url <docs-url> bring in a public docs site (up to 500',
2179
+ ' [--wait <seconds>] [--status] pages, with its navigation); waits and',
2180
+ ' reports progress, --status only checks',
2181
+ ' import --project <id> --dir <folder> bring in a docs folder: _site.json with',
2182
+ ' <tab>/<slug>.md pages, or Mintlify docs.json.',
2183
+ ' Tabs, groups and order as the config says;',
2184
+ ' pages already there are kept',
2185
+ ' appearance --project <id> [--from <folder>] colors, links and logo: --from reads its',
2186
+ ' [--primary <#hex>] [--logo <file>] _site.json or docs.json, and flags win.',
2187
+ ' [--logo-dark <file>] Also --primary-dark, --search-prompt and',
2188
+ ' [--favicon <file>] --favicon-dark. Unnamed settings are kept',
2189
+ ' redirects --project <id> --from <folder> add the config redirects; never changes or',
2190
+ ' removes one the site has',
2191
+ ' api add --project <id> --spec <url> an API reference tab made from an OpenAPI',
2192
+ ' [--tab "API reference"] spec: a page per endpoint, grouped by tag,',
2193
+ ' [--group <g>] [--directory <dir>] with Try it. The site keeps it in step with',
2194
+ ' the spec (hourly, and on `api sync`) and',
2195
+ ' publishes those pages itself. --spec is an',
2196
+ ' https URL, or {api}/openapi.json for',
2197
+ " Workover's own API",
2198
+ ' api sync --project <id> "the spec changed": sync it now (call it',
2199
+ ' from your deploy, with a site token)',
2200
+ ' api list --project <id> the spec-backed tabs and their last sync',
2201
+ ' api remove --project <id> [--tab <t>] stop following the spec; the pages stay',
2202
+ ' [--group <g>] as ordinary pages',
2203
+ ' domain --project <id> --set <host[/path]> connect docs.example.com, or serve under',
2204
+ ' [--preverify] example.com/docs; prints EVERY DNS record',
2205
+ ' to add. --preverify: TXT records that prove',
2206
+ ' a domain already live elsewhere first.',
2207
+ ' --set none disconnects it',
2208
+ ' [--move-from <id>] take the domain from another Help Center in',
2209
+ ' this workspace in one step: it keeps its',
2210
+ ' verification, the DNS stays as it is, and',
2211
+ ' neither site goes without it',
2212
+ ' domain --project <id> the records again, as they stand',
2213
+ ' check --project <id> ask now: records found, domain verified,',
2214
+ ' certificate issued, and for a path, the',
2215
+ ' live address',
2216
+ ' proxy --project <id> [--platform <name>] for a site under a path: the setup your',
2217
+ ' [--write] [--dir <repo>] website needs, for where it runs (found',
2218
+ ' from its headers, or --platform: cloudflare,',
2219
+ ' vercel, nextjs, cloudfront, amplify, netlify,',
2220
+ ' nginx, caddy, apache). --write adds it to the',
2221
+ ' repository in --dir (default: here)',
2222
+ ' publish --project <id> [--wait <seconds>] put the site live; --status only checks',
2223
+ ' [--status]',
2224
+ ' unpublish --project <id> --yes take the site offline; pages, settings',
2225
+ ' and domain are kept, publish restores it',
2226
+ ' index --project <id> on|off let search engines index the site (the',
2227
+ ' Publish page’s setting; new sites start off)',
2228
+ ' status [--project <id>] the site, its domain, the last import and',
2229
+ ' publish; without --project, which projects',
2230
+ ' have a Help Center',
2231
+ '',
2232
+ ' Every command takes --json. They need a sign-in from',
2233
+ ` \`${SITE_LOGIN}\`: the person approves "Set up and publish your Workover`,
2234
+ ' Help Center" in the browser. Payment and DNS records stay with the person.',
2235
+ ' New projects: `workover project create`. Ids: `workover projects`.',
2236
+ '',
2237
+ ].join('\n');
2238
+
2239
+ async function siteCommand() {
2240
+ const sub = process.argv[3];
2241
+ if (!['create', 'import', 'domain', 'check', 'proxy', 'publish', 'unpublish', 'index', 'status', 'appearance', 'redirects', 'api'].includes(sub)) {
2242
+ console.log(SITE_USAGE);
2243
+ process.exit(sub ? 1 : 0);
2244
+ }
2245
+ const { flags, positionals } = parseArgs(process.argv.slice(4), {
2246
+ booleans: ['json', 'status', 'preverify', 'write', 'yes'],
2247
+ });
2248
+ const cfg = requireSignIn();
2249
+ const call = siteCall(cfg);
2250
+ const json = flags.json === true;
2251
+ const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
2252
+ const apiAction = sub === 'api' ? positionals[0] : null;
2253
+ if (sub === 'api' && !['add', 'sync', 'list', 'remove'].includes(apiAction)) {
2254
+ console.log(SITE_USAGE);
2255
+ process.exit(1);
2256
+ }
2257
+ const projectId = rowId(flags.project ?? (sub === 'index' ? '' : positionals[sub === 'api' ? 1 : 0]) ?? '');
2258
+
2259
+ if (sub === 'status' && projectId === null) {
2260
+ // Which projects have a Help Center, so an agent can find the id without guessing.
2261
+ try {
2262
+ const res = await call('/project');
2263
+ const list = (Array.isArray(res) ? res : res?.projects || []).filter((p) => p.hasSite);
2264
+ if (json) return console.log(JSON.stringify(list, null, 2));
2265
+ if (!list.length) {
2266
+ console.log('\n No project has a Help Center yet. `workover project create --name "<name>"` makes one.\n');
2267
+ return;
2268
+ }
2269
+ console.log('\n Projects with a Help Center:');
2270
+ for (const p of list) console.log(` #${String(p.id).padEnd(6)} ${p.name || p.title || 'Project'}`);
2271
+ console.log('\n `workover site status --project <id>` shows one.\n');
2272
+ return;
2273
+ } catch (e) {
2274
+ return siteFail(e);
2275
+ }
2276
+ }
2277
+ if (projectId === null) {
2278
+ console.log(SITE_USAGE);
2279
+ process.exit(1);
2280
+ }
2281
+
2282
+ try {
2283
+ if (sub === 'create') {
2284
+ const res = await createSite(call, {
2285
+ projectId,
2286
+ address: typeof flags.address === 'string' ? flags.address : undefined,
2287
+ });
2288
+ return out(res, renderSiteCreated(res));
2289
+ }
2290
+ if (sub === 'domain') {
2291
+ if (flags.set === undefined) {
2292
+ const view = await call(`/sites/project/${projectId}`);
2293
+ if (!view?.site) throw apiError(404, `Project #${projectId} has no Help Center. \`workover site create --project ${projectId}\` adds one.`);
2294
+ const guess = view.site.domain?.basePath ? await detectPlatform(call, { projectId }) : {};
2295
+ return out(view.site.domain, renderDomain(view.site.domain, { projectId, ...guess }));
2296
+ }
2297
+ const moveFrom = flags['move-from'];
2298
+ if (moveFrom === true) throw apiError(400, 'Name the project to move the domain from: --move-from <id>.');
2299
+ const res = await setDomain(call, {
2300
+ projectId,
2301
+ address: String(flags.set),
2302
+ preverify: flags.preverify === true,
2303
+ moveFrom: moveFrom === undefined ? null : rowId(String(moveFrom)) ?? String(moveFrom),
2304
+ });
2305
+ if (res.disconnected) return out(res, ['', ` Disconnected the custom domain. The workover.site address keeps working. Remove its DNS records.`, '']);
2306
+ const guess = res.domain?.basePath ? await detectPlatform(call, { projectId }) : {};
2307
+ if (res.movedFrom) return out(res, [...renderMoved(res), ...renderDomain(res.domain, { projectId, ...guess })]);
2308
+ return out(res.domain, renderDomain(res.domain, { projectId, ...guess }));
2309
+ }
2310
+ if (sub === 'proxy') {
2311
+ const view = await call(`/sites/project/${projectId}`);
2312
+ if (!view?.site) throw apiError(404, `Project #${projectId} has no Help Center. \`workover site create --project ${projectId}\` adds one.`);
2313
+ const domain = view.site.domain;
2314
+ const asked = typeof flags.platform === 'string' ? flags.platform.toLowerCase() : null;
2315
+ if (asked && !MOUNT_PLATFORMS.includes(asked)) throw apiError(400, `No setup for "${asked}". One of: ${MOUNT_PLATFORMS.join(', ')}.`);
2316
+ proxyRecipe(domain, MOUNT_PLATFORMS[0]); // throws, with what to do, when the site is not under a path
2317
+ const guess = asked ? { platform: asked, evidence: null } : await detectPlatform(call, { projectId });
2318
+ if (!guess.platform)
2319
+ throw apiError(
2320
+ 400,
2321
+ `Could not tell where ${domain.hostname} runs from its headers. Name it: --platform ${MOUNT_PLATFORMS.join('|')}.`,
2322
+ );
2323
+ const recipe = proxyRecipe(domain, guess.platform);
2324
+ const lines = [''];
2325
+ if (!asked) lines.push(` ${domain.hostname} runs on ${recipe.label}${guess.evidence ? ` (${guess.evidence})` : ''}. \`--platform\` picks another.`, '');
2326
+ lines.push(...renderRecipe(recipe));
2327
+ let written = null;
2328
+ if (flags.write === true) {
2329
+ written = writeRecipe(recipe, typeof flags.dir === 'string' ? flags.dir : process.cwd());
2330
+ lines.push('');
2331
+ if (!written.path) lines.push(` ${written.reason}`);
2332
+ else lines.push(` ${written.changed ? 'Wrote' : 'Already there, unchanged:'} ${written.path}`);
2333
+ if (written.include) lines.push(` Then: ${written.include}`);
2334
+ }
2335
+ lines.push('', ` Once it is live, \`workover site check --project ${projectId}\` loads https://${domain.hostname}${domain.basePath} and says whether it works.`, '');
2336
+ return out({ ...recipe, written, detected: asked ? null : guess }, lines);
2337
+ }
2338
+ if (sub === 'unpublish') {
2339
+ if (flags.yes !== true) {
2340
+ console.error(`\n This takes the Help Center of project #${projectId} offline until it is published again. Nothing is deleted.\n Run it again with --yes once the person has said to.\n`);
2341
+ process.exit(1);
2342
+ }
2343
+ const res = await unpublishSite(call, { projectId });
2344
+ return out(res, renderUnpublish({ projectId }));
2345
+ }
2346
+ if (sub === 'check') {
2347
+ const res = await checkSite(call, { projectId });
2348
+ return out(res, renderCheck(res, { projectId }));
2349
+ }
2350
+ if (sub === 'import' || sub === 'publish') {
2351
+ const path = `/sites/project/${projectId}/${sub}`;
2352
+ const progress = (state) =>
2353
+ json ? undefined : console.error(sub === 'import' ? importProgressLine(state) : publishProgressLine(state));
2354
+ const wait = { timeoutMs: waitMs(flags), onProgress: progress };
2355
+ let state;
2356
+ if (flags.status === true) state = await waitForJob(() => call(path), { ...wait, timeoutMs: 0 });
2357
+ else if (sub === 'import' && typeof flags.dir === 'string') {
2358
+ const plan = readDocsFolder(flags.dir);
2359
+ if (!json) console.error(` Read ${pageCount(plan)} page(s) in ${plan.imports.length} tab(s) from ${plan.dir}.`);
2360
+ const res = await importFolder(call, {
2361
+ projectId,
2362
+ plan,
2363
+ waitFor: (first) => waitForJob(() => call(path), { first, ...wait }),
2364
+ });
2365
+ out({ ...res, layout: plan.layout, pages: pageCount(plan) }, renderFolderImport(res, { projectId, plan }));
2366
+ if (res.status === 'failed') process.exit(1);
2367
+ return;
2368
+ } else if (sub === 'import') {
2369
+ if (typeof flags.url !== 'string') {
2370
+ console.log(SITE_USAGE);
2371
+ process.exit(1);
2372
+ }
2373
+ state = await importSite(call, { projectId, url: flags.url, ...wait });
2374
+ } else state = await publishSite(call, { projectId, ...wait });
2375
+ if (sub === 'import') {
2376
+ out(state, renderImport(state, { projectId }));
2377
+ } else {
2378
+ const site = state?.status === 'done' ? (await call(`/sites/project/${projectId}`))?.site : null;
2379
+ out(state, renderPublish(state, { projectId, site }));
2380
+ }
2381
+ if (state?.status === 'failed') process.exit(1);
2382
+ return;
2383
+ }
2384
+ if (sub === 'appearance') {
2385
+ const plan = typeof flags.from === 'string' ? readDocsFolder(flags.from) : null;
2386
+ const pick = (pairs) =>
2387
+ Object.fromEntries(pairs.filter(([, k]) => typeof flags[k] === 'string').map(([key, k]) => [key, flags[k]]));
2388
+ const appearance = {
2389
+ ...(plan?.appearance ?? {}),
2390
+ ...pick([['primary', 'primary'], ['primaryDark', 'primary-dark'], ['searchPrompt', 'search-prompt']]),
2391
+ };
2392
+ const files = {
2393
+ ...(plan?.assets ?? {}),
2394
+ ...pick([['logoLight', 'logo'], ['logoDark', 'logo-dark'], ['favicon', 'favicon'], ['faviconDark', 'favicon-dark']]),
2395
+ };
2396
+ if (!Object.keys(appearance).length && !Object.keys(files).length) {
2397
+ console.log(SITE_USAGE);
2398
+ process.exit(1);
2399
+ }
2400
+ const res = await setAppearance(call, uploadWith(call), { projectId, appearance, files });
2401
+ return out(res, renderAppearance(res));
2402
+ }
2403
+ if (sub === 'redirects') {
2404
+ if (typeof flags.from !== 'string') {
2405
+ console.log(SITE_USAGE);
2406
+ process.exit(1);
2407
+ }
2408
+ const res = await addRedirects(call, { projectId, redirects: readDocsFolder(flags.from).redirects });
2409
+ return out(res, renderRedirects(res));
2410
+ }
2411
+ if (sub === 'api') {
2412
+ if (apiAction === 'add') {
2413
+ if (typeof flags.spec !== 'string') {
2414
+ console.log(SITE_USAGE);
2415
+ process.exit(1);
2416
+ }
2417
+ const res = await addApiReference(call, {
2418
+ projectId,
2419
+ spec: flags.spec,
2420
+ tab: typeof flags.tab === 'string' ? flags.tab : undefined,
2421
+ group: typeof flags.group === 'string' ? flags.group : undefined,
2422
+ directory: typeof flags.directory === 'string' ? flags.directory : undefined,
2423
+ });
2424
+ out(res, renderApiReferences(res, { projectId, verb: 'add' }));
2425
+ } else if (apiAction === 'remove') {
2426
+ const tab = typeof flags.tab === 'string' ? flags.tab : 'API reference';
2427
+ const group = typeof flags.group === 'string' ? flags.group : undefined;
2428
+ const res = await removeApiReference(call, { projectId, tab, group });
2429
+ if (!res) throw apiError(404, `Project #${projectId} has no API reference made from a spec in "${group ? `${tab} › ${group}` : tab}". \`workover site api list --project ${projectId}\` lists them.`);
2430
+ out(res, ['', ` ✓ "${group ? `${tab} › ${group}` : tab}" no longer follows ${res.spec}. Its ${res.pagesKept} page(s) stay, as ordinary pages.`, '']);
2431
+ } else {
2432
+ const res =
2433
+ apiAction === 'sync' ? await syncApiReferences(call, { projectId }) : await listApiReferences(call, { projectId });
2434
+ out(res, renderApiReferences(res, { projectId, verb: apiAction }));
2435
+ if (apiAction === 'sync' && res.references.some((r) => r.outcome?.status === 'failed')) process.exit(1);
2436
+ }
2437
+ return;
2438
+ }
2439
+ if (sub === 'index') {
2440
+ const want = String(positionals[0] ?? '').toLowerCase();
2441
+ if (!['on', 'off'].includes(want)) {
2442
+ console.log('\n Usage: workover site index --project <id> on|off\n');
2443
+ process.exit(1);
2444
+ }
2445
+ const res = await setIndexing(call, { projectId, index: want === 'on' });
2446
+ return out(res, renderIndexing(res));
2447
+ }
2448
+ if (sub === 'status') {
2449
+ const res = await siteStatus(call, { projectId });
2450
+ return out(res, renderSiteStatus(res, { projectId }));
2451
+ }
2452
+ } catch (e) {
2453
+ siteFail(e);
2454
+ }
2455
+ }
2456
+
2457
+ // ------------------------------------------------------------------ feedback
2458
+
2459
+ const FEEDBACK_USAGE = [
2460
+ '',
2461
+ ' Usage: workover feedback --summary "<one line>" --intent "<what you were doing>"',
2462
+ ' --problem "<what got in the way>" [--fix "<the change you propose>"]',
2463
+ ' [--tool <workover tool or command>] [--kind missing_capability|bug|confusing|docs|other]',
2464
+ ' [--json]',
2465
+ '',
2466
+ ' Tell the Workover team that a Workover command or MCP tool fell short. It is filed as an issue',
2467
+ ' in their tracker. Describe the problem, never the document text, customer data or secrets.',
2468
+ '',
2469
+ ].join('\n');
2470
+
2471
+ /** The CLI's own version, from its package.json, stamped on the report. */
2472
+ const cliVersion = () => {
2473
+ try {
2474
+ return JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8')).version;
2475
+ } catch {
2476
+ return undefined;
2477
+ }
2478
+ };
2479
+
2480
+ async function feedbackCommand() {
2481
+ const { flags } = parseArgs(process.argv.slice(3), { booleans: ['json'] });
2482
+ if (!['summary', 'intent', 'problem'].every((k) => typeof flags[k] === 'string' && flags[k].trim())) {
2483
+ console.log(FEEDBACK_USAGE);
2484
+ process.exit(1);
2485
+ }
2486
+ const cfg = requireSignIn();
2487
+ try {
2488
+ const res = await submitFeedback(
2489
+ siteCall(cfg),
2490
+ {
2491
+ summary: flags.summary,
2492
+ intent: flags.intent,
2493
+ problem: flags.problem,
2494
+ proposedFix: flags.fix,
2495
+ tool: flags.tool,
2496
+ kind: flags.kind,
2497
+ },
2498
+ { surface: 'cli', version: cliVersion() },
2499
+ );
2500
+ if (flags.json) return console.log(JSON.stringify(res, null, 2));
2501
+ console.log(`\n \x1b[32m✓\x1b[0m ${renderFeedbackResult(res).join('\n ')}\n`);
2502
+ } catch (e) {
2503
+ if (e.status === 401) e.message = 'This sign-in no longer works. Run `workover login` again.';
2504
+ siteFail(e);
1735
2505
  }
1736
- console.log('');
1737
2506
  }
1738
2507
 
1739
2508
  /**
@@ -1764,7 +2533,7 @@ function installClaude() {
1764
2533
  const cmd = process.argv[2];
1765
2534
  if (cmd === 'login') await login();
1766
2535
  else if (cmd === 'logout') await logout();
1767
- else if (cmd === 'whoami') whoami();
2536
+ else if (cmd === 'whoami') await whoami();
1768
2537
  else if (cmd === 'draft') await draft();
1769
2538
  else if (cmd === 'draft-set') await draftSet();
1770
2539
  else if (cmd === 'eval') await evaluateDocs();
@@ -1772,6 +2541,10 @@ else if (cmd === 'doc') await docCommand();
1772
2541
  else if (cmd === 'rules') await rulesCommand();
1773
2542
  else if (cmd === 'comments') await commentsCommand();
1774
2543
  else if (cmd === 'projects') await projects();
2544
+ else if (cmd === 'status') await status();
2545
+ else if (cmd === 'project') await projectCommand();
2546
+ else if (cmd === 'site') await siteCommand();
2547
+ else if (cmd === 'feedback') await feedbackCommand();
1775
2548
  else if (cmd === 'install-claude') installClaude();
1776
2549
  else {
1777
2550
  console.log('\n Workover CLI\n');
@@ -1781,8 +2554,13 @@ else {
1781
2554
  console.log(' --draft also request permission to write drafts with AI');
1782
2555
  console.log(' --write also allow direct edits (no suggestions to review)');
1783
2556
  console.log(' --rules also allow changing the style guide');
2557
+ console.log(' --site also allow setting up and publishing a Help Center');
1784
2558
  console.log(' --client "<name>" what to call this token in your history');
1785
- console.log(' doc Work on documents: list, read, create, propose, write, search');
2559
+ console.log(' --no-wait print the code and link and return at once (for agents);');
2560
+ console.log(' finish with `workover login --resume` once it is approved');
2561
+ console.log(' --json with --no-wait or --resume: JSON only; once signed in, the');
2562
+ console.log(' account (email, name) and its workspaces, to check');
2563
+ console.log(' doc Work on documents: list, read, create, propose, write, rename, search');
1786
2564
  console.log(' plus activity, to see who changed one and how');
1787
2565
  console.log(' plus tabs and tab-new for documents with several bodies');
1788
2566
  console.log(' plus images and image, for image file names and alt text');
@@ -1794,13 +2572,22 @@ else {
1794
2572
  console.log(' workover comments list 123 · workover comments resolve 45');
1795
2573
  console.log(' rules The style guide agents should write by: list, export, add');
1796
2574
  console.log(' workover rules export --project 11 >> AGENTS.md');
1797
- console.log(' projects List the projects you can reach, with their ids');
2575
+ console.log(' projects List the projects you can reach, with their ids and workspaces');
2576
+ console.log(' status Where a project’s setup has got to, and what is left to do');
2577
+ console.log(' workover status 11 [--json]');
2578
+ console.log(' project create: a new project that publishes to a Workover Help Center');
2579
+ console.log(' workover project create --name "Acme Docs" --start empty');
2580
+ console.log(' site Set up a Help Center: create, import, domain, check, publish, status');
2581
+ console.log(' workover site domain --project 11 --set docs.example.com');
2582
+ console.log(' (project and site need `workover login --site`)');
1798
2583
  console.log(' draft Queue a draft in Workover and wait for it');
1799
2584
  console.log(' --type tutorial|how-to|reference|explanation');
1800
2585
  console.log(' draft-set Plan a feature’s whole documentation set, then draft each article');
1801
2586
  console.log(' eval Score a project’s documentation against the editorial rubric');
1802
2587
  console.log(' --org <id> --project <id> [--limit N] [--json]');
2588
+ console.log(' feedback Tell the Workover team a command or tool fell short (files an issue)');
2589
+ console.log(' workover feedback --summary "..." --intent "..." --problem "..." --fix "..."');
1803
2590
  console.log(' logout Sign out and revoke this device’s token');
1804
- console.log(' whoami Show the current sign-in');
2591
+ console.log(' whoami Show who is signed in, where, and their workspaces [--json]');
1805
2592
  console.log(' install-claude Teach Claude Code to open Workover links (installs a skill)\n');
1806
2593
  }