@bigbongo/cli 3.3.0 → 3.4.1
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 +28 -7
- package/dist/api.js +2 -0
- package/dist/commands/claudeSetup.js +40 -17
- package/dist/commands/clone.js +12 -4
- package/dist/commands/logout.js +2 -1
- package/dist/commands/mcpToken.js +30 -0
- package/dist/commands/push.js +135 -0
- package/dist/commands/setup.js +346 -0
- package/dist/config.js +39 -5
- package/dist/git.js +4 -29
- package/dist/helper.js +18 -0
- package/dist/index.js +13 -2
- package/dist/util.js +17 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ you, so you never need a GitHub account. Once you've cloned your app it's all pl
|
|
|
10
10
|
|
|
11
11
|
- **Node.js 18+**
|
|
12
12
|
- **git** installed and on your PATH
|
|
13
|
+
- **Python 3.12+** to run and test your app on your machine (`bigbongo setup` says how to
|
|
14
|
+
install it when it is missing; [uv](https://docs.astral.sh/uv/) is used when installed)
|
|
13
15
|
|
|
14
16
|
## Install
|
|
15
17
|
|
|
@@ -39,8 +41,18 @@ bigbongo clone # pick your organization, then your app
|
|
|
39
41
|
bigbongo clone my-app # or name one directly
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
This clones your app into `./my-app`
|
|
43
|
-
|
|
44
|
+
This clones your app into `./my-app` (or into the current, empty folder with `--here`) and
|
|
45
|
+
runs `bigbongo setup` in it, so the folder is ready to build in:
|
|
46
|
+
|
|
47
|
+
- a Python environment in `.venv` with what your app's image installs, `requirements.txt`
|
|
48
|
+
and the test packages;
|
|
49
|
+
- the app's pre-push check, so tests run before every push;
|
|
50
|
+
- Claude Code pointed at your BigBongo credit, for this folder only
|
|
51
|
+
(`.claude/settings.local.json`);
|
|
52
|
+
- git access, so a plain `git push` works from any terminal - no tokens or GitHub setup.
|
|
53
|
+
|
|
54
|
+
Setup only writes inside the app's folder. Run `bigbongo setup` again any time (for example
|
|
55
|
+
after pulling a new `requirements.txt`); with nothing to do it finishes in well under a second.
|
|
44
56
|
|
|
45
57
|
### 3. Edit and deploy
|
|
46
58
|
|
|
@@ -49,9 +61,13 @@ cd my-app
|
|
|
49
61
|
# ...make your changes...
|
|
50
62
|
git add -A
|
|
51
63
|
git commit -m "Update the homepage"
|
|
52
|
-
|
|
64
|
+
bigbongo push # pushes, then follows the deploy to the end
|
|
53
65
|
```
|
|
54
66
|
|
|
67
|
+
`bigbongo push` is `git push` plus the result: it prints each step and ends with
|
|
68
|
+
`Live as v6 https://...`, or with the step that failed and why (a failing test stops the push
|
|
69
|
+
on your machine, before anything is sent). A plain `git push` deploys just the same.
|
|
70
|
+
|
|
55
71
|
Deploys come from the **`main`** branch: every push to `main` is deployed as your app's new
|
|
56
72
|
live version. After `bigbongo clone` you're already on `main`, so a plain `git push` deploys.
|
|
57
73
|
If you prefer to work on a separate branch, merge it into `main` and push to deploy.
|
|
@@ -71,11 +87,14 @@ bigbongo logs # recent logs from your running app
|
|
|
71
87
|
| command | what it does |
|
|
72
88
|
|---|---|
|
|
73
89
|
| `bigbongo login` | Sign in with your BigBongo account. Option: `--no-browser`. |
|
|
74
|
-
| `bigbongo clone [app]` | Clone your app,
|
|
90
|
+
| `bigbongo clone [app]` | Clone your app, then run `bigbongo setup` in it. Name an app, or omit it to pick your organization, then the app. Option: `--here` (clone into the current, empty folder). |
|
|
91
|
+
| `bigbongo setup` | Make the app folder ready: Python environment and packages, the pre-push check, Claude Code on BigBongo credit, and git access from any terminal. Safe to repeat. Option: `--quiet`. |
|
|
92
|
+
| `bigbongo push` | `git push`, then follow that commit until it is live (version and address) or failed (step and reason). |
|
|
75
93
|
| `bigbongo status` | Show what's live (version, commit, URL) and any deploy in progress. |
|
|
76
94
|
| `bigbongo logs` | Show recent runtime logs, newest first. Options: `--lines <n>` (default 50, max 500), `--search <text>`, `--level <error\|warn\|info>`. |
|
|
77
|
-
| `bigbongo claude-setup` | Point Claude Code at BigBongo
|
|
78
|
-
| `bigbongo
|
|
95
|
+
| `bigbongo claude-setup` | Point Claude Code at BigBongo in a folder that is not an app (an app folder gets this from `bigbongo setup`), so coding there is billed to your BigBongo credits. Options: `--org <slug>`, `--global`. |
|
|
96
|
+
| `bigbongo mcp-token` | (for Claude Code) Print the MCP headers for this folder's app, for Claude Code's `headersHelper`. |
|
|
97
|
+
| `bigbongo logout` | Sign out and delete the login and the git, Claude Code and MCP tokens the CLI cached in `~/.bigbongo`. |
|
|
79
98
|
|
|
80
99
|
Run `bigbongo <command> --help` for details on any command.
|
|
81
100
|
|
|
@@ -91,11 +110,13 @@ Anthropic account and no AWS account needed.
|
|
|
91
110
|
|
|
92
111
|
```
|
|
93
112
|
bigbongo login
|
|
113
|
+
bigbongo clone my-app # setup points Claude Code at BigBongo for this folder
|
|
94
114
|
cd my-app
|
|
95
|
-
bigbongo claude-setup
|
|
96
115
|
claude
|
|
97
116
|
```
|
|
98
117
|
|
|
118
|
+
For a folder that is not a BigBongo app, run `bigbongo claude-setup` there instead.
|
|
119
|
+
|
|
99
120
|
`claude-setup` writes two keys into a Claude settings file: the BigBongo endpoint, and a
|
|
100
121
|
credential helper. Claude Code then fetches its own short-lived credential whenever it
|
|
101
122
|
needs one and refreshes it on its own. **There is no key to copy and none stored in your
|
package/dist/api.js
CHANGED
|
@@ -46,5 +46,7 @@ export const api = {
|
|
|
46
46
|
return req(`/api/cli/apps/${appId}/logs${q ? `?${q}` : ""}`);
|
|
47
47
|
},
|
|
48
48
|
gatewayToken: (org) => req(`/api/cli/gateway-token${org ? `?organization=${encodeURIComponent(org)}` : ""}`, { method: "POST" }),
|
|
49
|
+
mcpToken: (appId) => req("/api/cli/mcp-token", { method: "POST", body: JSON.stringify({ app_id: appId }) }),
|
|
50
|
+
pushResult: (appId, sha) => req(`/api/cli/apps/${appId}/builds/${sha}`),
|
|
49
51
|
logout: () => req("/api/cli/auth/logout", { method: "POST" }),
|
|
50
52
|
};
|
|
@@ -4,6 +4,7 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { api } from "../api.js";
|
|
6
6
|
import { loadCredentials } from "../config.js";
|
|
7
|
+
import { isInside } from "../util.js";
|
|
7
8
|
export async function claudeSetup(opts = {}) {
|
|
8
9
|
if (!loadCredentials()?.token) {
|
|
9
10
|
console.error("Not logged in. Run `bigbongo login` first.");
|
|
@@ -47,26 +48,23 @@ export async function claudeSetup(opts = {}) {
|
|
|
47
48
|
const settingsPath = projectRoot
|
|
48
49
|
? join(projectRoot, ".claude", "settings.local.json")
|
|
49
50
|
: join(homedir(), ".claude", "settings.json");
|
|
50
|
-
let settings = {};
|
|
51
|
-
if (existsSync(settingsPath)) {
|
|
52
|
-
try {
|
|
53
|
-
settings = JSON.parse(readFileSync(settingsPath, "utf8")) || {};
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
console.error(`${settingsPath} is not valid JSON. Fix or move it, then run this again -\n` +
|
|
57
|
-
"refusing to overwrite a settings file that might hold your own configuration.");
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
51
|
const helper = org ? `bigbongo gateway-token --org ${org}` : "bigbongo gateway-token";
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
if (projectRoot && !isInside(projectRoot, settingsPath)) {
|
|
53
|
+
console.error(`${settingsPath} is a link or leads out of ${projectRoot}; refusing to write through it.`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
let written = false;
|
|
57
|
+
try {
|
|
58
|
+
written = writeGatewaySettings(settingsPath, baseUrl, helper);
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.error(e.message);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
66
64
|
const ignoredIn = repoRoot ? ensureGitIgnored(repoRoot) : "";
|
|
67
65
|
console.log("\n Claude Code is now pointed at BigBongo.\n");
|
|
68
66
|
console.log(` Credit used: ${orgName ? `${orgName} (${org})` : org}`);
|
|
69
|
-
console.log(` File written: ${settingsPath}`);
|
|
67
|
+
console.log(` ${written ? "File written:" : "Already set: "} ${settingsPath}`);
|
|
70
68
|
console.log(` ANTHROPIC_BASE_URL ${baseUrl}`);
|
|
71
69
|
console.log(` apiKeyHelper ${helper}\n`);
|
|
72
70
|
if (projectRoot) {
|
|
@@ -86,6 +84,28 @@ export async function claudeSetup(opts = {}) {
|
|
|
86
84
|
" instead of BigBongo.\n");
|
|
87
85
|
}
|
|
88
86
|
}
|
|
87
|
+
export function writeGatewaySettings(settingsPath, baseUrl, helper) {
|
|
88
|
+
let settings = {};
|
|
89
|
+
if (existsSync(settingsPath)) {
|
|
90
|
+
try {
|
|
91
|
+
settings = JSON.parse(readFileSync(settingsPath, "utf8")) || {};
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
throw new Error(`${settingsPath} is not valid JSON. Fix or move it, then run this again -\n` +
|
|
95
|
+
"refusing to overwrite a settings file that might hold your own configuration.");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (typeof settings !== "object" || Array.isArray(settings)) {
|
|
99
|
+
throw new Error(`${settingsPath} must hold a JSON object ({ ... }). Fix or move it, then run this again.`);
|
|
100
|
+
}
|
|
101
|
+
if (settings.env?.ANTHROPIC_BASE_URL === baseUrl && settings.apiKeyHelper === helper)
|
|
102
|
+
return false;
|
|
103
|
+
settings.env = { ...(settings.env || {}), ANTHROPIC_BASE_URL: baseUrl };
|
|
104
|
+
settings.apiKeyHelper = helper;
|
|
105
|
+
mkdirSync(dirname(settingsPath), { recursive: true });
|
|
106
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
89
109
|
function gitRoot(dir) {
|
|
90
110
|
try {
|
|
91
111
|
return resolve(git(dir, ["rev-parse", "--show-toplevel"]));
|
|
@@ -102,10 +122,13 @@ function ensureGitIgnored(root) {
|
|
|
102
122
|
}
|
|
103
123
|
catch {
|
|
104
124
|
}
|
|
105
|
-
|
|
125
|
+
let gitignore = join(root, ".gitignore");
|
|
126
|
+
if (!isInside(root, gitignore))
|
|
127
|
+
gitignore = resolve(root, git(root, ["rev-parse", "--git-path", "info/exclude"]));
|
|
106
128
|
const current = existsSync(gitignore) ? readFileSync(gitignore, "utf8") : "";
|
|
107
129
|
if (current.split(/\r?\n/).some((line) => line.trim() === entry || line.trim() === `/${entry}`))
|
|
108
130
|
return "";
|
|
131
|
+
mkdirSync(dirname(gitignore), { recursive: true });
|
|
109
132
|
appendFileSync(gitignore, `${current && !current.endsWith("\n") ? "\n" : ""}${entry}\n`);
|
|
110
133
|
return gitignore;
|
|
111
134
|
}
|
package/dist/commands/clone.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
1
2
|
import { join } from "node:path";
|
|
2
3
|
import { api } from "../api.js";
|
|
3
4
|
import { loadCredentials, saveProject } from "../config.js";
|
|
4
5
|
import { cloneApp } from "../git.js";
|
|
5
6
|
import { pickOne } from "../prompt.js";
|
|
6
7
|
import { isSafeAppSlug } from "../util.js";
|
|
8
|
+
import { setup } from "./setup.js";
|
|
7
9
|
function requireAuth() {
|
|
8
10
|
const c = loadCredentials();
|
|
9
11
|
if (!c?.token) {
|
|
@@ -36,7 +38,7 @@ async function pickApp(group, allowBack) {
|
|
|
36
38
|
const picked = await pickOne(`Pick an app to clone in ${group.name}`, choices);
|
|
37
39
|
return picked === BACK ? undefined : picked;
|
|
38
40
|
}
|
|
39
|
-
export async function clone(appArg) {
|
|
41
|
+
export async function clone(appArg, opts = {}) {
|
|
40
42
|
const cred = requireAuth();
|
|
41
43
|
const { apps } = await api.listApps();
|
|
42
44
|
if (!apps?.length) {
|
|
@@ -79,10 +81,16 @@ export async function clone(appArg) {
|
|
|
79
81
|
console.error(`Refusing to clone: unexpected app slug '${app.app_slug}'.`);
|
|
80
82
|
process.exit(1);
|
|
81
83
|
}
|
|
84
|
+
const dir = opts.here ? process.cwd() : join(process.cwd(), app.app_slug);
|
|
85
|
+
if (opts.here && readdirSync(dir).length) {
|
|
86
|
+
console.error("--here clones into the current folder, and it is not empty. Run it in an empty folder.");
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
82
89
|
const { token, repo_url } = await api.gitToken(app.id, "read");
|
|
83
|
-
const dir = join(process.cwd(), app.app_slug);
|
|
84
90
|
await cloneApp(repo_url, token, dir, { name: cred.email, email: cred.email });
|
|
85
91
|
saveProject({ app_id: app.id, org_id: app.org_id, app_slug: app.app_slug, repo_url }, dir);
|
|
86
|
-
console.log(`\nCloned ${app.app_slug} into
|
|
87
|
-
|
|
92
|
+
console.log(`\nCloned ${app.app_slug} into ${opts.here ? "this folder" : `./${app.app_slug}`}`);
|
|
93
|
+
await setup({ dir });
|
|
94
|
+
if (!opts.here)
|
|
95
|
+
console.log(`Next: cd ${app.app_slug}`);
|
|
88
96
|
}
|
package/dist/commands/logout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { api } from "../api.js";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
|
-
import { CREDENTIAL_FILES, clearCachedGatewayTokens, clearCachedGitTokens, clearCredentials, loadCredentials, } from "../config.js";
|
|
3
|
+
import { CREDENTIAL_FILES, clearCachedGatewayTokens, clearCachedGitTokens, clearCachedMcpTokens, clearCredentials, loadCredentials, } from "../config.js";
|
|
4
4
|
export async function logout() {
|
|
5
5
|
let revoked = false;
|
|
6
6
|
if (loadCredentials()?.token) {
|
|
@@ -16,6 +16,7 @@ export async function logout() {
|
|
|
16
16
|
["your login", clearCredentials],
|
|
17
17
|
["the cached git tokens", clearCachedGitTokens],
|
|
18
18
|
["the cached Claude Code tokens", clearCachedGatewayTokens],
|
|
19
|
+
["the cached MCP tokens", clearCachedMcpTokens],
|
|
19
20
|
]) {
|
|
20
21
|
try {
|
|
21
22
|
clear();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { api } from "../api.js";
|
|
2
|
+
import { findProjectUp, loadCachedMcpHeaders, loadCredentials, saveCachedMcpHeaders } from "../config.js";
|
|
3
|
+
export async function mcpToken(appArg) {
|
|
4
|
+
if (!loadCredentials()?.token)
|
|
5
|
+
fail("Not logged in to BigBongo. Run `bigbongo login`.");
|
|
6
|
+
const appId = appArg || findProjectUp(process.cwd())?.app_id;
|
|
7
|
+
if (!appId)
|
|
8
|
+
fail("No app here: run this inside a cloned app folder, or pass the app id.");
|
|
9
|
+
const cached = loadCachedMcpHeaders(appId);
|
|
10
|
+
if (cached) {
|
|
11
|
+
process.stdout.write(JSON.stringify(cached));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const r = await api.mcpToken(appId);
|
|
16
|
+
saveCachedMcpHeaders(appId, { headers: r.headers, expires_at: r.expires_at });
|
|
17
|
+
process.stdout.write(JSON.stringify(r.headers));
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
if (e?.status === 401)
|
|
21
|
+
fail("Your BigBongo login has expired. Run `bigbongo login` again.");
|
|
22
|
+
if (e?.status === 404)
|
|
23
|
+
fail("This login cannot reach this app (or it no longer exists).");
|
|
24
|
+
fail(e?.body?.error || e?.message || "Could not fetch an MCP token from BigBongo.");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function fail(message) {
|
|
28
|
+
process.stderr.write(message + "\n");
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { api } from "../api.js";
|
|
3
|
+
import { findProjectUp, loadCredentials } from "../config.js";
|
|
4
|
+
import { sleep } from "../util.js";
|
|
5
|
+
import { appWorkTree } from "./setup.js";
|
|
6
|
+
export async function push(opts = {}) {
|
|
7
|
+
const project = findProjectUp(process.cwd());
|
|
8
|
+
if (!project)
|
|
9
|
+
fail("Not in a BigBongo app folder (no .bigbongo.json here or above).");
|
|
10
|
+
const root = appWorkTree(process.cwd());
|
|
11
|
+
if (!root)
|
|
12
|
+
fail("Not in this app's git repository. Run `bigbongo push` in the app's folder.");
|
|
13
|
+
if (!loadCredentials()?.token)
|
|
14
|
+
fail("Not logged in. Run `bigbongo login` first.");
|
|
15
|
+
const pushed = await gitPush(root);
|
|
16
|
+
if (pushed.code !== 0) {
|
|
17
|
+
const why = explainPushFailure(pushed.output);
|
|
18
|
+
console.error(`\n✗ Failed at ${why.step}`);
|
|
19
|
+
for (const line of why.reason)
|
|
20
|
+
console.error(` ${line}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
const branch = git(root, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
24
|
+
if (branch !== "main") {
|
|
25
|
+
console.log(`\nPushed ${branch}. Only the main branch deploys, so there is no build to follow.`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const sha = git(root, ["rev-parse", "HEAD"]);
|
|
29
|
+
console.log(`\nFollowing ${sha.slice(0, 7)} on BigBongo...`);
|
|
30
|
+
const ok = await follow(project.app_id, sha, opts);
|
|
31
|
+
if (!ok)
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
function gitPush(cwd) {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
let output = "";
|
|
37
|
+
const child = spawn("git", ["push"], { cwd, stdio: ["inherit", "pipe", "pipe"] });
|
|
38
|
+
child.stdout.on("data", (c) => { output += c; process.stdout.write(c); });
|
|
39
|
+
child.stderr.on("data", (c) => { output += c; process.stderr.write(c); });
|
|
40
|
+
child.on("error", (e) => resolve({ code: 1, output: `${output}\nerror: ${e.message}` }));
|
|
41
|
+
child.on("close", (code) => resolve({ code: code ?? 1, output }));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function explainPushFailure(raw) {
|
|
45
|
+
const lines = raw.replace(/\x1b\[[0-9;]*m/g, "").split(/\r?\n/).map((l) => l.trimEnd()).filter(Boolean);
|
|
46
|
+
const text = lines.join("\n");
|
|
47
|
+
if (/Pre-push checks failed|hook declined|failed to push some refs/.test(text) && /^FAIL /m.test(text)) {
|
|
48
|
+
const failed = lines.filter((l) => /^(FAIL |FAILED |ERROR )/.test(l));
|
|
49
|
+
return { step: "the pre-push check on this computer (nothing was sent)", reason: failed };
|
|
50
|
+
}
|
|
51
|
+
if (/\[rejected\].*\((fetch first|non-fast-forward)\)/.test(text)) {
|
|
52
|
+
return {
|
|
53
|
+
step: "git push: main on BigBongo has changes you do not have",
|
|
54
|
+
reason: ["Someone (or BigBongo, for example an app update) pushed since you last pulled.",
|
|
55
|
+
"Run `git pull`, then `bigbongo push` again."],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (/Authentication failed|could not read Username|terminal prompts disabled|returned error: 403/.test(text)) {
|
|
59
|
+
return { step: "git push: GitHub refused the sign-in", reason: ["Run `bigbongo login`, then `bigbongo setup`, and push again."] };
|
|
60
|
+
}
|
|
61
|
+
const errors = lines.filter((l) => /^(error|fatal|remote: error)/i.test(l));
|
|
62
|
+
return { step: "git push", reason: (errors.length ? errors : lines).slice(-8) };
|
|
63
|
+
}
|
|
64
|
+
const MARK = { done: "✓", failed: "✗", in_progress: "…", running: "…" };
|
|
65
|
+
export async function follow(appId, sha, opts = {}) {
|
|
66
|
+
const pollMs = opts.pollMs ?? 3000;
|
|
67
|
+
const started = Date.now();
|
|
68
|
+
const printed = new Map();
|
|
69
|
+
let errors = 0;
|
|
70
|
+
let saidWaiting = false;
|
|
71
|
+
for (;;) {
|
|
72
|
+
let r;
|
|
73
|
+
try {
|
|
74
|
+
r = await api.pushResult(appId, sha);
|
|
75
|
+
errors = 0;
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
if (e?.status === 401)
|
|
79
|
+
fail("Your BigBongo login has expired. Run `bigbongo login`; the push itself went through.");
|
|
80
|
+
if (e?.status === 404)
|
|
81
|
+
fail("BigBongo does not know this app for your login (the push itself went through).");
|
|
82
|
+
if (++errors >= 5)
|
|
83
|
+
fail(`Lost contact with BigBongo (${e?.message || e}). Check later with \`bigbongo status\`.`);
|
|
84
|
+
await sleep(pollMs);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
for (const step of r.steps || []) {
|
|
88
|
+
const mark = MARK[step.status];
|
|
89
|
+
if (mark && printed.get(step.title) !== step.status) {
|
|
90
|
+
printed.set(step.title, step.status);
|
|
91
|
+
console.log(` ${mark} ${step.title}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (r.state === "live") {
|
|
95
|
+
console.log(`\nLive as v${r.version} ${r.url || ""}`.trimEnd());
|
|
96
|
+
if (r.serving === false)
|
|
97
|
+
console.log("(A later push or a rollback has replaced it since.)");
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
if (r.state === "failed") {
|
|
101
|
+
console.error(`\n✗ Failed at ${r.failed_step || "the build"}: ${r.reason || "no reason given"}`);
|
|
102
|
+
const detail = String(r.detail || "").trim().split(/\r?\n/).filter(Boolean).slice(-25);
|
|
103
|
+
if (detail.length)
|
|
104
|
+
console.error(detail.map((l) => ` ${l}`).join("\n"));
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (r.state === "skipped") {
|
|
108
|
+
console.error(`\n✗ Not deployed: ${r.reason || "the push was refused"}`);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (r.state === "waiting") {
|
|
112
|
+
if (!saidWaiting) {
|
|
113
|
+
console.log(" Waiting for the build to start...");
|
|
114
|
+
saidWaiting = true;
|
|
115
|
+
}
|
|
116
|
+
if (Date.now() - started > (opts.waitStartMs ?? 3 * 60_000)) {
|
|
117
|
+
console.error(`\n✗ ${r.reason || "No build started for this commit."}`);
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const limit = opts.timeoutMs ?? 20 * 60_000;
|
|
122
|
+
if (Date.now() - started > limit) {
|
|
123
|
+
console.error(`\n✗ Still not finished after ${Math.max(1, Math.round(limit / 60_000))} minutes. Check later with \`bigbongo status\`.`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
await sleep(pollMs);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function git(cwd, args) {
|
|
130
|
+
return (spawnSync("git", args, { cwd, encoding: "utf8" }).stdout || "").trim();
|
|
131
|
+
}
|
|
132
|
+
function fail(message) {
|
|
133
|
+
console.error(message);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { apiBase } from "../api.js";
|
|
8
|
+
import { findProjectRootUp, findProjectUp, loadCredentials } from "../config.js";
|
|
9
|
+
import { isInside } from "../util.js";
|
|
10
|
+
import { writeGatewaySettings } from "./claudeSetup.js";
|
|
11
|
+
const SDK_INSTALL = "./vendor/platform-sdk[django,llm,connections]";
|
|
12
|
+
const TEST_PACKAGES = ["pytest", "pytest-django"];
|
|
13
|
+
export const HELPER_FILES = [
|
|
14
|
+
"helper.js",
|
|
15
|
+
"commands/gitToken.js",
|
|
16
|
+
"commands/gatewayToken.js",
|
|
17
|
+
"api.js",
|
|
18
|
+
"config.js",
|
|
19
|
+
"util.js",
|
|
20
|
+
];
|
|
21
|
+
const HELPER_DIR = "bigbongo-helper";
|
|
22
|
+
const EXCLUDED = [".claude/settings.local.json", ".venv/", ".claude/worktrees/"];
|
|
23
|
+
export const PRE_PUSH_WRAPPER = `#!/bin/sh
|
|
24
|
+
# Written by bigbongo clone: runs this app's own pre-push check before every push.
|
|
25
|
+
# A checkout without the check (an older branch) pushes as before.
|
|
26
|
+
[ -f ./.githooks/pre-push ] || exit 0
|
|
27
|
+
exec bash ./.githooks/pre-push "$@"
|
|
28
|
+
`;
|
|
29
|
+
class Report {
|
|
30
|
+
quiet;
|
|
31
|
+
problems = [];
|
|
32
|
+
constructor(quiet) {
|
|
33
|
+
this.quiet = quiet;
|
|
34
|
+
}
|
|
35
|
+
ok(line) { if (!this.quiet)
|
|
36
|
+
console.log(` ✓ ${line}`); }
|
|
37
|
+
note(line) { if (!this.quiet)
|
|
38
|
+
console.log(` ${line}`); }
|
|
39
|
+
fail(line) { this.problems.push(line); console.error(` ✗ ${line}`); }
|
|
40
|
+
}
|
|
41
|
+
export async function setup(opts = {}) {
|
|
42
|
+
const start = opts.dir ? resolve(opts.dir) : process.cwd();
|
|
43
|
+
const project = findProjectUp(start);
|
|
44
|
+
if (!project) {
|
|
45
|
+
console.error("This is not a BigBongo app folder (no .bigbongo.json here or above).");
|
|
46
|
+
console.error("Run `bigbongo clone <app>` first, or run this inside the app's folder.");
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const git = version("git", ["--version"], /git version (\S+)/);
|
|
50
|
+
if (!git) {
|
|
51
|
+
console.error(` ✗ git is not installed. ${installHint("git")}`);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const root = appWorkTree(start);
|
|
55
|
+
if (!root) {
|
|
56
|
+
console.error("This app folder is not a git repository of this app. Clone it again with `bigbongo clone`,");
|
|
57
|
+
console.error("or run setup in the app's own folder (not in another repository inside it).");
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const r = new Report(!!opts.quiet);
|
|
61
|
+
if (!opts.quiet)
|
|
62
|
+
console.log(`\nSetting up ${project.app_slug} in ${root}\n`);
|
|
63
|
+
r.ok(`git ${git}`);
|
|
64
|
+
r.ok(`Node ${process.versions.node}`);
|
|
65
|
+
excludeFromGit(root);
|
|
66
|
+
const helper = installHelper(root, opts.sourceDir);
|
|
67
|
+
const runHelper = helper ? `node ${shQuote(helper)}` : "bigbongo";
|
|
68
|
+
if (helper || version("bigbongo", ["--version"], /(\d+\.\d+\.\d+)/)) {
|
|
69
|
+
setUpGitPush(root, runHelper);
|
|
70
|
+
r.ok("git push works from any terminal");
|
|
71
|
+
if (!helper)
|
|
72
|
+
r.note("(using `bigbongo` from your PATH: the helper copy could not be made)");
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
r.fail("Could not copy the git and Claude Code helper, and no `bigbongo` is on the PATH. Install it with `npm install -g @bigbongo/cli`, then run setup again.");
|
|
76
|
+
}
|
|
77
|
+
enablePrePushCheck(root, r);
|
|
78
|
+
if (helper || !r.problems.length)
|
|
79
|
+
setUpClaudeCode(root, project.org_id, runHelper, r);
|
|
80
|
+
setUpPython(root, r, !!opts.quiet);
|
|
81
|
+
if (!opts.quiet) {
|
|
82
|
+
console.log(r.problems.length
|
|
83
|
+
? "\nNot done yet: fix the lines marked ✗, then run `bigbongo setup` again.\n"
|
|
84
|
+
: "\nReady. Start Claude Code here with `claude`, and push with `bigbongo push`.\n");
|
|
85
|
+
}
|
|
86
|
+
return r.problems.length === 0;
|
|
87
|
+
}
|
|
88
|
+
export async function setupCommand(opts) {
|
|
89
|
+
if (!(await setup({ quiet: opts.quiet })))
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
export function appWorkTree(start) {
|
|
93
|
+
const projectRoot = findProjectRootUp(start);
|
|
94
|
+
const top = gitRun(start, ["rev-parse", "--show-toplevel"]).out.trim();
|
|
95
|
+
if (!projectRoot || !top)
|
|
96
|
+
return null;
|
|
97
|
+
const real = (dir) => { try {
|
|
98
|
+
return realpathSync(dir);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return "";
|
|
102
|
+
} };
|
|
103
|
+
const common = (dir) => {
|
|
104
|
+
const out = gitRun(dir, ["rev-parse", "--git-common-dir"]).out.trim();
|
|
105
|
+
return out ? real(resolve(dir, out)) : "";
|
|
106
|
+
};
|
|
107
|
+
if (real(gitRun(projectRoot, ["rev-parse", "--show-toplevel"]).out.trim()) !== real(projectRoot))
|
|
108
|
+
return null;
|
|
109
|
+
const ours = common(projectRoot);
|
|
110
|
+
return ours && ours === common(start) ? resolve(top) : null;
|
|
111
|
+
}
|
|
112
|
+
function setUpGitPush(root, runHelper) {
|
|
113
|
+
const command = `!${runHelper} git-token --helper`;
|
|
114
|
+
const current = gitRun(root, ["config", "--local", "--get-all", "credential.helper"]).out;
|
|
115
|
+
if (current !== `\n${command}\n`) {
|
|
116
|
+
gitRun(root, ["config", "--local", "--unset-all", "credential.helper"]);
|
|
117
|
+
gitRun(root, ["config", "--local", "--add", "credential.helper", ""]);
|
|
118
|
+
gitRun(root, ["config", "--local", "--add", "credential.helper", command]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export function installHelper(root, sourceDir = distDir()) {
|
|
122
|
+
const common = gitRun(root, ["rev-parse", "--git-common-dir"]).out.trim();
|
|
123
|
+
if (!common)
|
|
124
|
+
return "";
|
|
125
|
+
const gitDir = resolve(root, common);
|
|
126
|
+
const dest = join(gitDir, HELPER_DIR);
|
|
127
|
+
for (const file of HELPER_FILES) {
|
|
128
|
+
if (!existsSync(join(sourceDir, file)))
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
const files = [
|
|
132
|
+
...HELPER_FILES.map((f) => [f, readFileSync(join(sourceDir, f), "utf8")]),
|
|
133
|
+
["package.json", '{ "type": "module" }\n'],
|
|
134
|
+
];
|
|
135
|
+
for (const [file, content] of files) {
|
|
136
|
+
const target = join(dest, file);
|
|
137
|
+
if (!isInside(gitDir, target))
|
|
138
|
+
return "";
|
|
139
|
+
if (existsSync(target) && readFileSync(target, "utf8") === content)
|
|
140
|
+
continue;
|
|
141
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
142
|
+
writeFileSync(target, content);
|
|
143
|
+
}
|
|
144
|
+
return toPosix(join(dest, "helper.js"));
|
|
145
|
+
}
|
|
146
|
+
function distDir() {
|
|
147
|
+
return resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
148
|
+
}
|
|
149
|
+
function excludeFromGit(root) {
|
|
150
|
+
const exclude = resolve(root, gitRun(root, ["rev-parse", "--git-path", "info/exclude"]).out.trim());
|
|
151
|
+
const current = existsSync(exclude) ? readFileSync(exclude, "utf8") : "";
|
|
152
|
+
const lines = current.split(/\r?\n/).map((l) => l.trim());
|
|
153
|
+
const missing = EXCLUDED.filter((entry) => !lines.includes(entry));
|
|
154
|
+
if (!missing.length)
|
|
155
|
+
return;
|
|
156
|
+
mkdirSync(dirname(exclude), { recursive: true });
|
|
157
|
+
appendFileSync(exclude, `${current && !current.endsWith("\n") ? "\n" : ""}${missing.join("\n")}\n`);
|
|
158
|
+
}
|
|
159
|
+
export function enablePrePushCheck(root, r) {
|
|
160
|
+
if (!existsSync(join(root, ".githooks", "pre-push"))) {
|
|
161
|
+
r.note("This app has no pre-push check (.githooks/pre-push); nothing to turn on.");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const notice = (why) => {
|
|
165
|
+
r.note(`${why}, so the app's pre-push check is not turned on.`);
|
|
166
|
+
r.note("To run it before each push, call .githooks/pre-push from your pre-push hook.");
|
|
167
|
+
};
|
|
168
|
+
const hooksPath = gitRun(root, ["config", "--get", "core.hooksPath"]).out.trim();
|
|
169
|
+
if (hooksPath)
|
|
170
|
+
return notice(`Your git uses its own hooks folder (${hooksPath})`);
|
|
171
|
+
const hook = resolve(root, gitRun(root, ["rev-parse", "--git-path", "hooks/pre-push"]).out.trim());
|
|
172
|
+
if (existsSync(hook)) {
|
|
173
|
+
if (readFileSync(hook, "utf8") === PRE_PUSH_WRAPPER)
|
|
174
|
+
return r.ok("pre-push check on");
|
|
175
|
+
return notice("This clone already has a pre-push hook");
|
|
176
|
+
}
|
|
177
|
+
mkdirSync(dirname(hook), { recursive: true });
|
|
178
|
+
writeFileSync(hook, PRE_PUSH_WRAPPER);
|
|
179
|
+
chmodSync(hook, 0o755);
|
|
180
|
+
r.ok("pre-push check on");
|
|
181
|
+
}
|
|
182
|
+
function setUpClaudeCode(root, orgId, runHelper, r) {
|
|
183
|
+
if (resolve(root) === resolve(homedir())) {
|
|
184
|
+
r.fail("The app folder is your home folder; refusing to write Claude Code settings there.");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!loadCredentials()?.token) {
|
|
188
|
+
r.fail("Not logged in, so Claude Code is not set up on BigBongo credit. Run `bigbongo login`, then `bigbongo setup`.");
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const org = /^[A-Za-z0-9-]+$/.test(orgId || "") ? ` --org ${orgId}` : "";
|
|
192
|
+
const helper = `${runHelper} gateway-token${org}`;
|
|
193
|
+
const settingsPath = join(root, ".claude", "settings.local.json");
|
|
194
|
+
if (!isInside(root, settingsPath)) {
|
|
195
|
+
r.fail(".claude/settings.local.json is a link or leads out of this folder; refusing to write through it.");
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
writeGatewaySettings(settingsPath, apiBase(), helper);
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
r.fail(e.message);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
r.ok("Claude Code uses BigBongo credit (.claude/settings.local.json)");
|
|
206
|
+
}
|
|
207
|
+
function setUpPython(root, r, quiet) {
|
|
208
|
+
const venvPython = join(root, ".venv", process.platform === "win32" ? "Scripts/python.exe" : "bin/python");
|
|
209
|
+
if (gitRun(root, ["ls-files", ".venv"]).out.trim()) {
|
|
210
|
+
r.fail(".venv is committed to git; setup only uses an environment it makes. Remove it from git, then run setup again.");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
let venvVersion = existsSync(venvPython) ? pythonVersion(venvPython, []) : null;
|
|
214
|
+
if (venvVersion && !atLeast312(venvVersion)) {
|
|
215
|
+
r.fail(`.venv has Python ${venvVersion}; this app needs 3.12 or newer. Delete .venv and run \`bigbongo setup\` again.`);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const uv = version("uv", ["--version"], /uv (\S+)/);
|
|
219
|
+
if (!venvVersion) {
|
|
220
|
+
const python = findPython();
|
|
221
|
+
if (!python) {
|
|
222
|
+
r.fail(`Python 3.12 or newer is not installed. ${installHint("python")}`);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const made = uv
|
|
226
|
+
? run("uv", ["venv", "--python", python.version, ".venv"], root)
|
|
227
|
+
: run(python.cmd, [...python.pre, "-m", "venv", ".venv"], root);
|
|
228
|
+
venvVersion = made.ok ? pythonVersion(venvPython, []) : null;
|
|
229
|
+
if (!venvVersion) {
|
|
230
|
+
r.fail(`Could not make .venv: ${lastLines(made.out)}`);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
r.ok(`Python ${venvVersion} in .venv (made with ${uv ? "uv" : "python -m venv"})`);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
r.ok(`Python ${venvVersion} in .venv`);
|
|
237
|
+
}
|
|
238
|
+
const args = [
|
|
239
|
+
...imagePackages(root),
|
|
240
|
+
...(existsSync(join(root, "requirements.txt")) ? ["-r", "requirements.txt"] : []),
|
|
241
|
+
...TEST_PACKAGES,
|
|
242
|
+
];
|
|
243
|
+
const marker = join(root, ".venv", ".bigbongo-setup");
|
|
244
|
+
const fingerprint = packagesFingerprint(root, venvVersion, args);
|
|
245
|
+
if (existsSync(marker) && readFileSync(marker, "utf8") === fingerprint) {
|
|
246
|
+
r.ok("packages up to date");
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (!quiet)
|
|
250
|
+
console.log(" installing the packages...");
|
|
251
|
+
const installed = uv
|
|
252
|
+
? run("uv", ["pip", "install", "--python", venvPython, ...args], root, !quiet)
|
|
253
|
+
: run(venvPython, ["-m", "pip", "install", "--disable-pip-version-check", ...args], root, !quiet);
|
|
254
|
+
if (!installed.ok) {
|
|
255
|
+
r.fail(`Installing the packages failed${installed.out ? `:\n${lastLines(installed.out)}` : " (the reason is above)"}`);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
writeFileSync(marker, fingerprint);
|
|
259
|
+
r.ok("packages installed: what the app's image installs, requirements.txt, pytest");
|
|
260
|
+
}
|
|
261
|
+
const SDK_ARG = /^\.\/vendor\/platform-sdk(\[[A-Za-z0-9,._-]+\])?$/;
|
|
262
|
+
const PLAIN_PACKAGE = /^[A-Za-z0-9][A-Za-z0-9._-]*(\[[A-Za-z0-9,._-]+\])?((==|>=|<=|~=|!=|<|>)[A-Za-z0-9.*+!-]+)?$/;
|
|
263
|
+
export function imagePackages(root) {
|
|
264
|
+
const dockerfile = join(root, "Dockerfile");
|
|
265
|
+
const sdk = existsSync(join(root, "vendor", "platform-sdk", "pyproject.toml")) ? [SDK_INSTALL] : [];
|
|
266
|
+
if (!existsSync(dockerfile))
|
|
267
|
+
return sdk;
|
|
268
|
+
const packages = [];
|
|
269
|
+
for (const line of readFileSync(dockerfile, "utf8").split(/\r?\n/)) {
|
|
270
|
+
const m = /^RUN\s+(?:python\s+-m\s+)?pip install\s+(.+)$/.exec(line.trim());
|
|
271
|
+
if (!m || /--no-index|(^|\s)-r\s/.test(m[1]))
|
|
272
|
+
continue;
|
|
273
|
+
for (const word of m[1].split("&&")[0].trim().split(/\s+/)) {
|
|
274
|
+
const arg = word.replace(/^["']|["']$/g, "");
|
|
275
|
+
if (SDK_ARG.test(arg) || PLAIN_PACKAGE.test(arg))
|
|
276
|
+
packages.push(arg);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (!packages.some((p) => SDK_ARG.test(p)))
|
|
280
|
+
packages.unshift(...sdk);
|
|
281
|
+
return packages;
|
|
282
|
+
}
|
|
283
|
+
function packagesFingerprint(root, pythonVer, args) {
|
|
284
|
+
const sdk = gitRun(root, ["rev-parse", "HEAD:vendor/platform-sdk"]).out.trim();
|
|
285
|
+
const req = join(root, "requirements.txt");
|
|
286
|
+
return createHash("sha256")
|
|
287
|
+
.update(JSON.stringify({ pythonVer, sdk, req: existsSync(req) ? readFileSync(req, "utf8") : "", args }))
|
|
288
|
+
.digest("hex");
|
|
289
|
+
}
|
|
290
|
+
function findPython() {
|
|
291
|
+
const candidates = process.platform === "win32"
|
|
292
|
+
? [["py", ["-3.13"]], ["py", ["-3.12"]], ["python", []]]
|
|
293
|
+
: [["python3.13", []], ["python3.12", []], ["python3", []], ["python", []]];
|
|
294
|
+
for (const [cmd, pre] of candidates) {
|
|
295
|
+
const v = pythonVersion(cmd, pre);
|
|
296
|
+
if (v && atLeast312(v))
|
|
297
|
+
return { cmd, pre, version: v.split(".").slice(0, 2).join(".") };
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
function pythonVersion(cmd, pre) {
|
|
302
|
+
return version(cmd, [...pre, "--version"], /Python (\d+\.\d+(?:\.\d+)?)/);
|
|
303
|
+
}
|
|
304
|
+
function atLeast312(v) {
|
|
305
|
+
const [major, minor] = v.split(".").map(Number);
|
|
306
|
+
return major > 3 || (major === 3 && minor >= 12);
|
|
307
|
+
}
|
|
308
|
+
function installHint(tool) {
|
|
309
|
+
const hints = {
|
|
310
|
+
git: {
|
|
311
|
+
darwin: "Install it with `xcode-select --install` (or `brew install git`)",
|
|
312
|
+
win32: "Install it with `winget install Git.Git`",
|
|
313
|
+
other: "Install it with your package manager, for example `sudo apt install git`",
|
|
314
|
+
},
|
|
315
|
+
python: {
|
|
316
|
+
darwin: "Install it with `brew install python@3.13`, or from https://www.python.org/downloads/",
|
|
317
|
+
win32: "Install it with `winget install Python.Python.3.13`",
|
|
318
|
+
other: "Install it with your package manager, for example `sudo apt install python3.12 python3.12-venv`",
|
|
319
|
+
},
|
|
320
|
+
}[tool];
|
|
321
|
+
const platform = process.platform === "darwin" || process.platform === "win32" ? process.platform : "other";
|
|
322
|
+
return `${hints[platform]}, then run \`bigbongo setup\` again.`;
|
|
323
|
+
}
|
|
324
|
+
function run(cmd, args, cwd, show = false) {
|
|
325
|
+
const res = spawnSync(cmd, args, { cwd, encoding: "utf8", stdio: show ? "inherit" : "pipe" });
|
|
326
|
+
return { ok: res.status === 0, out: `${res.stdout || ""}${res.stderr || ""}` || String(res.error?.message || "") };
|
|
327
|
+
}
|
|
328
|
+
function gitRun(cwd, args) {
|
|
329
|
+
const res = spawnSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
330
|
+
return { ok: res.status === 0, out: res.stdout || "" };
|
|
331
|
+
}
|
|
332
|
+
function version(cmd, args, re) {
|
|
333
|
+
const res = spawnSync(cmd, args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
334
|
+
if (res.status !== 0)
|
|
335
|
+
return null;
|
|
336
|
+
return re.exec(`${res.stdout || ""}${res.stderr || ""}`)?.[1] ?? null;
|
|
337
|
+
}
|
|
338
|
+
function lastLines(text, n = 20) {
|
|
339
|
+
return text.trim().split(/\r?\n/).slice(-n).join("\n");
|
|
340
|
+
}
|
|
341
|
+
function shQuote(path) {
|
|
342
|
+
return `'${toPosix(path).replace(/'/g, `'\\''`)}'`;
|
|
343
|
+
}
|
|
344
|
+
function toPosix(path) {
|
|
345
|
+
return path.replace(/\\/g, "/");
|
|
346
|
+
}
|
package/dist/config.js
CHANGED
|
@@ -8,6 +8,8 @@ export function saveCredentials(c) {
|
|
|
8
8
|
chmodSync(DIR, 0o700);
|
|
9
9
|
writeFileSync(CRED, JSON.stringify(c, null, 2));
|
|
10
10
|
chmodSync(CRED, 0o600);
|
|
11
|
+
for (const cache of [GIT_TOKENS, GATEWAY_TOKENS, MCP_TOKENS])
|
|
12
|
+
rmSync(cache, { force: true });
|
|
11
13
|
}
|
|
12
14
|
export function loadCredentials() {
|
|
13
15
|
if (!existsSync(CRED))
|
|
@@ -71,18 +73,21 @@ export function loadProject(dir = process.cwd()) {
|
|
|
71
73
|
export function saveProject(cfg, dir = process.cwd()) {
|
|
72
74
|
writeFileSync(join(dir, ".bigbongo.json"), JSON.stringify(cfg, null, 2));
|
|
73
75
|
}
|
|
74
|
-
export function
|
|
76
|
+
export function findProjectRootUp(startDir = process.cwd()) {
|
|
75
77
|
let dir = startDir;
|
|
76
78
|
for (;;) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return cfg;
|
|
79
|
+
if (loadProject(dir))
|
|
80
|
+
return dir;
|
|
80
81
|
const parent = dirname(dir);
|
|
81
82
|
if (parent === dir)
|
|
82
83
|
return null;
|
|
83
84
|
dir = parent;
|
|
84
85
|
}
|
|
85
86
|
}
|
|
87
|
+
export function findProjectUp(startDir = process.cwd()) {
|
|
88
|
+
const root = findProjectRootUp(startDir);
|
|
89
|
+
return root ? loadProject(root) : null;
|
|
90
|
+
}
|
|
86
91
|
const GATEWAY_TOKENS = join(DIR, "gateway-tokens.json");
|
|
87
92
|
function readGatewayCache() {
|
|
88
93
|
try {
|
|
@@ -112,7 +117,36 @@ export function saveCachedGatewayToken(org, entry) {
|
|
|
112
117
|
export function clearCachedGatewayTokens() {
|
|
113
118
|
rmSync(GATEWAY_TOKENS, { force: true });
|
|
114
119
|
}
|
|
120
|
+
const MCP_TOKENS = join(DIR, "mcp-tokens.json");
|
|
121
|
+
function readMcpCache() {
|
|
122
|
+
try {
|
|
123
|
+
return JSON.parse(readFileSync(MCP_TOKENS, "utf8"));
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export function loadCachedMcpHeaders(appId) {
|
|
130
|
+
const entry = readMcpCache()[appId];
|
|
131
|
+
if (!entry?.headers || !entry?.expires_at)
|
|
132
|
+
return null;
|
|
133
|
+
const remaining = new Date(entry.expires_at).getTime() - Date.now();
|
|
134
|
+
if (!(remaining > TOKEN_REFRESH_SKEW_MS))
|
|
135
|
+
return null;
|
|
136
|
+
return entry.headers;
|
|
137
|
+
}
|
|
138
|
+
export function saveCachedMcpHeaders(appId, entry) {
|
|
139
|
+
const all = readMcpCache();
|
|
140
|
+
all[appId] = entry;
|
|
141
|
+
mkdirSync(DIR, { recursive: true });
|
|
142
|
+
chmodSync(DIR, 0o700);
|
|
143
|
+
writeFileSync(MCP_TOKENS, JSON.stringify(all));
|
|
144
|
+
chmodSync(MCP_TOKENS, 0o600);
|
|
145
|
+
}
|
|
146
|
+
export function clearCachedMcpTokens() {
|
|
147
|
+
rmSync(MCP_TOKENS, { force: true });
|
|
148
|
+
}
|
|
115
149
|
export function clearCachedGitTokens() {
|
|
116
150
|
rmSync(GIT_TOKENS, { force: true });
|
|
117
151
|
}
|
|
118
|
-
export const CREDENTIAL_FILES = [CRED, GIT_TOKENS, GATEWAY_TOKENS];
|
|
152
|
+
export const CREDENTIAL_FILES = [CRED, GIT_TOKENS, GATEWAY_TOKENS, MCP_TOKENS];
|
package/dist/git.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { appendFileSync
|
|
1
|
+
import { appendFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { simpleGit } from "simple-git";
|
|
4
4
|
export function tokenRemote(repoUrl, token) {
|
|
@@ -15,36 +15,11 @@ export function tokenRemote(repoUrl, token) {
|
|
|
15
15
|
return repoUrl.replace("https://", `https://x-access-token:${token}@`);
|
|
16
16
|
}
|
|
17
17
|
export async function cloneApp(repoUrl, token, dir, author) {
|
|
18
|
-
await simpleGit(
|
|
19
|
-
|
|
18
|
+
await simpleGit({ config: ["credential.helper="], unsafe: { allowUnsafeCredentialHelper: true } })
|
|
19
|
+
.clone(tokenRemote(repoUrl, token), dir);
|
|
20
|
+
const local = simpleGit(dir);
|
|
20
21
|
await local.remote(["set-url", "origin", repoUrl]);
|
|
21
22
|
await local.addConfig("user.name", author.name);
|
|
22
23
|
await local.addConfig("user.email", author.email);
|
|
23
|
-
await local.addConfig("credential.helper", "", false);
|
|
24
|
-
await local.addConfig("credential.helper", "!bigbongo git-token --helper", true);
|
|
25
24
|
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);
|
|
50
25
|
}
|
package/dist/helper.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { gitToken } from "./commands/gitToken.js";
|
|
3
|
+
import { gatewayToken } from "./commands/gatewayToken.js";
|
|
4
|
+
async function main(argv) {
|
|
5
|
+
const [command, ...rest] = argv;
|
|
6
|
+
if (command === "git-token" && rest[0] === "--helper")
|
|
7
|
+
return gitToken(rest[1], { helper: true });
|
|
8
|
+
if (command === "gateway-token") {
|
|
9
|
+
const i = rest.indexOf("--org");
|
|
10
|
+
return gatewayToken({ org: i >= 0 ? rest[i + 1] : undefined });
|
|
11
|
+
}
|
|
12
|
+
process.stderr.write("usage: helper.js git-token --helper <op> | gateway-token [--org <id>]\n");
|
|
13
|
+
process.exit(2);
|
|
14
|
+
}
|
|
15
|
+
main(process.argv.slice(2)).catch((err) => {
|
|
16
|
+
process.stderr.write(`${err?.message || err}\n`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -9,13 +9,22 @@ import { gitToken } from "./commands/gitToken.js";
|
|
|
9
9
|
import { logout } from "./commands/logout.js";
|
|
10
10
|
import { gatewayToken } from "./commands/gatewayToken.js";
|
|
11
11
|
import { claudeSetup } from "./commands/claudeSetup.js";
|
|
12
|
+
import { setupCommand } from "./commands/setup.js";
|
|
13
|
+
import { push } from "./commands/push.js";
|
|
14
|
+
import { mcpToken } from "./commands/mcpToken.js";
|
|
12
15
|
const version = createRequire(import.meta.url)("../package.json").version;
|
|
13
16
|
const program = new Command();
|
|
14
17
|
program.name("bigbongo").description("Edit your BigBongo app locally and git push to deploy.").version(version);
|
|
15
18
|
program.command("login").description("Authenticate against BigBongo").option("--token <token>", "non-interactive login")
|
|
16
19
|
.option("--no-browser", "print the approval address without opening a browser (BROWSER=<program> picks the browser)")
|
|
17
20
|
.action(login);
|
|
18
|
-
program.command("clone [app]").description("Clone your app's repo (BigBongo brokers GitHub access)")
|
|
21
|
+
program.command("clone [app]").description("Clone your app's repo (BigBongo brokers GitHub access), then set it up")
|
|
22
|
+
.option("--here", "clone into the current folder (it must be empty)")
|
|
23
|
+
.action((app, opts) => clone(app, opts));
|
|
24
|
+
program.command("setup").description("Make this app folder ready: Python environment, packages, pre-push check, Claude Code and git push")
|
|
25
|
+
.option("--quiet", "print only what is wrong")
|
|
26
|
+
.action(setupCommand);
|
|
27
|
+
program.command("push").description("git push, then follow the build until it is live or failed").action(() => push());
|
|
19
28
|
program.command("status").description("Show app + deployment status").action(status);
|
|
20
29
|
program.command("logs").description("Show app runtime logs")
|
|
21
30
|
.option("--lines <n>", "number of log lines (default 50, max 500)")
|
|
@@ -23,7 +32,7 @@ program.command("logs").description("Show app runtime logs")
|
|
|
23
32
|
.option("--level <level>", "filter by level: error | warn | info")
|
|
24
33
|
.action(logs);
|
|
25
34
|
program.command("logout").description("Revoke and clear local credentials").action(logout);
|
|
26
|
-
program.command("claude-setup").description("Point Claude Code at BigBongo
|
|
35
|
+
program.command("claude-setup").description("Point Claude Code at BigBongo in any folder (an app folder gets this from `bigbongo setup`)")
|
|
27
36
|
.option("--org <slug>", "organization whose BigBongo credit is used")
|
|
28
37
|
.addOption(new Option("--global", "write ~/.claude/settings.json instead, so EVERY Claude Code session on this computer uses BigBongo").conflicts("project"))
|
|
29
38
|
.option("--project", "same as the default (kept for older scripts)")
|
|
@@ -36,6 +45,8 @@ project uses it.`)
|
|
|
36
45
|
program.command("gateway-token").description("(internal) print a short-lived Claude Code credential")
|
|
37
46
|
.option("--org <slug>", "organization to bill")
|
|
38
47
|
.action(gatewayToken);
|
|
48
|
+
program.command("mcp-token [app]").description("(internal) print the MCP headers for Claude Code's headersHelper")
|
|
49
|
+
.action((app) => mcpToken(app));
|
|
39
50
|
program.command("git-token [app]").description("(internal) mint a short-lived git token").option("--helper", "git credential-helper mode").action(gitToken);
|
|
40
51
|
program.parseAsync(process.argv).catch((err) => {
|
|
41
52
|
const e = err;
|
package/dist/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { delimiter } from "node:path";
|
|
2
|
+
import { existsSync, lstatSync, realpathSync } from "node:fs";
|
|
3
|
+
import { delimiter, dirname, sep } from "node:path";
|
|
4
4
|
export function openBrowser(url) {
|
|
5
5
|
try {
|
|
6
6
|
const u = new URL(url);
|
|
@@ -78,3 +78,18 @@ export function readStdin(timeoutMs = 2000) {
|
|
|
78
78
|
setTimeout(() => resolve(data), timeoutMs);
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
export function isInside(root, target) {
|
|
82
|
+
const top = realpathSync(root);
|
|
83
|
+
let dir = dirname(target);
|
|
84
|
+
while (!existsSync(dir))
|
|
85
|
+
dir = dirname(dir);
|
|
86
|
+
const real = realpathSync(dir);
|
|
87
|
+
if (real !== top && !real.startsWith(top + sep))
|
|
88
|
+
return false;
|
|
89
|
+
try {
|
|
90
|
+
return !lstatSync(target).isSymbolicLink();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbongo/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "BigBongo CLI - edit your BigBongo app locally and git push to deploy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@inquirer/select": "^5.1.3",
|
|
38
38
|
"commander": "^12.0.0",
|
|
39
39
|
"ora": "^8.0.0",
|
|
40
|
-
"simple-git": "^3.
|
|
40
|
+
"simple-git": "^3.36.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^20.11.0",
|