@botcord/daemon 0.2.44 → 0.2.45

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.
@@ -280,6 +280,13 @@ export class OpenclawAcpAdapter {
280
280
  if (capped) {
281
281
  log.warn("openclaw-acp.assistant-text-capped", { sessionId: acpSessionId });
282
282
  }
283
+ if (!finalText) {
284
+ const stopReason = pickStopReason(promptResult);
285
+ const warningTail = handle.nonJsonStdoutTail.slice(-8).join("\n").trim();
286
+ const detail = warningTail ? `; stdout: ${truncateDetail(warningTail, 1000)}` : "";
287
+ const reason = stopReason ? `prompt stopped: ${stopReason}` : "empty assistant response";
288
+ return failResult(acpSessionId, `openclaw-acp: ${reason}${detail}`);
289
+ }
283
290
  return {
284
291
  text: finalText,
285
292
  newSessionId: acpSessionId,
@@ -359,6 +366,7 @@ export class OpenclawAcpAdapter {
359
366
  subscribers: new Map(),
360
367
  nextId: 1,
361
368
  buffer: "",
369
+ nonJsonStdoutTail: [],
362
370
  initialized: false,
363
371
  inFlight: 0,
364
372
  closed: false,
@@ -431,6 +439,10 @@ function onStdoutChunk(handle, chunk) {
431
439
  msg = JSON.parse(line);
432
440
  }
433
441
  catch (err) {
442
+ handle.nonJsonStdoutTail.push(line.slice(0, 500));
443
+ if (handle.nonJsonStdoutTail.length > 20) {
444
+ handle.nonJsonStdoutTail.splice(0, handle.nonJsonStdoutTail.length - 20);
445
+ }
434
446
  log.warn("openclaw-acp.parse-error", {
435
447
  error: err instanceof Error ? err.message : String(err),
436
448
  line: line.slice(0, 200),
@@ -744,6 +756,15 @@ function pickFinalText(result) {
744
756
  return r.message;
745
757
  return undefined;
746
758
  }
759
+ function pickStopReason(result) {
760
+ if (!result || typeof result !== "object")
761
+ return undefined;
762
+ const v = result.stopReason;
763
+ return typeof v === "string" && v.length > 0 ? v : undefined;
764
+ }
765
+ function truncateDetail(text, max) {
766
+ return text.length <= max ? text : `${text.slice(0, max)}…`;
767
+ }
747
768
  function looksLikeReasoningLeak(text) {
748
769
  const t = text.trim();
749
770
  if (!t)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botcord/daemon",
3
- "version": "0.2.44",
3
+ "version": "0.2.45",
4
4
  "description": "BotCord local daemon — bridges Hub inbox push to local Claude Code / Codex / Gemini CLIs",
5
5
  "type": "module",
6
6
  "bin": {
@@ -162,6 +162,46 @@ describe("OpenclawAcpAdapter.run", () => {
162
162
  expect(spawnFn.mock.calls[0][1]).toEqual(["acp", "--url", "ws://127.0.0.1:1"]);
163
163
  });
164
164
 
165
+ it("returns an error instead of empty text when OpenClaw emits warnings and no assistant text", async () => {
166
+ const child = new FakeChild();
167
+ const adapter = new OpenclawAcpAdapter({ spawnFn: makeSpawn(child) });
168
+ const gateway: ResolvedOpenclawGateway = {
169
+ name: "local",
170
+ url: "ws://127.0.0.1:1",
171
+ openclawAgent: "main",
172
+ };
173
+
174
+ child.stdin.on("data", (chunk: Buffer) => {
175
+ for (const line of chunk.toString("utf8").split("\n").filter(Boolean)) {
176
+ const frame = JSON.parse(line);
177
+ if (frame.method === "initialize") {
178
+ child.stdout.write("◇ Config warnings ─────────────────────╮\n");
179
+ child.stdout.write("│ - models.providers.foo.apiKey: Missing env var FOO_API_KEY │\n");
180
+ child.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: frame.id, result: { protocolVersion: 1 } }) + "\n");
181
+ } else if (frame.method === "session/new") {
182
+ child.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: frame.id, result: { sessionId: "sid-warn" } }) + "\n");
183
+ } else if (frame.method === "session/prompt") {
184
+ child.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: frame.id, result: { stopReason: "error" } }) + "\n");
185
+ }
186
+ }
187
+ });
188
+
189
+ const res = await adapter.run({
190
+ text: "hi",
191
+ sessionId: null,
192
+ cwd: "/tmp",
193
+ accountId: "ag_alice",
194
+ signal: new AbortController().signal,
195
+ trustLevel: "owner",
196
+ gateway,
197
+ });
198
+
199
+ expect(res.text).toBe("");
200
+ expect(res.newSessionId).toBe("sid-warn");
201
+ expect(res.error).toContain("prompt stopped: error");
202
+ expect(res.error).toContain("Missing env var FOO_API_KEY");
203
+ });
204
+
165
205
  it("streams only final text when OpenClaw sends reasoning before a final block", async () => {
166
206
  const child = new FakeChild();
167
207
  const adapter = new OpenclawAcpAdapter({ spawnFn: makeSpawn(child) });
@@ -37,6 +37,7 @@ interface AcpProcessHandle {
37
37
  subscribers: Map<string, (note: AcpNotification) => void>;
38
38
  nextId: number;
39
39
  buffer: string;
40
+ nonJsonStdoutTail: string[];
40
41
  initialized: boolean;
41
42
  initializePromise?: Promise<void>;
42
43
  idleTimer?: NodeJS.Timeout;
@@ -355,6 +356,14 @@ export class OpenclawAcpAdapter implements RuntimeAdapter {
355
356
  log.warn("openclaw-acp.assistant-text-capped", { sessionId: acpSessionId });
356
357
  }
357
358
 
359
+ if (!finalText) {
360
+ const stopReason = pickStopReason(promptResult);
361
+ const warningTail = handle.nonJsonStdoutTail.slice(-8).join("\n").trim();
362
+ const detail = warningTail ? `; stdout: ${truncateDetail(warningTail, 1000)}` : "";
363
+ const reason = stopReason ? `prompt stopped: ${stopReason}` : "empty assistant response";
364
+ return failResult(acpSessionId, `openclaw-acp: ${reason}${detail}`);
365
+ }
366
+
358
367
  return {
359
368
  text: finalText,
360
369
  newSessionId: acpSessionId,
@@ -447,6 +456,7 @@ export class OpenclawAcpAdapter implements RuntimeAdapter {
447
456
  subscribers: new Map(),
448
457
  nextId: 1,
449
458
  buffer: "",
459
+ nonJsonStdoutTail: [],
450
460
  initialized: false,
451
461
  inFlight: 0,
452
462
  closed: false,
@@ -533,6 +543,10 @@ function onStdoutChunk(handle: AcpProcessHandle, chunk: string): void {
533
543
  try {
534
544
  msg = JSON.parse(line);
535
545
  } catch (err) {
546
+ handle.nonJsonStdoutTail.push(line.slice(0, 500));
547
+ if (handle.nonJsonStdoutTail.length > 20) {
548
+ handle.nonJsonStdoutTail.splice(0, handle.nonJsonStdoutTail.length - 20);
549
+ }
536
550
  log.warn("openclaw-acp.parse-error", {
537
551
  error: err instanceof Error ? err.message : String(err),
538
552
  line: line.slice(0, 200),
@@ -847,6 +861,16 @@ function pickFinalText(result: unknown): string | undefined {
847
861
  return undefined;
848
862
  }
849
863
 
864
+ function pickStopReason(result: unknown): string | undefined {
865
+ if (!result || typeof result !== "object") return undefined;
866
+ const v = (result as Record<string, unknown>).stopReason;
867
+ return typeof v === "string" && v.length > 0 ? v : undefined;
868
+ }
869
+
870
+ function truncateDetail(text: string, max: number): string {
871
+ return text.length <= max ? text : `${text.slice(0, max)}…`;
872
+ }
873
+
850
874
  function looksLikeReasoningLeak(text: string): boolean {
851
875
  const t = text.trim();
852
876
  if (!t) return false;