@oked/openclaw-cli 0.6.23 → 0.6.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,31 +3,33 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@oked/openclaw-cli.svg)](https://www.npmjs.com/package/@oked/openclaw-cli)
4
4
  [![License: Apache-2.0](https://img.shields.io/npm/l/@oked/openclaw-cli.svg)](./LICENSE)
5
5
 
6
- Installer for the [`@oked/openclaw`](../openclaw) plugin. It runs `openclaw plugins install`, writes the OKed entry into `~/.openclaw/openclaw.json`, and can restart the gateway.
6
+ Pairing CLI for the [`@oked/openclaw`](../openclaw) plugin. Install the plugin with `openclaw plugins install npm:@oked/openclaw`, then use this CLI to pair the device, write the OKed entry into `~/.openclaw/openclaw.json`, and restart the gateway. The plugin requires OpenClaw 2026.5.4 or newer.
7
7
 
8
8
  Approvals are decided in Telegram and on the [web dashboard](https://oked.ai/dashboard). The iPhone app is coming soon.
9
9
 
10
10
  ## Install
11
11
 
12
12
  ```bash
13
- npm install -g @oked/openclaw @oked/openclaw-cli
13
+ openclaw plugins install npm:@oked/openclaw
14
+ npm install -g @oked/openclaw-cli
14
15
  oked-openclaw init
15
16
  ```
16
17
 
18
+ Once the package is listed on ClawHub, `openclaw plugins install @oked/openclaw` installs it from there.
19
+
17
20
  `openclaw` must already be on your PATH. `init` then:
18
21
 
19
- 1. Finds the plugin (a sibling `packages/openclaw` in this monorepo, or the global `@oked/openclaw` install).
20
- 2. Runs `openclaw plugins install --link <path>`.
21
- 3. Reuses `OKED_API_KEY` or an existing `plugins.entries.oked.apiKey`. Otherwise it pairs this device in the browser and saves the key to `~/.oked/config.json`. It does not ask you to paste a key.
22
- 4. Keeps `OKED_MIN_TIER` or an existing `minTier` when one is set. Otherwise a terminal asks (default `review`), and a non-interactive run uses `review`. Accepted values are `safe`, `warning`, `review`, and `high_stakes`.
23
- 5. Adds `"oked"` to `plugins.allow` and writes `plugins.entries.oked` with `enabled`, `apiKey`, and `minTier`. Existing keys on that entry are kept.
24
- 6. Looks for a running gateway (systemd user or system, pm2, launchd, or a bare process) and asks before restarting it.
22
+ 1. If a local checkout or a global npm copy of `@oked/openclaw` is present, runs `openclaw plugins install --link <path>`. If the plugin is already installed and no local copy is present, skips install. Otherwise it tries `openclaw plugins install @oked/openclaw` (ClawHub). If that fails, it retries `openclaw plugins install npm:@oked/openclaw`.
23
+ 2. Reuses `OKED_API_KEY` or an existing `plugins.entries.oked.apiKey`. Otherwise it pairs this device in the browser and saves the key to `~/.oked/config.json`. It does not ask you to paste a key.
24
+ 3. Keeps `OKED_MIN_TIER` or an existing `minTier` when one is set. Otherwise a terminal asks (default `review`), and a non-interactive run uses `review`. Accepted values are `safe`, `warning`, `review`, and `high_stakes`.
25
+ 4. Adds `"oked"` to `plugins.allow` and writes `plugins.entries.oked` with `enabled`, `apiKey`, and `minTier`. Existing keys on that entry are kept.
26
+ 5. Looks for a running gateway (systemd user or system, pm2, launchd, or a bare process) and asks before restarting it.
25
27
 
26
28
  ## Subcommands
27
29
 
28
30
  | Command | Description |
29
31
  |---|---|
30
- | `oked-openclaw init` | Install the plugin and update `openclaw.json` |
32
+ | `oked-openclaw init` | Install the plugin if needed, pair this device, and update `openclaw.json` |
31
33
  | `oked-openclaw status` | Show install state, config, and whether `GET /health` on the backend succeeds |
32
34
  | `oked-openclaw test` | Send one `high_stakes` approval. Decide it in Telegram or on the dashboard. |
33
35
  | `oked-openclaw uninstall` | Remove the OKed entry and run `openclaw plugins uninstall oked` |
@@ -3,7 +3,9 @@
3
3
  * @oked/openclaw-cli - installer for the @oked/openclaw plugin.
4
4
  *
5
5
  * Subcommands:
6
- * oked-openclaw init Install the plugin via `openclaw plugins install`,
6
+ * oked-openclaw init Install the plugin if needed (`openclaw plugins install
7
+ * @oked/openclaw`, then `npm:@oked/openclaw` if ClawHub
8
+ * fails, or `--link` for a local copy),
7
9
  * persist API key + minTier into ~/.openclaw/openclaw.json,
8
10
  * and restart the OpenClaw gateway daemon.
9
11
  * oked-openclaw status Print install state, config, and backend reachability.
@@ -14,7 +16,7 @@
14
16
  import { readFile, writeFile, mkdir, access, chmod } from 'node:fs/promises';
15
17
  import { homedir, hostname, platform } from 'node:os';
16
18
  import path from 'node:path';
17
- import { fileURLToPath } from 'node:url';
19
+ import { fileURLToPath, pathToFileURL } from 'node:url';
18
20
  import readline from 'node:readline/promises';
19
21
  import { stdin as input, stdout as output } from 'node:process';
20
22
  import { spawn, spawnSync } from 'node:child_process';
@@ -274,6 +276,65 @@ function detectDaemon() {
274
276
 
275
277
  // --- commands -------------------------------------------------------------
276
278
 
279
+ /** Bare package name. OpenClaw resolves this from ClawHub only, with no npm fallback. */
280
+ export const CLAWHUB_INSTALL_ARGS = ['plugins', 'install', '@oked/openclaw'];
281
+ /** npm specifier. Used when the ClawHub install fails. */
282
+ export const NPM_INSTALL_ARGS = ['plugins', 'install', 'npm:@oked/openclaw'];
283
+ /** Printed when both registry installs fail. */
284
+ export const NPM_INSTALL_HINT = 'openclaw plugins install npm:@oked/openclaw';
285
+
286
+ /**
287
+ * Decide how init installs the plugin.
288
+ * A local checkout or global npm copy stays on `--link`.
289
+ * An already installed plugin with no local copy is left in place so pairing
290
+ * does not replace a ClawHub install. Otherwise try ClawHub, then npm.
291
+ */
292
+ export function resolvePluginInstall({ pluginPath, alreadyInstalled }) {
293
+ if (pluginPath) {
294
+ return {
295
+ kind: 'link',
296
+ args: ['plugins', 'install', '--link', pluginPath],
297
+ fallbacks: [],
298
+ };
299
+ }
300
+ if (alreadyInstalled) return { kind: 'skip', args: [], fallbacks: [] };
301
+ return {
302
+ kind: 'clawhub',
303
+ args: CLAWHUB_INSTALL_ARGS,
304
+ fallbacks: [NPM_INSTALL_ARGS],
305
+ };
306
+ }
307
+
308
+ /**
309
+ * Run install argv lists in order. The first exit code 0 stops the sequence.
310
+ * `run` receives the argv after `openclaw` and returns an exit code.
311
+ * When the npm specifier was tried and every attempt failed, `hint` is the
312
+ * command a person can run by hand.
313
+ */
314
+ export async function runInstallAttempts(attempts, run) {
315
+ const calls = [];
316
+ for (const args of attempts) {
317
+ const code = await run(args);
318
+ calls.push({ args: args.slice(), code });
319
+ if (code === 0) return { ok: true, code: 0, calls, hint: null };
320
+ }
321
+ const code = calls.length ? calls[calls.length - 1].code : -1;
322
+ const triedNpm = calls.some((call) => call.args.includes('npm:@oked/openclaw'));
323
+ return {
324
+ ok: false,
325
+ code,
326
+ calls,
327
+ hint: triedNpm ? NPM_INSTALL_HINT : null,
328
+ };
329
+ }
330
+
331
+ function pluginAlreadyInstalled() {
332
+ if (!commandExists('openclaw')) return false;
333
+ const listed = run('openclaw', ['plugins', 'list']);
334
+ if (listed.code !== 0) return false;
335
+ return /\boked\b/.test(listed.stdout) && !/\boked\b.*not\s+found/i.test(listed.stdout);
336
+ }
337
+
277
338
  async function cmdInit() {
278
339
  console.log('\nOKed -> OpenClaw plugin installer\n');
279
340
 
@@ -283,29 +344,54 @@ async function cmdInit() {
283
344
  process.exit(1);
284
345
  }
285
346
 
286
- // 1. Find the plugin source.
347
+ // 1. Find a local copy, or plan ClawHub then npm.
287
348
  process.stdout.write('1. Locating @oked/openclaw plugin... ');
288
349
  const pluginPath = await findPluginPath();
289
- if (!pluginPath) {
290
- console.log('failed');
291
- console.error('\nCould not find a sibling packages/openclaw with openclaw.plugin.json.');
292
- console.error('If you cloned the monorepo, run this from inside it. Otherwise install');
293
- console.error('@oked/openclaw globally first: npm install -g @oked/openclaw\n');
294
- process.exit(1);
350
+ const plan = resolvePluginInstall({
351
+ pluginPath,
352
+ alreadyInstalled: pluginPath ? false : pluginAlreadyInstalled(),
353
+ });
354
+ if (plan.kind === 'link') {
355
+ console.log('found');
356
+ console.log(` Path: ${pluginPath}\n`);
357
+ } else if (plan.kind === 'skip') {
358
+ console.log('already installed');
359
+ console.log(' Leaving the current install in place.\n');
360
+ } else {
361
+ console.log('not on disk');
362
+ console.log(' Will try ClawHub: openclaw plugins install @oked/openclaw');
363
+ console.log(' If that fails: openclaw plugins install npm:@oked/openclaw\n');
295
364
  }
296
- console.log('found');
297
- console.log(` Path: ${pluginPath}\n`);
298
365
 
299
366
  // 2. Register the plugin with OpenClaw.
300
- console.log('2. Installing into OpenClaw...');
301
- const installArgs = ['plugins', 'install', '--link', pluginPath];
302
- console.log(` $ openclaw ${installArgs.join(' ')}`);
303
- const installCode = await runStreaming('openclaw', installArgs);
304
- if (installCode !== 0) {
305
- console.error(`\n X openclaw plugins install exited ${installCode}.`);
306
- process.exit(installCode);
367
+ if (plan.kind === 'skip') {
368
+ console.log('2. Plugin is already installed. Skipping install.\n');
369
+ } else {
370
+ console.log('2. Installing into OpenClaw...');
371
+ const attempts = [plan.args, ...(plan.fallbacks || [])];
372
+ let attempt = 0;
373
+ const result = await runInstallAttempts(attempts, async (args) => {
374
+ if (attempt > 0) {
375
+ console.log(' ClawHub install failed. Retrying from npm.');
376
+ }
377
+ attempt += 1;
378
+ console.log(` $ openclaw ${args.join(' ')}`);
379
+ return runStreaming('openclaw', args);
380
+ });
381
+ if (!result.ok) {
382
+ const present = plan.kind === 'clawhub' && pluginAlreadyInstalled();
383
+ if (!present) {
384
+ console.error(`\n X openclaw plugins install exited ${result.code}.`);
385
+ if (result.hint) {
386
+ console.error(` Install with: ${result.hint}\n`);
387
+ }
388
+ process.exit(result.code);
389
+ }
390
+ console.log(' Already installed. Continuing.\n');
391
+ } else {
392
+ console.log('');
393
+ }
307
394
  }
308
- console.log('');
309
395
 
310
396
  // 3. API key - reuse existing if present, otherwise pair this device.
311
397
  const existing = await readConfig();
@@ -513,10 +599,10 @@ async function cmdUninstall() {
513
599
  }
514
600
 
515
601
  function usage() {
516
- console.log(`oked-openclaw - installer for the @oked/openclaw plugin
602
+ console.log(`oked-openclaw - pairing CLI for the @oked/openclaw plugin
517
603
 
518
604
  Usage:
519
- oked-openclaw init Install the plugin and configure openclaw.json
605
+ oked-openclaw init Install the plugin if needed, then configure openclaw.json
520
606
  oked-openclaw status Show install state + backend reachability
521
607
  oked-openclaw uninstall Remove the OKed entry and uninstall the plugin
522
608
  oked-openclaw test Send a test approval request via the OKed SDK
@@ -552,7 +638,12 @@ async function main() {
552
638
  }
553
639
  }
554
640
 
555
- main().catch((err) => {
556
- console.error(`oked-openclaw: ${err.message}`);
557
- process.exit(1);
558
- });
641
+ const isDirectRun =
642
+ process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
643
+
644
+ if (isDirectRun) {
645
+ main().catch((err) => {
646
+ console.error(`oked-openclaw: ${err.message}`);
647
+ process.exit(1);
648
+ });
649
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/openclaw-cli",
3
- "version": "0.6.23",
3
+ "version": "0.6.25",
4
4
  "description": "Installer CLI for the @oked/openclaw plugin. Wraps `openclaw plugins install` and configures the plugin entry in openclaw.json.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,10 +11,10 @@
11
11
  "README.md"
12
12
  ],
13
13
  "scripts": {
14
- "test": "node --check bin/oked-openclaw.mjs"
14
+ "test": "node --check bin/oked-openclaw.mjs && node test/install-plan.test.mjs"
15
15
  },
16
16
  "dependencies": {
17
- "@oked/sdk": "0.6.23"
17
+ "@oked/sdk": "0.6.25"
18
18
  },
19
19
  "keywords": [
20
20
  "openclaw",