@bigbongo/cli 3.1.0 → 3.2.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/README.md CHANGED
@@ -73,6 +73,7 @@ bigbongo logs # recent logs from your running app
73
73
  | `bigbongo clone [app]` | Clone your app and set up git access. Name an app, or omit it to pick your organization, then the app. |
74
74
  | `bigbongo status` | Show what's live (version, commit, URL) and any deploy in progress. |
75
75
  | `bigbongo logs` | Show recent runtime logs, newest first. Options: `--lines <n>` (default 50, max 500), `--search <text>`, `--level <error\|warn\|info>`. |
76
+ | `bigbongo claude-setup` | Point Claude Code at BigBongo, so coding is billed to your BigBongo credits. Options: `--org <slug>`, `--project`. |
76
77
  | `bigbongo logout` | Sign out and clear your local session. |
77
78
 
78
79
  Run `bigbongo <command> --help` for details on any command.
@@ -82,6 +83,43 @@ then shows just that org's apps (pick `← Back to organizations` to switch). On
82
83
  that actually have apps are listed, and if all your apps are in one org that step is skipped -
83
84
  there's nothing extra to set up.
84
85
 
86
+ ## Using Claude Code with BigBongo
87
+
88
+ Run Claude Code on your own machine and pay for it with your BigBongo credits - no
89
+ Anthropic account and no AWS account needed.
90
+
91
+ ```
92
+ bigbongo login
93
+ bigbongo claude-setup
94
+ claude
95
+ ```
96
+
97
+ `claude-setup` writes two keys into your Claude settings: the BigBongo endpoint, and a
98
+ credential helper. Claude Code then fetches its own short-lived credential whenever it
99
+ needs one and refreshes it on its own. **There is no key to copy and none stored in your
100
+ shell profile.**
101
+
102
+ Use `--project` to write `.claude/settings.json` in the current directory instead of your
103
+ home settings, and `--org <slug>` if you belong to more than one organization.
104
+
105
+ A few things differ from a direct Anthropic connection, and it is better to know them up
106
+ front than to discover them mid-task:
107
+
108
+ - Claude Code's built-in web search is unavailable; BigBongo provides
109
+ `mcp__bigbongo__web_search` through its MCP server instead.
110
+ - Some experimental beta features are turned off, because the upstream provider rejects
111
+ them outright rather than ignoring them.
112
+ - Your prompts travel through BigBongo on the way to the model. Token counts are
113
+ recorded; prompts and code are not stored.
114
+ - When your credit balance reaches zero, requests stop with a message telling you so.
115
+
116
+ Everything local is unchanged: subagents, hooks, skills, MCP servers, plugins and your
117
+ CLAUDE.md all behave exactly as they do on any other connection.
118
+
119
+ If you already have `ANTHROPIC_API_KEY` set in your shell, remove it - Claude Code
120
+ prefers it, and it would bill Anthropic instead of BigBongo. `claude-setup` warns you if
121
+ it sees one.
122
+
85
123
  ## How access works
86
124
 
87
125
  You never handle a GitHub credential yourself. When git needs access, BigBongo issues a
package/dist/api.js CHANGED
@@ -13,9 +13,18 @@ async function req(path, init = {}, base) {
13
13
  ...(init.headers || {}),
14
14
  },
15
15
  });
16
- if (!res.ok)
17
- throw new Error(`${res.status} ${res.statusText} on ${path}`);
18
16
  const t = await res.text();
17
+ if (!res.ok) {
18
+ const err = new Error(`${res.status} ${res.statusText} on ${path}`);
19
+ err.status = res.status;
20
+ try {
21
+ err.body = t ? JSON.parse(t) : undefined;
22
+ }
23
+ catch {
24
+ err.body = undefined;
25
+ }
26
+ throw err;
27
+ }
19
28
  return t ? JSON.parse(t) : {};
20
29
  }
21
30
  export const api = {
@@ -36,5 +45,6 @@ export const api = {
36
45
  const q = qs.toString();
37
46
  return req(`/api/cli/apps/${appId}/logs${q ? `?${q}` : ""}`);
38
47
  },
48
+ gatewayToken: (org) => req(`/api/cli/gateway-token${org ? `?organization=${encodeURIComponent(org)}` : ""}`, { method: "POST" }),
39
49
  logout: () => req("/api/cli/auth/logout", { method: "POST" }),
40
50
  };
@@ -0,0 +1,62 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ import { api } from "../api.js";
5
+ import { loadCredentials } from "../config.js";
6
+ export async function claudeSetup(opts = {}) {
7
+ if (!loadCredentials()?.token) {
8
+ console.error("Not logged in. Run `bigbongo login` first.");
9
+ process.exit(1);
10
+ }
11
+ let org = opts.org || "";
12
+ let baseUrl = "https://llm.bigbongo.ai";
13
+ try {
14
+ const r = await api.gatewayToken(org || undefined);
15
+ org = r.organization;
16
+ baseUrl = r.base_url || baseUrl;
17
+ }
18
+ catch (e) {
19
+ if (e?.status === 409 && Array.isArray(e?.body?.organizations)) {
20
+ console.error("Your login reaches several organizations. Re-run with one of:\n");
21
+ for (const o of e.body.organizations)
22
+ console.error(` bigbongo claude-setup --org ${o.slug}`);
23
+ process.exit(1);
24
+ }
25
+ if (e?.status === 402) {
26
+ console.error(e?.body?.error || "This organization has no BigBongo credit.");
27
+ process.exit(1);
28
+ }
29
+ console.error(e?.body?.error || e?.message || "Could not reach BigBongo.");
30
+ process.exit(1);
31
+ }
32
+ const settingsPath = opts.project
33
+ ? join(process.cwd(), ".claude", "settings.json")
34
+ : join(homedir(), ".claude", "settings.json");
35
+ let settings = {};
36
+ if (existsSync(settingsPath)) {
37
+ try {
38
+ settings = JSON.parse(readFileSync(settingsPath, "utf8")) || {};
39
+ }
40
+ catch {
41
+ console.error(`${settingsPath} is not valid JSON. Fix or move it, then run this again -\n` +
42
+ "refusing to overwrite a settings file that might hold your own configuration.");
43
+ process.exit(1);
44
+ }
45
+ }
46
+ const helper = org ? `bigbongo gateway-token --org ${org}` : "bigbongo gateway-token";
47
+ settings.env = { ...(settings.env || {}), ANTHROPIC_BASE_URL: baseUrl };
48
+ settings.apiKeyHelper = helper;
49
+ mkdirSync(dirname(settingsPath), { recursive: true });
50
+ writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
51
+ console.log(`\n Claude Code is now pointed at BigBongo (${org}).\n`);
52
+ console.log(` ${settingsPath}`);
53
+ console.log(` ANTHROPIC_BASE_URL ${baseUrl}`);
54
+ console.log(` apiKeyHelper ${helper}\n`);
55
+ console.log(" Run `claude` as normal. Credits come off your BigBongo balance.");
56
+ console.log(" Nothing to copy - Claude Code fetches and refreshes the credential itself.\n");
57
+ if (process.env.ANTHROPIC_API_KEY) {
58
+ console.log(" Heads up: ANTHROPIC_API_KEY is set in this shell, and it wins over the\n" +
59
+ " helper. Remove it from your shell profile, or this will bill Anthropic\n" +
60
+ " instead of BigBongo.\n");
61
+ }
62
+ }
@@ -0,0 +1,45 @@
1
+ import { api } from "../api.js";
2
+ import { loadCachedGatewayToken, loadCredentials, saveCachedGatewayToken } from "../config.js";
3
+ export async function gatewayToken(opts = {}) {
4
+ if (!loadCredentials()?.token) {
5
+ fail("Not logged in to BigBongo.\n" +
6
+ "Run `bigbongo login` once, then Claude Code will fetch credentials on its own.");
7
+ }
8
+ const org = opts.org || process.env.BIGBONGO_ORG || "";
9
+ const cached = loadCachedGatewayToken(org);
10
+ if (cached) {
11
+ process.stdout.write(cached.token);
12
+ return;
13
+ }
14
+ try {
15
+ const r = await api.gatewayToken(org || undefined);
16
+ saveCachedGatewayToken(org, {
17
+ token: r.token,
18
+ expires_at: r.expires_at,
19
+ base_url: r.base_url,
20
+ });
21
+ process.stdout.write(r.token);
22
+ }
23
+ catch (e) {
24
+ const status = e?.status;
25
+ const body = e?.body || {};
26
+ if (status === 409 && Array.isArray(body.organizations)) {
27
+ const list = body.organizations.map((o) => ` ${o.slug} (${o.name})`).join("\n");
28
+ fail("Your BigBongo login reaches several organizations, so this needs one named:\n" +
29
+ `${list}\n\n` +
30
+ "Set it once with `bigbongo claude-setup --org <slug>`, or export BIGBONGO_ORG=<slug>.");
31
+ }
32
+ if (status === 402) {
33
+ fail(`${body.error || "This organization has no BigBongo credit."}\n` +
34
+ "Top up in BigBongo and the next request will go through.");
35
+ }
36
+ if (status === 401) {
37
+ fail("Your BigBongo login has expired. Run `bigbongo login` again.");
38
+ }
39
+ fail(body.error || e?.message || "Could not fetch a BigBongo gateway credential.");
40
+ }
41
+ }
42
+ function fail(message) {
43
+ process.stderr.write(message + "\n");
44
+ process.exit(1);
45
+ }
package/dist/config.js CHANGED
@@ -86,3 +86,35 @@ export function findProjectUp(startDir = process.cwd()) {
86
86
  dir = parent;
87
87
  }
88
88
  }
89
+ const GATEWAY_TOKENS = join(DIR, "gateway-tokens.json");
90
+ function readGatewayCache() {
91
+ try {
92
+ return JSON.parse(readFileSync(GATEWAY_TOKENS, "utf8"));
93
+ }
94
+ catch {
95
+ return {};
96
+ }
97
+ }
98
+ export function loadCachedGatewayToken(org) {
99
+ const entry = readGatewayCache()[org || "_default"];
100
+ if (!entry?.token || !entry?.expires_at)
101
+ return null;
102
+ const remaining = new Date(entry.expires_at).getTime() - Date.now();
103
+ if (!(remaining > TOKEN_REFRESH_SKEW_MS))
104
+ return null;
105
+ return entry;
106
+ }
107
+ export function saveCachedGatewayToken(org, entry) {
108
+ const all = readGatewayCache();
109
+ all[org || "_default"] = entry;
110
+ mkdirSync(DIR, { recursive: true });
111
+ chmodSync(DIR, 0o700);
112
+ writeFileSync(GATEWAY_TOKENS, JSON.stringify(all));
113
+ chmodSync(GATEWAY_TOKENS, 0o600);
114
+ }
115
+ export function clearCachedGatewayTokens() {
116
+ if (existsSync(GATEWAY_TOKENS)) {
117
+ writeFileSync(GATEWAY_TOKENS, "{}");
118
+ chmodSync(GATEWAY_TOKENS, 0o600);
119
+ }
120
+ }
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
2
3
  import { Command } from "commander";
3
4
  import { login } from "./commands/login.js";
4
5
  import { clone } from "./commands/clone.js";
@@ -6,8 +7,11 @@ import { status } from "./commands/status.js";
6
7
  import { logs } from "./commands/logs.js";
7
8
  import { gitToken } from "./commands/gitToken.js";
8
9
  import { logout } from "./commands/logout.js";
10
+ import { gatewayToken } from "./commands/gatewayToken.js";
11
+ import { claudeSetup } from "./commands/claudeSetup.js";
12
+ const version = createRequire(import.meta.url)("../package.json").version;
9
13
  const program = new Command();
10
- program.name("bigbongo").description("Edit your BigBongo app locally and git push to deploy.").version("3.0.0");
14
+ program.name("bigbongo").description("Edit your BigBongo app locally and git push to deploy.").version(version);
11
15
  program.command("login").description("Authenticate against BigBongo").option("--token <token>", "non-interactive login").action(login);
12
16
  program.command("clone [app]").description("Clone your app's repo (BigBongo brokers GitHub access)").action(clone);
13
17
  program.command("status").description("Show app + deployment status").action(status);
@@ -17,6 +21,13 @@ program.command("logs").description("Show app runtime logs")
17
21
  .option("--level <level>", "filter by level: error | warn | info")
18
22
  .action(logs);
19
23
  program.command("logout").description("Revoke and clear local credentials").action(logout);
24
+ program.command("claude-setup").description("Point Claude Code at BigBongo (writes apiKeyHelper + base URL)")
25
+ .option("--org <slug>", "organization to bill")
26
+ .option("--project", "write .claude/settings.json here instead of your home settings")
27
+ .action(claudeSetup);
28
+ program.command("gateway-token").description("(internal) print a short-lived Claude Code credential")
29
+ .option("--org <slug>", "organization to bill")
30
+ .action(gatewayToken);
20
31
  program.command("git-token [app]").description("(internal) mint a short-lived git token").option("--helper", "git credential-helper mode").action(gitToken);
21
32
  program.parseAsync(process.argv).catch((err) => {
22
33
  const e = err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbongo/cli",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "BigBongo CLI - edit your BigBongo app locally and git push to deploy.",
5
5
  "type": "module",
6
6
  "bin": {