benignswarm 0.12.40 → 0.12.41
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/commands/join.js +13 -1
- package/dist/harness.js +33 -1
- package/dist/index.js +2 -0
- package/dist/install.js +59 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/commands/join.js
CHANGED
|
@@ -7,7 +7,7 @@ import { join as pathJoin } from "node:path";
|
|
|
7
7
|
import { CliError } from "../errors.js";
|
|
8
8
|
import { defaultMachine } from "../git.js";
|
|
9
9
|
import { ensureInstall } from "../install.js";
|
|
10
|
-
import { HARNESSES, findIdentityFile, installForHarness, normalizeVendor, readIdentityFile, writeIdentity } from "../harness.js";
|
|
10
|
+
import { claudeCheckoutOwner, claudeCheckoutTaken, HARNESSES, findIdentityFile, installForHarness, normalizeVendor, readIdentityFile, writeIdentity } from "../harness.js";
|
|
11
11
|
import { detectVendor } from "../vendor.js";
|
|
12
12
|
function repoRoot() {
|
|
13
13
|
const r = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
@@ -40,6 +40,11 @@ export async function setup(p, out) {
|
|
|
40
40
|
const vendor = normalizeVendor(str(p.flags, "vendor") ?? creds.vendor);
|
|
41
41
|
const root = str(p.flags, "dir") ?? repoRoot();
|
|
42
42
|
const model = resolveModel(str(p.flags, "model"), process.env, process.cwd(), ref);
|
|
43
|
+
if (harnessList(p, vendor).includes("claude-code") && !bool(p.flags, "replace")) {
|
|
44
|
+
const owner = claudeCheckoutOwner(root);
|
|
45
|
+
if (owner && owner !== ref && owner !== creds.agent)
|
|
46
|
+
throw claudeCheckoutTaken(root, owner, creds.agent);
|
|
47
|
+
}
|
|
43
48
|
const inst = machineInstall();
|
|
44
49
|
const idPath = writeIdentity(root, vendor, creds.agent, model, bool(p.flags, "replace"), creds.project);
|
|
45
50
|
const files = await fetchSkill(creds.url);
|
|
@@ -70,6 +75,13 @@ export async function join(p, out) {
|
|
|
70
75
|
// A second agent of the same vendor in one worktree must not steal the repo mapping. With
|
|
71
76
|
// --no-bind the credentials are saved and the agent is addressed per call instead.
|
|
72
77
|
const noBind = bool(p.flags, "no-bind");
|
|
78
|
+
// --no-bind keeps the repo's mapping, but for Claude Code the hook still runs as the bound agent
|
|
79
|
+
// in every session here: a second Claude Code agent needs its own worktree, not --no-bind.
|
|
80
|
+
if (vendor === "claude-code" && !bool(p.flags, "replace")) {
|
|
81
|
+
const owner = claudeCheckoutOwner(root);
|
|
82
|
+
if (owner && owner.split("/").pop() !== name)
|
|
83
|
+
throw claudeCheckoutTaken(root, owner, name);
|
|
84
|
+
}
|
|
73
85
|
if (!noBind)
|
|
74
86
|
writeIdentityDryRun(root, vendor, name, bool(p.flags, "replace"));
|
|
75
87
|
// The machine's one bschat install comes first: if it cannot be made, the token is not spent.
|
package/dist/harness.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { shellPath } from "./install.js";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
3
|
+
import { basename, dirname, join } from "node:path";
|
|
4
4
|
import { CliError } from "./errors.js";
|
|
5
5
|
/** Canonical vendor ids and the aliases people type. */
|
|
6
6
|
const VENDOR_ALIASES = {
|
|
@@ -45,6 +45,8 @@ export function writeIdentity(root, vendor, name, model, replace, project) {
|
|
|
45
45
|
file = readIdentityFile(p);
|
|
46
46
|
const existing = file.agents[vendor];
|
|
47
47
|
if (existing && existing.name !== name && !replace) {
|
|
48
|
+
if (vendor === "claude-code")
|
|
49
|
+
throw claudeCheckoutTaken(root, existing.project ? `${existing.project}/${existing.name}` : existing.name, name);
|
|
48
50
|
throw new CliError("identity_exists", `${p} already maps ${vendor} to agent "${existing.name}"`, `Two ${vendor} agents share this checkout. Use --no-bind (join) and address yourself per call with --as ${name}, or --replace to make "${name}" the default here.`);
|
|
49
51
|
}
|
|
50
52
|
file.agents[vendor] = { name, project, ...(model ? { model } : {}) };
|
|
@@ -182,3 +184,33 @@ export function withBschatHooks(hooks, bin) {
|
|
|
182
184
|
}
|
|
183
185
|
return out;
|
|
184
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* The Claude Code agent this checkout's hook runs as (its settings' BSCHAT_AGENT, else the identity
|
|
189
|
+
* file's claude-code entry), or null when none is bound here.
|
|
190
|
+
*/
|
|
191
|
+
export function claudeCheckoutOwner(root) {
|
|
192
|
+
const sp = join(root, ".claude", "settings.local.json");
|
|
193
|
+
if (existsSync(sp)) {
|
|
194
|
+
try {
|
|
195
|
+
const env = JSON.parse(readFileSync(sp, "utf8")).env;
|
|
196
|
+
if (env?.BSCHAT_AGENT)
|
|
197
|
+
return env.BSCHAT_AGENT;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
throw new CliError("bad_settings", `${sp} is not valid JSON; fix it or remove it`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const idp = findIdentityFile(root);
|
|
204
|
+
const e = idp && idp.startsWith(root) ? readIdentityFile(idp).agents["claude-code"] : undefined;
|
|
205
|
+
return e ? (e.project ? `${e.project}/${e.name}` : e.name) : null;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Two Claude Code agents cannot share a checkout: its hook runs as one agent for every Claude Code
|
|
209
|
+
* session opened there, so the second session would be handed the first agent's messages, and
|
|
210
|
+
* they would count as delivered. Learned from StickJoy: a second agent joined with --no-bind, and
|
|
211
|
+
* once the hook worked it would have taken the triage lead's notifications. The way out is a worktree.
|
|
212
|
+
*/
|
|
213
|
+
export function claudeCheckoutTaken(root, owner, name) {
|
|
214
|
+
const sibling = join(dirname(root), `${basename(root)}-${name}`);
|
|
215
|
+
return new CliError("checkout_taken", `this checkout's Claude Code hook runs as ${owner} for every Claude Code session opened here, so ${name} would be handed ${owner}'s messages (and they would count as delivered)`, `Give ${name} its own worktree: git -C ${root} worktree add ${sibling} then start Claude Code in ${sibling} and run this command there. (--replace makes ${name} this checkout's Claude Code agent instead of ${owner}.)`);
|
|
216
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { feedback } from "./commands/feedback.js";
|
|
|
11
11
|
import { goal } from "./commands/goal.js";
|
|
12
12
|
import { wake } from "./commands/wake.js";
|
|
13
13
|
import { doctor, install } from "./commands/install.js";
|
|
14
|
+
import { warnIfForeignCopy } from "./install.js";
|
|
14
15
|
import { processCmd, record, wu, milestones, milestone, lock, askOperator } from "./commands/wu.js";
|
|
15
16
|
import { worktrees } from "./commands/worktrees.js";
|
|
16
17
|
import { CliError } from "./errors.js";
|
|
@@ -82,6 +83,7 @@ async function main(argv) {
|
|
|
82
83
|
const fn = COMMANDS[cmd];
|
|
83
84
|
if (!fn)
|
|
84
85
|
throw new CliError("usage", `unknown command ${cmd}`, "Run: bschat --help");
|
|
86
|
+
warnIfForeignCopy(cmd, CLI_VERSION);
|
|
85
87
|
await fn(p, out);
|
|
86
88
|
return 0;
|
|
87
89
|
}
|
package/dist/install.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { configRoot } from "./config.js";
|
|
@@ -106,3 +106,61 @@ export function reloadLaunchAgent(label, path) {
|
|
|
106
106
|
export function restartLaunchAgent(label) {
|
|
107
107
|
return spawnSync("launchctl", ["kickstart", "-k", `gui/${process.getuid()}/${label}`], { stdio: "ignore" }).status === 0;
|
|
108
108
|
}
|
|
109
|
+
/** Commands that legitimately run from a copy other than the recorded install (npx join, old npx hooks). */
|
|
110
|
+
const GUARD_EXEMPT = new Set(["join", "setup", "install", "doctor", "hook", "watch"]);
|
|
111
|
+
/**
|
|
112
|
+
* The line to print when this process is not the machine's recorded install, or null. Pure, so
|
|
113
|
+
* it is tested without a machine: `self` and `recorded` are real paths, `lastAt` when this copy
|
|
114
|
+
* was last warned about (epoch ms).
|
|
115
|
+
*/
|
|
116
|
+
export function foreignCopyNotice(cmd, self, selfVersion, rec, recorded, lastAt, now) {
|
|
117
|
+
if (!rec || !recorded || GUARD_EXEMPT.has(cmd) || self === recorded)
|
|
118
|
+
return null;
|
|
119
|
+
if (lastAt !== null && now - lastAt < 24 * 3600_000)
|
|
120
|
+
return null;
|
|
121
|
+
return `[bschat] this is ${self} (${selfVersion}), not this machine's install ${rec.bin} (${rec.version}). Run that one (put ${dirname(rec.bin)} first on PATH, or remove this copy), or see: bschat doctor`;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Warns once a day per copy when a bschat other than the recorded install runs: another
|
|
125
|
+
* `npm i -g` with a different Node quietly puts a second copy ahead on PATH (a publish routine
|
|
126
|
+
* did exactly that and an operator's shell ran 0.12.37, which had no install command).
|
|
127
|
+
* Never fails a command: a machine state it cannot read only skips the notice.
|
|
128
|
+
*/
|
|
129
|
+
export function warnIfForeignCopy(cmd, selfVersion) {
|
|
130
|
+
let rec;
|
|
131
|
+
try {
|
|
132
|
+
rec = readInstall();
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (!rec || !process.argv[1])
|
|
138
|
+
return;
|
|
139
|
+
let self;
|
|
140
|
+
let recorded;
|
|
141
|
+
try {
|
|
142
|
+
self = realpathSync(process.argv[1]);
|
|
143
|
+
recorded = realpathSync(rec.bin);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const stateFile = join(configRoot(), "state", "foreign-copy.json");
|
|
149
|
+
let seen = {};
|
|
150
|
+
try {
|
|
151
|
+
if (existsSync(stateFile))
|
|
152
|
+
seen = JSON.parse(readFileSync(stateFile, "utf8"));
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
seen = {};
|
|
156
|
+
}
|
|
157
|
+
const line = foreignCopyNotice(cmd, self, selfVersion, rec, recorded, seen[self] ?? null, Date.now());
|
|
158
|
+
if (!line)
|
|
159
|
+
return;
|
|
160
|
+
process.stderr.write(line + "\n");
|
|
161
|
+
try {
|
|
162
|
+
mkdirSync(dirname(stateFile), { recursive: true });
|
|
163
|
+
writeFileSync(stateFile, JSON.stringify({ ...seen, [self]: Date.now() }));
|
|
164
|
+
}
|
|
165
|
+
catch { /* the notice simply repeats next time */ }
|
|
166
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.41";
|