@clawnitor/cli 1.0.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/LICENSE ADDED
@@ -0,0 +1,66 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: David Kogan
6
+ Licensed Work: Clawnitor
7
+ The Licensed Work is (c) 2026 David Kogan.
8
+ Additional Use Grant: You may make production use of the Licensed Work,
9
+ provided your use does not include offering the
10
+ Licensed Work to third parties as a commercial
11
+ agent monitoring, observability, or safety service
12
+ that competes with the Licensor's offerings.
13
+ Change Date: Four years from the date the Licensed Work is
14
+ published. The specific Change Date will be set
15
+ when the repository is made public.
16
+ Change License: GNU Affero General Public License v3.0 (AGPL-3.0)
17
+
18
+ For information about alternative licensing arrangements for the Licensed
19
+ Work, please contact: david@clawnitor.io
20
+
21
+ Notice
22
+
23
+ Business Source License 1.1
24
+
25
+ Terms
26
+
27
+ The Licensor hereby grants you the right to copy, modify, create
28
+ derivative works, redistribute, and make non-production use of the
29
+ Licensed Work. The Licensor may make an Additional Use Grant, above,
30
+ permitting limited production use.
31
+
32
+ Effective on the Change Date, or the fourth anniversary of the first
33
+ publicly available distribution of a specific version of the Licensed
34
+ Work under this License, whichever comes first, the Licensor hereby
35
+ grants you rights under the terms of the Change License, and the rights
36
+ granted in the paragraph above terminate.
37
+
38
+ If your use of the Licensed Work does not comply with the requirements
39
+ currently in effect as described in this License, you must purchase a
40
+ commercial license from the Licensor, its affiliated entities, or
41
+ authorized resellers, or you must refrain from using the Licensed Work.
42
+
43
+ All copies of the original and modified Licensed Work, and derivative
44
+ works of the Licensed Work, are subject to this License. This License
45
+ applies separately for each version of the Licensed Work and the Change
46
+ Date may vary for each version of the Licensed Work released by
47
+ Licensor.
48
+
49
+ You must conspicuously display this License on each original or modified
50
+ copy of the Licensed Work. If you receive the Licensed Work in original
51
+ or modified form from a third party, the terms and conditions set forth
52
+ in this License apply to your use of that work.
53
+
54
+ Any use of the Licensed Work in violation of this License will
55
+ automatically terminate your rights under this License for the current
56
+ and all other versions of the Licensed Work.
57
+
58
+ This License does not grant you any right in any trademark or logo of
59
+ Licensor or its affiliates (provided that you may use a trademark or
60
+ logo of Licensor as expressly required by this License).
61
+
62
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS
63
+ PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES
64
+ AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION)
65
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
66
+ NON-INFRINGEMENT, AND TITLE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @clawnitor/cli
2
+
3
+ [![npm](https://img.shields.io/npm/v/@clawnitor/cli?color=FF6B4A)](https://www.npmjs.com/package/@clawnitor/cli)
4
+ [![license](https://img.shields.io/badge/license-AGPL--3.0-A78BFA)](LICENSE)
5
+
6
+ CLI for [Clawnitor](https://clawnitor.io) — agent monitoring, rules enforcement, and kill switch for OpenClaw.
7
+
8
+ ## Usage
9
+
10
+ ```bash
11
+ openclaw plugins install @clawnitor/plugin
12
+ npx clawnitor init
13
+ ```
14
+
15
+ `clawnitor init` handles authentication, API key generation, and configuration in one command. Choose GitHub or email magic link to sign in.
16
+
17
+ ```
18
+ $ npx clawnitor init
19
+
20
+ Clawnitor — Agent monitoring for OpenClaw
21
+ by Safer Intelligence Labs
22
+
23
+ How do you want to sign in?
24
+ 1. GitHub
25
+ 2. Email magic link
26
+
27
+ > 1
28
+
29
+ Open this URL: https://github.com/login/device
30
+ Enter code: ABCD-1234
31
+
32
+ Waiting for authorization...
33
+ Authenticated as you@example.com
34
+
35
+ Generating API key...
36
+ Writing to openclaw.json...
37
+
38
+ Done. Clawnitor is monitoring your agents.
39
+ Dashboard: https://app.clawnitor.io
40
+ ```
41
+
42
+ ## What it does
43
+
44
+ 1. Authenticates via GitHub device flow or email magic link
45
+ 2. Creates your Clawnitor account (or logs in if you already have one)
46
+ 3. Generates an API key
47
+ 4. Finds your `openclaw.json` (or creates one) and writes the API key
48
+
49
+ ## Manual setup
50
+
51
+ If you prefer not to use the CLI, sign up at [clawnitor.io](https://clawnitor.io), copy your API key, and add it to your `openclaw.json`:
52
+
53
+ ```json
54
+ {
55
+ "plugins": {
56
+ "entries": {
57
+ "clawnitor": {
58
+ "config": {
59
+ "apiKey": "clw_live_..."
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ ## Links
68
+
69
+ - [Dashboard](https://app.clawnitor.io)
70
+ - [Documentation](https://clawnitor.io/docs)
71
+ - [Interactive Demo](https://clawnitor.io/demo)
72
+ - [Plugin on npm](https://www.npmjs.com/package/@clawnitor/plugin)
@@ -0,0 +1,2 @@
1
+ export declare function githubDeviceAuth(): Promise<string>;
2
+ export declare function getGitHubEmail(token: string): Promise<string>;
@@ -0,0 +1,68 @@
1
+ const GITHUB_CLIENT_ID = "Ov23liNYdX5tPiHxNqx5";
2
+ export async function githubDeviceAuth() {
3
+ // Step 1: Request device code
4
+ const codeRes = await fetch("https://github.com/login/device/code", {
5
+ method: "POST",
6
+ headers: {
7
+ Accept: "application/json",
8
+ "Content-Type": "application/json",
9
+ },
10
+ body: JSON.stringify({
11
+ client_id: GITHUB_CLIENT_ID,
12
+ scope: "user:email",
13
+ }),
14
+ });
15
+ if (!codeRes.ok)
16
+ throw new Error("Failed to start GitHub device flow");
17
+ const codeData = await codeRes.json();
18
+ console.log(`
19
+ Open this URL: ${codeData.verification_uri}
20
+ Enter code: ${codeData.user_code}
21
+ `);
22
+ console.log(" Waiting for authorization...");
23
+ // Step 2: Poll for token
24
+ const interval = (codeData.interval || 5) * 1000;
25
+ const deadline = Date.now() + codeData.expires_in * 1000;
26
+ while (Date.now() < deadline) {
27
+ await new Promise((r) => setTimeout(r, interval));
28
+ const tokenRes = await fetch("https://github.com/login/oauth/access_token", {
29
+ method: "POST",
30
+ headers: {
31
+ Accept: "application/json",
32
+ "Content-Type": "application/json",
33
+ },
34
+ body: JSON.stringify({
35
+ client_id: GITHUB_CLIENT_ID,
36
+ device_code: codeData.device_code,
37
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
38
+ }),
39
+ });
40
+ const tokenData = await tokenRes.json();
41
+ if (tokenData.access_token) {
42
+ return tokenData.access_token;
43
+ }
44
+ if (tokenData.error === "authorization_pending" ||
45
+ tokenData.error === "slow_down") {
46
+ continue;
47
+ }
48
+ if (tokenData.error) {
49
+ throw new Error(`GitHub auth failed: ${tokenData.error}`);
50
+ }
51
+ }
52
+ throw new Error("GitHub authorization timed out");
53
+ }
54
+ export async function getGitHubEmail(token) {
55
+ const res = await fetch("https://api.github.com/user/emails", {
56
+ headers: {
57
+ Authorization: `Bearer ${token}`,
58
+ Accept: "application/vnd.github+json",
59
+ },
60
+ });
61
+ if (!res.ok)
62
+ throw new Error("Failed to get GitHub email");
63
+ const emails = await res.json();
64
+ const primary = emails.find((e) => e.primary);
65
+ if (!primary)
66
+ throw new Error("No primary email found on GitHub account");
67
+ return primary.email;
68
+ }
@@ -0,0 +1,5 @@
1
+ export declare function sendMagicLink(email: string): Promise<string>;
2
+ export declare function pollMagicLink(pollingToken: string): Promise<{
3
+ email: string;
4
+ sessionToken: string;
5
+ }>;
@@ -0,0 +1,34 @@
1
+ const API_URL = process.env.CLAWNITOR_API_URL || "https://api.clawnitor.io";
2
+ export async function sendMagicLink(email) {
3
+ const res = await fetch(`${API_URL}/api/auth/cli-magic-link`, {
4
+ method: "POST",
5
+ headers: { "Content-Type": "application/json" },
6
+ body: JSON.stringify({ email }),
7
+ });
8
+ if (!res.ok) {
9
+ const data = await res.json().catch(() => ({}));
10
+ throw new Error(data.error || "Failed to send magic link");
11
+ }
12
+ const data = await res.json();
13
+ return data.token; // polling token
14
+ }
15
+ export async function pollMagicLink(pollingToken) {
16
+ const deadline = Date.now() + 5 * 60_000; // 5 min timeout
17
+ console.log(" Check your email and click the link.\n");
18
+ console.log(" Waiting...");
19
+ while (Date.now() < deadline) {
20
+ await new Promise((r) => setTimeout(r, 3000));
21
+ const res = await fetch(`${API_URL}/api/auth/cli-magic-link/status`, {
22
+ method: "POST",
23
+ headers: { "Content-Type": "application/json" },
24
+ body: JSON.stringify({ token: pollingToken }),
25
+ });
26
+ if (!res.ok)
27
+ continue;
28
+ const data = await res.json();
29
+ if (data.verified && data.email && data.sessionToken) {
30
+ return { email: data.email, sessionToken: data.sessionToken };
31
+ }
32
+ }
33
+ throw new Error("Magic link timed out. Try again.");
34
+ }
@@ -0,0 +1,2 @@
1
+ export declare function findConfig(): string | null;
2
+ export declare function writeApiKey(apiKey: string): string;
package/dist/config.js ADDED
@@ -0,0 +1,51 @@
1
+ import { readFileSync, writeFileSync, existsSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ const CONFIG_FILE = "openclaw.json";
4
+ const MAX_SEARCH_DEPTH = 5;
5
+ export function findConfig() {
6
+ let dir = process.cwd();
7
+ for (let i = 0; i < MAX_SEARCH_DEPTH; i++) {
8
+ const configPath = join(dir, CONFIG_FILE);
9
+ if (existsSync(configPath))
10
+ return configPath;
11
+ const parent = resolve(dir, "..");
12
+ if (parent === dir)
13
+ break;
14
+ dir = parent;
15
+ }
16
+ return null;
17
+ }
18
+ export function writeApiKey(apiKey) {
19
+ let configPath = findConfig();
20
+ if (configPath) {
21
+ // Update existing config
22
+ const raw = readFileSync(configPath, "utf-8");
23
+ const config = JSON.parse(raw);
24
+ if (!config.plugins)
25
+ config.plugins = {};
26
+ if (!config.plugins.entries)
27
+ config.plugins.entries = {};
28
+ if (!config.plugins.entries.clawnitor)
29
+ config.plugins.entries.clawnitor = {};
30
+ if (!config.plugins.entries.clawnitor.config)
31
+ config.plugins.entries.clawnitor.config = {};
32
+ config.plugins.entries.clawnitor.config.apiKey = apiKey;
33
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
34
+ return configPath;
35
+ }
36
+ // Create new config
37
+ const newPath = join(process.cwd(), CONFIG_FILE);
38
+ const config = {
39
+ plugins: {
40
+ entries: {
41
+ clawnitor: {
42
+ config: {
43
+ apiKey: apiKey,
44
+ },
45
+ },
46
+ },
47
+ },
48
+ };
49
+ writeFileSync(newPath, JSON.stringify(config, null, 2) + "\n");
50
+ return newPath;
51
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import { init } from "./init.js";
3
+ const command = process.argv[2];
4
+ if (command === "init") {
5
+ init().catch((err) => {
6
+ console.error("\n Error:", err.message);
7
+ process.exit(1);
8
+ });
9
+ }
10
+ else {
11
+ console.log(`
12
+ Clawnitor CLI — Agent monitoring for OpenClaw
13
+
14
+ Commands:
15
+ init Set up Clawnitor (authenticate + configure API key)
16
+
17
+ Usage:
18
+ npx clawnitor init
19
+ `);
20
+ }
package/dist/init.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function init(): Promise<void>;
package/dist/init.js ADDED
@@ -0,0 +1,74 @@
1
+ import { createInterface } from "node:readline";
2
+ import { githubDeviceAuth, getGitHubEmail } from "./auth/github-device.js";
3
+ import { sendMagicLink, pollMagicLink } from "./auth/magic-link.js";
4
+ import { writeApiKey } from "./config.js";
5
+ const API_URL = process.env.CLAWNITOR_API_URL || "https://api.clawnitor.io";
6
+ function ask(question) {
7
+ const rl = createInterface({
8
+ input: process.stdin,
9
+ output: process.stdout,
10
+ });
11
+ return new Promise((resolve) => {
12
+ rl.question(question, (answer) => {
13
+ rl.close();
14
+ resolve(answer.trim());
15
+ });
16
+ });
17
+ }
18
+ async function provisionAndGetKey(email) {
19
+ // Provision user (creates account if new)
20
+ const provisionRes = await fetch(`${API_URL}/api/auth/cli-provision`, {
21
+ method: "POST",
22
+ headers: { "Content-Type": "application/json" },
23
+ body: JSON.stringify({ email }),
24
+ });
25
+ if (!provisionRes.ok) {
26
+ const data = await provisionRes.json().catch(() => ({}));
27
+ throw new Error(data.error || "Failed to provision account");
28
+ }
29
+ const { apiKey } = (await provisionRes.json());
30
+ return apiKey;
31
+ }
32
+ export async function init() {
33
+ console.log(`
34
+ Clawnitor — Agent monitoring for OpenClaw
35
+ by Safer Intelligence Labs
36
+ `);
37
+ const method = await ask(" How do you want to sign in?\n 1. GitHub\n 2. Email magic link\n\n > ");
38
+ let email;
39
+ if (method === "1" || method.toLowerCase() === "github") {
40
+ // GitHub device flow
41
+ const githubToken = await githubDeviceAuth();
42
+ email = await getGitHubEmail(githubToken);
43
+ console.log(`\n Authenticated as ${email}`);
44
+ }
45
+ else if (method === "2" ||
46
+ method.toLowerCase() === "email" ||
47
+ method.toLowerCase() === "magic") {
48
+ // Magic link flow
49
+ email = await ask("\n Email: ");
50
+ if (!email || !email.includes("@")) {
51
+ throw new Error("Invalid email");
52
+ }
53
+ const pollingToken = await sendMagicLink(email);
54
+ const result = await pollMagicLink(pollingToken);
55
+ email = result.email;
56
+ console.log(`\n Authenticated as ${email}`);
57
+ }
58
+ else {
59
+ throw new Error('Pick 1 or 2');
60
+ }
61
+ // Provision account and get API key
62
+ console.log("\n Generating API key...");
63
+ const apiKey = await provisionAndGetKey(email);
64
+ // Write to config
65
+ console.log(" Writing to openclaw.json...");
66
+ const configPath = writeApiKey(apiKey);
67
+ console.log(`
68
+ Done. Clawnitor is monitoring your agents.
69
+
70
+ Config: ${configPath}
71
+ Dashboard: https://app.clawnitor.io
72
+ Docs: https://clawnitor.io/docs
73
+ `);
74
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@clawnitor/cli",
3
+ "version": "1.0.0",
4
+ "description": "CLI for Clawnitor — agent monitoring for OpenClaw. Authenticate, generate API keys, and configure from the terminal.",
5
+ "type": "module",
6
+ "bin": {
7
+ "clawnitor": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "README.md"
12
+ ],
13
+ "keywords": [
14
+ "clawnitor",
15
+ "openclaw",
16
+ "agent",
17
+ "monitoring",
18
+ "cli",
19
+ "safety"
20
+ ],
21
+ "author": "David Kogan",
22
+ "license": "AGPL-3.0",
23
+ "homepage": "https://clawnitor.io",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/davidkny22/clawnitor"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^25.5.0",
33
+ "tsx": "^4.19.0",
34
+ "typescript": "^5.7.0"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc",
38
+ "dev": "tsx src/index.ts"
39
+ }
40
+ }