@workover/cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -4
- package/bin/workover.mjs +385 -8
- package/lib.mjs +64 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -11,14 +11,40 @@ npm i -g @workover/cli
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
workover login
|
|
15
|
-
workover
|
|
16
|
-
workover
|
|
14
|
+
workover login # sign in (opens your browser to approve)
|
|
15
|
+
workover login --publish # ...and also request permission to publish to WordPress
|
|
16
|
+
workover login --draft # ...and also request permission to write drafts with AI
|
|
17
|
+
workover draft --org 3 --project 11 "Document the billing flow"
|
|
18
|
+
workover whoami # show the current sign-in
|
|
19
|
+
workover logout # sign out and revoke this device's token
|
|
17
20
|
```
|
|
18
21
|
|
|
19
22
|
`workover login` uses the browser device-authorization flow: it prints a short code, opens your browser, and you approve the connection while signed in to Workover. The token is stored at `~/.workover/config.json` (owner-only) and can be revoked anytime in **Workover → Settings → Developer**.
|
|
20
23
|
|
|
21
|
-
A connected tool can read your documents and propose changes as suggestions you review.
|
|
24
|
+
A connected tool can read your documents and propose changes as suggestions you review. By default it **cannot** publish to WordPress.
|
|
25
|
+
|
|
26
|
+
Pass `--publish` if you want the tool to be able to publish to your connected WordPress sites — useful for an agent building out a documentation set rather than editing one. The browser shows exactly what is being granted before you approve, and even a publishing token **cannot** override a "WordPress is newer" conflict: forcing past someone else's edit needs a person who can go and look.
|
|
27
|
+
|
|
28
|
+
Whatever you grant, a token can never change your account security, your billing, or your other tokens.
|
|
29
|
+
|
|
30
|
+
## Queueing a draft
|
|
31
|
+
|
|
32
|
+
`workover draft` asks Workover to write something; it does not write it itself. Workover reads the
|
|
33
|
+
project's linked GitHub repo for grounding, writes the draft, and captures any screenshots it needs
|
|
34
|
+
by signing in to the app you connected in **Settings → Integrations** — all server-side. The command
|
|
35
|
+
just queues the job and reports progress:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
workover draft --org 3 --project 11 "Write a guide to inviting teammates" --ground yes
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
That division is the point. The tool at your terminal never handles your app's password: it stays
|
|
42
|
+
encrypted in Workover and is decrypted only where the screenshots are taken. Queueing a draft this
|
|
43
|
+
way is the same operation as typing the brief into the prompt box, so an agent can set the work up
|
|
44
|
+
and then review what came back.
|
|
45
|
+
|
|
46
|
+
`--draft` is not granted by default, because a draft spends AI credits and signs in to your
|
|
47
|
+
connected app. The browser says so before you approve.
|
|
22
48
|
|
|
23
49
|
## Coworking with Claude Code
|
|
24
50
|
|
package/bin/workover.mjs
CHANGED
|
@@ -12,9 +12,15 @@ import {
|
|
|
12
12
|
import { homedir } from 'os';
|
|
13
13
|
import { join } from 'path';
|
|
14
14
|
import { spawn } from 'child_process';
|
|
15
|
+
import {
|
|
16
|
+
normalizeApi,
|
|
17
|
+
browserCommand,
|
|
18
|
+
pollDecision,
|
|
19
|
+
summariseEvaluations,
|
|
20
|
+
} from '../lib.mjs';
|
|
15
21
|
|
|
16
22
|
// Point at a different API with WORKOVER_API (e.g. https://api.workover.test for local dev).
|
|
17
|
-
const API = (process.env.WORKOVER_API || 'https://api.workover.dev')
|
|
23
|
+
const API = normalizeApi(process.env.WORKOVER_API || 'https://api.workover.dev');
|
|
18
24
|
const CONFIG_DIR = join(homedir(), '.workover');
|
|
19
25
|
const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
|
|
20
26
|
|
|
@@ -32,9 +38,7 @@ const loadConfig = () => {
|
|
|
32
38
|
};
|
|
33
39
|
|
|
34
40
|
const openBrowser = (url) => {
|
|
35
|
-
const cmd =
|
|
36
|
-
process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
37
|
-
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
|
|
41
|
+
const { cmd, args } = browserCommand(process.platform, url);
|
|
38
42
|
try {
|
|
39
43
|
spawn(cmd, args, { stdio: 'ignore', detached: true }).unref();
|
|
40
44
|
} catch {
|
|
@@ -51,10 +55,50 @@ const post = async (path, body) => {
|
|
|
51
55
|
return res.json().catch(() => ({}));
|
|
52
56
|
};
|
|
53
57
|
|
|
58
|
+
/** An authenticated call against the signed-in API. GET unless a body is given. */
|
|
59
|
+
const authedCall = async (cfg, path, body) => {
|
|
60
|
+
const res = await fetch(`${cfg.api}${path}`, {
|
|
61
|
+
method: body ? 'POST' : 'GET',
|
|
62
|
+
headers: {
|
|
63
|
+
authorization: `Bearer ${cfg.token}`,
|
|
64
|
+
...(body ? { 'content-type': 'application/json' } : {}),
|
|
65
|
+
},
|
|
66
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
67
|
+
});
|
|
68
|
+
const text = await res.text();
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
console.error(`\n ✗ ${res.status} ${text.slice(0, 300)}\n`);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
return text ? JSON.parse(text) : null;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const flagValue = (name) => {
|
|
77
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
78
|
+
return i === -1 ? undefined : process.argv[i + 1];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const requireSignIn = (hint) => {
|
|
82
|
+
const cfg = loadConfig();
|
|
83
|
+
if (!cfg?.token) {
|
|
84
|
+
console.log(` Not signed in. Run \`workover login ${hint}\`.`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
return cfg;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
91
|
+
|
|
54
92
|
async function login() {
|
|
93
|
+
// `--publish` and `--draft` ask for scopes beyond the default. Off unless asked: a login that
|
|
94
|
+
// silently granted them would defeat the point of asking.
|
|
95
|
+
const scopes = ['read', 'propose'];
|
|
96
|
+
if (process.argv.includes('--publish')) scopes.push('publish');
|
|
97
|
+
if (process.argv.includes('--draft')) scopes.push('draft');
|
|
98
|
+
|
|
55
99
|
let start;
|
|
56
100
|
try {
|
|
57
|
-
start = await post('/cli-auth/device/code');
|
|
101
|
+
start = await post('/cli-auth/device/code', { scopes });
|
|
58
102
|
} catch {
|
|
59
103
|
console.error(`\n ✗ Couldn't reach Workover at ${API}\n`);
|
|
60
104
|
process.exit(1);
|
|
@@ -64,6 +108,14 @@ async function login() {
|
|
|
64
108
|
process.exit(1);
|
|
65
109
|
}
|
|
66
110
|
|
|
111
|
+
if (scopes.includes('publish')) {
|
|
112
|
+
console.log('\n Requesting permission to PUBLISH to your connected WordPress sites.');
|
|
113
|
+
}
|
|
114
|
+
if (scopes.includes('draft')) {
|
|
115
|
+
console.log('\n Requesting permission to WRITE DRAFTS with AI. This spends AI credits, and a');
|
|
116
|
+
console.log(' repo-grounded draft also captures screenshots by signing in to your connected');
|
|
117
|
+
console.log(' app with the credential you stored in Workover.');
|
|
118
|
+
}
|
|
67
119
|
console.log(`\n Your login code: \x1b[1m${start.user_code}\x1b[0m`);
|
|
68
120
|
console.log(` Approve it here: ${start.verification_uri_complete}\n`);
|
|
69
121
|
console.log(' Opening your browser…');
|
|
@@ -77,16 +129,17 @@ async function login() {
|
|
|
77
129
|
await new Promise((r) => setTimeout(r, interval));
|
|
78
130
|
process.stdout.write('.');
|
|
79
131
|
const res = await post('/cli-auth/device/token', { device_code: start.device_code });
|
|
80
|
-
|
|
132
|
+
const decision = pollDecision(res);
|
|
133
|
+
if (decision === 'complete') {
|
|
81
134
|
saveConfig({ api: API, token: res.access_token });
|
|
82
135
|
console.log('\n\n \x1b[32m✓\x1b[0m Signed in to Workover.\n');
|
|
83
136
|
return;
|
|
84
137
|
}
|
|
85
|
-
if (
|
|
138
|
+
if (decision === 'denied') {
|
|
86
139
|
console.log('\n\n ✗ Approval was denied.\n');
|
|
87
140
|
process.exit(1);
|
|
88
141
|
}
|
|
89
|
-
if (
|
|
142
|
+
if (decision === 'expired') {
|
|
90
143
|
console.log('\n\n ✗ The code expired. Run `workover login` again.\n');
|
|
91
144
|
process.exit(1);
|
|
92
145
|
}
|
|
@@ -115,14 +168,338 @@ function whoami() {
|
|
|
115
168
|
console.log(` Token: ${cfg.token.slice(0, 12)}… (manage in Workover → Settings → Developer)`);
|
|
116
169
|
}
|
|
117
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Queue a draft and watch it.
|
|
173
|
+
*
|
|
174
|
+
* The CLI only ASKS. Workover does the work: reading the linked repo for grounding, writing, and
|
|
175
|
+
* capturing screenshots by signing in to the connected app with the credential in its vault. That
|
|
176
|
+
* split is deliberate — whatever queues the job never sees the app credential, so this is the same
|
|
177
|
+
* operation as typing the brief into the prompt box, just initiated from a terminal.
|
|
178
|
+
*/
|
|
179
|
+
async function draft() {
|
|
180
|
+
const cfg = loadConfig();
|
|
181
|
+
if (!cfg?.token) {
|
|
182
|
+
console.log(' Not signed in. Run `workover login --draft`.');
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const flag = (name) => {
|
|
187
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
188
|
+
return i === -1 ? undefined : process.argv[i + 1];
|
|
189
|
+
};
|
|
190
|
+
const projectId = Number(flag('project'));
|
|
191
|
+
const organizationId = Number(flag('org'));
|
|
192
|
+
// Everything that is not a flag or a flag's value is the brief.
|
|
193
|
+
const prompt = flag('prompt') ?? process.argv.slice(3).filter((a, i, all) => {
|
|
194
|
+
if (a.startsWith('--')) return false;
|
|
195
|
+
return !all[i - 1]?.startsWith('--');
|
|
196
|
+
}).join(' ');
|
|
197
|
+
|
|
198
|
+
const DOC_TYPES = ['tutorial', 'how-to', 'reference', 'explanation'];
|
|
199
|
+
const docType = flag('type');
|
|
200
|
+
if (docType && !DOC_TYPES.includes(docType)) {
|
|
201
|
+
console.log(`\n ✗ --type must be one of: ${DOC_TYPES.join(', ')}\n`);
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!projectId || !organizationId || !prompt) {
|
|
206
|
+
console.log('\n Usage: workover draft --org <id> --project <id> "<brief>"');
|
|
207
|
+
console.log(' [--ground yes|no|auto] read the linked GitHub repo (default: auto)');
|
|
208
|
+
console.log(' [--type <kind>] tutorial | how-to | reference | explanation');
|
|
209
|
+
console.log(' one Divio type, held throughout the article\n');
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const authed = async (path, init = {}) => {
|
|
214
|
+
const res = await fetch(`${cfg.api}${path}`, {
|
|
215
|
+
...init,
|
|
216
|
+
headers: {
|
|
217
|
+
authorization: `Bearer ${cfg.token}`,
|
|
218
|
+
...(init.body ? { 'content-type': 'application/json' } : {}),
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
const text = await res.text();
|
|
222
|
+
if (res.status === 403 && text.includes('scope')) {
|
|
223
|
+
console.error('\n ✗ This token cannot draft. Run `workover login --draft`.\n');
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
if (!res.ok) {
|
|
227
|
+
console.error(`\n ✗ ${res.status} ${text.slice(0, 300)}\n`);
|
|
228
|
+
process.exit(1);
|
|
229
|
+
}
|
|
230
|
+
return text ? JSON.parse(text) : null;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const job = await authed('/ai/draft', {
|
|
234
|
+
method: 'POST',
|
|
235
|
+
body: JSON.stringify({
|
|
236
|
+
organizationId,
|
|
237
|
+
projectId,
|
|
238
|
+
prompt,
|
|
239
|
+
ground: flag('ground') || 'auto',
|
|
240
|
+
...(docType ? { docType } : {}),
|
|
241
|
+
}),
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
console.log(
|
|
245
|
+
`\n Queued draft #${job.jobId}${job.useRepo ? ' (reading the linked repo)' : ''}.`,
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
// A repo-grounded draft reads many files and may capture screenshots, so minutes is normal.
|
|
249
|
+
const deadline = Date.now() + 20 * 60_000;
|
|
250
|
+
let lastStep = '';
|
|
251
|
+
while (Date.now() < deadline) {
|
|
252
|
+
await new Promise((r) => setTimeout(r, 5_000));
|
|
253
|
+
const state = await authed(
|
|
254
|
+
`/ai/draft/job/${job.jobId}?organizationId=${organizationId}`,
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
// Echo Workover's own progress rather than a spinner: when a draft is slow you want to know
|
|
258
|
+
// whether it is reading the repo or driving a browser, not that it is still alive.
|
|
259
|
+
const step = state.progress?.[state.progress.length - 1];
|
|
260
|
+
if (step && step !== lastStep) {
|
|
261
|
+
console.log(` ${step}`);
|
|
262
|
+
lastStep = step;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (state.status === 'ready') {
|
|
266
|
+
console.log('\n \x1b[32m✓\x1b[0m Draft ready.');
|
|
267
|
+
if (state.grounding?.repo)
|
|
268
|
+
console.log(` Grounded in: ${state.grounding.repo} (${state.grounding.status})`);
|
|
269
|
+
// The number worth checking: whether Workover captured its own screenshots, or only
|
|
270
|
+
// suggested that some would help.
|
|
271
|
+
if (state.screenshots)
|
|
272
|
+
console.log(
|
|
273
|
+
` Screenshots: ${state.screenshots.added} captured${
|
|
274
|
+
state.screenshots.suggested ? ', more suggested' : ''
|
|
275
|
+
}`,
|
|
276
|
+
);
|
|
277
|
+
if (state.documentId) console.log(` Document: ${state.documentId}`);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (state.status === 'failed') {
|
|
281
|
+
console.log(`\n ✗ Draft failed: ${state.error || 'unknown error'}\n`);
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
console.log('\n ✗ Still running after 20 minutes. Check Workover for the job.\n');
|
|
286
|
+
process.exit(1);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Plan a whole documentation set for a feature, then draft each article.
|
|
291
|
+
*
|
|
292
|
+
* Two steps on purpose. The plan is one cheap call and is printed before anything is drafted, so a
|
|
293
|
+
* wrong plan — the wrong types, articles we already publish — costs seconds instead of a dozen
|
|
294
|
+
* grounded drafts. `--dry-run` stops after printing it.
|
|
295
|
+
*/
|
|
296
|
+
async function draftSet() {
|
|
297
|
+
const cfg = loadConfig();
|
|
298
|
+
if (!cfg?.token) {
|
|
299
|
+
console.log(' Not signed in. Run `workover login --draft`.');
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
302
|
+
const flag = (name) => {
|
|
303
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
304
|
+
return i === -1 ? undefined : process.argv[i + 1];
|
|
305
|
+
};
|
|
306
|
+
const organizationId = Number(flag('org'));
|
|
307
|
+
const projectId = Number(flag('project'));
|
|
308
|
+
const feature = flag('feature');
|
|
309
|
+
if (!organizationId || !projectId || !feature) {
|
|
310
|
+
console.log('\n Usage: workover draft-set --org <id> --project <id> --feature "<name>"');
|
|
311
|
+
console.log(' [--kind documentation|content] default: documentation');
|
|
312
|
+
console.log(' [--dry-run] print the plan and stop');
|
|
313
|
+
console.log(' [--yes] skip the confirmation (for scripts)\n');
|
|
314
|
+
process.exit(1);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const call = async (path, body) => {
|
|
318
|
+
const res = await fetch(`${cfg.api}${path}`, {
|
|
319
|
+
method: body ? 'POST' : 'GET',
|
|
320
|
+
headers: {
|
|
321
|
+
authorization: `Bearer ${cfg.token}`,
|
|
322
|
+
...(body ? { 'content-type': 'application/json' } : {}),
|
|
323
|
+
},
|
|
324
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
325
|
+
});
|
|
326
|
+
const text = await res.text();
|
|
327
|
+
if (!res.ok) {
|
|
328
|
+
console.error(`\n ✗ ${res.status} ${text.slice(0, 300)}\n`);
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
return text ? JSON.parse(text) : null;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
const kind = flag('kind') || 'documentation';
|
|
335
|
+
const plan = await call('/ai/doc-set/plan', {
|
|
336
|
+
organizationId,
|
|
337
|
+
projectId,
|
|
338
|
+
feature,
|
|
339
|
+
kind,
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
console.log(`\n ${plan.count} pieces planned for "${plan.feature}" (${plan.kind}):\n`);
|
|
343
|
+
plan.articles.forEach((a, i) => {
|
|
344
|
+
console.log(` ${String(i + 1).padStart(2)}. [${a.docType.padEnd(11)}] ${a.title}`);
|
|
345
|
+
if (a.brief) console.log(` ${a.brief}`);
|
|
346
|
+
});
|
|
347
|
+
// Named, not silently filled: a small feature may genuinely not warrant all four types, and
|
|
348
|
+
// inventing an article to satisfy a checklist is padding.
|
|
349
|
+
if (plan.gaps?.length) console.log(`\n Not covered: ${plan.gaps.join(', ')}`);
|
|
350
|
+
|
|
351
|
+
if (process.argv.includes('--dry-run')) {
|
|
352
|
+
console.log('\n Dry run — nothing drafted.\n');
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Nothing has been drafted yet, and nothing will be until this is answered. A plan is cheap; the
|
|
357
|
+
// drafts are minutes of work and real AI spend each, so the size of the commitment is stated and
|
|
358
|
+
// the default is no.
|
|
359
|
+
if (!process.argv.includes('--yes')) {
|
|
360
|
+
const { createInterface } = await import('node:readline/promises');
|
|
361
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
362
|
+
console.log(
|
|
363
|
+
`\n This will draft ${plan.count} article${plan.count === 1 ? '' : 's'}, each reading the ` +
|
|
364
|
+
`linked repo. That takes a few minutes each and spends AI credits.`,
|
|
365
|
+
);
|
|
366
|
+
console.log(' Drop any you do not want by number, e.g. "1,4" — or press enter to draft all.');
|
|
367
|
+
const answer = (await rl.question(' Draft them? [y/N/numbers to skip] ')).trim();
|
|
368
|
+
rl.close();
|
|
369
|
+
|
|
370
|
+
const skip = new Set(
|
|
371
|
+
answer
|
|
372
|
+
.split(/[\s,]+/)
|
|
373
|
+
.map((s) => Number(s))
|
|
374
|
+
.filter((n) => Number.isInteger(n) && n > 0),
|
|
375
|
+
);
|
|
376
|
+
if (!skip.size && !/^y(es)?$/i.test(answer)) {
|
|
377
|
+
console.log('\n Nothing drafted.\n');
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (skip.size) {
|
|
381
|
+
plan.articles = plan.articles.filter((_, i) => !skip.has(i + 1));
|
|
382
|
+
console.log(`\n Skipping ${skip.size}; drafting ${plan.articles.length}.`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (!plan.articles.length) {
|
|
387
|
+
console.log('\n Nothing left to draft.\n');
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Send back the list as approved — the server drafts exactly this, not the plan it produced.
|
|
392
|
+
const { jobs } = await call('/ai/doc-set/draft', {
|
|
393
|
+
organizationId,
|
|
394
|
+
projectId,
|
|
395
|
+
articles: plan.articles.map((a) => ({
|
|
396
|
+
title: a.title,
|
|
397
|
+
docType: a.docType,
|
|
398
|
+
brief: a.brief,
|
|
399
|
+
})),
|
|
400
|
+
});
|
|
401
|
+
console.log('');
|
|
402
|
+
for (const j of jobs) console.log(` queued #${j.jobId} [${j.docType}] ${j.title}`);
|
|
403
|
+
console.log(`\n ${jobs.length} drafts queued. Watch them in Workover.\n`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Score a project's published documentation against the editorial rubric.
|
|
408
|
+
*
|
|
409
|
+
* The point is the LIST, not the number. Every quality judgement on these docs so far has been made
|
|
410
|
+
* by eye, and by eye a permission-denied screenshot passed, a loading spinner got published, and a
|
|
411
|
+
* reference article citing a service class read fine. A fixed rubric that has to quote the article
|
|
412
|
+
* back at you is the cheapest correction available.
|
|
413
|
+
*
|
|
414
|
+
* The number exists only to answer one question between passes: is the list getting shorter?
|
|
415
|
+
*/
|
|
416
|
+
async function evaluateDocs() {
|
|
417
|
+
const cfg = requireSignIn('--draft');
|
|
418
|
+
const organizationId = Number(flagValue('org'));
|
|
419
|
+
const projectId = Number(flagValue('project'));
|
|
420
|
+
if (!organizationId || !projectId) {
|
|
421
|
+
console.log('\n Usage: workover eval --org <id> --project <id>');
|
|
422
|
+
console.log(' [--limit N] score only the first N documents');
|
|
423
|
+
console.log(' [--json] machine-readable, for diffing between passes\n');
|
|
424
|
+
process.exit(1);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const limit = Number(flagValue('limit')) || 0;
|
|
428
|
+
const asJson = process.argv.includes('--json');
|
|
429
|
+
|
|
430
|
+
const docs = (await authedCall(cfg, `/project/${projectId}/documents`)) || [];
|
|
431
|
+
const targets = (limit ? docs.slice(0, limit) : docs).filter((d) => !d.deletedAt);
|
|
432
|
+
if (!targets.length) {
|
|
433
|
+
console.log('\n No documents to score in that project.\n');
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (!asJson) {
|
|
438
|
+
console.log(`\n Scoring ${targets.length} document(s) — one model call each.\n`);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const results = [];
|
|
442
|
+
for (const [i, doc] of targets.entries()) {
|
|
443
|
+
// Paced deliberately. The AI endpoints allow 20 calls a minute per user, and a project of any
|
|
444
|
+
// size would trip that in the first ten seconds and fail the rest of the run.
|
|
445
|
+
if (i > 0) await sleep(3200);
|
|
446
|
+
try {
|
|
447
|
+
const r = await authedCall(cfg, '/ai/evaluate', {
|
|
448
|
+
organizationId,
|
|
449
|
+
documentId: doc.id,
|
|
450
|
+
});
|
|
451
|
+
results.push(r);
|
|
452
|
+
if (!asJson) {
|
|
453
|
+
const weak = (r.weakest || []).map((w) => `${w.criterion} ${w.score}`).join(', ');
|
|
454
|
+
console.log(` ${String(r.overall).padStart(4)} ${r.title || `#${doc.id}`}`);
|
|
455
|
+
if (weak) console.log(` ${weak}`);
|
|
456
|
+
if (r.topFix) console.log(` → ${r.topFix}`);
|
|
457
|
+
}
|
|
458
|
+
} catch {
|
|
459
|
+
// One unscoreable document must not cost the whole sweep — an empty doc, or a model reply
|
|
460
|
+
// that came back unusable. Reported in the count below rather than swallowed.
|
|
461
|
+
if (!asJson) console.log(` — ${doc.title || `#${doc.id}`} (could not score)`);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (asJson) {
|
|
466
|
+
console.log(JSON.stringify(results, null, 2));
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const summary = summariseEvaluations(results);
|
|
471
|
+
if (!summary.count) {
|
|
472
|
+
console.log('\n Nothing could be scored.\n');
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
console.log(`\n ${summary.count} scored · overall ${summary.overall.toFixed(2)}/5\n`);
|
|
477
|
+
for (const { criterion, mean } of summary.criteria) {
|
|
478
|
+
console.log(` ${criterion.padEnd(20)} ${mean.toFixed(2)} ${'█'.repeat(Math.round(mean * 4))}`);
|
|
479
|
+
}
|
|
480
|
+
console.log(
|
|
481
|
+
`\n ${summary.needingWork} of ${summary.count} would still be changed by a human editor.\n`,
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
118
485
|
const cmd = process.argv[2];
|
|
119
486
|
if (cmd === 'login') await login();
|
|
120
487
|
else if (cmd === 'logout') await logout();
|
|
121
488
|
else if (cmd === 'whoami') whoami();
|
|
489
|
+
else if (cmd === 'draft') await draft();
|
|
490
|
+
else if (cmd === 'draft-set') await draftSet();
|
|
491
|
+
else if (cmd === 'eval') await evaluateDocs();
|
|
122
492
|
else {
|
|
123
493
|
console.log('\n Workover CLI\n');
|
|
124
494
|
console.log(' Usage: workover <command>\n');
|
|
125
495
|
console.log(' login Sign in to Workover (opens your browser to approve)');
|
|
496
|
+
console.log(' --publish also request permission to publish to WordPress');
|
|
497
|
+
console.log(' --draft also request permission to write drafts with AI');
|
|
498
|
+
console.log(' draft Queue a draft in Workover and wait for it');
|
|
499
|
+
console.log(' --type tutorial|how-to|reference|explanation');
|
|
500
|
+
console.log(' draft-set Plan a feature’s whole documentation set, then draft each article');
|
|
501
|
+
console.log(' eval Score a project’s documentation against the editorial rubric');
|
|
502
|
+
console.log(' --org <id> --project <id> [--limit N] [--json]');
|
|
126
503
|
console.log(' logout Sign out and revoke this device’s token');
|
|
127
504
|
console.log(' whoami Show the current sign-in\n');
|
|
128
505
|
}
|
package/lib.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Pure helpers for the Workover CLI, split out so they can be unit-tested without importing
|
|
2
|
+
// bin/workover.mjs (which runs a command + calls process.exit on load).
|
|
3
|
+
|
|
4
|
+
/** Strip trailing slashes from the API base URL (so `${API}${path}` never doubles up). */
|
|
5
|
+
export const normalizeApi = (raw) => (raw || '').replace(/\/+$/, '');
|
|
6
|
+
|
|
7
|
+
/** Map a platform + URL to the browser-open command used to approve the device login. */
|
|
8
|
+
export const browserCommand = (platform, url) => {
|
|
9
|
+
if (platform === 'darwin') return { cmd: 'open', args: [url] };
|
|
10
|
+
if (platform === 'win32') return { cmd: 'cmd', args: ['/c', 'start', '', url] };
|
|
11
|
+
return { cmd: 'xdg-open', args: [url] };
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* RFC 8628 device-token poll: reduce a token-endpoint response to a decision. Anything that isn't a
|
|
16
|
+
* terminal state (complete/denied/expired) is 'pending' → keep polling.
|
|
17
|
+
*/
|
|
18
|
+
export const pollDecision = (res) => {
|
|
19
|
+
const s = res?.status;
|
|
20
|
+
if (s === 'complete') return 'complete';
|
|
21
|
+
if (s === 'denied') return 'denied';
|
|
22
|
+
if (s === 'expired') return 'expired';
|
|
23
|
+
return 'pending';
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Reduce a run of per-document evaluations to the shape a reader can act on.
|
|
28
|
+
*
|
|
29
|
+
* The per-CRITERION mean is the number that matters, and it is deliberately reported before the
|
|
30
|
+
* per-document one. Which article scored worst tells you to go and edit that article; which
|
|
31
|
+
* criterion scored worst tells you what is wrong with how they are all being written — a prompt
|
|
32
|
+
* change moves a column, editing one article moves a row.
|
|
33
|
+
*
|
|
34
|
+
* Averaged over the documents that actually scored each criterion, not over every document. A judge
|
|
35
|
+
* that skipped a criterion has said nothing about it, and counting that as a zero would make the
|
|
36
|
+
* rubric look like it found a problem it never looked for.
|
|
37
|
+
*/
|
|
38
|
+
export const summariseEvaluations = (results) => {
|
|
39
|
+
const scored = (results || []).filter((r) => r && Number.isFinite(r.overall));
|
|
40
|
+
if (!scored.length) {
|
|
41
|
+
return { count: 0, overall: 0, criteria: [], needingWork: 0 };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const byCriterion = new Map();
|
|
45
|
+
for (const r of scored) {
|
|
46
|
+
for (const [criterion, v] of Object.entries(r.scores || {})) {
|
|
47
|
+
if (!Number.isFinite(v?.score)) continue;
|
|
48
|
+
if (!byCriterion.has(criterion)) byCriterion.set(criterion, []);
|
|
49
|
+
byCriterion.get(criterion).push(v.score);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const mean = (xs) => xs.reduce((a, b) => a + b, 0) / xs.length;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
count: scored.length,
|
|
57
|
+
overall: mean(scored.map((r) => r.overall)),
|
|
58
|
+
// Worst first: the top line is what to fix next.
|
|
59
|
+
criteria: [...byCriterion.entries()]
|
|
60
|
+
.map(([criterion, xs]) => ({ criterion, mean: mean(xs), scored: xs.length }))
|
|
61
|
+
.sort((a, b) => a.mean - b.mean || a.criterion.localeCompare(b.criterion)),
|
|
62
|
+
needingWork: scored.filter((r) => (r.weakest || []).length > 0).length,
|
|
63
|
+
};
|
|
64
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workover/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Workover command line — sign in and cowork on your documents from the terminal.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "ScaleMath",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"bin/",
|
|
24
|
+
"lib.mjs",
|
|
24
25
|
"README.md"
|
|
25
26
|
],
|
|
26
27
|
"engines": {
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
"access": "public"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
|
-
"workover": "node bin/workover.mjs"
|
|
34
|
+
"workover": "node bin/workover.mjs",
|
|
35
|
+
"test": "node --test"
|
|
34
36
|
}
|
|
35
37
|
}
|