@emqo/claudebridge 0.2.1 → 0.2.3

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.
@@ -129,7 +129,7 @@ export class AgentEngine {
129
129
  let buffer = "";
130
130
  child.stdout.on("data", (data) => {
131
131
  const chunk = data.toString();
132
- console.log(`[agent] stdout chunk: ${chunk.slice(0, 100)}`);
132
+ console.log(`[agent] stdout chunk: ${chunk.slice(0, 200)}`);
133
133
  buffer += chunk;
134
134
  const lines = buffer.split("\n");
135
135
  buffer = lines.pop() || "";
@@ -155,6 +155,9 @@ export class AgentEngine {
155
155
  fullText = msg.result;
156
156
  if (msg.total_cost_usd)
157
157
  cost = msg.total_cost_usd;
158
+ if (msg.is_error) {
159
+ console.error(`[agent] claude error result: subtype=${msg.subtype} message=${JSON.stringify(msg.error_message || msg.message || "unknown").slice(0, 500)}`);
160
+ }
158
161
  }
159
162
  }
160
163
  catch { }
@@ -175,12 +178,14 @@ export class AgentEngine {
175
178
  resolve({ text: fullText.trim() || "(timed out)", sessionId: newSessionId, cost });
176
179
  return;
177
180
  }
178
- if (newSessionId)
179
- this.store.setSession(userId, newSessionId, platform);
180
181
  if (code === 0 || fullText.trim()) {
182
+ if (newSessionId)
183
+ this.store.setSession(userId, newSessionId, platform);
181
184
  resolve({ text: fullText.trim() || "(no response)", sessionId: newSessionId, cost });
182
185
  }
183
186
  else {
187
+ // Don't save session on failure — stale session would lock the user in a failure loop
188
+ this.store.clearSession(userId);
184
189
  reject(new Error(`claude exited ${code}: ${stderr.slice(0, 500)}`));
185
190
  }
186
191
  });
package/dist/index.js CHANGED
@@ -31,30 +31,12 @@ async function main() {
31
31
  console.error("[fatal] no platform enabled");
32
32
  process.exit(1);
33
33
  }
34
- for (const a of adapters)
35
- await a.start();
36
- console.log(`[claudebridge] running with ${adapters.length} adapter(s)`);
37
- // Hot reload config.yaml
38
- let reloadTimer = null;
39
- watch(_cfgPath || "config.yaml", () => {
40
- if (reloadTimer)
41
- clearTimeout(reloadTimer);
42
- reloadTimer = setTimeout(() => {
43
- try {
44
- config = reloadConfig();
45
- engine.reloadConfig(config);
46
- console.log("[claudebridge] config reloaded");
47
- }
48
- catch (err) {
49
- console.error("[claudebridge] config reload failed:", err);
50
- }
51
- }, 500); // debounce
52
- });
34
+ // --- Register signal handlers and hot-reload BEFORE starting adapters ---
53
35
  const shutdown = () => {
54
36
  console.log("[claudebridge] shutting down...");
55
37
  for (const a of adapters)
56
38
  a.stop();
57
- process.exit(0);
39
+ setTimeout(() => process.exit(0), 1000);
58
40
  };
59
41
  process.on("SIGINT", shutdown);
60
42
  process.on("SIGTERM", shutdown);
@@ -68,6 +50,30 @@ async function main() {
68
50
  console.error("[claudebridge] config reload failed:", err);
69
51
  }
70
52
  });
53
+ // Hot reload config.yaml on file change
54
+ let reloadTimer = null;
55
+ watch(_cfgPath || "config.yaml", () => {
56
+ if (reloadTimer)
57
+ clearTimeout(reloadTimer);
58
+ reloadTimer = setTimeout(() => {
59
+ try {
60
+ config = reloadConfig();
61
+ engine.reloadConfig(config);
62
+ console.log("[claudebridge] config reloaded");
63
+ }
64
+ catch (err) {
65
+ console.error("[claudebridge] config reload failed:", err);
66
+ }
67
+ }, 500); // debounce
68
+ });
69
+ // --- Start adapters (fire-and-forget, they run infinite polling loops) ---
70
+ for (const a of adapters) {
71
+ a.start().catch(err => {
72
+ console.error("[fatal] adapter crashed:", err);
73
+ process.exit(1);
74
+ });
75
+ }
76
+ console.log(`[claudebridge] running with ${adapters.length} adapter(s)`);
71
77
  }
72
78
  main().catch((err) => {
73
79
  console.error("[fatal]", err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emqo/claudebridge",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Bridge Claude Code Agent SDK to chat platforms (Telegram, Discord, etc.)",
5
5
  "main": "dist/index.js",
6
6
  "bin": {