baychat 0.55.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.
Files changed (42) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +7 -0
  3. package/dist/approval-wait.js +1 -1
  4. package/dist/bay-gone.js +35 -0
  5. package/dist/bay-mcp.js +22 -8
  6. package/dist/channel/launch.js +10 -3
  7. package/dist/channel/mcp-server.js +37 -0
  8. package/dist/channel/server.js +6 -20
  9. package/dist/claude-command.js +130 -0
  10. package/dist/claude-register.js +162 -0
  11. package/dist/claude-user-config.js +215 -0
  12. package/dist/codex-onboarding.js +16 -2
  13. package/dist/commands.js +22 -187
  14. package/dist/connect-claude.js +26 -5
  15. package/dist/connect-link-budget.js +2 -0
  16. package/dist/connect-link-check.js +96 -0
  17. package/dist/connect-link-setup.js +17 -0
  18. package/dist/connect-link.js +41 -34
  19. package/dist/doctor-claude-file.js +17 -0
  20. package/dist/doctor-command.js +3 -0
  21. package/dist/doctor-questions.js +22 -0
  22. package/dist/doctor.js +13 -12
  23. package/dist/notify-answer.js +53 -31
  24. package/dist/protocol-content.js +1 -1
  25. package/dist/quiet-claude-env.js +15 -0
  26. package/dist/refresh-clients.js +4 -6
  27. package/dist/relay/launcher/blocking-screen.fixtures.js +147 -0
  28. package/dist/relay/launcher/blocking-screen.js +68 -0
  29. package/dist/relay/launcher/dev-channel-screen.js +1 -1
  30. package/dist/relay/launcher/handle.js +3 -2
  31. package/dist/relay/launcher/loop.js +3 -0
  32. package/dist/relay/launcher/multiplexer.js +26 -0
  33. package/dist/relay/launcher/pane-watch.js +16 -0
  34. package/dist/relay/launcher/reset-time.js +82 -0
  35. package/dist/relay/launcher/session-watch-deps.js +116 -0
  36. package/dist/relay/launcher/session-watch.js +252 -0
  37. package/dist/runtimes.js +1 -3
  38. package/dist/tool-defs-boards.js +8 -0
  39. package/dist/tool-defs.js +6 -6
  40. package/dist/tool-hints.js +11 -5
  41. package/dist/waiting-cards.js +33 -3
  42. package/package.json +2 -2
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ // The doctor, run by `baychat connect <link>` itself after the join (26 Nov 2026).
3
+ //
4
+ // WHY. On Primea's PC the paste signed the computer in and then stopped; Karmen ran `doctor`
5
+ // herself and fixed it by hand. A person who pasted one command should never be sent to a second.
6
+ // So the same checks `baychat doctor` reports are read here, what can be fixed is fixed, and only
7
+ // what is still wrong is handed back, one plain line each, for the paste's last line.
8
+ //
9
+ // What it fixes: the relay when it is not running, and the link's own app when its BayChat entry
10
+ // or skill is missing (that app's `connect <app>` once more). Nothing else is touched: other
11
+ // apps, sessions and the channel are reported by `doctor`, not repaired behind the person's back.
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.realCheckDeps = void 0;
17
+ exports.problemsIn = problemsIn;
18
+ exports.checkAndFix = checkAndFix;
19
+ const doctor_1 = require("./doctor");
20
+ const doctor_command_1 = require("./doctor-command");
21
+ const commands_1 = require("./relay/commands");
22
+ const connect_link_setup_1 = require("./connect-link-setup");
23
+ const connect_link_setup_2 = require("./connect-link-setup");
24
+ const node_child_process_1 = require("node:child_process");
25
+ const node_os_1 = __importDefault(require("node:os"));
26
+ const node_util_1 = require("node:util");
27
+ const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
28
+ const failed = (c) => c?.status === "fail";
29
+ /** A doctor remedy ("baychat relay start") as the command to paste. */
30
+ const runnable = (remedy, fallback) => `npx -y baychat@latest ${(remedy ?? fallback).replace(/^baychat /, "")}`;
31
+ function ownChecks(report, app) {
32
+ const block = report.runtimes.find((r) => r.runtime === app);
33
+ return (block?.checks ?? []).filter((c) => c.name === "mcp" || c.name === "skill" || c.name === "setup");
34
+ }
35
+ /** What is still wrong for this paste, in plain words, each with the one command that fixes it. */
36
+ function problemsIn(report, app, relayNote) {
37
+ const out = [];
38
+ if (failed(report.credentials))
39
+ out.push(`this computer's BayChat login: ${report.credentials.detail}. Run: ${runnable(report.credentials.remedy, "login")}`);
40
+ if (failed(report.relay)) {
41
+ out.push(relayNote && !/startup requested/i.test(relayNote)
42
+ ? relayNote.replace(/^Relay: /, "the BayChat helper: ")
43
+ : `the BayChat helper (relay) is not running. Run: ${runnable(report.relay.remedy, "relay start")}`);
44
+ }
45
+ for (const c of ownChecks(report, app)) {
46
+ if (c.status === "fail" || (c.name === "setup" && c.status === "skip")) {
47
+ out.push(`${connect_link_setup_2.APP_LABELS[app]}: ${c.detail}. Run: npx -y baychat@latest connect ${app}`);
48
+ }
49
+ }
50
+ return out;
51
+ }
52
+ async function checkAndFix(app, signal, deps) {
53
+ let report = await deps.report();
54
+ let relayNote = null;
55
+ if (failed(report.relay))
56
+ relayNote = await deps.startRelay();
57
+ const ownBroken = ownChecks(report, app).some((c) => c.status === "fail" || (c.name === "setup" && c.status === "skip"));
58
+ if (ownBroken)
59
+ await deps.setUpAgain(app, signal);
60
+ if (relayNote !== null || ownBroken) {
61
+ report = await deps.report();
62
+ // A relay asked to start takes a moment to answer: look again for a few seconds.
63
+ for (let i = 0; i < 5 && failed(report.relay) && relayNote && /startup requested|running/i.test(relayNote) && !signal.aborted; i++) {
64
+ await deps.pause(1_000, signal);
65
+ report = await deps.report();
66
+ }
67
+ }
68
+ const left = problemsIn(report, app, relayNote);
69
+ const user = failed(report.relay) ? null : await deps.lingerOff();
70
+ // `enable-linger` for oneself needs an admin over SSH (polkit): the one thing the paste cannot do.
71
+ if (user)
72
+ left.push(`the BayChat helper stops when you log out of this server. Run once: sudo loginctl enable-linger ${user}`);
73
+ return left;
74
+ }
75
+ const realCheckDeps = (base) => ({
76
+ report: async () => (0, doctor_1.buildReport)(await (0, doctor_command_1.currentDoctorEnv)()),
77
+ startRelay: commands_1.ensureRelayInstalled,
78
+ setUpAgain: async (app, signal) => (await (0, connect_link_setup_1.setUpAppInChild)(app, base, signal)).code === 0,
79
+ lingerOff: async () => {
80
+ if (process.platform !== "linux")
81
+ return null;
82
+ const user = node_os_1.default.userInfo().username;
83
+ try {
84
+ const { stdout } = await execFileAsync("loginctl", ["show-user", user, "--property=Linger", "--value"], { timeout: 5_000 });
85
+ return stdout.trim() === "no" ? user : null;
86
+ }
87
+ catch {
88
+ return null; // No loginctl (no systemd): the relay is not a user unit here, nothing to say.
89
+ }
90
+ },
91
+ pause: (ms, signal) => new Promise((resolve) => {
92
+ const t = setTimeout(resolve, ms);
93
+ signal.addEventListener("abort", () => (clearTimeout(t), resolve()), { once: true });
94
+ }),
95
+ });
96
+ exports.realCheckDeps = realCheckDeps;
@@ -24,6 +24,8 @@ exports.appEndLine = appEndLine;
24
24
  exports.appsOnThisComputer = appsOnThisComputer;
25
25
  exports.configFilesOf = configFilesOf;
26
26
  exports.setUpAppInChild = setUpAppInChild;
27
+ exports.joinLine = joinLine;
28
+ exports.readyLine = readyLine;
27
29
  const node_child_process_1 = require("node:child_process");
28
30
  const node_fs_1 = __importDefault(require("node:fs"));
29
31
  const node_os_1 = __importDefault(require("node:os"));
@@ -137,3 +139,18 @@ async function setUpAppInChild(app, base, signal) {
137
139
  ...(code === 0 ? {} : { tail }),
138
140
  };
139
141
  }
142
+ /**
143
+ * What the person says to the agent after its restart (vps, 19 Nov 2026: on a fresh Mac Claude Code came back and did
144
+ * nothing until told). The same words the app's card copies (`joinBayChatLine` in both apps' lib/connect-link.ts).
145
+ */
146
+ function joinLine(name) {
147
+ return `join BayChat as ${name}`;
148
+ }
149
+ /** The last line of a paste that worked: ready, and the one thing the person does next. */
150
+ function readyLine(runtime, name) {
151
+ const app = exports.APP_LABELS[runtime];
152
+ // Claude Code reads its MCP servers when it starts: a Claude app left open would not have BayChat yet.
153
+ const slashName = /\s/.test(name) ? `"${name}"` : name; // /baychat <name> ["<group>"]: a name with a space is quoted
154
+ const next = runtime === "claude" ? `type /baychat ${slashName}` : `tell it: ${joinLine(name)}`;
155
+ return `Ready. Quit ${app} fully and open it again, then ${next} (or start a session from the BayChat app).`;
156
+ }
@@ -12,12 +12,11 @@
12
12
  // first four characters only (`maskConnectToken`). The token lives in the link's #fragment, which
13
13
  // no server sees; it travels once, in a POST body, to the redeem endpoint.
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.realConnectLinkDeps = exports.CONNECT_LINK_CLIENTS = void 0;
15
+ exports.realConnectLinkDeps = exports.CONNECT_LINK_CLIENTS = exports.readyLine = exports.joinLine = void 0;
16
16
  exports.looksLikeConnectLink = looksLikeConnectLink;
17
17
  exports.maskConnectToken = maskConnectToken;
18
18
  exports.parseConnectLink = parseConnectLink;
19
19
  exports.describeRedeemError = describeRedeemError;
20
- exports.joinLine = joinLine;
21
20
  exports.helloLine = helloLine;
22
21
  exports.cmdConnectLink = cmdConnectLink;
23
22
  exports.joinAndGreetOverMcp = joinAndGreetOverMcp;
@@ -29,6 +28,10 @@ const connect_link_budget_1 = require("./connect-link-budget");
29
28
  const connect_link_setup_1 = require("./connect-link-setup");
30
29
  const device_login_1 = require("./device-login");
31
30
  const machine_name_1 = require("./machine-name");
31
+ const connect_link_check_1 = require("./connect-link-check");
32
+ const connect_link_setup_2 = require("./connect-link-setup");
33
+ Object.defineProperty(exports, "joinLine", { enumerable: true, get: function () { return connect_link_setup_2.joinLine; } });
34
+ Object.defineProperty(exports, "readyLine", { enumerable: true, get: function () { return connect_link_setup_2.readyLine; } });
32
35
  /**
33
36
  * The runtimes a link can connect, by the name in its path (`/connect/<client>`), and the `connect <app>`
34
37
  * setup each one runs. Cursor since 19 Nov 2026: `connect cursor`, Cursor's own MCP file.
@@ -111,16 +114,9 @@ function describeRedeemError(error) {
111
114
  }
112
115
  return error instanceof Error ? error.message : String(error);
113
116
  }
114
- /**
115
- * What the person says to the agent after its restart (vps, 19 Nov 2026: on a fresh Mac Claude Code came back and did
116
- * nothing until told). The same words the app's card copies (`joinBayChatLine` in both apps' lib/connect-link.ts).
117
- */
118
- function joinLine(name) {
119
- return `join BayChat as ${name}`;
120
- }
121
117
  function helloLine(name, runtime, computer) {
122
118
  const app = connect_link_setup_1.APP_LABELS[runtime];
123
- return `Connected ✅ I'm ${name}, ${app} on ${computer}. Restart ${app}, then tell it: ${joinLine(name)} (or start a session from the BayChat app), and I'll answer here.`;
119
+ return `Connected ✅ I'm ${name}, ${app} on ${computer}. Restart ${app}, then tell it: ${(0, connect_link_setup_2.joinLine)(name)} (or start a session from the BayChat app), and I'll answer here.`;
124
120
  }
125
121
  /** Set every app up, the link's own first, inside the budget. Each one's outcome, in that order. */
126
122
  async function setUpApps(apps, own, base, deps, budget) {
@@ -147,9 +143,8 @@ async function setUpApps(apps, own, base, deps, budget) {
147
143
  deps.log(` (${connect_link_setup_1.APP_LABELS[app]}: ${e instanceof Error ? e.message : String(e)})`);
148
144
  outcomes.push({ app, kind: e instanceof connect_link_budget_1.OutOfTime ? "slow" : "failed" });
149
145
  }
150
- // The agent the link is for comes first; if it did not take, the others wait for `doctor`.
151
- if (app === own && outcomes[outcomes.length - 1].kind !== "done")
152
- break;
146
+ // The agent the link is for comes first. If it did not take, the others still go on: each is its
147
+ // own app, and the check after the join tries the link's own once more (Primea's PC, 26 Nov 2026).
153
148
  }
154
149
  return outcomes;
155
150
  }
@@ -202,38 +197,49 @@ async function cmdConnectLink(raw, deps, opts = {}) {
202
197
  const outcomes = await setUpApps([runtime, ...others], runtime, base, deps, budget);
203
198
  for (const outcome of outcomes)
204
199
  deps.log((0, connect_link_setup_1.appEndLine)(outcome));
200
+ // The join needs only the login, never the app: an app that did not take no longer keeps the agent
201
+ // out of the Bay (Primea's PC, 26 Nov 2026: signed in, no agent, and the doctor run by hand).
205
202
  const own = outcomes[0];
206
- if (own.kind !== "done") {
207
- deps.log(own.kind === "failed"
208
- ? "The login is saved, but the setup did not finish. Run: npx -y baychat@latest doctor"
209
- : `The computer is signed in to BayChat, but setting up ${app} took too long. Run: npx -y baychat@latest doctor`);
210
- return 2;
211
- }
203
+ const ownLine = own.kind === "done" ? null
204
+ : own.kind === "failed" ? `${app} is not set up yet. Run: npx -y baychat@latest connect ${runtime}`
205
+ : `setting up ${app} took too long. Run: npx -y baychat@latest connect ${runtime}`;
212
206
  // The group comes only from the server's record of the link, never from anything typed here.
213
207
  const g = redeemed.group ?? null;
214
208
  const target = g ? ("id" in g ? { id: g.id } : { newTitle: g.newTitle }) : undefined;
215
209
  const where = g ? ("id" in g ? (g.title ?? "the group") : g.newTitle) : null;
216
- let landed;
210
+ let joined = false;
217
211
  try {
218
- landed = await budget.run(connect_link_budget_1.CONNECT_LINK_CAPS.join, (signal) => deps.joinAndGreet(base, device.token, redeemed.agentName, helloLine(redeemed.agentName, runtime, computer), target, signal));
212
+ const landed = await budget.run(connect_link_budget_1.CONNECT_LINK_CAPS.join, (signal) => deps.joinAndGreet(base, device.token, redeemed.agentName, helloLine(redeemed.agentName, runtime, computer), target, signal));
213
+ joined = true;
214
+ if (where && !landed.inGroup) {
215
+ deps.log(`✓ "${redeemed.agentName}" is in your Bay and said hello. It is in your private chat: the group "${where}" did not work (${landed.missed ?? "refused"}).`);
216
+ }
217
+ else {
218
+ deps.log(`✓ "${redeemed.agentName}" is in your Bay${where ? ` (group "${where}")` : ""} and said hello.`);
219
+ }
219
220
  }
220
221
  catch (e) {
221
- if (e instanceof connect_link_budget_1.OutOfTime) {
222
- deps.log(`The computer is signed in and ${app} is set up, but joining the Bay took too long. Restart ${app}, then tell it: ${joinLine(redeemed.agentName)}`);
223
- return 2;
224
- }
225
- deps.log(`Joined nothing yet: ${describeRedeemError(e)}`);
226
- deps.log(`The computer is connected. Restart ${app}, then tell it: ${joinLine(redeemed.agentName)}`);
227
- return 2;
222
+ deps.log(e instanceof connect_link_budget_1.OutOfTime ? ` Joining the Bay took too long.` : ` Joined nothing yet: ${describeRedeemError(e)}`);
228
223
  }
229
- if (where && !landed.inGroup) {
230
- deps.log(`✓ "${redeemed.agentName}" is in your Bay and said hello. It is in your private chat: the group "${where}" did not work (${landed.missed ?? "refused"}).`);
224
+ // The doctor, run here instead of by the person: it fixes what it can and says what is left.
225
+ let left = [];
226
+ if (deps.checkAndFix) {
227
+ try {
228
+ left = await budget.run(connect_link_budget_1.CONNECT_LINK_CAPS.check, (signal) => deps.checkAndFix(runtime, base, signal));
229
+ }
230
+ catch (e) {
231
+ left = [e instanceof connect_link_budget_1.OutOfTime ? "the last check took too long. Run: npx -y baychat@latest doctor" : `the last check failed (${e instanceof Error ? e.message : String(e)}). Run: npx -y baychat@latest doctor`];
232
+ }
231
233
  }
232
- else {
233
- deps.log(`✓ "${redeemed.agentName}" is in your Bay${where ? ` (group "${where}")` : ""} and said hello.`);
234
+ // ONE last line: ready and the one thing to do, or the one thing still in the way.
235
+ // With the check, its answer is the truth (it set the link's own app up again when that had failed).
236
+ const problem = deps.checkAndFix ? (left[0] ?? null) : ownLine;
237
+ if (!problem && joined) {
238
+ deps.log((0, connect_link_setup_2.readyLine)(runtime, redeemed.agentName));
239
+ return 0;
234
240
  }
235
- deps.log(` Tell the person: restart ${app}, then tell it: ${joinLine(redeemed.agentName)} (or start a session from the BayChat app), so it can answer there.`);
236
- return 0;
241
+ deps.log(problem ? `Almost ready: ${problem}` : `Almost ready: restart ${app}, then tell it: ${(0, connect_link_setup_2.joinLine)(redeemed.agentName)}`);
242
+ return 2;
237
243
  }
238
244
  /** The conversation a join or create answer names: its text says "conversation <id>." either way. */
239
245
  function conversationOf(answer) {
@@ -336,5 +342,6 @@ const realConnectLinkDeps = () => ({
336
342
  setUp: connect_link_setup_1.setUpAppInChild,
337
343
  joinAndGreet: joinAndGreetOverMcp,
338
344
  log: (line) => console.log(line),
345
+ checkAndFix: (runtime, base, signal) => (0, connect_link_check_1.checkAndFix)(runtime, signal, (0, connect_link_check_1.realCheckDeps)(base)),
339
346
  });
340
347
  exports.realConnectLinkDeps = realConnectLinkDeps;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.claudeFileMcpCheck = claudeFileMcpCheck;
4
+ const launch_1 = require("./channel/launch");
5
+ const claude_trust_1 = require("./launch/claude-trust");
6
+ /**
7
+ * Doctor's Claude Code `mcp` check on a computer with no `claude` command to ask (only the Claude
8
+ * app, 26 Nov 2026): the file Claude Code reads, `~/.claude.json` (claude-user-config.ts). A FAIL here,
9
+ * unlike "could not run claude mcp list", is something `connect` can fix — and the paste's own check
10
+ * (connect-link-check.ts) then does.
11
+ */
12
+ function claudeFileMcpCheck(home, readText, remedy, display) {
13
+ const file = (0, claude_trust_1.claudeConfigPath)(process.env, home);
14
+ return (0, launch_1.channelRegistered)(file, (p) => readText(p) ?? "", "baychat")
15
+ ? { name: "mcp", status: "pass", detail: `${display(file)} names baychat (no claude command to ask)` }
16
+ : { name: "mcp", status: "fail", detail: `no baychat entry in ${display(file)}`, remedy };
17
+ }
@@ -43,6 +43,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
43
43
  exports.currentDoctorEnv = currentDoctorEnv;
44
44
  exports.cmdDoctor = cmdDoctor;
45
45
  const child_process_1 = require("child_process");
46
+ const bay_gone_1 = require("./bay-gone");
46
47
  const fs = __importStar(require("fs"));
47
48
  const os = __importStar(require("os"));
48
49
  const config_1 = require("./config");
@@ -92,9 +93,11 @@ async function currentDoctorEnv() {
92
93
  }
93
94
  }
94
95
  const relay = await (0, commands_1.tryRelayStatus)();
96
+ const device = (0, config_1.loadDeviceCredentials)();
95
97
  return {
96
98
  bays,
97
99
  bayRelayAlive,
100
+ bayGone: device ? await (0, bay_gone_1.goneBays)(device.baseUrl, bays) : new Set(),
98
101
  home: os.homedir(),
99
102
  platform: process.platform,
100
103
  now: Date.now(),
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.questionsCheck = questionsCheck;
4
+ /**
5
+ * Can a question in a Claude Code terminal reach the phone? The relay reads the panes of sessions
6
+ * started from BayChat and with `baychat claude` (relay/launcher/session-watch.ts); a plain
7
+ * `claude` outside tmux has no pane anyone can read, so a question there waits for the keyboard.
8
+ */
9
+ function questionsCheck(env) {
10
+ const name = "questions";
11
+ if (env.platform === "win32") {
12
+ return { name, status: "warn", detail: "a question in a Windows terminal cannot reach your phone", remedy: "start sessions in WSL with `baychat claude`" };
13
+ }
14
+ if (!env.resolveBinary("tmux").ok) {
15
+ return { name, status: "warn", detail: "tmux is not installed, so a question in a terminal cannot reach your phone", remedy: "install tmux, then start sessions with `baychat claude`" };
16
+ }
17
+ return {
18
+ name,
19
+ status: "pass",
20
+ detail: "questions reach your phone in sessions started from BayChat or with `baychat claude`; a plain `claude` outside tmux cannot be read",
21
+ };
22
+ }
package/dist/doctor.js CHANGED
@@ -63,6 +63,7 @@ exports.renderReport = renderReport;
63
63
  exports.bayChecks = bayChecks;
64
64
  exports.autoUpdateCheck = autoUpdateCheck;
65
65
  const fs = __importStar(require("fs"));
66
+ const doctor_questions_1 = require("./doctor-questions");
66
67
  const os = __importStar(require("os"));
67
68
  const path = __importStar(require("path"));
68
69
  const mailbox_1 = require("./relay/mailbox");
@@ -74,6 +75,7 @@ const runtime_binary_1 = require("./runtime-binary");
74
75
  const runtimes_1 = require("./runtimes");
75
76
  const runtime_install_1 = require("./runtime-install");
76
77
  const launch_1 = require("./channel/launch");
78
+ const doctor_claude_file_1 = require("./doctor-claude-file");
77
79
  const plugin_1 = require("./channel/plugin");
78
80
  const transport_1 = require("./relay/transport");
79
81
  const ws_1 = require("./relay/ws");
@@ -313,11 +315,7 @@ function renderReport(report) {
313
315
  return lines;
314
316
  }
315
317
  // ─── Individual checks ──────────────────────────────────────────────────────
316
- /**
317
- * One line per Bay login. An expired Bay login fails exactly as an expired device login does
318
- * (`baychat login` renews every Bay at once); a non-default Bay whose relay does not answer
319
- * warns, because only that Bay's terminal sessions lose their wake-ups.
320
- */
318
+ /** One line per Bay login: expired fails (`login` renews all), a dead relay warns, a deleted Bay fails. */
321
319
  function bayChecks(env) {
322
320
  const bays = env.bays ?? [];
323
321
  if (bays.length < 2)
@@ -325,6 +323,8 @@ function bayChecks(env) {
325
323
  return bays.map((bay) => {
326
324
  const name = "bay";
327
325
  const label = `"${bay.bayName}"${bay.isDefault ? " (default)" : ""}`;
326
+ if (env.bayGone?.has(bay.bayId))
327
+ return { name, status: "fail", detail: `${label} — deleted in BayChat, still on this computer`, remedy: "baychat connect claude" };
328
328
  const expiresAt = Date.parse(bay.expiresAt);
329
329
  if (Number.isNaN(expiresAt) || expiresAt <= env.now) {
330
330
  return { name, status: "fail", detail: `${label} — login expired`, remedy: "baychat login" };
@@ -524,12 +524,12 @@ function runtimeReport(runtime, env) {
524
524
  return {
525
525
  runtime,
526
526
  label: spec.label,
527
- checks: [mcp, skill, binaryCheck(runtime, env), sessionCheck(runtime, env), ...(extra ? [extra(env)] : [])],
527
+ checks: [mcp, skill, binaryCheck(runtime, env), sessionCheck(runtime, env), ...(extra ? extra(env) : [])],
528
528
  };
529
529
  }
530
- /** Checks only one runtime has. Claude Code alone has the wake-up channel. */
530
+ /** Checks only one runtime has. Claude Code alone has the wake-up channel, and a terminal the relay reads. */
531
531
  const RUNTIME_EXTRA_CHECKS = {
532
- claude: channelCheck,
532
+ claude: (env) => [channelCheck(env), (0, doctor_questions_1.questionsCheck)(env)],
533
533
  };
534
534
  /** `baychat@baychat 0.28.0`; Claude Code records "unknown" for a manifest that names no version. */
535
535
  function pluginLabel(version) {
@@ -609,11 +609,12 @@ function mcpCheck(runtime, env) {
609
609
  // it is correct wherever the config turns out to live.
610
610
  if (command) {
611
611
  const listed = env.mcpList(runtime);
612
- if (listed === null) {
613
- // Unknown, not absent. Reporting "not registered" because we could not
614
- // run the command would send a user to reinstall something that is fine.
612
+ // No `claude` to ask (only the Claude app, 26 Nov 2026): its own config file is what it reads.
613
+ if (listed === null && runtime === "claude")
614
+ return (0, doctor_claude_file_1.claudeFileMcpCheck)(env.home, env.readText, remedy, (p) => display(p, env));
615
+ // Unknown, not absent: "not registered" would send a user to reinstall something that is fine.
616
+ if (listed === null)
615
617
  return { name: "mcp", status: "skip", detail: `could not run \`${command} mcp list\``, remedy };
616
- }
617
618
  return listed.includes("baychat")
618
619
  ? { name: "mcp", status: "pass", detail: `${command} lists baychat` }
619
620
  : { name: "mcp", status: "fail", detail: `\`${command} mcp list\` does not list baychat`, remedy };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SETTLE_MS = exports.ANSWER_DEADLINE_MS = void 0;
3
+ exports.NOT_ASKED = exports.SETTLE_MS = exports.ANSWER_DEADLINE_MS = void 0;
4
4
  exports.readDialog = readDialog;
5
5
  exports.answerFromPhone = answerFromPhone;
6
6
  exports.paneAnswerDeps = paneAnswerDeps;
@@ -26,6 +26,7 @@ const api_1 = require("./api");
26
26
  const approval_wait_1 = require("./approval-wait");
27
27
  const config_1 = require("./config");
28
28
  const terminal_pane_1 = require("./relay/terminal-pane");
29
+ const waiting_cards_1 = require("./waiting-cards");
29
30
  /** How long the phone may take: the same hour a permission card waits. */
30
31
  exports.ANSWER_DEADLINE_MS = 60 * 60_000;
31
32
  /** One wait on the card between looks at the terminal. */
@@ -39,45 +40,54 @@ const GAP_MS = 1_000;
39
40
  exports.SETTLE_MS = 700;
40
41
  const OPTION = /^\s*(?:❯\s*)?([1-9])\.\s+(\S.*?)\s*$/;
41
42
  const DECORATION = /^[\s│╌─━┃┄┈|]*$/;
43
+ /** The question picker's last rows, which ask for typing, not a tap. */
44
+ const OPEN_ENDED = /^(?:Type something\.?|Chat about this)$/;
42
45
  /**
43
46
  * The open dialog on a captured screen, or undefined. A dialog is a run of options numbered from
44
47
  * 1 with "Esc to cancel" right under it, and the question is the nearest line above ending in "?"
45
48
  * (a conversation's own numbered list has no "Esc to cancel" under it, so it is never one).
49
+ *
50
+ * Between the options there may be rules and each option's own description, indented deeper than
51
+ * its number: Claude Code 2.1.332's question picker (AskUserQuestion) draws them, and ends with
52
+ * "Type something." and "Chat about this", which a tap cannot answer, so they are left off the card
53
+ * (they are the last rows, so the digits of the rest are unchanged). Live run, 29 Nov.
46
54
  */
47
55
  function readDialog(screen) {
48
56
  const lines = screen.split("\n");
49
57
  for (let end = lines.length - 1; end >= 0; end--) {
50
58
  if (!/Esc to cancel/.test(lines[end]))
51
59
  continue;
52
- // The options: the numbered run directly above "Esc to cancel".
53
- const options = [];
54
60
  let i = end - 1;
55
- while (i >= 0 && DECORATION.test(lines[i]) && lines[i].trim() === "")
61
+ while (i >= 0 && DECORATION.test(lines[i]))
56
62
  i--;
57
- let first = i;
58
- while (i >= 0 && OPTION.test(lines[i])) {
59
- first = i;
60
- i--;
61
- }
62
- for (let k = first; k < end; k++) {
63
- const m = OPTION.exec(lines[k]);
64
- if (m)
65
- options.push(m[2]);
66
- }
67
- if (options.length === 0)
63
+ if (i < 0 || !OPTION.test(lines[i]))
68
64
  return undefined;
69
- // In order from 1: "1. …", "2. …".
70
- for (let k = first, n = 1; k < end; k++) {
71
- const m = OPTION.exec(lines[k]);
72
- if (!m)
65
+ // Upward from the last option: options, rules, and descriptions deeper than the option below.
66
+ const found = [];
67
+ let indent = Infinity;
68
+ for (; i >= 0 && end - i <= 40; i--) {
69
+ const line = lines[i];
70
+ const m = OPTION.exec(line);
71
+ if (m) {
72
+ found.unshift({ n: Number(m[1]), label: m[2] });
73
+ indent = line.search(/\d/);
73
74
  continue;
74
- if (Number(m[1]) !== n++)
75
- return undefined;
75
+ }
76
+ if (DECORATION.test(line))
77
+ continue;
78
+ const lead = line.search(/\S/);
79
+ if (found[0]?.n !== 1 && lead > indent && !line.trim().endsWith("?"))
80
+ continue;
81
+ break;
76
82
  }
77
- for (let q = first - 1; q >= Math.max(0, first - 15); q--) {
83
+ if (found.length === 0 || found.some((o, k) => o.n !== k + 1))
84
+ return undefined;
85
+ while (found.length > 1 && OPEN_ENDED.test(found[found.length - 1].label))
86
+ found.pop();
87
+ for (let q = i; q >= Math.max(0, i - 15); q--) {
78
88
  const text = lines[q].trim();
79
89
  if (text.endsWith("?") && !text.startsWith("│"))
80
- return { question: text, options };
90
+ return { question: text, options: found.map((o) => o.label) };
81
91
  }
82
92
  return undefined;
83
93
  }
@@ -88,8 +98,14 @@ const sameDialog = (screen, dialog) => readDialog(screen)?.question === dialog.q
88
98
  * One dialog, answered from the phone or left to the terminal. Returns what happened, for the log.
89
99
  * NEVER THROWS (a failing capture counts as "the dialog is gone": send nothing).
90
100
  */
101
+ /** How an answer that never reached the owner starts (the first card failed): the watch tries again. */
102
+ exports.NOT_ASKED = "not asked: ";
103
+ /** After a wait that failed (an API restart), the next wait starts this much later. */
104
+ const POLL_RETRY_MS = 15_000;
91
105
  async function answerFromPhone(run, deps) {
92
106
  const { session, dialog } = run;
107
+ // What the card says above the dialog's own question (the session watch names a usage limit).
108
+ const intro = run.intro ?? `${session} is waiting on a question in its terminal:`;
93
109
  const capture = async () => {
94
110
  try {
95
111
  return await deps.capture();
@@ -99,7 +115,10 @@ async function answerFromPhone(run, deps) {
99
115
  }
100
116
  };
101
117
  const until = deps.now() + exports.ANSWER_DEADLINE_MS;
102
- let outcome = await deps.ask({ session, question: `${session} is waiting on a question in its terminal:\n${dialog.question}`, options: dialog.options }, Math.min(until, deps.now() + WINDOW_MS));
118
+ let outcome = await deps.ask({ session, question: `${intro}\n${dialog.question}`, options: dialog.options }, Math.min(until, deps.now() + WINDOW_MS));
119
+ if (outcome.kind === "failed")
120
+ return `${exports.NOT_ASKED}${outcome.reason}`;
121
+ const { requestId } = outcome;
103
122
  for (;;) {
104
123
  if (outcome.kind === "answered") {
105
124
  const index = outcome.index;
@@ -118,19 +137,20 @@ async function answerFromPhone(run, deps) {
118
137
  const pressed = await deps.press(key);
119
138
  return pressed.ok ? `sent ${key}` : `refused: ${pressed.reason}`;
120
139
  }
121
- if (outcome.kind !== "deadline")
122
- return outcome.kind === "failed" ? `failed: ${outcome.reason}` : outcome.kind;
140
+ // A wait that failed (an API restart) is not the end: the card is still on the phone.
141
+ if (outcome.kind !== "deadline" && outcome.kind !== "failed")
142
+ return outcome.kind;
123
143
  // Nobody tapped yet. Answered at the keyboard meanwhile? Then the card goes.
124
144
  if (!sameDialog(await capture(), dialog)) {
125
- await deps.withdraw(outcome.requestId);
145
+ await deps.withdraw(requestId);
126
146
  return "answered in the terminal";
127
147
  }
128
148
  if (deps.now() >= until) {
129
- await deps.withdraw(outcome.requestId);
149
+ await deps.withdraw(requestId);
130
150
  return "no answer";
131
151
  }
132
- await deps.sleep(GAP_MS);
133
- outcome = await deps.poll(outcome.requestId, Math.min(until, deps.now() + WINDOW_MS));
152
+ await deps.sleep(outcome.kind === "failed" ? POLL_RETRY_MS : GAP_MS);
153
+ outcome = await deps.poll(requestId, Math.min(until, deps.now() + WINDOW_MS));
134
154
  }
135
155
  }
136
156
  function tmux(handle, args) {
@@ -186,7 +206,9 @@ async function cmdNotifyAnswer(argv = []) {
186
206
  const device = (0, config_1.loadDeviceCredentials)();
187
207
  if (!session || !device || handle?.kind !== "tmux" || !dialog?.question || !Array.isArray(dialog.options))
188
208
  return 0;
189
- const outcome = await answerFromPhone({ session, dialog }, paneAnswerDeps(device, handle));
209
+ // Marked for the whole wait (every window), so the relay's session watch never adds a second card.
210
+ const unmark = (0, waiting_cards_1.markWaitingCard)(`notify-${process.pid}`, process.pid, session);
211
+ const outcome = await answerFromPhone({ session, dialog }, paneAnswerDeps(device, handle)).finally(unmark);
190
212
  process.stderr.write(`baychat notify-answer: ${outcome}\n`);
191
213
  }
192
214
  catch (err) {