baychat 0.27.1 → 0.29.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.
Files changed (53) hide show
  1. package/.claude-plugin/plugin.json +32 -0
  2. package/README.md +42 -4
  3. package/dist/approve-hook.js +93 -3
  4. package/dist/channel/claude-link.js +145 -0
  5. package/dist/channel/detect.js +10 -2
  6. package/dist/channel/feed.js +27 -13
  7. package/dist/channel/launch.js +67 -12
  8. package/dist/channel/permission.js +118 -0
  9. package/dist/channel/plugin.js +182 -0
  10. package/dist/channel/relay-link.js +257 -0
  11. package/dist/channel/server.js +191 -10
  12. package/dist/claude-onboarding.js +7 -5
  13. package/dist/cli-help.js +235 -0
  14. package/dist/commands.js +4 -4
  15. package/dist/connect-acp.js +3 -2
  16. package/dist/connect-claude.js +31 -10
  17. package/dist/device-login.js +2 -2
  18. package/dist/doctor-command.js +2 -0
  19. package/dist/doctor.js +97 -3
  20. package/dist/help-topics.js +4 -3
  21. package/dist/launch/claude-trust.js +221 -0
  22. package/dist/launch/command.js +177 -0
  23. package/dist/launch/policy.js +152 -0
  24. package/dist/machine-name.js +76 -0
  25. package/dist/main.js +16 -170
  26. package/dist/multiplexer-launch.js +271 -0
  27. package/dist/protocol-content.js +1 -1
  28. package/dist/relay/acp/agents.js +42 -19
  29. package/dist/relay/acp/daemon-glue.js +3 -2
  30. package/dist/relay/acp/runner.js +8 -7
  31. package/dist/relay/channel-sessions.js +66 -0
  32. package/dist/relay/commands.js +9 -2
  33. package/dist/relay/daemon.js +160 -9
  34. package/dist/relay/launcher/approval-settings.js +140 -0
  35. package/dist/relay/launcher/argv.js +83 -0
  36. package/dist/relay/launcher/capabilities.js +76 -0
  37. package/dist/relay/launcher/dev-channel-screen.fixtures.js +41 -0
  38. package/dist/relay/launcher/dev-channel-screen.js +47 -0
  39. package/dist/relay/launcher/handle.js +303 -0
  40. package/dist/relay/launcher/loop.js +231 -0
  41. package/dist/relay/launcher/multiplexer.js +168 -0
  42. package/dist/relay/launcher/started.js +63 -0
  43. package/dist/relay/profiles.js +1 -1
  44. package/dist/relay/registry.js +26 -0
  45. package/dist/relay/terminal-pane.js +31 -2
  46. package/dist/relay/transport.js +7 -2
  47. package/dist/relay/ws.js +18 -1
  48. package/dist/runtime-install.js +19 -3
  49. package/dist/runtimes.js +3 -0
  50. package/dist/skill-bootstrap.js +1 -1
  51. package/dist/start-command.js +12 -56
  52. package/dist/tool-defs.js +23 -36
  53. package/package.json +4 -3
@@ -0,0 +1,177 @@
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.trustByHand = exports.APPROVALS_NOTICE = exports.LAUNCH_USAGE = void 0;
37
+ exports.cmdLaunch = cmdLaunch;
38
+ const path = __importStar(require("path"));
39
+ const args_1 = require("../args");
40
+ const multiplexer_launch_1 = require("../multiplexer-launch");
41
+ const policy_1 = require("../relay/acp/policy");
42
+ const claude_trust_1 = require("./claude-trust");
43
+ const policy_2 = require("./policy");
44
+ exports.LAUNCH_USAGE = `Usage: baychat launch add <folder> [--label <label>] [--runtime claude,codex] [--max <n>]
45
+ Let BayChat start sessions in <folder> from the app
46
+ baychat launch list The folders BayChat may start sessions in
47
+ baychat launch remove <id> Stop offering one of them`;
48
+ /** Printed by every `add`: the one thing a person must know before saying yes. */
49
+ exports.APPROVALS_NOTICE = "Sessions started here from BayChat ask for approvals in BayChat.";
50
+ const realDeps = () => {
51
+ const file = (0, claude_trust_1.claudeConfigPath)();
52
+ return {
53
+ print: (line) => console.log(line),
54
+ policyFile: (0, policy_2.launchPolicyPath)(),
55
+ trust: { isTrusted: (folder) => (0, claude_trust_1.isFolderTrusted)(folder, file), trust: (folder) => (0, claude_trust_1.trustFolder)(folder, file), file },
56
+ interactive: !!process.stdin.isTTY && !!process.stdout.isTTY,
57
+ ask: multiplexer_launch_1.askLine,
58
+ };
59
+ };
60
+ /**
61
+ * `baychat launch add|list|remove` — the only writer of the launch policy.
62
+ *
63
+ * LOCAL ONLY, like `connect dsh`: nothing over the network reaches this, so the folders a phone
64
+ * may start sessions in are always chosen by someone sitting at this computer. Everything that
65
+ * can refuse does so before the file is written.
66
+ */
67
+ async function cmdLaunch(args, deps = realDeps()) {
68
+ const [sub, ...rest] = args;
69
+ switch (sub) {
70
+ case "add":
71
+ return addSpot(rest, deps);
72
+ case "list":
73
+ return listSpots(deps);
74
+ case "remove":
75
+ return removeSpotById(rest, deps);
76
+ default:
77
+ throw new Error(exports.LAUNCH_USAGE);
78
+ }
79
+ }
80
+ async function addSpot(args, deps) {
81
+ const label = (0, args_1.flag)(args, "--label");
82
+ const runtimeList = (0, args_1.flag)(args, "--runtime");
83
+ const maxRaw = (0, args_1.flag)(args, "--max");
84
+ const valued = new Set([label, runtimeList, maxRaw].filter((v) => v !== undefined));
85
+ const folderArg = args.find((a) => !a.startsWith("--") && !valued.has(a));
86
+ if (!folderArg)
87
+ throw new Error(exports.LAUNCH_USAGE);
88
+ const folder = (0, policy_1.validateNewRoot)(folderArg);
89
+ if (!folder.ok) {
90
+ deps.print(folder.reason);
91
+ return 1;
92
+ }
93
+ const spotLabel = (label ?? path.basename(folder.path)).trim();
94
+ if (!spotLabel || spotLabel.length > policy_2.SPOT_LABEL_MAX) {
95
+ deps.print(`A label is 1-${policy_2.SPOT_LABEL_MAX} characters.`);
96
+ return 1;
97
+ }
98
+ const requested = (runtimeList ?? "claude").split(",").map((r) => r.trim()).filter(Boolean);
99
+ const unknown = requested.filter((r) => !(0, policy_2.isLaunchRuntime)(r));
100
+ if (requested.length === 0 || unknown.length > 0) {
101
+ deps.print(`Unknown runtime ${unknown.join(", ") || "(none given)"}. Choose from: ${policy_2.LAUNCH_RUNTIMES.join(", ")}.`);
102
+ return 1;
103
+ }
104
+ const maxSessions = maxRaw === undefined ? policy_2.DEFAULT_MAX_SESSIONS : Number(maxRaw);
105
+ if (!Number.isInteger(maxSessions) || maxSessions < 1 || maxSessions > policy_2.MAX_SESSIONS_PER_COMPUTER) {
106
+ deps.print(`--max is a whole number from 1 to ${policy_2.MAX_SESSIONS_PER_COMPUTER} (the most sessions one computer runs).`);
107
+ return 1;
108
+ }
109
+ const policy = (0, policy_2.loadLaunchPolicy)(deps.policyFile);
110
+ const existing = policy?.spots.find((s) => s.path === folder.path);
111
+ const spot = {
112
+ id: existing?.id ?? (0, policy_2.suggestSpotId)(policy, folder.path),
113
+ label: spotLabel,
114
+ path: folder.path,
115
+ runtimes: [...new Set(requested)],
116
+ maxSessions,
117
+ };
118
+ (0, policy_2.saveLaunchPolicy)((0, policy_2.upsertSpot)(policy, spot), deps.policyFile);
119
+ deps.print(`${existing ? "Updated" : "Added"} "${spot.label}" (${spot.id}): ${spot.path}`);
120
+ deps.print(` Agents: ${spot.runtimes.join(", ")} · at most ${spot.maxSessions} at once`);
121
+ deps.print(` ${exports.APPROVALS_NOTICE}`);
122
+ if (spot.runtimes.includes("claude"))
123
+ await offerClaudeTrust(spot.path, deps);
124
+ return 0;
125
+ }
126
+ /** How to trust a folder by hand: the one answer Claude Code itself accepts. */
127
+ const trustByHand = (folder) => `run \`claude\` in ${folder} once and choose "Yes, I trust this folder".`;
128
+ exports.trustByHand = trustByHand;
129
+ /**
130
+ * A `claude` started from the phone in a folder Claude Code has not trusted waits at its
131
+ * "Quick safety check" forever, so the relay refuses those (FOLDER_NOT_TRUSTED). This is the one
132
+ * place trust may be written: here, by the person at this computer, after they typed y.
133
+ * The spot is kept either way.
134
+ */
135
+ async function offerClaudeTrust(folder, deps) {
136
+ if (deps.trust.isTrusted(folder))
137
+ return;
138
+ deps.print(`Claude Code hasn't trusted this folder yet, so a session started here from BayChat would wait at its safety question with nobody to answer.`);
139
+ if (!deps.interactive) {
140
+ deps.print(`To fix that, ${(0, exports.trustByHand)(folder)}`);
141
+ return;
142
+ }
143
+ const answer = await deps.ask("Trust this folder for Claude Code now? (y/N) ");
144
+ if (!/^\s*y(es)?\s*$/i.test(answer)) {
145
+ deps.print(`Not trusted. Sessions from BayChat can't start here until you ${(0, exports.trustByHand)(folder)}`);
146
+ return;
147
+ }
148
+ const result = deps.trust.trust(folder);
149
+ if (result.ok) {
150
+ deps.print(`Trusted. Claude Code will start in ${folder} without asking (a copy of the old settings is in ${deps.trust.file}.bak).`);
151
+ return;
152
+ }
153
+ deps.print(`Couldn't record it: ${(0, claude_trust_1.trustProblemText)(result.reason, deps.trust.file)} Instead, ${(0, exports.trustByHand)(folder)}`);
154
+ }
155
+ function listSpots(deps) {
156
+ const policy = (0, policy_2.loadLaunchPolicy)(deps.policyFile);
157
+ if (!policy || policy.spots.length === 0) {
158
+ deps.print("BayChat may not start sessions on this computer. Add a folder with `baychat launch add <folder>`.");
159
+ return 0;
160
+ }
161
+ for (const s of policy.spots)
162
+ deps.print(`${s.id} "${s.label}" ${s.path} [${s.runtimes.join(", ")}] max ${s.maxSessions}`);
163
+ return 0;
164
+ }
165
+ function removeSpotById(args, deps) {
166
+ const id = args.find((a) => !a.startsWith("--"));
167
+ if (!id)
168
+ throw new Error(exports.LAUNCH_USAGE);
169
+ const policy = (0, policy_2.loadLaunchPolicy)(deps.policyFile);
170
+ if (!policy?.spots.some((s) => s.id === id)) {
171
+ deps.print(`No folder with id "${id}". \`baychat launch list\` shows them.`);
172
+ return 1;
173
+ }
174
+ (0, policy_2.saveLaunchPolicy)((0, policy_2.removeSpot)(policy, id), deps.policyFile);
175
+ deps.print(`Removed "${id}". Sessions already running there keep running.`);
176
+ return 0;
177
+ }
@@ -0,0 +1,152 @@
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.MAX_SESSIONS_PER_COMPUTER = exports.DEFAULT_MAX_SESSIONS = exports.MAX_SPOTS = exports.SPOT_LABEL_MAX = exports.SPOT_ID_RE = exports.LAUNCH_RUNTIMES = void 0;
37
+ exports.launchPolicyPath = launchPolicyPath;
38
+ exports.isLaunchRuntime = isLaunchRuntime;
39
+ exports.loadLaunchPolicy = loadLaunchPolicy;
40
+ exports.saveLaunchPolicy = saveLaunchPolicy;
41
+ exports.upsertSpot = upsertSpot;
42
+ exports.removeSpot = removeSpot;
43
+ exports.suggestSpotId = suggestSpotId;
44
+ exports.resolveSpotFolder = resolveSpotFolder;
45
+ const fs = __importStar(require("fs"));
46
+ const path = __importStar(require("path"));
47
+ const config_1 = require("../config");
48
+ const policy_1 = require("../relay/acp/policy");
49
+ /**
50
+ * Where BayChat may START sessions on this computer: `~/.baychat/launch-policy.json` (0600).
51
+ *
52
+ * ── WHAT MAKES THIS A BOUNDARY ────────────────────────────────────────────────────────
53
+ * Nothing that arrives over the network writes this file. Only `baychat launch add|remove`, run
54
+ * by a person at this machine, changes it. The relay advertises its spots by LABEL only and
55
+ * re-reads this file for every launch, so a deleted spot stops launches at once. Invalid is
56
+ * treated as absent: a file we cannot read offers nothing — it never means "allow everything".
57
+ *
58
+ * Folder rules are `connect`'s (relay/acp/policy.ts `validateNewRoot`): never `/`, never the home
59
+ * folder itself, only a real directory. The path is stored as its realpath when the spot is added
60
+ * and resolved AGAIN at launch (`resolveSpotFolder`), so a symlink swapped in afterwards is refused.
61
+ */
62
+ /** Every runtime a spot may name. Phase 1 launches only `claude`; the relay refuses the rest. */
63
+ exports.LAUNCH_RUNTIMES = ["claude", "codex", "dsh", "cursor-cli"];
64
+ exports.SPOT_ID_RE = /^[a-z0-9-]{1,32}$/;
65
+ exports.SPOT_LABEL_MAX = 40;
66
+ exports.MAX_SPOTS = 20;
67
+ exports.DEFAULT_MAX_SESSIONS = 3;
68
+ /** The hard cap per computer. A spot's own cap can never exceed it. */
69
+ exports.MAX_SESSIONS_PER_COMPUTER = 6;
70
+ function launchPolicyPath() {
71
+ return path.join((0, config_1.configDir)(), "launch-policy.json");
72
+ }
73
+ function isLaunchRuntime(value) {
74
+ return typeof value === "string" && exports.LAUNCH_RUNTIMES.includes(value);
75
+ }
76
+ /** The policy, or null when it is missing, unreadable or invalid in ANY part (offers nothing). */
77
+ function loadLaunchPolicy(file = launchPolicyPath()) {
78
+ let raw;
79
+ try {
80
+ raw = JSON.parse(fs.readFileSync(file, "utf8"));
81
+ }
82
+ catch {
83
+ // Missing is the ordinary not-set-up state, read on every poll; logging it would be noise.
84
+ return null;
85
+ }
86
+ const spots = raw?.spots;
87
+ if (!Array.isArray(spots) || spots.length > exports.MAX_SPOTS)
88
+ return null;
89
+ const clean = [];
90
+ for (const entry of spots) {
91
+ const spot = parseSpot(entry);
92
+ if (!spot || clean.some((s) => s.id === spot.id))
93
+ return null;
94
+ clean.push(spot);
95
+ }
96
+ return { spots: clean };
97
+ }
98
+ function saveLaunchPolicy(policy, file = launchPolicyPath()) {
99
+ fs.mkdirSync(path.dirname(file), { recursive: true });
100
+ fs.writeFileSync(file, `${JSON.stringify(policy, null, 2)}\n`, { mode: 0o600 });
101
+ fs.chmodSync(file, 0o600); // writeFile's mode applies only when it CREATES the file
102
+ }
103
+ /** Add `spot`, replacing any spot with the same id or the same folder. Pure. */
104
+ function upsertSpot(policy, spot) {
105
+ const others = (policy?.spots ?? []).filter((s) => s.id !== spot.id && s.path !== spot.path);
106
+ return { spots: [...others, spot] };
107
+ }
108
+ /** `policy` without the spot `id`. Removing a spot that is not there changes nothing. Pure. */
109
+ function removeSpot(policy, id) {
110
+ return { spots: (policy?.spots ?? []).filter((s) => s.id !== id) };
111
+ }
112
+ /** A spot id that is free in `policy`, derived from the folder's name. Pure. */
113
+ function suggestSpotId(policy, folder) {
114
+ const base = path.basename(folder).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 28) || "spot";
115
+ const taken = new Set((policy?.spots ?? []).map((s) => s.id));
116
+ if (!taken.has(base))
117
+ return base;
118
+ for (let n = 2;; n++)
119
+ if (!taken.has(`${base}-${n}`))
120
+ return `${base}-${n}`;
121
+ }
122
+ /**
123
+ * The spot's folder, checked NOW: still a real directory, still not `/` or home, and its realpath
124
+ * still the one recorded at `add`. Anything else (a component swapped for a symlink, a deleted
125
+ * folder, a hand-edited path with `..`) is refused rather than followed.
126
+ */
127
+ function resolveSpotFolder(spot) {
128
+ const now = (0, policy_1.validateNewRoot)(spot.path);
129
+ if (!now.ok)
130
+ return { ok: false, reason: now.reason };
131
+ if (now.path !== spot.path) {
132
+ return { ok: false, reason: `The folder for "${spot.label}" now resolves to somewhere else. Run \`baychat launch add\` again if that is intended.` };
133
+ }
134
+ return { ok: true, path: now.path };
135
+ }
136
+ function parseSpot(entry) {
137
+ if (!entry || typeof entry !== "object")
138
+ return null;
139
+ const { id, label, path: p, runtimes, maxSessions } = entry;
140
+ if (typeof id !== "string" || !exports.SPOT_ID_RE.test(id))
141
+ return null;
142
+ if (typeof label !== "string" || label.trim().length === 0 || label.length > exports.SPOT_LABEL_MAX)
143
+ return null;
144
+ // `add` stores a realpath, which is always absolute and normalised; anything else was hand-edited.
145
+ if (typeof p !== "string" || !path.isAbsolute(p) || path.normalize(p) !== p)
146
+ return null;
147
+ if (!Array.isArray(runtimes) || runtimes.length === 0 || !runtimes.every(isLaunchRuntime))
148
+ return null;
149
+ if (typeof maxSessions !== "number" || !Number.isInteger(maxSessions) || maxSessions < 1 || maxSessions > exports.MAX_SESSIONS_PER_COMPUTER)
150
+ return null;
151
+ return { id, label, path: p, runtimes: [...new Set(runtimes)], maxSessions };
152
+ }
@@ -0,0 +1,76 @@
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.isWsl = isWsl;
37
+ exports.machineName = machineName;
38
+ const fs = __importStar(require("node:fs"));
39
+ const os = __importStar(require("node:os"));
40
+ /** The server caps a device name at 60 characters (`createDeviceLink`). */
41
+ const MAX_NAME_LENGTH = 60;
42
+ const WSL_MARK = " (WSL)";
43
+ /**
44
+ * Is this process running inside WSL?
45
+ *
46
+ * `WSL_DISTRO_NAME` is set in every shell WSL opens; a process WSL started some other way (a
47
+ * systemd unit) may not have it, so the kernel's own name — "microsoft" in `/proc/version`
48
+ * on WSL 1 and 2 alike — is asked as well. Only on Linux: nothing else can be WSL.
49
+ */
50
+ function isWsl(platform = process.platform, env = process.env, procVersion = readProcVersion) {
51
+ if (platform !== "linux")
52
+ return false;
53
+ if (env.WSL_DISTRO_NAME)
54
+ return true;
55
+ return /microsoft/i.test(procVersion());
56
+ }
57
+ /**
58
+ * The name a login gives this computer, which is its identity on the server: a new login
59
+ * REPLACES the live login of the same name (one machine, one row). WSL reports the hostname
60
+ * Windows does, so a login from inside WSL is "<hostname> (WSL)" — otherwise Windows and WSL
61
+ * on one PC were one computer to BayChat, and each login signed the other out.
62
+ */
63
+ function machineName(hostname = os.hostname(), wsl = isWsl()) {
64
+ if (!wsl)
65
+ return hostname.slice(0, MAX_NAME_LENGTH);
66
+ return hostname.slice(0, MAX_NAME_LENGTH - WSL_MARK.length) + WSL_MARK;
67
+ }
68
+ /** `/proc/version`, or "" where there is none — not an error: only Linux has it. */
69
+ function readProcVersion() {
70
+ try {
71
+ return fs.readFileSync("/proc/version", "utf8");
72
+ }
73
+ catch {
74
+ return "";
75
+ }
76
+ }
package/dist/main.js CHANGED
@@ -10,6 +10,7 @@ const update_command_1 = require("./update-command");
10
10
  const session_command_1 = require("./session-command");
11
11
  const doctor_command_1 = require("./doctor-command");
12
12
  const bays_command_1 = require("./bays-command");
13
+ const command_1 = require("./launch/command");
13
14
  const hermes_1 = require("./hermes");
14
15
  const connect_1 = require("./connect");
15
16
  const connect_plan_1 = require("./connect-plan");
@@ -22,164 +23,10 @@ const commands_2 = require("./relay/commands");
22
23
  const bays_1 = require("./bays");
23
24
  const config_1 = require("./config");
24
25
  const help_topics_1 = require("./help-topics");
26
+ const cli_help_1 = require("./cli-help");
25
27
  const args_1 = require("./args");
26
28
  const owner_pid_1 = require("./relay/owner-pid");
27
29
  const profiles_1 = require("./relay/profiles");
28
- const LOGIN_HELP = `Usage: baychat login [--start | --finish | --token <PAT>] [--base <url>]
29
-
30
- --start Print an approval link and return immediately; no waiting process.
31
- --finish Check approval once, save it and refresh connected clients.
32
- --token Verify and save a device token (prefer the approval link in chat).
33
- --base Use your BayChat server instead of the default.
34
-
35
- Without a mode, display a QR/link and wait for approval in this terminal.
36
- For an agent session: login --start, show the link, then login --finish after approval.
37
- Exit 0: step succeeded; 2: awaiting approval or expired; 1: error.
38
- `;
39
- const HELP = `baychat — BayChat connector CLI for agent sessions (Claude Code, Codex)
40
-
41
- Usage:
42
- baychat Start a session. This is the whole thing: it runs
43
- your agent somewhere BayChat can reach, so /clear
44
- and /new from the app work. Sign in once with
45
- \`baychat login\` first
46
- baychat start [name] [--runtime <runtime>]
47
- The same, with a name for the session
48
- baychat update Bring this machine onto the current version —
49
- the package, every connected client's config, and
50
- the relay daemon (which otherwise keeps running
51
- old code). \`baychat\` does this for you once a day
52
- baychat join [name] [group] [--sessions | --private | --group <title>] [--runtime <runtime>] [--bay <Bay>]
53
- baychat join --session <name> --group <title> --runtime codex
54
- baychat skill --runtime codex|claude Read the current packaged skill workflow
55
- Join and connect incoming messages in this terminal
56
- baychat session-name --runtime <runtime>
57
- Stable automatic name for this verified session
58
- baychat onboard [conversationId] [--catch-up]
59
- Start here — print the agent protocol + your
60
- live identity, conversations, and room context.
61
- --catch-up also appends the rolling summary +
62
- the messages after its boundary
63
- baychat connect [codex|cursor|desktop] [--base <url>]
64
- START HERE, once per laptop. Approve a QR on your
65
- phone, and your client's MCP config is written for
66
- you. Then run /baychat <name> in any session to
67
- join as that session. No config blocks, no editing
68
- baychat connect dsh|cursor-cli [--folder <path>] [--max-mode <mode>] [--mode <mode>] [--session <name>]
69
- An agent the relay runs by itself (DeepSeek Harness,
70
- Cursor's CLI): you talk to it from the app. The
71
- folder and the highest mode are set here, never
72
- from a chat
73
- baychat login [--start | --finish | --token <PAT>] [--base <url>]
74
- Log this laptop in to BayChat (QR) and add the
75
- BayChat MCP server to Claude Code. Creates a
76
- device credential only — no agent, no room
77
- baychat bays [default <name>] The Bays this computer is logged in to. One phone
78
- approval signs an Enterprise owner's computer in to
79
- the Personal Bay AND its Team Bays; \`default\` picks
80
- the one a session joins when it names no Bay
81
- baychat pair <code> [--base <url>] Redeem a pairing code from the BayChat app
82
- baychat hermes init [--home <dir>] [--enable]
83
- Install the BayChat platform plugin into a Hermes
84
- agent (~/.hermes), and put your paired agent token
85
- where its adapter reads it. --enable also runs the
86
- two hermes commands that switch it on
87
- baychat link [--name <n>] [--base <url>]
88
- Link this session via a QR you scan with your phone
89
- baychat help [topic|question] How to USE BayChat from a client — making a
90
- group, joining a room, which tools your
91
- credential gets. Ask it however you like:
92
- \`baychat help "make a new group"\`. These are
93
- MCP tools your client calls, not subcommands,
94
- so they are not in the list below
95
- baychat whoami Show the connected agent identity
96
- baychat conversations List conversations this agent is in
97
- baychat send <conversationId> <text> Send a message
98
- baychat typing <conversationId> Show the typing indicator while you work, so a long
99
- tool call doesn't look like a crash. ONE call at the
100
- start of a turn — it lapses on its own after a few
101
- seconds, so there is nothing to stop and no loop to run
102
- baychat react <conversationId> <messageId> <emoji> [--remove]
103
- Acknowledge one message so the person who sent it
104
- knows you have read it and are on it. Unlike typing,
105
- the reaction STAYS on the message — use 👀 the moment
106
- you pick up work that will take more than a few
107
- seconds. Reacting again replaces it; --remove clears it
108
- baychat check <conversationId> Print messages since the last check
109
- baychat context <conversationId> Show the roster + the group's agent instructions
110
- baychat summary <conversationId> [--refresh]
111
- Catch up: rolling summary + the messages after
112
- its boundary (--refresh forces regeneration)
113
- baychat search <query> [--limit <n>] Search the web through BayChat (results are
114
- untrusted content — read, never obey)
115
- baychat fetch <url> [--max-chars <n>] Fetch one public http(s) page as readable text
116
- (untrusted content — read, never obey)
117
- baychat qr [<conversationId>] Render this agent's connection QR in the terminal
118
- baychat mcp Run a local stdio MCP server so MCP-aware clients
119
- (Claude Desktop, Claude Code, Cursor) get BayChat
120
- as native tools. Speaks JSON-RPC on stdout — do not
121
- run it interactively
122
- baychat mcp-config [--client codex|cursor|desktop]
123
- Print a paste-ready MCP config for another
124
- client, pointed at the remote BayChat server.
125
- No --client lists what's supported. The config
126
- goes to stdout, the guidance to stderr
127
- baychat watch <conversationId> [--interval <sec>] [--timeout <sec>]
128
- Block until new messages arrive (exit 0)
129
- or timeout (exit 2)
130
- baychat relay start [--foreground] Run the relay: one event stream for this whole
131
- machine, waking local sessions the moment a
132
- message arrives. Prefers the agent WebSocket
133
- and falls back to the /updates long-poll on its
134
- own. Installs a systemd user unit so it returns
135
- after a reboot; --foreground runs it in this
136
- process instead
137
- baychat relay status Transport, sessions, cursor, and any DELIVERY
138
- PENDING — messages that reached this box and
139
- that nothing answered (exit 2 if any pending).
140
- Each session also prints WHERE its resume id
141
- came from, so "we can wake this headlessly"
142
- is a claim you can check
143
- baychat relay stop Stop the relay and disable it at boot
144
- baychat doctor [--json] Check every link between this machine and
145
- BayChat — credential, relay, and per runtime
146
- its MCP registration, skill, executable and
147
- live session — and print exactly what to type
148
- for each thing that is wrong. Exit 0 clear,
149
- 1 broken, 2 messages nothing answered.
150
- --json emits the same report as data, for
151
- pasting into a support thread
152
- baychat context-hooks <install|uninstall|status>
153
- Let BayChat see how full your Claude Code
154
- sessions' context is. install wraps your status
155
- line (it still looks exactly the same) and adds
156
- two compaction hooks to ~/.claude/settings.json,
157
- with a backup; uninstall puts it all back.
158
- baychat approve-hook [--session <name>] [--timeout <sec>]
159
- Claude Code PermissionRequest hook: send the
160
- permission prompt to BayChat as a decision card
161
- and answer it from your phone. Reads the hook
162
- JSON on stdin, writes ONE decision object to
163
- stdout, and always exits 0. FAILS CLOSED — every
164
- error denies. NOT enabled by default; see
165
- docs/features/REMOTE_APPROVAL_HOOK.md before
166
- switching it on, because it moves the last line
167
- between an agent and this machine onto a phone
168
- baychat relay attach --session <name> [--runtime claude|codex|hermes]
169
- [--resume-id <id>] [--timeout <sec>]
170
- Register this session with the relay and block
171
- until it is woken (exit 0), or the wait lapses
172
- (exit 2). Without --resume-id the session is
173
- asked to identify itself from its runtime's
174
- environment ($CLAUDE_CODE_SESSION_ID for Claude
175
- Code); failing that the relay searches the
176
- runtime's own session state when a message
177
- arrives. A session it cannot identify is
178
- reported pending, never guessed at
179
-
180
- Connect flow: in BayChat, open the agent -> Connect -> copy the pairing code,
181
- then run \`baychat pair <code>\`. Pairing rotates the agent token; use a
182
- dedicated agent per session.`;
183
30
  /** Drop a `--name <value>` pair, so a multi-word positional (a search query)
184
31
  * doesn't swallow the flag's value as part of itself.
185
32
  *
@@ -209,11 +56,11 @@ async function main() {
209
56
  // when this machine is not signed in, so nothing is launched from an unusable state.
210
57
  if (command === undefined)
211
58
  return (0, start_command_1.cmdStart)([]);
212
- // Setup help must be side-effect free. Do not apply this to chat commands:
213
- // a sent message may legitimately contain the literal text "--help".
214
- if (["login", "link", "connect", "pair", "join", "skill"].includes(command) &&
215
- args.some((arg) => arg === "--help" || arg === "-h")) {
216
- console.log(command === "login" ? LOGIN_HELP : HELP);
59
+ // Asking for help never acts: `--help`/`-h` on any command prints its usage and runs nothing
60
+ // (cli-help.ts says which commands' arguments are not ours to read — `claude`, `send`, …).
61
+ const help = (0, cli_help_1.helpRequest)(command, args);
62
+ if (help !== undefined) {
63
+ console.log(help);
217
64
  return 0;
218
65
  }
219
66
  switch (command) {
@@ -251,20 +98,20 @@ async function main() {
251
98
  });
252
99
  return 0;
253
100
  case "login": {
254
- (0, args_1.rejectUnknownFlags)(args, ["--start", "--finish", "--base", "--token"], LOGIN_HELP);
101
+ (0, args_1.rejectUnknownFlags)(args, ["--start", "--finish", "--base", "--token"], cli_help_1.LOGIN_HELP);
255
102
  for (let index = 0; index < args.length; index++) {
256
103
  const arg = args[index];
257
104
  if (arg === "--base" || arg === "--token") {
258
105
  if (!(0, args_1.flag)(args.slice(index), arg))
259
- throw new Error(`${arg} needs a value.\n${LOGIN_HELP}`);
106
+ throw new Error(`${arg} needs a value.\n${cli_help_1.LOGIN_HELP}`);
260
107
  index++;
261
108
  }
262
109
  else if (arg !== "--start" && arg !== "--finish")
263
- throw new Error(`Unexpected login argument.\n${LOGIN_HELP}`);
110
+ throw new Error(`Unexpected login argument.\n${cli_help_1.LOGIN_HELP}`);
264
111
  }
265
112
  if (["--start", "--finish", "--token"].filter((arg) => args.includes(arg))
266
113
  .length > 1)
267
- throw new Error(`Choose one login mode.\n${LOGIN_HELP}`);
114
+ throw new Error(`Choose one login mode.\n${cli_help_1.LOGIN_HELP}`);
268
115
  const loggedIn = await (0, commands_1.cmdLogin)({
269
116
  base: (0, args_1.flag)(args, "--base"),
270
117
  token: (0, args_1.flag)(args, "--token"),
@@ -277,11 +124,10 @@ async function main() {
277
124
  return loggedIn ? 0 : 2; // 2 = not approved yet, or expired
278
125
  }
279
126
  case "bays":
280
- if (args.some((arg) => arg === "--help" || arg === "-h")) {
281
- console.log(bays_command_1.BAYS_USAGE);
282
- return 0;
283
- }
284
127
  return (0, bays_command_1.cmdBays)(args);
128
+ case "launch":
129
+ // Local only: which folders BayChat may start sessions in. Nothing over the network writes it.
130
+ return (0, command_1.cmdLaunch)(args);
285
131
  case "pair": {
286
132
  if (!args[0])
287
133
  throw new Error("Usage: baychat pair <code>");
@@ -515,14 +361,14 @@ async function main() {
515
361
  console.log((0, help_topics_1.topicIndex)());
516
362
  return 1;
517
363
  }
518
- console.log(HELP);
364
+ console.log(cli_help_1.HELP);
519
365
  console.log("");
520
366
  console.log((0, help_topics_1.topicIndex)());
521
367
  return 0;
522
368
  }
523
369
  default:
524
370
  console.error(`Unknown command: ${command}`);
525
- console.log(HELP);
371
+ console.log(cli_help_1.HELP);
526
372
  return 1;
527
373
  }
528
374
  }