@opennous/cli 0.4.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.
- package/package.json +1 -1
- package/src/index.js +69 -50
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -659,63 +659,82 @@ program
|
|
|
659
659
|
});
|
|
660
660
|
|
|
661
661
|
// ---------------------------------------------------------------------------
|
|
662
|
-
//
|
|
663
|
-
//
|
|
664
|
-
//
|
|
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
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
|
+
|
|
666
715
|
program
|
|
667
716
|
.command("login")
|
|
668
717
|
.description("Sign in with your browser and save an API key (no copy-paste)")
|
|
669
718
|
.option("--url <url>", "API base URL (default: https://api.opennous.cloud)")
|
|
670
719
|
.action(async ({ url }) => {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
try {
|
|
675
|
-
const r = await fetch(`${apiUrl}/api/cli/auth/start`, {
|
|
676
|
-
method: "POST", headers: { "Content-Type": "application/json" }, body: "{}",
|
|
677
|
-
});
|
|
678
|
-
if (!r.ok) throw new Error(`server returned ${r.status}`);
|
|
679
|
-
start = await r.json();
|
|
680
|
-
} catch (e) {
|
|
681
|
-
console.error(`Couldn't start sign-in: ${e.message}`);
|
|
682
|
-
process.exit(1);
|
|
683
|
-
}
|
|
720
|
+
await browserLogin(url);
|
|
721
|
+
console.log("Your Nous tools are ready — try `get_workspace_status` in your agent.");
|
|
722
|
+
});
|
|
684
723
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
method: "POST", headers: { "Content-Type": "application/json" },
|
|
699
|
-
body: JSON.stringify({ device_code: start.device_code }),
|
|
700
|
-
});
|
|
701
|
-
j = await r.json().catch(() => ({}));
|
|
702
|
-
} catch { continue; }
|
|
703
|
-
|
|
704
|
-
if (j.status === "approved" && j.api_key) {
|
|
705
|
-
const cfg = readConfig();
|
|
706
|
-
cfg.apiKey = j.api_key;
|
|
707
|
-
cfg.apiUrl = apiUrl;
|
|
708
|
-
writeConfig(cfg);
|
|
709
|
-
console.log(`\n\n✓ Signed in. Key saved to ~/.nous/config.json`);
|
|
710
|
-
console.log("Your Nous tools are ready — try `get_workspace_status` in your agent.");
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
if (j.status === "denied") { console.log("\nAuthorization was denied."); process.exit(1); }
|
|
714
|
-
if (j.status === "expired") { console.log("\nThis sign-in expired. Run `nous login` again."); process.exit(1); }
|
|
715
|
-
}
|
|
716
|
-
console.log("\nTimed out waiting for approval. Run `nous login` again.");
|
|
717
|
-
process.exit(1);
|
|
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");
|
|
718
737
|
});
|
|
719
738
|
|
|
720
739
|
// ---------------------------------------------------------------------------
|
|
721
|
-
program.name("nous").version("0.
|
|
740
|
+
program.name("nous").version("0.5.0").parse();
|