@workover/cli 0.1.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.
Files changed (3) hide show
  1. package/README.md +39 -0
  2. package/bin/workover.mjs +128 -0
  3. package/package.json +35 -0
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @workover/cli
2
+
3
+ The command line for [Workover](https://workover.dev) — sign in from your terminal so tools like Claude Code can read and cowork on your documents.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm i -g @workover/cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```sh
14
+ workover login # sign in (opens your browser to approve)
15
+ workover whoami # show the current sign-in
16
+ workover logout # sign out and revoke this device's token
17
+ ```
18
+
19
+ `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
+
21
+ A connected tool can read your documents and propose changes as suggestions you review. It **cannot** publish to WordPress or change your account security.
22
+
23
+ ## Coworking with Claude Code
24
+
25
+ Pair it with the [Workover MCP server](https://www.npmjs.com/package/@workover/mcp):
26
+
27
+ ```sh
28
+ claude mcp add workover -- npx -y @workover/mcp
29
+ ```
30
+
31
+ Then ask Claude Code to read or revise a document — its edits appear in Workover as tracked-change suggestions you accept or reject.
32
+
33
+ ## Configuration
34
+
35
+ - `WORKOVER_API` — point the CLI at a different Workover API (defaults to `https://api.workover.dev`).
36
+
37
+ ---
38
+
39
+ © ScaleMath. All rights reserved.
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+ // Workover CLI — Phase 1: `login` / `logout` / `whoami` via the device-authorization flow (RFC 8628).
3
+ // Auth only for now; document/coworking commands (and the MCP server) build on the stored token.
4
+ import {
5
+ readFileSync,
6
+ writeFileSync,
7
+ mkdirSync,
8
+ existsSync,
9
+ chmodSync,
10
+ rmSync,
11
+ } from 'fs';
12
+ import { homedir } from 'os';
13
+ import { join } from 'path';
14
+ import { spawn } from 'child_process';
15
+
16
+ // 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').replace(/\/+$/, '');
18
+ const CONFIG_DIR = join(homedir(), '.workover');
19
+ const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
20
+
21
+ const saveConfig = (cfg) => {
22
+ mkdirSync(CONFIG_DIR, { recursive: true });
23
+ writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2));
24
+ chmodSync(CONFIG_FILE, 0o600); // owner read/write only — it holds a bearer token
25
+ };
26
+ const loadConfig = () => {
27
+ try {
28
+ return JSON.parse(readFileSync(CONFIG_FILE, 'utf8'));
29
+ } catch {
30
+ return null;
31
+ }
32
+ };
33
+
34
+ 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];
38
+ try {
39
+ spawn(cmd, args, { stdio: 'ignore', detached: true }).unref();
40
+ } catch {
41
+ /* the URL is printed anyway */
42
+ }
43
+ };
44
+
45
+ const post = async (path, body) => {
46
+ const res = await fetch(`${API}${path}`, {
47
+ method: 'POST',
48
+ headers: { 'content-type': 'application/json' },
49
+ body: body ? JSON.stringify(body) : undefined,
50
+ });
51
+ return res.json().catch(() => ({}));
52
+ };
53
+
54
+ async function login() {
55
+ let start;
56
+ try {
57
+ start = await post('/cli-auth/device/code');
58
+ } catch {
59
+ console.error(`\n ✗ Couldn't reach Workover at ${API}\n`);
60
+ process.exit(1);
61
+ }
62
+ if (!start?.device_code) {
63
+ console.error('\n ✗ Unexpected response from Workover. Try again.\n');
64
+ process.exit(1);
65
+ }
66
+
67
+ console.log(`\n Your login code: \x1b[1m${start.user_code}\x1b[0m`);
68
+ console.log(` Approve it here: ${start.verification_uri_complete}\n`);
69
+ console.log(' Opening your browser…');
70
+ openBrowser(start.verification_uri_complete);
71
+
72
+ const interval = (start.interval || 5) * 1000;
73
+ const deadline = Date.now() + (start.expires_in || 600) * 1000;
74
+ process.stdout.write(' Waiting for approval');
75
+
76
+ while (Date.now() < deadline) {
77
+ await new Promise((r) => setTimeout(r, interval));
78
+ process.stdout.write('.');
79
+ const res = await post('/cli-auth/device/token', { device_code: start.device_code });
80
+ if (res.status === 'complete') {
81
+ saveConfig({ api: API, token: res.access_token });
82
+ console.log('\n\n \x1b[32m✓\x1b[0m Signed in to Workover.\n');
83
+ return;
84
+ }
85
+ if (res.status === 'denied') {
86
+ console.log('\n\n ✗ Approval was denied.\n');
87
+ process.exit(1);
88
+ }
89
+ if (res.status === 'expired') {
90
+ console.log('\n\n ✗ The code expired. Run `workover login` again.\n');
91
+ process.exit(1);
92
+ }
93
+ }
94
+ console.log('\n\n ✗ Timed out waiting for approval. Run `workover login` again.\n');
95
+ process.exit(1);
96
+ }
97
+
98
+ async function logout() {
99
+ const cfg = loadConfig();
100
+ if (cfg?.token) {
101
+ // Best-effort server-side revoke (possessing the token authorizes revoking it).
102
+ await post('/cli-auth/logout', { token: cfg.token }).catch(() => {});
103
+ }
104
+ if (existsSync(CONFIG_FILE)) rmSync(CONFIG_FILE);
105
+ console.log(' Signed out.');
106
+ }
107
+
108
+ function whoami() {
109
+ const cfg = loadConfig();
110
+ if (!cfg?.token) {
111
+ console.log(' Not signed in. Run `workover login`.');
112
+ process.exit(1);
113
+ }
114
+ console.log(` Signed in to ${cfg.api}`);
115
+ console.log(` Token: ${cfg.token.slice(0, 12)}… (manage in Workover → Settings → Developer)`);
116
+ }
117
+
118
+ const cmd = process.argv[2];
119
+ if (cmd === 'login') await login();
120
+ else if (cmd === 'logout') await logout();
121
+ else if (cmd === 'whoami') whoami();
122
+ else {
123
+ console.log('\n Workover CLI\n');
124
+ console.log(' Usage: workover <command>\n');
125
+ console.log(' login Sign in to Workover (opens your browser to approve)');
126
+ console.log(' logout Sign out and revoke this device’s token');
127
+ console.log(' whoami Show the current sign-in\n');
128
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@workover/cli",
3
+ "version": "0.1.0",
4
+ "description": "Workover command line — sign in and cowork on your documents from the terminal.",
5
+ "license": "UNLICENSED",
6
+ "author": "ScaleMath",
7
+ "homepage": "https://workover.dev",
8
+ "bugs": {
9
+ "url": "https://workover.dev"
10
+ },
11
+ "keywords": [
12
+ "workover",
13
+ "cli",
14
+ "documents",
15
+ "wordpress",
16
+ "ai"
17
+ ],
18
+ "type": "module",
19
+ "bin": {
20
+ "workover": "bin/workover.mjs"
21
+ },
22
+ "files": [
23
+ "bin/",
24
+ "README.md"
25
+ ],
26
+ "engines": {
27
+ "node": ">=20"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "workover": "node bin/workover.mjs"
34
+ }
35
+ }