@orth/cli 0.2.14 → 0.2.16

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.
@@ -7,23 +7,113 @@ exports.loginCommand = loginCommand;
7
7
  exports.logoutCommand = logoutCommand;
8
8
  exports.whoamiCommand = whoamiCommand;
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
+ const http_1 = __importDefault(require("http"));
10
11
  const config_js_1 = require("../config.js");
12
+ const API_BASE = process.env.ORTH_API_URL || "https://api.orth.sh";
13
+ const WEB_BASE = process.env.ORTH_WEB_URL || "https://orthogonal.sh";
14
+ function openBrowser(url) {
15
+ const { exec } = require("child_process");
16
+ const platform = process.platform;
17
+ if (platform === "darwin")
18
+ exec(`open "${url}"`);
19
+ else if (platform === "win32")
20
+ exec(`start "${url}"`);
21
+ else
22
+ exec(`xdg-open "${url}"`);
23
+ }
24
+ async function browserLogin() {
25
+ return new Promise((resolve, reject) => {
26
+ // Find a random available port
27
+ const server = http_1.default.createServer((req, res) => {
28
+ const url = new URL(req.url || "/", `http://localhost`);
29
+ if (url.pathname === "/callback") {
30
+ const key = url.searchParams.get("key");
31
+ const error = url.searchParams.get("error");
32
+ if (key) {
33
+ // Send a nice HTML response
34
+ res.writeHead(200, { "Content-Type": "text/html" });
35
+ res.end(`
36
+ <html>
37
+ <body style="font-family: -apple-system, sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; background: #f0f0f0;">
38
+ <div style="text-align: center; background: white; padding: 48px; border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
39
+ <h1 style="font-size: 24px; margin: 0 0 8px;">Authenticated</h1>
40
+ <p style="color: #666; margin: 0;">You can close this tab and return to your terminal.</p>
41
+ </div>
42
+ </body>
43
+ </html>
44
+ `);
45
+ (0, config_js_1.setApiKey)(key);
46
+ console.log(chalk_1.default.green("\n✓ Logged in successfully!"));
47
+ console.log(chalk_1.default.gray(` Key: ${key.slice(0, 15)}...${key.slice(-4)}`));
48
+ server.close();
49
+ resolve();
50
+ }
51
+ else {
52
+ res.writeHead(400, { "Content-Type": "text/html" });
53
+ res.end(`
54
+ <html>
55
+ <body style="font-family: -apple-system, sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; background: #f0f0f0;">
56
+ <div style="text-align: center; background: white; padding: 48px; border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
57
+ <h1 style="font-size: 24px; margin: 0 0 8px; color: #e11d48;">Authentication Failed</h1>
58
+ <p style="color: #666; margin: 0;">${error || "Unknown error"}</p>
59
+ </div>
60
+ </body>
61
+ </html>
62
+ `);
63
+ console.log(chalk_1.default.red(`\n✗ Login failed: ${error || "Unknown error"}`));
64
+ server.close();
65
+ reject(new Error(error || "Login failed"));
66
+ }
67
+ }
68
+ else {
69
+ res.writeHead(404);
70
+ res.end();
71
+ }
72
+ });
73
+ server.listen(0, "127.0.0.1", () => {
74
+ const address = server.address();
75
+ if (!address || typeof address === "string") {
76
+ reject(new Error("Failed to start local server"));
77
+ return;
78
+ }
79
+ const port = address.port;
80
+ const callbackUrl = `http://127.0.0.1:${port}/callback`;
81
+ const authUrl = `${WEB_BASE}/cli-auth?callback=${encodeURIComponent(callbackUrl)}`;
82
+ console.log(chalk_1.default.gray("Opening browser to authenticate..."));
83
+ console.log(chalk_1.default.gray(`If it doesn't open, visit: ${authUrl}\n`));
84
+ openBrowser(authUrl);
85
+ // Timeout after 5 minutes
86
+ setTimeout(() => {
87
+ console.log(chalk_1.default.red("\n✗ Login timed out. Try again."));
88
+ server.close();
89
+ reject(new Error("Timed out"));
90
+ }, 5 * 60 * 1000);
91
+ });
92
+ server.on("error", (err) => {
93
+ reject(err);
94
+ });
95
+ });
96
+ }
11
97
  async function loginCommand(options) {
12
98
  const key = options.key || process.env.ORTHOGONAL_API_KEY;
13
- if (!key) {
14
- console.log(chalk_1.default.yellow("Usage: orth login --key <your-api-key>"));
15
- console.log(chalk_1.default.gray("\nGet your API key at: https://orthogonal.com/dashboard/settings/api-keys"));
16
- console.log(chalk_1.default.gray("Or set ORTHOGONAL_API_KEY environment variable"));
99
+ if (key) {
100
+ // Direct key login (existing flow)
101
+ if (!key.startsWith("orth_")) {
102
+ console.error(chalk_1.default.red("Invalid API key format. Keys should start with 'orth_'"));
103
+ process.exit(1);
104
+ }
105
+ (0, config_js_1.setApiKey)(key);
106
+ console.log(chalk_1.default.green("✓ Logged in successfully!"));
107
+ console.log(chalk_1.default.gray(` Key: ${key.slice(0, 15)}...${key.slice(-4)}`));
17
108
  return;
18
109
  }
19
- // Validate the key format
20
- if (!key.startsWith("orth_")) {
21
- console.error(chalk_1.default.red("Invalid API key format. Keys should start with 'orth_'"));
110
+ // Browser-based login
111
+ try {
112
+ await browserLogin();
113
+ }
114
+ catch {
22
115
  process.exit(1);
23
116
  }
24
- (0, config_js_1.setApiKey)(key);
25
- console.log(chalk_1.default.green("✓ Logged in successfully!"));
26
- console.log(chalk_1.default.gray(` Key: ${key.slice(0, 15)}...${key.slice(-4)}`));
27
117
  }
28
118
  async function logoutCommand() {
29
119
  (0, config_js_1.clearApiKey)();
package/dist/index.js CHANGED
@@ -214,6 +214,7 @@ skillsGroup
214
214
  }));
215
215
  skillsGroup
216
216
  .command("add <slug>")
217
+ .alias("install")
217
218
  .description("Add a skill to your local agent skills directories")
218
219
  .option("--agent <agent>", "Install for specific agent only (cursor, claude, copilot)")
219
220
  .action(asyncAction(async (slug, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orth/cli",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "CLI to access all APIs and skills on the Orthogonal platform",
5
5
  "main": "dist/index.js",
6
6
  "bin": {