charon-hooks 0.2.4 → 0.2.6

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/bin/charon.js CHANGED
@@ -160,9 +160,24 @@ async function getWebhookBaseUrl(port) {
160
160
  * Handle --wait command: blocks until the promise is resolved
161
161
  */
162
162
  async function handleWaitCommand(uuid, triggerId, port) {
163
- const running = await isCharonRunning(port);
163
+ // Wait for service to be ready with retries
164
+ const maxRetries = 5;
165
+ const retryDelay = 1000;
166
+ let running = false;
167
+
168
+ for (let i = 0; i < maxRetries; i++) {
169
+ running = await isCharonRunning(port);
170
+ if (running) break;
171
+
172
+ if (i < maxRetries - 1) {
173
+ console.error(`[charon] Service not ready, retrying in ${retryDelay}ms... (${i + 1}/${maxRetries})`);
174
+ await new Promise(r => setTimeout(r, retryDelay));
175
+ }
176
+ }
177
+
164
178
  if (!running) {
165
179
  console.error('[charon] Charon is not running. Start it with: npx charon-hooks --service start');
180
+ console.error('[charon] Tip: Run "npx charon-hooks" directly (foreground) to see startup errors');
166
181
  process.exit(1);
167
182
  }
168
183
 
@@ -208,7 +223,19 @@ async function handleWaitCommand(uuid, triggerId, port) {
208
223
  // Process was killed, exit gracefully
209
224
  process.exit(0);
210
225
  }
211
- console.error(`[charon] Wait error: ${err.message}`);
226
+ // Provide more helpful error messages
227
+ if (err.cause?.code === 'ECONNREFUSED') {
228
+ console.error(`[charon] Connection refused to localhost:${port}`);
229
+ console.error('[charon] The service may have crashed. Check: npx charon-hooks --service status');
230
+ } else if (err.cause?.code === 'ECONNRESET') {
231
+ console.error(`[charon] Connection reset by localhost:${port}`);
232
+ console.error('[charon] The service may have restarted. Try running --wait again.');
233
+ } else {
234
+ console.error(`[charon] Wait error: ${err.message}`);
235
+ if (err.cause) {
236
+ console.error(`[charon] Cause: ${err.cause.code || err.cause.message || err.cause}`);
237
+ }
238
+ }
212
239
  process.exit(1);
213
240
  }
214
241
  }
@@ -220,6 +247,7 @@ async function handleResolveCommand(uuid, description, port) {
220
247
  const running = await isCharonRunning(port);
221
248
  if (!running) {
222
249
  console.error('[charon] Charon is not running. Start it with: npx charon-hooks --service start');
250
+ console.error('[charon] Tip: Run "npx charon-hooks" directly (foreground) to see startup errors');
223
251
  process.exit(1);
224
252
  }
225
253
 
@@ -245,7 +273,16 @@ async function handleResolveCommand(uuid, description, port) {
245
273
  console.log(`[charon] No waiter for ${uuid} (already resolved or never registered)`);
246
274
  }
247
275
  } catch (err) {
248
- console.error(`[charon] Resolve error: ${err.message}`);
276
+ // Provide more helpful error messages
277
+ if (err.cause?.code === 'ECONNREFUSED') {
278
+ console.error(`[charon] Connection refused to localhost:${port}`);
279
+ console.error('[charon] The service may have crashed. Check: npx charon-hooks --service status');
280
+ } else {
281
+ console.error(`[charon] Resolve error: ${err.message}`);
282
+ if (err.cause) {
283
+ console.error(`[charon] Cause: ${err.cause.code || err.cause.message || err.cause}`);
284
+ }
285
+ }
249
286
  process.exit(1);
250
287
  }
251
288
  }
@@ -1249,7 +1249,7 @@ async function startTunnel(config, port = 3e3) {
1249
1249
  try {
1250
1250
  const currentState = getTunnelState(db2);
1251
1251
  const targetDomain = config.domain || null;
1252
- if (currentState.connected && currentState.domain === targetDomain) {
1252
+ if (listener && currentState.connected && currentState.domain === targetDomain) {
1253
1253
  if (currentState.expose_ui !== (config.expose_ui ?? false)) {
1254
1254
  console.log(`[tunnel] Updating expose_ui to ${config.expose_ui ?? false}`);
1255
1255
  const updatedState = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "charon-hooks",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Autonomous task triggering service - webhooks and cron to AI agents",
5
5
  "type": "module",
6
6
  "bin": {