baychat 0.56.0 → 0.57.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/.claude-plugin/plugin.json +1 -1
- package/README.md +7 -0
- package/dist/approval-wait.js +1 -1
- package/dist/bay-gone.js +35 -0
- package/dist/bay-mcp.js +22 -8
- package/dist/channel/launch.js +10 -3
- package/dist/channel/mcp-server.js +37 -0
- package/dist/channel/server.js +6 -20
- package/dist/claude-command.js +130 -0
- package/dist/claude-register.js +162 -0
- package/dist/claude-user-config.js +215 -0
- package/dist/codex-onboarding.js +16 -2
- package/dist/commands.js +22 -187
- package/dist/connect-claude.js +26 -5
- package/dist/connect-link-budget.js +2 -0
- package/dist/connect-link-check.js +96 -0
- package/dist/connect-link-setup.js +17 -0
- package/dist/connect-link.js +41 -34
- package/dist/doctor-claude-file.js +17 -0
- package/dist/doctor-command.js +3 -0
- package/dist/doctor-questions.js +22 -0
- package/dist/doctor.js +13 -12
- package/dist/notify-answer.js +53 -31
- package/dist/protocol-content.js +1 -1
- package/dist/quiet-claude-env.js +15 -0
- package/dist/refresh-clients.js +4 -6
- package/dist/relay/launcher/blocking-screen.fixtures.js +147 -0
- package/dist/relay/launcher/blocking-screen.js +68 -0
- package/dist/relay/launcher/dev-channel-screen.js +1 -1
- package/dist/relay/launcher/handle.js +3 -2
- package/dist/relay/launcher/loop.js +3 -0
- package/dist/relay/launcher/multiplexer.js +26 -0
- package/dist/relay/launcher/pane-watch.js +16 -0
- package/dist/relay/launcher/reset-time.js +82 -0
- package/dist/relay/launcher/session-watch-deps.js +116 -0
- package/dist/relay/launcher/session-watch.js +252 -0
- package/dist/runtimes.js +1 -3
- package/dist/tool-defs.js +6 -6
- package/dist/tool-hints.js +11 -5
- package/dist/waiting-cards.js +33 -3
- package/package.json +2 -2
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.realClaudeConfigIo = exports.claudeUserConfigFile = void 0;
|
|
37
|
+
exports.claudeOnPath = claudeOnPath;
|
|
38
|
+
exports.claudeUserServerNamed = claudeUserServerNamed;
|
|
39
|
+
exports.claudeHttpServer = claudeHttpServer;
|
|
40
|
+
exports.claudeStdioServer = claudeStdioServer;
|
|
41
|
+
exports.editClaudeUserServers = editClaudeUserServers;
|
|
42
|
+
/**
|
|
43
|
+
* Claude Code's user config, written by BayChat itself when this computer has no `claude` command.
|
|
44
|
+
*
|
|
45
|
+
* WHY. A computer with only the Claude app (its Code tab) has no `claude` on PATH, so
|
|
46
|
+
* `claude mcp add` cannot run. Until 26 Nov 2026 `connect claude` then printed a command for the
|
|
47
|
+
* person to finish by hand, with their token to be copied out of ~/.baychat/credentials.json — the
|
|
48
|
+
* opposite of a one-paste connect (Primea's PC: "'claude' is not recognized", exit 2).
|
|
49
|
+
*
|
|
50
|
+
* WHAT CLAUDE CODE READS (checked 26 Nov 2026 with the Claude Code 2.1.286 the Claude app bundles,
|
|
51
|
+
* in a sandbox): `claude mcp add --scope user` writes `mcpServers.<name>` into `~/.claude.json` —
|
|
52
|
+
* `{ type: "http", url, headers }` — and into `$CLAUDE_CONFIG_DIR/.claude.json` when that is set.
|
|
53
|
+
* The terminal, the IDE extensions and the desktop app "all read the same settings files"
|
|
54
|
+
* (code.claude.com/docs/en/settings). On Windows `~` is `%USERPROFILE%` (same page), which is what
|
|
55
|
+
* `os.homedir()` returns there.
|
|
56
|
+
*
|
|
57
|
+
* FILE SAFETY. The file is Claude Code's own and holds far more than servers (projects, history
|
|
58
|
+
* flags, account ids): every other key is kept, a timestamped copy of the old file is left beside
|
|
59
|
+
* it, the new one is written to a temporary file and renamed over (never half-written), keeping the
|
|
60
|
+
* file's mode (0600 for a new one: it now holds a bearer token). A file that is not JSON is left alone, never replaced.
|
|
61
|
+
* The token is written, never printed.
|
|
62
|
+
*/
|
|
63
|
+
const fs = __importStar(require("node:fs"));
|
|
64
|
+
const os = __importStar(require("node:os"));
|
|
65
|
+
const path = __importStar(require("node:path"));
|
|
66
|
+
const claude_trust_1 = require("./launch/claude-trust");
|
|
67
|
+
/** The file Claude Code keeps user-scope MCP servers in: the one `launch/claude-trust.ts` already reads. */
|
|
68
|
+
const claudeUserConfigFile = (env = process.env, home = os.homedir()) => (0, claude_trust_1.claudeConfigPath)(env, home);
|
|
69
|
+
exports.claudeUserConfigFile = claudeUserConfigFile;
|
|
70
|
+
/**
|
|
71
|
+
* Is there a `claude` command on PATH? Read from the disk, no process spawned: through cmd.exe a
|
|
72
|
+
* missing command is only an exit code and a sentence in the system's language (exit 1 and
|
|
73
|
+
* "'claude' is not recognized…" on Primea's PC, where the code expected 9009).
|
|
74
|
+
*/
|
|
75
|
+
function claudeOnPath(env = process.env, platform = process.platform, isFile = realIsFile) {
|
|
76
|
+
const windows = platform === "win32";
|
|
77
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(windows ? ";" : ":").filter((d) => d.trim() !== "");
|
|
78
|
+
const names = windows ? ["claude.exe", "claude.cmd", "claude.bat", "claude"] : ["claude"];
|
|
79
|
+
const p = windows ? path.win32 : path.posix;
|
|
80
|
+
return dirs.some((dir) => names.some((name) => isFile(p.join(dir.replace(/^"|"$/g, ""), name))));
|
|
81
|
+
}
|
|
82
|
+
function realIsFile(p) {
|
|
83
|
+
try {
|
|
84
|
+
return fs.statSync(p).isFile();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return false; // Absent or unreadable: not a command we could run.
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Does Claude Code's user config name this server? Unreadable or absent counts as no. */
|
|
91
|
+
function claudeUserServerNamed(name, file = (0, exports.claudeUserConfigFile)(), io = exports.realClaudeConfigIo) {
|
|
92
|
+
try {
|
|
93
|
+
const servers = JSON.parse(io.read(file) ?? "{}").mcpServers;
|
|
94
|
+
return !!servers && typeof servers === "object" && Object.hasOwn(servers, name);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return false; // Not JSON, or unreadable: nothing we can say it names.
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** An http server entry, the shape `claude mcp add --transport http … --header` writes. */
|
|
101
|
+
function claudeHttpServer(url, token) {
|
|
102
|
+
return { type: "http", url, headers: { Authorization: `Bearer ${token}` } };
|
|
103
|
+
}
|
|
104
|
+
/** A stdio server entry, the shape `claude mcp add --scope user <name> -- <command> <args…>` writes. */
|
|
105
|
+
function claudeStdioServer(command, args) {
|
|
106
|
+
return { type: "stdio", command, args, env: {} };
|
|
107
|
+
}
|
|
108
|
+
exports.realClaudeConfigIo = {
|
|
109
|
+
read: (file) => {
|
|
110
|
+
try {
|
|
111
|
+
return fs.readFileSync(file, "utf8");
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
if (err.code === "ENOENT")
|
|
115
|
+
return null;
|
|
116
|
+
throw err; // Unreadable is not absent: never overwrite a file we could not read.
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
write: (file, content) => {
|
|
120
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
121
|
+
let mode = 0o600; // A new file: it holds a bearer token.
|
|
122
|
+
try {
|
|
123
|
+
mode = fs.statSync(file).mode & 0o777; // An existing one keeps the mode it had.
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// No file yet: 0600.
|
|
127
|
+
}
|
|
128
|
+
const tmp = `${file}.baychat-tmp-${process.pid}`;
|
|
129
|
+
try {
|
|
130
|
+
fs.writeFileSync(tmp, content, { mode });
|
|
131
|
+
fs.chmodSync(tmp, mode); // writeFileSync's mode is masked by the umask.
|
|
132
|
+
fs.renameSync(tmp, file);
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
// The temporary file holds the bearer token: it never outlives a failed write (Windows EPERM
|
|
136
|
+
// when the app or an antivirus holds the file, a full disk…).
|
|
137
|
+
fs.rmSync(tmp, { force: true });
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
copy: (from, to) => fs.copyFileSync(from, to),
|
|
142
|
+
list: (dir) => {
|
|
143
|
+
try {
|
|
144
|
+
return fs.readdirSync(dir);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return []; // No folder: no older copies to tidy.
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
remove: (file) => fs.rmSync(file, { force: true }),
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Set and remove user-scope servers in Claude Code's config, keeping everything else.
|
|
154
|
+
*
|
|
155
|
+
* @returns what happened, for the caller to say in plain words; never throws.
|
|
156
|
+
*/
|
|
157
|
+
function editClaudeUserServers(edit, opts = {}) {
|
|
158
|
+
const file = opts.file ?? (0, exports.claudeUserConfigFile)();
|
|
159
|
+
const io = opts.io ?? exports.realClaudeConfigIo;
|
|
160
|
+
try {
|
|
161
|
+
const before = io.read(file);
|
|
162
|
+
let config = {};
|
|
163
|
+
if (before !== null && before.trim() !== "") {
|
|
164
|
+
const parsed = JSON.parse(before);
|
|
165
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
166
|
+
return { ok: false, file, reason: "it does not hold a settings object, so it was left as it was" };
|
|
167
|
+
}
|
|
168
|
+
config = parsed;
|
|
169
|
+
}
|
|
170
|
+
const current = config.mcpServers;
|
|
171
|
+
const servers = current && typeof current === "object" && !Array.isArray(current) ? { ...current } : {};
|
|
172
|
+
for (const name of edit.remove ?? [])
|
|
173
|
+
delete servers[name];
|
|
174
|
+
Object.assign(servers, edit.set ?? {});
|
|
175
|
+
const next = { ...config, mcpServers: servers };
|
|
176
|
+
if (JSON.stringify(next) === JSON.stringify(config))
|
|
177
|
+
return { ok: true, file, changed: false, backup: null };
|
|
178
|
+
let backup = null;
|
|
179
|
+
if (before !== null && before.trim() !== "") {
|
|
180
|
+
backup = `${file}.baychat-backup-${stamp(opts.now ?? new Date())}`;
|
|
181
|
+
io.copy(file, backup);
|
|
182
|
+
}
|
|
183
|
+
io.write(file, JSON.stringify(next, null, 2) + "\n");
|
|
184
|
+
if (backup)
|
|
185
|
+
dropOlderBackups(file, backup, io);
|
|
186
|
+
return { ok: true, file, changed: true, backup };
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
const why = err instanceof SyntaxError ? "it is not valid JSON, so it was left as it was" : err instanceof Error ? err.message : String(err);
|
|
190
|
+
return { ok: false, file, reason: why };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Each copy holds the token of its day: only the newest BayChat copy is kept. Never another
|
|
195
|
+
* program's backups (`.claude.json.backup`, Claude Code's own `backups/`).
|
|
196
|
+
*/
|
|
197
|
+
function dropOlderBackups(file, keep, io) {
|
|
198
|
+
const dir = path.dirname(file);
|
|
199
|
+
const prefix = `${path.basename(file)}.baychat-backup-`;
|
|
200
|
+
for (const name of io.list(dir)) {
|
|
201
|
+
const full = path.join(dir, name);
|
|
202
|
+
if (name.startsWith(prefix) && /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}Z$/.test(name.slice(prefix.length)) && full !== keep) {
|
|
203
|
+
try {
|
|
204
|
+
io.remove(full);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
// A copy that cannot be removed now is removed by the next write; the write itself is done.
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** 2026-11-26T21-58-03Z: sortable, and legal in a Windows file name (no colons). */
|
|
213
|
+
function stamp(now) {
|
|
214
|
+
return now.toISOString().replace(/\.\d{3}Z$/, "Z").replace(/:/g, "-");
|
|
215
|
+
}
|
package/dist/codex-onboarding.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CODEX_JOIN_STEPS = void 0;
|
|
4
|
+
exports.autoNameLines = autoNameLines;
|
|
4
5
|
/**
|
|
5
6
|
* Codex joins THROUGH MCP and uses its existing native turn queue for later wakes.
|
|
6
7
|
*
|
|
@@ -18,8 +19,8 @@ exports.CODEX_JOIN_STEPS = `1. Preserve BOTH arguments. The first argument is th
|
|
|
18
19
|
(the value from step 2). For \`$baychat codex "vps_baychat"\` call exactly:
|
|
19
20
|
\`join_session({ session: "codex", group: "vps_baychat", runtime: "codex", threadId: "<CODEX_THREAD_ID>" })\`
|
|
20
21
|
With only a chosen name pass neither \`group\` nor \`sessions\` (your private chat with your
|
|
21
|
-
owner). With \`--sessions\` pass \`sessions: true\` instead of \`group\`. For automatic naming run \`baychat session-name --runtime codex\` (local,
|
|
22
|
-
sandbox-safe) and use the name it prints, with \`group: "<title>"\` or \`sessions: true\`.
|
|
22
|
+
owner). With \`--sessions\` pass \`sessions: true\` instead of \`group\`. For automatic naming (no name given) run \`baychat session-name --runtime codex\` (local,
|
|
23
|
+
sandbox-safe) and use the name it prints, without asking the user, with \`group: "<title>"\` or \`sessions: true\`.
|
|
23
24
|
Do not drop the name, swap the arguments, or join Sessions when a group was supplied.
|
|
24
25
|
A bare invocation lists sessions and stops.
|
|
25
26
|
**Do NOT run \`baychat join … --runtime codex\` or any \`baychat relay\` command from inside
|
|
@@ -46,3 +47,16 @@ exports.CODEX_JOIN_STEPS = `1. Preserve BOTH arguments. The first argument is th
|
|
|
46
47
|
Registration is not proof that the model has read or answered a message.
|
|
47
48
|
Successful setup ends here; do not start a second diagnostic workflow.
|
|
48
49
|
`;
|
|
50
|
+
/**
|
|
51
|
+
* How a session with no name gets one, under "## Invocation". Codex joins by MCP, not by the join
|
|
52
|
+
* command, so "the join command chooses a name" left it nothing to run and it asked the user
|
|
53
|
+
* (review, 29 Nov): it runs `baychat session-name` itself, and asks only when that fails.
|
|
54
|
+
*/
|
|
55
|
+
function autoNameLines(runtime) {
|
|
56
|
+
if (runtime === "codex")
|
|
57
|
+
return ` Run \`baychat session-name --runtime codex\` and join with the name it prints.
|
|
58
|
+
Do not ask the user for a name; only if that command fails, ask for one.`;
|
|
59
|
+
return ` The join command chooses a name from this verified native session. It stays
|
|
60
|
+
the same for this session and differs for other sessions. If verification
|
|
61
|
+
fails, ask the user for a name.`;
|
|
62
|
+
}
|
package/dist/commands.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.realConfigIo = exports.WINDOWS_UNSAFE = exports.quoteForCmd = exports.cmdExeSpawn = exports.CATCHUP_UNTRUSTED_REMINDER = void 0;
|
|
6
|
+
exports.realConfigIo = exports.registerWithClaude = exports.claudeSpawn = exports.claudeMcpAddSpawn = exports.WINDOWS_UNSAFE = exports.quoteForCmd = exports.cmdExeSpawn = exports.CATCHUP_UNTRUSTED_REMINDER = void 0;
|
|
7
7
|
exports.requireCredentials = requireCredentials;
|
|
8
8
|
exports.cmdPair = cmdPair;
|
|
9
9
|
exports.cmdWhoami = cmdWhoami;
|
|
@@ -18,11 +18,8 @@ exports.resetSessionState = resetSessionState;
|
|
|
18
18
|
exports.cmdCheck = cmdCheck;
|
|
19
19
|
exports.cmdWatch = cmdWatch;
|
|
20
20
|
exports.cmdLink = cmdLink;
|
|
21
|
-
exports.claudeSpawn = claudeSpawn;
|
|
22
|
-
exports.claudeMcpAddSpawn = claudeMcpAddSpawn;
|
|
23
21
|
exports.refreshConnectedClients = refreshConnectedClients;
|
|
24
22
|
exports.refreshClientsAfterRenewal = refreshClientsAfterRenewal;
|
|
25
|
-
exports.registerWithClaude = registerWithClaude;
|
|
26
23
|
exports.cmdLogin = cmdLogin;
|
|
27
24
|
exports.deviceExpiryWarning = deviceExpiryWarning;
|
|
28
25
|
exports.printDeviceExpiryWarning = printDeviceExpiryWarning;
|
|
@@ -39,9 +36,7 @@ const connection_qr_1 = require("./connection-qr");
|
|
|
39
36
|
const config_1 = require("./config");
|
|
40
37
|
const bay_mcp_1 = require("./bay-mcp");
|
|
41
38
|
const client_scope_1 = require("./client-scope");
|
|
42
|
-
const windows_cmd_1 = require("./windows-cmd");
|
|
43
39
|
const context_1 = require("./context");
|
|
44
|
-
const runtime_install_1 = require("./runtime-install");
|
|
45
40
|
const credential_refresh_1 = require("./credential-refresh");
|
|
46
41
|
const client_paths_1 = require("./client-paths");
|
|
47
42
|
const device_login_1 = require("./device-login");
|
|
@@ -566,74 +561,17 @@ async function cmdLink(opts = {}) {
|
|
|
566
561
|
// The user-credential twin of `cmdLink`: same reverse-QR mechanics, but the
|
|
567
562
|
// approved token acts as the HUMAN and unlocks the remote MCP server, so one
|
|
568
563
|
// command both logs the laptop in and registers BayChat with Claude Code.
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
function
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* The spawn recipe for `claude <args>`, or null when it cannot be run safely.
|
|
582
|
-
*
|
|
583
|
-
* On Windows `claude` is a `.cmd` shim, and Node has refused to spawn `.bat` /
|
|
584
|
-
* `.cmd` directly since the CVE-2024-27980 fix (18.20.2 / 20.12.2+) — it throws
|
|
585
|
-
* EINVAL. Every runtime this package supports (node >=20) is past that fix, so
|
|
586
|
-
* naming `claude.cmd` explicitly cannot work either: cmd.exe is the only route
|
|
587
|
-
* (`cmdExeSpawn`, the same line `shell: true` used to build).
|
|
588
|
-
*
|
|
589
|
-
* The cost of cmd.exe is that arguments become shell syntax. It gets one string
|
|
590
|
-
* of argv joined with spaces, so `Authorization: Bearer <token>` would arrive as
|
|
591
|
-
* three separate arguments, and a `&` in an interpolated value would arrive as a
|
|
592
|
-
* command separator. Hence: quote every argument here, and refuse outright when
|
|
593
|
-
* a value contains something quoting cannot contain. Refusing costs the user one
|
|
594
|
-
* manual paste; guessing would run their token through a command interpreter.
|
|
595
|
-
*
|
|
596
|
-
* POSIX keeps `execve` semantics — argv is passed verbatim, there is no shell to
|
|
597
|
-
* interpret it, and so nothing to quote or refuse.
|
|
598
|
-
*/
|
|
599
|
-
function claudeSpawn(platform, args) {
|
|
600
|
-
if (platform !== "win32")
|
|
601
|
-
return { command: "claude", args, viaCmd: false };
|
|
602
|
-
if (args.some((a) => windows_cmd_1.WINDOWS_UNSAFE.test(a)))
|
|
603
|
-
return null;
|
|
604
|
-
return { ...(0, windows_cmd_1.cmdExeSpawn)("claude", args.map(windows_cmd_1.quoteForCmd)), viaCmd: true };
|
|
605
|
-
}
|
|
606
|
-
/** `claude mcp add` for the remote BayChat server — see `claudeSpawn`. */
|
|
607
|
-
function claudeMcpAddSpawn(platform, baseUrl, token) {
|
|
608
|
-
const args = [
|
|
609
|
-
"mcp",
|
|
610
|
-
"add",
|
|
611
|
-
"--transport",
|
|
612
|
-
"http",
|
|
613
|
-
"--scope",
|
|
614
|
-
"user",
|
|
615
|
-
"baychat",
|
|
616
|
-
`${baseUrl}/api/mcp`,
|
|
617
|
-
"--header",
|
|
618
|
-
`Authorization: Bearer ${token}`,
|
|
619
|
-
];
|
|
620
|
-
return claudeSpawn(platform, args);
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Register the remote BayChat MCP server with Claude Code, carrying the device
|
|
624
|
-
* token as a static Authorization header.
|
|
625
|
-
*
|
|
626
|
-
* The token travels in argv, which is briefly visible in a process listing on a
|
|
627
|
-
* shared machine. That is the accepted trade for a one-command login.
|
|
628
|
-
*
|
|
629
|
-
* Neither a missing `claude` binary nor a rejected add is a login failure — the
|
|
630
|
-
* credential is already saved — so both only print and return. They print
|
|
631
|
-
* DIFFERENTLY, though: the common non-zero exit is a renewal where an MCP server
|
|
632
|
-
* named `baychat` already exists, and reporting that as "CLI not found" would
|
|
633
|
-
* send the user hunting for the wrong problem while Claude Code quietly keeps
|
|
634
|
-
* the old, expiring token. We surface the real reason and suggest the removal —
|
|
635
|
-
* we never run it for them, since that server entry may not be ours.
|
|
636
|
-
*/
|
|
564
|
+
var windows_cmd_1 = require("./windows-cmd");
|
|
565
|
+
Object.defineProperty(exports, "cmdExeSpawn", { enumerable: true, get: function () { return windows_cmd_1.cmdExeSpawn; } });
|
|
566
|
+
Object.defineProperty(exports, "quoteForCmd", { enumerable: true, get: function () { return windows_cmd_1.quoteForCmd; } });
|
|
567
|
+
Object.defineProperty(exports, "WINDOWS_UNSAFE", { enumerable: true, get: function () { return windows_cmd_1.WINDOWS_UNSAFE; } });
|
|
568
|
+
var claude_register_1 = require("./claude-register");
|
|
569
|
+
Object.defineProperty(exports, "claudeMcpAddSpawn", { enumerable: true, get: function () { return claude_register_1.claudeMcpAddSpawn; } });
|
|
570
|
+
Object.defineProperty(exports, "claudeSpawn", { enumerable: true, get: function () { return claude_register_1.claudeSpawn; } });
|
|
571
|
+
Object.defineProperty(exports, "registerWithClaude", { enumerable: true, get: function () { return claude_register_1.registerWithClaude; } });
|
|
572
|
+
const claude_register_2 = require("./claude-register");
|
|
573
|
+
const claude_command_1 = require("./claude-command");
|
|
574
|
+
const claude_user_config_1 = require("./claude-user-config");
|
|
637
575
|
/**
|
|
638
576
|
* Bring every already-connected client onto the credential we just saved.
|
|
639
577
|
*
|
|
@@ -688,122 +626,19 @@ exports.realConfigIo = {
|
|
|
688
626
|
*/
|
|
689
627
|
function refreshClientsAfterRenewal(baseUrl, token) {
|
|
690
628
|
refreshConnectedClients(baseUrl, token);
|
|
691
|
-
const
|
|
629
|
+
const claude = (0, claude_command_1.findClaude)();
|
|
630
|
+
// No `claude` to ask: Claude Code's own file says whether BayChat was connected there.
|
|
631
|
+
if (!claude) {
|
|
632
|
+
if ((0, claude_user_config_1.claudeUserServerNamed)("baychat"))
|
|
633
|
+
(0, claude_register_2.registerWithClaude)(baseUrl, token);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const get = (0, claude_register_2.claudeSpawn)(process.platform, ["mcp", "get", "baychat"], claude);
|
|
692
637
|
if (!get)
|
|
693
638
|
return;
|
|
694
639
|
const res = (0, node_child_process_1.spawnSync)(get.command, get.args, { encoding: "utf8", stdio: "ignore", timeout: 15_000, windowsVerbatimArguments: get.viaCmd });
|
|
695
640
|
if (res.status === 0)
|
|
696
|
-
registerWithClaude(baseUrl, token);
|
|
697
|
-
}
|
|
698
|
-
function registerWithClaude(baseUrl, token) {
|
|
699
|
-
const recipe = claudeMcpAddSpawn(process.platform, baseUrl, token);
|
|
700
|
-
if (!recipe) {
|
|
701
|
-
// Windows only, and only for a value a quoted cmd.exe argument cannot hold.
|
|
702
|
-
console.log("\nCould not add BayChat to Claude Code safely on Windows — add it manually:");
|
|
703
|
-
printManualMcpAdd(baseUrl);
|
|
704
|
-
return false;
|
|
705
|
-
}
|
|
706
|
-
// stderr is captured (not ignored) so a failure can quote claude's own words;
|
|
707
|
-
// the timeout keeps a hung binary from hanging a login whose credential is
|
|
708
|
-
// already on disk — a timeout lands in the failure branch below as ETIMEDOUT.
|
|
709
|
-
const res = (0, node_child_process_1.spawnSync)(recipe.command, recipe.args, {
|
|
710
|
-
encoding: "utf8",
|
|
711
|
-
stdio: ["ignore", "ignore", "pipe"],
|
|
712
|
-
timeout: 15_000,
|
|
713
|
-
killSignal: "SIGKILL",
|
|
714
|
-
windowsVerbatimArguments: recipe.viaCmd,
|
|
715
|
-
});
|
|
716
|
-
// 9009 is cmd.exe's "'claude' is not recognized": through cmd.exe there is no
|
|
717
|
-
// ENOENT to catch, and reporting a missing binary as a generic failure would
|
|
718
|
-
// point the user at the renewal advice below instead of at installing it.
|
|
719
|
-
// "already exists" is what a RENEWAL looks like, and it was being reported as
|
|
720
|
-
// a failure — leaving Claude Code registered with the token that just expired
|
|
721
|
-
// and telling the user to run two commands by hand. Renewal is the normal
|
|
722
|
-
// scheduled state of a credential with an expiry, so it is handled, not
|
|
723
|
-
// reported.
|
|
724
|
-
if (res.status !== 0 && /already exists/i.test(String(res.stderr ?? ""))) {
|
|
725
|
-
// Fixed words only, so this recipe is never null where `recipe` was not.
|
|
726
|
-
const remove = claudeSpawn(process.platform, ["mcp", "remove", "baychat"]);
|
|
727
|
-
const removed = (0, node_child_process_1.spawnSync)(remove.command, remove.args, {
|
|
728
|
-
encoding: "utf8",
|
|
729
|
-
stdio: ["ignore", "ignore", "pipe"],
|
|
730
|
-
timeout: 15_000,
|
|
731
|
-
windowsVerbatimArguments: remove.viaCmd,
|
|
732
|
-
});
|
|
733
|
-
if (removed.status === 0) {
|
|
734
|
-
const readded = (0, node_child_process_1.spawnSync)(recipe.command, recipe.args, {
|
|
735
|
-
encoding: "utf8",
|
|
736
|
-
stdio: ["ignore", "ignore", "pipe"],
|
|
737
|
-
timeout: 15_000,
|
|
738
|
-
windowsVerbatimArguments: recipe.viaCmd,
|
|
739
|
-
});
|
|
740
|
-
if (readded.status === 0) {
|
|
741
|
-
console.log("✓ BayChat re-registered with Claude Code (credential renewed)");
|
|
742
|
-
installClaudeSkill();
|
|
743
|
-
return true;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
if (recipe.viaCmd && res.status === 9009) {
|
|
748
|
-
console.log("\nClaude Code CLI not found — add BayChat manually:");
|
|
749
|
-
printManualMcpAdd(baseUrl);
|
|
750
|
-
return false;
|
|
751
|
-
}
|
|
752
|
-
if (res.error && res.error.code === "ENOENT") {
|
|
753
|
-
console.log("\nClaude Code CLI not found — add BayChat manually:");
|
|
754
|
-
printManualMcpAdd(baseUrl);
|
|
755
|
-
return false;
|
|
756
|
-
}
|
|
757
|
-
if (res.error || res.status !== 0) {
|
|
758
|
-
const reason = res.error?.code ??
|
|
759
|
-
res.error?.message ??
|
|
760
|
-
`exit ${res.status}`;
|
|
761
|
-
console.log(`\nCould not add BayChat to Claude Code (${reason}).`);
|
|
762
|
-
// Defensive redaction: the token is in argv, not in output, but a CLI that
|
|
763
|
-
// echoes the failing command back would otherwise print it to scrollback.
|
|
764
|
-
const stderr = String(res.stderr ?? "").split(token).join("<token>").trim();
|
|
765
|
-
if (stderr)
|
|
766
|
-
for (const line of stderr.split("\n").slice(0, 3))
|
|
767
|
-
console.log(` ${line}`);
|
|
768
|
-
console.log('\n If a server named "baychat" is already registered (a renewal), remove it:');
|
|
769
|
-
console.log(" claude mcp remove baychat");
|
|
770
|
-
console.log(" then add it back:");
|
|
771
|
-
printManualMcpAdd(baseUrl);
|
|
772
|
-
// The skill is independent of the MCP registration and must not be skipped
|
|
773
|
-
// because of it: a session with the rules and no tools still knows how to
|
|
774
|
-
// ask for them, while one with neither knows nothing at all.
|
|
775
|
-
installClaudeSkill();
|
|
776
|
-
return false;
|
|
777
|
-
}
|
|
778
|
-
console.log("✓ BayChat added to Claude Code");
|
|
779
|
-
installClaudeSkill();
|
|
780
|
-
return true;
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* Install Claude Code's BayChat skill, the other half of registering the server.
|
|
784
|
-
*
|
|
785
|
-
* `runtimes.ts` has always declared this file — `.claude/skills/baychat/SKILL.md`
|
|
786
|
-
* — and until now nothing wrote it. `connect` installs a runtime's skill, but
|
|
787
|
-
* `connect` does not accept `claude`; Claude Code is set up by `login`, and
|
|
788
|
-
* `login` only ever called `claude mcp add`. So every Claude Code user got the
|
|
789
|
-
* TOOLS and never the RULES: no `/baychat`, and no protocol telling the session
|
|
790
|
-
* about shouldRespond, the round cap, or re-arming attach.
|
|
791
|
-
*
|
|
792
|
-
* That is the same half-finished install this release teaches `doctor` to flag,
|
|
793
|
-
* sitting in our own setup path.
|
|
794
|
-
*
|
|
795
|
-
* Best-effort: the credential is already on disk and the server is already
|
|
796
|
-
* registered, so a skill that could not be written is worth a line, never a
|
|
797
|
-
* failed login.
|
|
798
|
-
*/
|
|
799
|
-
function installClaudeSkill() {
|
|
800
|
-
try {
|
|
801
|
-
for (const line of (0, runtime_install_1.describeInstall)((0, runtime_install_1.installRuntimeCommand)("claude")))
|
|
802
|
-
console.log(` ${line}`);
|
|
803
|
-
}
|
|
804
|
-
catch (err) {
|
|
805
|
-
console.log(` Could not install the Claude Code skill: ${err instanceof Error ? err.message : String(err)}`);
|
|
806
|
-
}
|
|
641
|
+
(0, claude_register_2.registerWithClaude)(baseUrl, token);
|
|
807
642
|
}
|
|
808
643
|
/**
|
|
809
644
|
* `baychat login` — log this laptop in to BayChat as the human.
|
|
@@ -946,7 +781,7 @@ function completeDeviceLogin(device, options) {
|
|
|
946
781
|
else {
|
|
947
782
|
refreshConnectedClients(device.baseUrl, device.token);
|
|
948
783
|
if (options.registerClaude !== false)
|
|
949
|
-
registerWithClaude(device.baseUrl, device.token);
|
|
784
|
+
(0, claude_register_2.registerWithClaude)(device.baseUrl, device.token);
|
|
950
785
|
(0, bay_mcp_1.applyBayEntries)(device.baseUrl, options.previousBays ?? [], bays, {
|
|
951
786
|
claude: options.registerClaude !== false,
|
|
952
787
|
io: exports.realConfigIo,
|
package/dist/connect-claude.js
CHANGED
|
@@ -4,15 +4,17 @@ exports.cmdConnectClaude = cmdConnectClaude;
|
|
|
4
4
|
exports.channelReport = channelReport;
|
|
5
5
|
const commands_1 = require("./commands");
|
|
6
6
|
const config_1 = require("./config");
|
|
7
|
+
const bay_gone_1 = require("./bay-gone");
|
|
7
8
|
const bay_mcp_1 = require("./bay-mcp");
|
|
8
9
|
const client_paths_1 = require("./client-paths");
|
|
9
|
-
const runtime_install_1 = require("./runtime-install");
|
|
10
10
|
const connect_link_budget_1 = require("./connect-link-budget");
|
|
11
11
|
const bay_mcp_2 = require("./bay-mcp");
|
|
12
12
|
const context_hooks_command_1 = require("./context-hooks-command");
|
|
13
13
|
const launch_1 = require("./channel/launch");
|
|
14
14
|
const plugin_1 = require("./channel/plugin");
|
|
15
15
|
const ws_1 = require("./relay/ws");
|
|
16
|
+
const claude_command_1 = require("./claude-command");
|
|
17
|
+
const commands_2 = require("./relay/commands");
|
|
16
18
|
/** One-time Claude setup reuses a valid login, registers MCP, and refreshes its skill. */
|
|
17
19
|
async function cmdConnectClaude(opts = {}) {
|
|
18
20
|
try {
|
|
@@ -51,11 +53,23 @@ async function cmdConnectClaude(opts = {}) {
|
|
|
51
53
|
// the current set as "previous" too removes only entries that no longer belong — e.g. the
|
|
52
54
|
// Bay that is now the default.
|
|
53
55
|
const bays = (0, config_1.loadBayLogins)();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
// A Bay deleted in BayChat (its MCP answers 410) leaves this computer, once: its login and its
|
|
57
|
+
// `baychat-<bay>` entries (bay-gone.ts; Karmen's server and Harbour, 26 Nov 2026).
|
|
58
|
+
const gone = await (0, bay_gone_1.goneBays)(device.baseUrl, bays);
|
|
59
|
+
const current = bays.filter((b) => !gone.has(b.bayId));
|
|
60
|
+
for (const b of bays.filter((b) => gone.has(b.bayId)))
|
|
61
|
+
console.log(` "${b.bayName}" was deleted in BayChat: removed from this computer.`);
|
|
62
|
+
if (gone.size > 0)
|
|
63
|
+
(0, config_1.saveDeviceCredentials)(device, current);
|
|
64
|
+
(0, bay_mcp_1.applyBayEntries)(device.baseUrl, bays, current, { claude: true, io: commands_1.realConfigIo, env: (0, client_paths_1.currentPathEnv)() });
|
|
65
|
+
// (The skill: registerWithClaude installs it, whatever happened to the server.)
|
|
57
66
|
if (!registered)
|
|
58
67
|
return 1;
|
|
68
|
+
// The relay starts sessions from the BayChat app and wakes them (docs/features/REMOTE_MCP_SESSIONS.md).
|
|
69
|
+
// Left out on 12 Sep, when sessions listened only through a Monitor; a computer set up by one paste
|
|
70
|
+
// then had no relay, and "start a session from the BayChat app" did nothing (Primea's PC, 26 Nov).
|
|
71
|
+
if (!opts.mode)
|
|
72
|
+
console.log(` ${await (0, commands_2.ensureRelayInstalled)()}`);
|
|
59
73
|
for (const line of channelReport(registerChannel(), { version: process.version, webSocket: (0, ws_1.hasBuiltInWebSocket)() }))
|
|
60
74
|
console.log(line);
|
|
61
75
|
console.log(' Restart Claude Code once, then use /baychat <name> "<group>".');
|
|
@@ -77,7 +91,11 @@ function registerChannel() {
|
|
|
77
91
|
const problem = (0, context_hooks_command_1.launchProblem)(launch);
|
|
78
92
|
if (problem)
|
|
79
93
|
return { skipped: problem };
|
|
80
|
-
|
|
94
|
+
// The channel is a plugin, installed only through a `claude` (on PATH or the Claude app's own).
|
|
95
|
+
const claude = (0, claude_command_1.findClaude)();
|
|
96
|
+
if (!claude)
|
|
97
|
+
return "no-claude";
|
|
98
|
+
const run = (0, bay_mcp_2.realClaudeRun)(process.platform, claude);
|
|
81
99
|
// The plugin first: it updates with the npm package and is the form Anthropic can approve.
|
|
82
100
|
// Where this Claude Code cannot install it, the same server is registered by hand.
|
|
83
101
|
if ((0, plugin_1.installPluginWithClaude)(run))
|
|
@@ -96,6 +114,9 @@ function registerChannel() {
|
|
|
96
114
|
* said here, at the moment of setup, rather than discovered as a silent session later.
|
|
97
115
|
*/
|
|
98
116
|
function channelReport(result, node) {
|
|
117
|
+
if (result === "no-claude") {
|
|
118
|
+
return [" No wake-up channel: it needs the `claude` command, which this computer does not have. BayChat's tools work in Claude Code; new messages arrive through the Monitor."];
|
|
119
|
+
}
|
|
99
120
|
if (result !== "registered") {
|
|
100
121
|
return [
|
|
101
122
|
` BayChat channel not added: ${result.skipped}`,
|
|
@@ -25,6 +25,8 @@ exports.CONNECT_LINK_CAPS = {
|
|
|
25
25
|
otherSetup: 15_000,
|
|
26
26
|
/** Joining the Bay and saying hello over MCP. */
|
|
27
27
|
join: 20_000,
|
|
28
|
+
/** The doctor's checks after the join, and the fixes they call for (connect-link-check.ts). */
|
|
29
|
+
check: 12_000,
|
|
28
30
|
};
|
|
29
31
|
/** Kept back for the join while apps are set up: without the join, nobody sees the hello. */
|
|
30
32
|
exports.JOIN_RESERVE_MS = 15_000;
|