@workover/cli 0.15.0 → 0.25.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
+ }
203
282
 
204
- const interval = (start.interval || 5) * 1000;
205
- const deadline = Date.now() + (start.expires_in || 600) * 1000;
206
- process.stdout.write(' Waiting for approval');
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
+ }
355
+
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
  //
@@ -1272,6 +1504,7 @@ async function docCommand() {
1272
1504
  note: typeof flags.note === 'string' ? flags.note : undefined,
1273
1505
  source: 'Workover CLI',
1274
1506
  ...(tabId === null ? {} : { tabId }),
1507
+ ...(flags['allow-block-removal'] === true ? { allowBlockRemoval: true } : {}),
1275
1508
  });
1276
1509
  if (asJson) return console.log(JSON.stringify(res, null, 2));
1277
1510
  console.log(
@@ -1280,6 +1513,9 @@ async function docCommand() {
1280
1513
  if (res?.replacedCharacters) {
1281
1514
  console.log(` Replaced ${res.replacedCharacters} characters of existing text.`);
1282
1515
  }
1516
+ if (Array.isArray(res?.removedBlocks) && res.removedBlocks.length) {
1517
+ console.log(` Removed as asked: ${res.removedBlocks.join(', ')}.`);
1518
+ }
1283
1519
  if (res?.documentUrl) console.log(` ${res.documentUrl}`);
1284
1520
  printTitleHeading(res?.titleHeading);
1285
1521
  printStyleFeedback(res?.style);
@@ -1320,7 +1556,7 @@ async function docCommand() {
1320
1556
  const applied = await authedCall(
1321
1557
  cfg,
1322
1558
  `/project/doc/${docId}/${direct ? 'content' : 'propose'}`,
1323
- { markdown: res.html, note, source: 'Workover CLI' },
1559
+ { markdown: res.html, format: 'html', note, source: 'Workover CLI' },
1324
1560
  );
1325
1561
  if (asJson) return console.log(JSON.stringify({ ...res, applied }, null, 2));
1326
1562
  console.log(
@@ -1379,7 +1615,7 @@ async function docCommand() {
1379
1615
  const applied = await authedCall(
1380
1616
  cfg,
1381
1617
  `/project/doc/${docId}/${direct ? 'content' : 'propose'}`,
1382
- { markdown: res.html, note, source: 'Workover CLI' },
1618
+ { markdown: res.html, format: 'html', note, source: 'Workover CLI' },
1383
1619
  );
1384
1620
  if (asJson) return console.log(JSON.stringify({ ...res, applied }, null, 2));
1385
1621
  console.log(
@@ -1498,6 +1734,73 @@ async function docCommand() {
1498
1734
  return;
1499
1735
  }
1500
1736
 
1737
+ if (sub === 'status') {
1738
+ // The document's WORKOVER status (Triage, In review, Published, or its workflow's own), read or
1739
+ // set through the same rules as the browser's status picker: the project role, the workflow's
1740
+ // gates and the approval a gated status opens (WO-1264). It never touches WordPress: a post goes
1741
+ // live only from the document's WordPress tab, and this says so next to the status.
1742
+ const usage = 'workover doc status <doc> [<status>] [--json]';
1743
+ const docId = await resolveDocArg(cfg, positionals.slice(0, 1), usage);
1744
+ const wanted = positionals[1] ? String(positionals[1]).trim() : '';
1745
+ let res;
1746
+ try {
1747
+ res = await fetch(`${cfg.api}/project/doc/${docId}/status`, {
1748
+ method: wanted ? 'PATCH' : 'GET',
1749
+ headers: {
1750
+ authorization: `Bearer ${cfg.token}`,
1751
+ ...(wanted ? { 'content-type': 'application/json' } : {}),
1752
+ },
1753
+ ...(wanted ? { body: JSON.stringify({ status: wanted }) } : {}),
1754
+ });
1755
+ } catch {
1756
+ console.error(`\n ✗ Couldn't reach Workover at ${cfg.api}\n`);
1757
+ process.exit(1);
1758
+ }
1759
+ const body = await res.json().catch(() => null);
1760
+ if (!res.ok) {
1761
+ if (asJson) console.log(JSON.stringify({ refused: true, httpStatus: res.status, ...(body || {}) }, null, 2));
1762
+ else console.error(`\n ✗ ${statusRefusal(res.status, body)}\n`);
1763
+ process.exit(1);
1764
+ }
1765
+ if (asJson) return console.log(JSON.stringify(body, null, 2));
1766
+ console.log((wanted ? renderStatusChange(body) : renderStatusList(body)).join('\n'));
1767
+ return;
1768
+ }
1769
+
1770
+ if (sub === 'rename') {
1771
+ // The editor's rename, by document id: only the title is sent, so the body cannot change. Needs
1772
+ // `workover login --write`, like `doc write`. A `# Heading` in a written body never renames.
1773
+ const usage = 'workover doc rename <doc> --title "<new title>" [--json]';
1774
+ const docId = await resolveDocArg(cfg, positionals.slice(0, 1), usage);
1775
+ const title = typeof flags.title === 'string' ? flags.title.trim() : '';
1776
+ if (!title) {
1777
+ console.log(`\n Usage: ${usage}`);
1778
+ console.log(' Pass the new name as --title. Only the title changes; the body is left');
1779
+ console.log(' as it is. Needs a token from `workover login --write`.\n');
1780
+ process.exit(1);
1781
+ }
1782
+ let res;
1783
+ try {
1784
+ res = await fetch(`${cfg.api}/project/doc/${docId}/title`, {
1785
+ method: 'PATCH',
1786
+ headers: { authorization: `Bearer ${cfg.token}`, 'content-type': 'application/json' },
1787
+ body: JSON.stringify({ title }),
1788
+ });
1789
+ } catch {
1790
+ console.error(`\n ✗ Couldn't reach Workover at ${cfg.api}\n`);
1791
+ process.exit(1);
1792
+ }
1793
+ const body = await res.json().catch(() => null);
1794
+ if (!res.ok) {
1795
+ if (asJson) console.log(JSON.stringify({ refused: true, httpStatus: res.status, ...(body || {}) }, null, 2));
1796
+ else console.error(`\n ✗ ${renameRefusal(res.status, body)}\n`);
1797
+ process.exit(1);
1798
+ }
1799
+ if (asJson) return console.log(JSON.stringify(body, null, 2));
1800
+ console.log(renderRename(body).join('\n'));
1801
+ return;
1802
+ }
1803
+
1501
1804
  if (sub === 'activity') {
1502
1805
  const docId = await resolveDocArg(cfg, positionals, 'workover doc activity <doc>');
1503
1806
  const limit = rowId(flags.limit) ?? 20;
@@ -1728,12 +2031,464 @@ async function projects() {
1728
2031
  const res = await authedCall(cfg, '/project');
1729
2032
  const list = Array.isArray(res) ? res : res?.projects || [];
1730
2033
  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'}`);
2034
+ // Grouped by workspace with its slug: a Workover URL needs the slug (`/app/<workspace>/p/<id>`),
2035
+ // and the bare list could not tell two workspaces' "Docs" apart.
2036
+ console.log(renderProjects(list).join('\n'));
2037
+ }
2038
+
2039
+ /**
2040
+ * `workover status <project>`: where a project's setup has got to (site, domain, GitHub, reviewer,
2041
+ * what waits in review) and what is left for the person, so an agent can check its own steps
2042
+ * instead of asking (WO-1284).
2043
+ */
2044
+ async function status() {
2045
+ const cfg = requireSignIn();
2046
+ const { flags, positionals } = parseArgs(process.argv.slice(3), { booleans: ['json'] });
2047
+ const id = rowId(flags.project ?? positionals[0] ?? '');
2048
+ if (id === null) {
2049
+ console.error('\n Usage: workover status <projectId> [--json] (ids from `workover projects`)\n');
2050
+ process.exit(1);
2051
+ }
2052
+ const res = await tryAuthedGet(cfg, `/cli-auth/setup/${id}`);
2053
+ if (res.status === 404 && !res.body?.message?.includes('Project')) {
2054
+ console.error(`\n ✗ ${cfg.api} does not offer setup status yet. Update it, or check in the app.\n`);
2055
+ process.exit(1);
2056
+ }
2057
+ if (!res.ok) {
2058
+ const msg = res.body?.message || `HTTP ${res.status}`;
2059
+ console.error(`\n ✗ ${res.status === 404 ? `No project #${id} that you can see.` : msg}\n`);
2060
+ process.exit(1);
2061
+ }
2062
+ if (flags.json === true) return console.log(JSON.stringify(res.body, null, 2));
2063
+ console.log(renderSetupStatus(res.body, { web: webForApi(cfg.api) }).join('\n'));
2064
+ }
2065
+
2066
+ // ------------------------------------------------------------------ Help Center setup
2067
+
2068
+ /**
2069
+ * The api caller the site commands share with the MCP server (site-setup.mjs): resolves the JSON,
2070
+ * or throws an Error with the HTTP status and the api's own sentence, so each command can say what
2071
+ * to do next instead of exiting from deep inside a helper.
2072
+ */
2073
+ const siteCall = (cfg) => async (path, { method, body } = {}) => {
2074
+ let res;
2075
+ try {
2076
+ res = await fetch(`${cfg.api}${path}`, {
2077
+ method: method || 'GET',
2078
+ headers: {
2079
+ authorization: `Bearer ${cfg.token}`,
2080
+ ...(body && !(body instanceof FormData) ? { 'content-type': 'application/json' } : {}),
2081
+ },
2082
+ // A FormData body (a logo upload) goes as it is: fetch sets its multipart boundary.
2083
+ ...(body ? { body: body instanceof FormData ? body : JSON.stringify(body) } : {}),
2084
+ });
2085
+ } catch {
2086
+ throw apiError(0, `Couldn't reach Workover at ${cfg.api}.`);
2087
+ }
2088
+ const text = await res.text();
2089
+ let parsed = null;
2090
+ try {
2091
+ parsed = text ? JSON.parse(text) : null;
2092
+ } catch {
2093
+ /* not JSON */
2094
+ }
2095
+ if (!res.ok) {
2096
+ const m = Array.isArray(parsed?.message) ? parsed.message.join('; ') : parsed?.message;
2097
+ if (res.status === 401) throw apiError(401, 'This sign-in no longer works. Run `workover login --site` again.');
2098
+ throw apiError(res.status, typeof m === 'string' && m ? m : text.slice(0, 300) || `HTTP ${res.status}`);
2099
+ }
2100
+ return parsed;
2101
+ };
2102
+
2103
+ /** Print a refusal the way an agent can act on it, and exit. */
2104
+ const siteFail = (e) => {
2105
+ console.error(`\n ✗ ${e.message}`);
2106
+ const help = e.status === 403 ? scopeHelp(e.message) : null;
2107
+ if (help) console.error(` ${help}`);
2108
+ console.error('');
2109
+ process.exit(1);
2110
+ };
2111
+
2112
+ /** `--wait <seconds>`: how long import and publish wait before handing back "still running". */
2113
+ const waitMs = (flags) => {
2114
+ const n = Number(flags.wait);
2115
+ return Number.isFinite(n) && n >= 0 ? n * 1000 : 110_000;
2116
+ };
2117
+
2118
+ const PROJECT_USAGE = [
2119
+ '',
2120
+ ' Usage: workover project create --name "<name>" [--workspace <slug|id>]',
2121
+ ' [--address <name>] [--start blank|starter|empty] [--json]',
2122
+ '',
2123
+ ' A new project that publishes to a Workover Help Center: the project, its site at',
2124
+ ' <address>.workover.site, and its first pages (blank: one page; starter: the starter',
2125
+ ' template; empty: none, for `workover site import` to fill). Nothing is published.',
2126
+ ' --workspace is needed only when the account has more than one (`workover whoami`).',
2127
+ ' --address defaults to one made from the name; a taken or reserved one gets a free alternative.',
2128
+ ` Needs \`${SITE_LOGIN}\`.`,
2129
+ '',
2130
+ ].join('\n');
2131
+
2132
+ async function projectCommand() {
2133
+ const sub = process.argv[3];
2134
+ if (sub !== 'create') {
2135
+ console.log(PROJECT_USAGE);
2136
+ process.exit(sub ? 1 : 0);
2137
+ }
2138
+ const { flags } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
2139
+ if (typeof flags.name !== 'string' || !flags.name.trim()) {
2140
+ console.log(PROJECT_USAGE);
2141
+ process.exit(1);
2142
+ }
2143
+ const cfg = requireSignIn();
2144
+ try {
2145
+ const res = await createProject(siteCall(cfg), {
2146
+ workspace: flags.workspace ?? flags.org,
2147
+ name: flags.name,
2148
+ address: typeof flags.address === 'string' ? flags.address : undefined,
2149
+ start: typeof flags.start === 'string' ? flags.start : 'blank',
2150
+ });
2151
+ if (flags.json === true) return console.log(JSON.stringify(res, null, 2));
2152
+ console.log(renderProjectCreated(res, { web: webForApi(cfg.api) }).join('\n'));
2153
+ } catch (e) {
2154
+ siteFail(e);
2155
+ }
2156
+ }
2157
+
2158
+ const SITE_USAGE = [
2159
+ '',
2160
+ ' Usage: workover site <command> --project <id>',
2161
+ '',
2162
+ ' create --project <id> [--address <name>] give the project a Workover Help Center',
2163
+ ' at <address>.workover.site (or change its address)',
2164
+ ' import --project <id> --url <docs-url> bring in a public docs site (up to 500',
2165
+ ' [--wait <seconds>] [--status] pages, with its navigation); waits and',
2166
+ ' reports progress, --status only checks',
2167
+ ' import --project <id> --dir <folder> bring in a docs folder: _site.json with',
2168
+ ' <tab>/<slug>.md pages, or Mintlify docs.json.',
2169
+ ' Tabs, groups and order as the config says;',
2170
+ ' pages already there are kept',
2171
+ ' appearance --project <id> [--from <folder>] colors, links and logo: --from reads its',
2172
+ ' [--primary <#hex>] [--logo <file>] _site.json or docs.json, and flags win.',
2173
+ ' [--logo-dark <file>] Also --primary-dark, --search-prompt and',
2174
+ ' [--favicon <file>] --favicon-dark. Unnamed settings are kept',
2175
+ ' redirects --project <id> --from <folder> add the config redirects; never changes or',
2176
+ ' removes one the site has',
2177
+ ' api add --project <id> --spec <url> an API reference tab made from an OpenAPI',
2178
+ ' [--tab "API reference"] spec: a page per endpoint, grouped by tag,',
2179
+ ' [--group <g>] [--directory <dir>] with Try it. The site keeps it in step with',
2180
+ ' the spec (hourly, and on `api sync`) and',
2181
+ ' publishes those pages itself. --spec is an',
2182
+ ' https URL, or {api}/openapi.json for',
2183
+ " Workover's own API",
2184
+ ' api sync --project <id> "the spec changed": sync it now (call it',
2185
+ ' from your deploy, with a site token)',
2186
+ ' api list --project <id> the spec-backed tabs and their last sync',
2187
+ ' api remove --project <id> [--tab <t>] stop following the spec; the pages stay',
2188
+ ' [--group <g>] as ordinary pages',
2189
+ ' domain --project <id> --set <host[/path]> connect docs.example.com, or serve under',
2190
+ ' [--preverify] example.com/docs; prints EVERY DNS record',
2191
+ ' to add. --preverify: TXT records that prove',
2192
+ ' a domain already live elsewhere first.',
2193
+ ' --set none disconnects it',
2194
+ ' [--move-from <id>] take the domain from another Help Center in',
2195
+ ' this workspace in one step: it keeps its',
2196
+ ' verification, the DNS stays as it is, and',
2197
+ ' neither site goes without it',
2198
+ ' domain --project <id> the records again, as they stand',
2199
+ ' check --project <id> ask now: records found, domain verified,',
2200
+ ' certificate issued, and for a path, the',
2201
+ ' live address',
2202
+ ' proxy --project <id> [--platform <name>] for a site under a path: the setup your',
2203
+ ' [--write] [--dir <repo>] website needs, for where it runs (found',
2204
+ ' from its headers, or --platform: cloudflare,',
2205
+ ' vercel, nextjs, cloudfront, amplify, netlify,',
2206
+ ' nginx, caddy, apache). --write adds it to the',
2207
+ ' repository in --dir (default: here)',
2208
+ ' publish --project <id> [--wait <seconds>] put the site live; --status only checks',
2209
+ ' [--status]',
2210
+ ' unpublish --project <id> --yes take the site offline; pages, settings',
2211
+ ' and domain are kept, publish restores it',
2212
+ ' index --project <id> on|off let search engines index the site (the',
2213
+ ' Publish page’s setting; new sites start off)',
2214
+ ' status [--project <id>] the site, its domain, the last import and',
2215
+ ' publish; without --project, which projects',
2216
+ ' have a Help Center',
2217
+ '',
2218
+ ' Every command takes --json. They need a sign-in from',
2219
+ ` \`${SITE_LOGIN}\`: the person approves "Set up and publish your Workover`,
2220
+ ' Help Center" in the browser. Payment and DNS records stay with the person.',
2221
+ ' New projects: `workover project create`. Ids: `workover projects`.',
2222
+ '',
2223
+ ].join('\n');
2224
+
2225
+ async function siteCommand() {
2226
+ const sub = process.argv[3];
2227
+ if (!['create', 'import', 'domain', 'check', 'proxy', 'publish', 'unpublish', 'index', 'status', 'appearance', 'redirects', 'api'].includes(sub)) {
2228
+ console.log(SITE_USAGE);
2229
+ process.exit(sub ? 1 : 0);
2230
+ }
2231
+ const { flags, positionals } = parseArgs(process.argv.slice(4), {
2232
+ booleans: ['json', 'status', 'preverify', 'write', 'yes'],
2233
+ });
2234
+ const cfg = requireSignIn();
2235
+ const call = siteCall(cfg);
2236
+ const json = flags.json === true;
2237
+ const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
2238
+ const apiAction = sub === 'api' ? positionals[0] : null;
2239
+ if (sub === 'api' && !['add', 'sync', 'list', 'remove'].includes(apiAction)) {
2240
+ console.log(SITE_USAGE);
2241
+ process.exit(1);
2242
+ }
2243
+ const projectId = rowId(flags.project ?? (sub === 'index' ? '' : positionals[sub === 'api' ? 1 : 0]) ?? '');
2244
+
2245
+ if (sub === 'status' && projectId === null) {
2246
+ // Which projects have a Help Center, so an agent can find the id without guessing.
2247
+ try {
2248
+ const res = await call('/project');
2249
+ const list = (Array.isArray(res) ? res : res?.projects || []).filter((p) => p.hasSite);
2250
+ if (json) return console.log(JSON.stringify(list, null, 2));
2251
+ if (!list.length) {
2252
+ console.log('\n No project has a Help Center yet. `workover project create --name "<name>"` makes one.\n');
2253
+ return;
2254
+ }
2255
+ console.log('\n Projects with a Help Center:');
2256
+ for (const p of list) console.log(` #${String(p.id).padEnd(6)} ${p.name || p.title || 'Project'}`);
2257
+ console.log('\n `workover site status --project <id>` shows one.\n');
2258
+ return;
2259
+ } catch (e) {
2260
+ return siteFail(e);
2261
+ }
2262
+ }
2263
+ if (projectId === null) {
2264
+ console.log(SITE_USAGE);
2265
+ process.exit(1);
2266
+ }
2267
+
2268
+ try {
2269
+ if (sub === 'create') {
2270
+ const res = await createSite(call, {
2271
+ projectId,
2272
+ address: typeof flags.address === 'string' ? flags.address : undefined,
2273
+ });
2274
+ return out(res, renderSiteCreated(res));
2275
+ }
2276
+ if (sub === 'domain') {
2277
+ if (flags.set === undefined) {
2278
+ const view = await call(`/sites/project/${projectId}`);
2279
+ if (!view?.site) throw apiError(404, `Project #${projectId} has no Help Center. \`workover site create --project ${projectId}\` adds one.`);
2280
+ const guess = view.site.domain?.basePath ? await detectPlatform(call, { projectId }) : {};
2281
+ return out(view.site.domain, renderDomain(view.site.domain, { projectId, ...guess }));
2282
+ }
2283
+ const moveFrom = flags['move-from'];
2284
+ if (moveFrom === true) throw apiError(400, 'Name the project to move the domain from: --move-from <id>.');
2285
+ const res = await setDomain(call, {
2286
+ projectId,
2287
+ address: String(flags.set),
2288
+ preverify: flags.preverify === true,
2289
+ moveFrom: moveFrom === undefined ? null : rowId(String(moveFrom)) ?? String(moveFrom),
2290
+ });
2291
+ if (res.disconnected) return out(res, ['', ` Disconnected the custom domain. The workover.site address keeps working. Remove its DNS records.`, '']);
2292
+ const guess = res.domain?.basePath ? await detectPlatform(call, { projectId }) : {};
2293
+ if (res.movedFrom) return out(res, [...renderMoved(res), ...renderDomain(res.domain, { projectId, ...guess })]);
2294
+ return out(res.domain, renderDomain(res.domain, { projectId, ...guess }));
2295
+ }
2296
+ if (sub === 'proxy') {
2297
+ const view = await call(`/sites/project/${projectId}`);
2298
+ if (!view?.site) throw apiError(404, `Project #${projectId} has no Help Center. \`workover site create --project ${projectId}\` adds one.`);
2299
+ const domain = view.site.domain;
2300
+ const asked = typeof flags.platform === 'string' ? flags.platform.toLowerCase() : null;
2301
+ if (asked && !MOUNT_PLATFORMS.includes(asked)) throw apiError(400, `No setup for "${asked}". One of: ${MOUNT_PLATFORMS.join(', ')}.`);
2302
+ proxyRecipe(domain, MOUNT_PLATFORMS[0]); // throws, with what to do, when the site is not under a path
2303
+ const guess = asked ? { platform: asked, evidence: null } : await detectPlatform(call, { projectId });
2304
+ if (!guess.platform)
2305
+ throw apiError(
2306
+ 400,
2307
+ `Could not tell where ${domain.hostname} runs from its headers. Name it: --platform ${MOUNT_PLATFORMS.join('|')}.`,
2308
+ );
2309
+ const recipe = proxyRecipe(domain, guess.platform);
2310
+ const lines = [''];
2311
+ if (!asked) lines.push(` ${domain.hostname} runs on ${recipe.label}${guess.evidence ? ` (${guess.evidence})` : ''}. \`--platform\` picks another.`, '');
2312
+ lines.push(...renderRecipe(recipe));
2313
+ let written = null;
2314
+ if (flags.write === true) {
2315
+ written = writeRecipe(recipe, typeof flags.dir === 'string' ? flags.dir : process.cwd());
2316
+ lines.push('');
2317
+ if (!written.path) lines.push(` ${written.reason}`);
2318
+ else lines.push(` ${written.changed ? 'Wrote' : 'Already there, unchanged:'} ${written.path}`);
2319
+ if (written.include) lines.push(` Then: ${written.include}`);
2320
+ }
2321
+ lines.push('', ` Once it is live, \`workover site check --project ${projectId}\` loads https://${domain.hostname}${domain.basePath} and says whether it works.`, '');
2322
+ return out({ ...recipe, written, detected: asked ? null : guess }, lines);
2323
+ }
2324
+ if (sub === 'unpublish') {
2325
+ if (flags.yes !== true) {
2326
+ 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`);
2327
+ process.exit(1);
2328
+ }
2329
+ const res = await unpublishSite(call, { projectId });
2330
+ return out(res, renderUnpublish({ projectId }));
2331
+ }
2332
+ if (sub === 'check') {
2333
+ const res = await checkSite(call, { projectId });
2334
+ return out(res, renderCheck(res, { projectId }));
2335
+ }
2336
+ if (sub === 'import' || sub === 'publish') {
2337
+ const path = `/sites/project/${projectId}/${sub}`;
2338
+ const progress = (state) =>
2339
+ json ? undefined : console.error(sub === 'import' ? importProgressLine(state) : publishProgressLine(state));
2340
+ const wait = { timeoutMs: waitMs(flags), onProgress: progress };
2341
+ let state;
2342
+ if (flags.status === true) state = await waitForJob(() => call(path), { ...wait, timeoutMs: 0 });
2343
+ else if (sub === 'import' && typeof flags.dir === 'string') {
2344
+ const plan = readDocsFolder(flags.dir);
2345
+ if (!json) console.error(` Read ${pageCount(plan)} page(s) in ${plan.imports.length} tab(s) from ${plan.dir}.`);
2346
+ const res = await importFolder(call, {
2347
+ projectId,
2348
+ plan,
2349
+ waitFor: (first) => waitForJob(() => call(path), { first, ...wait }),
2350
+ });
2351
+ out({ ...res, layout: plan.layout, pages: pageCount(plan) }, renderFolderImport(res, { projectId, plan }));
2352
+ if (res.status === 'failed') process.exit(1);
2353
+ return;
2354
+ } else if (sub === 'import') {
2355
+ if (typeof flags.url !== 'string') {
2356
+ console.log(SITE_USAGE);
2357
+ process.exit(1);
2358
+ }
2359
+ state = await importSite(call, { projectId, url: flags.url, ...wait });
2360
+ } else state = await publishSite(call, { projectId, ...wait });
2361
+ if (sub === 'import') {
2362
+ out(state, renderImport(state, { projectId }));
2363
+ } else {
2364
+ const site = state?.status === 'done' ? (await call(`/sites/project/${projectId}`))?.site : null;
2365
+ out(state, renderPublish(state, { projectId, site }));
2366
+ }
2367
+ if (state?.status === 'failed') process.exit(1);
2368
+ return;
2369
+ }
2370
+ if (sub === 'appearance') {
2371
+ const plan = typeof flags.from === 'string' ? readDocsFolder(flags.from) : null;
2372
+ const pick = (pairs) =>
2373
+ Object.fromEntries(pairs.filter(([, k]) => typeof flags[k] === 'string').map(([key, k]) => [key, flags[k]]));
2374
+ const appearance = {
2375
+ ...(plan?.appearance ?? {}),
2376
+ ...pick([['primary', 'primary'], ['primaryDark', 'primary-dark'], ['searchPrompt', 'search-prompt']]),
2377
+ };
2378
+ const files = {
2379
+ ...(plan?.assets ?? {}),
2380
+ ...pick([['logoLight', 'logo'], ['logoDark', 'logo-dark'], ['favicon', 'favicon'], ['faviconDark', 'favicon-dark']]),
2381
+ };
2382
+ if (!Object.keys(appearance).length && !Object.keys(files).length) {
2383
+ console.log(SITE_USAGE);
2384
+ process.exit(1);
2385
+ }
2386
+ const res = await setAppearance(call, uploadWith(call), { projectId, appearance, files });
2387
+ return out(res, renderAppearance(res));
2388
+ }
2389
+ if (sub === 'redirects') {
2390
+ if (typeof flags.from !== 'string') {
2391
+ console.log(SITE_USAGE);
2392
+ process.exit(1);
2393
+ }
2394
+ const res = await addRedirects(call, { projectId, redirects: readDocsFolder(flags.from).redirects });
2395
+ return out(res, renderRedirects(res));
2396
+ }
2397
+ if (sub === 'api') {
2398
+ if (apiAction === 'add') {
2399
+ if (typeof flags.spec !== 'string') {
2400
+ console.log(SITE_USAGE);
2401
+ process.exit(1);
2402
+ }
2403
+ const res = await addApiReference(call, {
2404
+ projectId,
2405
+ spec: flags.spec,
2406
+ tab: typeof flags.tab === 'string' ? flags.tab : undefined,
2407
+ group: typeof flags.group === 'string' ? flags.group : undefined,
2408
+ directory: typeof flags.directory === 'string' ? flags.directory : undefined,
2409
+ });
2410
+ out(res, renderApiReferences(res, { projectId, verb: 'add' }));
2411
+ } else if (apiAction === 'remove') {
2412
+ const tab = typeof flags.tab === 'string' ? flags.tab : 'API reference';
2413
+ const group = typeof flags.group === 'string' ? flags.group : undefined;
2414
+ const res = await removeApiReference(call, { projectId, tab, group });
2415
+ 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.`);
2416
+ out(res, ['', ` ✓ "${group ? `${tab} › ${group}` : tab}" no longer follows ${res.spec}. Its ${res.pagesKept} page(s) stay, as ordinary pages.`, '']);
2417
+ } else {
2418
+ const res =
2419
+ apiAction === 'sync' ? await syncApiReferences(call, { projectId }) : await listApiReferences(call, { projectId });
2420
+ out(res, renderApiReferences(res, { projectId, verb: apiAction }));
2421
+ if (apiAction === 'sync' && res.references.some((r) => r.outcome?.status === 'failed')) process.exit(1);
2422
+ }
2423
+ return;
2424
+ }
2425
+ if (sub === 'index') {
2426
+ const want = String(positionals[0] ?? '').toLowerCase();
2427
+ if (!['on', 'off'].includes(want)) {
2428
+ console.log('\n Usage: workover site index --project <id> on|off\n');
2429
+ process.exit(1);
2430
+ }
2431
+ const res = await setIndexing(call, { projectId, index: want === 'on' });
2432
+ return out(res, renderIndexing(res));
2433
+ }
2434
+ if (sub === 'status') {
2435
+ const res = await siteStatus(call, { projectId });
2436
+ return out(res, renderSiteStatus(res, { projectId }));
2437
+ }
2438
+ } catch (e) {
2439
+ siteFail(e);
2440
+ }
2441
+ }
2442
+
2443
+ // ------------------------------------------------------------------ feedback
2444
+
2445
+ const FEEDBACK_USAGE = [
2446
+ '',
2447
+ ' Usage: workover feedback --summary "<one line>" --intent "<what you were doing>"',
2448
+ ' --problem "<what got in the way>" [--fix "<the change you propose>"]',
2449
+ ' [--tool <workover tool or command>] [--kind missing_capability|bug|confusing|docs|other]',
2450
+ ' [--json]',
2451
+ '',
2452
+ ' Tell the Workover team that a Workover command or MCP tool fell short. It is filed as an issue',
2453
+ ' in their tracker. Describe the problem, never the document text, customer data or secrets.',
2454
+ '',
2455
+ ].join('\n');
2456
+
2457
+ /** The CLI's own version, from its package.json, stamped on the report. */
2458
+ const cliVersion = () => {
2459
+ try {
2460
+ return JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8')).version;
2461
+ } catch {
2462
+ return undefined;
2463
+ }
2464
+ };
2465
+
2466
+ async function feedbackCommand() {
2467
+ const { flags } = parseArgs(process.argv.slice(3), { booleans: ['json'] });
2468
+ if (!['summary', 'intent', 'problem'].every((k) => typeof flags[k] === 'string' && flags[k].trim())) {
2469
+ console.log(FEEDBACK_USAGE);
2470
+ process.exit(1);
2471
+ }
2472
+ const cfg = requireSignIn();
2473
+ try {
2474
+ const res = await submitFeedback(
2475
+ siteCall(cfg),
2476
+ {
2477
+ summary: flags.summary,
2478
+ intent: flags.intent,
2479
+ problem: flags.problem,
2480
+ proposedFix: flags.fix,
2481
+ tool: flags.tool,
2482
+ kind: flags.kind,
2483
+ },
2484
+ { surface: 'cli', version: cliVersion() },
2485
+ );
2486
+ if (flags.json) return console.log(JSON.stringify(res, null, 2));
2487
+ console.log(`\n \x1b[32m✓\x1b[0m ${renderFeedbackResult(res).join('\n ')}\n`);
2488
+ } catch (e) {
2489
+ if (e.status === 401) e.message = 'This sign-in no longer works. Run `workover login` again.';
2490
+ siteFail(e);
1735
2491
  }
1736
- console.log('');
1737
2492
  }
1738
2493
 
1739
2494
  /**
@@ -1764,7 +2519,7 @@ function installClaude() {
1764
2519
  const cmd = process.argv[2];
1765
2520
  if (cmd === 'login') await login();
1766
2521
  else if (cmd === 'logout') await logout();
1767
- else if (cmd === 'whoami') whoami();
2522
+ else if (cmd === 'whoami') await whoami();
1768
2523
  else if (cmd === 'draft') await draft();
1769
2524
  else if (cmd === 'draft-set') await draftSet();
1770
2525
  else if (cmd === 'eval') await evaluateDocs();
@@ -1772,6 +2527,10 @@ else if (cmd === 'doc') await docCommand();
1772
2527
  else if (cmd === 'rules') await rulesCommand();
1773
2528
  else if (cmd === 'comments') await commentsCommand();
1774
2529
  else if (cmd === 'projects') await projects();
2530
+ else if (cmd === 'status') await status();
2531
+ else if (cmd === 'project') await projectCommand();
2532
+ else if (cmd === 'site') await siteCommand();
2533
+ else if (cmd === 'feedback') await feedbackCommand();
1775
2534
  else if (cmd === 'install-claude') installClaude();
1776
2535
  else {
1777
2536
  console.log('\n Workover CLI\n');
@@ -1781,8 +2540,13 @@ else {
1781
2540
  console.log(' --draft also request permission to write drafts with AI');
1782
2541
  console.log(' --write also allow direct edits (no suggestions to review)');
1783
2542
  console.log(' --rules also allow changing the style guide');
2543
+ console.log(' --site also allow setting up and publishing a Help Center');
1784
2544
  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');
2545
+ console.log(' --no-wait print the code and link and return at once (for agents);');
2546
+ console.log(' finish with `workover login --resume` once it is approved');
2547
+ console.log(' --json with --no-wait or --resume: JSON only; once signed in, the');
2548
+ console.log(' account (email, name) and its workspaces, to check');
2549
+ console.log(' doc Work on documents: list, read, create, propose, write, rename, search');
1786
2550
  console.log(' plus activity, to see who changed one and how');
1787
2551
  console.log(' plus tabs and tab-new for documents with several bodies');
1788
2552
  console.log(' plus images and image, for image file names and alt text');
@@ -1794,13 +2558,22 @@ else {
1794
2558
  console.log(' workover comments list 123 · workover comments resolve 45');
1795
2559
  console.log(' rules The style guide agents should write by: list, export, add');
1796
2560
  console.log(' workover rules export --project 11 >> AGENTS.md');
1797
- console.log(' projects List the projects you can reach, with their ids');
2561
+ console.log(' projects List the projects you can reach, with their ids and workspaces');
2562
+ console.log(' status Where a project’s setup has got to, and what is left to do');
2563
+ console.log(' workover status 11 [--json]');
2564
+ console.log(' project create: a new project that publishes to a Workover Help Center');
2565
+ console.log(' workover project create --name "Acme Docs" --start empty');
2566
+ console.log(' site Set up a Help Center: create, import, domain, check, publish, status');
2567
+ console.log(' workover site domain --project 11 --set docs.example.com');
2568
+ console.log(' (project and site need `workover login --site`)');
1798
2569
  console.log(' draft Queue a draft in Workover and wait for it');
1799
2570
  console.log(' --type tutorial|how-to|reference|explanation');
1800
2571
  console.log(' draft-set Plan a feature’s whole documentation set, then draft each article');
1801
2572
  console.log(' eval Score a project’s documentation against the editorial rubric');
1802
2573
  console.log(' --org <id> --project <id> [--limit N] [--json]');
2574
+ console.log(' feedback Tell the Workover team a command or tool fell short (files an issue)');
2575
+ console.log(' workover feedback --summary "..." --intent "..." --problem "..." --fix "..."');
1803
2576
  console.log(' logout Sign out and revoke this device’s token');
1804
- console.log(' whoami Show the current sign-in');
2577
+ console.log(' whoami Show who is signed in, where, and their workspaces [--json]');
1805
2578
  console.log(' install-claude Teach Claude Code to open Workover links (installs a skill)\n');
1806
2579
  }