@gonzih/cc-discord 0.2.41 → 0.2.42

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.
@@ -343,15 +343,15 @@ function spawnPersistentSession(ns, token, wire, onExit, onOutput) {
343
343
  const claudeBin = resolveClaude();
344
344
  const env = buildEnv(token);
345
345
  console.log(`[meta-agent-manager] spawning persistent session (ns=${ns})`);
346
- // DO NOT ADD -p OR --input-format stream-json HERE.
347
- // With -p + --input-format stream-json, Claude buffers all stdin until EOF before responding.
348
- // Since the stdin pipe is never closed (it stays open for subsequent messages), Claude
349
- // waits forever and never produces output. Interactive mode (no -p) reads one line at a
350
- // time and responds immediately. Verified by direct test: `echo msg | claude --continue
351
- // --output-format stream-json ...` responds correctly; the -p variant does not.
346
+ // --input-format stream-json: Claude reads newline-delimited JSON messages from stdin.
347
+ // Each message must be: {"type":"user","message":{"role":"user","content":"..."}}
348
+ // Claude responds immediately to each message and stays alive waiting for the next one.
349
+ // DO NOT omit --input-format stream-json: without it, Claude ignores stdin when the
350
+ // pipe stays open (no TTY), producing no output until stdin is closed (EOF).
352
351
  const proc = spawn(claudeBin, [
353
352
  "--continue",
354
353
  "--output-format", "stream-json",
354
+ "--input-format", "stream-json",
355
355
  "--verbose",
356
356
  "--dangerously-skip-permissions",
357
357
  ], { cwd: wsPath, env, stdio: ["pipe", "pipe", "pipe"] });
@@ -402,13 +402,14 @@ export function createMetaAgentManager() {
402
402
  * Resets the inactivity timer so the watchdog doesn't kill a session
403
403
  * that just received a message but hasn't responded yet.
404
404
  */
405
- function writeToStdin(ns, line) {
405
+ function writeToStdin(ns, content) {
406
406
  const session = sessions.get(ns);
407
407
  if (!session)
408
408
  return;
409
409
  try {
410
- // Interactive mode: plain text line, Claude reads it as user input
411
- session.proc.stdin.write(`${line}\n`);
410
+ // --input-format stream-json: each message must be a newline-delimited JSON object.
411
+ const jsonMsg = JSON.stringify({ type: "user", message: { role: "user", content } });
412
+ session.proc.stdin.write(`${jsonMsg}\n`);
412
413
  // Reset inactivity timer — the session now has SESSION_INACTIVITY_MS to respond
413
414
  session.lastOutputAt = Date.now();
414
415
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-discord",
3
- "version": "0.2.41",
3
+ "version": "0.2.42",
4
4
  "description": "Claude Code Discord bot — chat with Claude Code via Discord",
5
5
  "type": "module",
6
6
  "bin": {