@bunshin-cc/bunshin 0.14.0 → 0.14.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/dist/bin.js +46 -22
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -8662,7 +8662,7 @@ async function onSessionEnd(ctx) {
|
|
|
8662
8662
|
}
|
|
8663
8663
|
let action = "none";
|
|
8664
8664
|
const ephemeral = ephemeralHost();
|
|
8665
|
-
if (gate.reflect && config.reflect.enabled && !ephemeral) {
|
|
8665
|
+
if (gate.reflect && config.reflect.enabled && (!ephemeral || config.upload === "header-only")) {
|
|
8666
8666
|
episode.reflected = "edge";
|
|
8667
8667
|
action = "fork";
|
|
8668
8668
|
} else if (gate.worth) action = "cloud";
|
|
@@ -9060,13 +9060,13 @@ function removeBunshinHooks(settings) {
|
|
|
9060
9060
|
else delete out.hooks;
|
|
9061
9061
|
return out;
|
|
9062
9062
|
}
|
|
9063
|
-
function mergeClaudeSettings(settings, { bin = "bunshin", harness = "claude-code", user = false, allTools = false, autoConnect: autoConnect2 = false } = {}) {
|
|
9063
|
+
function mergeClaudeSettings(settings, { bin = "bunshin", harness = "claude-code", user = false, allTools = false, autoConnect: autoConnect2 = false, upload } = {}) {
|
|
9064
9064
|
const base = removeBunshinHooks(settings);
|
|
9065
9065
|
const hooks = { ...base.hooks ?? {} };
|
|
9066
9066
|
for (const { event, arg, timeout, matcher } of harness === "codex" ? CODEX_HOOK_EVENTS : HOOK_EVENTS) {
|
|
9067
9067
|
const groups = Array.isArray(hooks[event]) ? [...hooks[event]] : [];
|
|
9068
9068
|
const hook = bunshinHookEntry(arg, autoConnect2 && arg === "session-start" ? AUTO_CONNECT_SESSION_START_TIMEOUT : timeout, bin);
|
|
9069
|
-
hook.command = `${user ? "BUNSHIN_HOOK_SCOPE=user " : ""}${user && autoConnect2 ? "BUNSHIN_AUTO_CONNECT=1 " : ""}BUNSHIN_HARNESS=${harness} ${hook.command}`;
|
|
9069
|
+
hook.command = `${user ? "BUNSHIN_HOOK_SCOPE=user " : ""}${user && autoConnect2 ? "BUNSHIN_AUTO_CONNECT=1 " : ""}${user && autoConnect2 && upload ? `BUNSHIN_UPLOAD=${upload} ` : ""}BUNSHIN_HARNESS=${harness} ${hook.command}`;
|
|
9070
9070
|
if (harness === "codex") delete hook._bunshin;
|
|
9071
9071
|
const m = matcher && allTools && event === "PreToolUse" ? ALL_TOOLS_MATCHER : matcher;
|
|
9072
9072
|
groups.push(m ? { matcher: m, hooks: [hook] } : { hooks: [hook] });
|
|
@@ -9107,10 +9107,10 @@ export { default } from ${JSON.stringify(pathToFileURL(extension).href)};
|
|
|
9107
9107
|
return { file: file2, installed: 0, changed: false, error: error instanceof Error ? error.message : String(error) };
|
|
9108
9108
|
}
|
|
9109
9109
|
}
|
|
9110
|
-
function installClaudeHooks({ file: file2 = claudeSettingsPath(), bin = "bunshin", remove = false, harness = "claude-code", user = false, allTools = false, autoConnect: autoConnect2 = false } = {}) {
|
|
9110
|
+
function installClaudeHooks({ file: file2 = claudeSettingsPath(), bin = "bunshin", remove = false, harness = "claude-code", user = false, allTools = false, autoConnect: autoConnect2 = false, upload } = {}) {
|
|
9111
9111
|
try {
|
|
9112
9112
|
const before = fileExists(file2) ? JSON.parse(fs22.readFileSync(file2, "utf8")) : {};
|
|
9113
|
-
const after = remove ? removeBunshinHooks(before) : mergeClaudeSettings(before, { bin, harness, user, allTools, autoConnect: autoConnect2 });
|
|
9113
|
+
const after = remove ? removeBunshinHooks(before) : mergeClaudeSettings(before, { bin, harness, user, allTools, autoConnect: autoConnect2, ...upload ? { upload } : {} });
|
|
9114
9114
|
const changed = JSON.stringify(before) !== JSON.stringify(after);
|
|
9115
9115
|
if (changed) {
|
|
9116
9116
|
ensureDir(path18.dirname(file2));
|
|
@@ -9373,6 +9373,7 @@ var setup_exports = {};
|
|
|
9373
9373
|
__export(setup_exports, {
|
|
9374
9374
|
HARNESS_NAMES: () => HARNESS_NAMES,
|
|
9375
9375
|
HOSTED_API: () => HOSTED_API,
|
|
9376
|
+
UPLOAD_MODES: () => UPLOAD_MODES,
|
|
9376
9377
|
apiAddress: () => apiAddress,
|
|
9377
9378
|
askSources: () => askSources,
|
|
9378
9379
|
autoConnect: () => autoConnect,
|
|
@@ -9532,6 +9533,7 @@ ${profile.userId}`).digest("hex");
|
|
|
9532
9533
|
store.saveConfig({
|
|
9533
9534
|
...base,
|
|
9534
9535
|
...sources ? { sources } : {},
|
|
9536
|
+
...opts.upload ? { upload: opts.upload } : {},
|
|
9535
9537
|
...profile,
|
|
9536
9538
|
apiKey: void 0,
|
|
9537
9539
|
credentialFile,
|
|
@@ -9579,7 +9581,7 @@ function setupEnvironment(opts) {
|
|
|
9579
9581
|
const bin = opts.bin ?? hookBinary(opts.harness);
|
|
9580
9582
|
const claudeDir = path19.dirname(claudeSettingsPath());
|
|
9581
9583
|
return {
|
|
9582
|
-
hooks: installClaudeHooks({ bin, harness: opts.harness, user: true, autoConnect: true }),
|
|
9584
|
+
hooks: installClaudeHooks({ bin, harness: opts.harness, user: true, autoConnect: true, ...opts.upload ? { upload: opts.upload } : {} }),
|
|
9583
9585
|
permissions: installClaudePermissions(),
|
|
9584
9586
|
mcp: installUserMcp({ launcher: mcpLauncher(bin), ...opts.claude ? { claude: opts.claude } : {} }),
|
|
9585
9587
|
learnCommand: installLearnCommand({ file: path19.join(claudeDir, "commands", "learn.md") }),
|
|
@@ -9603,13 +9605,14 @@ async function autoConnect(cwd, env = process.env) {
|
|
|
9603
9605
|
const root = repositoryRoot(cwd);
|
|
9604
9606
|
if (!root || root === path19.resolve(homeDir()) || root === path19.parse(root).root) return { connected: false, reason: "not-a-repository" };
|
|
9605
9607
|
try {
|
|
9606
|
-
const
|
|
9608
|
+
const upload = UPLOAD_MODES.find((m) => m === env.BUNSHIN_UPLOAD);
|
|
9609
|
+
const result = await setupProject({ cwd: root, apiKey, harness, noHooks: true, hooks: "user", ...env.BUNSHIN_API_URL ? { apiUrl: env.BUNSHIN_API_URL } : {}, ...upload ? { upload } : {} });
|
|
9607
9610
|
return { connected: true, root, profile: result.profile };
|
|
9608
9611
|
} catch (error) {
|
|
9609
9612
|
return { connected: false, reason: "failed", error: error instanceof Error ? error.message : String(error) };
|
|
9610
9613
|
}
|
|
9611
9614
|
}
|
|
9612
|
-
var shellQuote, HARNESS_NAMES;
|
|
9615
|
+
var shellQuote, HARNESS_NAMES, UPLOAD_MODES;
|
|
9613
9616
|
var init_setup = __esm({
|
|
9614
9617
|
"src/setup.ts"() {
|
|
9615
9618
|
"use strict";
|
|
@@ -9620,6 +9623,7 @@ var init_setup = __esm({
|
|
|
9620
9623
|
init_trust();
|
|
9621
9624
|
shellQuote = (value) => `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
9622
9625
|
HARNESS_NAMES = { "claude-code": "Claude Code", codex: "Codex", pi: "Pi" };
|
|
9626
|
+
UPLOAD_MODES = ["redacted", "header-only", "full"];
|
|
9623
9627
|
}
|
|
9624
9628
|
});
|
|
9625
9629
|
|
|
@@ -9667,8 +9671,13 @@ async function handleHook(rawEvent, input, opts = {}) {
|
|
|
9667
9671
|
if (isChild()) return {};
|
|
9668
9672
|
const cwd = opts.cwd ?? input.cwd ?? process.cwd();
|
|
9669
9673
|
let store = opts.store !== void 0 ? opts.store : Store.discover(cwd);
|
|
9674
|
+
let connected;
|
|
9670
9675
|
if (!store && opts.store === void 0 && event === "session-start" && process.env.BUNSHIN_AUTO_CONNECT === "1" && !deferToProject(cwd)) {
|
|
9671
|
-
|
|
9676
|
+
const r = await connectHere(cwd);
|
|
9677
|
+
if ("problem" in r) return r.problem ? { systemMessage: `\u25C6 Bunshin: ${r.problem}`, hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: `## Bunshin
|
|
9678
|
+
Bunshin is installed in this environment but did not connect: ${r.problem} If the person asks about Bunshin, tell them this.` } } : {};
|
|
9679
|
+
store = r.store;
|
|
9680
|
+
connected = r.connected;
|
|
9672
9681
|
}
|
|
9673
9682
|
if (!store) return {};
|
|
9674
9683
|
const config = store.config();
|
|
@@ -9683,9 +9692,11 @@ async function handleHook(rawEvent, input, opts = {}) {
|
|
|
9683
9692
|
timer = setTimeout(() => resolve({}), Math.max(1, deadline - Date.now()) + 250);
|
|
9684
9693
|
timer.unref?.();
|
|
9685
9694
|
});
|
|
9686
|
-
const out = await Promise.race([work, late]);
|
|
9695
|
+
const out = await Promise.race([work, late]) ?? {};
|
|
9687
9696
|
if (timer) clearTimeout(timer);
|
|
9688
|
-
|
|
9697
|
+
if (connected) out.systemMessage = out.systemMessage ? `\u25C6 Bunshin: ${connected}
|
|
9698
|
+
${out.systemMessage}` : `\u25C6 Bunshin: ${connected}`;
|
|
9699
|
+
return out;
|
|
9689
9700
|
} catch (err) {
|
|
9690
9701
|
try {
|
|
9691
9702
|
store.log("hook-error", { event, session: input.session_id, error: err instanceof Error ? err.message : String(err) });
|
|
@@ -9694,21 +9705,22 @@ async function handleHook(rawEvent, input, opts = {}) {
|
|
|
9694
9705
|
return {};
|
|
9695
9706
|
}
|
|
9696
9707
|
}
|
|
9697
|
-
async function connectHere(cwd) {
|
|
9708
|
+
async function connectHere(cwd, env = process.env) {
|
|
9698
9709
|
try {
|
|
9699
9710
|
const { autoConnect: autoConnect2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
|
|
9700
|
-
const result = await autoConnect2(cwd);
|
|
9711
|
+
const result = await autoConnect2(cwd, env);
|
|
9701
9712
|
if (!result.connected) {
|
|
9702
|
-
|
|
9703
|
-
if (
|
|
9713
|
+
const problem = result.reason === "no-key" ? "it has no key yet. Add the secret BUNSHIN_API_KEY to this environment (create it in the Bunshin console: Overview \u2192 A cloud environment); new sessions then connect on their own." : result.reason === "failed" ? `it could not connect this repository: ${result.error ?? "unknown error"}` : result.reason === "no-harness" ? "its hooks were installed without an agent. Run bunshin setup --env again in the environment's setup script." : "";
|
|
9714
|
+
if (problem) process.stderr.write(`bunshin: ${problem}
|
|
9704
9715
|
`);
|
|
9705
|
-
return
|
|
9716
|
+
return { problem };
|
|
9706
9717
|
}
|
|
9707
9718
|
const store = Store.discover(cwd);
|
|
9708
|
-
store
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9719
|
+
if (!store) return { problem: "it connected this repository but could not open its store." };
|
|
9720
|
+
store.log("auto-connect", { root: result.root, role: result.profile.role, orgUnit: result.profile.orgUnit });
|
|
9721
|
+
return { store, connected: `connected ${path20.basename(result.root)} to your workspace as ${result.profile.role}${result.profile.orgUnit ? ` (${result.profile.orgUnit})` : ""}. It learns from this session and recalls what the workspace knows.` };
|
|
9722
|
+
} catch (err) {
|
|
9723
|
+
return { problem: `it could not connect this repository: ${err instanceof Error ? err.message : String(err)}` };
|
|
9712
9724
|
}
|
|
9713
9725
|
}
|
|
9714
9726
|
function deferToProject(cwd, env = process.env) {
|
|
@@ -13341,7 +13353,8 @@ async function main(argv, opts = {}) {
|
|
|
13341
13353
|
const harness = str7(args.flags.harness) ?? "claude-code";
|
|
13342
13354
|
if (harness !== "claude-code") throw new Error("--env supports --harness claude-code for now.");
|
|
13343
13355
|
const { setupEnvironment: setupEnvironment2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
|
|
13344
|
-
const
|
|
13356
|
+
const upload = transcriptsFlag(args);
|
|
13357
|
+
const result = setupEnvironment2({ harness, ...upload ? { upload } : {} });
|
|
13345
13358
|
if (result.hooks.error) throw new Error(`hooks could not be configured in ${result.hooks.file}: ${result.hooks.error}`);
|
|
13346
13359
|
out(`${result.hooks.installed} hooks configured in ${result.hooks.file}: each git repository connects on its first session.
|
|
13347
13360
|
`);
|
|
@@ -13355,6 +13368,7 @@ async function main(argv, opts = {}) {
|
|
|
13355
13368
|
if (command.error) err(`! ${path31.basename(command.file, ".md")} not installed at ${command.file}: ${command.error}
|
|
13356
13369
|
`);
|
|
13357
13370
|
}
|
|
13371
|
+
if (upload === "header-only") out("Transcripts stay in the container: sessions upload what they learned and a header, and reflect here.\n");
|
|
13358
13372
|
out("No key is needed now. Give sessions BUNSHIN_API_KEY as an environment variable; a repository with no `.bunshin/` store is connected when a session starts in it.\n");
|
|
13359
13373
|
return 0;
|
|
13360
13374
|
} catch (error) {
|
|
@@ -13395,12 +13409,14 @@ async function main(argv, opts = {}) {
|
|
|
13395
13409
|
const exclude = str7(args.flags.exclude);
|
|
13396
13410
|
const listed = (v) => v.split(",").map((x) => x.trim().replace(/\/+$/, "")).filter(Boolean);
|
|
13397
13411
|
out("Connecting to Bunshin\u2026\n");
|
|
13412
|
+
const upload = transcriptsFlag(args);
|
|
13398
13413
|
const result = await setupProject2({
|
|
13399
13414
|
cwd,
|
|
13400
13415
|
harness,
|
|
13401
13416
|
apiKey: key,
|
|
13402
13417
|
apiUrl,
|
|
13403
13418
|
noHooks: bool5(args.flags["no-hooks"]),
|
|
13419
|
+
...upload ? { upload } : {},
|
|
13404
13420
|
...hooksFlag ? { hooks: hooksFlag } : {},
|
|
13405
13421
|
...bool5(args.flags.all) ? { sources: null } : only || exclude ? { sources: { ...only ? { only: listed(only) } : {}, ...exclude ? { exclude: listed(exclude) } : {} } } : {}
|
|
13406
13422
|
});
|
|
@@ -14012,6 +14028,13 @@ async function cmdConflict(store, args, out, err) {
|
|
|
14012
14028
|
}
|
|
14013
14029
|
return 0;
|
|
14014
14030
|
}
|
|
14031
|
+
function transcriptsFlag(args) {
|
|
14032
|
+
const v = str7(args.flags.transcripts);
|
|
14033
|
+
if (v === void 0) return void 0;
|
|
14034
|
+
if (v === "local" || v === "header-only") return "header-only";
|
|
14035
|
+
if (v === "redacted" || v === "full") return v;
|
|
14036
|
+
throw new Error("--transcripts must be local (keep them on this machine), redacted (the default) or full");
|
|
14037
|
+
}
|
|
14015
14038
|
async function signIn(apiUrl, harness, out) {
|
|
14016
14039
|
const { deviceLogin: deviceLogin2, DeviceLoginUnavailable: DeviceLoginUnavailable2 } = await Promise.resolve().then(() => (init_login(), login_exports));
|
|
14017
14040
|
try {
|
|
@@ -14074,13 +14097,14 @@ Usage: bunshin <command> [options]
|
|
|
14074
14097
|
it (no key to copy); later projects connect without asking
|
|
14075
14098
|
--harness codex|claude-code|pi pick the agent when several are installed
|
|
14076
14099
|
--login approve again (another workspace: select it in the console first)
|
|
14100
|
+
--transcripts local keep session transcripts on this machine (upload only what was learned)
|
|
14077
14101
|
--api-url <url> --no-hooks a self-hosted workspace; hooks off
|
|
14078
14102
|
--key-stdin read an agent key from stdin (for automated setup)
|
|
14079
14103
|
--hooks user a folder of projects: hooks in your user settings, so every
|
|
14080
14104
|
session under this folder uses its workspace (default: project)
|
|
14081
14105
|
--only a,b | --exclude c | --all
|
|
14082
14106
|
which of the folder's projects take part (asked when omitted)
|
|
14083
|
-
setup --env [--harness claude-code]
|
|
14107
|
+
setup --env [--harness claude-code] [--transcripts local]
|
|
14084
14108
|
an environment's setup script (a cloud container): no key now;
|
|
14085
14109
|
user hooks connect each git repository on its first session,
|
|
14086
14110
|
with BUNSHIN_API_KEY from the environment
|