@caphub/cli 0.1.2 → 0.1.3

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
@@ -16,10 +16,16 @@ npx @caphub/cli help
16
16
 
17
17
  ## Auth
18
18
 
19
- Store your API key once:
19
+ Open the website approval flow:
20
20
 
21
21
  ```bash
22
- caphub auth login --api-key csk_live_...
22
+ caphub auth login
23
+ ```
24
+
25
+ For headless/cloud agents, put the key in the platform secret manager and expose it as:
26
+
27
+ ```bash
28
+ CAPHUB_API_KEY=csk_live_...
23
29
  ```
24
30
 
25
31
  ## Discovery
package/bin/caphub.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import os from "node:os";
5
5
  import { dirname, resolve } from "node:path";
6
+ import { spawn } from "node:child_process";
6
7
  import { fileURLToPath } from "node:url";
7
8
 
8
9
  const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -24,7 +25,7 @@ commands:
24
25
  help <capability> show capability-specific help from the API
25
26
  capabilities list live capabilities with short descriptions
26
27
  auth show current login state
27
- auth login website login flow; stores api key locally after approval
28
+ auth login open website login flow; stores api key locally after approval
28
29
  auth whoami verify the current api key against the API
29
30
  auth logout remove stored api key from local config
30
31
  <capability> <json> run a capability directly, e.g. search or search-ideas
@@ -96,6 +97,27 @@ function fail(message) {
96
97
  process.exit(1);
97
98
  }
98
99
 
100
+ function openUrl(url) {
101
+ if (process.env.CAPHUB_NO_OPEN === "1") return false;
102
+
103
+ const command = process.platform === "darwin"
104
+ ? "open"
105
+ : process.platform === "win32"
106
+ ? "cmd"
107
+ : "xdg-open";
108
+ const args = process.platform === "win32"
109
+ ? ["/c", "start", "", url]
110
+ : [url];
111
+
112
+ try {
113
+ const child = spawn(command, args, { detached: true, stdio: "ignore" });
114
+ child.unref();
115
+ return true;
116
+ } catch {
117
+ return false;
118
+ }
119
+ }
120
+
99
121
  function readStdin() {
100
122
  return new Promise((resolveInput) => {
101
123
  let data = "";
@@ -314,14 +336,18 @@ async function commandAuth(args) {
314
336
  if (!explicitApiKey && !args.includes("--api-key")) {
315
337
  const apiUrl = getApiUrl();
316
338
  const started = await fetchJson(`${apiUrl}/v1/auth/cli/start`, { method: "POST", body: {} });
339
+ const opened = openUrl(started.approval_url);
317
340
  process.stdout.write([
318
341
  "caphub auth login",
319
342
  "",
320
- "Open this URL in your browser and finish sign-in:",
343
+ opened
344
+ ? "Opened the browser approval page. If it did not open, use this URL:"
345
+ : "Open this URL in your browser and finish sign-in:",
321
346
  started.approval_url,
322
347
  "",
323
348
  `code: ${started.code}`,
324
349
  `expires_in_seconds: ${started.expires_in_seconds}`,
350
+ process.env.CAPHUB_NO_OPEN === "1" ? "browser_open: disabled by CAPHUB_NO_OPEN=1" : `browser_open: ${opened ? "attempted" : "failed"}`,
325
351
  "",
326
352
  "Waiting for website approval...",
327
353
  "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caphub/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Root CLI for Caphub agent capabilities",
5
5
  "type": "module",
6
6
  "bin": {