@opennous/cli 0.2.0 → 0.5.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 (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +90 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opennous/cli",
3
- "version": "0.2.0",
3
+ "version": "0.5.0",
4
4
  "description": "Nous CLI — install Nous event tracking into your app, plus terminal access to the Context API",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,10 +12,10 @@
12
12
  "start": "node src/index.js"
13
13
  },
14
14
  "keywords": ["nous", "crm", "cli", "agents", "memory", "observability", "stripe"],
15
- "license": "AGPL-3.0",
15
+ "license": "AGPL-3.0-only",
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/bennetglinder1/nous.git",
18
+ "url": "https://github.com/NousC/nous.git",
19
19
  "directory": "apps/cli"
20
20
  },
21
21
  "homepage": "https://opennous.cloud",
package/src/index.js CHANGED
@@ -10,6 +10,17 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync, appendFileSync } fr
10
10
  import { homedir } from "os";
11
11
  import { join, resolve } from "path";
12
12
  import { createInterface } from "readline";
13
+ import { spawn } from "child_process";
14
+
15
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
16
+
17
+ // Best-effort open the user's browser; if it fails they have the printed URL.
18
+ function openBrowser(url) {
19
+ const cmd = process.platform === "darwin" ? "open"
20
+ : process.platform === "win32" ? "start"
21
+ : "xdg-open";
22
+ try { spawn(cmd, [url], { stdio: "ignore", detached: true }).unref(); } catch { /* printed URL is the fallback */ }
23
+ }
13
24
 
14
25
  const CONFIG_PATH = join(homedir(), ".nous", "config.json");
15
26
 
@@ -648,4 +659,82 @@ program
648
659
  });
649
660
 
650
661
  // ---------------------------------------------------------------------------
651
- program.name("nous").version("0.3.0").parse();
662
+ // Browser sign-in (device authorization). Opens the browser, you approve, and a
663
+ // freshly minted API key is saved to ~/.nous/config.json. No copy-paste. Shared
664
+ // by `nous login`, `nous init`, and the plugin's /nous-login command.
665
+ // ---------------------------------------------------------------------------
666
+ async function browserLogin(url) {
667
+ const apiUrl = url || process.env.NOUS_API_URL || readConfig().apiUrl || "https://api.opennous.cloud";
668
+
669
+ let start;
670
+ try {
671
+ const r = await fetch(`${apiUrl}/api/cli/auth/start`, {
672
+ method: "POST", headers: { "Content-Type": "application/json" }, body: "{}",
673
+ });
674
+ if (!r.ok) throw new Error(`server returned ${r.status}`);
675
+ start = await r.json();
676
+ } catch (e) {
677
+ console.error(`Couldn't start sign-in: ${e.message}`);
678
+ process.exit(1);
679
+ }
680
+
681
+ console.log(`\nOpening your browser to sign in. If it doesn't open, visit:\n ${start.verification_uri_complete}\n`);
682
+ openBrowser(start.verification_uri_complete);
683
+
684
+ const interval = (start.interval || 4) * 1000;
685
+ const deadline = Date.now() + (start.expires_in || 600) * 1000;
686
+ process.stdout.write("Waiting for you to approve in the browser");
687
+
688
+ while (Date.now() < deadline) {
689
+ await sleep(interval);
690
+ process.stdout.write(".");
691
+ let j = {};
692
+ try {
693
+ const r = await fetch(`${apiUrl}/api/cli/auth/poll`, {
694
+ method: "POST", headers: { "Content-Type": "application/json" },
695
+ body: JSON.stringify({ device_code: start.device_code }),
696
+ });
697
+ j = await r.json().catch(() => ({}));
698
+ } catch { continue; }
699
+
700
+ if (j.status === "approved" && j.api_key) {
701
+ const cfg = readConfig();
702
+ cfg.apiKey = j.api_key;
703
+ cfg.apiUrl = apiUrl;
704
+ writeConfig(cfg);
705
+ console.log(`\n\n✓ Signed in. Key saved to ~/.nous/config.json`);
706
+ return true;
707
+ }
708
+ if (j.status === "denied") { console.log("\nAuthorization was denied."); process.exit(1); }
709
+ if (j.status === "expired") { console.log("\nThis sign-in expired. Run it again."); process.exit(1); }
710
+ }
711
+ console.log("\nTimed out waiting for approval. Run it again.");
712
+ process.exit(1);
713
+ }
714
+
715
+ program
716
+ .command("login")
717
+ .description("Sign in with your browser and save an API key (no copy-paste)")
718
+ .option("--url <url>", "API base URL (default: https://api.opennous.cloud)")
719
+ .action(async ({ url }) => {
720
+ await browserLogin(url);
721
+ console.log("Your Nous tools are ready — try `get_workspace_status` in your agent.");
722
+ });
723
+
724
+ // nous init — the one-line "get started": sign in, then connect to your agent.
725
+ // This is the command the marketing site points to (`npx @opennous/cli init`).
726
+ program
727
+ .command("init")
728
+ .description("Get started — sign in, then connect Nous to your agent")
729
+ .option("--url <url>", "API base URL (default: https://api.opennous.cloud)")
730
+ .action(async ({ url }) => {
731
+ await browserLogin(url);
732
+ console.log("\nNow add Nous to Claude Code:\n");
733
+ console.log(" /plugin marketplace add NousC/nous");
734
+ console.log(" /plugin install nous@nous-plugins\n");
735
+ console.log('Then tell your agent: "set me up" — it onboards your workspace and builds your playbook.');
736
+ console.log("\nDocs: https://docs.opennous.cloud/mcp/introduction");
737
+ });
738
+
739
+ // ---------------------------------------------------------------------------
740
+ program.name("nous").version("0.5.0").parse();