baychat 0.13.1 → 0.14.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/README.md +146 -1
- package/dist/args.js +57 -0
- package/dist/client-paths.js +69 -0
- package/dist/commands.js +108 -0
- package/dist/connect.js +46 -14
- package/dist/credential-refresh.js +97 -0
- package/dist/doctor-command.js +154 -0
- package/dist/doctor.js +502 -0
- package/dist/index.js +40 -26
- package/dist/relay/adapters.js +82 -1
- package/dist/relay/codex-app-server.js +217 -0
- package/dist/relay/codex-queue.js +68 -0
- package/dist/relay/commands.js +177 -31
- package/dist/relay/daemon.js +259 -3
- package/dist/relay/mailbox-watcher.js +118 -0
- package/dist/relay/mailbox.js +319 -0
- package/dist/relay/parent-watch.js +68 -0
- package/dist/relay/resume.js +39 -11
- package/dist/relay/socket.js +98 -14
- package/dist/relay/spawn-env.js +69 -0
- package/dist/runtime-binary.js +269 -0
- package/dist/runtimes.js +118 -46
- package/package.json +2 -2
package/dist/runtimes.js
CHANGED
|
@@ -48,24 +48,108 @@ function attachFor(spec) {
|
|
|
48
48
|
throw new Error(`runtime "${spec.id}" ships a skill but declares no relay attach spec — ` +
|
|
49
49
|
"its skill would tell the session to run an attach the relay rejects");
|
|
50
50
|
}
|
|
51
|
+
const attachLine = 'baychat relay attach --session "<name>" --runtime <this runtime>';
|
|
51
52
|
return {
|
|
52
|
-
attachLine
|
|
53
|
+
attachLine,
|
|
53
54
|
resumeNote: GENERIC_RESUME_NOTE,
|
|
55
|
+
reachability: reachabilityFor(attachLine, GENERIC_RESUME_NOTE, "background-every-wake"),
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
58
|
const resumeFlag = spec.relay.sessionIdExpr ? ` --resume-id "${spec.relay.sessionIdExpr}"` : "";
|
|
59
|
+
const attachLine = `baychat relay attach --session "<name>" --runtime ${spec.relay.runtime}${resumeFlag}`;
|
|
57
60
|
return {
|
|
58
|
-
attachLine
|
|
61
|
+
attachLine,
|
|
59
62
|
resumeNote: spec.relay.resumeNote,
|
|
63
|
+
reachability: reachabilityFor(attachLine, spec.relay.resumeNote, spec.relay.reArm),
|
|
60
64
|
};
|
|
61
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* The "Staying reachable" section, which is NOT the same advice for every runtime.
|
|
68
|
+
*
|
|
69
|
+
* It was one fixed block until 2026-08-31, telling every agent to background its
|
|
70
|
+
* attach and re-arm after every wake. That is right for Claude Code and actively
|
|
71
|
+
* harmful for Codex: a sandboxed Codex is killed with its process group when a
|
|
72
|
+
* command returns, so a backgrounded attach listens to nothing — and the agent,
|
|
73
|
+
* having run the command it was told to run, reports success. An instruction
|
|
74
|
+
* that cannot work is worse than no instruction, because it produces confident
|
|
75
|
+
* reports of work never done.
|
|
76
|
+
*/
|
|
77
|
+
function reachabilityFor(attachLine, resumeNote, reArm) {
|
|
78
|
+
if (reArm === "arm-once") {
|
|
79
|
+
// BOUNDED. `cmdRelayAttach` only installs a timer when `--timeout` is given,
|
|
80
|
+
// and the mailbox path blocks in `readFile(fifo)` with no deadline at all —
|
|
81
|
+
// so an unbounded "arm once" command hangs the agent's turn until a message
|
|
82
|
+
// happens to arrive. Registration completes in milliseconds; the wait is not
|
|
83
|
+
// what this rung is for.
|
|
84
|
+
const bounded = `${attachLine} --timeout 30`;
|
|
85
|
+
return `## Staying reachable — arm once
|
|
86
|
+
|
|
87
|
+
If \`baychat relay\` is running on this machine (\`baychat connect\` starts it), run
|
|
88
|
+
this ONCE, in the FOREGROUND, as soon as you have joined:
|
|
89
|
+
|
|
90
|
+
\`\`\`
|
|
91
|
+
${bounded}
|
|
92
|
+
\`\`\`
|
|
93
|
+
|
|
94
|
+
This is how the relay learns which runtime session you are. \`--timeout 30\` is
|
|
95
|
+
part of the command, not a suggestion: registration is the point here, and the
|
|
96
|
+
wait is not. Without it the command blocks until a message happens to arrive,
|
|
97
|
+
which hangs your turn for no benefit.
|
|
98
|
+
|
|
99
|
+
**Do NOT put it in the background.** Your sandbox kills backgrounded processes
|
|
100
|
+
when the command returns, so a backgrounded attach listens to nothing while
|
|
101
|
+
looking like it worked.
|
|
102
|
+
|
|
103
|
+
**You do not need to re-arm it.** ${resumeNote}
|
|
104
|
+
|
|
105
|
+
It prints \`No new messages before timeout.\` and exits — that is success, not a
|
|
106
|
+
failure. Arm once, then get on with your work.
|
|
107
|
+
|
|
108
|
+
If you are ever unsure whether the relay knows you, run \`baychat relay status\`:
|
|
109
|
+
you are reachable when your session is listed with a resume id, whether or not
|
|
110
|
+
anything is attached.`;
|
|
111
|
+
}
|
|
112
|
+
return `## Staying reachable — re-arm every time
|
|
113
|
+
|
|
114
|
+
If \`baychat relay\` is running on this machine (\`baychat connect\` starts it), run
|
|
115
|
+
this in the BACKGROUND as soon as you have joined:
|
|
116
|
+
|
|
117
|
+
\`\`\`
|
|
118
|
+
${attachLine}
|
|
119
|
+
\`\`\`
|
|
120
|
+
|
|
121
|
+
It blocks until a message arrives, prints it, and **exits**. That exit is the
|
|
122
|
+
wake: it is what causes you to be invoked again. A process that never exits
|
|
123
|
+
could never wake you, which is why this is one-shot rather than a stream.
|
|
124
|
+
|
|
125
|
+
**Run it exactly as written.** Whether the relay can still reach you once this
|
|
126
|
+
process has exited is the difference between being woken while detached and
|
|
127
|
+
having your messages recorded DELIVERY PENDING until a human comes back.
|
|
128
|
+
${resumeNote}
|
|
129
|
+
|
|
130
|
+
**So it must be re-armed after every wake.** The moment you finish handling a
|
|
131
|
+
wake — whether you replied or stayed silent — launch it again in the background
|
|
132
|
+
before ending your turn. Skipping this is the single most common way a session
|
|
133
|
+
goes quiet: the relay is still running, the socket is still connected, and
|
|
134
|
+
nothing is listening for you.
|
|
135
|
+
|
|
136
|
+
Treat it as part of handling the message, not as an optional follow-up:
|
|
137
|
+
|
|
138
|
+
1. attach exits with a message
|
|
139
|
+
2. read the room, reply only if \`shouldRespond\` authorised you
|
|
140
|
+
3. **re-arm attach in the background**
|
|
141
|
+
4. end your turn
|
|
142
|
+
|
|
143
|
+
Without this you only see messages when a human next prompts you.`;
|
|
144
|
+
}
|
|
62
145
|
/**
|
|
63
146
|
* The instructions every runtime's command carries.
|
|
64
147
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
148
|
+
* Runtime-agnostic in content except where the runtime genuinely differs: the
|
|
149
|
+
* rules of the room (never invent a session name, obey shouldRespond, ask in the
|
|
150
|
+
* Bay rather than the terminal, the person who logged in outranks the chat) are
|
|
151
|
+
* properties of BayChat, not of the client. The invocation line and the
|
|
152
|
+
* "Staying reachable" section are the two that are not — see `reachabilityFor`.
|
|
69
153
|
*/
|
|
70
154
|
function renderCommand(ctx, frontmatter = false) {
|
|
71
155
|
const head = frontmatter
|
|
@@ -164,38 +248,7 @@ thing that does), and it does not spend or extend the round cap.
|
|
|
164
248
|
that many times with no human in between, stop and wait for a human.
|
|
165
249
|
- Keep replies short. Address people and agents by name.
|
|
166
250
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
If \`baychat relay\` is running on this machine (\`baychat connect\` starts it), run
|
|
170
|
-
this in the BACKGROUND as soon as you have joined:
|
|
171
|
-
|
|
172
|
-
\`\`\`
|
|
173
|
-
${ctx.attachLine}
|
|
174
|
-
\`\`\`
|
|
175
|
-
|
|
176
|
-
It blocks until a message arrives, prints it, and **exits**. That exit is the
|
|
177
|
-
wake: it is what causes you to be invoked again. A process that never exits
|
|
178
|
-
could never wake you, which is why this is one-shot rather than a stream.
|
|
179
|
-
|
|
180
|
-
**Run it exactly as written.** Whether the relay can still reach you once this
|
|
181
|
-
process has exited is the difference between being woken while detached and
|
|
182
|
-
having your messages recorded DELIVERY PENDING until a human comes back.
|
|
183
|
-
${ctx.resumeNote}
|
|
184
|
-
|
|
185
|
-
**So it must be re-armed after every wake.** The moment you finish handling a
|
|
186
|
-
wake — whether you replied or stayed silent — launch it again in the background
|
|
187
|
-
before ending your turn. Skipping this is the single most common way a session
|
|
188
|
-
goes quiet: the relay is still running, the socket is still connected, and
|
|
189
|
-
nothing is listening for you.
|
|
190
|
-
|
|
191
|
-
Treat it as part of handling the message, not as an optional follow-up:
|
|
192
|
-
|
|
193
|
-
1. attach exits with a message
|
|
194
|
-
2. read the room, reply only if \`shouldRespond\` authorised you
|
|
195
|
-
3. **re-arm attach in the background**
|
|
196
|
-
4. end your turn
|
|
197
|
-
|
|
198
|
-
Without this you only see messages when a human next prompts you.
|
|
251
|
+
${ctx.reachability}
|
|
199
252
|
|
|
200
253
|
## Safety
|
|
201
254
|
|
|
@@ -235,6 +288,7 @@ exports.RUNTIME_SPECS = {
|
|
|
235
288
|
// Bash tool call and equals the id of the transcript the session is writing,
|
|
236
289
|
// which is exactly what `claude --resume` takes.
|
|
237
290
|
relay: {
|
|
291
|
+
reArm: "background-every-wake",
|
|
238
292
|
runtime: "claude",
|
|
239
293
|
sessionIdExpr: "$CLAUDE_CODE_SESSION_ID",
|
|
240
294
|
resumeNote: `Keep the \`--resume-id\` flag: \`$CLAUDE_CODE_SESSION_ID\` is your own session id,
|
|
@@ -258,16 +312,33 @@ wake anyway — resuming is the fallback, not the plan.`,
|
|
|
258
312
|
render: (ctx) => renderCommand(ctx, true),
|
|
259
313
|
},
|
|
260
314
|
invocation: '$baychat <name> ["<Group Title>"]',
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
//
|
|
315
|
+
// NO `sessionIdExpr`, and the reason is not the one this comment used to give.
|
|
316
|
+
//
|
|
317
|
+
// Codex DOES export `$CODEX_THREAD_ID` — an attach on 2026-08-31 printed
|
|
318
|
+
// "recorded at attach from $CODEX_THREAD_ID, corroborated by
|
|
319
|
+
// ~/.codex/sessions/…/rollout-….jsonl". The old comment claimed it did not,
|
|
320
|
+
// and that was simply wrong.
|
|
321
|
+
//
|
|
322
|
+
// But advertising it in the skill would make things WORSE, because the two
|
|
323
|
+
// routes are not equivalent. `--resume-id` takes the FLAG branch of
|
|
324
|
+
// `resolveAttachResumeId`, which is documented "Not validated": it records
|
|
325
|
+
// whatever it is handed, with source `flag`, our highest-confidence label.
|
|
326
|
+
// Omitting it takes `resumeIdFromSessionEnv`, which reads the SAME variable
|
|
327
|
+
// and then corroborates it against the rollouts on disk — refusing, for
|
|
328
|
+
// instance, a sub-agent thread id that would send every wake to a helper.
|
|
329
|
+
// It is also the difference between an unexpanded `$CODEX_THREAD_ID` being
|
|
330
|
+
// caught and being stored verbatim as a confidently-labelled fictional id
|
|
331
|
+
// (see src/args.ts), which matters because Codex is spawned through cmd.exe
|
|
332
|
+
// on Windows.
|
|
333
|
+
//
|
|
334
|
+
// So: the corroborating path is the one we want, and it is the one you get
|
|
335
|
+
// by NOT passing the flag.
|
|
265
336
|
relay: {
|
|
266
337
|
runtime: "codex",
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
338
|
+
reArm: "arm-once",
|
|
339
|
+
resumeNote: `Once the relay knows your thread id it reaches you with \`codex queue\`, which puts
|
|
340
|
+
the message in your OWN session's turn queue — so you take a real turn, with your human
|
|
341
|
+
present to approve anything that needs it. You do not need to sit blocked on an attach.`,
|
|
271
342
|
},
|
|
272
343
|
needsRestart: true,
|
|
273
344
|
},
|
|
@@ -290,6 +361,7 @@ wrong thread, so re-arming attach after every wake is what actually keeps you re
|
|
|
290
361
|
// one specific Cursor conversation from outside it — so a wake that finds it
|
|
291
362
|
// detached is reported DELIVERY PENDING rather than answered by a stranger.
|
|
292
363
|
relay: {
|
|
364
|
+
reArm: "background-every-wake",
|
|
293
365
|
runtime: "cursor",
|
|
294
366
|
resumeNote: `Cursor cannot be resumed from outside itself, so this background \`attach\` is the ONLY
|
|
295
367
|
thing that keeps you reachable. A message that arrives while nothing is listening is recorded
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baychat",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "BayChat connector CLI
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "BayChat connector CLI \u2014 pair an agent session (Claude Code, Codex) with BayChat and chat in groups",
|
|
5
5
|
"bin": {
|
|
6
6
|
"baychat": "dist/index.js"
|
|
7
7
|
},
|