@brainbase-labs/cli 0.2.1 → 0.2.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/dist/index.js +52 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6974,12 +6974,25 @@ function ensureGitignore(cwd) {
|
|
|
6974
6974
|
|
|
6975
6975
|
// src/core/route-adapters.ts
|
|
6976
6976
|
import path37 from "node:path";
|
|
6977
|
+
import os7 from "node:os";
|
|
6977
6978
|
import fs34 from "node:fs";
|
|
6978
6979
|
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
6979
6980
|
var CLAUDE_ENV_KEYS = ["ANTHROPIC_BASE_URL", "ANTHROPIC_AUTH_TOKEN"];
|
|
6980
6981
|
function claudeSettingsPath(cwd) {
|
|
6981
6982
|
return path37.join(cwd, ".claude", "settings.json");
|
|
6982
6983
|
}
|
|
6984
|
+
function claudeUserConfigPath() {
|
|
6985
|
+
return path37.join(os7.homedir(), ".claude.json");
|
|
6986
|
+
}
|
|
6987
|
+
function ensureClaudeOnboarded() {
|
|
6988
|
+
const file = claudeUserConfigPath();
|
|
6989
|
+
const cfg = readJsonOr(file, {});
|
|
6990
|
+
if (cfg.hasCompletedOnboarding === true)
|
|
6991
|
+
return false;
|
|
6992
|
+
cfg.hasCompletedOnboarding = true;
|
|
6993
|
+
writeJson(file, cfg);
|
|
6994
|
+
return true;
|
|
6995
|
+
}
|
|
6983
6996
|
var claudeRouteAdapter = {
|
|
6984
6997
|
id: "claude-code",
|
|
6985
6998
|
async enable(cwd, target) {
|
|
@@ -6995,7 +7008,11 @@ var claudeRouteAdapter = {
|
|
|
6995
7008
|
settings.env.ANTHROPIC_AUTH_TOKEN = target.apiKey;
|
|
6996
7009
|
ensureDir(path37.dirname(file));
|
|
6997
7010
|
writeJson(file, settings);
|
|
6998
|
-
|
|
7011
|
+
const notes = [];
|
|
7012
|
+
if (ensureClaudeOnboarded()) {
|
|
7013
|
+
notes.push("Marked claude as onboarded in ~/.claude.json so it picks up the proxy on first run.");
|
|
7014
|
+
}
|
|
7015
|
+
return { data: snap, notes };
|
|
6999
7016
|
},
|
|
7000
7017
|
async disable(cwd, snapshot) {
|
|
7001
7018
|
const file = claudeSettingsPath(cwd);
|
|
@@ -7226,28 +7243,43 @@ async function attachToExistingAgent(cwd, agentId, args, existing) {
|
|
|
7226
7243
|
const adapter = getRouteAdapter(harness);
|
|
7227
7244
|
if (adapter) {
|
|
7228
7245
|
const apiBase2 = proxyBaseUrl(session ?? null);
|
|
7229
|
-
const
|
|
7230
|
-
ksp.start("Generating an API key…");
|
|
7246
|
+
const presetKey = process.env.BB_TASK_KEY?.trim();
|
|
7231
7247
|
try {
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
|
|
7248
|
+
let keyId;
|
|
7249
|
+
let keyPrefix;
|
|
7250
|
+
let keyPlain;
|
|
7251
|
+
if (presetKey) {
|
|
7252
|
+
keyPlain = presetKey;
|
|
7253
|
+
keyPrefix = presetKey.slice(0, 12) + "…";
|
|
7254
|
+
keyId = "";
|
|
7255
|
+
p13.log.info("Using pre-provisioned BB_TASK_KEY for tracking.");
|
|
7256
|
+
} else {
|
|
7257
|
+
const ksp = p13.spinner();
|
|
7258
|
+
ksp.start("Generating an API key…");
|
|
7259
|
+
const created = await api.createCliKey(agent.id, {
|
|
7260
|
+
name: `${harness} on this machine`,
|
|
7261
|
+
harness: harness === "claude-code" ? "claude_code" : harness
|
|
7262
|
+
});
|
|
7263
|
+
ksp.stop("Key generated.");
|
|
7264
|
+
keyPlain = created.key;
|
|
7265
|
+
keyPrefix = created.prefix;
|
|
7266
|
+
keyId = created.id;
|
|
7267
|
+
}
|
|
7237
7268
|
const cfg = p13.spinner();
|
|
7238
7269
|
cfg.start(`Configuring ${harness}…`);
|
|
7239
|
-
const snap = await adapter.enable(cwd, { apiBase: apiBase2, apiKey:
|
|
7270
|
+
const snap = await adapter.enable(cwd, { apiBase: apiBase2, apiKey: keyPlain });
|
|
7240
7271
|
cfg.stop(`${harness} pointed at brainbase.`);
|
|
7272
|
+
for (const note3 of snap.notes ?? [])
|
|
7273
|
+
p13.log.info(note3);
|
|
7241
7274
|
tracking = {
|
|
7242
7275
|
harness,
|
|
7243
|
-
key_id:
|
|
7244
|
-
key_prefix:
|
|
7276
|
+
key_id: keyId,
|
|
7277
|
+
key_prefix: keyPrefix,
|
|
7245
7278
|
api_base: apiBase2,
|
|
7246
7279
|
snapshot: snap.data,
|
|
7247
7280
|
enabled_at: new Date().toISOString()
|
|
7248
7281
|
};
|
|
7249
7282
|
} catch (err) {
|
|
7250
|
-
ksp.stop("Failed.");
|
|
7251
7283
|
handleApiError(err);
|
|
7252
7284
|
process.exit(1);
|
|
7253
7285
|
}
|
|
@@ -7282,6 +7314,8 @@ async function tearDownTracking(cwd, link) {
|
|
|
7282
7314
|
p13.log.warn(`Failed to restore ${link.tracking.harness} config: ${err.message}`);
|
|
7283
7315
|
}
|
|
7284
7316
|
}
|
|
7317
|
+
if (!link.tracking.key_id)
|
|
7318
|
+
return;
|
|
7285
7319
|
try {
|
|
7286
7320
|
await api.revokeCliKey(link.tracking.key_id);
|
|
7287
7321
|
} catch (err) {
|
|
@@ -7379,7 +7413,7 @@ async function runUnlink(cwd, args) {
|
|
|
7379
7413
|
// src/cli/sync.ts
|
|
7380
7414
|
import path38 from "node:path";
|
|
7381
7415
|
import fs35 from "node:fs";
|
|
7382
|
-
import
|
|
7416
|
+
import os8 from "node:os";
|
|
7383
7417
|
import crypto3 from "node:crypto";
|
|
7384
7418
|
import * as p15 from "@clack/prompts";
|
|
7385
7419
|
import pc22 from "picocolors";
|
|
@@ -7651,7 +7685,7 @@ function computeLocalHash(paths) {
|
|
|
7651
7685
|
return h.digest("hex");
|
|
7652
7686
|
}
|
|
7653
7687
|
function stageManifest(components) {
|
|
7654
|
-
const root = fs35.mkdtempSync(path38.join(
|
|
7688
|
+
const root = fs35.mkdtempSync(path38.join(os8.tmpdir(), "brainbase-sync-"));
|
|
7655
7689
|
for (const c of components) {
|
|
7656
7690
|
const compDir = path38.join(root, c.type, c.slug);
|
|
7657
7691
|
ensureDir(compDir);
|
|
@@ -7677,7 +7711,7 @@ import pc28 from "picocolors";
|
|
|
7677
7711
|
// src/cli/agent-pull.ts
|
|
7678
7712
|
import path42 from "node:path";
|
|
7679
7713
|
import fs39 from "node:fs";
|
|
7680
|
-
import
|
|
7714
|
+
import os9 from "node:os";
|
|
7681
7715
|
import * as p16 from "@clack/prompts";
|
|
7682
7716
|
import pc23 from "picocolors";
|
|
7683
7717
|
|
|
@@ -8294,7 +8328,7 @@ async function runAgentPull(cwd, args) {
|
|
|
8294
8328
|
}
|
|
8295
8329
|
}
|
|
8296
8330
|
function stageManifestComponents(components) {
|
|
8297
|
-
const root = fs39.mkdtempSync(path42.join(
|
|
8331
|
+
const root = fs39.mkdtempSync(path42.join(os9.tmpdir(), "brainbase-pull-"));
|
|
8298
8332
|
for (const c of components) {
|
|
8299
8333
|
const compDir = path42.join(root, c.type, c.slug);
|
|
8300
8334
|
ensureDir(compDir);
|
|
@@ -9142,6 +9176,8 @@ async function runAgentCreate(cwd, args) {
|
|
|
9142
9176
|
apiKey: created.key
|
|
9143
9177
|
});
|
|
9144
9178
|
cfgSpinner.stop(`${harness} pointed at brainbase.`);
|
|
9179
|
+
for (const note4 of snap.notes ?? [])
|
|
9180
|
+
p19.log.info(note4);
|
|
9145
9181
|
tracking = {
|
|
9146
9182
|
harness,
|
|
9147
9183
|
key_id: created.id,
|