@bigbongo/cli 3.2.0 → 3.3.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
@@ -28,8 +28,9 @@ bigbongo login
28
28
  ```
29
29
 
30
30
  Your browser opens to a BigBongo approval page showing a short code. Check the code matches,
31
- approve, and you're in. Your session lasts 7 days; run `bigbongo login` again to refresh it or
32
- `bigbongo logout` to sign out.
31
+ approve, and you're in. No browser on this machine? `bigbongo login --no-browser` prints the
32
+ address to open elsewhere (`BROWSER=<program>` picks the browser). Your session lasts 7 days; run
33
+ `bigbongo login` again to refresh it or `bigbongo logout` to sign out.
33
34
 
34
35
  ### 2. Clone your app
35
36
 
@@ -69,12 +70,12 @@ bigbongo logs # recent logs from your running app
69
70
 
70
71
  | command | what it does |
71
72
  |---|---|
72
- | `bigbongo login` | Sign in with your BigBongo account. |
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. |
73
+ | `bigbongo login` | Sign in with your BigBongo account. Option: `--no-browser`. |
74
+ | `bigbongo clone [app]` | Clone your app, set up git access and turn on its pre-push check. Name an app, or omit it to pick your organization, then the app. |
74
75
  | `bigbongo status` | Show what's live (version, commit, URL) and any deploy in progress. |
75
76
  | `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`. |
77
- | `bigbongo logout` | Sign out and clear your local session. |
77
+ | `bigbongo claude-setup` | Point Claude Code at BigBongo for the current project, so coding there is billed to your BigBongo credits. Options: `--org <slug>`, `--global`. |
78
+ | `bigbongo logout` | Sign out and delete the login and the git and Claude Code tokens the CLI cached in `~/.bigbongo`. |
78
79
 
79
80
  Run `bigbongo <command> --help` for details on any command.
80
81
 
@@ -90,17 +91,31 @@ Anthropic account and no AWS account needed.
90
91
 
91
92
  ```
92
93
  bigbongo login
94
+ cd my-app
93
95
  bigbongo claude-setup
94
96
  claude
95
97
  ```
96
98
 
97
- `claude-setup` writes two keys into your Claude settings: the BigBongo endpoint, and a
99
+ `claude-setup` writes two keys into a Claude settings file: the BigBongo endpoint, and a
98
100
  credential helper. Claude Code then fetches its own short-lived credential whenever it
99
101
  needs one and refreshes it on its own. **There is no key to copy and none stored in your
100
102
  shell profile.**
101
103
 
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
+ Which file it writes:
105
+
106
+ | how you run it | file written | who it affects |
107
+ |---|---|---|
108
+ | `bigbongo claude-setup` (default) | `.claude/settings.local.json` at the root of the current git repo, or in the current folder when it is not in a git repo | only Claude Code started in this project, only for you. The file is kept out of git (added to `.gitignore` when needed), so it is never shared with people who clone the repo. |
109
+ | `bigbongo claude-setup --global` | `~/.claude/settings.json` | every Claude Code session on this computer, in every project. All of them spend this organization's credit. |
110
+
111
+ It prints the organization whose credit will be used (name and slug) and the file it
112
+ wrote. Run it in each project you want on BigBongo, or once with `--global` if you want
113
+ it everywhere. Add `--org <slug>` if you belong to more than one organization. It will
114
+ not run in your home folder without `--global`, because that is not a project.
115
+
116
+ `--project` still works for older scripts and now means the default. It no longer
117
+ writes the shared `.claude/settings.json`, which gets committed and would hand the
118
+ helper to everyone who clones the repo.
104
119
 
105
120
  A few things differ from a direct Anthropic connection, and it is better to know them up
106
121
  front than to discover them mid-task:
@@ -1,6 +1,7 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
1
+ import { execFileSync } from "node:child_process";
2
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
3
  import { homedir } from "node:os";
3
- import { dirname, join } from "node:path";
4
+ import { dirname, join, resolve } from "node:path";
4
5
  import { api } from "../api.js";
5
6
  import { loadCredentials } from "../config.js";
6
7
  export async function claudeSetup(opts = {}) {
@@ -8,6 +9,16 @@ export async function claudeSetup(opts = {}) {
8
9
  console.error("Not logged in. Run `bigbongo login` first.");
9
10
  process.exit(1);
10
11
  }
12
+ if (opts.project) {
13
+ console.log("--project is now the default: writing .claude/settings.local.json (just you, git-ignored), not the shared .claude/settings.json.");
14
+ }
15
+ const repoRoot = opts.global ? null : gitRoot(process.cwd());
16
+ const projectRoot = opts.global ? null : repoRoot || process.cwd();
17
+ if (projectRoot && resolve(projectRoot) === resolve(homedir())) {
18
+ console.error("This is your home folder, not a project. Run it inside the project you want to use\n" +
19
+ "BigBongo in, or add --global to use it for every project on this computer.");
20
+ process.exit(1);
21
+ }
11
22
  let org = opts.org || "";
12
23
  let baseUrl = "https://llm.bigbongo.ai";
13
24
  try {
@@ -29,8 +40,12 @@ export async function claudeSetup(opts = {}) {
29
40
  console.error(e?.body?.error || e?.message || "Could not reach BigBongo.");
30
41
  process.exit(1);
31
42
  }
32
- const settingsPath = opts.project
33
- ? join(process.cwd(), ".claude", "settings.json")
43
+ const orgName = await api
44
+ .listOrgs()
45
+ .then((r) => (r?.organizations || []).find((o) => o.slug === org)?.name || "")
46
+ .catch(() => "");
47
+ const settingsPath = projectRoot
48
+ ? join(projectRoot, ".claude", "settings.local.json")
34
49
  : join(homedir(), ".claude", "settings.json");
35
50
  let settings = {};
36
51
  if (existsSync(settingsPath)) {
@@ -48,11 +63,22 @@ export async function claudeSetup(opts = {}) {
48
63
  settings.apiKeyHelper = helper;
49
64
  mkdirSync(dirname(settingsPath), { recursive: true });
50
65
  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}`);
66
+ const ignoredIn = repoRoot ? ensureGitIgnored(repoRoot) : "";
67
+ console.log("\n Claude Code is now pointed at BigBongo.\n");
68
+ console.log(` Credit used: ${orgName ? `${orgName} (${org})` : org}`);
69
+ console.log(` File written: ${settingsPath}`);
53
70
  console.log(` ANTHROPIC_BASE_URL ${baseUrl}`);
54
71
  console.log(` apiKeyHelper ${helper}\n`);
55
- console.log(" Run `claude` as normal. Credits come off your BigBongo balance.");
72
+ if (projectRoot) {
73
+ console.log(` Applies only to Claude Code started in ${projectRoot}.`);
74
+ if (ignoredIn)
75
+ console.log(` Added .claude/settings.local.json to ${ignoredIn} so it is never committed.`);
76
+ console.log(" To use BigBongo in every project on this computer instead, run it with --global.\n");
77
+ }
78
+ else {
79
+ console.log(" Applies to EVERY Claude Code session on this computer, in every project.\n");
80
+ }
81
+ console.log(" Run `claude` as normal. Credits come off that organization's BigBongo balance.");
56
82
  console.log(" Nothing to copy - Claude Code fetches and refreshes the credential itself.\n");
57
83
  if (process.env.ANTHROPIC_API_KEY) {
58
84
  console.log(" Heads up: ANTHROPIC_API_KEY is set in this shell, and it wins over the\n" +
@@ -60,3 +86,29 @@ export async function claudeSetup(opts = {}) {
60
86
  " instead of BigBongo.\n");
61
87
  }
62
88
  }
89
+ function gitRoot(dir) {
90
+ try {
91
+ return resolve(git(dir, ["rev-parse", "--show-toplevel"]));
92
+ }
93
+ catch {
94
+ return null;
95
+ }
96
+ }
97
+ function ensureGitIgnored(root) {
98
+ const entry = ".claude/settings.local.json";
99
+ try {
100
+ git(root, ["check-ignore", "-q", "--no-index", entry]);
101
+ return "";
102
+ }
103
+ catch {
104
+ }
105
+ const gitignore = join(root, ".gitignore");
106
+ const current = existsSync(gitignore) ? readFileSync(gitignore, "utf8") : "";
107
+ if (current.split(/\r?\n/).some((line) => line.trim() === entry || line.trim() === `/${entry}`))
108
+ return "";
109
+ appendFileSync(gitignore, `${current && !current.endsWith("\n") ? "\n" : ""}${entry}\n`);
110
+ return gitignore;
111
+ }
112
+ function git(cwd, args) {
113
+ return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
114
+ }
@@ -20,7 +20,8 @@ export async function login(opts) {
20
20
  console.log("\n Approve this login in your browser. Confirm this code matches:\n");
21
21
  console.log(` ${session.user_code}\n`);
22
22
  console.log(` ${session.verification_url}\n`);
23
- openBrowser(session.verification_url);
23
+ if (opts.browser !== false)
24
+ openBrowser(session.verification_url);
24
25
  const spin = ora("Waiting for approval...").start();
25
26
  const deadline = Date.now() + (session.expires_in || 900) * 1000;
26
27
  const interval = (session.poll_interval || 5) * 1000;
@@ -1,13 +1,33 @@
1
1
  import { api } from "../api.js";
2
- import { clearCredentials, loadCredentials } from "../config.js";
2
+ import { dirname } from "node:path";
3
+ import { CREDENTIAL_FILES, clearCachedGatewayTokens, clearCachedGitTokens, clearCredentials, loadCredentials, } from "../config.js";
3
4
  export async function logout() {
5
+ let revoked = false;
4
6
  if (loadCredentials()?.token) {
5
7
  try {
6
8
  await api.logout();
9
+ revoked = true;
7
10
  }
8
11
  catch {
9
12
  }
10
13
  }
11
- clearCredentials();
14
+ const failed = [];
15
+ for (const [what, clear] of [
16
+ ["your login", clearCredentials],
17
+ ["the cached git tokens", clearCachedGitTokens],
18
+ ["the cached Claude Code tokens", clearCachedGatewayTokens],
19
+ ]) {
20
+ try {
21
+ clear();
22
+ }
23
+ catch (e) {
24
+ failed.push(`${what} (${e?.code || e?.message || e})`);
25
+ }
26
+ }
27
+ if (failed.length) {
28
+ const server = revoked ? "Logged out on the server, but" : "Could not log out on the server, and";
29
+ console.error(`${server} could not delete ${failed.join(", ")} in ${dirname(CREDENTIAL_FILES[0])}.`);
30
+ process.exit(1);
31
+ }
12
32
  console.log("Logged out.");
13
33
  }
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { homedir } from "node:os";
2
2
  import { join, dirname } from "node:path";
3
- import { mkdirSync, readFileSync, writeFileSync, existsSync, chmodSync } from "node:fs";
3
+ import { mkdirSync, readFileSync, writeFileSync, existsSync, chmodSync, rmSync } from "node:fs";
4
4
  const DIR = join(homedir(), ".bigbongo");
5
5
  const CRED = join(DIR, "credentials.json");
6
6
  export function saveCredentials(c) {
@@ -20,10 +20,7 @@ export function loadCredentials() {
20
20
  }
21
21
  }
22
22
  export function clearCredentials() {
23
- if (existsSync(CRED)) {
24
- writeFileSync(CRED, "{}");
25
- chmodSync(CRED, 0o600);
26
- }
23
+ rmSync(CRED, { force: true });
27
24
  }
28
25
  const GIT_TOKENS = join(DIR, "git-tokens.json");
29
26
  const TOKEN_REFRESH_SKEW_MS = 5 * 60 * 1000;
@@ -113,8 +110,9 @@ export function saveCachedGatewayToken(org, entry) {
113
110
  chmodSync(GATEWAY_TOKENS, 0o600);
114
111
  }
115
112
  export function clearCachedGatewayTokens() {
116
- if (existsSync(GATEWAY_TOKENS)) {
117
- writeFileSync(GATEWAY_TOKENS, "{}");
118
- chmodSync(GATEWAY_TOKENS, 0o600);
119
- }
113
+ rmSync(GATEWAY_TOKENS, { force: true });
114
+ }
115
+ export function clearCachedGitTokens() {
116
+ rmSync(GIT_TOKENS, { force: true });
120
117
  }
118
+ export const CREDENTIAL_FILES = [CRED, GIT_TOKENS, GATEWAY_TOKENS];
package/dist/git.js CHANGED
@@ -1,4 +1,4 @@
1
- import { appendFileSync } from "node:fs";
1
+ import { appendFileSync, chmodSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { simpleGit } from "simple-git";
4
4
  export function tokenRemote(repoUrl, token) {
@@ -23,4 +23,28 @@ export async function cloneApp(repoUrl, token, dir, author) {
23
23
  await local.addConfig("credential.helper", "", false);
24
24
  await local.addConfig("credential.helper", "!bigbongo git-token --helper", true);
25
25
  appendFileSync(join(dir, ".git", "info", "exclude"), "\n.bigbongo.json\n");
26
+ await enablePrePushCheck(local, dir);
27
+ }
28
+ const PRE_PUSH_WRAPPER = `#!/bin/sh
29
+ # Written by bigbongo clone: runs this app's own pre-push check before every push.
30
+ # A checkout without the check (an older branch) pushes as before.
31
+ [ -f ./.githooks/pre-push ] || exit 0
32
+ exec bash ./.githooks/pre-push "$@"
33
+ `;
34
+ async function enablePrePushCheck(local, dir) {
35
+ if (!existsSync(join(dir, ".githooks", "pre-push")))
36
+ return;
37
+ const hooksPath = (await local.raw(["config", "--get", "core.hooksPath"]).catch(() => "")).trim();
38
+ const notice = (why) => {
39
+ console.log(`${why}, so the app's pre-push check is not turned on.`);
40
+ console.log("To run it before each push, call .githooks/pre-push from your pre-push hook.");
41
+ };
42
+ if (hooksPath)
43
+ return notice(`Your git uses its own hooks folder (${hooksPath})`);
44
+ const hook = join(dir, ".git", "hooks", "pre-push");
45
+ if (existsSync(hook))
46
+ return notice("This clone already has a pre-push hook");
47
+ mkdirSync(join(dir, ".git", "hooks"), { recursive: true });
48
+ writeFileSync(hook, PRE_PUSH_WRAPPER);
49
+ chmodSync(hook, 0o755);
26
50
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from "node:module";
3
- import { Command } from "commander";
3
+ import { Command, Option } from "commander";
4
4
  import { login } from "./commands/login.js";
5
5
  import { clone } from "./commands/clone.js";
6
6
  import { status } from "./commands/status.js";
@@ -12,7 +12,9 @@ import { claudeSetup } from "./commands/claudeSetup.js";
12
12
  const version = createRequire(import.meta.url)("../package.json").version;
13
13
  const program = new Command();
14
14
  program.name("bigbongo").description("Edit your BigBongo app locally and git push to deploy.").version(version);
15
- program.command("login").description("Authenticate against BigBongo").option("--token <token>", "non-interactive login").action(login);
15
+ program.command("login").description("Authenticate against BigBongo").option("--token <token>", "non-interactive login")
16
+ .option("--no-browser", "print the approval address without opening a browser (BROWSER=<program> picks the browser)")
17
+ .action(login);
16
18
  program.command("clone [app]").description("Clone your app's repo (BigBongo brokers GitHub access)").action(clone);
17
19
  program.command("status").description("Show app + deployment status").action(status);
18
20
  program.command("logs").description("Show app runtime logs")
@@ -21,9 +23,15 @@ program.command("logs").description("Show app runtime logs")
21
23
  .option("--level <level>", "filter by level: error | warn | info")
22
24
  .action(logs);
23
25
  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")
26
+ program.command("claude-setup").description("Point Claude Code at BigBongo for this project (writes apiKeyHelper + base URL)")
27
+ .option("--org <slug>", "organization whose BigBongo credit is used")
28
+ .addOption(new Option("--global", "write ~/.claude/settings.json instead, so EVERY Claude Code session on this computer uses BigBongo").conflicts("project"))
29
+ .option("--project", "same as the default (kept for older scripts)")
30
+ .addHelpText("after", `
31
+ By default this writes .claude/settings.local.json at the root of the current git repo
32
+ (or the current folder when it is not in a git repo). That file is just for you: it is
33
+ kept out of git (added to .gitignore when needed) and only Claude Code started in this
34
+ project uses it.`)
27
35
  .action(claudeSetup);
28
36
  program.command("gateway-token").description("(internal) print a short-lived Claude Code credential")
29
37
  .option("--org <slug>", "organization to bill")
package/dist/util.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { delimiter } from "node:path";
2
4
  export function openBrowser(url) {
3
5
  try {
4
6
  const u = new URL(url);
@@ -10,18 +12,41 @@ export function openBrowser(url) {
10
12
  }
11
13
  if (!/^https?:\/\/[A-Za-z0-9._:/~-]+$/.test(url))
12
14
  return;
15
+ const browser = (process.env.BROWSER || "").trim();
16
+ if (browser === "none")
17
+ return;
18
+ const entries = browser && existsSync(browser) ? [browser] : browser.split(delimiter);
19
+ const candidates = entries
20
+ .map((entry) => entry.trim())
21
+ .filter(Boolean)
22
+ .map((entry) => {
23
+ if (existsSync(entry))
24
+ return [entry, [url]];
25
+ const [program, ...args] = entry.split(/\s+/);
26
+ return [program, args.some((a) => a.includes("%s")) ? args.map((a) => a.replace("%s", url)) : [...args, url]];
27
+ });
28
+ candidates.push(platformOpener(url));
29
+ const tryFrom = (i) => {
30
+ if (i < candidates.length)
31
+ launch(candidates[i][0], candidates[i][1], () => tryFrom(i + 1));
32
+ };
33
+ tryFrom(0);
34
+ }
35
+ function platformOpener(url) {
36
+ if (process.platform === "darwin")
37
+ return ["open", [url]];
38
+ if (process.platform === "win32")
39
+ return ["cmd", ["/c", "start", "", url]];
40
+ return ["xdg-open", [url]];
41
+ }
42
+ function launch(program, args, onError) {
13
43
  try {
14
- if (process.platform === "darwin") {
15
- spawn("open", [url], { stdio: "ignore", detached: true }).unref();
16
- }
17
- else if (process.platform === "win32") {
18
- spawn("cmd", ["/c", "start", "", url], { stdio: "ignore", detached: true }).unref();
19
- }
20
- else {
21
- spawn("xdg-open", [url], { stdio: "ignore", detached: true }).unref();
22
- }
44
+ const child = spawn(program, args, { stdio: "ignore", detached: true });
45
+ child.on("error", onError);
46
+ child.unref();
23
47
  }
24
48
  catch {
49
+ onError();
25
50
  }
26
51
  }
27
52
  export function parseGitCredential(input) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbongo/cli",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "BigBongo CLI - edit your BigBongo app locally and git push to deploy.",
5
5
  "type": "module",
6
6
  "bin": {